Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / hkdf / unwrapKey.html
blob1d381f09505345b2ff7debed67487a1181036f27
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>
11 <script>
12 description("Test unwrapping an HKDF key");
14 jsTestIsAsync = true;
16 kHkdfKey = hexStringToUint8Array("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
17 kIv = new Uint8Array(16);
19 var extractable = true;
20 var derivingKeyAlgorithm = {
21 name: "HKDF",
22 hash: "SHA-256",
23 salt: new Uint8Array(),
24 info: new Uint8Array()
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, ['encrypt', 'unwrapKey']);
30 }).then(function(result) {
31 wrappingKey = result;
33 shouldEvaluateAs("wrappingKey.algorithm.name", "AES-GCM");
34 shouldEvaluateAs("wrappingKey.extractable", false);
35 shouldEvaluateAs("wrappingKey.usages.join(',')", "encrypt,unwrapKey");
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}, wrappingKey, kHkdfKey);
40 }).then(function(result) {
41 wrappedKey = result;
43 // Unwrap it as a raw key.
44 return crypto.subtle.unwrapKey("raw", wrappedKey, wrappingKey, {name: "AES-GCM", length: 256, iv: kIv}, "HKDF", false, ['deriveBits']);
45 }).then(function(result) {
46 unwrappedHkdfKey = result;
48 shouldEvaluateAs("unwrappedHkdfKey.algorithm.name", "HKDF");
49 shouldEvaluateAs("unwrappedHkdfKey.extractable", false);
50 shouldEvaluateAs("unwrappedHkdfKey.usages.join(',')", "deriveBits");
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);
58 </script>
60 </body>
61 </html>