Skip to content

Commit

Permalink
crypto: ensure "x" is present when importing private CFRG webcrypto keys
Browse files Browse the repository at this point in the history
PR-URL: #45569
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
panva authored and danielleadams committed Jan 5, 2023
1 parent cc99751 commit 8645a17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
4 changes: 4 additions & 0 deletions lib/internal/crypto/cfrg.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ async function cfrgImportKey(
}
}

if (!isPublic && typeof keyData.x !== 'string') {
throw lazyDOMException('Invalid JWK keyData', 'DataError');
}

verifyAcceptableCfrgKeyUse(
name,
isPublic ? 'public' : 'private',
Expand Down
24 changes: 0 additions & 24 deletions test/wpt/status/WebCryptoAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
"Bad key length: importKey(jwk (public) , {name: Ed25519}, false, [verify])",
"Bad key length: importKey(jwk (public) , {name: Ed25519}, true, [verify, verify])",
"Bad key length: importKey(jwk (public) , {name: Ed25519}, false, [verify, verify])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed25519}, true, [sign])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed25519}, false, [sign])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed25519}, true, [sign, sign])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed25519}, false, [sign, sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed25519}, true, [sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed25519}, true, [sign, sign])"
]
Expand All @@ -55,10 +51,6 @@
"Bad key length: importKey(jwk (public) , {name: Ed448}, false, [verify])",
"Bad key length: importKey(jwk (public) , {name: Ed448}, true, [verify, verify])",
"Bad key length: importKey(jwk (public) , {name: Ed448}, false, [verify, verify])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed448}, true, [sign])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed448}, false, [sign])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed448}, true, [sign, sign])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: Ed448}, false, [sign, sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed448}, true, [sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed448}, true, [sign, sign])"
]
Expand Down Expand Up @@ -95,14 +87,6 @@
"Bad key length: importKey(jwk(private), {name: X25519}, false, [deriveBits])",
"Bad key length: importKey(jwk(private), {name: X25519}, true, [deriveKey, deriveBits, deriveKey, deriveBits])",
"Bad key length: importKey(jwk(private), {name: X25519}, false, [deriveKey, deriveBits, deriveKey, deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, true, [deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, false, [deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, true, [deriveBits, deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, false, [deriveBits, deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, true, [deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, false, [deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, true, [deriveKey, deriveBits, deriveKey, deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X25519}, false, [deriveKey, deriveBits, deriveKey, deriveBits])",
"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])",
Expand Down Expand Up @@ -141,14 +125,6 @@
"Bad key length: importKey(jwk(private), {name: X448}, false, [deriveKey, deriveBits, deriveKey, deriveBits])",
"Bad key length: importKey(jwk (public) , {name: X448}, true, [])",
"Bad key length: importKey(jwk (public) , {name: X448}, false, [])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, true, [deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, false, [deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, true, [deriveBits, deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, false, [deriveBits, deriveKey])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, true, [deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, false, [deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, true, [deriveKey, deriveBits, deriveKey, deriveBits])",
"Missing JWK 'x' parameter: importKey(jwk(private), {name: X448}, false, [deriveKey, deriveBits, deriveKey, deriveBits])",
"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])",
Expand Down

0 comments on commit 8645a17

Please sign in to comment.