<!-- Utilities for manipulating ABVs -->
<script src="util.js"></script>
<!-- A simple wrapper around IndexedDB -->
<script src="simpledb.js"></script>
<!-- Test vectors drawn from the literature -->
<script src="./test-vectors.js"></script>
<!-- General testing framework -->
<script src="./test-array.js"></script>
<script>/* <![CDATA[*/ "use strict";
// -----------------------------------------------------------------------------
TestArray.addTest( "JWK import and use of an AES-GCM key",
function() { var that = this;
// -----------------------------------------------------------------------------
TestArray.addTest( "JWK import and use of an RSASSA-PKCS1-v1_5 private key",
function() { var that = this; var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
function doSign(x) {
return crypto.subtle.sign(alg.name, x, tv.rsassa.data);
}
function fail(x) { console.log(x); error(that); }
// -----------------------------------------------------------------------------
TestArray.addTest( "JWK import and use of an RSASSA-PKCS1-v1_5 public key",
function() { var that = this; var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
function doVerify(x) {
return crypto.subtle.verify(alg.name, x, tv.rsassa.sig256, tv.rsassa.data);
}
function fail() { error(that); }
// -----------------------------------------------------------------------------
TestArray.addTest( "JWK export of a symmetric key",
function() { var that = this; var alg = "AES-GCM"; var jwk = { k: "c2l4dGVlbiBieXRlIGtleQ", kty: "oct" };
function doExport(k) {
return crypto.subtle.exportKey("jwk", k);
}
// -----------------------------------------------------------------------------
TestArray.addTest( "JWK import/export of an RSA private key where p < q",
function() { var jwk = tv.rsassa.jwk_priv_pLTq;
var that = this; var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" };
function doExport(k) {
return crypto.subtle.exportKey("jwk", k);
}
// -----------------------------------------------------------------------------
TestArray.addTest( "JWK export of an RSA public key",
function() { var that = this; var alg = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }; var jwk = tv.rsassa.jwk_pub;
function doExport(k) {
return crypto.subtle.exportKey("jwk", k);
}
// --------
TestArray.addTest( "Check JWK parameters on generated ECDSA key pair",
function() {
crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"])
.then(pair => Promise.all([
crypto.subtle.exportKey("jwk", pair.privateKey),
crypto.subtle.exportKey("jwk", pair.publicKey),
]))
.then(
complete(this, function(x) { var priv = x[0]; var pub = x[1]; var pubIsSubsetOfPriv = Object.keys(pub)
.filter(k => k !== "key_ops") // key_ops is the only complex attr
.reduce((all, k) => all && pub[k] === priv[k], true);
// Can't use hasBaseJwkFields() because EC keys don't get "alg":
// "alg" matches curve to hash, but WebCrypto keys are more flexible.
return hasFields(pub, ["kty", "crv", "key_ops", "ext"]) &&
pub.kty === "EC" &&
pub.crv === "P-256" &&
pub.ext &&
typeof(pub.x) === "string" &&
typeof(pub.y) === "string" &&
shallowArrayEquals(pub.key_ops, ["verify"]) &&
pubIsSubsetOfPriv &&
shallowArrayEquals(priv.key_ops, ["sign"]) &&
typeof(priv.d) === "string";
}),
error(this));
}
);
// --------
TestArray.addTest( "Check key_ops parameter on an unusable RSA public key",
function() { var parameters = {
name: "RSASSA-PKCS1-v1_5",
modulusLength: 1024,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256",
};
// The public key generated here will have no usages and will therefore
// have an empty key_ops list.
crypto.subtle.generateKey(parameters, true, ["sign"])
.then(pair => crypto.subtle.exportKey("jwk", pair.publicKey))
.then(complete(this, x => x.key_ops.length === 0),
error(this));
}
);
/* ]]>*/</script>
</head>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.