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

Unified Diff: LayoutTests/crypto/subtle/hkdf-unwrapKey.html

Issue 822083003: Webcrypto: add layout tests for HKDF algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 months 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 side-by-side diff with in-line comments
Download patch
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..791e5ca2b8af95df831f24c44d09e32abf38dd00
--- /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, it is wrapped by calling encrypt.
+ 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>

Powered by Google App Engine
This is Rietveld 408576698