Skip to content

Commit 1c00155

Browse files
panvatargos
authored andcommittedOct 4, 2024
test,crypto: update WebCryptoAPI WPT
PR-URL: #55029 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a50dd21 commit 1c00155

20 files changed

+405
-328
lines changed
 

‎test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Last update:
3232
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3333
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3434
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
35-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/272064ebf9/WebCryptoAPI
35+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/203d2ac459/WebCryptoAPI
3636
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
3737
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/e97fac4791/webmessaging/broadcastchannel
3838
- webstorage: https://github.com/web-platform-tests/wpt/tree/9dafa89214/webstorage

‎test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits.js

+30-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
function define_tests_25519() {
2+
return define_tests("X25519");
3+
}
4+
5+
function define_tests_448() {
6+
return define_tests("X448");
7+
}
18

2-
function define_tests() {
9+
function define_tests(algorithmName) {
310
// May want to test prefixed implementations.
411
var subtle = self.crypto.subtle;
512

613
// Verify the derive functions perform checks against the all-zero value results,
714
// ensuring small-order points are rejected.
815
// https://www.rfc-editor.org/rfc/rfc7748#section-6.1
9-
Object.keys(kSmallOrderPoint).forEach(function(algorithmName) {
16+
{
1017
kSmallOrderPoint[algorithmName].forEach(function(test) {
1118
promise_test(async() => {
1219
let derived;
@@ -28,15 +35,16 @@ function define_tests() {
2835
assert_equals(derived, undefined, "Operation succeeded, but should not have.");
2936
}, algorithmName + " key derivation checks for all-zero value result with a key of order " + test.order);
3037
});
31-
});
38+
}
3239

3340
return importKeys(pkcs8, spki, sizes)
3441
.then(function(results) {
3542
publicKeys = results.publicKeys;
3643
privateKeys = results.privateKeys;
3744
noDeriveBitsKeys = results.noDeriveBitsKeys;
45+
ecdhKeys = results.ecdhKeys;
3846

39-
Object.keys(sizes).forEach(function(algorithmName) {
47+
{
4048
// Basic success case
4149
promise_test(function(test) {
4250
return subtle.deriveBits({name: algorithmName, public: publicKeys[algorithmName]}, privateKeys[algorithmName], 8 * sizes[algorithmName])
@@ -101,11 +109,7 @@ function define_tests() {
101109

102110
// - wrong algorithm
103111
promise_test(function(test) {
104-
publicKey = publicKeys["X25519"];
105-
if (algorithmName === "X25519") {
106-
publicKey = publicKeys["X448"];
107-
}
108-
return subtle.deriveBits({name: algorithmName, public: publicKey}, privateKeys[algorithmName], 8 * sizes[algorithmName])
112+
return subtle.deriveBits({name: algorithmName, public: ecdhKeys[algorithmName]}, privateKeys[algorithmName], 8 * sizes[algorithmName])
109113
.then(function(derivation) {
110114
assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError");
111115
}, function(err) {
@@ -165,16 +169,17 @@ function define_tests() {
165169
assert_equals(err.name, "OperationError", "Should throw correct error, not " + err.name + ": " + err.message);
166170
});
167171
}, algorithmName + " asking for too many bits");
168-
});
172+
}
169173
});
170174

171175
function importKeys(pkcs8, spki, sizes) {
172176
var privateKeys = {};
173177
var publicKeys = {};
174178
var noDeriveBitsKeys = {};
179+
var ecdhPublicKeys = {};
175180

176181
var promises = [];
177-
Object.keys(pkcs8).forEach(function(algorithmName) {
182+
{
178183
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
179184
{name: algorithmName},
180185
false, ["deriveBits", "deriveKey"])
@@ -184,8 +189,8 @@ function define_tests() {
184189
privateKeys[algorithmName] = null;
185190
});
186191
promises.push(operation);
187-
});
188-
Object.keys(pkcs8).forEach(function(algorithmName) {
192+
}
193+
{
189194
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
190195
{name: algorithmName},
191196
false, ["deriveKey"])
@@ -195,8 +200,8 @@ function define_tests() {
195200
noDeriveBitsKeys[algorithmName] = null;
196201
});
197202
promises.push(operation);
198-
});
199-
Object.keys(spki).forEach(function(algorithmName) {
203+
}
204+
{
200205
var operation = subtle.importKey("spki", spki[algorithmName],
201206
{name: algorithmName},
202207
false, [])
@@ -206,10 +211,17 @@ function define_tests() {
206211
publicKeys[algorithmName] = null;
207212
});
208213
promises.push(operation);
209-
});
210-
214+
}
215+
{
216+
var operation = subtle.importKey("spki", ecSPKI,
217+
{name: "ECDH", namedCurve: "P-256"},
218+
false, [])
219+
.then(function(key) {
220+
ecdhPublicKeys[algorithmName] = key;
221+
});
222+
}
211223
return Promise.all(promises)
212-
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveBitsKeys: noDeriveBitsKeys}});
224+
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveBitsKeys: noDeriveBitsKeys, ecdhKeys: ecdhPublicKeys}});
213225
}
214226

