Skip to content

Commit

Permalink
crypto: use DataError for CFRG webcrypto raw and jwk import key checks
Browse files Browse the repository at this point in the history
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 5, 2023
1 parent 0ca8413 commit c4ae718
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
6 changes: 3 additions & 3 deletions lib/internal/crypto/cfrg.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ function createCFRGRawKey(name, keyData, isPublic) {
case 'X25519':
if (keyData.byteLength !== 32) {
throw lazyDOMException(
`${name} raw keys must be exactly 32-bytes`);
`${name} raw keys must be exactly 32-bytes`, 'DataError');
}
break;
case 'Ed448':
if (keyData.byteLength !== 57) {
throw lazyDOMException(
`${name} raw keys must be exactly 57-bytes`);
`${name} raw keys must be exactly 57-bytes`, 'DataError');
}
break;
case 'X448':
if (keyData.byteLength !== 56) {
throw lazyDOMException(
`${name} raw keys must be exactly 56-bytes`);
`${name} raw keys must be exactly 56-bytes`, 'DataError');
}
break;
}
Expand Down
36 changes: 0 additions & 36 deletions test/wpt/status/WebCryptoAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
"import_export/okp_importKey_failures_Ed25519.https.any.js": {
"fail": {
"expected": [
"Bad key length: importKey(jwk(private), {name: Ed25519}, true, [sign])",
"Bad key length: importKey(jwk(private), {name: Ed25519}, false, [sign])",
"Bad key length: importKey(jwk(private), {name: Ed25519}, true, [sign, sign])",
"Bad key length: importKey(jwk(private), {name: Ed25519}, false, [sign, sign])",
"Bad key length: importKey(jwk (public) , {name: Ed25519}, true, [verify])",
"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])",
"Invalid key pair: importKey(jwk(private), {name: Ed25519}, true, [sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed25519}, true, [sign, sign])"
]
Expand All @@ -27,14 +19,6 @@
"import_export/okp_importKey_failures_Ed448.https.any.js": {
"fail": {
"expected": [
"Bad key length: importKey(jwk(private), {name: Ed448}, true, [sign])",
"Bad key length: importKey(jwk(private), {name: Ed448}, false, [sign])",
"Bad key length: importKey(jwk(private), {name: Ed448}, true, [sign, sign])",
"Bad key length: importKey(jwk(private), {name: Ed448}, false, [sign, sign])",
"Bad key length: importKey(jwk (public) , {name: Ed448}, true, [verify])",
"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])",
"Invalid key pair: importKey(jwk(private), {name: Ed448}, true, [sign])",
"Invalid key pair: importKey(jwk(private), {name: Ed448}, true, [sign, sign])"
]
Expand All @@ -43,16 +27,6 @@
"import_export/okp_importKey_failures_X25519.https.any.js": {
"fail": {
"expected": [
"Bad key length: importKey(jwk (public) , {name: X25519}, true, [])",
"Bad key length: importKey(jwk (public) , {name: X25519}, false, [])",
"Bad key length: importKey(jwk(private), {name: X25519}, true, [deriveKey])",
"Bad key length: importKey(jwk(private), {name: X25519}, false, [deriveKey])",
"Bad key length: importKey(jwk(private), {name: X25519}, true, [deriveBits, deriveKey])",
"Bad key length: importKey(jwk(private), {name: X25519}, false, [deriveBits, deriveKey])",
"Bad key length: importKey(jwk(private), {name: X25519}, true, [deriveBits])",
"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])",
"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 All @@ -63,16 +37,6 @@
"import_export/okp_importKey_failures_X448.https.any.js": {
"fail": {
"expected": [
"Bad key length: importKey(jwk(private), {name: X448}, true, [deriveKey])",
"Bad key length: importKey(jwk(private), {name: X448}, false, [deriveKey])",
"Bad key length: importKey(jwk(private), {name: X448}, true, [deriveBits, deriveKey])",
"Bad key length: importKey(jwk(private), {name: X448}, false, [deriveBits, deriveKey])",
"Bad key length: importKey(jwk(private), {name: X448}, true, [deriveBits])",
"Bad key length: importKey(jwk(private), {name: X448}, false, [deriveBits])",
"Bad key length: importKey(jwk(private), {name: X448}, true, [deriveKey, deriveBits, deriveKey, deriveBits])",
"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, [])",
"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 c4ae718

Please sign in to comment.