blob: f9006bd6256c1ea9839afb9b1b0d8cfdcd7a0c99 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test ECDH deriveBits operation with malformed parameters");
jsTestIsAsync = true;
var extractable = true;
var jwkPrivateKey = {
kty: "EC",
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
d: "ppxBSov3N8_AUcisAuvmLV4yE8e_L_BLE8bZb9Z1Xjg",
};
var jwkPublicKey = {
kty: "EC",
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
};
var jwkPublicKeyP384 = {
kty: "EC",
crv: "P-384",
x: "TEsQRAL-nau4K75XNynuR6fdoTGGm5X1XgOrR5iSziBVqhRYOAteuF8-U0wxN89s",
y: "r-Wn9YIXJ_r7uNN5s9eVeXElm6ZcTGvYKg6GtKJXUXuJUZRMF7EIB_H6xpOmthV6",
};
var rsaSpkiKey = Base64URL.parse("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCjRCtFwvSNYMZ07u5SxARxglJl75T7bUZXFsDVxHkMhpNC2RaN4jWE5bwYUDMeD2fVmxhpaUQn/6AbFLh6gHxtwrCfc7rIo/SfDdGd3GkRlXK5xXwGuM6MvP9nuZHaarIyArRFh2U2UZxFlVsKI0pSHo6n58W1fPZ1syOoVEZ/WYE6gLhMMwfpeAm97mro7mekRdMULOV/mR5Ul3CHm9Zt93Dc8GpnPA8bhLiB0VNyGTEMa06nJul4gj1sjxLDoUvZY2EWq7oUUnfLBUYMfiqK0kQcW94wvBrIq2DQUApLyTTbaAOY46TLwX6c8LtubJriYKTC5a9Bb0/7ovTWB0wIDAQAB");
crypto.subtle.importKey("jwk", jwkPrivateKey, { name: "ECDH", namedCurve: "P-256" }, extractable, ["deriveBits"]).then(function(result) {
privateKey = result;
return crypto.subtle.importKey("jwk", jwkPublicKey, { name: "ECDH", namedCurve: "P-256" }, extractable, [ ]);
}).then(function(result) {
publicKey = result;
return crypto.subtle.importKey("spki", rsaSpkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]);
}).then(function(result) {
fakeKey = result;
return crypto.subtle.importKey("jwk", jwkPublicKeyP384, { name: "ECDH", namedCurve: "P-384" }, extractable, [ ]);
}).then(function(result) {
publicKeyP384 = result;
// Malformed AlgorithmIdentifiers
shouldReject('crypto.subtle.deriveBits("ecdh", privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh"}, privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: true}, privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: null}, privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: undefined}, privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: Symbol()}, privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: { }}, privateKey, null)');
shouldReject('crypto.subtle.deriveBits({name: "ecdh", public: 1}, privateKey, null)');
// base key is public
shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:publicKey }, publicKey, null)');
// public key is private
shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:privateKey }, privateKey, null)');
// faked public key
shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:fakeKey }, privateKey, null)');
// mismatched named curve
shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:publicKeyP384 }, privateKey, null)');
// Wrong length
return shouldReject('crypto.subtle.deriveBits({ name:"ECDH", public:publicKey }, privateKey, 384)');
}).then(finishJSTest, finishJSTest);
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>