blob: 11901f972279fc3fefad01a54b2815dc8298477b [file] [log] [blame]
<!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 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.
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.
shouldThrow("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.
shouldThrow("crypto.subtle.wrapKey('raw', key, wrappingKey, {name: 'SHA-1'})");
// 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
// --------------------------------
wrappedKey = new Uint8Array(100);
unwrappingKey = keys.aesCbc;
unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)};
unwrappedKeyAlgorithm = unwrapAlgorithm;
extractable = true;
keyUsages = ['encrypt'];
// Invalid format
shouldThrow("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)");
// Invalid unwrapAlgorithm
shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, null, unwrappedKeyAlgorithm, extractable, keyUsages)");
// Invalid unwrappedKeyAlgorithm (specified but bad).
shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwrapAlgorithm, 3, extractable, keyUsages)");
// SHA-1 isn't a valid unwrapKey algorithm.
shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, {name: 'SHA-1'}, unwrappedKeyAlgorithm, extractable, keyUsages)");
// Mismatch between the unwrappingKey's algorithm and unwrapAlgorithm.
shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, aesCtrAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>