OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1); | 7 var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1); |
8 | 8 |
9 var assertEq = chrome.test.assertEq; | 9 var assertEq = chrome.test.assertEq; |
10 var assertTrue = chrome.test.assertTrue; | 10 var assertTrue = chrome.test.assertTrue; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 0x33, 0x51, 0x02, 0xe4, 0x24, 0x86, 0xab, 0x8e, 0xaa, 0x94, 0xf4, 0x25, | 72 0x33, 0x51, 0x02, 0xe4, 0x24, 0x86, 0xab, 0x8e, 0xaa, 0x94, 0xf4, 0x25, |
73 0x6e, 0x3f, 0x53, 0x42, 0xce, 0x12, 0x91, 0x99, 0x23, 0x52, 0x1d, 0xba, | 73 0x6e, 0x3f, 0x53, 0x42, 0xce, 0x12, 0x91, 0x99, 0x23, 0x52, 0x1d, 0xba, |
74 0xdf, 0x59, 0x11, 0x0f, 0x34, 0x2e, 0x8e, 0x58, 0xac, 0xdf, 0x6b, 0x1a, | 74 0xdf, 0x59, 0x11, 0x0f, 0x34, 0x2e, 0x8e, 0x58, 0xac, 0xdf, 0x6b, 0x1a, |
75 0x08, 0xa3, 0x03, 0x46, 0x0f, 0xc0, 0x11, 0x72, 0x66, 0xc4, 0xe8, 0x92, | 75 0x08, 0xa3, 0x03, 0x46, 0x0f, 0xc0, 0x11, 0x72, 0x66, 0xc4, 0xe8, 0x92, |
76 0x5a, 0x20, 0x06, 0xfe, 0xe2, 0x2b, 0xe9, 0xb3, 0x9b, 0x70, 0x1a, 0xb9, | 76 0x5a, 0x20, 0x06, 0xfe, 0xe2, 0x2b, 0xe9, 0xb3, 0x9b, 0x70, 0x1a, 0xb9, |
77 0x53, 0x21, 0xad, 0xd7, 0x5f, 0xa1, 0xab, 0x26, 0x97, 0x17, 0x0b, 0xba, | 77 0x53, 0x21, 0xad, 0xd7, 0x5f, 0xa1, 0xab, 0x26, 0x97, 0x17, 0x0b, 0xba, |
78 0xb0, 0x8b, 0x2d, 0xdb, 0x0c, 0x4e, 0xed, 0x75, 0x8b, 0x72, 0x46, 0xb0, | 78 0xb0, 0x8b, 0x2d, 0xdb, 0x0c, 0x4e, 0xed, 0x75, 0x8b, 0x72, 0x46, 0xb0, |
79 0x6b, 0x23, 0x11, 0xba, 0x1e, 0x03 | 79 0x6b, 0x23, 0x11, 0xba, 0x1e, 0x03 |
80 ]); | 80 ]); |
81 | 81 |
82 // The public key of clientCert1 as Subject Public Key Info in DER encoding. | |
83 var clientPubkey1 = new Uint8Array([ | |
84 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | |
85 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, | |
86 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xd5, 0xdf, 0xba, | |
87 0x34, 0xcb, 0xc2, 0x03, 0xb5, 0x37, 0x7a, 0x61, 0x89, 0x1a, 0xb5, 0x1a, | |
88 0xb9, 0x27, 0x7f, 0xa9, 0x2c, 0xba, 0xa1, 0x36, 0xac, 0x83, 0x6d, 0xb8, | |
89 0x45, 0x9e, 0x35, 0x82, 0xa4, 0xde, 0xa3, 0x69, 0x38, 0x25, 0x84, 0x57, | |
90 0x00, 0x8c, 0x41, 0x84, 0x86, 0x6d, 0x78, 0x41, 0xd4, 0x10, 0x99, 0x1b, | |
91 0x15, 0x18, 0xa6, 0x04, 0x2f, 0x92, 0xa0, 0x1c, 0x29, 0xc3, 0xe0, 0x5d, | |
92 0xe2, 0x90, 0x11, 0x2c, 0xfa, 0xac, 0x18, 0x0d, 0xfe, 0x5e, 0x8d, 0x5c, | |
93 0x5a, 0x01, 0x4a, 0xf7, 0x2c, 0xc9, 0x6e, 0x39, 0x8e, 0x14, 0x30, 0xd9, | |
94 0xfc, 0xf6, 0x6a, 0xee, 0x9d, 0xa3, 0xba, 0x23, 0xfe, 0x5d, 0xaa, 0x2f, | |
95 0x96, 0x07, 0x65, 0x38, 0xca, 0xa4, 0x3c, 0xd2, 0x93, 0x21, 0xb0, 0xb6, | |
96 0xdb, 0xfb, 0x40, 0x12, 0x00, 0x01, 0x99, 0x30, 0x41, 0x67, 0xe2, 0x2f, | |
97 0x65, 0x63, 0x71, 0xaa, 0xa6, 0xef, 0x45, 0x23, 0x05, 0x8b, 0xb4, 0x28, | |
98 0x6c, 0x35, 0xbf, 0x41, 0x73, 0x61, 0xf1, 0x9e, 0x77, 0x8c, 0xa7, 0x51, | |
99 0xcf, 0xc7, 0x51, 0x63, 0xc7, 0x00, 0xab, 0x4e, 0xa3, 0xe5, 0x8f, 0xfe, | |
100 0x3c, 0x45, 0xfa, 0x9e, 0xd2, 0x29, 0xbc, 0x59, 0x94, 0x7d, 0x14, 0xc9, | |
101 0x36, 0xdf, 0xcd, 0x0a, 0xb5, 0x9f, 0xbf, 0xac, 0xfd, 0x1d, 0x2b, 0x6d, | |
102 0xe5, 0x13, 0x30, 0x14, 0x71, 0xde, 0x77, 0xdf, 0x83, 0xf3, 0x6d, 0x2c, | |
103 0xcd, 0x16, 0xc0, 0xa5, 0xdc, 0xf2, 0x1f, 0x65, 0x86, 0x37, 0x91, 0x2f, | |
104 0x31, 0x66, 0x7e, 0x1a, 0x4b, 0x42, 0xb7, 0x29, 0xe1, 0xcd, 0x1d, 0xc9, | |
105 0x72, 0x0e, 0x65, 0x8e, 0xa9, 0x4c, 0x74, 0x2e, 0x90, 0xb7, 0xe0, 0x91, | |
106 0x0c, 0xe8, 0xfe, 0x92, 0x26, 0xa7, 0x17, 0x9a, 0xb6, 0x25, 0x7f, 0x66, | |
107 0x89, 0x2f, 0xbf, 0x54, 0xa7, 0x51, 0x4c, 0xe6, 0x8f, 0x4d, 0x34, 0xa1, | |
108 0xc3, 0x02, 0x03, 0x01, 0x00, 0x01 | |
109 ]); | |
Ryan Sleevi
2015/02/03 01:44:51
Is there no way to move all this test data into se
pneubeck (no reviews)
2015/02/03 20:15:00
I assume that you mean adding files that contains
pneubeck (no reviews)
2015/02/04 20:59:20
changed to XHR loading local files.
| |
110 | |
111 // echo -n "hello world" > input | |
112 // xxd -i input | |
113 var rawData = new Uint8Array([ | |
114 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64 | |
115 ]); | |
116 | |
117 // openssl rsautl -inkey net/data/ssl/certificates/client_1.key -sign -in input | |
118 // -pkcs -out signature.pkcs | |
119 // xxd -i signature.pkcs | |
120 var signatureNoHashPkcs = new Uint8Array([ | |
121 0x6a, 0x79, 0xf2, 0x64, 0x3f, 0x5e, 0xa5, 0xe6, 0xab, 0xbc, 0x64, 0x17, | |
122 0xab, 0x6b, 0x7c, 0x56, 0xc2, 0xfc, 0xf5, 0xd0, 0x23, 0x21, 0x70, 0x59, | |
123 0xda, 0x18, 0xc5, 0x15, 0x6f, 0x5f, 0xab, 0x9a, 0x6e, 0x37, 0xc2, 0xcf, | |
124 0x4a, 0xea, 0x35, 0x98, 0x15, 0x01, 0xe6, 0xf9, 0x73, 0x87, 0x6a, 0x4f, | |
125 0x39, 0x48, 0xdd, 0x54, 0x46, 0x9a, 0xc2, 0xcb, 0xf4, 0x72, 0x4e, 0x02, | |
126 0x20, 0xda, 0x71, 0x37, 0xcd, 0xf3, 0xf2, 0xd1, 0x8d, 0x6b, 0x65, 0xed, | |
127 0xf2, 0x78, 0xc7, 0x7e, 0x39, 0xad, 0x29, 0x73, 0x37, 0xb7, 0x06, 0x13, | |
128 0x60, 0xad, 0x13, 0xaf, 0xe2, 0x85, 0x4c, 0xba, 0x85, 0xd5, 0xa2, 0xc4, | |
129 0x59, 0x5b, 0x1a, 0x95, 0xd1, 0xc1, 0xf9, 0x1b, 0x9f, 0x83, 0x5c, 0xd5, | |
130 0xd4, 0xa7, 0xda, 0xa0, 0x7c, 0x08, 0xb5, 0x9e, 0xdb, 0x9e, 0x2f, 0xa2, | |
131 0xc4, 0x23, 0x9f, 0x2f, 0x3d, 0x84, 0xc7, 0xc8, 0xaa, 0x26, 0xce, 0x1a, | |
132 0xd6, 0x54, 0x78, 0x2b, 0x78, 0x78, 0x22, 0x63, 0xb5, 0x6b, 0xa0, 0xdb, | |
133 0xf3, 0xfe, 0x57, 0x13, 0xd0, 0x75, 0x57, 0x11, 0x7d, 0xf0, 0xe1, 0x34, | |
134 0x39, 0x7c, 0xac, 0xef, 0xc9, 0x86, 0xec, 0xd3, 0x14, 0x05, 0x5a, 0x81, | |
135 0x81, 0xdc, 0x29, 0x56, 0xe3, 0x55, 0x8f, 0xdf, 0xad, 0xb1, 0x27, 0x86, | |
136 0x36, 0xa6, 0x60, 0x17, 0x62, 0x87, 0xee, 0x75, 0x06, 0x62, 0xd2, 0xef, | |
137 0xf9, 0x6e, 0x99, 0x77, 0x0e, 0xea, 0xc6, 0xb8, 0xce, 0xbc, 0x4a, 0x8a, | |
138 0x61, 0xe3, 0x28, 0x86, 0x55, 0x90, 0x98, 0x51, 0x84, 0xe4, 0x86, 0xb2, | |
139 0x40, 0xa5, 0x5b, 0x31, 0x45, 0xce, 0xf2, 0xe8, 0xb2, 0x20, 0xc8, 0x60, | |
140 0x8a, 0xae, 0xab, 0x94, 0x1c, 0x6f, 0xfb, 0x30, 0x47, 0x71, 0x77, 0x5d, | |
141 0xbf, 0x27, 0x94, 0xfc, 0xf6, 0xe2, 0x8c, 0x4d, 0xd0, 0xc6, 0x3e, 0x2a, | |
142 0xbb, 0xdd, 0xda, 0x89 | |
143 ]); | |
144 | |
145 // openssl dgst -sha1 -sign net/data/ssl/certificates/client_1.key | |
146 // -out signature.pkcs_sha1 input | |
147 // xxd -i signature.pkcs_sha1 | |
148 var signatureSha1Pkcs = new Uint8Array([ | |
149 0x74, 0x51, 0xe0, 0x09, 0xd7, 0xd2, 0xf3, 0xa1, 0xa0, 0x29, 0xec, 0x03, | |
150 0x2a, 0x75, 0x92, 0xac, 0x23, 0x86, 0x47, 0x37, 0x07, 0x8a, 0x66, 0xe3, | |
151 0x6b, 0x8f, 0x8e, 0xbf, 0x8e, 0x48, 0xab, 0x14, 0xe1, 0x54, 0x90, 0xd0, | |
152 0xf3, 0x94, 0xdb, 0x15, 0x5f, 0x05, 0xaf, 0x00, 0x8c, 0xb5, 0xac, 0x26, | |
153 0x85, 0xa9, 0xb4, 0xdc, 0x3a, 0x09, 0x9e, 0x13, 0x0a, 0x60, 0xbf, 0x8e, | |
154 0x9e, 0xc5, 0x42, 0xb0, 0x5d, 0x66, 0x5b, 0x82, 0xc9, 0xd0, 0x7b, 0xb9, | |
155 0x4c, 0x6f, 0xfb, 0xcc, 0x5c, 0xb3, 0x92, 0x98, 0xf6, 0x7e, 0x7d, 0xaa, | |
156 0x46, 0xb4, 0xc6, 0x81, 0x7e, 0x3a, 0x31, 0xe5, 0x46, 0x45, 0x08, 0x81, | |
157 0x1e, 0x1d, 0x0a, 0x9f, 0x71, 0x72, 0x6e, 0x7e, 0x24, 0x52, 0x93, 0x24, | |
158 0x78, 0x66, 0x71, 0x99, 0xa9, 0x03, 0xdc, 0xc9, 0x90, 0xe0, 0x5d, 0x9c, | |
159 0x45, 0x2a, 0xc3, 0x70, 0x6e, 0xa0, 0x82, 0xbb, 0x56, 0xd3, 0x00, 0x02, | |
160 0x30, 0x30, 0x2c, 0xb9, 0xe3, 0x6e, 0x9b, 0x2a, 0x9d, 0x81, 0xc3, 0x41, | |
161 0xb9, 0xfc, 0x63, 0x2c, 0x8c, 0xb5, 0x49, 0x9f, 0xc7, 0x08, 0x56, 0x87, | |
162 0x93, 0x69, 0x5d, 0xab, 0x78, 0xbb, 0xce, 0x5c, 0x24, 0xd3, 0x42, 0x60, | |
163 0x9a, 0xec, 0xa0, 0x4d, 0xa9, 0x8d, 0x79, 0x3b, 0xf7, 0xed, 0xc0, 0x03, | |
164 0x54, 0xc3, 0x1f, 0x91, 0x8b, 0xbd, 0x31, 0x08, 0x11, 0xa1, 0xe7, 0xcd, | |
165 0x53, 0x38, 0x8c, 0x32, 0x03, 0xc1, 0x88, 0x0a, 0xc4, 0x01, 0x3e, 0xfe, | |
166 0xb6, 0x56, 0x78, 0xdb, 0x7c, 0x7d, 0xe4, 0xe8, 0xca, 0xa5, 0xc5, 0x37, | |
167 0xda, 0xa4, 0xa2, 0x16, 0x6b, 0x66, 0xb0, 0x89, 0x28, 0x32, 0x90, 0xd2, | |
168 0xb8, 0xb1, 0x1c, 0x21, 0xcb, 0x3a, 0x68, 0xef, 0x18, 0x1e, 0x84, 0xc9, | |
169 0x6e, 0xe1, 0xc5, 0xb1, 0x8d, 0x23, 0x1b, 0xc2, 0xa6, 0xc7, 0x37, 0x7a, | |
170 0x76, 0x67, 0xb8, 0xa0 | |
171 ]); | |
172 | |
82 // The distinguished name of the CA that issued clientCert1 in DER encoding. | 173 // The distinguished name of the CA that issued clientCert1 in DER encoding. |
83 var ca1DistinguishedNameDER = new Uint8Array([ | 174 var ca1DistinguishedNameDER = new Uint8Array([ |
84 0x30, 0x0f, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, | 175 0x30, 0x0f, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, |
85 0x04, 0x42, 0x20, 0x43, 0x41 | 176 0x04, 0x42, 0x20, 0x43, 0x41 |
86 ]); | 177 ]); |
87 | 178 |
88 // A X.509 client certificate in DER encoding. | 179 // A X.509 client certificate in DER encoding. |
89 var clientCert2 = new Uint8Array([ | 180 var clientCert2 = new Uint8Array([ |
90 0x30, 0x82, 0x02, 0xd2, 0x30, 0x82, 0x01, 0xba, 0xa0, 0x03, 0x02, 0x01, | 181 0x30, 0x82, 0x02, 0xd2, 0x30, 0x82, 0x01, 0xba, 0xa0, 0x03, 0x02, 0x01, |
91 0x02, 0x02, 0x02, 0x10, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, | 182 0x02, 0x02, 0x02, 0x10, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 for (var i = 0; i < expectedCerts.length; i++) { | 279 for (var i = 0; i < expectedCerts.length; i++) { |
189 assertEq(expectedCerts[i], actualCerts[i], | 280 assertEq(expectedCerts[i], actualCerts[i], |
190 'Certs at index ' + i + ' differ'); | 281 'Certs at index ' + i + ' differ'); |
191 } | 282 } |
192 } | 283 } |
193 if (callback) | 284 if (callback) |
194 callback(); | 285 callback(); |
195 })); | 286 })); |
196 } | 287 } |
197 | 288 |
289 function checkAlgorithmIsCopiedOnRead(key) { | |
290 var algorithm = key.algorithm; | |
291 var originalAlgorithm = { | |
292 name: algorithm.name, | |
293 modulusLength: algorithm.modulusLength, | |
294 publicExponent: algorithm.publicExponent, | |
295 hash: {name: algorithm.hash.name} | |
296 }; | |
297 var originalModulusLength = algorithm.modulusLength; | |
298 algorithm.hash.name = null; | |
299 algorithm.hash = null; | |
300 algorithm.name = null; | |
301 algorithm.modulusLength = null; | |
302 algorithm.publicExponent = null; | |
303 assertEq(originalAlgorithm, key.algorithm); | |
304 } | |
305 | |
306 function checkPropertyIsReadOnly(object, key) { | |
307 var original = object[key]; | |
308 try { | |
309 object[key] = {}; | |
310 fail('Expected the property to be read-only and an exception to be thrown'); | |
311 } catch (error) { | |
312 assertEq(original, object[key]); | |
313 } | |
314 } | |
315 | |
316 function checkPrivateKeyFormat(privateKey) { | |
317 assertEq('private', privateKey.type); | |
318 assertEq(false, privateKey.extractable); | |
319 checkPropertyIsReadOnly(privateKey, 'algorithm'); | |
320 checkAlgorithmIsCopiedOnRead(privateKey); | |
321 } | |
322 | |
323 function checkPublicKeyFormat(publicKey) { | |
324 assertEq('public', publicKey.type); | |
325 assertEq(true, publicKey.extractable); | |
326 checkPropertyIsReadOnly(publicKey, 'algorithm'); | |
327 checkAlgorithmIsCopiedOnRead(publicKey); | |
328 } | |
329 | |
198 function testStaticMethods() { | 330 function testStaticMethods() { |
199 assertTrue(!!chrome.platformKeys, "No platformKeys namespace."); | 331 assertTrue(!!chrome.platformKeys, "No platformKeys namespace."); |
200 assertTrue(!!chrome.platformKeys.selectClientCertificates, | 332 assertTrue(!!chrome.platformKeys.selectClientCertificates, |
201 "No selectClientCertificates function."); | 333 "No selectClientCertificates function."); |
202 succeed(); | 334 succeed(); |
203 } | 335 } |
204 | 336 |
337 function testHasSubtleCryptoMethods(token) { | |
338 assertTrue(!!token.subtleCrypto.generateKey, | |
339 "token has no generateKey method"); | |
340 assertTrue(!!token.subtleCrypto.sign, "token has no sign method"); | |
341 assertTrue(!!token.subtleCrypto.exportKey, "token has no exportKey method"); | |
342 succeed(); | |
343 } | |
344 | |
205 function testSelectAllCerts() { | 345 function testSelectAllCerts() { |
206 var requestAll = { | 346 var requestAll = { |
207 certificateTypes: [], | 347 certificateTypes: [], |
208 certificateAuthorities: [] | 348 certificateAuthorities: [] |
209 }; | 349 }; |
210 var expectedCerts = [clientCert1]; | 350 var expectedCerts = [clientCert1]; |
211 if (systemTokenEnabled) | 351 if (systemTokenEnabled) |
212 expectedCerts.push(clientCert2); | 352 expectedCerts.push(clientCert2); |
213 assertCertsSelected(requestAll, expectedCerts); | 353 assertCertsSelected(requestAll, expectedCerts); |
214 } | 354 } |
215 | 355 |
216 function testSelectCA1Certs() { | 356 function testSelectCA1Certs() { |
217 var requestCA1 = { | 357 var requestCA1 = { |
218 certificateTypes: [], | 358 certificateTypes: [], |
219 certificateAuthorities: [ca1DistinguishedNameDER.buffer] | 359 certificateAuthorities: [ca1DistinguishedNameDER.buffer] |
220 }; | 360 }; |
221 assertCertsSelected(requestCA1, [clientCert1]); | 361 assertCertsSelected(requestCA1, [clientCert1]); |
222 } | 362 } |
223 | 363 |
364 function testMatchResult() { | |
365 var requestCA1 = { | |
366 certificateTypes: [], | |
367 certificateAuthorities: [ca1DistinguishedNameDER.buffer] | |
368 }; | |
369 chrome.platformKeys.selectClientCertificates( | |
370 {interactive: false, request: requestCA1}, | |
371 callbackPass(function(matches) { | |
372 var expectedAlgorithm = { | |
373 modulusLength: 2048, | |
374 name: "RSASSA-PKCS1-v1_5", | |
375 publicExponent: new Uint8Array([0x01, 0x00, 0x01]) | |
376 }; | |
377 var actualAlgorithm = matches[0].keyAlgorithm; | |
378 assertEq( | |
379 expectedAlgorithm, actualAlgorithm, | |
380 'Member algorithm of Match does not equal the expected algorithm'); | |
381 })); | |
382 } | |
383 | |
384 function getClientCert1Keys(keyParams, callback) { | |
385 var requestCA1 = { | |
386 certificateTypes: [], | |
387 certificateAuthorities: [ca1DistinguishedNameDER.buffer] | |
388 }; | |
389 chrome.platformKeys.selectClientCertificates( | |
390 {interactive: false, request: requestCA1}, | |
391 callbackPass(function(matches) { | |
392 chrome.platformKeys.getKeyPair(matches[0].certificate, keyParams, | |
393 callback); | |
394 })); | |
395 } | |
396 | |
397 function testGetKeyPair() { | |
398 var keyParams = { | |
399 // Algorithm names are case-insensitive. | |
400 'hash': {'name': 'sha-1'} | |
401 }; | |
402 getClientCert1Keys(keyParams, callbackPass(function(publicKey, privateKey) { | |
403 var expectedAlgorithm = { | |
404 modulusLength: 2048, | |
405 name: "RSASSA-PKCS1-v1_5", | |
406 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
407 hash: {name: 'SHA-1'} | |
408 }; | |
409 assertEq(expectedAlgorithm, publicKey.algorithm); | |
410 assertEq(expectedAlgorithm, privateKey.algorithm); | |
411 | |
412 checkPublicKeyFormat(publicKey); | |
413 checkPrivateKeyFormat(privateKey); | |
414 | |
415 chrome.platformKeys.subtleCrypto() | |
416 .exportKey('spki', publicKey) | |
417 .then(callbackPass(function(actualPublicKeySpki) { | |
418 assertTrue(compareArrays(clientPubkey1, actualPublicKeySpki) == 0, | |
419 'Match did not contain correct public key'); | |
420 }), | |
421 function(error) { fail("Export failed: " + error); }); | |
422 })); | |
423 } | |
424 | |
425 function testSignNoHash() { | |
426 var keyParams = { | |
427 // Algorithm names are case-insensitive. | |
428 hash: {name: 'NONE'} | |
429 }; | |
430 var signParams = { | |
431 name: 'RSASSA-PKCS1-v1_5' | |
432 }; | |
433 getClientCert1Keys(keyParams, callbackPass(function(publicKey, privateKey) { | |
434 chrome.platformKeys.subtleCrypto() | |
435 .sign(signParams, privateKey, rawData) | |
436 .then(callbackPass(function(signature) { | |
437 var actualSignature = new Uint8Array(signature); | |
438 assertTrue(compareArrays(signatureNoHashPkcs, actualSignature) == 0, | |
439 'Incorrect signature'); | |
440 })); | |
441 })); | |
442 } | |
443 | |
444 function testSignSha1() { | |
445 var keyParams = { | |
446 // Algorithm names are case-insensitive. | |
447 hash: {name: 'Sha-1'} | |
448 }; | |
449 var signParams = { | |
450 // Algorithm names are case-insensitive. | |
451 name: 'RSASSA-Pkcs1-v1_5' | |
452 }; | |
453 getClientCert1Keys(keyParams, callbackPass(function(publicKey, privateKey) { | |
454 chrome.platformKeys.subtleCrypto() | |
455 .sign(signParams, privateKey, rawData) | |
456 .then(callbackPass(function(signature) { | |
457 var actualSignature = new Uint8Array(signature); | |
458 assertTrue(compareArrays(signatureSha1Pkcs, actualSignature) == 0, | |
459 'Incorrect signature'); | |
460 })); | |
461 })); | |
462 } | |
463 | |
224 function runTests() { | 464 function runTests() { |
225 var tests = [ | 465 var tests = [ |
226 testStaticMethods, | 466 testStaticMethods, |
227 testSelectAllCerts, | 467 testSelectAllCerts, |
228 testSelectCA1Certs | 468 testSelectCA1Certs, |
469 testMatchResult, | |
470 testGetKeyPair, | |
471 testSignNoHash, | |
472 testSignSha1 | |
229 ]; | 473 ]; |
230 | 474 |
231 chrome.test.runTests(tests); | 475 chrome.test.runTests(tests); |
232 } | 476 } |
233 | 477 |
234 runTests(); | 478 runTests(); |
OLD | NEW |