OLD | NEW |
1 // The following key pair is comprised of the SPKI (public key) and PKCS#8 | 1 // FIXME: Delete this (tests should import their own keys). |
2 // (private key) representations of the key pair provided in Example 1 of the | |
3 // NIST test vectors at ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.t
xt | |
4 var kPublicKeySpkiDerHex = "30819f300d06092a864886f70d010101050003818d0030818902
818100a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ff
edb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671
ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f2
0d0ce8cffb2249bd9a21370203010001"; | |
5 var kPrivateKeyPkcs8DerHex = "30820275020100300d06092a864886f70d0101010500048202
5f3082025b02010002818100a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e6
1f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508
096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e138
6b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137020301000102818033a5042a90b27d4f5451" + | |
6 "ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724
ac3c568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee896a10ce707c3ed7
e734e44727a39574501a532683109c2abacaba283c31b4bd2f53c3ee37e352cee34f9e503bd80c06
22ad79c6dcee883547c6a3b325024100e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e
86296b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b3b6dcd3eda8e6443
024100b69dca1cf7d4d7ec81e75b90fcca874abcde123fd2700180aa90479b6e48de8d67ed24f9f1
9d85ba275874f542cd20dc723e6963364a1f9425452b269a6799fd024028fa13938655be1f8a159c
baca5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8dd3ede2448328f385
d81b30e8e43b2fffa02786197902401a8b38f398fa712049898d7fb79ee0a77668791299cdfa09ef
c0e507acb21ed74301ef5bfd48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e72902
4027156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319584b8e22fdde1e5a
2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24a79f4d"; | |
7 | |
8 function importTestKeys() | 2 function importTestKeys() |
9 { | 3 { |
10 var data = asciiToUint8Array("16 bytes of key!"); | 4 var data = asciiToUint8Array("16 bytes of key!"); |
11 var extractable = true; | 5 var extractable = true; |
12 var keyUsages = ['wrapKey', 'unwrapKey', 'encrypt', 'decrypt', 'sign', 'veri
fy']; | 6 var keyUsages = ['wrapKey', 'unwrapKey', 'encrypt', 'decrypt', 'sign', 'veri
fy']; |
13 | 7 |
14 var hmacPromise = crypto.subtle.importKey('raw', data, {name: 'hmac', hash:
{name: 'sha-1'}}, extractable, keyUsages); | 8 var hmacPromise = crypto.subtle.importKey('raw', data, {name: 'hmac', hash:
{name: 'sha-1'}}, extractable, keyUsages); |
15 var aesCbcPromise = crypto.subtle.importKey('raw', data, {name: 'AES-CBC'},
extractable, keyUsages); | 9 var aesCbcPromise = crypto.subtle.importKey('raw', data, {name: 'AES-CBC'},
extractable, keyUsages); |
16 var aesCbcJustDecrypt = crypto.subtle.importKey('raw', data, {name: 'AES-CBC
'}, false, ['decrypt']); | 10 var aesCbcJustDecrypt = crypto.subtle.importKey('raw', data, {name: 'AES-CBC
'}, false, ['decrypt']); |
17 // FIXME: use AES-CTR key type once it's implemented | 11 // FIXME: use AES-CTR key type once it's implemented |
18 var aesCtrPromise = crypto.subtle.importKey('raw', data, {name: 'AES-CBC'},
extractable, keyUsages); | 12 var aesCtrPromise = crypto.subtle.importKey('raw', data, {name: 'AES-CBC'},
extractable, keyUsages); |
19 var aesGcmPromise = crypto.subtle.importKey('raw', data, {name: 'AES-GCM'},
extractable, keyUsages); | 13 var aesGcmPromise = crypto.subtle.importKey('raw', data, {name: 'AES-GCM'},
extractable, keyUsages); |
20 var rsaSsaSha1PublicPromise = crypto.subtle.importKey('spki', hexStringToUin
t8Array(kPublicKeySpkiDerHex), {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'sha-1'}
}, extractable, keyUsages); | 14 var rsaSsaSha1PublicPromise = crypto.subtle.importKey('spki', hexStringToUin
t8Array(kKeyData.rsa1.spki), {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'sha-1'}},
extractable, keyUsages); |
21 var rsaSsaSha1PrivatePromise = crypto.subtle.importKey('pkcs8', hexStringToU
int8Array(kPrivateKeyPkcs8DerHex), {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'sha
-1'}}, extractable, keyUsages); | 15 var rsaSsaSha1PrivatePromise = crypto.subtle.importKey('pkcs8', hexStringToU
int8Array(kKeyData.rsa1.pkcs8), {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'sha-1'
}}, extractable, keyUsages); |
22 | 16 |
23 return Promise.all([hmacPromise, aesCbcPromise, aesCbcJustDecrypt, aesCtrPro
mise, aesGcmPromise, rsaSsaSha1PublicPromise, rsaSsaSha1PrivatePromise]).then(fu
nction(results) { | 17 return Promise.all([hmacPromise, aesCbcPromise, aesCbcJustDecrypt, aesCtrPro
mise, aesGcmPromise, rsaSsaSha1PublicPromise, rsaSsaSha1PrivatePromise]).then(fu
nction(results) { |
24 return { | 18 return { |
25 hmacSha1: results[0], | 19 hmacSha1: results[0], |
26 aesCbc: results[1], | 20 aesCbc: results[1], |
27 aesCbcJustDecrypt: results[2], | 21 aesCbcJustDecrypt: results[2], |
28 aesCtr: results[3], | 22 aesCtr: results[3], |
29 aesGcm: results[4], | 23 aesGcm: results[4], |
30 rsaSsaSha1Public: results[5], | 24 rsaSsaSha1Public: results[5], |
31 rsaSsaSha1Private: results[6], | 25 rsaSsaSha1Private: results[6], |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 return new Uint8Array(chars); | 87 return new Uint8Array(chars); |
94 } | 88 } |
95 | 89 |
96 function failAndFinishJSTest(error) | 90 function failAndFinishJSTest(error) |
97 { | 91 { |
98 if (error) | 92 if (error) |
99 debug(error); | 93 debug(error); |
100 finishJSTest(); | 94 finishJSTest(); |
101 } | 95 } |
102 | 96 |
| 97 // ===================================================== |
| 98 // FIXME: Delete the addTask() functions (better to test results directly) |
| 99 // ===================================================== |
| 100 |
103 numOutstandingTasks = 0; | 101 numOutstandingTasks = 0; |
104 | 102 |
105 function addTask(promise) | 103 function addTask(promise) |
106 { | 104 { |
107 numOutstandingTasks++; | 105 numOutstandingTasks++; |
108 | 106 |
109 function taskFinished() | 107 function taskFinished() |
110 { | 108 { |
111 numOutstandingTasks--; | 109 numOutstandingTasks--; |
112 completeTestWhenAllTasksDone(); | 110 completeTestWhenAllTasksDone(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 150 } |
153 | 151 |
154 function rejectCallback(result) | 152 function rejectCallback(result) |
155 { | 153 { |
156 debug("FAIL: '" + code + "' rejected with " + result); | 154 debug("FAIL: '" + code + "' rejected with " + result); |
157 } | 155 } |
158 | 156 |
159 addTask(promise.then(acceptCallback, rejectCallback)); | 157 addTask(promise.then(acceptCallback, rejectCallback)); |
160 } | 158 } |
161 | 159 |
| 160 // ===================================================== |
| 161 |
162 // Returns a Promise for the cloned key. | 162 // Returns a Promise for the cloned key. |
163 function cloneKey(key) | 163 function cloneKey(key) |
164 { | 164 { |
165 // Sending an object through a MessagePort implicitly clones it. | 165 // Sending an object through a MessagePort implicitly clones it. |
166 // Use a single MessageChannel so requests complete in FIFO order. | 166 // Use a single MessageChannel so requests complete in FIFO order. |
167 var self = cloneKey; | 167 var self = cloneKey; |
168 if (!self.channel) { | 168 if (!self.channel) { |
169 self.channel = new MessageChannel(); | 169 self.channel = new MessageChannel(); |
170 self.callbacks = []; | 170 self.callbacks = []; |
171 self.channel.port1.addEventListener('message', function(e) { | 171 self.channel.port1.addEventListener('message', function(e) { |
(...skipping 15 matching lines...) Expand all Loading... |
187 if (internals) | 187 if (internals) |
188 debug("Serialized key bytes: " + bytesToHexString(internals.serializeObj
ect(o))); | 188 debug("Serialized key bytes: " + bytesToHexString(internals.serializeObj
ect(o))); |
189 } | 189 } |
190 | 190 |
191 function shouldEvaluateAs(actual, expectedValue) | 191 function shouldEvaluateAs(actual, expectedValue) |
192 { | 192 { |
193 if (typeof expectedValue == "string") | 193 if (typeof expectedValue == "string") |
194 return shouldBeEqualToString(actual, expectedValue); | 194 return shouldBeEqualToString(actual, expectedValue); |
195 return shouldEvaluateTo(actual, expectedValue); | 195 return shouldEvaluateTo(actual, expectedValue); |
196 } | 196 } |
OLD | NEW |