Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: LayoutTests/crypto/subtle/hkdf-deriveBits-failures.html

Issue 822083003: Webcrypto: add layout tests for HKDF algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10
11 <script>
12 description("Test bad inputs to HKDF deriveBits()");
13
14 jsTestIsAsync = true;
15
16 kHkdfKey = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b";
17
18 var extractable = true;
19 Promise.resolve(null).then(function(result) {
20 // set up the test by creating an HKDF key and an RSA key
eroman 2014/12/23 23:29:39 This comment is incorrect
nharper 2015/01/06 23:51:59 Done.
21 return crypto.subtle.importKey("raw", hexStringToUint8Array(kHkdfKey), {name: "HKDF"}, extractable, ['deriveKey', 'deriveBits']);
eroman 2014/12/23 23:29:39 4 space indentation throughout
nharper 2015/01/06 23:51:59 Done.
22 }).then(function(result) {
23 hkdfKey = result;
24
25 return crypto.subtle.generateKey({name: "ECDH", namedCurve: "P-256"}, true, [' deriveBits']);
26 }).then(function(result) {
27 ecdhKey = result;
28
29 // Should throw a NotSupportedError if hash does not describe a recognized
30 // algorithm that supports the digest operation.
31 debug("\nderiveBits() with an unsupported hash...");
32 return crypto.subtle.deriveBits({name: "HKDF", hash: "HMAC", salt: new Uint8Ar ray(), info: new Uint8Array()}, hkdfKey, 8);
33 }).then(failAndFinishJSTest, function(result) {
34 logError(result);
35
36 // Should throw an InvalidAccessError if key doesn't match the algorithm
37 debug("\nderiveBits() with a key that doesn't match the algorithm...");
38 return crypto.subtle.deriveBits({name: "HKDF", hash: "SHA-256", salt: new Uint 8Array(), info: new Uint8Array()}, ecdhKey.privateKey, 8);
39 }).then(failAndFinishJSTest, function(result) {
40 logError(result);
41
42 // Should throw an OperationError if the key derivation operation fails.
43 // The key derivation operation will fail here because the length is too long.
44 //
45 // The maximum length (in bytes) of output material for HKDF is 255 times the
46 // digest length. In this case, the digest length (in bytes) of SHA-256 is 32;
47 // 32*255 = 8160. deriveBits expects the length to be in bits, so 8160*8=65280
48 // and add 1 to exceed the maximum length.
49 debug("\nderiveBits() with requested length too long...");
50 return crypto.subtle.deriveBits({name: "HKDF", hash: "SHA-256", salt: new Uint 8Array(), info: new Uint8Array()}, hkdfKey, 65281);
51 }).then(failAndFinishJSTest, function(result) {
52 logError(result);
53
54 // TODO: move this out of this file
eroman 2014/12/23 23:29:39 (1) WebKit uses FIXME: style. (2) This seems like
nharper 2015/01/06 23:51:59 Done.
55 // Create a key with only deriveKey usages.
56 return crypto.subtle.importKey("raw", hexStringToUint8Array(kHkdfKey), {name: "HKDF"}, extractable, ['deriveKey']);
57 }).then(function(result) {
58 derivingKey = result;
59
60 return crypto.subtle.deriveKey({name: "HKDF", hash: "SHA-256", salt: new Uint8 Array(), info: new Uint8Array()}, derivingKey, {name: "AES-GCM", length: 256}, e xtractable, ['encrypt']);
61 }).then(function(result) {
62 derivedKey = result;
63
64 shouldEvaluateAs("derivedKey.type", "secret");
65 shouldEvaluateAs("derivedKey.extractable", true);
66 shouldEvaluateAs("derivedKey.algorithm.name", "AES-GCM");
67 shouldEvaluateAs("derivedKey.usages.join(',')", "encrypt");
68 }).then(finishJSTest, failAndFinishJSTest);
69
70 </script>
71
72 </body>
73 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698