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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 assertEq(algorithm.publicExponent, | 330 assertEq(algorithm.publicExponent, |
331 webCryptoPublicKey.algorithm.publicExponent); | 331 webCryptoPublicKey.algorithm.publicExponent); |
332 return window.crypto.subtle.verify( | 332 return window.crypto.subtle.verify( |
333 algorithm, webCryptoPublicKey, cachedSignature, data); | 333 algorithm, webCryptoPublicKey, cachedSignature, data); |
334 }), | 334 }), |
335 function(error) { | 335 function(error) { |
336 assertTrue(false, "Import failed: " + error); | 336 assertTrue(false, "Import failed: " + error); |
337 }) | 337 }) |
338 .then(callbackPass(function(success) { | 338 .then(callbackPass(function(success) { |
339 assertEq(true, success, "Signature invalid."); | 339 assertEq(true, success, "Signature invalid."); |
| 340 // Try to sign data with the same key a second time, which |
| 341 // must fail. |
| 342 return userToken.subtleCrypto.sign( |
| 343 {}, cachedKeyPair.privateKey, data); |
340 }), | 344 }), |
341 function(error) { | 345 function(error) { |
342 assertTrue(false, "Verification failed: " + error); | 346 assertTrue(false, "Verification failed: " + error); |
343 }); | 347 }) |
| 348 .then(function(signature) { |
| 349 assertTrue(false, "Second sign call was expected to fail."); |
| 350 }, callbackPass(function(error) { |
| 351 assertTrue(error instanceof Error); |
| 352 assertEq( |
| 353 'The operation failed for an operation-specific reason', |
| 354 error.message); |
| 355 })); |
344 }, | 356 }, |
345 | 357 |
346 // Imports and removes certificates for privateKeyPkcs8, which was imported | 358 // Imports and removes certificates for privateKeyPkcs8, which was imported |
347 // by on C++'s side. | 359 // by on C++'s side. |
348 // Note: After this test, privateKeyPkcs8 is not stored anymore! | 360 // Note: After this test, privateKeyPkcs8 is not stored anymore! |
349 function importAndRemoveCerts() { | 361 function importAndRemoveCerts() { |
350 runAsyncSequence([ | 362 runAsyncSequence([ |
351 chrome.enterprise.platformKeys.importCertificate.bind( | 363 chrome.enterprise.platformKeys.importCertificate.bind( |
352 null, userToken.id, cert1a.buffer), | 364 null, userToken.id, cert1a.buffer), |
353 assertCertsStored.bind(null, userToken, [cert1a]), | 365 assertCertsStored.bind(null, userToken, [cert1a]), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 callbackFail('Certificate is not a valid X.509 certificate.')); | 468 callbackFail('Certificate is not a valid X.509 certificate.')); |
457 }, | 469 }, |
458 function getCertsInvalidToken() { | 470 function getCertsInvalidToken() { |
459 chrome.enterprise.platformKeys.getCertificates( | 471 chrome.enterprise.platformKeys.getCertificates( |
460 'invalid token id', callbackFail('The token is not valid.')); | 472 'invalid token id', callbackFail('The token is not valid.')); |
461 } | 473 } |
462 ]); | 474 ]); |
463 } | 475 } |
464 | 476 |
465 beforeTests(runTests); | 477 beforeTests(runTests); |
OLD | NEW |