Commit b651c9a6 authored by ap@apple.com's avatar ap@apple.com

WebCrypto no longer uses sequences of ArrayBuffers

https://bugs.webkit.org/show_bug.cgi?id=124451

Reviewed by Sam Weinig.

Source/WebCore: 

Covered by existing tests.

Changed all operations to take single CryptoOperationData objects.

* bindings/js/JSCryptoOperationData.cpp:
* bindings/js/JSCryptoOperationData.h:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::JSSubtleCrypto::encrypt):
(WebCore::JSSubtleCrypto::decrypt):
(WebCore::JSSubtleCrypto::sign):
(WebCore::JSSubtleCrypto::verify):
(WebCore::JSSubtleCrypto::digest):
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::encrypt):
(WebCore::CryptoAlgorithm::decrypt):
(WebCore::CryptoAlgorithm::sign):
(WebCore::CryptoAlgorithm::verify):
(WebCore::CryptoAlgorithm::digest):
* crypto/CryptoAlgorithm.h:
* crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
* crypto/algorithms/CryptoAlgorithmAES_CBC.h:
* crypto/algorithms/CryptoAlgorithmHMAC.h:
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
* crypto/algorithms/CryptoAlgorithmSHA1.cpp:
(WebCore::CryptoAlgorithmSHA1::digest):
* crypto/algorithms/CryptoAlgorithmSHA1.h:
* crypto/algorithms/CryptoAlgorithmSHA224.cpp:
(WebCore::CryptoAlgorithmSHA224::digest):
* crypto/algorithms/CryptoAlgorithmSHA224.h:
* crypto/algorithms/CryptoAlgorithmSHA256.cpp:
(WebCore::CryptoAlgorithmSHA256::digest):
* crypto/algorithms/CryptoAlgorithmSHA256.h:
* crypto/algorithms/CryptoAlgorithmSHA384.cpp:
(WebCore::CryptoAlgorithmSHA384::digest):
* crypto/algorithms/CryptoAlgorithmSHA384.h:
* crypto/algorithms/CryptoAlgorithmSHA512.cpp:
(WebCore::CryptoAlgorithmSHA512::digest):
* crypto/algorithms/CryptoAlgorithmSHA512.h:
* crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
(WebCore::transformAES_CBC):
(WebCore::CryptoAlgorithmAES_CBC::encrypt):
(WebCore::CryptoAlgorithmAES_CBC::decrypt):
* crypto/mac/CryptoAlgorithmHMACMac.cpp:
(WebCore::calculateSignature):
(WebCore::CryptoAlgorithmHMAC::sign):
(WebCore::CryptoAlgorithmHMAC::verify):
* crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:

LayoutTests: 

Updated tests accordingly.