215227
// Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves
2+
// META: script=cfrg_curves_bits_fixtures.js
3+
// META: script=cfrg_curves_bits.js
4+
5+
// Define subtests from a `promise_test` to ensure the harness does not
6+
// complete before the subtests are available. `explicit_done` cannot be used
7+
// for this purpose because the global `done` function is automatically invoked
8+
// by the WPT infrastructure in dedicated worker tests defined using the
9+
// "multi-global" pattern.
10+
promise_test(define_tests_25519, 'setup - define tests');
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: title=WebCryptoAPI: deriveBits() Using ECDH with CFRG Elliptic Curves
1+
// META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves
22
// META: script=cfrg_curves_bits_fixtures.js
33
// META: script=cfrg_curves_bits.js
44

@@ -7,4 +7,4 @@
77
// for this purpose because the global `done` function is automatically invoked
88
// by the WPT infrastructure in dedicated worker tests defined using the
99
// "multi-global" pattern.
10-
promise_test(define_tests, 'setup - define tests');
10+
promise_test(define_tests_448, 'setup - define tests');

‎test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits_fixtures.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys.js

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
function define_tests_25519() {
2+
return define_tests("X25519");
3+
}
4+
5+
function define_tests_448() {
6+
return define_tests("X448");
7+
}
18

