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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 assertEq(algorithm.modulusLength, | 320 assertEq(algorithm.modulusLength, |
321 webCryptoPublicKey.algorithm.modulusLength); | 321 webCryptoPublicKey.algorithm.modulusLength); |
322 return window.crypto.subtle.verify( | 322 return window.crypto.subtle.verify( |
323 algorithm, webCryptoPublicKey, cachedSignature, data); | 323 algorithm, webCryptoPublicKey, cachedSignature, data); |
324 }), | 324 }), |
325 function(error) { | 325 function(error) { |
326 assertTrue(false, "Import failed: " + error); | 326 assertTrue(false, "Import failed: " + error); |
327 }) | 327 }) |
328 .then(callbackPass(function(success) { | 328 .then(callbackPass(function(success) { |
329 assertEq(true, success, "Signature invalid."); | 329 assertEq(true, success, "Signature invalid."); |
| 330 // Try to sign data with the same key a second time, which |
| 331 // must fail. |
| 332 return userToken.subtleCrypto.sign( |
| 333 {}, cachedKeyPair.privateKey, data); |
330 }), | 334 }), |
331 function(error) { | 335 function(error) { |
332 assertTrue(false, "Verification failed: " + error); | 336 assertTrue(false, "Verification failed: " + error); |
333 }); | 337 }) |
| 338 .then(function(signature) { |
| 339 assertTrue(false, "Second sign call was expected to fail."); |
| 340 }, callbackPass(function(error) { |
| 341 assertTrue(error instanceof Error); |
| 342 assertEq( |
| 343 'The operation failed for an operation-specific reason', |
| 344 error.message); |
| 345 })); |
334 }, | 346 }, |
335 | 347 |
336 // Imports and removes certificates for privateKeyPkcs8, which was imported | 348 // Imports and removes certificates for privateKeyPkcs8, which was imported |
337 // by on C++'s side. | 349 // by on C++'s side. |
338 // Note: After this test, privateKeyPkcs8 is not stored anymore! | 350 // Note: After this test, privateKeyPkcs8 is not stored anymore! |
339 function importAndRemoveCerts() { | 351 function importAndRemoveCerts() { |
340 runAsyncSequence([ | 352 runAsyncSequence([ |
341 chrome.enterprise.platformKeys.importCertificate.bind( | 353 chrome.enterprise.platformKeys.importCertificate.bind( |
342 null, userToken.id, cert1a.buffer), | 354 null, userToken.id, cert1a.buffer), |
343 assertCertsStored.bind(null, userToken, [cert1a]), | 355 assertCertsStored.bind(null, userToken, [cert1a]), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 callbackFail('Certificate is not a valid X.509 certificate.')); | 397 callbackFail('Certificate is not a valid X.509 certificate.')); |
386 }, | 398 }, |
387 function getCertsInvalidToken() { | 399 function getCertsInvalidToken() { |
388 chrome.enterprise.platformKeys.getCertificates( | 400 chrome.enterprise.platformKeys.getCertificates( |
389 'invalid token id', callbackFail('The token is not valid.')); | 401 'invalid token id', callbackFail('The token is not valid.')); |
390 } | 402 } |
391 ]); | 403 ]); |
392 } | 404 } |
393 | 405 |
394 beforeTests(runTests); | 406 beforeTests(runTests); |
OLD | NEW |