* crypto/subtle/aes-cbc-192-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-256-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html:
* crypto/subtle/aes-cbc-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-import-jwk.html:
* crypto/subtle/aes-cbc-wrong-key-class-expected.txt:
* crypto/subtle/aes-cbc-wrong-key-class.html:
* crypto/subtle/argument-conversion-expected.txt:
* crypto/subtle/argument-conversion.html:
* crypto/subtle/hmac-import-jwk.html:
* crypto/subtle/hmac-sign-verify-empty-key.html:
* crypto/subtle/hmac-sign-verify.html:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html:
* crypto/subtle/sha-1-expected.txt:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224-expected.txt:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256-expected.txt:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384-expected.txt:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512-expected.txt:
* crypto/subtle/sha-512.html:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159379 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 40a88fcc
2013-11-16 Alexey Proskuryakov <ap@apple.com>
WebCrypto no longer uses sequences of ArrayBuffers
https://bugs.webkit.org/show_bug.cgi?id=124451
Reviewed by Sam Weinig.
Updated tests accordingly.
* crypto/subtle/aes-cbc-192-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-256-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html:
* crypto/subtle/aes-cbc-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-import-jwk.html:
* crypto/subtle/aes-cbc-wrong-key-class-expected.txt:
* crypto/subtle/aes-cbc-wrong-key-class.html:
* crypto/subtle/argument-conversion-expected.txt:
* crypto/subtle/argument-conversion.html:
* crypto/subtle/hmac-import-jwk.html:
* crypto/subtle/hmac-sign-verify-empty-key.html:
* crypto/subtle/hmac-sign-verify.html:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html:
* crypto/subtle/sha-1-expected.txt:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224-expected.txt:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256-expected.txt:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384-expected.txt:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512-expected.txt:
* crypto/subtle/sha-512.html:
2013-11-15 Alexey Proskuryakov <ap@apple.com>
Support exporting symmetric keys as JWK
......
......@@ -28,13 +28,13 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
shouldBe("key.usages", "['encrypt', 'decrypt']");
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
}).then(function(result) {
encryptionResult = result;
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
}).then(function(result) {
decryptionResult = result;
shouldBe("new Uint8Array(decryptionResult)", "plaintext");
......
......@@ -28,13 +28,13 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
shouldBe("key.usages", "['encrypt', 'decrypt']");
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
}).then(function(result) {
encryptionResult = result;
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
}).then(function(result) {
decryptionResult = result;
shouldBe("new Uint8Array(decryptionResult)", "plaintext");
......
......@@ -14,10 +14,10 @@ PASS bytesToHexString(new Uint8Array(encryptionResult)) is '7649abac8119b246cee9
Decrypting it back...
PASS new Uint8Array(decryptionResult) is plaintext
Testing initialization vector bindings...
PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, [plaintext]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.encrypt({name: 'AES-CBC'}, key, [plaintext]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, [plaintext]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, [plaintext]) threw exception Error: AES-CBC initialization data must be 16 bytes.
PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, plaintext) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.encrypt({name: 'AES-CBC'}, key, plaintext) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, plaintext) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, plaintext) threw exception Error: AES-CBC initialization data must be 16 bytes.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -28,13 +28,13 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
shouldBe("key.usages", "['encrypt', 'decrypt']");
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
}).then(function(result) {
cyphertext = result;
shouldBe("bytesToHexString(new Uint8Array(cyphertext))", "'630199c5f202cc7167bb84c6c72b349d'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
}).then(function(result) {
decryptionResult = result;
shouldBe("new Uint8Array(decryptionResult)", "plaintext");
......
......@@ -28,22 +28,22 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
shouldBe("key.usages", "['encrypt', 'decrypt']");
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
}).then(function(result) {
encryptionResult = result;
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
}).then(function(result) {
decryptionResult = result;
shouldBe("new Uint8Array(decryptionResult)", "plaintext");
debug("Testing initialization vector bindings...");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, [plaintext])");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC'}, key, [plaintext])");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, [plaintext])");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, [plaintext])");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, plaintext)");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC'}, key, plaintext)");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, plaintext)");
shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, plaintext)");
finishJSTest();
});
......
......@@ -39,7 +39,7 @@ crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, null, false, ["encrypt"]).th
shouldBe("key.usages", '["encrypt"]');
debug("\nUsing the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
}).then(function(result) {
encryptionResult = result;
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'");
......
......@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Importing a raw HMAC key from string literal...
Using the key to encrypt plaintext...
PASS crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext) threw exception Error: NotSupportedError: DOM Exception 9.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -22,7 +22,7 @@ debug("Importing a raw HMAC key from string literal...");
crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, extractable, ["sign", "verify", "encrypt", "decrypt"]).then(function(result) {
key = result;
debug("Using the key to encrypt plaintext...");
shouldThrow('crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext])')
shouldThrow('crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext)')
finishJSTest();
});
......
......@@ -3,8 +3,6 @@ Test crypto.subtle argument conversion
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
SHA1 of new Uint8Array([]))
PASS bytesToHexString(new Uint8Array(digest)) is 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
Passing algorithm name as a string object...
PASS ...succeeded
......@@ -17,23 +15,23 @@ PASS ...succeeded
Passing invalid data to digest()
PASS crypto.subtle.digest({name: 'sha-1'}) threw exception TypeError: Not enough arguments.
PASS crypto.subtle.digest({name: 'sha-1'}, null) threw exception TypeError: Value is not a sequence.
PASS crypto.subtle.digest({name: 'sha-1'}, 10) threw exception TypeError: Value is not a sequence.
PASS crypto.subtle.digest({name: 'sha-1'}, [10]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be part of CryptoOperationData sequence.
PASS crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0])) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be part of CryptoOperationData sequence.
PASS crypto.subtle.digest({name: 'sha-1'}, null) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.digest({name: 'sha-1'}, 10) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.digest({name: 'sha-1'}, [10]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
PASS crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
Passing invalid algorithmIdentifiers to digest()
PASS crypto.subtle.digest({ toString:function() { return 'sha-1' } }, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: ''}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: null}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: undefined}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: 'sha'}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: 1}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest('', [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest(null, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest(undefined, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest(1, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({ toString:function() { return 'sha-1' } }, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: ''}, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: null}, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: undefined}, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: 'sha'}, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({name: 1}, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest('', data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest(null, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest(undefined, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest(1, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS crypto.subtle.digest({}, data) threw exception Error: NotSupportedError: DOM Exception 9.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -14,24 +14,16 @@ description("Test crypto.subtle argument conversion");
jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
// This looks like invalid input, but it actually isn't - Uint8Array is a sequence too,
// so it's just an empty sequence, same as passing [].
debug("SHA1 of new Uint8Array([]))");
return crypto.subtle.digest('sha-1', new Uint8Array([]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'da39a3ee5e6b4b0d3255bfef95601890afd80709'");
debug("\nPassing algorithm name as a string object...");
return crypto.subtle.digest(new String('sha-1'), []);
return crypto.subtle.digest(new String('sha-1'), new Uint8Array([]));
}).then(function(result) {
testPassed("...succeeded");
debug("\nPassing algorithm name as a string object in a dictionary...");
return crypto.subtle.digest({name: new String('sha-1')}, []);
return crypto.subtle.digest({name: new String('sha-1')}, new Uint8Array([]));
}).then(function(result) {
testPassed("...succeeded");
debug("\nPassing algorithm name as an object with toString");
return crypto.subtle.digest({name: { toString:function() { return 'sha-1' } } }, []);
return crypto.subtle.digest({name: { toString:function() { return 'sha-1' } } }, new Uint8Array([]));
}).then(function(result) {
testPassed("...succeeded");
......@@ -40,21 +32,21 @@ Promise.fulfill(null).then(function() {
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, [10])");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]))");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])])");
debug("\nPassing invalid algorithmIdentifiers to digest()");
data = new Uint8Array([0]);
shouldThrow("crypto.subtle.digest({ toString:function() { return 'sha-1' } }, [data])"); // Algorithm normalization doesn't attempt to call toString.
shouldThrow("crypto.subtle.digest({name: ''}, [data])");
shouldThrow("crypto.subtle.digest({name: null}, [data])");
shouldThrow("crypto.subtle.digest({name: undefined}, [data])");
shouldThrow("crypto.subtle.digest({name: 'sha'}, [data])");
shouldThrow("crypto.subtle.digest({name: 1}, [data])");
shouldThrow("crypto.subtle.digest('', [data])");
shouldThrow("crypto.subtle.digest(null, [data])");
shouldThrow("crypto.subtle.digest(undefined, [data])");
shouldThrow("crypto.subtle.digest(1, [data])");
shouldThrow("crypto.subtle.digest({}, [data])");
shouldThrow("crypto.subtle.digest({ toString:function() { return 'sha-1' } }, data)"); // Algorithm normalization doesn't attempt to call toString.
shouldThrow("crypto.subtle.digest({name: ''}, data)");
shouldThrow("crypto.subtle.digest({name: null}, data)");
shouldThrow("crypto.subtle.digest({name: undefined}, data)");
shouldThrow("crypto.subtle.digest({name: 'sha'}, data)");
shouldThrow("crypto.subtle.digest({name: 1}, data)");
shouldThrow("crypto.subtle.digest('', data)");
shouldThrow("crypto.subtle.digest(null, data)");
shouldThrow("crypto.subtle.digest(undefined, data)");
shouldThrow("crypto.subtle.digest(1, data)");
shouldThrow("crypto.subtle.digest({}, data)");
}).then(finishJSTest);
</script>
......
......@@ -36,13 +36,13 @@ crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, null, extractable, ["sign",
shouldBe("key.usages", '["sign", "verify"]');
debug("\nUsing the key to sign message 'foo'...");
return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
}).then(function(result) {
signature = result;
shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
debug("\nVerifying the signature...");
return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
......
......@@ -27,13 +27,13 @@ crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, e
shouldBe("key.usages", "['sign', 'verify']");
debug("Using the key to sign 'foo'...");
return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
}).then(function(result) {
signature = result;
shouldBe("bytesToHexString(new Uint8Array(signature))", "'a3cc770fc033e2cb419d42b64e0081a3bd3be30e'");
debug("Verifying the signature...");
return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
......
......@@ -27,13 +27,13 @@ crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, e
shouldBe("key.usages", "['sign', 'verify']");
debug("Using the key to sign 'foo'...");
return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
}).then(function(result) {
signature = result;
shouldBe("bytesToHexString(new Uint8Array(signature))", "'bebbc02e46b0f81183f40c25dce23e5045d65519'");
debug("Verifying the signature...");
return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
......
......@@ -45,18 +45,18 @@ crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(publicKeyJSON)),
}).then(function(result) {
privateKey = result;
debug("\nSigning some text...");
return crypto.subtle.sign({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, privateKey, [data]);
return crypto.subtle.sign({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, privateKey, data);
}).then(function(result) {
signature = result;
shouldBe("bytesToHexString(new Uint8Array(signature))", "'0fd9a8aef4cc1876c0b762545336c6d1fb315ae16ae4b5e4bf34d384d8585ea7a01e76ea09ee7f7ee8d1c122e7dd15b7c94a573b2aa07203e8d13bc6fd16156cd8e5f0c15a15dccb62d152127fca09882fb53bc3e60ab586d15b95cf411e3aab4a1c231a7e91aab09ee3d4b13d11e97505ddff77683470da510ee76e8bd530c56a85f901626a5a710f716f113dfe9cf6c473ee16fa248aea3480a1033abe30f4c1243289a661e64d7818b55698280688097135968c6d4b029496d85cab2a67e4696737781f70e4392c7df71bbd6c92465947f029a1de48160aced11b5721b1cd25039fe2c16c2b38de73df3b9a83e3ea755fd0cfe51ca06b61fadf6d84677f95'");
debug("\nVerifying the signature...");
return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, signature, [data]);
return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, signature, data);
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "true");
debug("\nVerifying a bad signature...");
return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, new Uint8Array(256), [data]);
return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, new Uint8Array(256), data);
}).then(function(result) {
verificationResult = result;
shouldBe("verificationResult", "false");
......
......@@ -9,8 +9,6 @@ SHA1 of [0x0]
PASS bytesToHexString(new Uint8Array(digest)) is '5ba93c9db0cff93f52b521d7420e43f6eda2784f'
SHA1 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
PASS bytesToHexString(new Uint8Array(digest)) is '2c7e7c384f7829694282b1e3a6216def8082d055'
SHA1 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
PASS bytesToHexString(new Uint8Array(digest)) is '2c7e7c384f7829694282b1e3a6216def8082d055'
PASS crypto.subtle.generateKey('sha-1') threw exception Error: NotSupportedError: DOM Exception 9.
PASS successfullyParsed is true
......
......@@ -15,29 +15,24 @@ jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
debug("SHA1 of []");
return crypto.subtle.digest('sha-1', [new Uint8Array([])]);
return crypto.subtle.digest('sha-1', new Uint8Array([]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'da39a3ee5e6b4b0d3255bfef95601890afd80709'");
debug("SHA1 of [0x0]")
return crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])]);
return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'5ba93c9db0cff93f52b521d7420e43f6eda2784f'");
debug("SHA1 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
return crypto.subtle.digest({name: 'sha-1'}, [data]);
return crypto.subtle.digest({name: 'sha-1'}, data);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'2c7e7c384f7829694282b1e3a6216def8082d055'");
debug("SHA1 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
return crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'2c7e7c384f7829694282b1e3a6216def8082d055'");
// All SHA-1 can do is digest.
shouldThrow("crypto.subtle.generateKey('sha-1')");
finishJSTest();
......
......@@ -9,8 +9,6 @@ SHA224 of [0x0]
PASS bytesToHexString(new Uint8Array(digest)) is 'fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073'
SHA224 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
PASS bytesToHexString(new Uint8Array(digest)) is '767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'
SHA224 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
PASS bytesToHexString(new Uint8Array(digest)) is '767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -15,26 +15,20 @@ jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
debug("SHA224 of []");
return crypto.subtle.digest('sha-224', [new Uint8Array([])]);
return crypto.subtle.digest('sha-224', new Uint8Array([]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f'");
debug("SHA224 of [0x0]")
return crypto.subtle.digest({name: 'sha-224'}, [new Uint8Array([0])]);
return crypto.subtle.digest({name: 'sha-224'}, new Uint8Array([0]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073'");
debug("SHA224 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
return crypto.subtle.digest({name: 'sha-224'}, [data]);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'");
debug("SHA224 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
return crypto.subtle.digest({name: 'sha-224'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
return crypto.subtle.digest({name: 'sha-224'}, data);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'");
......
......@@ -9,8 +9,6 @@ SHA256 of [0x0]
PASS bytesToHexString(new Uint8Array(digest)) is '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d'
SHA256 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
PASS bytesToHexString(new Uint8Array(digest)) is '78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'
SHA256 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
PASS bytesToHexString(new Uint8Array(digest)) is '78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -15,26 +15,20 @@ jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
debug("SHA256 of []");
return crypto.subtle.digest('sha-256', [new Uint8Array([])]);
return crypto.subtle.digest('sha-256', new Uint8Array([]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'");
debug("SHA256 of [0x0]")
return crypto.subtle.digest({name: 'sha-256'}, [new Uint8Array([0])]);
return crypto.subtle.digest({name: 'sha-256'}, new Uint8Array([0]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d'");
debug("SHA256 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
return crypto.subtle.digest({name: 'sha-256'}, [data]);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'");
debug("SHA256 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
return crypto.subtle.digest({name: 'sha-256'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
return crypto.subtle.digest({name: 'sha-256'}, data);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'");
......
......@@ -9,8 +9,6 @@ SHA384 of [0x0]
PASS bytesToHexString(new Uint8Array(digest)) is 'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717'
SHA384 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
PASS bytesToHexString(new Uint8Array(digest)) is '89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'
SHA384 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
PASS bytesToHexString(new Uint8Array(digest)) is '89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -15,26 +15,20 @@ jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
debug("SHA384 of []");
return crypto.subtle.digest('sha-384', [new Uint8Array([])]);
return crypto.subtle.digest('sha-384', new Uint8Array([]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'");
debug("SHA384 of [0x0]")
return crypto.subtle.digest({name: 'sha-384'}, [new Uint8Array([0])]);
return crypto.subtle.digest({name: 'sha-384'}, new Uint8Array([0]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717'");
debug("SHA384 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
return crypto.subtle.digest({name: 'sha-384'}, [data]);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'");
debug("SHA384 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
return crypto.subtle.digest({name: 'sha-384'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
return crypto.subtle.digest({name: 'sha-384'}, data);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'");
......
......@@ -9,8 +9,6 @@ SHA512 of [0x0]
PASS bytesToHexString(new Uint8Array(digest)) is 'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee'
SHA512 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
PASS bytesToHexString(new Uint8Array(digest)) is '8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'
SHA512 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
PASS bytesToHexString(new Uint8Array(digest)) is '8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -15,26 +15,20 @@ jsTestIsAsync = true;
Promise.fulfill(null).then(function() {
debug("SHA512 of []");
return crypto.subtle.digest('sha-512', [new Uint8Array([])]);
return crypto.subtle.digest('sha-512', new Uint8Array([]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e'");
debug("SHA512 of [0x0]")
return crypto.subtle.digest({name: 'sha-512'}, [new Uint8Array([0])]);
return crypto.subtle.digest({name: 'sha-512'}, new Uint8Array([0]));
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee'");
debug("SHA512 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
return crypto.subtle.digest({name: 'sha-512'}, [data]);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'");
debug("SHA512 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
return crypto.subtle.digest({name: 'sha-512'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
return crypto.subtle.digest({name: 'sha-512'}, data);
}).then(function(result) {
digest = result;
shouldBe("bytesToHexString(new Uint8Array(digest))", "'8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'");
......
2013-11-16 Alexey Proskuryakov <ap@apple.com>
WebCrypto no longer uses sequences of ArrayBuffers
https://bugs.webkit.org/show_bug.cgi?id=124451
Reviewed by Sam Weinig.
Covered by existing tests.
Changed all operations to take single CryptoOperationData objects.
* bindings/js/JSCryptoOperationData.cpp:
* bindings/js/JSCryptoOperationData.h:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::JSSubtleCrypto::encrypt):
(WebCore::JSSubtleCrypto::decrypt):
(WebCore::JSSubtleCrypto::sign):
(WebCore::JSSubtleCrypto::verify):
(WebCore::JSSubtleCrypto::digest):
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::encrypt):