2-
function define_tests() {
9+
function define_tests(algorithmName) {
310
// May want to test prefixed implementations.
411
var subtle = self.crypto.subtle;
512

@@ -8,7 +15,7 @@ function define_tests() {
815
// https://www.rfc-editor.org/rfc/rfc7748#section-6.1
916
// TODO: The spec states that the check must be done on use, but there is discussion about doing it on import.
1017
// https://github.com/WICG/webcrypto-secure-curves/pull/13
11-
Object.keys(kSmallOrderPoint).forEach(function(algorithmName) {
18+
{
1219
kSmallOrderPoint[algorithmName].forEach(function(test) {
1320
promise_test(async() => {
1421
let derived;
@@ -32,10 +39,10 @@ function define_tests() {
3239
assert_equals(derived, undefined, "Operation succeeded, but should not have.");
3340
}, algorithmName + " deriveBits checks for all-zero value result with a key of order " + test.order);
3441
});
35-
});
42+
}
3643

3744
// Ensure the keys generated by each algorithm are valid for key derivation.
38-
Object.keys(sizes).forEach(function(algorithmName) {
45+
{
3946
promise_test(async() => {
4047
let derived;
4148
try {
@@ -46,15 +53,16 @@ function define_tests() {
4653
}
4754
assert_false (derived === undefined, "Key derivation failed.");
4855
}, "Key derivation using a " + algorithmName + " generated keys.");
49-
});
56+
}
5057

5158
return importKeys(pkcs8, spki, sizes)
5259
.then(function(results) {
5360
publicKeys = results.publicKeys;
5461
privateKeys = results.privateKeys;
5562
noDeriveKeyKeys = results.noDeriveKeyKeys;
63+
ecdhKeys = results.ecdhKeys;
5664

57-
Object.keys(sizes).forEach(function(algorithmName) {
65+
{
5866
// Basic success case
5967
promise_test(function(test) {
6068
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() {
102110

103111
// - wrong algorithm
104112
promise_test(function(test) {
105-
publicKey = publicKeys["X25519"];
106-
if (algorithmName === "X25519") {
107-
publicKey = publicKeys["X448"];
108-
}
109-
return subtle.deriveKey({name: algorithmName, public: publicKey}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
113+
return subtle.deriveKey({name: algorithmName, public: ecdhKeys[algorithmName]}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
110114
.then(function(key) {return crypto.subtle.exportKey("raw", key);})
111115
.then(function(exportedKey) {
112116
assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError");
@@ -161,16 +165,17 @@ function define_tests() {
161165
});
162166
});
163167
}, algorithmName + " public property value is a secret key");
164-
});
168+
}
165169
});
166170

167171
function importKeys(pkcs8, spki, sizes) {
168172
var privateKeys = {};
169173
var publicKeys = {};
170174
var noDeriveKeyKeys = {};
175+
var ecdhPublicKeys = {};
171176

172177
var promises = [];
173-
Object.keys(pkcs8).forEach(function(algorithmName) {
178+
{
174179
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
175180
{name: algorithmName},
176181
false, ["deriveBits", "deriveKey"])
@@ -180,8 +185,8 @@ function define_tests() {
180185
privateKeys[algorithmName] = null;
181186
});
182187
promises.push(operation);
183-
});
184-
Object.keys(pkcs8).forEach(function(algorithmName) {
188+
}
189+
{
185190
var operation = subtle.importKey("pkcs8", pkcs8[algorithmName],
186191
{name: algorithmName},
187192
false, ["deriveBits"])
@@ -191,8 +196,8 @@ function define_tests() {
191196
noDeriveKeyKeys[algorithmName] = null;
192197
});
193198
promises.push(operation);
194-
});
195-
Object.keys(spki).forEach(function(algorithmName) {
199+
}
200+
{
196201
var operation = subtle.importKey("spki", spki[algorithmName],
197202
{name: algorithmName},
198203
false, [])
@@ -202,10 +207,18 @@ function define_tests() {
202207
publicKeys[algorithmName] = null;
203208
});
204209
promises.push(operation);
205-
});
210+
}
211+
{
212+
var operation = subtle.importKey("spki", ecSPKI,
213+
{name: "ECDH", namedCurve: "P-256"},
214+
false, [])
215+
.then(function(key) {
216+
ecdhPublicKeys[algorithmName] = key;
217+
});
218+
}
206219

207220
return Promise.all(promises)
208-
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveKeyKeys: noDeriveKeyKeys}});
221+
.then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveKeyKeys: noDeriveKeyKeys, ecdhKeys: ecdhPublicKeys}});
209222
}
210223

211224
// Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves
2+
// META: script=cfrg_curves_bits_fixtures.js
3+
// META: script=cfrg_curves_keys.js
4+
5+
// Define subtests from a `promise_test` to ensure the harness does not
6+
// complete before the subtests are available. `explicit_done` cannot be used
7+
// for this purpose because the global `done` function is automatically invoked
8+
// by the WPT infrastructure in dedicated worker tests defined using the
9+
// "multi-global" pattern.
10+
promise_test(define_tests_25519, 'setup - define tests');

‎test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys.https.any.js ‎test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys_curve448.https.any.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
// for this purpose because the global `done` function is automatically invoked
88
// by the WPT infrastructure in dedicated worker tests defined using the
99
// "multi-global" pattern.
10-
promise_test(define_tests, 'setup - define tests');
10+
promise_test(define_tests_448, 'setup - define tests');

‎test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js

