| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,7 +102,7 @@ function registerDeriveTests(options) { | |||
| 102 | 102 | failureTest( | |
| 103 | 103 | test.name, | |
| 104 | 104 | "InvalidAccessError", | |
| 105 | - () => derive(algorithmName, test.key, privateKey) | ||
| 105 | + () => derive(algorithmName, test.key, privateKey, test.length) | ||
| 106 | 106 | ); | |
| 107 | 107 | }); | |
| 108 | 108 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,16 +17,16 @@ function define_tests() { | |||
| 17 | 17 | derivedBits = await subtle.deriveBits(testData.deriveAlg, privateKey); | |
| 18 | 18 | else | |
| 19 | 19 | derivedBits = await subtle.deriveBits(testData.deriveAlg, privateKey, testParam.length); | |
| 20 | - if (testParam.expected === undefined) { | ||
| 21 | - assert_unreached("deriveBits should have thrown an OperationError exception."); | ||
| 20 | + if (testParam.expected === "TypeError" || testParam.expected === "OperationError") { | ||
| 21 | + assert_unreached("deriveBits should have thrown an " + testParam.expected + " exception."); | ||
| 22 | 22 | } | |
| 23 | 23 | assert_array_equals(new Uint8Array(derivedBits), testParam.expected, "Derived bits do not match the expected result."); | |
| 24 | 24 | } catch (err) { | |
| 25 | - if (err instanceof AssertionError || testParam.expected !== undefined) { | ||
| 25 | + if (err instanceof AssertionError || !(testParam.expected === "TypeError" || testParam.expected === "OperationError")) { | ||
| 26 | 26 | throw err; | |
| 27 | 27 | } | |
| 28 | 28 | assert_true(privateKey !== undefined, "Key should be valid."); | |
| 29 | - assert_equals(err.name, "OperationError", "deriveBits correctly threw OperationError: " + err.message); | ||
| 29 | + assert_equals(err.name, testParam.expected, "deriveBits correctly threw " + testParam.expected + ": " + err.message); | ||
| 30 | 30 | } | |
| 31 | 31 | }, algorithm + " derivation with " + testParam.length + " as 'length' parameter"); | |
| 32 | 32 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,38 +1,49 @@ | |||
| 1 | + var enforceRangeTestCases = [ | ||
| 2 | + // These cases should throw an error in all algorithms due to [EnforceRange] | ||
| 3 | + {length: NaN, expected: "TypeError"}, | ||
| 4 | + {length: Infinity, expected: "TypeError"}, | ||
| 5 | + {length: -8, expected: "TypeError"}, | ||
| 6 | + {length: 2**32 + 8, expected: "TypeError"}, | ||
| 7 | + ]; | ||
| 1 | 8 | var testCases = { | |
| 2 | 9 | "HKDF": [ | |
| 3 | 10 | {length: 256, expected: algorithms["HKDF"].derivation}, | |
| 4 | 11 | {length: 384, expected: algorithms["HKDF"].derivation384}, | |
| 5 | - {length: 230, expected: undefined}, // should throw an exception, not multiple of 8 | ||
| 12 | + {length: 230, expected: "OperationError"}, // should throw an exception, not multiple of 8 | ||
| 6 | 13 | {length: 0, expected: emptyArray}, | |
| 7 | - {length: null, expected: undefined }, // should throw an exception | ||
| 8 | - {length: undefined, expected: undefined }, // should throw an exception | ||
| 9 | - {length: "omitted", expected: undefined }, // default value is null, so should throw | ||
| 14 | + {length: null, expected: "OperationError"}, // should throw an exception | ||
| 15 | + {length: undefined, expected: "OperationError"}, // should throw an exception | ||
| 16 | + {length: "omitted", expected: "OperationError"}, // default value is null, so should throw | ||
| 17 | + ...enforceRangeTestCases, | ||
| 10 | 18 | ], | |
| 11 | 19 | "PBKDF2": [ | |
| 12 | 20 | {length: 256, expected: algorithms["PBKDF2"].derivation}, | |
| 13 | 21 | {length: 384, expected: algorithms["PBKDF2"].derivation384}, | |
| 14 | - {length: 230, expected: undefined}, // should throw an exception, not multiple of 8 | ||
| 22 | + {length: 230, expected: "OperationError"}, // should throw an exception, not multiple of 8 | ||
| 15 | 23 | {length: 0, expected: emptyArray}, | |
| 16 | - {length: null, expected: undefined }, // should throw an exception | ||
| 17 | - {length: undefined, expected: undefined }, // should throw an exception | ||
| 18 | - {length: "omitted", expected: undefined }, // default value is null, so should throw | ||
| 24 | + {length: null, expected: "OperationError"}, // should throw an exception | ||
| 25 | + {length: undefined, expected: "OperationError"}, // should throw an exception | ||
| 26 | + {length: "omitted", expected: "OperationError"}, // default value is null, so should throw | ||
| 27 | + ...enforceRangeTestCases, | ||
| 19 | 28 | ], | |
| 20 | 29 | "ECDH": [ | |
| 21 | 30 | {length: 256, expected: algorithms["ECDH"].derivation}, | |
| 22 | - {length: 384, expected: undefined}, // should throw an exception, bigger than the output size | ||
| 31 | + {length: 384, expected: "OperationError"}, // should throw an exception, bigger than the output size | ||
| 23 | 32 | {length: 230, expected: algorithms["ECDH"].derivation230}, | |
| 24 | 33 | {length: 0, expected: emptyArray}, | |
| 25 | 34 | {length: null, expected: algorithms["ECDH"].derivation}, | |
| 26 | 35 | {length: undefined, expected: algorithms["ECDH"].derivation}, | |
| 27 | - {length: "omitted", expected: algorithms["ECDH"].derivation }, // default value is null | ||
| 36 | + {length: "omitted", expected: algorithms["ECDH"].derivation}, // default value is null | ||
| 37 | + ...enforceRangeTestCases, | ||
| 28 | 38 | ], | |
| 29 | 39 | "X25519": [ | |
| 30 | 40 | {length: 256, expected: algorithms["X25519"].derivation}, | |
| 31 | - {length: 384, expected: undefined}, // should throw an exception, bigger than the output size | ||
| 41 | + {length: 384, expected: "OperationError"}, // should throw an exception, bigger than the output size | ||
| 32 | 42 | {length: 230, expected: algorithms["X25519"].derivation230}, | |
| 33 | 43 | {length: 0, expected: emptyArray}, | |
| 34 | 44 | {length: null, expected: algorithms["X25519"].derivation}, | |
| 35 | 45 | {length: undefined, expected: algorithms["X25519"].derivation}, | |
| 36 | - {length: "omitted", expected: algorithms["X25519"].derivation }, // default value is null | ||
| 46 | + {length: "omitted", expected: algorithms["X25519"].derivation}, // default value is null | ||
| 47 | + ...enforceRangeTestCases, | ||
| 37 | 48 | ], | |
| 38 | 49 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,6 +66,7 @@ async function defineEcdhTests(operation) { | |||
| 66 | 66 | { | |
| 67 | 67 | name: namedCurve + " mismatched curves", | |
| 68 | 68 | key: keys[otherCurve].publicKey, | |
| 69 | + length: 256, | ||
| 69 | 70 | }, | |
| 70 | 71 | { | |
| 71 | 72 | name: namedCurve + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,13 +101,19 @@ function run_test(algorithmNames) { | |||
| 101 | 101 | ||
| 102 | 102 | if (algorithmName.toUpperCase().substring(0, 3) === "AES") { | |
| 103 | 103 | // Specifier properties are name and length | |
| 104 | - [64, 127, 129, 255, 257, 512].forEach(function(length) { | ||
| 104 | + [64, 127, 129, 255, 257, 512, 128 + 2**32, 128 - 2**32].forEach(function(length) { | ||
| 105 | 105 | results.push({name: algorithmName, length: length}); | |
| 106 | 106 | }); | |
| 107 | + } else if (algorithmName.toUpperCase() === "HMAC") { | ||
| 108 | + [128 + 2**32, 128 - 2**32].forEach(function(length) { | ||
| 109 | + results.push({name: algorithmName, hash: "SHA-256", length: length}); | ||
| 110 | + }); | ||
| 107 | 111 | } else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") { | |
| 108 | 112 | [new Uint8Array([1]), new Uint8Array([1,0,0])].forEach(function(publicExponent) { | |
| 109 | 113 | results.push({name: algorithmName, hash: "SHA-256", modulusLength: 1024, publicExponent: publicExponent}); | |
| 110 | 114 | }); | |
| 115 | + results.push({name: algorithmName, hash: "SHA-256", modulusLength: 1024 + 2 ** 32, publicExponent: new Uint8Array([1,0,1])}); | ||
| 116 | + results.push({name: algorithmName, hash: "SHA-256", modulusLength: 1024 - 2 ** 32, publicExponent: new Uint8Array([1,0,1])}); | ||
| 111 | 117 | } else if (algorithmName.toUpperCase().substring(0, 2) === "EC") { | |
| 112 | 118 | ["P-512", "Curve25519"].forEach(function(curveName) { | |
| 113 | 119 | results.push({name: algorithmName, namedCurve: curveName}); | |
@@ -177,6 +183,9 @@ function run_test(algorithmNames) { | |||
| 177 | 183 | [false, true].forEach(function(extractable) { | |
| 178 | 184 | if (name.substring(0,2) === "EC") { | |
| 179 | 185 | testError(algorithm, extractable, usages, "NotSupportedError", "Bad algorithm property"); | |
| 186 | + } else if (name.substring(0,3) === "RSA" && (algorithm.modulusLength < 0 || algorithm.modulusLength > 2**32) || | ||
| 187 | + (name.substring(0,3) === "AES" || name === "HMAC") && (algorithm.length < 0 || algorithm.length > 2**32)) { | ||
| 188 | + testError(algorithm, extractable, usages, "TypeError", "Bad algorithm property"); | ||
| 180 | 189 | } else { | |
| 181 | 190 | testError(algorithm, extractable, usages, "OperationError", "Bad algorithm property"); | |
| 182 | 191 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,6 +65,70 @@ testSupportsMethod(); | |||
| 65 | 65 | // Test standard WebCrypto algorithms for requested operations | |
| 66 | 66 | runSupportsTests(modernAlgorithms, operations); | |
| 67 | 67 | ||
| 68 | + ['ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87'].forEach(name => { | ||
| 69 | + ['sign', 'verify'].forEach(operation => { | ||
| 70 | + test(() => { | ||
| 71 | + assert_true( | ||
| 72 | + SubtleCrypto.supports(operation, { | ||
| 73 | + name, | ||
| 74 | + context: new Uint8Array(255), | ||
| 75 | + }), | ||
| 76 | + `${name} ${operation} supports a 255-byte context` | ||
| 77 | + ); | ||
| 78 | + assert_false( | ||
| 79 | + SubtleCrypto.supports(operation, { | ||
| 80 | + name, | ||
| 81 | + context: new Uint8Array(256), | ||
| 82 | + }), | ||
| 83 | + `${name} ${operation} rejects a 256-byte context` | ||
| 84 | + ); | ||
| 85 | + }, `supports validates ${name} ${operation} context length`); | ||
| 86 | + }); | ||
| 87 | + }); | ||
| 88 | + | ||
| 89 | + const mlKemImportedKeyCases = [ | ||
| 90 | + { | ||
| 91 | + description: 'a matching HMAC length', | ||
| 92 | + additionalAlgorithm: {name: 'HMAC', hash: 'SHA-256', length: 256}, | ||
| 93 | + expected: true, | ||
| 94 | + }, | ||
| 95 | + { | ||
| 96 | + description: 'an algorithm without raw-secret import', | ||
| 97 | + additionalAlgorithm: 'Ed25519', | ||
| 98 | + expected: false, | ||
| 99 | + }, | ||
| 100 | + { | ||
| 101 | + description: 'an HMAC length shorter than the shared secret', | ||
| 102 | + additionalAlgorithm: {name: 'HMAC', hash: 'SHA-256', length: 128}, | ||
| 103 | + expected: false, | ||
| 104 | + }, | ||
| 105 | + { | ||
| 106 | + description: 'an HMAC length longer than the shared secret', | ||
| 107 | + additionalAlgorithm: {name: 'HMAC', hash: 'SHA-256', length: 512}, | ||
| 108 | + expected: false, | ||
| 109 | + }, | ||
| 110 | + ]; | ||
| 111 | + | ||
| 112 | + ['encapsulateKey', 'decapsulateKey'].forEach(operation => { | ||
| 113 | + mlKemImportedKeyCases.forEach(({ | ||
| 114 | + description, | ||
| 115 | + additionalAlgorithm, | ||
| 116 | + expected, | ||
| 117 | + }) => { | ||
| 118 | + test(() => { | ||
| 119 | + assert_equals( | ||
| 120 | + SubtleCrypto.supports( | ||
| 121 | + operation, | ||
| 122 | + 'ML-KEM-768', | ||
| 123 | + additionalAlgorithm | ||
| 124 | + ), | ||
| 125 | + expected, | ||
| 126 | + `ML-KEM-768 ${operation} with ${description}` | ||
| 127 | + ); | ||
| 128 | + }, `supports ${operation} with ${description}`); | ||
| 129 | + }); | ||
| 130 | + }); | ||
| 131 | + | ||
| 68 | 132 | // Test some algorithm objects with valid parameters | |
| 69 | 133 | test(() => { | |
| 70 | 134 | assert_true( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments