Skip to content

Commit d4e14d7

Browse files
authored
WebCryptoAPI: check secure curves JWK alg being ignored and not exported (#42333)
1 parent 3c6d898 commit d4e14d7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

WebCryptoAPI/import_export/okp_importKey.https.any.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
}
8282

8383
testFormat(format, algorithm, data, vector.name, usages, extractable);
84+
85+
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
86+
if (format === "jwk" && extractable) {
87+
testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);
88+
}
8489
});
8590

8691
});
@@ -92,6 +97,11 @@
9297
var data = keyData[vector.name];
9398

9499
testFormat(format, algorithm, data, vector.name, usages, extractable);
100+
101+
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
102+
if (format === "jwk" && extractable) {
103+
testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);
104+
}
95105
});
96106
});
97107
});
@@ -126,6 +136,28 @@
126136
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], algorithm, extractable, usages));
127137
}
128138

139+
// Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export
140+
// https://github.com/WICG/webcrypto-secure-curves/pull/24
141+
function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {
142+
promise_test(function(test) {
143+
return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, algorithm, true, usages).
144+
then(function(key) {
145+
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
146+
147+
return subtle.exportKey('jwk', key).
148+
then(function(result) {
149+
assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");
150+
assert_equals(result.alg, undefined, 'No JWK "alg" member is present');
151+
assert_true(equalJwk(keyData, result), "Round trip works");
152+
}, function(err) {
153+
assert_unreached("Threw an unexpected error: " + err.toString());
154+
});
155+
}, function(err) {
156+
assert_unreached("Threw an unexpected error: " + err.toString());
157+
});
158+
}, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, algorithm, true, usages));
159+
}
160+
129161

130162

131163
// Helper methods follow:

0 commit comments

Comments
 (0)