Commit b5e41b6e authored by eroman@chromium.org's avatar eroman@chromium.org

[refactor] Split wrap-unwrap.html into smaller files, and directly check the error result.

wrap-unwrap.html becomes these files:

 * wrapKey-unextractable.html
 * wrapKey-lacks-usage.html
 * wrapKey-badParameters.html
 * unwrapKey-lacks-usage.html
 * unwrapKey-badParameters.html

BUG=245025

Review URL: https://codereview.chromium.org/214263002

git-svn-id: svn://svn.chromium.org/blink/trunk@170201 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6800ab5b
CONSOLE ERROR: Invalid keyFormat argument
CONSOLE ERROR: key is not extractable
CONSOLE ERROR: key.usages does not permit this operation
CONSOLE ERROR: Algorithm: SHA-1: Unsupported operation
CONSOLE ERROR: key.algorithm does not match that of operation
CONSOLE ERROR: Invalid keyFormat argument
CONSOLE ERROR: key.usages does not permit this operation
CONSOLE ERROR: Algorithm: SHA-1: Unsupported operation
CONSOLE ERROR: key.algorithm does not match that of operation
Tests cypto.subtle.sign and crypto.subtle.verify
Tests calls to unwrapKey() with bad inputs.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS crypto.subtle.wrapKey('raw', 1, wrappingKey, wrapAlgorithm) threw exception TypeError: Failed to execute 'wrapKey' on 'SubtleCrypto': Invalid key argument.
PASS crypto.subtle.wrapKey('raw', key, '', wrapAlgorithm) threw exception TypeError: Failed to execute 'wrapKey' on 'SubtleCrypto': Invalid wrappingKey argument.
PASS crypto.subtle.wrapKey('raw', key, wrappingKey, undefined) threw exception TypeError: Failed to execute 'wrapKey' on 'SubtleCrypto': Algorithm: Not an object.
PASS crypto.subtle.unwrapKey('raw', null, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages) threw exception TypeError: Failed to execute 'unwrapKey' on 'SubtleCrypto': Invalid wrappedKey argument.
PASS crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages) threw exception TypeError: Failed to execute 'unwrapKey' on 'SubtleCrypto': Invalid unwrappingKey argument.
PASS crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorithm, null, extractable, 9) threw exception TypeError: The 7th argument is neither an array, nor does it have indexed properties..
PASS crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, null, unwrappedKeyAlgorithm, extractable, keyUsages) threw exception TypeError: Failed to execute 'unwrapKey' on 'SubtleCrypto': Algorithm: Not an object.
PASS crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwrapAlgorithm, 3, extractable, keyUsages) threw exception TypeError: Failed to execute 'unwrapKey' on 'SubtleCrypto': parameter 5 ('unwrappedKeyAlgorithm') is not an object..
PASS: 'crypto.subtle.wrapKey('bad-format', key, wrappingKey, wrapAlgorithm)' rejected with null
PASS: 'crypto.subtle.wrapKey('raw', keys.aesCbcJustDecrypt, wrappingKey, wrapAlgorithm)' rejected with null
PASS: 'crypto.subtle.wrapKey('raw', key, keys.aesCbcJustDecrypt, wrapAlgorithm)' rejected with null
PASS: 'crypto.subtle.wrapKey('raw', key, wrappingKey, {name: 'SHA-1'})' rejected with null
PASS: 'crypto.subtle.wrapKey('raw', key, wrappingKey, aesCtrAlgorithm)' rejected with null
PASS: 'crypto.subtle.unwrapKey('bad-format', wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)' rejected with null
PASS: 'crypto.subtle.unwrapKey('raw', wrappedKey, keys.aesCbcJustDecrypt, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)' rejected with null
PASS: 'crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, {name: 'SHA-1'}, unwrappedKeyAlgorithm, extractable, keyUsages)' rejected with null
PASS: 'crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, aesCtrAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)' rejected with null
PASS error is null
PASS error is null
PASS error is null
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -3,81 +3,39 @@
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/common.js"></script>
<script src="resources/keys.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests cypto.subtle.sign and crypto.subtle.verify");
// FIXME: This is only testing invalid parameters right now. Once the
// chromium-side implements the algorithms more interesting tests should be
// added.
description("Tests calls to unwrapKey() with bad inputs.");
jsTestIsAsync = true;
importTestKeys().then(function(result) {
keys = result;
key = keys.hmacSha1;
wrappingKey = keys.aesCbc;
wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
// --------------------------------
// wrapKey invalid parameters
// --------------------------------
// Invalid format.
shouldRejectPromiseWithNull("crypto.subtle.wrapKey('bad-format', key, wrappingKey, wrapAlgorithm)");
// Invalid key
shouldThrow("crypto.subtle.wrapKey('raw', 1, wrappingKey, wrapAlgorithm)");
// Invalid wrappingKey
shouldThrow("crypto.subtle.wrapKey('raw', key, '', wrapAlgorithm)");
// Invalid wrapAlgorithm
shouldThrow("crypto.subtle.wrapKey('raw', key, wrappingKey, undefined)");
// Key is not extractable.
shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', keys.aesCbcJustDecrypt, wrappingKey, wrapAlgorithm)");
// wrappingKey's usage does not include wrapKey.
shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', key, keys.aesCbcJustDecrypt, wrapAlgorithm)");
// SHA-1 isn't a valid wrapKey algorithm.
shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', key, wrappingKey, {name: 'SHA-1'})");
function importUnwrappingKey()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['unwrapKey'];
// Wrap algorithm doesn't match the wrapping key's algorithm (AES-CBC key
// with AES-CTR wrap algorithm)
aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0};
shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', key, wrappingKey, aesCtrAlgorithm)");
// --------------------------------
// unwrapKey invalid parameters
// --------------------------------
return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages);
}
importUnwrappingKey().then(function(result) {
wrappedKey = new Uint8Array(100);
unwrappingKey = keys.aesCbc;
unwrappingKey = result;
unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
unwrappedKeyAlgorithm = unwrapAlgorithm;
extractable = true;
keyUsages = ['encrypt'];
// Invalid format
shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('bad-format', wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)");
// Invalid wrappedKey
shouldThrow("crypto.subtle.unwrapKey('raw', null, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)");
// Invalid unwrappingKey
shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)");
// unwrappingKey does not include unwrapKey usage.
shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, keys.aesCbcJustDecrypt, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)");
// Invalid keyUsages (also, unwrappedKeyAlgorithm is set to null).
shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorithm, null, extractable, 9)");
......@@ -87,15 +45,27 @@ importTestKeys().then(function(result) {
// Invalid unwrappedKeyAlgorithm (specified but bad).
shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwrapAlgorithm, 3, extractable, keyUsages)");
// Invalid format
return crypto.subtle.unwrapKey('bad-format', wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
// SHA-1 isn't a valid unwrapKey algorithm.
shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, {name: 'SHA-1'}, unwrappedKeyAlgorithm, extractable, keyUsages)");
return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, {name: 'SHA-1'}, unwrappedKeyAlgorithm, extractable, keyUsages);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
// Mismatch between the unwrappingKey's algorithm and unwrapAlgorithm.
shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, aesCtrAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)");
aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0};
return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, aesCtrAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
CONSOLE ERROR: key.usages does not permit this operation
Tests that unwrapping keys must have the 'unwrapKey' usage.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS error is null
PASS successfullyParsed is true
TEST COMPLETE
<!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("Tests that unwrapping keys must have the 'unwrapKey' usage.");
jsTestIsAsync = true;
function importUnwrappingKey()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['decrypt'];
return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages);
}
importUnwrappingKey().then(function(result) {
wrappedKey = new Uint8Array(100);
unwrappingKey = result;
unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
unwrappedKeyAlgorithm = unwrapAlgorithm;
extractable = true;
keyUsages = ['encrypt'];
return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
CONSOLE ERROR: Invalid keyFormat argument
CONSOLE ERROR: Algorithm: SHA-1: Unsupported operation
CONSOLE ERROR: key.algorithm does not match that of operation
Tests calls to wrapKey() with bad inputs.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS crypto.subtle.wrapKey('raw', 1, wrappingKey, wrapAlgorithm) threw exception TypeError: Failed to execute 'wrapKey' on 'SubtleCrypto': Invalid key argument.
PASS crypto.subtle.wrapKey('raw', key, '', wrapAlgorithm) threw exception TypeError: Failed to execute 'wrapKey' on 'SubtleCrypto': Invalid wrappingKey argument.
PASS crypto.subtle.wrapKey('raw', key, wrappingKey, undefined) threw exception TypeError: Failed to execute 'wrapKey' on 'SubtleCrypto': Algorithm: Not an object.
PASS error is null
PASS error is null
PASS error is null
PASS successfullyParsed is true
TEST COMPLETE
<!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("Tests calls to wrapKey() with bad inputs.");
jsTestIsAsync = true;
function importWrappingKey()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['wrapKey'];
return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages);
}
function importKeyToWrap()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['sign'];
return crypto.subtle.importKey('raw', data, {name: 'HMAC', hash: {name: 'SHA-1'}}, extractable, keyUsages);
}
importWrappingKey().then(function(result) {
wrappingKey = result;
return importKeyToWrap();
}).then(function(result) {
key = result;
wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
// Invalid key
shouldThrow("crypto.subtle.wrapKey('raw', 1, wrappingKey, wrapAlgorithm)");
// Invalid wrappingKey
shouldThrow("crypto.subtle.wrapKey('raw', key, '', wrapAlgorithm)");
// Invalid wrapAlgorithm
shouldThrow("crypto.subtle.wrapKey('raw', key, wrappingKey, undefined)");
// Invalid format for wrapKey
return crypto.subtle.wrapKey('bad-format', key, wrappingKey, wrapAlgorithm);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
// SHA-1 isn't a valid wrapKey algorithm.
return crypto.subtle.wrapKey('raw', key, wrappingKey, {name: 'SHA-1'});
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
// Wrap algorithm doesn't match the wrapping key's algorithm (AES-CBC key
// with AES-CTR wrap algorithm)
aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0};
return crypto.subtle.wrapKey('raw', key, wrappingKey, aesCtrAlgorithm);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
CONSOLE ERROR: key.usages does not permit this operation
Tests that wrapping keys must have the 'wrapKey' usage.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS error is null
PASS successfullyParsed is true
TEST COMPLETE
<!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("Tests that wrapping keys must have the 'wrapKey' usage.");
jsTestIsAsync = true;
function importWrappingKey()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['encrypt'];
return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages);
}
function importKeyToWrap()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['sign'];
return crypto.subtle.importKey('raw', data, {name: 'HMAC', hash: {name: 'SHA-1'}}, extractable, keyUsages);
}
importWrappingKey().then(function(result) {
wrappingKey = result;
return importKeyToWrap();
}).then(function(result) {
key = result;
wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
return crypto.subtle.wrapKey('raw', key, wrappingKey, wrapAlgorithm);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
CONSOLE ERROR: key is not extractable
Tests that an unextractable key cannot be wrapped.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS typeof key.extractable is 'boolean'
PASS key.extractable is false
PASS error is null
PASS successfullyParsed is true
TEST COMPLETE
<!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("Tests that an unextractable key cannot be wrapped.");
jsTestIsAsync = true;
function importWrappingKey()
{
var data = new Uint8Array(16);
var extractable = true;
var keyUsages = ['wrapKey'];
return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages);
}
function importUnextractableKeyToWrap()
{
var data = new Uint8Array(16);
var extractable = false;
var keyUsages = ['sign'];
return crypto.subtle.importKey('raw', data, {name: 'HMAC', hash: {name: 'SHA-1'}}, extractable, keyUsages);
}
importWrappingKey().then(function(result) {
wrappingKey = result;
return importUnextractableKeyToWrap();
}).then(function(result) {
key = result;
shouldEvaluateAs("key.extractable", false);
wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
return crypto.subtle.wrapKey('raw', key, wrappingKey, wrapAlgorithm);
}).then(failAndFinishJSTest, function(result) {
error = result;
shouldBeNull("error");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
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