Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
crypto: validate CFRG webcrypto JWK import "d" and "x" are a pair
PR-URL: #45569
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
panva authored and danielleadams committed Jan 3, 2023
1 parent 621e3c9 commit b92b804
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 41 deletions.
22 changes: 17 additions & 5 deletions lib/internal/crypto/cfrg.js
Expand Up @@ -300,12 +300,24 @@ async function cfrgImportKey(
name,
isPublic ? 'public' : 'private',
usagesSet);
keyObject = createCFRGRawKey(

const publicKeyObject = createCFRGRawKey(
name,
Buffer.from(
isPublic ? keyData.x : keyData.d,
'base64'),
isPublic);
Buffer.from(keyData.x, 'base64'),
true);

if (isPublic) {
keyObject = publicKeyObject;
} else {
keyObject = createCFRGRawKey(
name,
Buffer.from(keyData.d, 'base64'),
false);

if (!createPublicKey(keyObject).equals(publicKeyObject)) {
throw lazyDOMException('Invalid JWK keyData', 'DataError');
}
}
break;
}
case 'raw': {
Expand Down
36 changes: 0 additions & 36 deletions test/wpt/status/WebCryptoAPI.json
Expand Up @@ -7,41 +7,5 @@
},
"idlharness.https.any.js": {
"skip": "Various non-IDL-compliant things"
},
"import_export/okp_importKey_failures_Ed25519.https.any.js": {
"fail": {
"expected": [
"Invalid key pair: importKey(jwk(private), {name: Ed25519}, true, [sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed25519}, true, [sign, sign])"
]
}
},
"import_export/okp_importKey_failures_Ed448.https.any.js": {
"fail": {
"expected": [
"Invalid key pair: importKey(jwk(private), {name: Ed448}, true, [sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed448}, true, [sign, sign])"
]
}
},
"import_export/okp_importKey_failures_X25519.https.any.js": {
"fail": {
"expected": [
"Invalid key pair: importKey(jwk(private), {name: X25519}, true, [deriveKey])",
"Invalid key pair: importKey(jwk(private), {name: X25519}, true, [deriveBits, deriveKey])",
"Invalid key pair: importKey(jwk(private), {name: X25519}, true, [deriveBits])",
"Invalid key pair: importKey(jwk(private), {name: X25519}, true, [deriveKey, deriveBits, deriveKey, deriveBits])"
]
}
},
"import_export/okp_importKey_failures_X448.https.any.js": {
"fail": {
"expected": [
"Invalid key pair: importKey(jwk(private), {name: X448}, true, [deriveKey])",
"Invalid key pair: importKey(jwk(private), {name: X448}, true, [deriveBits, deriveKey])",
"Invalid key pair: importKey(jwk(private), {name: X448}, true, [deriveBits])",
"Invalid key pair: importKey(jwk(private), {name: X448}, true, [deriveKey, deriveBits, deriveKey, deriveBits])"
]
}
}
}

0 comments on commit b92b804

Please sign in to comment.