Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Prev Previous commit
Next Next commit
crypto: validate CFRG webcrypto JWK import "d" and "x" are a pair
  • Loading branch information
panva committed Nov 24, 2022
commit 3785129f719dbadd540b0aeff0f1ebb5bbe464ac
22 changes: 17 additions & 5 deletions 22 lib/internal/crypto/cfrg.js
Original file line number Diff line number Diff line change
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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might find a faster solution for this in the future :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping you'd say that ;)

throw lazyDOMException('Invalid JWK keyData', 'DataError');
}
}
break;
}
case 'raw': {
Expand Down
36 changes: 0 additions & 36 deletions 36 test/wpt/status/WebCryptoAPI.json
Original file line number Diff line number Diff line change
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])"
]
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.