crypto: allow length=0 for HKDF and PBKDF2 in SubtleCrypto.deriveBits
PR-URL: https://github.com/nodejs/node/pull/55866 Backport-PR-URL: https://github.com/nodejs/node/pull/58589 Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
8237346fb7
commit
f56e62851a
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayBuffer,
|
||||
FunctionPrototypeCall,
|
||||
} = primordials;
|
||||
|
||||
@ -141,7 +142,7 @@ async function hkdfDeriveBits(algorithm, baseKey, length) {
|
||||
const { hash, salt, info } = algorithm;
|
||||
|
||||
if (length === 0)
|
||||
throw lazyDOMException('length cannot be zero', 'OperationError');
|
||||
return new ArrayBuffer(0);
|
||||
if (length === null)
|
||||
throw lazyDOMException('length cannot be null', 'OperationError');
|
||||
if (length % 8) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayBuffer,
|
||||
FunctionPrototypeCall,
|
||||
} = primordials;
|
||||
|
||||
@ -98,10 +99,8 @@ async function pbkdf2DeriveBits(algorithm, baseKey, length) {
|
||||
'iterations cannot be zero',
|
||||
'OperationError');
|
||||
|
||||
const raw = baseKey[kKeyObject].export();
|
||||
|
||||
if (length === 0)
|
||||
throw lazyDOMException('length cannot be zero', 'OperationError');
|
||||
return new ArrayBuffer(0);
|
||||
if (length === null)
|
||||
throw lazyDOMException('length cannot be null', 'OperationError');
|
||||
if (length % 8) {
|
||||
@ -113,7 +112,7 @@ async function pbkdf2DeriveBits(algorithm, baseKey, length) {
|
||||
let result;
|
||||
try {
|
||||
result = await pbkdf2Promise(
|
||||
raw, salt, iterations, length / 8, normalizeHashName(hash.name),
|
||||
baseKey[kKeyObject].export(), salt, iterations, length / 8, normalizeHashName(hash.name),
|
||||
);
|
||||
} catch (err) {
|
||||
throw lazyDOMException(
|
||||
|
6
test/fixtures/wpt/README.md
vendored
6
test/fixtures/wpt/README.md
vendored
@ -25,15 +25,15 @@ Last update:
|
||||
- interfaces: https://github.com/web-platform-tests/wpt/tree/df731dab88/interfaces
|
||||
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
|
||||
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
|
||||
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
|
||||
- resources: https://github.com/web-platform-tests/wpt/tree/919874f84f/resources
|
||||
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
|
||||
- url: https://github.com/web-platform-tests/wpt/tree/67880a4eb8/url
|
||||
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
|
||||
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
|
||||
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
|
||||
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/6748a0a246/WebCryptoAPI
|
||||
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/b81831169b/WebCryptoAPI
|
||||
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
|
||||
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/e97fac4791/webmessaging/broadcastchannel
|
||||
|
||||
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
|
||||
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-wpt
|
||||
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-wpt
|
||||
|
24
test/fixtures/wpt/WebCryptoAPI/cryptokey_algorithm_returns_cached_object.https.any.js
vendored
Normal file
24
test/fixtures/wpt/WebCryptoAPI/cryptokey_algorithm_returns_cached_object.https.any.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// META: title=WebCryptoAPI: CryptoKey.algorithm getter returns cached object
|
||||
|
||||
// https://w3c.github.io/webcrypto/#dom-cryptokey-algorithm
|
||||
// https://github.com/servo/servo/issues/33908
|
||||
|
||||
promise_test(function() {
|
||||
return self.crypto.subtle.generateKey(
|
||||
{
|
||||
name: "AES-CTR",
|
||||
length: 256,
|
||||
},
|
||||
true,
|
||||
["encrypt"],
|
||||
).then(
|
||||
function(key) {
|
||||
let a = key.algorithm;
|
||||
let b = key.algorithm;
|
||||
assert_true(a === b);
|
||||
},
|
||||
function(err) {
|
||||
assert_unreached("generateKey threw an unexpected error: " + err.toString());
|
||||
}
|
||||
);
|
||||
}, "CryptoKey.algorithm getter returns cached object");
|
@ -1,12 +1,19 @@
|
||||
function define_tests_25519() {
|
||||
return define_tests("X25519");
|
||||
}
|
||||
|
||||
function define_tests() {
|
||||
function define_tests_448() {
|
||||
return define_tests("X448");
|
||||
}
|
||||
|
||||
function define_tests(algorithmName) {
|
||||
// May want to test prefixed implementations.
|
||||
var subtle = self.crypto.subtle;
|
||||
|
||||
// Verify the derive functions perform checks against the all-zero value results,
|
||||
// ensuring small-order points are rejected.
|
||||
// https://www.rfc-editor.org/rfc/rfc7748#section-6.1
|
||||
Object.keys(kSmallOrderPoint).forEach(function(algorithmName) {
|
||||
{
|
||||
kSmallOrderPoint[algorithmName].forEach(function(test) {
|
||||
promise_test(async() => {
|
||||
let derived;
|
||||
@ -28,15 +35,16 @@ function define_tests() {
|
||||
assert_equals(derived, undefined, "Operation succeeded, but should not have.");
|
||||
}, algorithmName + " key derivation checks for all-zero value result with a key of order " + test.order);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return importKeys(pkcs8, spki, sizes)
|
||||
.then(function(results) {
|
||||
publicKeys = results.publicKeys;
|
||||
privateKeys = results.privateKeys;
|
||||
noDeriveBitsKeys = results.noDeriveBitsKeys;
|
||||
ecdhKeys = results.ecdhKeys;
|
||||
|
||||
Object.keys(sizes).forEach(function(algorithmName) {
|
||||
{
|
||||
// Basic success case
|
||||
promise_test(function(test) {
|
||||
return subtle.deriveBits({name: algorithmName, public: publicKeys[algorithmName]}, privateKeys[algorithmName], 8 * sizes[algorithmName])
|
||||
@ -101,11 +109,7 @@ function define_tests() {
|
||||
|
||||
// - wrong algorithm
|
||||
promise_test(function(test) {
|
||||
publicKey = publicKeys["X25519"];
|
||||
if (algorithmName === "X25519") {
|
||||
publicKey = publicKeys["X448"];
|
||||
}
|
||||
return subtle.deriveBits({name: algorithmName, public: publicKey}, privateKeys[algorithmName], 8 * sizes[algorithmName])
|
||||
return subtle.deriveBits({name: algorithmName, public: ecdhKeys[algorithmName]}, privateKeys[algorithmName], 8 * sizes[algorithmName])
|
||||
.then(function(derivation) {
|
||||
assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError");
|
||||
}, function(err) {
|
||||
@ -165,16 +169,17 @@ function define_tests() {
|
||||
assert_equals(err.name, "OperationError", "Should throw correct error, not " + err.name + ": " + err.message);
|
||||
});
|
||||
}, algorithmName + " asking for too many bits");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function importKeys(pkcs8, spki, sizes) {
|
||||
var privateKeys = {};
|
||||
var publicKeys = {};
|
||||
var noDeriveBitsKeys = {};
|
||||
var ecdhPublicKeys = {};
|
||||
|
||||
var promises = [];
|
||||
Object.keys(pkcs8).forEach(function(algorithmName) {
|
||||
{
|
||||
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
|
||||
{name: algorithmName},
|
||||
false, ["deriveBits", "deriveKey"])
|
||||
@ -184,8 +189,8 @@ function define_tests() {
|
||||
privateKeys[algorithmName] = null;
|
||||
});
|
||||
promises.push(operation);
|
||||
});
|
||||
Object.keys(pkcs8).forEach(function(algorithmName) {
|
||||
}
|
||||
{
|
||||
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
|
||||
{name: algorithmName},
|
||||
false, ["deriveKey"])
|
||||
@ -195,8 +200,8 @@ function define_tests() {
|
||||
noDeriveBitsKeys[algorithmName] = null;
|
||||
});
|
||||
promises.push(operation);
|
||||
});
|
||||
Object.keys(spki).forEach(function(algorithmName) {
|
||||
}
|
||||
{
|
||||
var operation = subtle.importKey("spki", spki[algorithmName],
|
||||
{name: algorithmName},
|
||||
false, [])
|
||||
@ -206,10 +211,17 @@ function define_tests() {
|
||||
publicKeys[algorithmName] = null;
|
||||
});
|
||||
promises.push(operation);
|
||||
});
|
||||
|
||||
}
|
||||
{
|
||||
var operation = subtle.importKey("spki", ecSPKI,
|
||||
{name: "ECDH", namedCurve: "P-256"},
|
||||
false, [])
|
||||
.then(function(key) {
|
||||
ecdhPublicKeys[algorithmName] = key;
|
||||
});
|
||||
}
|
||||
return Promise.all(promises)
|
||||
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveBitsKeys: noDeriveBitsKeys}});
|
||||
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveBitsKeys: noDeriveBitsKeys, ecdhKeys: ecdhPublicKeys}});
|
||||
}
|
||||
|
||||
// Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is
|
||||
|
10
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits_curve25519.https.any.js
vendored
Normal file
10
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits_curve25519.https.any.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves
|
||||
// META: script=cfrg_curves_bits_fixtures.js
|
||||
// META: script=cfrg_curves_bits.js
|
||||
|
||||
// Define subtests from a `promise_test` to ensure the harness does not
|
||||
// complete before the subtests are available. `explicit_done` cannot be used
|
||||
// for this purpose because the global `done` function is automatically invoked
|
||||
// by the WPT infrastructure in dedicated worker tests defined using the
|
||||
// "multi-global" pattern.
|
||||
promise_test(define_tests_25519, 'setup - define tests');
|
@ -1,4 +1,4 @@
|
||||
// META: title=WebCryptoAPI: deriveBits() Using ECDH with CFRG Elliptic Curves
|
||||
// META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves
|
||||
// META: script=cfrg_curves_bits_fixtures.js
|
||||
// META: script=cfrg_curves_bits.js
|
||||
|
||||
@ -7,4 +7,4 @@
|
||||
// for this purpose because the global `done` function is automatically invoked
|
||||
// by the WPT infrastructure in dedicated worker tests defined using the
|
||||
// "multi-global" pattern.
|
||||
promise_test(define_tests, 'setup - define tests');
|
||||
promise_test(define_tests_448, 'setup - define tests');
|
@ -35,3 +35,6 @@ var kSmallOrderPoint = {
|
||||
{ order: "p+1 (=1, order 1)", vector : new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]) },
|
||||
]
|
||||
};
|
||||
|
||||
// "P-256":
|
||||
var ecSPKI = new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 154, 116, 32, 120, 126, 95, 77, 105, 211, 232, 34, 114, 115, 1, 109, 56, 224, 71, 129, 133, 223, 127, 238, 156, 142, 103, 60, 202, 211, 79, 126, 128, 254, 49, 141, 182, 221, 107, 119, 218, 99, 32, 165, 246, 151, 89, 9, 68, 23, 177, 52, 239, 138, 139, 116, 193, 101, 4, 57, 198, 115, 0, 90, 61]);
|
||||
|
@ -1,5 +1,12 @@
|
||||
function define_tests_25519() {
|
||||
return define_tests("X25519");
|
||||
}
|
||||
|
||||
function define_tests() {
|
||||
function define_tests_448() {
|
||||
return define_tests("X448");
|
||||
}
|
||||
|
||||
function define_tests(algorithmName) {
|
||||
// May want to test prefixed implementations.
|
||||
var subtle = self.crypto.subtle;
|
||||
|
||||
@ -8,7 +15,7 @@ function define_tests() {
|
||||
// https://www.rfc-editor.org/rfc/rfc7748#section-6.1
|
||||
// TODO: The spec states that the check must be done on use, but there is discussion about doing it on import.
|
||||
// https://github.com/WICG/webcrypto-secure-curves/pull/13
|
||||
Object.keys(kSmallOrderPoint).forEach(function(algorithmName) {
|
||||
{
|
||||
kSmallOrderPoint[algorithmName].forEach(function(test) {
|
||||
promise_test(async() => {
|
||||
let derived;
|
||||
@ -32,10 +39,10 @@ function define_tests() {
|
||||
assert_equals(derived, undefined, "Operation succeeded, but should not have.");
|
||||
}, algorithmName + " deriveBits checks for all-zero value result with a key of order " + test.order);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Ensure the keys generated by each algorithm are valid for key derivation.
|
||||
Object.keys(sizes).forEach(function(algorithmName) {
|
||||
{
|
||||
promise_test(async() => {
|
||||
let derived;
|
||||
try {
|
||||
@ -46,15 +53,16 @@ function define_tests() {
|
||||
}
|
||||
assert_false (derived === undefined, "Key derivation failed.");
|
||||
}, "Key derivation using a " + algorithmName + " generated keys.");
|
||||
});
|
||||
}
|
||||
|
||||
return importKeys(pkcs8, spki, sizes)
|
||||
.then(function(results) {
|
||||
publicKeys = results.publicKeys;
|
||||
privateKeys = results.privateKeys;
|
||||
noDeriveKeyKeys = results.noDeriveKeyKeys;
|
||||
ecdhKeys = results.ecdhKeys;
|
||||
|
||||
Object.keys(sizes).forEach(function(algorithmName) {
|
||||
{
|
||||
// Basic success case
|
||||
promise_test(function(test) {
|
||||
return subtle.deriveKey({name: algorithmName, public: publicKeys[algorithmName]}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
|
||||
@ -102,11 +110,7 @@ function define_tests() {
|
||||
|
||||
// - wrong algorithm
|
||||
promise_test(function(test) {
|
||||
publicKey = publicKeys["X25519"];
|
||||
if (algorithmName === "X25519") {
|
||||
publicKey = publicKeys["X448"];
|
||||
}
|
||||
return subtle.deriveKey({name: algorithmName, public: publicKey}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
|
||||
return subtle.deriveKey({name: algorithmName, public: ecdhKeys[algorithmName]}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
|
||||
.then(function(key) {return crypto.subtle.exportKey("raw", key);})
|
||||
.then(function(exportedKey) {
|
||||
assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError");
|
||||
@ -161,16 +165,17 @@ function define_tests() {
|
||||
});
|
||||
});
|
||||
}, algorithmName + " public property value is a secret key");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function importKeys(pkcs8, spki, sizes) {
|
||||
var privateKeys = {};
|
||||
var publicKeys = {};
|
||||
var noDeriveKeyKeys = {};
|
||||
var ecdhPublicKeys = {};
|
||||
|
||||
var promises = [];
|
||||
Object.keys(pkcs8).forEach(function(algorithmName) {
|
||||
{
|
||||
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
|
||||
{name: algorithmName},
|
||||
false, ["deriveBits", "deriveKey"])
|
||||
@ -180,8 +185,8 @@ function define_tests() {
|
||||
privateKeys[algorithmName] = null;
|
||||
});
|
||||
promises.push(operation);
|
||||
});
|
||||
Object.keys(pkcs8).forEach(function(algorithmName) {
|
||||
}
|
||||
{
|
||||
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
|
||||
{name: algorithmName},
|
||||
false, ["deriveBits"])
|
||||
@ -191,8 +196,8 @@ function define_tests() {
|
||||
noDeriveKeyKeys[algorithmName] = null;
|
||||
});
|
||||
promises.push(operation);
|
||||
});
|
||||
Object.keys(spki).forEach(function(algorithmName) {
|
||||
}
|
||||
{
|
||||
var operation = subtle.importKey("spki", spki[algorithmName],
|
||||
{name: algorithmName},
|
||||
false, [])
|
||||
@ -202,10 +207,18 @@ function define_tests() {
|
||||
publicKeys[algorithmName] = null;
|
||||
});
|
||||
promises.push(operation);
|
||||
});
|
||||
}
|
||||
{
|
||||
var operation = subtle.importKey("spki", ecSPKI,
|
||||
{name: "ECDH", namedCurve: "P-256"},
|
||||
false, [])
|
||||
.then(function(key) {
|
||||
ecdhPublicKeys[algorithmName] = key;
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.all(promises)
|
||||
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveKeyKeys: noDeriveKeyKeys}});
|
||||
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveKeyKeys: noDeriveKeyKeys, ecdhKeys: ecdhPublicKeys}});
|
||||
}
|
||||
|
||||
// Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is
|
||||
|
10
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys_curve25519.https.any.js
vendored
Normal file
10
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys_curve25519.https.any.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves
|
||||
// META: script=cfrg_curves_bits_fixtures.js
|
||||
// META: script=cfrg_curves_keys.js
|
||||
|
||||
// Define subtests from a `promise_test` to ensure the harness does not
|
||||
// complete before the subtests are available. `explicit_done` cannot be used
|
||||
// for this purpose because the global `done` function is automatically invoked
|
||||
// by the WPT infrastructure in dedicated worker tests defined using the
|
||||
// "multi-global" pattern.
|
||||
promise_test(define_tests_25519, 'setup - define tests');
|
@ -7,4 +7,4 @@
|
||||
// for this purpose because the global `done` function is automatically invoked
|
||||
// by the WPT infrastructure in dedicated worker tests defined using the
|
||||
// "multi-global" pattern.
|
||||
promise_test(define_tests, 'setup - define tests');
|
||||
promise_test(define_tests_448, 'setup - define tests');
|
9
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/derive_key_and_encrypt.https.any.js
vendored
Normal file
9
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/derive_key_and_encrypt.https.any.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// META: title=WebCryptoAPI: deriveKey() Using HKDF and PBKDF2 from an ECDH key
|
||||
// META: script=derive_key_and_encrypt.js
|
||||
// META: script=../util/helpers.js
|
||||
|
||||
// Test imported from WebKit's source, defined to check the impact of the
|
||||
// 'Get Key Length' behavior of HKDF and PBKDF2, which should return 'null'
|
||||
// in both cases, in the 'deriveKey' operation.
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=282096
|
||||
promise_test(define_tests, 'setup - define tests');
|
49
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/derive_key_and_encrypt.js
vendored
Normal file
49
test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/derive_key_and_encrypt.js
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
let iv = new Uint8Array(Array(12).keys());
|
||||
let salt = new Uint8Array(Array(10).keys());
|
||||
let plaintext = new Uint8Array(Array(100).keys());
|
||||
|
||||
function define_tests() {
|
||||
importKeys().then((keys) => {
|
||||
// Make sure that ecdh produces the same shared secret and the same encryption results using a key derived from that secret.
|
||||
keys.forEach(keyData => {
|
||||
promise_test(async() => {
|
||||
let hkdfKey = await crypto.subtle.deriveKey({name: "ECDH", public: keyData.publicKey }, keyData.privateKey, { name: "HKDF", hash: "" , salt: new Uint8Array(), info: new Uint8Array() }, false, ["deriveKey"]);
|
||||
let aesKey = await crypto.subtle.deriveKey({name: "HKDF", hash: "SHA-256", salt: salt, info: plaintext}, hkdfKey, {name:"AES-GCM", length: 256}, true, ["encrypt", "decrypt"]);
|
||||
let result = await crypto.subtle.encrypt({ name: "AES-GCM", iv: iv }, aesKey, plaintext);
|
||||
assert_equals(bytesToHexString(result), "a6280c522670eaf82f6564afbeb20a5b3f2d4e13c5596f6df3dcff8c34cb2118d2770fb24d83cfac5079c323118485bb01170292ee41eb82b07208f4840478fea3771d8922785c476ba06c2a0b933fc1661431419530a916ad4468545d1af5004a1149fea241c2ff1582ee58a8b7d79935de5def");
|
||||
}, "HKDF derivation of a ECDH key " + keyData.test);
|
||||
promise_test(async() => {
|
||||
let pkdf2Key = await crypto.subtle.deriveKey({name: "ECDH", public: keyData.publicKey }, keyData.privateKey, { name: "PBKDF2", hash: "" , salt: new Uint8Array(), iterations: 32 }, false, ["deriveKey"]);
|
||||
let aesKey = await crypto.subtle.deriveKey({name: "PBKDF2", hash: "SHA-256", salt: salt, iterations: 32 }, pkdf2Key, { name:"AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
|
||||
let result = await crypto.subtle.encrypt({ name: "AES-GCM", iv: iv }, aesKey, plaintext);
|
||||
assert_equals(bytesToHexString(result), "c6201dfbb6fa92c1c246f6ce52f8f1c037f087efde41bac7f6485a2a8207623d2d3825b9cbe8ef864a90378667ed25544ce44cd2904bd96c19f0eeb611d626185165a8afb4e52f95700d7880f83939a42712fc4e377f198c01a61b397b76c3a4b93d932c321084bbef33332169dea09458b27df3");
|
||||
}, "PBKDF2 derivation of a ECDH key " + keyData.test);
|
||||
});
|
||||
}, (e) => {
|
||||
assert_unreached("Setup failed: " + e.message);
|
||||
});
|
||||
|
||||
return Promise.resolve("define_tests");
|
||||
}
|
||||
|
||||
async function importKeys() {
|
||||
// "ECDSA" with a 'P-256' curve
|
||||
let keyData = [
|
||||
hexStringToUint8Array("308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b0201010420fe77a808a7109ba5ceb93ebebad2c84a714d864ad29b62d6537e1969035c0079a144034200042684c752eef1c927a80c74e8b02ce459f848b5977f37fd878b36dae632be9a6cadd56126e404a4f75c535e5769d95b49fb1106f784f3d231b776d1f4d57927ce"),
|
||||
hexStringToUint8Array("042684c752eef1c927a80c74e8b02ce459f848b5977f37fd878b36dae632be9a6cadd56126e404a4f75c535e5769d95b49fb1106f784f3d231b776d1f4d57927ce"),
|
||||
hexStringToUint8Array("308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b020101042067521ccd1f85516118182bca3394c273bab9ce5cd6265105559e325e01f2df1ca144034200043042d8698882f2b59de972390d3fc9277e2e677a6c560148017c9475218fda1b38f76f7645fbcaf3d03e6259d080204fbafb04731b6ad53cb25c3d35d95b7c73"),
|
||||
hexStringToUint8Array("043042d8698882f2b59de972390d3fc9277e2e677a6c560148017c9475218fda1b38f76f7645fbcaf3d03e6259d080204fbafb04731b6ad53cb25c3d35d95b7c73"),
|
||||
];
|
||||
let extractable = true;
|
||||
var allKeys = await Promise.all([
|
||||
crypto.subtle.importKey("pkcs8", keyData[0], {name: "ECDH", namedCurve: "P-256"}, extractable, ["deriveKey", 'deriveBits']),
|
||||
crypto.subtle.importKey("raw", keyData[1], {name: "ECDH", namedCurve: "P-256"}, extractable, []),
|
||||
crypto.subtle.importKey("pkcs8", keyData[2], {name: "ECDH", namedCurve: "P-256"}, extractable, ["deriveKey", 'deriveBits']),
|
||||
crypto.subtle.importKey("raw", keyData[3], {name: "ECDH", namedCurve: "P-256"}, extractable, []),
|
||||
]);
|
||||
// Test cases defined combining public and private keys of each key-pair.
|
||||
return [
|
||||
{ test: 1, publicKey: allKeys[3], privateKey: allKeys[0] },
|
||||
{ test: 2, publicKey: allKeys[1], privateKey: allKeys[2] }
|
||||
];
|
||||
}
|
@ -1,20 +1,26 @@
|
||||
var testCases = {
|
||||
"HKDF": [
|
||||
{length: 256, expected: algorithms["HKDF"].derivation},
|
||||
{length: 0, expected: undefined}, // explicitly disallowed, so should throw
|
||||
{length: 384, expected: algorithms["HKDF"].derivation384},
|
||||
{length: 230, expected: undefined}, // should throw an exception, not multiple of 8
|
||||
{length: 0, expected: emptyArray},
|
||||
{length: null, expected: undefined }, // should throw an exception
|
||||
{length: undefined, expected: undefined }, // should throw an exception
|
||||
{length: "omitted", expected: undefined }, // default value is null, so should throw
|
||||
],
|
||||
"PBKDF2": [
|
||||
{length: 256, expected: algorithms["PBKDF2"].derivation},
|
||||
{length: 0, expected: undefined}, // explicitly disallowed, so should throw
|
||||
{length: 384, expected: algorithms["PBKDF2"].derivation384},
|
||||
{length: 230, expected: undefined}, // should throw an exception, not multiple of 8
|
||||
{length: 0, expected: emptyArray},
|
||||
{length: null, expected: undefined }, // should throw an exception
|
||||
{length: undefined, expected: undefined }, // should throw an exception
|
||||
{length: "omitted", expected: undefined }, // default value is null, so should throw
|
||||
],
|
||||
"ECDH": [
|
||||
{length: 256, expected: algorithms["ECDH"].derivation},
|
||||
{length: 384, expected: undefined}, // should throw an exception, bigger than the output size
|
||||
{length: 230, expected: algorithms["ECDH"].derivation230},
|
||||
{length: 0, expected: emptyArray},
|
||||
{length: null, expected: algorithms["ECDH"].derivation},
|
||||
{length: undefined, expected: algorithms["ECDH"].derivation},
|
||||
@ -22,6 +28,8 @@ var testCases = {
|
||||
],
|
||||
"X25519": [
|
||||
{length: 256, expected: algorithms["X25519"].derivation},
|
||||
{length: 384, expected: undefined}, // should throw an exception, bigger than the output size
|
||||
{length: 230, expected: algorithms["X25519"].derivation230},
|
||||
{length: 0, expected: emptyArray},
|
||||
{length: null, expected: algorithms["X25519"].derivation},
|
||||
{length: undefined, expected: algorithms["X25519"].derivation},
|
||||
|
@ -9,12 +9,16 @@ var algorithms = {
|
||||
privateKey: {format: "raw", data: rawKey},
|
||||
deriveAlg: {name: "HKDF", salt: salt, hash: "SHA-256", info: info},
|
||||
derivation: new Uint8Array([49, 183, 214, 133, 48, 168, 99, 231, 23, 192, 129, 202, 105, 23, 182, 134, 80, 179, 221, 154, 41, 243, 6, 6, 226, 202, 209, 153, 190, 193, 77, 19]),
|
||||
derivation384: new Uint8Array([49, 183, 214, 133, 48, 168, 99, 231, 23, 192, 129, 202, 105, 23, 182, 134, 80, 179, 221, 154, 41, 243, 6, 6, 226, 202, 209, 153, 190, 193, 77, 19, 165, 50, 181, 8, 254, 59, 122, 199, 25, 224,146, 248, 105, 105, 75, 84]),
|
||||
derivation230: undefined,
|
||||
},
|
||||
"PBKDF2": {
|
||||
importAlg: {name: "PBKDF2"},
|
||||
privateKey: {format: "raw", data: rawKey},
|
||||
deriveAlg: {name: "PBKDF2", salt: salt, hash: "SHA-256", iterations: 100000},
|
||||
derivation: new Uint8Array([17, 153, 45, 139, 129, 51, 17, 36, 76, 84, 75, 98, 41, 41, 69, 226, 8, 212, 3, 206, 189, 107, 149, 82, 161, 165, 98, 6, 93, 153, 88, 234]),
|
||||
derivation384: new Uint8Array([17, 153, 45, 139, 129, 51, 17, 36, 76, 84, 75, 98, 41, 41, 69, 226, 8, 212, 3, 206, 189, 107, 149, 82, 161, 165, 98, 6, 93, 153, 88, 234, 39, 104, 8, 112, 222, 57, 166, 47, 102, 146, 195, 59, 219, 239, 238, 47]),
|
||||
derivation230: undefined,
|
||||
},
|
||||
"ECDH": {
|
||||
importAlg: {name: "ECDH", namedCurve: "P-256"},
|
||||
@ -22,6 +26,8 @@ var algorithms = {
|
||||
publicKey: {format: "spki", data: new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 154, 116, 32, 120, 126, 95, 77, 105, 211, 232, 34, 114, 115, 1, 109, 56, 224, 71, 129, 133, 223, 127, 238, 156, 142, 103, 60, 202, 211, 79, 126, 128, 254, 49, 141, 182, 221, 107, 119, 218, 99, 32, 165, 246, 151, 89, 9, 68, 23, 177, 52, 239, 138, 139, 116, 193, 101, 4, 57, 198, 115, 0, 90, 61])},
|
||||
deriveAlg: {name: "ECDH", public: new Uint8Array ([])},
|
||||
derivation: new Uint8Array([14, 143, 60, 77, 177, 178, 162, 131, 115, 90, 0, 220, 87, 31, 26, 232, 151, 28, 227, 35, 250, 17, 131, 137, 203, 95, 65, 196, 59, 61, 181, 161]),
|
||||
derivation384: undefined,
|
||||
derivation230: new Uint8Array([14, 143, 60, 77, 177, 178, 162, 131, 115, 90, 0, 220, 87, 31, 26, 232, 151, 28, 227, 35, 250, 17, 131, 137, 203, 95, 65, 196, 56]),
|
||||
},
|
||||
"X25519": {
|
||||
importAlg: {name: "X25519"},
|
||||
@ -29,5 +35,7 @@ var algorithms = {
|
||||
publicKey: {format: "spki", data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6])},
|
||||
deriveAlg: {name: "X25519", public: new Uint8Array ([])},
|
||||
derivation: new Uint8Array([39, 104, 64, 157, 250, 185, 158, 194, 59, 140, 137, 185, 63, 245, 136, 2, 149, 247, 97, 118, 8, 143, 137, 228, 61, 254, 190, 126, 161, 149, 0, 8]),
|
||||
derivation384: undefined,
|
||||
derivation230: new Uint8Array([39, 104, 64, 157, 250, 185, 158, 194, 59, 140, 137, 185, 63, 245, 136, 2, 149, 247, 97, 118, 8, 143, 137, 228, 61, 254, 190, 126, 160]),
|
||||
}
|
||||
};
|
||||
|
@ -45,13 +45,13 @@ function define_tests() {
|
||||
});
|
||||
}, testName);
|
||||
|
||||
// 0 length (OperationError)
|
||||
// 0 length
|
||||
subsetTest(promise_test, function(test) {
|
||||
return subtle.deriveBits(algorithm, baseKeys[derivedKeySize], 0)
|
||||
.then(function(derivation) {
|
||||
assert_equals(derivation.byteLength, 0, "Derived correctly empty key");
|
||||
}, function(err) {
|
||||
assert_equals(err.name, "OperationError", "deriveBits with 0 length correctly threw OperationError: " + err.message);
|
||||
assert_unreached("deriveBits failed with error " + err.name + ": " + err.message);
|
||||
});
|
||||
}, testName + " with 0 length");
|
||||
|
||||
|
@ -42,6 +42,16 @@ function define_tests() {
|
||||
});
|
||||
}, testName);
|
||||
|
||||
// 0 length
|
||||
subsetTest(promise_test, function(test) {
|
||||
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 0)
|
||||
.then(function(derivation) {
|
||||
assert_true(equalBuffers(derivation.byteLength, 0, "Derived correctly empty key"));
|
||||
}, function(err) {
|
||||
assert_unreached("deriveBits failed with error " + err.name + ": " + err.message);
|
||||
});
|
||||
}, testName + " with 0 length");
|
||||
|
||||
// Check for correct deriveKey results for every kind of
|
||||
// key that can be created by the deriveKeys operation.
|
||||
derivedKeyTypes.forEach(function(derivedKeyType) {
|
||||
@ -103,16 +113,6 @@ function define_tests() {
|
||||
|
||||
});
|
||||
|
||||
// 0 length (OperationError)
|
||||
subsetTest(promise_test, function(test) {
|
||||
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 0)
|
||||
.then(function(derivation) {
|
||||
assert_unreached("0 length should have thrown an OperationError");
|
||||
}, function(err) {
|
||||
assert_equals(err.name, "OperationError", "deriveBits with 0 length correctly threw OperationError: " + err.message);
|
||||
});
|
||||
}, testName + " with 0 length");
|
||||
|
||||
// length not multiple of 8 (OperationError)
|
||||
subsetTest(promise_test, function(test) {
|
||||
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 44)
|
||||
|
@ -5,7 +5,8 @@ function run_test(algorithmNames, slowTest) {
|
||||
setup({explicit_timeout: true});
|
||||
|
||||
// These tests check that generateKey successfully creates keys
|
||||
// when provided any of a wide set of correct parameters.
|
||||
// when provided any of a wide set of correct parameters
|
||||
// and that they can be exported afterwards.
|
||||
//
|
||||
// There are a lot of combinations of possible parameters,
|
||||
// resulting in a very large number of tests
|
||||
@ -68,9 +69,32 @@ function run_test(algorithmNames, slowTest) {
|
||||
} else {
|
||||
assert_goodCryptoKey(result, algorithm, extractable, usages, "secret");
|
||||
}
|
||||
return result;
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
assert_unreached("generateKey threw an unexpected error: " + err.toString());
|
||||
})
|
||||
.then(async function (result) {
|
||||
if (resultType === "CryptoKeyPair") {
|
||||
await Promise.all([
|
||||
subtle.exportKey('jwk', result.publicKey),
|
||||
subtle.exportKey('spki', result.publicKey),
|
||||
result.publicKey.algorithm.name.startsWith('RSA') ? undefined : subtle.exportKey('raw', result.publicKey),
|
||||
...(extractable ? [
|
||||
subtle.exportKey('jwk', result.privateKey),
|
||||
subtle.exportKey('pkcs8', result.privateKey),
|
||||
] : [])
|
||||
]);
|
||||
} else {
|
||||
if (extractable) {
|
||||
await Promise.all([
|
||||
subtle.exportKey('raw', result),
|
||||
subtle.exportKey('jwk', result),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}, function(err) {
|
||||
assert_unreached("exportKey threw an unexpected error: " + err.toString());
|
||||
})
|
||||
}, testTag + ": generateKey" + parameterString(algorithm, extractable, usages));
|
||||
}
|
||||
|
||||
|
10
test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey_failures_ECDH.https.any.js
vendored
Normal file
10
test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey_failures_ECDH.https.any.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// META: title=WebCryptoAPI: importKey() for Failures
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=ec_importKey_failures_fixtures.js
|
||||
// META: script=importKey_failures.js
|
||||
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
run_test(["ECDH"]);
|
10
test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey_failures_ECDSA.https.any.js
vendored
Normal file
10
test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey_failures_ECDSA.https.any.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// META: title=WebCryptoAPI: importKey() for Failures
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=ec_importKey_failures_fixtures.js
|
||||
// META: script=importKey_failures.js
|
||||
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
run_test(["ECDSA"]);
|
203
test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey_failures_fixtures.js
vendored
Normal file
203
test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey_failures_fixtures.js
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
function getValidKeyData(algorithm) {
|
||||
return validKeyData[algorithm.namedCurve];
|
||||
}
|
||||
|
||||
function getBadKeyLengthData(algorithm) {
|
||||
return badKeyLengthData[algorithm.namedCurve];
|
||||
}
|
||||
|
||||
function getMissingJWKFieldKeyData(algorithm) {
|
||||
// The curve doesn't affect when testing for missing JWK fields.
|
||||
return missingJWKFieldKeyData["P-521"];
|
||||
}
|
||||
|
||||
function getMismatchedJWKKeyData(algorithm) {
|
||||
// TODO: Implement test cases where the public key doesn't match the private key.
|
||||
return [];
|
||||
}
|
||||
|
||||
var validKeyData = {
|
||||
"P-521": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 129, 155, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 35, 3, 129, 134, 0, 4, 1, 86, 244, 121, 248, 223, 30, 32, 167, 255, 192, 76, 228, 32, 195, 225, 84, 174, 37, 25, 150, 190, 228, 47, 3, 75, 132, 212, 27, 116, 63, 52, 228, 95, 49, 27, 129, 58, 156, 222, 200, 205, 165, 155, 187, 189, 49, 212, 96, 179, 41, 37, 33, 231, 193, 183, 34, 229, 102, 124, 3, 219, 47, 174, 117, 63, 1, 80, 23, 54, 207, 226, 71, 57, 67, 32, 216, 228, 175, 194, 253, 57, 181, 169, 51, 16, 97, 184, 30, 34, 65, 40, 43, 158, 23, 137, 24, 34, 181, 183, 158, 5, 47, 69, 151, 181, 150, 67, 253, 57, 55, 156, 81, 189, 81, 37, 196, 244, 139, 195, 240, 37, 206, 60, 211, 105, 83, 40, 108, 203, 56, 251]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([4, 1, 86, 244, 121, 248, 223, 30, 32, 167, 255, 192, 76, 228, 32, 195, 225, 84, 174, 37, 25, 150, 190, 228, 47, 3, 75, 132, 212, 27, 116, 63, 52, 228, 95, 49, 27, 129, 58, 156, 222, 200, 205, 165, 155, 187, 189, 49, 212, 96, 179, 41, 37, 33, 231, 193, 183, 34, 229, 102, 124, 3, 219, 47, 174, 117, 63, 1, 80, 23, 54, 207, 226, 71, 57, 67, 32, 216, 228, 175, 194, 253, 57, 181, 169, 51, 16, 97, 184, 30, 34, 65, 40, 43, 158, 23, 137, 24, 34, 181, 183, 158, 5, 47, 69, 151, 181, 150, 67, 253, 57, 55, 156, 81, 189, 81, 37, 196, 244, 139, 195, 240, 37, 206, 60, 211, 105, 83, 40, 108, 203, 56, 251]),
|
||||
},
|
||||
{
|
||||
format:"pkcs8",
|
||||
data: new Uint8Array([48, 129, 238, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 35, 4, 129, 214, 48, 129, 211, 2, 1, 1, 4, 66, 0, 244, 8, 117, 131, 104, 186, 147, 15, 48, 247, 106, 224, 84, 254, 92, 210, 206, 127, 218, 44, 159, 118, 166, 212, 54, 207, 117, 214, 108, 68, 11, 254, 99, 49, 199, 193, 114, 161, 36, 120, 25, 60, 130, 81, 72, 123, 201, 18, 99, 250, 80, 33, 127, 133, 255, 99, 111, 89, 205, 84, 110, 58, 180, 131, 180, 161, 129, 137, 3, 129, 134, 0, 4, 1, 86, 244, 121, 248, 223, 30, 32, 167, 255, 192, 76, 228, 32, 195, 225, 84, 174, 37, 25, 150, 190, 228, 47, 3, 75, 132, 212, 27, 116, 63, 52, 228, 95, 49, 27, 129, 58, 156, 222, 200, 205, 165, 155, 187, 189, 49, 212, 96, 179, 41, 37, 33, 231, 193, 183, 34, 229, 102, 124, 3, 219, 47, 174, 117, 63, 1, 80, 23, 54, 207, 226, 71, 57, 67, 32, 216, 228, 175, 194, 253, 57, 181, 169, 51, 16, 97, 184, 30, 34, 65, 40, 43, 158, 23, 137, 24, 34, 181, 183, 158, 5, 47, 69, 151, 181, 150, 67, 253, 57, 55, 156, 81, 189, 81, 37, 196, 244, 139, 195, 240, 37, 206, 60, 211, 105, 83, 40, 108, 203, 56, 251]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-521",
|
||||
x: "AVb0efjfHiCn_8BM5CDD4VSuJRmWvuQvA0uE1Bt0PzTkXzEbgTqc3sjNpZu7vTHUYLMpJSHnwbci5WZ8A9svrnU_",
|
||||
y: "AVAXNs_iRzlDINjkr8L9ObWpMxBhuB4iQSgrnheJGCK1t54FL0WXtZZD_Tk3nFG9USXE9IvD8CXOPNNpUyhsyzj7",
|
||||
d: "APQIdYNoupMPMPdq4FT-XNLOf9osn3am1DbPddZsRAv-YzHHwXKhJHgZPIJRSHvJEmP6UCF_hf9jb1nNVG46tIO0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"P-256": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97, 232]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97, 232]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 19, 211, 58, 45, 90, 191, 156, 249, 235, 178, 31, 248, 96, 212, 174, 254, 110, 86, 231, 119, 144, 244, 222, 233, 180, 8, 132, 235, 211, 53, 68, 234, 161, 68, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97, 232]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-256",
|
||||
x: "0hCwpvnZ8BKGgFi0P6T0cQGFQ7ugDJJQ35JXwqyuXdE",
|
||||
y: "zgN1UtSBRQzjm00QlXAbF1v6s0uObAmeGPHBmDWDYeg",
|
||||
d: "E9M6LVq_nPnrsh_4YNSu_m5W53eQ9N7ptAiE69M1ROo"
|
||||
}
|
||||
},
|
||||
],
|
||||
"P-384": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 118, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 3, 98, 0, 4, 33, 156, 20, 214, 102, 23, 179, 110, 198, 216, 133, 107, 56, 91, 115, 167, 77, 52, 79, 216, 174, 117, 239, 4, 100, 53, 221, 165, 78, 59, 68, 189, 95, 189, 235, 209, 208, 141, 214, 158, 45, 125, 193, 220, 33, 140, 180, 53, 189, 40, 19, 140, 199, 120, 51, 122, 132, 47, 107, 214, 27, 36, 14, 116, 36, 159, 36, 102, 124, 42, 88, 16, 167, 107, 252, 40, 224, 51, 95, 136, 166, 80, 29, 236, 1, 151, 109, 168, 90, 251, 0, 134, 156, 182, 172, 232]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([4, 33, 156, 20, 214, 102, 23, 179, 110, 198, 216, 133, 107, 56, 91, 115, 167, 77, 52, 79, 216, 174, 117, 239, 4, 100, 53, 221, 165, 78, 59, 68, 189, 95, 189, 235, 209, 208, 141, 214, 158, 45, 125, 193, 220, 33, 140, 180, 53, 189, 40, 19, 140, 199, 120, 51, 122, 132, 47, 107, 214, 27, 36, 14, 116, 36, 159, 36, 102, 124, 42, 88, 16, 167, 107, 252, 40, 224, 51, 95, 136, 166, 80, 29, 236, 1, 151, 109, 168, 90, 251, 0, 134, 156, 182, 172, 232]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 129, 182, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 4, 129, 158, 48, 129, 155, 2, 1, 1, 4, 48, 69, 55, 181, 153, 7, 132, 211, 194, 210, 46, 150, 168, 249, 47, 161, 170, 73, 46, 232, 115, 229, 118, 164, 21, 130, 225, 68, 24, 60, 152, 136, 209, 14, 107, 158, 180, 206, 212, 178, 204, 64, 18, 228, 172, 94, 168, 64, 115, 161, 100, 3, 98, 0, 4, 33, 156, 20, 214, 102, 23, 179, 110, 198, 216, 133, 107, 56, 91, 115, 167, 77, 52, 79, 216, 174, 117, 239, 4, 100, 53, 221, 165, 78, 59, 68, 189, 95, 189, 235, 209, 208, 141, 214, 158, 45, 125, 193, 220, 33, 140, 180, 53, 189, 40, 19, 140, 199, 120, 51, 122, 132, 47, 107, 214, 27, 36, 14, 116, 36, 159, 36, 102, 124, 42, 88, 16, 167, 107, 252, 40, 224, 51, 95, 136, 166, 80, 29, 236, 1, 151, 109, 168, 90, 251, 0, 134, 156, 182, 172, 232]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-384",
|
||||
x: "IZwU1mYXs27G2IVrOFtzp000T9iude8EZDXdpU47RL1fvevR0I3Wni19wdwhjLQ1",
|
||||
y: "vSgTjMd4M3qEL2vWGyQOdCSfJGZ8KlgQp2v8KOAzX4imUB3sAZdtqFr7AIactqzo",
|
||||
d: "RTe1mQeE08LSLpao-S-hqkku6HPldqQVguFEGDyYiNEOa560ztSyzEAS5KxeqEBz"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// Removed just the last byte.
|
||||
var badKeyLengthData = {
|
||||
"P-521": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 129, 155, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 35, 3, 129, 134, 0, 4, 1, 86, 244, 121, 248, 223, 30, 32, 167, 255, 192, 76, 228, 32, 195, 225, 84, 174, 37, 25, 150, 190, 228, 47, 3, 75, 132, 212, 27, 116, 63, 52, 228, 95, 49, 27, 129, 58, 156, 222, 200, 205, 165, 155, 187, 189, 49, 212, 96, 179, 41, 37, 33, 231, 193, 183, 34, 229, 102, 124, 3, 219, 47, 174, 117, 63, 1, 80, 23, 54, 207, 226, 71, 57, 67, 32, 216, 228, 175, 194, 253, 57, 181, 169, 51, 16, 97, 184, 30, 34, 65, 40, 43, 158, 23, 137, 24, 34, 181, 183, 158, 5, 47, 69, 151, 181, 150, 67, 253, 57, 55, 156, 81, 189, 81, 37, 196, 244, 139, 195, 240, 37, 206, 60, 211, 105, 83, 40, 108, 203, 56]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([4, 1, 86, 244, 121, 248, 223, 30, 32, 167, 255, 192, 76, 228, 32, 195, 225, 84, 174, 37, 25, 150, 190, 228, 47, 3, 75, 132, 212, 27, 116, 63, 52, 228, 95, 49, 27, 129, 58, 156, 222, 200, 205, 165, 155, 187, 189, 49, 212, 96, 179, 41, 37, 33, 231, 193, 183, 34, 229, 102, 124, 3, 219, 47, 174, 117, 63, 1, 80, 23, 54, 207, 226, 71, 57, 67, 32, 216, 228, 175, 194, 253, 57, 181, 169, 51, 16, 97, 184, 30, 34, 65, 40, 43, 158, 23, 137, 24, 34, 181, 183, 158, 5, 47, 69, 151, 181, 150, 67, 253, 57, 55, 156, 81, 189, 81, 37, 196, 244, 139, 195, 240, 37, 206, 60, 211, 105, 83, 40, 108, 203, 56]),
|
||||
},
|
||||
{
|
||||
format:"pkcs8",
|
||||
data: new Uint8Array([48, 129, 238, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 35, 4, 129, 214, 48, 129, 211, 2, 1, 1, 4, 66, 0, 244, 8, 117, 131, 104, 186, 147, 15, 48, 247, 106, 224, 84, 254, 92, 210, 206, 127, 218, 44, 159, 118, 166, 212, 54, 207, 117, 214, 108, 68, 11, 254, 99, 49, 199, 193, 114, 161, 36, 120, 25, 60, 130, 81, 72, 123, 201, 18, 99, 250, 80, 33, 127, 133, 255, 99, 111, 89, 205, 84, 110, 58, 180, 131, 180, 161, 129, 137, 3, 129, 134, 0, 4, 1, 86, 244, 121, 248, 223, 30, 32, 167, 255, 192, 76, 228, 32, 195, 225, 84, 174, 37, 25, 150, 190, 228, 47, 3, 75, 132, 212, 27, 116, 63, 52, 228, 95, 49, 27, 129, 58, 156, 222, 200, 205, 165, 155, 187, 189, 49, 212, 96, 179, 41, 37, 33, 231, 193, 183, 34, 229, 102, 124, 3, 219, 47, 174, 117, 63, 1, 80, 23, 54, 207, 226, 71, 57, 67, 32, 216, 228, 175, 194, 253, 57, 181, 169, 51, 16, 97, 184, 30, 34, 65, 40, 43, 158, 23, 137, 24, 34, 181, 183, 158, 5, 47, 69, 151, 181, 150, 67, 253, 57, 55, 156, 81, 189, 81, 37, 196, 244, 139, 195, 240, 37, 206, 60, 211, 105, 83, 40, 108, 203, 56]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-521",
|
||||
x: "AVb0efjfHiCn_8BM5CDD4VSuJRmWvuQvA0uE1Bt0PzTkXzEbgTqc3sjNpZu7vTHUYLMpJSHnwbci5WZ8A9svrnU",
|
||||
y: "AVAXNs_iRzlDINjkr8L9ObWpMxBhuB4iQSgrnheJGCK1t54FL0WXtZZD_Tk3nFG9USXE9IvD8CXOPNNpUyhsyzj7",
|
||||
d: "APQIdYNoupMPMPdq4FT-XNLOf9osn3am1DbPddZsRAv-YzHHwXKhJHgZPIJRSHvJEmP6UCF_hf9jb1nNVG46tIO0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"P-256": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 19, 211, 58, 45, 90, 191, 156, 249, 235, 178, 31, 248, 96, 212, 174, 254, 110, 86, 231, 119, 144, 244, 222, 233, 180, 8, 132, 235, 211, 53, 68, 234, 161, 68, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-256",
|
||||
x: "0hCwpvnZ8BKGgFi0P6T0cQGFQ7ugDJJQ35JXwqyuXd",
|
||||
y: "zgN1UtSBRQzjm00QlXAbF1v6s0uObAmeGPHBmDWDYeg",
|
||||
d: "E9M6LVq_nPnrsh_4YNSu_m5W53eQ9N7ptAiE69M1ROo"
|
||||
}
|
||||
},
|
||||
],
|
||||
"P-384": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 118, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 3, 98, 0, 4, 33, 156, 20, 214, 102, 23, 179, 110, 198, 216, 133, 107, 56, 91, 115, 167, 77, 52, 79, 216, 174, 117, 239, 4, 100, 53, 221, 165, 78, 59, 68, 189, 95, 189, 235, 209, 208, 141, 214, 158, 45, 125, 193, 220, 33, 140, 180, 53, 189, 40, 19, 140, 199, 120, 51, 122, 132, 47, 107, 214, 27, 36, 14, 116, 36, 159, 36, 102, 124, 42, 88, 16, 167, 107, 252, 40, 224, 51, 95, 136, 166, 80, 29, 236, 1, 151, 109, 168, 90, 251, 0, 134, 156, 182, 172]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([4, 33, 156, 20, 214, 102, 23, 179, 110, 198, 216, 133, 107, 56, 91, 115, 167, 77, 52, 79, 216, 174, 117, 239, 4, 100, 53, 221, 165, 78, 59, 68, 189, 95, 189, 235, 209, 208, 141, 214, 158, 45, 125, 193, 220, 33, 140, 180, 53, 189, 40, 19, 140, 199, 120, 51, 122, 132, 47, 107, 214, 27, 36, 14, 116, 36, 159, 36, 102, 124, 42, 88, 16, 167, 107, 252, 40, 224, 51, 95, 136, 166, 80, 29, 236, 1, 151, 109, 168, 90, 251, 0, 134, 156, 182, 172]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 129, 182, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 4, 129, 158, 48, 129, 155, 2, 1, 1, 4, 48, 69, 55, 181, 153, 7, 132, 211, 194, 210, 46, 150, 168, 249, 47, 161, 170, 73, 46, 232, 115, 229, 118, 164, 21, 130, 225, 68, 24, 60, 152, 136, 209, 14, 107, 158, 180, 206, 212, 178, 204, 64, 18, 228, 172, 94, 168, 64, 115, 161, 100, 3, 98, 0, 4, 33, 156, 20, 214, 102, 23, 179, 110, 198, 216, 133, 107, 56, 91, 115, 167, 77, 52, 79, 216, 174, 117, 239, 4, 100, 53, 221, 165, 78, 59, 68, 189, 95, 189, 235, 209, 208, 141, 214, 158, 45, 125, 193, 220, 33, 140, 180, 53, 189, 40, 19, 140, 199, 120, 51, 122, 132, 47, 107, 214, 27, 36, 14, 116, 36, 159, 36, 102, 124, 42, 88, 16, 167, 107, 252, 40, 224, 51, 95, 136, 166, 80, 29, 236, 1, 151, 109, 168, 90, 251, 0, 134, 156, 182, 172]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-384",
|
||||
x: "IZwU1mYXs27G2IVrOFtzp000T9iude8EZDXdpU47RL1fvevR0I3Wni19wdwhjLQ",
|
||||
y: "vSgTjMd4M3qEL2vWGyQOdCSfJGZ8KlgQp2v8KOAzX4imUB3sAZdtqFr7AIactqzo",
|
||||
d: "RTe1mQeE08LSLpao-S-hqkku6HPldqQVguFEGDyYiNEOa560ztSyzEAS5KxeqEBz"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var missingJWKFieldKeyData = {
|
||||
"P-521": [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
kty: "EC",
|
||||
crv: "P-521",
|
||||
y: "AVAXNs_iRzlDINjkr8L9ObWpMxBhuB4iQSgrnheJGCK1t54FL0WXtZZD_Tk3nFG9USXE9IvD8CXOPNNpUyhsyzj7",
|
||||
d: "APQIdYNoupMPMPdq4FT-XNLOf9osn3am1DbPddZsRAv-YzHHwXKhJHgZPIJRSHvJEmP6UCF_hf9jb1nNVG46tIO0"
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "P-521",
|
||||
x: "AVb0efjfHiCn_8BM5CDD4VSuJRmWvuQvA0uE1Bt0PzTkXzEbgTqc3sjNpZu7vTHUYLMpJSHnwbci5WZ8A9svrnU_",
|
||||
y: "AVAXNs_iRzlDINjkr8L9ObWpMxBhuB4iQSgrnheJGCK1t54FL0WXtZZD_Tk3nFG9USXE9IvD8CXOPNNpUyhsyzj7",
|
||||
d: "APQIdYNoupMPMPdq4FT-XNLOf9osn3am1DbPddZsRAv-YzHHwXKhJHgZPIJRSHvJEmP6UCF_hf9jb1nNVG46tIO0"
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
kty: "EC",
|
||||
x: "AVb0efjfHiCn_8BM5CDD4VSuJRmWvuQvA0uE1Bt0PzTkXzEbgTqc3sjNpZu7vTHUYLMpJSHnwbci5WZ8A9svrnU_",
|
||||
y: "AVAXNs_iRzlDINjkr8L9ObWpMxBhuB4iQSgrnheJGCK1t54FL0WXtZZD_Tk3nFG9USXE9IvD8CXOPNNpUyhsyzj7",
|
||||
d: "APQIdYNoupMPMPdq4FT-XNLOf9osn3am1DbPddZsRAv-YzHHwXKhJHgZPIJRSHvJEmP6UCF_hf9jb1nNVG46tIO0"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
@ -20,8 +20,10 @@ function run_test(algorithmNames) {
|
||||
var allTestVectors = [ // Parameters that should work for importKey / exportKey
|
||||
{name: "Ed25519", privateUsages: ["sign"], publicUsages: ["verify"]},
|
||||
{name: "Ed448", privateUsages: ["sign"], publicUsages: ["verify"]},
|
||||
{name: "ECDSA", privateUsages: ["sign"], publicUsages: ["verify"]},
|
||||
{name: "X25519", privateUsages: ["deriveKey", "deriveBits"], publicUsages: []},
|
||||
{name: "X448", privateUsages: ["deriveKey", "deriveBits"], publicUsages: []},
|
||||
{name: "ECDH", privateUsages: ["deriveKey", "deriveBits"], publicUsages: []}
|
||||
];
|
||||
|
||||
var testVectors = [];
|
||||
@ -109,6 +111,10 @@ function run_test(algorithmNames) {
|
||||
return [];
|
||||
}
|
||||
|
||||
function isPrivateKey(data) {
|
||||
return data.d !== undefined;
|
||||
}
|
||||
|
||||
// Now test for properly handling errors
|
||||
// - Unsupported algorithm
|
||||
// - Bad usages for algorithm
|
||||
@ -121,8 +127,8 @@ function run_test(algorithmNames) {
|
||||
// due to SyntaxError
|
||||
testVectors.forEach(function(vector) {
|
||||
var name = vector.name;
|
||||
validKeyData.forEach(function(test) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
getValidKeyData(algorithm).forEach(function(test) {
|
||||
invalidUsages(validUsages(vector, test.format, test.data)).forEach(function(usages) {
|
||||
[true, false].forEach(function(extractable) {
|
||||
testError(test.format, algorithm, test.data, name, usages, extractable, "SyntaxError", "Bad usages");
|
||||
@ -136,8 +142,8 @@ function run_test(algorithmNames) {
|
||||
// Should fail due to SyntaxError
|
||||
testVectors.forEach(function(vector) {
|
||||
var name = vector.name;
|
||||
validKeyData.filter((test) => test.format === 'pkcs8' || (test.format === 'jwk' && test.data.d)).forEach(function(test) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
getValidKeyData(algorithm).filter((test) => test.format === 'pkcs8' || (test.format === 'jwk' && isPrivateKey(test.data))).forEach(function(test) {
|
||||
[true, false].forEach(function(extractable) {
|
||||
testError(test.format, algorithm, test.data, name, [/* Empty usages */], extractable, "SyntaxError", "Empty usages");
|
||||
});
|
||||
@ -145,11 +151,11 @@ function run_test(algorithmNames) {
|
||||
});
|
||||
});
|
||||
|
||||
// Algorithms normalize okay, usages ok. The length of the key must thouw a DataError exception.
|
||||
// Algorithms normalize okay, usages ok. The length of the key must throw a DataError exception.
|
||||
testVectors.forEach(function(vector) {
|
||||
var name = vector.name;
|
||||
badKeyLengthData.forEach(function(test) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
getBadKeyLengthData(algorithm).forEach(function(test) {
|
||||
allValidUsages(validUsages(vector, test.format, test.data)).forEach(function(usages) {
|
||||
[true, false].forEach(function(extractable) {
|
||||
testError(test.format, algorithm, test.data, name, usages, extractable, "DataError", "Bad key length");
|
||||
@ -159,11 +165,11 @@ function run_test(algorithmNames) {
|
||||
});
|
||||
});
|
||||
|
||||
// Algorithms normalize okay, usages ok and valid key. The lack of the mandatory JWK parameter must throw a syntax error.
|
||||
// Algorithms normalize okay, usages ok and valid key. The lack of the mandatory JWK parameter must throw a DataError exception.
|
||||
testVectors.forEach(function(vector) {
|
||||
var name = vector.name;
|
||||
missingJWKFieldKeyData.forEach(function(test) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
getMissingJWKFieldKeyData(algorithm).forEach(function(test) {
|
||||
allValidUsages(validUsages(vector, 'jwk', test.data)).forEach(function(usages) {
|
||||
[true, false].forEach(function(extractable) {
|
||||
testError('jwk', algorithm, test.data, name, usages, extractable, "DataError", "Missing JWK '" + test.param + "' parameter");
|
||||
@ -176,8 +182,8 @@ function run_test(algorithmNames) {
|
||||
// Algorithms normalize okay, usages ok and valid key. The public key is not compatible with the private key.
|
||||
testVectors.forEach(function(vector) {
|
||||
var name = vector.name;
|
||||
invalidJWKKeyData.forEach(function(data) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
|
||||
getMismatchedJWKKeyData(algorithm).forEach(function(data) {
|
||||
allValidUsages(vector.privateUsages).forEach(function(usages) {
|
||||
[true].forEach(function(extractable) {
|
||||
testError('jwk', algorithm, data, name, usages, extractable, "DataError", "Invalid key pair");
|
@ -1,280 +0,0 @@
|
||||
// META: title=WebCryptoAPI: importKey() for OKP keys
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
|
||||
// Test importKey and exportKey for OKP algorithms. Only "happy paths" are
|
||||
// currently tested - those where the operation should succeed.
|
||||
|
||||
var subtle = crypto.subtle;
|
||||
|
||||
var keyData = {
|
||||
"Ed25519": {
|
||||
spki: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0, 216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204]),
|
||||
raw: new Uint8Array([216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204]),
|
||||
pkcs8: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168, 31]),
|
||||
jwk: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
"Ed448": {
|
||||
spki: new Uint8Array([48, 67, 48, 5, 6, 3, 43, 101, 113, 3, 58, 0, 171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
raw: new Uint8Array([171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
pkcs8: new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29, 46]),
|
||||
jwk: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
"X25519": {
|
||||
spki: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
raw: new Uint8Array([28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
pkcs8: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 200, 131, 142, 118, 208, 87, 223, 183, 216, 201, 90, 105, 225, 56, 22, 10, 221, 99, 115, 253, 113, 164, 210, 118, 187, 86, 227, 168, 27, 100, 255, 97]),
|
||||
jwk: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
"X448": {
|
||||
spki: new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
raw: new Uint8Array([182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
pkcs8: new Uint8Array([48, 70, 2, 1, 0, 48, 5, 6, 3, 43, 101, 111, 4, 58, 4, 56, 88, 199, 210, 154, 62, 181, 25, 178, 157, 0, 207, 177, 145, 187, 100, 252, 109, 138, 66, 216, 241, 113, 118, 39, 43, 137, 242, 39, 45, 24, 25, 41, 92, 101, 37, 192, 130, 150, 113, 176, 82, 239, 7, 39, 83, 15, 24, 142, 49, 208, 204, 83, 191, 38, 146, 158]),
|
||||
jwk: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// combinations to test
|
||||
var testVectors = [
|
||||
{name: "Ed25519", privateUsages: ["sign"], publicUsages: ["verify"]},
|
||||
{name: "Ed448", privateUsages: ["sign"], publicUsages: ["verify"]},
|
||||
{name: "X25519", privateUsages: ["deriveKey", "deriveBits"], publicUsages: []},
|
||||
{name: "X448", privateUsages: ["deriveKey", "deriveBits"], publicUsages: []},
|
||||
];
|
||||
|
||||
// TESTS ARE HERE:
|
||||
// Test every test vector, along with all available key data
|
||||
testVectors.forEach(function(vector) {
|
||||
[true, false].forEach(function(extractable) {
|
||||
|
||||
// Test public keys first
|
||||
allValidUsages(vector.publicUsages, true).forEach(function(usages) {
|
||||
['spki', 'jwk', 'raw'].forEach(function(format) {
|
||||
var algorithm = {name: vector.name};
|
||||
var data = keyData[vector.name];
|
||||
if (format === "jwk") { // Not all fields used for public keys
|
||||
data = {jwk: {kty: keyData[vector.name].jwk.kty, crv: keyData[vector.name].jwk.crv, x: keyData[vector.name].jwk.x}};
|
||||
}
|
||||
|
||||
testFormat(format, algorithm, data, vector.name, usages, extractable);
|
||||
|
||||
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
|
||||
if (format === "jwk" && extractable) {
|
||||
testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Next, test private keys
|
||||
allValidUsages(vector.privateUsages).forEach(function(usages) {
|
||||
['pkcs8', 'jwk'].forEach(function(format) {
|
||||
var algorithm = {name: vector.name};
|
||||
var data = keyData[vector.name];
|
||||
|
||||
testFormat(format, algorithm, data, vector.name, usages, extractable);
|
||||
|
||||
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
|
||||
if (format === "jwk" && extractable) {
|
||||
testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Test importKey with a given key format and other parameters. If
|
||||
// extrable is true, export the key and verify that it matches the input.
|
||||
function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
|
||||
promise_test(function(test) {
|
||||
return subtle.importKey(format, keyData[format], algorithm, extractable, usages).
|
||||
then(function(key) {
|
||||
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
|
||||
assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData[format].d)) ? 'private' : 'public');
|
||||
if (!extractable) {
|
||||
return;
|
||||
}
|
||||
|
||||
return subtle.exportKey(format, key).
|
||||
then(function(result) {
|
||||
if (format !== "jwk") {
|
||||
assert_true(equalBuffers(keyData[format], result), "Round trip works");
|
||||
} else {
|
||||
assert_true(equalJwk(keyData[format], result), "Round trip works");
|
||||
}
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], algorithm, extractable, usages));
|
||||
}
|
||||
|
||||
// Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export
|
||||
// https://github.com/WICG/webcrypto-secure-curves/pull/24
|
||||
function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {
|
||||
promise_test(function(test) {
|
||||
return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, algorithm, true, usages).
|
||||
then(function(key) {
|
||||
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
|
||||
|
||||
return subtle.exportKey('jwk', key).
|
||||
then(function(result) {
|
||||
assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");
|
||||
assert_equals(result.alg, undefined, 'No JWK "alg" member is present');
|
||||
assert_true(equalJwk(keyData, result), "Round trip works");
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, algorithm, true, usages));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Helper methods follow:
|
||||
|
||||
// Are two array buffers the same?
|
||||
function equalBuffers(a, b) {
|
||||
if (a.byteLength !== b.byteLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var aBytes = new Uint8Array(a);
|
||||
var bBytes = new Uint8Array(b);
|
||||
|
||||
for (var i=0; i<a.byteLength; i++) {
|
||||
if (aBytes[i] !== bBytes[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Are two Jwk objects "the same"? That is, does the object returned include
|
||||
// matching values for each property that was expected? It's okay if the
|
||||
// returned object has extra methods; they aren't checked.
|
||||
function equalJwk(expected, got) {
|
||||
var fields = Object.keys(expected);
|
||||
var fieldName;
|
||||
|
||||
for(var i=0; i<fields.length; i++) {
|
||||
fieldName = fields[i];
|
||||
if (!(fieldName in got)) {
|
||||
return false;
|
||||
}
|
||||
if (expected[fieldName] !== got[fieldName]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Build minimal Jwk objects from raw key data and algorithm specifications
|
||||
function jwkData(keyData, algorithm) {
|
||||
var result = {
|
||||
kty: "oct",
|
||||
k: byteArrayToUnpaddedBase64(keyData)
|
||||
};
|
||||
|
||||
if (algorithm.name.substring(0, 3) === "AES") {
|
||||
result.alg = "A" + (8 * keyData.byteLength).toString() + algorithm.name.substring(4);
|
||||
} else if (algorithm.name === "HMAC") {
|
||||
result.alg = "HS" + algorithm.hash.substring(4);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Jwk format wants Base 64 without the typical padding at the end.
|
||||
function byteArrayToUnpaddedBase64(byteArray){
|
||||
var binaryString = "";
|
||||
for (var i=0; i<byteArray.byteLength; i++){
|
||||
binaryString += String.fromCharCode(byteArray[i]);
|
||||
}
|
||||
var base64String = btoa(binaryString);
|
||||
|
||||
return base64String.replace(/=/g, "");
|
||||
}
|
||||
|
||||
// Convert method parameters to a string to uniquely name each test
|
||||
function parameterString(format, data, algorithm, extractable, usages) {
|
||||
if ("byteLength" in data) {
|
||||
data = "buffer(" + data.byteLength.toString() + ")";
|
||||
} else {
|
||||
data = "object(" + Object.keys(data).join(", ") + ")";
|
||||
}
|
||||
var result = "(" +
|
||||
objectToString(format) + ", " +
|
||||
objectToString(data) + ", " +
|
||||
objectToString(algorithm) + ", " +
|
||||
objectToString(extractable) + ", " +
|
||||
objectToString(usages) +
|
||||
")";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Character representation of any object we may use as a parameter.
|
||||
function objectToString(obj) {
|
||||
var keyValuePairs = [];
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return "[" + obj.map(function(elem){return objectToString(elem);}).join(", ") + "]";
|
||||
} else if (typeof obj === "object") {
|
||||
Object.keys(obj).sort().forEach(function(keyName) {
|
||||
keyValuePairs.push(keyName + ": " + objectToString(obj[keyName]));
|
||||
});
|
||||
return "{" + keyValuePairs.join(", ") + "}";
|
||||
} else if (typeof obj === "undefined") {
|
||||
return "undefined";
|
||||
} else {
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
var keyValuePairs = [];
|
||||
|
||||
Object.keys(obj).sort().forEach(function(keyName) {
|
||||
var value = obj[keyName];
|
||||
if (typeof value === "object") {
|
||||
value = objectToString(value);
|
||||
} else if (typeof value === "array") {
|
||||
value = "[" + value.map(function(elem){return objectToString(elem);}).join(", ") + "]";
|
||||
} else {
|
||||
value = value.toString();
|
||||
}
|
||||
|
||||
keyValuePairs.push(keyName + ": " + value);
|
||||
});
|
||||
|
||||
return "{" + keyValuePairs.join(", ") + "}";
|
||||
}
|
213
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.js
vendored
Normal file
213
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.js
vendored
Normal file
@ -0,0 +1,213 @@
|
||||
var subtle = crypto.subtle;
|
||||
|
||||
function runTests(algorithmName) {
|
||||
var algorithm = {name: algorithmName};
|
||||
var data = keyData[algorithmName];
|
||||
var jwkData = {jwk: {kty: data.jwk.kty, crv: data.jwk.crv, x: data.jwk.x}};
|
||||
|
||||
[true, false].forEach(function(extractable) {
|
||||
// Test public keys first
|
||||
allValidUsages(data.publicUsages, true).forEach(function(usages) {
|
||||
['spki', 'jwk', 'raw'].forEach(function(format) {
|
||||
if (format === "jwk") { // Not all fields used for public keys
|
||||
testFormat(format, algorithm, jwkData, algorithmName, usages, extractable);
|
||||
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
|
||||
if (extractable) {
|
||||
testJwkAlgBehaviours(algorithm, jwkData.jwk, algorithmName, usages);
|
||||
}
|
||||
} else {
|
||||
testFormat(format, algorithm, data, algorithmName, usages, extractable);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Next, test private keys
|
||||
allValidUsages(data.privateUsages).forEach(function(usages) {
|
||||
['pkcs8', 'jwk'].forEach(function(format) {
|
||||
testFormat(format, algorithm, data, algorithmName, usages, extractable);
|
||||
|
||||
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
|
||||
if (format === "jwk" && extractable) {
|
||||
testJwkAlgBehaviours(algorithm, data.jwk, algorithmName, usages);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Test importKey with a given key format and other parameters. If
|
||||
// extrable is true, export the key and verify that it matches the input.
|
||||
function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
|
||||
[algorithm, algorithm.name].forEach((alg) => {
|
||||
promise_test(function(test) {
|
||||
return subtle.importKey(format, keyData[format], alg, extractable, usages).
|
||||
then(function(key) {
|
||||
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
|
||||
assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData[format].d)) ? 'private' : 'public');
|
||||
if (!extractable) {
|
||||
return;
|
||||
}
|
||||
|
||||
return subtle.exportKey(format, key).
|
||||
then(function(result) {
|
||||
if (format !== "jwk") {
|
||||
assert_true(equalBuffers(keyData[format], result), "Round trip works");
|
||||
} else {
|
||||
assert_true(equalJwk(keyData[format], result), "Round trip works");
|
||||
}
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], alg, extractable, usages));
|
||||
});
|
||||
}
|
||||
|
||||
// Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export
|
||||
// https://github.com/WICG/webcrypto-secure-curves/pull/24
|
||||
function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {
|
||||
[algorithm, algorithm.name].forEach((alg) => {
|
||||
promise_test(function(test) {
|
||||
return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, alg, true, usages).
|
||||
then(function(key) {
|
||||
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
|
||||
|
||||
return subtle.exportKey('jwk', key).
|
||||
then(function(result) {
|
||||
assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");
|
||||
assert_equals(result.alg, undefined, 'No JWK "alg" member is present');
|
||||
assert_true(equalJwk(keyData, result), "Round trip works");
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, function(err) {
|
||||
assert_unreached("Threw an unexpected error: " + err.toString());
|
||||
});
|
||||
}, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, alg, true, usages));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Helper methods follow:
|
||||
|
||||
// Are two array buffers the same?
|
||||
function equalBuffers(a, b) {
|
||||
if (a.byteLength !== b.byteLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var aBytes = new Uint8Array(a);
|
||||
var bBytes = new Uint8Array(b);
|
||||
|
||||
for (var i=0; i<a.byteLength; i++) {
|
||||
if (aBytes[i] !== bBytes[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Are two Jwk objects "the same"? That is, does the object returned include
|
||||
// matching values for each property that was expected? It's okay if the
|
||||
// returned object has extra methods; they aren't checked.
|
||||
function equalJwk(expected, got) {
|
||||
var fields = Object.keys(expected);
|
||||
var fieldName;
|
||||
|
||||
for(var i=0; i<fields.length; i++) {
|
||||
fieldName = fields[i];
|
||||
if (!(fieldName in got)) {
|
||||
return false;
|
||||
}
|
||||
if (expected[fieldName] !== got[fieldName]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Build minimal Jwk objects from raw key data and algorithm specifications
|
||||
function jwkData(keyData, algorithm) {
|
||||
var result = {
|
||||
kty: "oct",
|
||||
k: byteArrayToUnpaddedBase64(keyData)
|
||||
};
|
||||
|
||||
if (algorithm.name.substring(0, 3) === "AES") {
|
||||
result.alg = "A" + (8 * keyData.byteLength).toString() + algorithm.name.substring(4);
|
||||
} else if (algorithm.name === "HMAC") {
|
||||
result.alg = "HS" + algorithm.hash.substring(4);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Jwk format wants Base 64 without the typical padding at the end.
|
||||
function byteArrayToUnpaddedBase64(byteArray){
|
||||
var binaryString = "";
|
||||
for (var i=0; i<byteArray.byteLength; i++){
|
||||
binaryString += String.fromCharCode(byteArray[i]);
|
||||
}
|
||||
var base64String = btoa(binaryString);
|
||||
|
||||
return base64String.replace(/=/g, "");
|
||||
}
|
||||
|
||||
// Convert method parameters to a string to uniquely name each test
|
||||
function parameterString(format, data, algorithm, extractable, usages) {
|
||||
if ("byteLength" in data) {
|
||||
data = "buffer(" + data.byteLength.toString() + ")";
|
||||
} else {
|
||||
data = "object(" + Object.keys(data).join(", ") + ")";
|
||||
}
|
||||
var result = "(" +
|
||||
objectToString(format) + ", " +
|
||||
objectToString(data) + ", " +
|
||||
objectToString(algorithm) + ", " +
|
||||
objectToString(extractable) + ", " +
|
||||
objectToString(usages) +
|
||||
")";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Character representation of any object we may use as a parameter.
|
||||
function objectToString(obj) {
|
||||
var keyValuePairs = [];
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return "[" + obj.map(function(elem){return objectToString(elem);}).join(", ") + "]";
|
||||
} else if (typeof obj === "object") {
|
||||
Object.keys(obj).sort().forEach(function(keyName) {
|
||||
keyValuePairs.push(keyName + ": " + objectToString(obj[keyName]));
|
||||
});
|
||||
return "{" + keyValuePairs.join(", ") + "}";
|
||||
} else if (typeof obj === "undefined") {
|
||||
return "undefined";
|
||||
} else {
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
var keyValuePairs = [];
|
||||
|
||||
Object.keys(obj).sort().forEach(function(keyName) {
|
||||
var value = obj[keyName];
|
||||
if (typeof value === "object") {
|
||||
value = objectToString(value);
|
||||
} else if (typeof value === "array") {
|
||||
value = "[" + value.map(function(elem){return objectToString(elem);}).join(", ") + "]";
|
||||
} else {
|
||||
value = value.toString();
|
||||
}
|
||||
|
||||
keyValuePairs.push(keyName + ": " + value);
|
||||
});
|
||||
|
||||
return "{" + keyValuePairs.join(", ") + "}";
|
||||
}
|
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_Ed25519.https.any.js
vendored
Normal file
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_Ed25519.https.any.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// META: title=WebCryptoAPI: importKey() for OKP keys
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_fixtures.js
|
||||
// META: script=okp_importKey.js
|
||||
|
||||
|
||||
// Test importKey and exportKey for OKP algorithms.
|
||||
runTests("Ed25519");
|
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_Ed448.https.any.js
vendored
Normal file
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_Ed448.https.any.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// META: title=WebCryptoAPI: importKey() for OKP keys
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_fixtures.js
|
||||
// META: script=okp_importKey.js
|
||||
|
||||
|
||||
// Test importKey and exportKey for OKP algorithms.
|
||||
runTests("Ed448");
|
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_X25519.https.any.js
vendored
Normal file
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_X25519.https.any.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// META: title=WebCryptoAPI: importKey() for OKP keys
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_fixtures.js
|
||||
// META: script=okp_importKey.js
|
||||
|
||||
|
||||
// Test importKey and exportKey for OKP algorithms.
|
||||
runTests("X25519");
|
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_X448.https.any.js
vendored
Normal file
9
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_X448.https.any.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// META: title=WebCryptoAPI: importKey() for OKP keys
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_fixtures.js
|
||||
// META: script=okp_importKey.js
|
||||
|
||||
|
||||
// Test importKey and exportKey for OKP algorithms.
|
||||
runTests("X448");
|
@ -1,110 +1,7 @@
|
||||
// META: title=WebCryptoAPI: importKey() for Failures
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_failures.js
|
||||
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
var validKeyData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0, 216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204])
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168, 31])
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204])
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Removed just the last byte.
|
||||
var badKeyLengthData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0, 216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61])
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168])
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61])
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPc",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
var missingJWKFieldKeyData = [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
kty: "OKP"
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
// The public key doesn't match the private key.
|
||||
var invalidJWKKeyData = [
|
||||
{
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
kty: "OKP"
|
||||
},
|
||||
];
|
||||
// META: script=okp_importKey_failures_fixtures.js
|
||||
// META: script=importKey_failures.js
|
||||
|
||||
run_test(["Ed25519"]);
|
||||
|
@ -1,111 +1,8 @@
|
||||
// META: title=WebCryptoAPI: importKey() for Failures
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_failures.js
|
||||
// META: script=okp_importKey_failures_fixtures.js
|
||||
// META: script=importKey_failures.js
|
||||
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
var validKeyData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 67, 48, 5, 6, 3, 43, 101, 113, 3, 58, 0, 171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29, 46]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Removed just the last byte.
|
||||
var badKeyLengthData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 67, 48, 5, 6, 3, 43, 101, 113, 3, 58, 0, 171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalq",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
var missingJWKFieldKeyData = [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// The public key doesn't match the private key.
|
||||
var invalidJWKKeyData = [
|
||||
{
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "X9dEm1m0Yf0s54fsYWrUah2hNCSFpw4fig6nXYDpZ3jt8SR2m0bHBhvWeD3x5Q9s0foavq_oJWGA",
|
||||
kty: "OKP"
|
||||
},
|
||||
];
|
||||
|
||||
run_test(["Ed448"]);
|
||||
|
@ -1,110 +1,8 @@
|
||||
// META: title=WebCryptoAPI: importKey() for Failures
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_failures.js
|
||||
// META: script=okp_importKey_failures_fixtures.js
|
||||
// META: script=importKey_failures.js
|
||||
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
var validKeyData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 200, 131, 142, 118, 208, 87, 223, 183, 216, 201, 90, 105, 225, 56, 22, 10, 221, 99, 115, 253, 113, 164, 210, 118, 187, 86, 227, 168, 27, 100, 255, 97]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Removed just the last byte.
|
||||
var badKeyLengthData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 200, 131, 142, 118, 208, 87, 223, 183, 216, 201, 90, 105, 225, 56, 22, 10, 221, 99, 115, 253, 113, 164, 210, 118, 187, 86, 227, 168, 27, 100, 255]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lw",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
var missingJWKFieldKeyData = [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
// The public key doesn't match the private key.
|
||||
var invalidJWKKeyData = [
|
||||
{
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "hSDwCYkwp1R0i33ctD73Wg2_Og0mOBr066SpjqqbTmo",
|
||||
kty: "OKP"
|
||||
},
|
||||
];
|
||||
|
||||
run_test(["X25519"]);
|
||||
|
@ -1,111 +1,8 @@
|
||||
// META: title=WebCryptoAPI: importKey() for Failures
|
||||
// META: timeout=long
|
||||
// META: script=../util/helpers.js
|
||||
// META: script=okp_importKey_failures.js
|
||||
// META: script=okp_importKey_failures_fixtures.js
|
||||
// META: script=importKey_failures.js
|
||||
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
var validKeyData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 70, 2, 1, 0, 48, 5, 6, 3, 43, 101, 111, 4, 58, 4, 56, 88, 199, 210, 154, 62, 181, 25, 178, 157, 0, 207, 177, 145, 187, 100, 252, 109, 138, 66, 216, 241, 113, 118, 39, 43, 137, 242, 39, 45, 24, 25, 41, 92, 101, 37, 192, 130, 150, 113, 176, 82, 239, 7, 39, 83, 15, 24, 142, 49, 208, 204, 83, 191, 38, 146, 158]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Removed just the last byte.
|
||||
var badKeyLengthData = [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 70, 2, 1, 0, 48, 5, 6, 3, 43, 101, 111, 4, 58, 4, 56, 88, 199, 210, 154, 62, 181, 25, 178, 157, 0, 207, 177, 145, 187, 100, 252, 109, 138, 66, 216, 241, 113, 118, 39, 43, 137, 242, 39, 45, 24, 25, 41, 92, 101, 37, 192, 130, 150, 113, 176, 82, 239, 7, 39, 83, 15, 24, 142, 49, 208, 204, 83, 191, 38, 146]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
var missingJWKFieldKeyData = [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// The public key doesn't match the private key.
|
||||
var invalidJWKKeyData = [
|
||||
{
|
||||
|
||||
crv: "X448",
|
||||
kty: "OKP",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "mwj3zDG34+Z9ItWuoSEHSic70rg94Jxj+qc9LCLF2bvINmRyQdlT1AxbEtqIEg1TF3+A5TLEH6A",
|
||||
},
|
||||
];
|
||||
|
||||
run_test(["X448"]);
|
||||
|
414
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_failures_fixtures.js
vendored
Normal file
414
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_failures_fixtures.js
vendored
Normal file
@ -0,0 +1,414 @@
|
||||
// Setup: define the correct behaviors that should be sought, and create
|
||||
// helper functions that generate all possible test parameters for
|
||||
// different situations.
|
||||
function getValidKeyData(algorithm) {
|
||||
return validKeyData[algorithm.name];
|
||||
}
|
||||
|
||||
function getBadKeyLengthData(algorithm) {
|
||||
return badKeyLengthData[algorithm.name];
|
||||
}
|
||||
|
||||
function getMissingJWKFieldKeyData(algorithm) {
|
||||
return missingJWKFieldKeyData[algorithm.name];
|
||||
}
|
||||
|
||||
function getMismatchedJWKKeyData(algorithm) {
|
||||
return mismatchedJWKKeyData[algorithm.name];
|
||||
}
|
||||
|
||||
var validKeyData = {
|
||||
"Ed25519": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0, 216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204])
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168, 31])
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204])
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
},
|
||||
}
|
||||
],
|
||||
"Ed448": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 67, 48, 5, 6, 3, 43, 101, 113, 3, 58, 0, 171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29, 46]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
],
|
||||
"X25519": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 200, 131, 142, 118, 208, 87, 223, 183, 216, 201, 90, 105, 225, 56, 22, 10, 221, 99, 115, 253, 113, 164, 210, 118, 187, 86, 227, 168, 27, 100, 255, 97]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
],
|
||||
"X448": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 70, 2, 1, 0, 48, 5, 6, 3, 43, 101, 111, 4, 58, 4, 56, 88, 199, 210, 154, 62, 181, 25, 178, 157, 0, 207, 177, 145, 187, 100, 252, 109, 138, 66, 216, 241, 113, 118, 39, 43, 137, 242, 39, 45, 24, 25, 41, 92, 101, 37, 192, 130, 150, 113, 176, 82, 239, 7, 39, 83, 15, 24, 142, 49, 208, 204, 83, 191, 38, 146, 158]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Removed just the last byte.
|
||||
var badKeyLengthData = {
|
||||
"Ed25519": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0, 216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61])
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168])
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61])
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPc",
|
||||
kty: "OKP"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Ed448": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 67, 48, 5, 6, 3, 43, 101, 113, 3, 58, 0, 171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalq",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
],
|
||||
"X25519": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 200, 131, 142, 118, 208, 87, 223, 183, 216, 201, 90, 105, 225, 56, 22, 10, 221, 99, 115, 253, 113, 164, 210, 118, 187, 86, 227, 168, 27, 100, 255]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lw",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
],
|
||||
"X448": [
|
||||
{
|
||||
format: "spki",
|
||||
data: new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206]),
|
||||
},
|
||||
{
|
||||
format: "pkcs8",
|
||||
data: new Uint8Array([48, 70, 2, 1, 0, 48, 5, 6, 3, 43, 101, 111, 4, 58, 4, 56, 88, 199, 210, 154, 62, 181, 25, 178, 157, 0, 207, 177, 145, 187, 100, 252, 109, 138, 66, 216, 241, 113, 118, 39, 43, 137, 242, 39, 45, 24, 25, 41, 92, 101, 37, 192, 130, 150, 113, 176, 82, 239, 7, 39, 83, 15, 24, 142, 49, 208, 204, 83, 191, 38, 146]),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
data: new Uint8Array([182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206]),
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
format: "jwk",
|
||||
data: {
|
||||
crv: "X448",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
var missingJWKFieldKeyData = {
|
||||
"Ed25519": [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "Ed25519",
|
||||
x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
kty: "OKP"
|
||||
},
|
||||
}
|
||||
],
|
||||
"Ed448": [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
}
|
||||
}
|
||||
],
|
||||
"X25519": [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
kty: "OKP"
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
},
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
},
|
||||
}
|
||||
],
|
||||
"X448": [
|
||||
{
|
||||
param: "x",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "kty",
|
||||
data: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
}
|
||||
},
|
||||
{
|
||||
param: "crv",
|
||||
data: {
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
}
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
// The public key doesn't match the private key.
|
||||
var mismatchedJWKKeyData = {
|
||||
"Ed25519": [
|
||||
{
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
kty: "OKP"
|
||||
},
|
||||
],
|
||||
"Ed448": [
|
||||
{
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "X9dEm1m0Yf0s54fsYWrUah2hNCSFpw4fig6nXYDpZ3jt8SR2m0bHBhvWeD3x5Q9s0foavq_oJWGA",
|
||||
kty: "OKP"
|
||||
},
|
||||
],
|
||||
"X25519": [
|
||||
{
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "hSDwCYkwp1R0i33ctD73Wg2_Og0mOBr066SpjqqbTmo",
|
||||
kty: "OKP"
|
||||
},
|
||||
],
|
||||
"X448": [
|
||||
{
|
||||
|
||||
crv: "X448",
|
||||
kty: "OKP",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "mwj3zDG34+Z9ItWuoSEHSic70rg94Jxj+qc9LCLF2bvINmRyQdlT1AxbEtqIEg1TF3+A5TLEH6A",
|
||||
},
|
||||
],
|
||||
}
|
58
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_fixtures.js
vendored
Normal file
58
test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_fixtures.js
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
var keyData = {
|
||||
"Ed25519": {
|
||||
privateUsages: ["sign"],
|
||||
publicUsages: ["verify"],
|
||||
spki: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 112, 3, 33, 0, 216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204]),
|
||||
raw: new Uint8Array([216, 225, 137, 99, 216, 9, 212, 135, 217, 84, 154, 204, 174, 198, 116, 46, 126, 235, 162, 77, 138, 13, 59, 20, 183, 227, 202, 234, 6, 137, 61, 204]),
|
||||
pkcs8: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168, 31]),
|
||||
jwk: {
|
||||
crv: "Ed25519",
|
||||
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
|
||||
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
"Ed448": {
|
||||
privateUsages: ["sign"],
|
||||
publicUsages: ["verify"],
|
||||
spki: new Uint8Array([48, 67, 48, 5, 6, 3, 43, 101, 113, 3, 58, 0, 171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
raw: new Uint8Array([171, 75, 184, 133, 253, 125, 44, 90, 242, 78, 131, 113, 12, 255, 160, 199, 74, 87, 226, 116, 128, 29, 178, 5, 123, 11, 220, 94, 160, 50, 182, 254, 107, 199, 139, 128, 69, 54, 90, 235, 38, 232, 110, 31, 20, 253, 52, 157, 7, 196, 132, 149, 245, 164, 106, 90, 128]),
|
||||
pkcs8: new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29, 46]),
|
||||
jwk: {
|
||||
crv: "Ed448",
|
||||
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
|
||||
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
"X25519": {
|
||||
privateUsages: ["deriveKey", "deriveBits"],
|
||||
publicUsages: [],
|
||||
spki: new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
raw: new Uint8Array([28, 242, 177, 230, 2, 46, 197, 55, 55, 30, 215, 245, 62, 84, 250, 17, 84, 216, 62, 152, 235, 100, 234, 81, 250, 229, 179, 48, 124, 254, 151, 6]),
|
||||
pkcs8: new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 200, 131, 142, 118, 208, 87, 223, 183, 216, 201, 90, 105, 225, 56, 22, 10, 221, 99, 115, 253, 113, 164, 210, 118, 187, 86, 227, 168, 27, 100, 255, 97]),
|
||||
jwk: {
|
||||
crv: "X25519",
|
||||
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
|
||||
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
"X448": {
|
||||
privateUsages: ["deriveKey", "deriveBits"],
|
||||
publicUsages: [],
|
||||
spki: new Uint8Array([48, 66, 48, 5, 6, 3, 43, 101, 111, 3, 57, 0, 182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
raw: new Uint8Array([182, 4, 161, 209, 165, 205, 29, 148, 38, 213, 97, 239, 99, 10, 158, 177, 108, 190, 105, 213, 185, 202, 97, 94, 220, 83, 99, 62, 251, 82, 234, 49, 230, 230, 160, 161, 219, 172, 198, 231, 108, 188, 230, 72, 45, 126, 75, 163, 213, 93, 158, 128, 39, 101, 206, 111]),
|
||||
pkcs8: new Uint8Array([48, 70, 2, 1, 0, 48, 5, 6, 3, 43, 101, 111, 4, 58, 4, 56, 88, 199, 210, 154, 62, 181, 25, 178, 157, 0, 207, 177, 145, 187, 100, 252, 109, 138, 66, 216, 241, 113, 118, 39, 43, 137, 242, 39, 45, 24, 25, 41, 92, 101, 37, 192, 130, 150, 113, 176, 82, 239, 7, 39, 83, 15, 24, 142, 49, 208, 204, 83, 191, 38, 146, 158]),
|
||||
jwk: {
|
||||
crv: "X448",
|
||||
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
|
||||
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
|
||||
kty: "OKP"
|
||||
}
|
||||
},
|
||||
|
||||
};
|
@ -1,10 +1,10 @@
|
||||
|
||||
function run_test() {
|
||||
function run_test(algorithmName) {
|
||||
var subtle = self.crypto.subtle; // Change to test prefixed implementations
|
||||
|
||||
// Source file [algorithm_name]_vectors.js provides the getTestVectors method
|
||||
// for the algorithm that drives these tests.
|
||||
var testVectors = getTestVectors();
|
||||
var testVectors = getTestVectors(algorithmName);
|
||||
|
||||
testVectors.forEach(function(vector) {
|
||||
var algorithm = {name: vector.algorithmName};
|
||||
|
6
test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa_curve25519.https.any.js
vendored
Normal file
6
test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa_curve25519.https.any.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
// META: title=WebCryptoAPI: sign() and verify() Using EdDSA
|
||||
// META: script=eddsa_vectors.js
|
||||
// META: script=eddsa.js
|
||||
// META: timeout=long
|
||||
|
||||
run_test("Ed25519");
|
@ -3,4 +3,4 @@
|
||||
// META: script=eddsa.js
|
||||
// META: timeout=long
|
||||
|
||||
run_test();
|
||||
run_test("Ed448");
|
@ -16,7 +16,7 @@
|
||||
// algorithmName - the name of the AlgorithmIdentifier parameter to provide to sign
|
||||
// data - the text to sign
|
||||
// signature - the expected signature
|
||||
function getTestVectors() {
|
||||
function getTestVectors(algorithmName) {
|
||||
var pkcs8 = {
|
||||
"Ed25519": new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 243, 200, 244, 196, 141, 248, 120, 20, 110, 140, 211, 191, 109, 244, 229, 14, 56, 155, 167, 7, 78, 21, 194, 53, 45, 205, 93, 48, 141, 76, 168, 31]),
|
||||
"Ed448": new Uint8Array([48, 71, 2, 1, 0, 48, 5, 6, 3, 43, 101, 113, 4, 59, 4, 57, 14, 255, 3, 69, 140, 40, 224, 23, 156, 82, 29, 227, 18, 201, 105, 183, 131, 67, 72, 236, 171, 153, 26, 96, 227, 178, 233, 167, 158, 76, 217, 228, 128, 239, 41, 23, 18, 210, 200, 61, 4, 114, 114, 213, 201, 244, 40, 102, 79, 105, 109, 38, 112, 69, 143, 29, 46]),
|
||||
@ -37,7 +37,7 @@ function getTestVectors() {
|
||||
}
|
||||
|
||||
var vectors = [];
|
||||
["Ed25519", "Ed448"].forEach(function(algorithmName) {
|
||||
{
|
||||
var vector = {
|
||||
name: "EdDSA " + algorithmName,
|
||||
publicKeyBuffer: spki[algorithmName],
|
||||
@ -52,7 +52,7 @@ function getTestVectors() {
|
||||
};
|
||||
|
||||
vectors.push(vector);
|
||||
});
|
||||
}
|
||||
return vectors;
|
||||
}
|
||||
|
||||
|
38
test/fixtures/wpt/WebCryptoAPI/util/helpers.js
vendored
38
test/fixtures/wpt/WebCryptoAPI/util/helpers.js
vendored
@ -259,3 +259,41 @@ function allNameVariants(name, slowTest) {
|
||||
if (slowTest) return [mixedCaseName];
|
||||
return unique([upCaseName, lowCaseName, mixedCaseName]);
|
||||
}
|
||||
|
||||
// Builds a hex string representation for an array-like input.
|
||||
// "bytes" can be an Array of bytes, an ArrayBuffer, or any TypedArray.
|
||||
// The output looks like this:
|
||||
// ab034c99
|
||||
function bytesToHexString(bytes)
|
||||
{
|
||||
if (!bytes)
|
||||
return null;
|
||||
|
||||
bytes = new Uint8Array(bytes);
|
||||
var hexBytes = [];
|
||||
|
||||
for (var i = 0; i < bytes.length; ++i) {
|
||||
var byteString = bytes[i].toString(16);
|
||||
if (byteString.length < 2)
|
||||
byteString = "0" + byteString;
|
||||
hexBytes.push(byteString);
|
||||
}
|
||||
|
||||
return hexBytes.join("");
|
||||
}
|
||||
|
||||
function hexStringToUint8Array(hexString)
|
||||
{
|
||||
if (hexString.length % 2 != 0)
|
||||
throw "Invalid hexString";
|
||||
var arrayBuffer = new Uint8Array(hexString.length / 2);
|
||||
|
||||
for (var i = 0; i < hexString.length; i += 2) {
|
||||
var byteValue = parseInt(hexString.substr(i, 2), 16);
|
||||
if (byteValue == NaN)
|
||||
throw "Invalid hexString";
|
||||
arrayBuffer[i/2] = byteValue;
|
||||
}
|
||||
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
4
test/fixtures/wpt/versions.json
vendored
4
test/fixtures/wpt/versions.json
vendored
@ -84,7 +84,7 @@
|
||||
"path": "wasm/webapi"
|
||||
},
|
||||
"WebCryptoAPI": {
|
||||
"commit": "6748a0a24614b01ce6527493a19ef846738bee3a",
|
||||
"commit": "b81831169b8527a6c569a4ad92cf8a1baf4a7118",
|
||||
"path": "WebCryptoAPI"
|
||||
},
|
||||
"webidl/ecmascript-binding/es-exceptions": {
|
||||
@ -95,4 +95,4 @@
|
||||
"commit": "e97fac4791931fb7455ba3fad759d362c7108b09",
|
||||
"path": "webmessaging/broadcastchannel"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,11 +261,6 @@ async function testDeriveBitsBadLengths(
|
||||
subtle.deriveBits(algorithm, baseKeys[size], undefined), {
|
||||
name: 'OperationError',
|
||||
}),
|
||||
assert.rejects(
|
||||
subtle.deriveBits(algorithm, baseKeys[size], 0), {
|
||||
message: /length cannot be zero/,
|
||||
name: 'OperationError',
|
||||
}),
|
||||
assert.rejects(
|
||||
subtle.deriveBits(algorithm, baseKeys[size], null), {
|
||||
message: 'length cannot be null',
|
||||
@ -562,3 +557,18 @@ async function testWrongKeyType(
|
||||
await Promise.all(variations);
|
||||
|
||||
})().then(common.mustCall());
|
||||
|
||||
// https://github.com/w3c/webcrypto/pull/380
|
||||
{
|
||||
crypto.subtle.importKey('raw', new Uint8Array(0), 'HKDF', false, ['deriveBits']).then((key) => {
|
||||
return crypto.subtle.deriveBits({
|
||||
name: 'HKDF',
|
||||
hash: { name: 'SHA-256' },
|
||||
info: new Uint8Array(0),
|
||||
salt: new Uint8Array(0),
|
||||
}, key, 0);
|
||||
}).then((bits) => {
|
||||
assert.deepStrictEqual(bits, new ArrayBuffer(0));
|
||||
})
|
||||
.then(common.mustCall());
|
||||
}
|
||||
|
@ -449,11 +449,6 @@ async function testDeriveBitsBadLengths(
|
||||
subtle.deriveBits(algorithm, baseKeys[size], undefined), {
|
||||
name: 'OperationError',
|
||||
}),
|
||||
assert.rejects(
|
||||
subtle.deriveBits(algorithm, baseKeys[size], 0), {
|
||||
message: /length cannot be zero/,
|
||||
name: 'OperationError',
|
||||
}),
|
||||
assert.rejects(
|
||||
subtle.deriveBits(algorithm, baseKeys[size], null), {
|
||||
message: 'length cannot be null',
|
||||
@ -693,3 +688,19 @@ async function testWrongKeyType(
|
||||
|
||||
await Promise.all(variations);
|
||||
})().then(common.mustCall());
|
||||
|
||||
|
||||
// https://github.com/w3c/webcrypto/pull/380
|
||||
{
|
||||
crypto.subtle.importKey('raw', new Uint8Array(0), 'PBKDF2', false, ['deriveBits']).then((key) => {
|
||||
return crypto.subtle.deriveBits({
|
||||
name: 'PBKDF2',
|
||||
hash: { name: 'SHA-256' },
|
||||
iterations: 10,
|
||||
salt: new Uint8Array(0),
|
||||
}, key, 0);
|
||||
}).then((bits) => {
|
||||
assert.deepStrictEqual(bits, new ArrayBuffer(0));
|
||||
})
|
||||
.then(common.mustCall());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user