-280
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
var subtle = crypto.subtle;
2+
3+
function runTests(algorithmName) {
4+
var algorithm = {name: algorithmName};
5+
var data = keyData[algorithmName];
6+
var jwkData = {jwk: {kty: data.jwk.kty, crv: data.jwk.crv, x: data.jwk.x}};
7+
8+
[true, false].forEach(function(extractable) {
9+
// Test public keys first
10+
allValidUsages(data.publicUsages, true).forEach(function(usages) {
11+
['spki', 'jwk', 'raw'].forEach(function(format) {
12+
if (format === "jwk") { // Not all fields used for public keys
13+
testFormat(format, algorithm, jwkData, algorithmName, usages, extractable);
14+
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
15+
if (extractable) {
16+
testJwkAlgBehaviours(algorithm, jwkData.jwk, algorithmName, usages);
17+
}
18+
} else {
19+
testFormat(format, algorithm, data, algorithmName, usages, extractable);
20+
}
21+
});
22+
23+
});
24+
25+
// Next, test private keys
26+
allValidUsages(data.privateUsages).forEach(function(usages) {
27+
['pkcs8', 'jwk'].forEach(function(format) {
28+
testFormat(format, algorithm, data, algorithmName, usages, extractable);
29+
30+
// Test for https://github.com/WICG/webcrypto-secure-curves/pull/24
31+
if (format === "jwk" && extractable) {
32+
testJwkAlgBehaviours(algorithm, data.jwk, algorithmName, usages);
33+
}
34+
});
35+
});
36+
});
37+
}
38+
39+
40+
// Test importKey with a given key format and other parameters. If
41+
// extrable is true, export the key and verify that it matches the input.
42+
function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
43+
promise_test(function(test) {
44+
return subtle.importKey(format, keyData[format], algorithm, extractable, usages).
45+
then(function(key) {
46+
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
47+
assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData[format].d)) ? 'private' : 'public');
48+
if (!extractable) {
49+
return;
50+
}
51+
52+
return subtle.exportKey(format, key).
53+
then(function(result) {
54+
if (format !== "jwk") {
55+
assert_true(equalBuffers(keyData[format], result), "Round trip works");
56+
} else {
57+
assert_true(equalJwk(keyData[format], result), "Round trip works");
58+
}
59+
}, function(err) {
60+
assert_unreached("Threw an unexpected error: " + err.toString());
61+
});
62+
}, function(err) {
63+
assert_unreached("Threw an unexpected error: " + err.toString());
64+
});
65+
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], algorithm, extractable, usages));
66+
}
67+
68+
// Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export
69+
// https://github.com/WICG/webcrypto-secure-curves/pull/24
70+
function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {
71+
promise_test(function(test) {
72+
return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, algorithm, true, usages).
73+
then(function(key) {
74+
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
75+
76+
return subtle.exportKey('jwk', key).
77+
then(function(result) {
78+
assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");
79+
assert_equals(result.alg, undefined, 'No JWK "alg" member is present');
80+
assert_true(equalJwk(keyData, result), "Round trip works");
81+
}, function(err) {
82+
assert_unreached("Threw an unexpected error: " + err.toString());
83+
});
84+
}, function(err) {
85+
assert_unreached("Threw an unexpected error: " + err.toString());
86+
});
87+
}, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, algorithm, true, usages));
88+
}
89+
90+
91+
92+
// Helper methods follow:
93+
94+
// Are two array buffers the same?
95+
function equalBuffers(a, b) {
96+
if (a.byteLength !== b.byteLength) {
97+
return false;
98+
}
99+
100+
var aBytes = new Uint8Array(a);
101+
var bBytes = new Uint8Array(b);
102+
103+
for (var i=0; i<a.byteLength; i++) {
104+
if (aBytes[i] !== bBytes[i]) {
105+
return false;
106+
}
107+
}
108+
109+
return true;
110+
}
111+
112+
// Are two Jwk objects "the same"? That is, does the object returned include
113+
// matching values for each property that was expected? It's okay if the
114+
// returned object has extra methods; they aren't checked.
115+
function equalJwk(expected, got) {
116+
var fields = Object.keys(expected);
117+
var fieldName;
118+
119+
for(var i=0; i<fields.length; i++) {
120+
fieldName = fields[i];
121+
if (!(fieldName in got)) {
122+
return false;
123+
}
124+
if (expected[fieldName] !== got[fieldName]) {
125+
return false;
126+
}
127+
}
128+
129+
return true;
130+
}
131+
132+
// Build minimal Jwk objects from raw key data and algorithm specifications
133+
function jwkData(keyData, algorithm) {
134+
var result = {
135+
kty: "oct",
136+
k: byteArrayToUnpaddedBase64(keyData)
137+
};
138+
139+
if (algorithm.name.substring(0, 3) === "AES") {
140+
result.alg = "A" + (8 * keyData.byteLength).toString() + algorithm.name.substring(4);
141+
} else if (algorithm.name === "HMAC") {
142+
result.alg = "HS" + algorithm.hash.substring(4);
143+
}
144+
return result;
145+
}
146+
147+
// Jwk format wants Base 64 without the typical padding at the end.
148+
function byteArrayToUnpaddedBase64(byteArray){
149+
var binaryString = "";
150+
for (var i=0; i<byteArray.byteLength; i++){
151+
binaryString += String.fromCharCode(byteArray[i]);
152+
}
153+
var base64String = btoa(binaryString);
154+
155+
return base64String.replace(/=/g, "");
156+
}
157+
158+
// Convert method parameters to a string to uniquely name each test
159+
function parameterString(format, data, algorithm, extractable, usages) {
160+
if ("byteLength" in data) {
161+
data = "buffer(" + data.byteLength.toString() + ")";
162+
} else {
163+
data = "object(" + Object.keys(data).join(", ") + ")";
164+
}
165+
var result = "(" +
166+
objectToString(format) + ", " +
167+
objectToString(data) + ", " +
168+
objectToString(algorithm) + ", " +
169+
objectToString(extractable) + ", " +
170+
objectToString(usages) +
171+
")";
172+
173+
return result;
174+
}
175+
176+
// Character representation of any object we may use as a parameter.
177+
function objectToString(obj) {
178+
var keyValuePairs = [];
179+
180+
if (Array.isArray(obj)) {
181+
return "[" + obj.map(function(elem){return objectToString(elem);}).join(", ") + "]";
182+
} else if (typeof obj === "object") {
183+
Object.keys(obj).sort().forEach(function(keyName) {
184+
keyValuePairs.push(keyName + ": " + objectToString(obj[keyName]));
185+
});
186+
return "{" + keyValuePairs.join(", ") + "}";
187+
} else if (typeof obj === "undefined") {
188+
return "undefined";
189+
} else {
190+
return obj.toString();
191+
}
192+
193+
var keyValuePairs = [];
194+
195+
Object.keys(obj).sort().forEach(function(keyName) {
196+
var value = obj[keyName];
197+
if (typeof value === "object") {
198+
value = objectToString(value);
199+
} else if (typeof value === "array") {
200+
value = "[" + value.map(function(elem){return objectToString(elem);}).join(", ") + "]";
201+
} else {
202+
value = value.toString();
203+
}
204+
205+
keyValuePairs.push(keyName + ": " + value);
206+
});
207+
208+
return "{" + keyValuePairs.join(", ") + "}";
209+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// META: title=WebCryptoAPI: importKey() for OKP keys
2+
// META: timeout=long
3+
// META: script=../util/helpers.js
4+
// META: script=okp_importKey_fixtures.js
5+
// META: script=okp_importKey.js
6+
7+
8+
// Test importKey and exportKey for OKP algorithms.
9+
runTests("Ed25519");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// META: title=WebCryptoAPI: importKey() for OKP keys
2+
// META: timeout=long
3+
// META: script=../util/helpers.js
4+
// META: script=okp_importKey_fixtures.js
5+
// META: script=okp_importKey.js
6+
7+
8+
// Test importKey and exportKey for OKP algorithms.
9+
runTests("Ed448");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// META: title=WebCryptoAPI: importKey() for OKP keys
2+
// META: timeout=long
3+
// META: script=../util/helpers.js
4+
// META: script=okp_importKey_fixtures.js
5+
// META: script=okp_importKey.js
6+
7+
8+
// Test importKey and exportKey for OKP algorithms.
9+
runTests("X25519");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// META: title=WebCryptoAPI: importKey() for OKP keys
2+
// META: timeout=long
3+
// META: script=../util/helpers.js
4+
// META: script=okp_importKey_fixtures.js
5+
// META: script=okp_importKey.js
6+
7+
8+
// Test importKey and exportKey for OKP algorithms.
9+
runTests("X448");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var keyData = {
2+
"Ed25519": {
3+
privateUsages: ["sign"],
4+
publicUsages: ["verify"],
5+
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]),
6+
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]),
7+
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]),
8+
jwk: {
9+
crv: "Ed25519",
10+
d: "88j0xI34eBRujNO_bfTlDjibpwdOFcI1Lc1dMI1MqB8",
11+
x: "2OGJY9gJ1IfZVJrMrsZ0Ln7rok2KDTsUt-PK6gaJPcw",
12+
kty: "OKP"
13+
}
14+
},
15+
16+
"Ed448": {
17+
privateUsages: ["sign"],
18+
publicUsages: ["verify"],
19+
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]),
20+
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]),
21+
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]),
22+
jwk: {
23+
crv: "Ed448",
24+
d: "Dv8DRYwo4BecUh3jEslpt4NDSOyrmRpg47Lpp55M2eSA7ykXEtLIPQRyctXJ9ChmT2ltJnBFjx0u",
25+
x: "q0u4hf19LFryToNxDP-gx0pX4nSAHbIFewvcXqAytv5rx4uARTZa6ybobh8U_TSdB8SElfWkalqA",
26+
kty: "OKP"
27+
}
28+
},
29+
30+
"X25519": {
31+
privateUsages: ["deriveKey", "deriveBits"],
32+
publicUsages: [],
33+
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]),
34+
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]),
35+
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]),
36+
jwk: {
37+
crv: "X25519",
38+
d: "yIOOdtBX37fYyVpp4TgWCt1jc_1xpNJ2u1bjqBtk_2E",
39+
x: "HPKx5gIuxTc3Htf1PlT6EVTYPpjrZOpR-uWzMHz-lwY",
40+
kty: "OKP"
41+
}
42+
},
43+
44+
"X448": {
45+
privateUsages: ["deriveKey", "deriveBits"],
46+
publicUsages: [],
47+
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]),
48+
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]),
49+
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]),
50+
jwk: {
51+
crv: "X448",
52+
d: "WMfSmj61GbKdAM-xkbtk_G2KQtjxcXYnK4nyJy0YGSlcZSXAgpZxsFLvBydTDxiOMdDMU78mkp4",
53+
x: "tgSh0aXNHZQm1WHvYwqesWy-adW5ymFe3FNjPvtS6jHm5qCh26zG52y85kgtfkuj1V2egCdlzm8",
54+
kty: "OKP"
55+
}
56+
},
57+
58+
};

