Skip to content

Commit 36c5927

Browse files
panvaRafaelGSS
authored andcommitted
test,crypto: update WebCryptoAPI WPT
PR-URL: #45165 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 29b9f4f commit 36c5927

File tree

7 files changed

+59
-12
lines changed

7 files changed

+59
-12
lines changed

test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Last update:
3131
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
3232
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
3333
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
34-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/edca84af42/WebCryptoAPI
34+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/0042d42ee6/WebCryptoAPI
3535
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
3636

3737
[Web Platform Tests]: https://github.com/web-platform-tests/wpt

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function define_tests() {
150150
promise_test(function(test) {
151151
return subtle.generateKey({name: "AES-CBC", length: 128}, true, ["encrypt", "decrypt"])
152152
.then(function(secretKey) {
153-
subtle.deriveBits({name: algorithmName, public: secretKey}, privateKeys[algorithmName], 8 * sizes[algorithmName])
153+
return subtle.deriveBits({name: algorithmName, public: secretKey}, privateKeys[algorithmName], 8 * sizes[algorithmName])
154154
.then(function(derivation) {
155155
assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError");
156156
}, function(err) {
@@ -183,6 +183,8 @@ function define_tests() {
183183
false, ["deriveBits", "deriveKey"])
184184
.then(function(key) {
185185
privateKeys[algorithmName] = key;
186+
}, function (err) {
187+
privateKeys[algorithmName] = null;
186188
});
187189
promises.push(operation);
188190
});
@@ -192,6 +194,8 @@ function define_tests() {
192194
false, ["deriveKey"])
193195
.then(function(key) {
194196
noDeriveBitsKeys[algorithmName] = key;
197+
}, function (err) {
198+
noDeriveBitsKeys[algorithmName] = null;
195199
});
196200
promises.push(operation);
197201
});
@@ -201,6 +205,8 @@ function define_tests() {
201205
false, [])
202206
.then(function(key) {
203207
publicKeys[algorithmName] = key;
208+
}, function (err) {
209+
publicKeys[algorithmName] = null;
204210
});
205211
promises.push(operation);
206212
});

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function define_tests() {
127127
promise_test(function(test) {
128128
return subtle.generateKey({name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
129129
.then(function(secretKey) {
130-
subtle.deriveKey({name: algorithmName, public: secretKey}, privateKeys[algorithmName], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
130+
return subtle.deriveKey({name: algorithmName, public: secretKey}, privateKeys[algorithmName], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
131131
.then(function(key) {return crypto.subtle.exportKey("raw", key);})
132132
.then(function(exportedKey) {
133133
assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError");
@@ -151,6 +151,8 @@ function define_tests() {
151151
false, ["deriveBits", "deriveKey"])
152152
.then(function(key) {
153153
privateKeys[algorithmName] = key;
154+
}, function (err) {
155+
privateKeys[algorithmName] = null;
154156
});
155157
promises.push(operation);
156158
});
@@ -160,6 +162,8 @@ function define_tests() {
160162
false, ["deriveBits"])
161163
.then(function(key) {
162164
noDeriveKeyKeys[algorithmName] = key;
165+
}, function (err) {
166+
noDeriveKeyKeys[algorithmName] = null;
163167
});
164168
promises.push(operation);
165169
});
@@ -169,6 +173,8 @@ function define_tests() {
169173
false, [])
170174
.then(function(key) {
171175
publicKeys[algorithmName] = key;
176+
}, function (err) {
177+
publicKeys[algorithmName] = null;
172178
});
173179
promises.push(operation);
174180
});

test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function define_tests() {
165165
promise_test(function(test) {
166166
return subtle.generateKey({name: "AES-CBC", length: 128}, true, ["encrypt", "decrypt"])
167167
.then(function(secretKey) {
168-
subtle.deriveBits({name: "ECDH", public: secretKey}, privateKeys[namedCurve], 8 * sizes[namedCurve])
168+
return subtle.deriveBits({name: "ECDH", public: secretKey}, privateKeys[namedCurve], 8 * sizes[namedCurve])
169169
.then(function(derivation) {
170170
assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError");
171171
}, function(err) {
@@ -199,6 +199,8 @@ function define_tests() {
199199
false, ["deriveBits", "deriveKey"])
200200
.then(function(key) {
201201
privateKeys[namedCurve] = key;
202+
}, function (err) {
203+
privateKeys[namedCurve] = null;
202204
});
203205
promises.push(operation);
204206
});
@@ -208,6 +210,8 @@ function define_tests() {
208210
false, ["deriveKey"])
209211
.then(function(key) {
210212
noDeriveBitsKeys[namedCurve] = key;
213+
}, function (err) {
214+
noDeriveBitsKeys[namedCurve] = null;
211215
});
212216
promises.push(operation);
213217
});
@@ -217,13 +221,17 @@ function define_tests() {
217221
false, [])
218222
.then(function(key) {
219223
publicKeys[namedCurve] = key;
224+
}, function (err) {
225+
publicKeys[namedCurve] = null;
220226
});
221227
promises.push(operation);
222228
});
223229
Object.keys(sizes).forEach(function(namedCurve) {
224230
var operation = subtle.generateKey({name: "ECDSA", namedCurve: namedCurve}, false, ["sign", "verify"])
225231
.then(function(keyPair) {
226232
ecdsaKeyPairs[namedCurve] = keyPair;
233+
}, function (err) {
234+
ecdsaKeyPairs[namedCurve] = null;
227235
});
228236
promises.push(operation);
229237
});

test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function define_tests() {
143143
promise_test(function(test) {
144144
return subtle.generateKey({name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
145145
.then(function(secretKey) {
146-
subtle.deriveKey({name: "ECDH", public: secretKey}, privateKeys[namedCurve], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
146+
return subtle.deriveKey({name: "ECDH", public: secretKey}, privateKeys[namedCurve], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
147147
.then(function(key) {return crypto.subtle.exportKey("raw", key);})
148148
.then(function(exportedKey) {
149149
assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError");
@@ -168,6 +168,8 @@ function define_tests() {
168168
false, ["deriveBits", "deriveKey"])
169169
.then(function(key) {
170170
privateKeys[namedCurve] = key;
171+
}, function (err) {
172+
privateKeys[namedCurve] = null;
171173
});
172174
promises.push(operation);
173175
});
@@ -177,6 +179,8 @@ function define_tests() {
177179
false, ["deriveBits"])
178180
.then(function(key) {
179181
noDeriveKeyKeys[namedCurve] = key;
182+
}, function (err) {
183+
noDeriveKeyKeys[namedCurve] = null;
180184
});
181185
promises.push(operation);
182186
});
@@ -186,13 +190,17 @@ function define_tests() {
186190
false, [])
187191
.then(function(key) {
188192
publicKeys[namedCurve] = key;
193+
}, function (err) {
194+
publicKeys[namedCurve] = null;
189195
});
190196
promises.push(operation);
191197
});
192198
Object.keys(sizes).forEach(function(namedCurve) {
193199
var operation = subtle.generateKey({name: "ECDSA", namedCurve: namedCurve}, false, ["sign", "verify"])
194200
.then(function(keyPair) {
195201
ecdsaKeyPairs[namedCurve] = keyPair;
202+
}, function (err) {
203+
ecdsaKeyPairs[namedCurve] = null;
196204
});
197205
promises.push(operation);
198206
});

test/fixtures/wpt/WebCryptoAPI/util/helpers.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,22 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {
110110
assert_equals(key.extractable, extractable, "Extractability is correct");
111111

112112
assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name");
113-
assert_equals(key.algorithm.length, algorithm.length, "Correct length");
113+
if (key.algorithm.name.toUpperCase() === "HMAC" && algorithm.length === undefined) {
114+
switch (key.algorithm.hash.name.toUpperCase()) {
115+
case 'SHA-1':
116+
case 'SHA-256':
117+
assert_equals(key.algorithm.length, 512, "Correct length");
118+
break;
119+
case 'SHA-384':
120+
case 'SHA-512':
121+
assert_equals(key.algorithm.length, 1024, "Correct length");
122+
break;
123+
default:
124+
assert_unreached("Unrecognized hash");
125+
}
126+
} else {
127+
assert_equals(key.algorithm.length, algorithm.length, "Correct length");
128+
}
114129
if (["HMAC", "RSASSA-PKCS1-v1_5", "RSA-PSS"].includes(registeredAlgorithmName)) {
115130
assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function");
116131
}
@@ -166,12 +181,16 @@ function allAlgorithmSpecifiersFor(algorithmName) {
166181
});
167182
} else if (algorithmName.toUpperCase() === "HMAC") {
168183
[
169-
{name: "SHA-1", length: 160},
170-
{name: "SHA-256", length: 256},
171-
{name: "SHA-384", length: 384},
172-
{name: "SHA-512", length: 512}
184+
{hash: "SHA-1", length: 160},
185+
{hash: "SHA-256", length: 256},
186+
{hash: "SHA-384", length: 384},
187+
{hash: "SHA-512", length: 512},
188+
{hash: "SHA-1"},
189+
{hash: "SHA-256"},
190+
{hash: "SHA-384"},
191+
{hash: "SHA-512"},
173192
].forEach(function(hashAlgorithm) {
174-
results.push({name: algorithmName, hash: hashAlgorithm.name, length: hashAlgorithm.length});
193+
results.push({name: algorithmName, ...hashAlgorithm});
175194
});
176195
} else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") {
177196
hashes.forEach(function(hashName) {

test/fixtures/wpt/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"path": "wasm/webapi"
8585
},
8686
"WebCryptoAPI": {
87-
"commit": "edca84af42bd7e84da94e63b322fe343191842d2",
87+
"commit": "0042d42ee69baf05a4ac4f5745be9c3b92c04e25",
8888
"path": "WebCryptoAPI"
8989
},
9090
"webidl/ecmascript-binding/es-exceptions": {

0 commit comments

Comments
 (0)