OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Must be packed to ../enterprise_platform_keys.crx using the private key | 5 // Must be packed to ../enterprise_platform_keys.crx using the private key |
6 // ../enterprise_platform_keys.pem . | 6 // ../enterprise_platform_keys.pem . |
7 | 7 |
8 var assertEq = chrome.test.assertEq; | 8 var assertEq = chrome.test.assertEq; |
9 var assertTrue = chrome.test.assertTrue; | 9 var assertTrue = chrome.test.assertTrue; |
10 var assertThrows = chrome.test.assertThrows; | 10 var assertThrows = chrome.test.assertThrows; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 }, | 271 }, |
272 function initiallyNoCerts() { assertCertsStored(userToken, []); }, | 272 function initiallyNoCerts() { assertCertsStored(userToken, []); }, |
273 | 273 |
274 // Generates a key and sign some data with it. Verifies the signature using | 274 // Generates a key and sign some data with it. Verifies the signature using |
275 // WebCrypto. | 275 // WebCrypto. |
276 function generateKeyAndSign() { | 276 function generateKeyAndSign() { |
277 var algorithm = { | 277 var algorithm = { |
278 name: "RSASSA-PKCS1-v1_5", | 278 name: "RSASSA-PKCS1-v1_5", |
279 // RsaHashedKeyGenParams | 279 // RsaHashedKeyGenParams |
280 modulusLength: 512, | 280 modulusLength: 512, |
281 publicExponent: | 281 // Use some non-standard exponent. This one is equivalent to 257 |
282 new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 | 282 publicExponent: new Uint8Array([0x01, 0x01]), |
283 hash: { | 283 hash: { |
284 name: "SHA-1", | 284 name: "SHA-1", |
285 } | 285 } |
286 }; | 286 }; |
287 // Some random data to sign. | 287 // Some random data to sign. |
288 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]); | 288 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]); |
289 var cachedKeyPair; | 289 var cachedKeyPair; |
290 var cachedSpki; | 290 var cachedSpki; |
291 var cachedSignature; | 291 var cachedSignature; |
292 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) | 292 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) |
293 .then(callbackPass(function(keyPair) { | 293 .then(callbackPass(function(keyPair) { |
294 assertTrue(!!keyPair, "No key pair."); | 294 assertTrue(!!keyPair, "No key pair."); |
295 cachedKeyPair = keyPair; | 295 cachedKeyPair = keyPair; |
296 return userToken.subtleCrypto.exportKey('spki', | 296 return userToken.subtleCrypto.exportKey('spki', |
297 keyPair.publicKey); | 297 keyPair.publicKey); |
298 }), | 298 }), |
299 function(error) { | 299 function(error) { |
300 assertTrue(false, "GenerateKey failed: " + error); | 300 assertTrue(false, "GenerateKey failed: " + error); |
301 }) | 301 }) |
302 .then(callbackPass(function(publicKeySpki) { | 302 .then(callbackPass(function(publicKeySpki) { |
303 cachedSpki = publicKeySpki; | 303 cachedSpki = publicKeySpki; |
304 var signParams = {name: 'RSASSA-PKCS1-v1_5'}; | 304 var signParams = {name: 'RSASSA-PKCS1-v1_5'}; |
305 return userToken.subtleCrypto.sign( | 305 return userToken.subtleCrypto.sign( |
306 signParams, cachedKeyPair.privateKey, data); | 306 signParams, cachedKeyPair.privateKey, data); |
307 }), | 307 }), |
308 function(error) { | 308 function(error) { |
309 assertTrue(false, "Export failed: " + error); | 309 assertTrue(false, "Export failed: " + error); |
310 }) | 310 }) |
311 .then(callbackPass(function(signature) { | 311 .then(callbackPass(function(signature) { |
| 312 var importParams = { |
| 313 name: algorithm.name, |
| 314 // RsaHashedImportParams |
| 315 hash: { |
| 316 name: "SHA-1", |
| 317 } |
| 318 }; |
312 assertTrue(!!signature, "No signature."); | 319 assertTrue(!!signature, "No signature."); |
313 assertTrue(signature.length != 0, "Signature is empty."); | 320 assertTrue(signature.length != 0, "Signature is empty."); |
314 cachedSignature = signature; | 321 cachedSignature = signature; |
315 return window.crypto.subtle.importKey( | 322 return window.crypto.subtle.importKey( |
316 "spki", cachedSpki, algorithm, false, ["verify"]); | 323 "spki", cachedSpki, importParams, false, ["verify"]); |
317 }), | 324 }), |
318 function(error) { assertTrue(false, "Sign failed: " + error); }) | 325 function(error) { assertTrue(false, "Sign failed: " + error); }) |
319 .then(callbackPass(function(webCryptoPublicKey) { | 326 .then(callbackPass(function(webCryptoPublicKey) { |
320 assertTrue(!!webCryptoPublicKey); | 327 assertTrue(!!webCryptoPublicKey); |
321 assertEq(algorithm.modulusLength, | 328 assertEq(algorithm.modulusLength, |
322 webCryptoPublicKey.algorithm.modulusLength); | 329 webCryptoPublicKey.algorithm.modulusLength); |
| 330 console.log(algorithm.publicExponent); |
| 331 assertEq(algorithm.publicExponent, |
| 332 webCryptoPublicKey.algorithm.publicExponent); |
323 return window.crypto.subtle.verify( | 333 return window.crypto.subtle.verify( |
324 algorithm, webCryptoPublicKey, cachedSignature, data); | 334 algorithm, webCryptoPublicKey, cachedSignature, data); |
325 }), | 335 }), |
326 function(error) { | 336 function(error) { |
327 assertTrue(false, "Import failed: " + error); | 337 assertTrue(false, "Import failed: " + error); |
328 }) | 338 }) |
329 .then(callbackPass(function(success) { | 339 .then(callbackPass(function(success) { |
330 assertEq(true, success, "Signature invalid."); | 340 assertEq(true, success, "Signature invalid."); |
331 }), | 341 }), |
332 function(error) { | 342 function(error) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 callbackFail('Certificate is not a valid X.509 certificate.')); | 437 callbackFail('Certificate is not a valid X.509 certificate.')); |
428 }, | 438 }, |
429 function getCertsInvalidToken() { | 439 function getCertsInvalidToken() { |
430 chrome.enterprise.platformKeys.getCertificates( | 440 chrome.enterprise.platformKeys.getCertificates( |
431 'invalid token id', callbackFail('The token is not valid.')); | 441 'invalid token id', callbackFail('The token is not valid.')); |
432 } | 442 } |
433 ]); | 443 ]); |
434 } | 444 } |
435 | 445 |
436 beforeTests(runTests); | 446 beforeTests(runTests); |
OLD | NEW |