| Index: LayoutTests/crypto/normalize-algorithm.html
|
| diff --git a/LayoutTests/crypto/normalize-algorithm.html b/LayoutTests/crypto/normalize-algorithm.html
|
| index e3fea0d633f04d13cbb06d2417e2e36c0944fcd9..c867fd469131cdf74412e081145f8debaca699ef 100644
|
| --- a/LayoutTests/crypto/normalize-algorithm.html
|
| +++ b/LayoutTests/crypto/normalize-algorithm.html
|
| @@ -22,20 +22,21 @@ jsTestIsAsync = true;
|
|
|
| aesCbcKey = null;
|
| hmacSha1Key = null;
|
| +rsaSsaKey = null;
|
|
|
| function normalizeDigest(algorithmIdentifier)
|
| {
|
| return crypto.subtle.digest(algorithmIdentifier).algorithm;
|
| }
|
|
|
| -function normalizeEncrypt(algorithmIdentifier)
|
| +function normalizeEncrypt(algorithmIdentifier, key)
|
| {
|
| - return crypto.subtle.encrypt(algorithmIdentifier, aesCbcKey).algorithm;
|
| + return crypto.subtle.encrypt(algorithmIdentifier, key).algorithm;
|
| }
|
|
|
| -function normalizeSign(algorithmIdentifier)
|
| +function normalizeSign(algorithmIdentifier, key)
|
| {
|
| - return crypto.subtle.sign(algorithmIdentifier, hmacSha1Key).algorithm;
|
| + return crypto.subtle.sign(algorithmIdentifier, key).algorithm;
|
| }
|
|
|
| function runTests()
|
| @@ -76,7 +77,7 @@ function runTests()
|
| // Normalized algorithm COPIES all data
|
| // -------------------------------
|
| originalIv = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
|
| - algorithm = normalizeEncrypt({ name: "aes-cbc", iv: originalIv });
|
| + algorithm = normalizeEncrypt({ name: "aes-cbc", iv: originalIv }, aesCbcKey);
|
|
|
| // Make sure it constructed the normalized result.
|
| shouldBe("algorithm.name", "'AES-CBC'");
|
| @@ -96,7 +97,7 @@ function runTests()
|
| name: "AES-CBC",
|
| iv: new Uint8Array([1, 2, 3])
|
| };
|
| - shouldThrow("normalizeEncrypt(rawAlgorithm)");
|
| + shouldThrow("normalizeEncrypt(rawAlgorithm, aesCbcKey)");
|
|
|
| // -------------------------------
|
| // Normalize a normalized algorithm (SHA-384)
|
| @@ -109,12 +110,12 @@ function runTests()
|
| // -------------------------------
|
| // Normalize a normalized algorithm (AES-CBC, encrypt)
|
| // -------------------------------
|
| - algorithm = normalizeEncrypt({ name: "aEs-cbc", iv: originalIv });
|
| + algorithm = normalizeEncrypt({ name: "aEs-cbc", iv: originalIv }, aesCbcKey);
|
| // Make sure it constructed the normalized result.
|
| shouldBe("algorithm.name", "'AES-CBC'");
|
| shouldBe("algorithm.iv.length", "16");
|
| shouldBe("algorithm.iv[1]", "1");
|
| - algorithm = normalizeEncrypt(algorithm);
|
| + algorithm = normalizeEncrypt(algorithm, aesCbcKey);
|
| shouldBe("algorithm.name", "'AES-CBC'");
|
| shouldBe("algorithm.iv.length", "16");
|
| shouldBe("algorithm.iv[1]", "1");
|
| @@ -122,22 +123,38 @@ function runTests()
|
| // -------------------------------
|
| // Unsupported operation on algorithm
|
| // -------------------------------
|
| - shouldThrow("normalizeEncrypt({ name: 'SHA-1' })");
|
| + shouldThrow("normalizeEncrypt({ name: 'SHA-1' }, aesCbcKey)");
|
| shouldThrow("normalizeDigest({ name: 'AES-CBC', iv: originalIv })");
|
|
|
| // -------------------------------
|
| // Normalize HMAC
|
| // -------------------------------
|
| - shouldThrow("normalizeSign({name: 'hmac'})"); // Missing "hash"
|
| - shouldThrow("normalizeSign({name: 'hmac', hash: 'foo'})"); // Not a valid "hash"
|
| - shouldThrow("normalizeSign({name: 'hmac', hash: { name: 'AES-CBC', iv: originalIv }})"); // Not a valid "hash"
|
| + shouldThrow("normalizeSign({name: 'hmac'}, hmacSha1Key)"); // Missing "hash"
|
| + shouldThrow("normalizeSign({name: 'hmac', hash: 'foo'}, hmacSha1Key)"); // Not a valid "hash"
|
| + shouldThrow("normalizeSign({name: 'hmac', hash: { name: 'AES-CBC', iv: originalIv }}, hmacSha1Key)"); // Not a valid "hash"
|
|
|
| validHmacSha1 = {name: 'hmac', hash: {name: 'Sha-1'}};
|
| - algorithm = normalizeSign(validHmacSha1);
|
| + algorithm = normalizeSign(validHmacSha1, hmacSha1Key);
|
| shouldBe("algorithm.name", "'HMAC'");
|
| shouldBe("algorithm.hash.name", "'SHA-1'");
|
|
|
| - shouldThrow("normalizeEncrypt(validHmacSha1)"); // Not defined for encrypt()
|
| + shouldThrow("normalizeEncrypt(validHmacSha1, hmacSha1Key)"); // Not defined for encrypt()
|
| +
|
| + // -------------------------------
|
| + // Normalize RSASSA-PKCS1-v1_5
|
| + // -------------------------------
|
| + shouldThrow("normalizeSign({name: 'RSASSA-PKCS1-v1_5'}, rsaSsaKey)"); // Missing "hash"
|
| + shouldThrow("normalizeSign({name: 'RSASSA-PKCS1-v1_5', hash: 'foo'}, rsaSsaKey)"); // Not a valid "hash"
|
| + shouldThrow("normalizeSign({name: 'RSASSA-PKCS1-v1_5', hash: { name: 'AES-CBC', iv: originalIv }}, rsaSsaKey)"); // Not a valid "hash"
|
| +
|
| + validRsaSsa = {name: 'RsaSsa-PKCS1-v1_5', hash: {name: 'Sha-256'}};
|
| + algorithm = normalizeSign(validRsaSsa, rsaSsaKey);
|
| + shouldBe("algorithm.name", "'RSASSA-PKCS1-v1_5'");
|
| + shouldBe("algorithm.hash.name", "'SHA-256'");
|
| +
|
| + shouldThrow("normalizeEncrypt(validRsaSsa, rsaSsaKey)"); // Not defined for encrypt()
|
| +
|
| + // FIXME: Test the normalization of RsaSsaKeyGen parameters.
|
|
|
| // -------------------------------
|
| // Try using a key for an unsupported operation.
|
| @@ -168,6 +185,17 @@ function importAesCbcKey(keyUsages)
|
| return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsages);
|
| }
|
|
|
| +function importRsaSsaKey()
|
| +{
|
| + var keyFormat = "spki";
|
| + var data = new Uint8Array([]);
|
| + var algorithm = {name: "RSASSA-PKCS1-v1_5"};
|
| + var extractable = false;
|
| + var keyUsages = ["encrypt", "decrypt", "verify", "sign"];
|
| +
|
| + return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsages);
|
| +}
|
| +
|
| function failedKeyImport(value)
|
| {
|
| debug("Failed importing key: " + value);
|
| @@ -176,11 +204,12 @@ function failedKeyImport(value)
|
|
|
| // Import two keys before starting the tests: one for AES-CBC, and one for
|
| // HMAC SHA1.
|
| -Promise.every(importAesCbcKey(['encrypt', 'decrypt', 'sign', 'verify']), importAesCbcKey(['decrypt', 'sign', 'verify']), importHmacSha1Key()).then(function(keys)
|
| +Promise.every(importAesCbcKey(['encrypt', 'decrypt', 'sign', 'verify']), importAesCbcKey(['decrypt', 'sign', 'verify']), importHmacSha1Key(), importRsaSsaKey()).then(function(keys)
|
| {
|
| aesCbcKey = keys[0];
|
| aesCbcKeyNoEncrypt = keys[1];
|
| hmacSha1Key = keys[2];
|
| + rsaSsaKey = keys[3];
|
|
|
| runTests();
|
| finishJSTest();
|
|
|