Commit 1ab645b4 authored by ap@apple.com's avatar ap@apple.com

WebCrypto wrapKey operation doesn't check key usage

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

Reviewed by Darin Adler.

Source/WebCore: 

Tests: crypto/subtle/unwrapKey-check-usage.html
       crypto/subtle/wrapKey-check-usage.html

* bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::JSSubtleCrypto::wrapKey):
Added accidentally omitted code. Other operations are fine.

LayoutTests: 

* crypto/subtle/unwrapKey-check-usage-expected.txt: Added.
* crypto/subtle/unwrapKey-check-usage.html: Added.
* crypto/subtle/wrapKey-check-usage-expected.txt: Added.
* crypto/subtle/wrapKey-check-usage.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160534 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bca07ebb
2013-12-12 Alexey Proskuryakov <ap@apple.com>
WebCrypto wrapKey operation doesn't check key usage
https://bugs.webkit.org/show_bug.cgi?id=125675
Reviewed by Darin Adler.
* crypto/subtle/unwrapKey-check-usage-expected.txt: Added.
* crypto/subtle/unwrapKey-check-usage.html: Added.
* crypto/subtle/wrapKey-check-usage-expected.txt: Added.
* crypto/subtle/wrapKey-check-usage.html: Added.
2013-12-12 Alexey Proskuryakov <ap@apple.com>
Add support for RSAES-PKCS1-v1_5
CONSOLE MESSAGE: Key usages do not include 'unwrapKey'
Verify that usage is respected in unwrapKey operation.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Importing RSA keys...
Importing an AES key...
Wrapping it...
Unwrapping it...
PASS crypto.subtle.unwrapKey("raw", wrappedKey, privateKey, wrapAlgorithm, "aes-cbc", extractable, ["encrypt", "decrypt"]) threw exception Error: NotSupportedError: DOM Exception 9.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Verify that usage is respected in unwrapKey operation.");
jsTestIsAsync = true;
var publicKeyJSON = {
kty: "RSA",
alg: "RSA-OAEP",
n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
e: "AQAB"
};
var privateKeyJSON = {
kty: "RSA",
alg: "RSA-OAEP",
n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
e: "AQAB",
d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk"
};
var wrapAlgorithm = {name: "RSA-OAEP", hash: "sha-1"};
var extractable = true;
var nonExtractable = false;
debug("Importing RSA keys...");
crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(publicKeyJSON)), null, extractable, ["wrapKey"]).then(function(result) {
publicKey = result;
return crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(privateKeyJSON)), null, extractable, ["encrypt", "decrypt", "wrapKey"]);
}).then(function(result) {
privateKey = result;
debug("Importing an AES key...");
aesKeyData = hexStringToUint8Array("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
return crypto.subtle.importKey("raw", aesKeyData, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])
}).then(function(result) {
aesKey = result;
debug("Wrapping it...");
return crypto.subtle.wrapKey("raw", aesKey, publicKey, wrapAlgorithm);
}).then(function(result) {
wrappedKey = result;
debug("Unwrapping it...");
// privateKey lacks unwrapKey usage.
shouldThrow('crypto.subtle.unwrapKey("raw", wrappedKey, privateKey, wrapAlgorithm, "aes-cbc", extractable, ["encrypt", "decrypt"])');
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
CONSOLE MESSAGE: Key usages do not include 'wrapKey'
Verify that usage is respected in wrapKey operation.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Importing an RSA key...
Importing an AES key...
Wrapping it...
PASS crypto.subtle.wrapKey("raw", aesKey, publicKey, wrapAlgorithm) threw exception Error: NotSupportedError: DOM Exception 9.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Verify that usage is respected in wrapKey operation.");
jsTestIsAsync = true;
var publicKeyJSON = {
kty: "RSA",
alg: "RSA-OAEP",
n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
e: "AQAB"
};
var wrapAlgorithm = {name: "RSA-OAEP", hash: "sha-1"};
var extractable = true;
var nonExtractable = false;
debug("Importing an RSA key...");
crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(publicKeyJSON)), null, extractable, ["encrypt", "decrypt", "unwrapKey"]).then(function(result) {
publicKey = result;
debug("Importing an AES key...");
aesKeyData = hexStringToUint8Array("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
return crypto.subtle.importKey("raw", aesKeyData, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])
}).then(function(result) {
aesKey = result;
debug("Wrapping it...");
// publicKey lacks wrapKey usage.
shouldThrow('crypto.subtle.wrapKey("raw", aesKey, publicKey, wrapAlgorithm)');
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
2013-12-12 Alexey Proskuryakov <ap@apple.com>
WebCrypto wrapKey operation doesn't check key usage
https://bugs.webkit.org/show_bug.cgi?id=125675
Reviewed by Darin Adler.
Tests: crypto/subtle/unwrapKey-check-usage.html
crypto/subtle/wrapKey-check-usage.html
* bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::JSSubtleCrypto::wrapKey):
Added accidentally omitted code. Other operations are fine.
2013-12-12 Darin Adler <darin@apple.com>
Make some improvements in CSSImageGeneratorValue code
......@@ -646,6 +646,11 @@ JSValue JSSubtleCrypto::wrapKey(ExecState* exec)
if (!key)
return throwTypeError(exec);
if (!wrappingKey->allows(CryptoKeyUsageWrapKey)) {
m_impl->document()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Key usages do not include 'wrapKey'");
setDOMException(exec, NOT_SUPPORTED_ERR);
return jsUndefined();
}
auto algorithm = createAlgorithmFromJSValue(exec, exec->uncheckedArgument(3));
if (!algorithm) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment