Skip to content

Commit ab08796

Browse files
authored
WebCryptoAPI: Check that generated JWK public and private keys match (#53680)
When generating extractable key pairs, check that the exported JWK public key is a superset of the exported JWK private key (with the exception of the `key_ops` property).
1 parent a71b0f4 commit ab08796

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

WebCryptoAPI/generateKey/successes.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function run_test(algorithmNames, slowTest) {
7575
})
7676
.then(async function (result) {
7777
if (resultType === "CryptoKeyPair") {
78-
await Promise.all([
78+
const [jwkPub,,, jwkPriv] = await Promise.all([
7979
subtle.exportKey('jwk', result.publicKey),
8080
subtle.exportKey('spki', result.publicKey),
8181
result.publicKey.algorithm.name.startsWith('RSA') ? undefined : subtle.exportKey('raw', result.publicKey),
@@ -84,6 +84,15 @@ function run_test(algorithmNames, slowTest) {
8484
subtle.exportKey('pkcs8', result.privateKey),
8585
] : [])
8686
]);
87+
88+
if (extractable) {
89+
// Test that the JWK public key is a superset of the JWK private key.
90+
for (const [prop, value] of Object.entries(jwkPub)) {
91+
if (prop !== 'key_ops') {
92+
assert_equals(value, jwkPriv[prop], `Property ${prop} is equal in public and private JWK`);
93+
}
94+
}
95+
}
8796
} else {
8897
if (extractable) {
8998
await Promise.all([

0 commit comments

Comments
 (0)