Chromium Code Reviews| Index: LayoutTests/crypto/subtle/hkdf-unwrapKey.html |
| diff --git a/LayoutTests/crypto/subtle/hkdf-unwrapKey.html b/LayoutTests/crypto/subtle/hkdf-unwrapKey.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f5d53c4f9ea7e96c9c5696f024eb754596612456 |
| --- /dev/null |
| +++ b/LayoutTests/crypto/subtle/hkdf-unwrapKey.html |
| @@ -0,0 +1,61 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<head> |
| +<script src="../../resources/js-test.js"></script> |
| +<script src="resources/common.js"></script> |
| +</head> |
| +<body> |
| +<p id="description"></p> |
| +<div id="console"></div> |
| + |
| +<script> |
| +description("Test unwrapping an HKDF key"); |
| + |
| +jsTestIsAsync = true; |
| + |
| +kHkdfKey = hexStringToUint8Array("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"); |
| +kIv = new Uint8Array(16); |
| + |
| +var extractable = true; |
| +var derivingKeyAlgorithm = { |
| + name: "HKDF", |
| + hash: "SHA-256", |
| + salt: new Uint8Array(), |
| + info: new Uint8Array() |
| +}; |
| + |
| +Promise.resolve(null).then(function(result) { |
| + // Create a key to use for wrapping/unwrapping |
| + return crypto.subtle.generateKey({name: "AES-GCM", length: 256}, false, ['encrypt', 'unwrapKey']); |
| +}).then(function(result) { |
| + wrappingKey = result; |
| + |
| + shouldEvaluateAs("wrappingKey.algorithm.name", "AES-GCM"); |
| + shouldEvaluateAs("wrappingKey.extractable", false); |
| + shouldEvaluateAs("wrappingKey.usages.join(',')", "encrypt,unwrapKey"); |
| + |
| + // Wrap the HKDF key. Since the HKDF algorithm does not support the export |
| + // key operation, I wrap it by calling encrypt. |
|
eroman
2015/01/07 01:18:44
Same comment as in another review: Avoid the use o
nharper
2015/01/09 22:41:47
Done.
|
| + return crypto.subtle.encrypt({name: "AES-GCM", length: 256, iv: kIv}, wrappingKey, kHkdfKey); |
| +}).then(function(result) { |
| + wrappedKey = result; |
| + |
| + // Unwrap it as a raw key. |
| + return crypto.subtle.unwrapKey("raw", wrappedKey, wrappingKey, {name: "AES-GCM", length: 256, iv: kIv}, "HKDF", false, ['deriveBits']); |
| +}).then(function(result) { |
| + unwrappedHkdfKey = result; |
| + |
| + shouldEvaluateAs("unwrappedHkdfKey.algorithm.name", "HKDF"); |
| + shouldEvaluateAs("unwrappedHkdfKey.extractable", false); |
| + shouldEvaluateAs("unwrappedHkdfKey.usages.join(',')", "deriveBits"); |
| + |
| + debug("\nUnwrapping an HKDF key from a format other than raw should fail."); |
| + return crypto.subtle.unwrapKey("pkcs8", wrappedKey, wrappingKey, {name: "AES-GCM", length: 256, iv: kIv}, "HKDF", false, ['deriveBits']); |
| +}).then(failAndFinishJSTest, function(result) { |
| + logError(result); |
| +}).then(finishJSTest, failAndFinishJSTest); |
| + |
| +</script> |
| + |
| +</body> |
| +</html> |