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

Import WebKit RSA-OAEP LayoutTests.

BUG=377941,245025

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

git-svn-id: svn://svn.chromium.org/blink/trunk@176062 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8c3a9c63
...@@ -615,6 +615,11 @@ crbug.com/243782 virtual/android/fullscreen/full-screen-remove-ancestor.html [ P ...@@ -615,6 +615,11 @@ crbug.com/243782 virtual/android/fullscreen/full-screen-remove-ancestor.html [ P
crbug.com/267888 [ Android ] crypto [ Skip ] crbug.com/267888 [ Android ] crypto [ Skip ]
crbug.com/382732 [ Linux ] crypto/rsa-oaep-generate-non-extractable-key.html [ Failure Pass ]
crbug.com/382732 [ Linux ] crypto/rsa-oaep-key-manipulation.html [ Failure Pass ]
crbug.com/382732 [ Linux ] crypto/rsa-oaep-plaintext-length.html [ Failure Pass ]
crbug.com/382732 [ Linux ] crypto/rsa-oaep-wrap-unwrap-aes.html [ Failure Pass ]
crbug.com/327698 [ Win Release ] virtual/gpu/fast/canvas/canvas-lost-gpu-context.html [ Pass Timeout ] crbug.com/327698 [ Win Release ] virtual/gpu/fast/canvas/canvas-lost-gpu-context.html [ Pass Timeout ]
crbug.com/327698 [ Debug Mac Win ] virtual/gpu/fast/canvas/canvas-lost-gpu-context.html [ Pass Timeout ] crbug.com/327698 [ Debug Mac Win ] virtual/gpu/fast/canvas/canvas-lost-gpu-context.html [ Pass Timeout ]
......
Test that even when non-extractability is requested, the public key is still extractable.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Generating a key pair...
PASS keyPair.toString() is '[object KeyPair]'
PASS keyPair.publicKey.type is 'public'
PASS keyPair.publicKey.extractable is true
PASS keyPair.publicKey.algorithm.name is 'RSA-OAEP'
PASS keyPair.publicKey.algorithm.modulusLength is 2048
PASS bytesToHexString(keyPair.publicKey.algorithm.publicExponent) is '010001'
PASS keyPair.publicKey.algorithm.hash.name is 'SHA-256'
PASS keyPair.privateKey.type is 'private'
PASS keyPair.privateKey.extractable is false
PASS keyPair.privateKey.algorithm.name is 'RSA-OAEP'
PASS keyPair.privateKey.algorithm.modulusLength is 2048
PASS bytesToHexString(keyPair.privateKey.algorithm.publicExponent) is '010001'
PASS keyPair.privateKey.algorithm.hash.name is 'SHA-256'
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("Test that even when non-extractability is requested, the public key is still extractable.");
jsTestIsAsync = true;
var algorithmKeyGen = {
name: "RSA-OAEP",
hash: {name: "sha-256"},
// RsaKeyGenParams
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
};
var nonExtractable = false;
debug("Generating a key pair...");
crypto.subtle.generateKey(algorithmKeyGen, nonExtractable, []).then(function(result) {
keyPair = result;
shouldBe("keyPair.toString()", "'[object KeyPair]'");
shouldBe("keyPair.publicKey.type", "'public'");
shouldBe("keyPair.publicKey.extractable", "true");
shouldBe("keyPair.publicKey.algorithm.name", "'RSA-OAEP'");
shouldBe("keyPair.publicKey.algorithm.modulusLength", "2048");
shouldBe("bytesToHexString(keyPair.publicKey.algorithm.publicExponent)", "'010001'");
shouldBe("keyPair.publicKey.algorithm.hash.name", "'SHA-256'");
shouldBe("keyPair.privateKey.type", "'private'");
shouldBe("keyPair.privateKey.extractable", "false");
shouldBe("keyPair.privateKey.algorithm.name", "'RSA-OAEP'");
shouldBe("keyPair.privateKey.algorithm.modulusLength", "2048");
shouldBe("bytesToHexString(keyPair.privateKey.algorithm.publicExponent)", "'010001'");
shouldBe("keyPair.privateKey.algorithm.hash.name", "'SHA-256'");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
Test generating, importing and exporting RSA keys for RSA-OAEP. Test that they can't be used with another algorithm.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Generating a key pair...
PASS keyPair.toString() is '[object KeyPair]'
PASS keyPair.publicKey.type is 'public'
PASS keyPair.publicKey.algorithm.name is 'RSA-OAEP'
PASS keyPair.publicKey.algorithm.modulusLength is 2048
PASS keyPair.publicKey.usages is ["encrypt", "wrapKey"]
PASS bytesToHexString(keyPair.publicKey.algorithm.publicExponent) is '010001'
PASS keyPair.publicKey.algorithm.hash.name is 'SHA-1'
PASS keyPair.privateKey.type is 'private'
PASS keyPair.privateKey.algorithm.name is 'RSA-OAEP'
PASS keyPair.privateKey.algorithm.modulusLength is 2048
PASS keyPair.privateKey.usages is ["decrypt", "unwrapKey"]
PASS bytesToHexString(keyPair.privateKey.algorithm.publicExponent) is '010001'
PASS keyPair.privateKey.algorithm.hash.name is 'SHA-1'
Testing that the keys can't be used with different algorithms...
error is: InvalidAccessError: key.usages does not permit this operation
error is: InvalidAccessError: key.algorithm does not match that of operation
Trying to export keys to raw...
error is: InvalidAccessError: The key is not of the expected type
PASS Promise rejected for exporting public key
error is: InvalidAccessError: The key is not of the expected type
PASS Promise rejected for exporting private key
Exporting public key to JWK...
PASS jwkPublicKey.alg is 'RSA-OAEP'
PASS jwkPublicKey.ext is true
PASS jwkPublicKey.key_ops is ['encrypt', 'wrapKey']
PASS jwkPublicKey.use is undefined
PASS jwkPublicKey.kty is 'RSA'
PASS bytesToHexString(Base64URL.parse(jwkPublicKey.e)) is '010001'
Importing it back...
PASS exportedPublicKey.type is 'public'
PASS exportedPublicKey.algorithm.name is 'RSA-OAEP'
PASS exportedPublicKey.algorithm.modulusLength is 2048
PASS bytesToHexString(exportedPublicKey.algorithm.publicExponent) is '010001'
PASS exportedPublicKey.algorithm.hash.name is 'SHA-1'
PASS exportedPublicKey.extractable is true
PASS exportedPublicKey.usages is ['encrypt','wrapKey']
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("Test generating, importing and exporting RSA keys for RSA-OAEP. Test that they can't be used with another algorithm.");
jsTestIsAsync = true;
var algorithmKeyGen = {
name: "RSA-OAEP",
hash: {name: "sha-1"},
// RsaKeyGenParams
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
};
var extractable = true;
debug("Generating a key pair...");
crypto.subtle.generateKey(algorithmKeyGen, extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]).then(function(result) {
keyPair = result;
shouldBe("keyPair.toString()", "'[object KeyPair]'");
shouldBe("keyPair.publicKey.type", "'public'");
shouldBe("keyPair.publicKey.algorithm.name", "'RSA-OAEP'");
shouldBe("keyPair.publicKey.algorithm.modulusLength", "2048");
shouldBe("keyPair.publicKey.usages", '["encrypt", "wrapKey"]');
shouldBe("bytesToHexString(keyPair.publicKey.algorithm.publicExponent)", "'010001'");
shouldBe("keyPair.publicKey.algorithm.hash.name", "'SHA-1'");
shouldBe("keyPair.privateKey.type", "'private'");
shouldBe("keyPair.privateKey.algorithm.name", "'RSA-OAEP'");
shouldBe("keyPair.privateKey.algorithm.modulusLength", "2048");
shouldBe("keyPair.privateKey.usages", '["decrypt", "unwrapKey"]');
shouldBe("bytesToHexString(keyPair.privateKey.algorithm.publicExponent)", "'010001'");
shouldBe("keyPair.privateKey.algorithm.hash.name", "'SHA-1'");
debug("\nTesting that the keys can't be used with different algorithms...");
iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, keyPair.privateKey, hexStringToUint8Array("00"));
}, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
logError(result);
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, keyPair.publicKey, hexStringToUint8Array("00"));
}, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
logError(result);
debug("\nTrying to export keys to raw...");
return crypto.subtle.exportKey('raw', keyPair.publicKey);
}, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
logError(result);
testPassed("Promise rejected for exporting public key");
return crypto.subtle.exportKey('raw', keyPair.privateKey);
}).then(failAndFinishJSTest, function(result) {
logError(result);
testPassed("Promise rejected for exporting private key");
debug("\nExporting public key to JWK...");
return crypto.subtle.exportKey("jwk", keyPair.publicKey);
}).then(function(result) {
jwkPublicKeyArray = result;
jwkPublicKey = JSON.parse(bytesToASCIIString(jwkPublicKeyArray));
shouldBe("jwkPublicKey.alg", "'RSA-OAEP'");
shouldBe("jwkPublicKey.ext", "true");
shouldBe("jwkPublicKey.key_ops", "['encrypt', 'wrapKey']");
shouldBe("jwkPublicKey.use", "undefined");
shouldBe("jwkPublicKey.kty", "'RSA'");
shouldBe("bytesToHexString(Base64URL.parse(jwkPublicKey.e))", "'010001'");
debug("\nImporting it back...");
return crypto.subtle.importKey("jwk", jwkPublicKeyArray, { name: "RSA-OAEP", hash: {name: "sha-1"} }, extractable, ["encrypt", "wrapKey"]);
}).then(function(result) {
exportedPublicKey = result;
shouldBe("exportedPublicKey.type", "'public'");
shouldBe("exportedPublicKey.algorithm.name", "'RSA-OAEP'");
shouldBe("exportedPublicKey.algorithm.modulusLength", "2048");
shouldBe("bytesToHexString(exportedPublicKey.algorithm.publicExponent)", "'010001'");
shouldBe("exportedPublicKey.algorithm.hash.name", "'SHA-1'");
shouldBe("exportedPublicKey.extractable", "true");
shouldBe("exportedPublicKey.usages", "['encrypt','wrapKey']");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
Test what happens when trying to encrypt a too large plain text with RSA-OAEP.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Importing RSA keys...
Encrypting a 214 byte buffer with RSA-OAEP SHA-1, 2048 bit key...
PASS Succeeded
Encrypting a 215 byte buffer...
error is: OperationError:
PASS Rejected
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("Test what happens when trying to encrypt a too large plain text with RSA-OAEP.");
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 encryptAlgorithm = {name: "RSA-OAEP", hash: "sha-1"};
var extractable = true;
var nonExtractable = false;
debug("Importing RSA keys...");
crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(publicKeyJSON)), {name:"rsa-oaep", hash:{name: "sha-1"}}, extractable, ["encrypt"]).then(function(result) {
publicKey = result;
return crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(privateKeyJSON)), {name:"rsa-oaep", hash:{name: "sha-1"}}, extractable, ["decrypt"]);
}, failAndFinishJSTest).then(function(result) {
privateKey = result;
debug("Encrypting a 214 byte buffer with RSA-OAEP SHA-1, 2048 bit key...");
return crypto.subtle.encrypt({name: "RSA-OAEP"}, publicKey, new Uint8Array(214));
}, failAndFinishJSTest).then(function(result) {
testPassed("Succeeded");
debug("Encrypting a 215 byte buffer...");
return crypto.subtle.encrypt({name: "RSA-OAEP"}, publicKey, new Uint8Array(215));
}, failAndFinishJSTest).then(function(result) {
testFailed("Succeeded");
}, function(result) {
logError(result);
testPassed("Rejected");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>
Test wrapping and unwrapping AES keys with RSA-OAEP.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Importing RSA keys...
Importing an AES key...
Wrapping it...
PASS wrappedKey.toString() is '[object ArrayBuffer]'
Unwrapping it...
PASS unwrappedKey.toString() is '[object Key]'
PASS unwrappedKey.type is 'secret'
PASS unwrappedKey.extractable is true
PASS unwrappedKey.algorithm.name is 'AES-CBC'
PASS unwrappedKey.algorithm.length is 256
PASS unwrappedKey.usages is ['encrypt', 'decrypt']
Exporting it...
PASS bytesToHexString(unwrappedKeyData) is bytesToHexString(aesKeyData)
Wrapping the same key as JWK...
PASS wrappedKey.toString() is '[object ArrayBuffer]'
Unwrapping it...
PASS unwrappedKey.toString() is '[object Key]'
PASS unwrappedKey.type is 'secret'
PASS unwrappedKey.extractable is true
PASS unwrappedKey.algorithm.name is 'AES-CBC'
PASS unwrappedKey.algorithm.length is 256
PASS unwrappedKey.usages is ['encrypt', 'decrypt']
Exporting it...
PASS bytesToHexString(unwrappedKeyData) is bytesToHexString(aesKeyData)
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("Test wrapping and unwrapping AES keys with RSA-OAEP.");
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;
var importAlgorithm = {name: "rsa-oaep", hash: {name:"sha-1"}};
debug("Importing RSA keys...");
crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(publicKeyJSON)), importAlgorithm, extractable, ["wrapKey"]).then(function(result) {
publicKey = result;
return crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(privateKeyJSON)), importAlgorithm, extractable, ["unwrapKey"]);
}).then(function(result) {
privateKey = result;
debug("Importing an AES key...");
aesKeyData = hexStringToUint8Array("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
return crypto.subtle.importKey("raw", aesKeyData, {name:"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;
shouldBe("wrappedKey.toString()", "'[object ArrayBuffer]'");
debug("Unwrapping it...");
return crypto.subtle.unwrapKey("raw", wrappedKey, privateKey, wrapAlgorithm, {name:"aes-cbc"}, extractable, ["encrypt", "decrypt"]);
}).then(function(result) {
unwrappedKey = result;
shouldBe("unwrappedKey.toString()", "'[object Key]'");
shouldBe("unwrappedKey.type", "'secret'");
shouldBe("unwrappedKey.extractable", "true");
shouldBe("unwrappedKey.algorithm.name", "'AES-CBC'");
shouldBe("unwrappedKey.algorithm.length", "256");
shouldBe("unwrappedKey.usages", "['encrypt', 'decrypt']");
debug("Exporting it...");
return crypto.subtle.exportKey("raw", unwrappedKey);
}).then(function(result) {
unwrappedKeyData = result;
shouldBe("bytesToHexString(unwrappedKeyData)", "bytesToHexString(aesKeyData)");
debug("\nWrapping the same key as JWK...");
return crypto.subtle.wrapKey("jwk", aesKey, publicKey, wrapAlgorithm);
}).then(function(result) {
wrappedKey = result;
shouldBe("wrappedKey.toString()", "'[object ArrayBuffer]'");
debug("Unwrapping it...");
return crypto.subtle.unwrapKey("jwk", wrappedKey, privateKey, wrapAlgorithm, {name:"aes-cbc"}, extractable, ["encrypt", "decrypt"]);
}).then(function(result) {
unwrappedKey = result;
shouldBe("unwrappedKey.toString()", "'[object Key]'");
shouldBe("unwrappedKey.type", "'secret'");
shouldBe("unwrappedKey.extractable", "true");
shouldBe("unwrappedKey.algorithm.name", "'AES-CBC'");
shouldBe("unwrappedKey.algorithm.length", "256");
shouldBe("unwrappedKey.usages", "['encrypt', 'decrypt']");
debug("Exporting it...");
return crypto.subtle.exportKey("raw", unwrappedKey);
}).then(function(result) {
unwrappedKeyData = result;
shouldBe("bytesToHexString(unwrappedKeyData)", "bytesToHexString(aesKeyData)");
}).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