OLD | NEW |
| (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 unwrapping an HKDF key"); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 kHkdfKey = hexStringToUint8Array("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
; | |
17 kIv = new Uint8Array(16); | |
18 | |
19 var extractable = true; | |
20 var derivingKeyAlgorithm = { | |
21 name: "HKDF", | |
22 hash: "SHA-256", | |
23 salt: new Uint8Array(), | |
24 info: new Uint8Array() | |
25 }; | |
26 | |
27 Promise.resolve(null).then(function(result) { | |
28 // Create a key to use for wrapping/unwrapping | |
29 return crypto.subtle.generateKey({name: "AES-GCM", length: 256}, false, ['en
crypt', 'unwrapKey']); | |
30 }).then(function(result) { | |
31 wrappingKey = result; | |
32 | |
33 shouldEvaluateAs("wrappingKey.algorithm.name", "AES-GCM"); | |
34 shouldEvaluateAs("wrappingKey.extractable", false); | |
35 shouldEvaluateAs("wrappingKey.usages.join(',')", "encrypt,unwrapKey"); | |
36 | |
37 // Wrap the HKDF key. Since the HKDF algorithm does not support the export | |
38 // key operation, it is wrapped by calling encrypt. | |
39 return crypto.subtle.encrypt({name: "AES-GCM", length: 256, iv: kIv}, wrappi
ngKey, kHkdfKey); | |
40 }).then(function(result) { | |
41 wrappedKey = result; | |
42 | |
43 // Unwrap it as a raw key. | |
44 return crypto.subtle.unwrapKey("raw", wrappedKey, wrappingKey, {name: "AES-G
CM", length: 256, iv: kIv}, "HKDF", false, ['deriveBits']); | |
45 }).then(function(result) { | |
46 unwrappedHkdfKey = result; | |
47 | |
48 shouldEvaluateAs("unwrappedHkdfKey.algorithm.name", "HKDF"); | |
49 shouldEvaluateAs("unwrappedHkdfKey.extractable", false); | |
50 shouldEvaluateAs("unwrappedHkdfKey.usages.join(',')", "deriveBits"); | |
51 | |
52 debug("\nUnwrap an HKDF key using pkcs8 as the format."); | |
53 return crypto.subtle.unwrapKey("pkcs8", wrappedKey, wrappingKey, {name: "AES
-GCM", length: 256, iv: kIv}, "HKDF", false, ['deriveBits']); | |
54 }).then(failAndFinishJSTest, function(result) { | |
55 logError(result); | |
56 }).then(finishJSTest, failAndFinishJSTest); | |
57 | |
58 </script> | |
59 | |
60 </body> | |
61 </html> | |
OLD | NEW |