‎test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
function run_test() {
2+
function run_test(algorithmName) {
33
var subtle = self.crypto.subtle; // Change to test prefixed implementations
44

55
// Source file [algorithm_name]_vectors.js provides the getTestVectors method
66
// for the algorithm that drives these tests.
7-
var testVectors = getTestVectors();
7+
var testVectors = getTestVectors(algorithmName);
88

99
testVectors.forEach(function(vector) {
1010
var algorithm = {name: vector.algorithmName};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// META: title=WebCryptoAPI: sign() and verify() Using EdDSA
2+
// META: script=eddsa_vectors.js
3+
// META: script=eddsa.js
4+
// META: timeout=long
5+
6+
run_test("Ed25519");

‎test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.https.any.js ‎test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa_curve448.https.any.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// META: script=eddsa.js
44
// META: timeout=long
55

6-
run_test();
6+
run_test("Ed448");

‎test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa_vectors.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// algorithmName - the name of the AlgorithmIdentifier parameter to provide to sign
1717
// data - the text to sign
1818
// signature - the expected signature
19-
function getTestVectors() {
19+
function getTestVectors(algorithmName) {
2020
var pkcs8 = {
2121
"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]),
2222
"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() {
3737
}
3838

3939
var vectors = [];
40-
["Ed25519", "Ed448"].forEach(function(algorithmName) {
40+
{
4141
var vector = {
4242
name: "EdDSA " + algorithmName,
4343
publicKeyBuffer: spki[algorithmName],
@@ -52,7 +52,7 @@ function getTestVectors() {
5252
};
5353

5454
vectors.push(vector);
55-
});
55+
}
5656
return vectors;
5757
}
5858

‎test/fixtures/wpt/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"path": "wasm/webapi"
8989
},
9090
"WebCryptoAPI": {
91-
"commit": "272064ebf9a3d313a2d4db8bb9ce2790648aa162",
91+
"commit": "203d2ac45900139633d4f3f29750ea4b5e06d6f5",
9292
"path": "WebCryptoAPI"
9393
},
9494
"webidl/ecmascript-binding/es-exceptions": {

0 commit comments

Comments
 (0)
Please sign in to comment.