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 'use strict'; | 8 'use strict'; |
9 | 9 |
10 var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1); | |
11 | |
10 var assertEq = chrome.test.assertEq; | 12 var assertEq = chrome.test.assertEq; |
11 var assertTrue = chrome.test.assertTrue; | 13 var assertTrue = chrome.test.assertTrue; |
12 var assertThrows = chrome.test.assertThrows; | 14 var assertThrows = chrome.test.assertThrows; |
13 var fail = chrome.test.fail; | 15 var fail = chrome.test.fail; |
14 var succeed = chrome.test.succeed; | 16 var succeed = chrome.test.succeed; |
15 var callbackPass = chrome.test.callbackPass; | 17 var callbackPass = chrome.test.callbackPass; |
16 var callbackFail= chrome.test.callbackFail; | 18 var callbackFail= chrome.test.callbackFail; |
17 | 19 |
18 // openssl req -new -x509 -key privkey.pem \ | 20 // openssl req -new -x509 -key privkey.pem \ |
19 // -outform der -out cert.der -days 36500 | 21 // -outform der -out cert.der -days 36500 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 function sortCerts(certs) { | 240 function sortCerts(certs) { |
239 return certs.sort(compareArrays); | 241 return certs.sort(compareArrays); |
240 } | 242 } |
241 | 243 |
242 /** | 244 /** |
243 * Checks whether the certificates currently stored in |token| match | 245 * Checks whether the certificates currently stored in |token| match |
244 * |expectedCerts| by comparing to the result of platformKeys.getCertificates. | 246 * |expectedCerts| by comparing to the result of platformKeys.getCertificates. |
245 * The order of |expectedCerts| is ignored. Afterwards calls |callback|. | 247 * The order of |expectedCerts| is ignored. Afterwards calls |callback|. |
246 */ | 248 */ |
247 function assertCertsStored(token, expectedCerts, callback) { | 249 function assertCertsStored(token, expectedCerts, callback) { |
250 if (!token) { | |
251 if (callback) | |
252 callback(); | |
253 return; | |
254 } | |
248 chrome.enterprise.platformKeys.getCertificates( | 255 chrome.enterprise.platformKeys.getCertificates( |
249 token.id, | 256 token.id, |
250 callbackPass(function(actualCerts) { | 257 callbackPass(function(actualCerts) { |
251 assertEq(expectedCerts.length, | 258 assertEq(expectedCerts.length, |
252 actualCerts.length, | 259 actualCerts.length, |
253 'Number of stored certs not as expected'); | 260 'Number of stored certs not as expected'); |
254 if (expectedCerts.length == actualCerts.length) { | 261 if (expectedCerts.length == actualCerts.length) { |
255 actualCerts = actualCerts.map( | 262 actualCerts = actualCerts.map( |
256 function(buffer) { return new Uint8Array(buffer); }); | 263 function(buffer) { return new Uint8Array(buffer); }); |
257 actualCerts = sortCerts(actualCerts); | 264 actualCerts = sortCerts(actualCerts); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 assertTrue(!!chrome.enterprise.platformKeys.getTokens, | 301 assertTrue(!!chrome.enterprise.platformKeys.getTokens, |
295 "No getTokens function."); | 302 "No getTokens function."); |
296 assertTrue(!!chrome.enterprise.platformKeys.importCertificate, | 303 assertTrue(!!chrome.enterprise.platformKeys.importCertificate, |
297 "No importCertificate function."); | 304 "No importCertificate function."); |
298 assertTrue(!!chrome.enterprise.platformKeys.removeCertificate, | 305 assertTrue(!!chrome.enterprise.platformKeys.removeCertificate, |
299 "No removeCertificate function."); | 306 "No removeCertificate function."); |
300 | 307 |
301 getTokens(function(userToken, systemToken) { | 308 getTokens(function(userToken, systemToken) { |
302 if (!userToken) | 309 if (!userToken) |
303 fail('no user token'); | 310 fail('no user token'); |
304 if (userToken.id != 'user') | 311 assertEq('user', userToken.id); |
305 fail('user token is not named "user".'); | |
306 | 312 |
307 if (!systemToken) | 313 if (systemTokenEnabled) { |
308 fail('no system token'); | 314 if (!systemToken) |
309 if (systemToken.id != 'system') | 315 fail('no system token'); |
310 fail('system token is not named "system".'); | 316 assertEq('system', systemToken.id); |
317 } else { | |
318 assertEq(null, | |
319 systemToken, | |
320 'system token is disabled, but found the token nonetheless.'); | |
321 } | |
311 | 322 |
312 callback(userToken, systemToken); | 323 callback(userToken, systemToken); |
313 }); | 324 }); |
314 } | 325 } |
315 | 326 |
316 function checkAlgorithmIsCopiedOnRead(key) { | 327 function checkAlgorithmIsCopiedOnRead(key) { |
317 var algorithm = key.algorithm; | 328 var algorithm = key.algorithm; |
318 var originalAlgorithm = { | 329 var originalAlgorithm = { |
319 name: algorithm.name, | 330 name: algorithm.name, |
320 modulusLength: algorithm.modulusLength, | 331 modulusLength: algorithm.modulusLength, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 return window.crypto.subtle.verify( | 435 return window.crypto.subtle.verify( |
425 algorithm, webCryptoPublicKey, cachedSignature, data); | 436 algorithm, webCryptoPublicKey, cachedSignature, data); |
426 }), | 437 }), |
427 function(error) { fail("Import failed: " + error); }) | 438 function(error) { fail("Import failed: " + error); }) |
428 .then(callbackPass(function(success) { | 439 .then(callbackPass(function(success) { |
429 assertEq(true, success, "Signature invalid."); | 440 assertEq(true, success, "Signature invalid."); |
430 callback(cachedKeyPair); | 441 callback(cachedKeyPair); |
431 }), function(error) { fail("Verification failed: " + error); }); | 442 }), function(error) { fail("Verification failed: " + error); }); |
432 } | 443 } |
433 | 444 |
445 function testInitiallyNoCerts(token) { | |
446 assertCertsStored(token, []); | |
447 } | |
448 | |
449 function testHasSubtleCryptoMethods(token) { | |
450 assertTrue(!!token.subtleCrypto.generateKey, | |
451 "token has no generateKey method"); | |
452 assertTrue(!!token.subtleCrypto.sign, "token has no sign method"); | |
453 assertTrue(!!token.subtleCrypto.exportKey, | |
454 "token has no exportKey method"); | |
455 succeed(); | |
456 } | |
457 | |
458 // Generates a key and signs some data with it. Verifies the signature using | |
459 // WebCrypto. Verifies also that a second sign operation fails. | |
460 function testGenerateKeyAndSign(token) { | |
461 var algorithm = { | |
462 name: "RSASSA-PKCS1-v1_5", | |
463 // RsaHashedKeyGenParams | |
464 modulusLength: 512, | |
465 // Equivalent to 65537 | |
466 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
467 hash: { | |
468 name: "SHA-1", | |
469 } | |
470 }; | |
471 | |
472 // Some random data to sign. | |
473 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]); | |
474 generateKeyAndVerify(token, | |
475 algorithm, | |
476 data, | |
477 callbackPass(function(keyPair) { | |
478 // Try to sign data with the same key a second time, which | |
479 // must fail. | |
480 var signParams = {name: 'RSASSA-PKCS1-v1_5'}; | |
481 token.subtleCrypto.sign(signParams, keyPair.privateKey, data).then( | |
482 function(signature) { fail("Second sign call was expected to fail."); }, | |
483 callbackPass(function(error) { | |
484 assertTrue(error instanceof Error); | |
485 assertEq('The operation failed for an operation-specific reason', | |
486 error.message); | |
487 })); | |
488 })); | |
489 } | |
490 | |
491 // Generates a key and signs some data with other parameters. Verifies the | |
492 // signature using WebCrypto. | |
493 function testGenerateKeyAndSignOtherParameters(token) { | |
494 var algorithm = { | |
495 name: "RSASSA-PKCS1-v1_5", | |
496 // RsaHashedKeyGenParams | |
497 modulusLength: 1024, | |
498 // Equivalent to 65537 | |
499 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
500 hash: { | |
501 name: "SHA-512", | |
502 } | |
503 }; | |
504 | |
505 // Some random data to sign. | |
506 var data = new Uint8Array([5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 254]); | |
507 generateKeyAndVerify(token, algorithm, data, callbackPass()); | |
508 } | |
509 | |
510 // Call generate key with invalid algorithm parameter, missing | |
511 // modulusLength. | |
512 function testAlgorithmParameterMissingModulusLength(token) { | |
513 var algorithm = { | |
514 name: "RSASSA-PKCS1-v1_5", | |
515 // Equivalent to 65537 | |
516 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
517 hash: { | |
518 name: "SHA-1", | |
519 } | |
520 }; | |
521 token.subtleCrypto.generateKey(algorithm, false, ['sign']) | |
522 .then(function(keyPair) { fail('generateKey was expected to fail'); }, | |
523 callbackPass(function(error) { | |
524 assertTrue(error instanceof Error); | |
525 assertEq('A required parameter was missing or out-of-range', error.message); | |
526 })); | |
527 } | |
528 | |
529 // Call generate key with invalid algorithm parameter, missing hash. | |
530 function testAlgorithmParameterMissingHash(token) { | |
531 var algorithm = { | |
532 name: 'RSASSA-PKCS1-v1_5', | |
533 modulusLength: 512, | |
534 // Equivalent to 65537 | |
535 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
536 }; | |
537 token.subtleCrypto.generateKey(algorithm, false, ['sign']) | |
538 .then(function(keyPair) { fail('generateKey was expected to fail'); }, | |
539 callbackPass(function(error) { | |
540 assertEq( | |
541 new Error('Error: A required parameter was missing our out-of-range'), | |
542 error); | |
543 })); | |
544 } | |
545 | |
546 // Call generate key with invalid algorithm parameter, unsupported public | |
547 // exponent. | |
548 function testAlgorithmParameterUnsupportedPublicExponent(token) { | |
549 var algorithm = { | |
550 name: 'RSASSA-PKCS1-v1_5', | |
551 modulusLength: 512, | |
552 // Different from 65537. | |
553 publicExponent: new Uint8Array([0x01, 0x01]), | |
554 }; | |
555 token.subtleCrypto.generateKey(algorithm, false, ['sign']) | |
556 .then(function(keyPair) { fail('generateKey was expected to fail'); }, | |
557 callbackPass(function(error) { | |
558 assertTrue(error instanceof Error); | |
559 assertEq('A required parameter was missing or out-of-range', error.message); | |
560 })); | |
561 } | |
562 | |
563 function testImportInvalidCert(token) { | |
564 var invalidCert = new ArrayBuffer(16); | |
565 chrome.enterprise.platformKeys.importCertificate( | |
566 token.id, | |
567 invalidCert, | |
568 callbackFail('Certificate is not a valid X.509 certificate.')); | |
569 } | |
570 | |
571 function testRemoveUnknownCert(token) { | |
572 chrome.enterprise.platformKeys.removeCertificate( | |
573 token.id, cert2.buffer, callbackFail('Certificate could not be found.')); | |
574 } | |
575 | |
576 function testRemoveInvalidCert(token) { | |
577 var invalidCert = new ArrayBuffer(16); | |
578 chrome.enterprise.platformKeys.removeCertificate( | |
579 token.id, | |
580 invalidCert, | |
581 callbackFail('Certificate is not a valid X.509 certificate.')); | |
582 } | |
583 | |
584 function bindTestsToToken(tests, token) { | |
585 var result = []; | |
586 for (var i = 0; i < tests.length; i++) { | |
587 var boundFunction = tests[i].bind(undefined, token) | |
588 boundFunction.generatedName = tests[i].name; | |
589 result.push(boundFunction); | |
590 } | |
591 return result; | |
Joao da Silva
2014/07/30 15:29:49
How about:
return tests.map(function(test) {
va
pneubeck (no reviews)
2014/08/02 19:09:12
Done.
| |
592 } | |
593 | |
434 function runTests(userToken, systemToken) { | 594 function runTests(userToken, systemToken) { |
435 chrome.test.runTests([ | 595 // These tests don't depend on keys being loaded on C++ side (which will be |
436 function hasSubtleCryptoMethods() { | 596 // removed by tests below) and are run for each available token. |
437 assertTrue(!!userToken.subtleCrypto.generateKey, | 597 var testsIndependentOfKeysWithTokenParameter = [ |
438 "user token has no generateKey method"); | 598 testInitiallyNoCerts, |
439 assertTrue(!!userToken.subtleCrypto.sign, | 599 testHasSubtleCryptoMethods, |
440 "user token has no sign method"); | 600 testRemoveUnknownCert, |
441 assertTrue(!!userToken.subtleCrypto.exportKey, | 601 testGenerateKeyAndSign, |
442 "user token has no exportKey method"); | 602 testGenerateKeyAndSignOtherParameters, |
443 succeed(); | 603 testAlgorithmParameterMissingModulusLength, |
444 }, | 604 testAlgorithmParameterMissingHash, |
445 | 605 testAlgorithmParameterUnsupportedPublicExponent, |
446 function initiallyNoCerts() { | 606 testImportInvalidCert, |
447 assertCertsStored(userToken, []); | 607 testRemoveInvalidCert, |
448 assertCertsStored(systemToken, []); | 608 ]; |
449 }, | 609 var testsIndependentOfKeys = |
450 | 610 bindTestsToToken(testsIndependentOfKeysWithTokenParameter, userToken); |
451 // Generates a key and signs some data with it. Verifies the signature using | 611 if (systemToken) { |
452 // WebCrypto. Verifies also that a second sign operation fails. | 612 testsIndependentOfKeys.concat(bindTestsToToken( |
453 function generateKeyAndSign() { | 613 testsIndependentOfKeysWithTokenParameter, systemToken)); |
454 var algorithm = { | 614 } |
455 name: "RSASSA-PKCS1-v1_5", | 615 |
456 // RsaHashedKeyGenParams | 616 // These tests are not parameterized and work with the keys loaded by the C++ |
457 modulusLength: 512, | 617 // side and potentially remove these keys from the tokens. |
458 // Equivalent to 65537 | 618 var testsNotParameterized = [ |
459 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
460 hash: { | |
461 name: "SHA-1", | |
462 } | |
463 }; | |
464 | |
465 // Some random data to sign. | |
466 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]); | |
467 generateKeyAndVerify(userToken, | |
468 algorithm, | |
469 data, | |
470 callbackPass(function(keyPair) { | |
471 // Try to sign data with the same key a second time, which | |
472 // must fail. | |
473 var signParams = {name: 'RSASSA-PKCS1-v1_5'}; | |
474 userToken.subtleCrypto.sign(signParams, keyPair.privateKey, data).then( | |
475 function(signature) { | |
476 fail("Second sign call was expected to fail."); | |
477 }, | |
478 callbackPass(function(error) { | |
479 assertTrue(error instanceof Error); | |
480 assertEq('The operation failed for an operation-specific reason', | |
481 error.message); | |
482 })); | |
483 })); | |
484 }, | |
485 | |
486 // Generates a key and signs some data with other parameters. Verifies the | |
487 // signature using WebCrypto. | |
488 function generateKeyAndSignOtherParameters() { | |
489 var algorithm = { | |
490 name: "RSASSA-PKCS1-v1_5", | |
491 // RsaHashedKeyGenParams | |
492 modulusLength: 1024, | |
493 // Equivalent to 65537 | |
494 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
495 hash: { | |
496 name: "SHA-512", | |
497 } | |
498 }; | |
499 | |
500 // Some random data to sign. | |
501 var data = new Uint8Array([5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 254]); | |
502 generateKeyAndVerify(userToken, algorithm, data, callbackPass()); | |
503 }, | |
504 | |
505 // Importing a cert should fail, if the private key is stored in another | 619 // Importing a cert should fail, if the private key is stored in another |
506 // token. | 620 // token. |
507 // This uses the cert that refers to the privateKeyPkcs8, which was imported | 621 // This uses the certs that refers to the privateKeyPkcs8User and |
508 // on C++'s side. | 622 // privateKeyPkcs8System keys, which were imported on C++'s side. |
509 function importCertWithKeyInOtherToken() { | 623 function importCertWithKeyInOtherToken() { |
510 chrome.enterprise.platformKeys.importCertificate( | 624 if (!systemToken) { |
511 systemToken.id, cert1a.buffer, callbackFail('Key not found.')); | 625 succeed(); |
626 return; | |
627 } | |
628 | |
629 function importToSystemWithKeyInUserToken(callback) { | |
630 chrome.enterprise.platformKeys.importCertificate( | |
631 systemToken.id, | |
632 cert1a.buffer, | |
633 callbackFail('Key not found.', callback)); | |
634 } | |
635 function importToUserWithKeyInSystemToken(callback) { | |
636 chrome.enterprise.platformKeys.importCertificate( | |
637 userToken.id, | |
638 certSystem.buffer, | |
639 callbackFail('Key not found.', callback)); | |
640 } | |
641 | |
642 importToSystemWithKeyInUserToken( | |
643 importToUserWithKeyInSystemToken.bind(null, null)); | |
512 }, | 644 }, |
513 | 645 |
514 // Imports and removes certificates for privateKeyPkcs8User, which was | 646 // Imports and removes certificates for privateKeyPkcs8User and |
647 // privateKeyPkcs8System (if the system token is enabled), which were | |
515 // imported on C++'s side. | 648 // imported on C++'s side. |
516 // Note: After this test, privateKeyPkcs8User is not stored anymore! | 649 // Note: After this test, privateKeyPkcs8User and privateKeyPkcs8System are |
517 function importAndRemoveCertsToUserToken() { | 650 // not stored anymore! |
518 runAsyncSequence([ | 651 function importAndRemoveCerts() { |
519 chrome.enterprise.platformKeys.importCertificate.bind( | 652 if (systemToken) { |
520 null, userToken.id, cert1a.buffer), | 653 runAsyncSequence([ |
521 assertCertsStored.bind(null, userToken, [cert1a]), | 654 chrome.enterprise.platformKeys.importCertificate.bind( |
522 // Importing the same cert again shouldn't change anything. | 655 null, userToken.id, cert1a.buffer), |
523 chrome.enterprise.platformKeys.importCertificate.bind( | 656 assertCertsStored.bind(null, userToken, [cert1a]), |
524 null, userToken.id, cert1a.buffer), | 657 |
525 assertCertsStored.bind(null, userToken, [cert1a]), | 658 // Importing the same cert again shouldn't change anything. |
526 // Importing another certificate should succeed. | 659 chrome.enterprise.platformKeys.importCertificate.bind( |
527 chrome.enterprise.platformKeys.importCertificate.bind( | 660 null, userToken.id, cert1a.buffer), |
528 null, userToken.id, cert1b.buffer), | 661 assertCertsStored.bind(null, userToken, [cert1a]), |
529 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | 662 |
530 // Shouldn't affect the system token. | 663 // The system token should still be empty. |
531 assertCertsStored.bind(null, systemToken, []), | 664 assertCertsStored.bind(null, systemToken, []), |
532 chrome.enterprise.platformKeys.removeCertificate.bind( | 665 |
533 null, userToken.id, cert1a.buffer), | 666 // Importing to the system token should not affect the user token. |
534 assertCertsStored.bind(null, userToken, [cert1b]), | 667 chrome.enterprise.platformKeys.importCertificate.bind( |
535 chrome.enterprise.platformKeys.removeCertificate.bind( | 668 null, systemToken.id, certSystem.buffer), |
536 null, userToken.id, cert1b.buffer), | 669 assertCertsStored.bind(null, systemToken, [certSystem]), |
537 assertCertsStored.bind(null, userToken, []) | 670 assertCertsStored.bind(null, userToken, [cert1a]), |
538 ]); | 671 |
672 // Importing the same cert again to the system token shouldn't change | |
673 // anything. | |
674 chrome.enterprise.platformKeys.importCertificate.bind( | |
675 null, systemToken.id, certSystem.buffer), | |
676 assertCertsStored.bind(null, systemToken, [certSystem]), | |
677 | |
678 // Importing another certificate should succeed. | |
679 chrome.enterprise.platformKeys.importCertificate.bind( | |
680 null, userToken.id, cert1b.buffer), | |
681 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | |
682 | |
683 // Remove cert1a. | |
684 chrome.enterprise.platformKeys.removeCertificate.bind( | |
685 null, userToken.id, cert1a.buffer), | |
686 assertCertsStored.bind(null, userToken, [cert1b]), | |
687 | |
688 // Remove certSystem. | |
689 chrome.enterprise.platformKeys.removeCertificate.bind( | |
690 null, systemToken.id, certSystem.buffer), | |
691 assertCertsStored.bind(null, systemToken, []), | |
692 assertCertsStored.bind(null, userToken, [cert1b]), | |
693 | |
694 // Remove cert1b. | |
695 chrome.enterprise.platformKeys.removeCertificate.bind( | |
696 null, userToken.id, cert1b.buffer), | |
697 assertCertsStored.bind(null, userToken, []) | |
698 ]); | |
699 } else { | |
700 runAsyncSequence([ | |
701 chrome.enterprise.platformKeys.importCertificate.bind( | |
702 null, userToken.id, cert1a.buffer), | |
703 assertCertsStored.bind(null, userToken, [cert1a]), | |
704 // Importing the same cert again shouldn't change anything. | |
705 chrome.enterprise.platformKeys.importCertificate.bind( | |
706 null, userToken.id, cert1a.buffer), | |
707 assertCertsStored.bind(null, userToken, [cert1a]), | |
708 // Importing another certificate should succeed. | |
709 chrome.enterprise.platformKeys.importCertificate.bind( | |
710 null, userToken.id, cert1b.buffer), | |
711 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | |
712 chrome.enterprise.platformKeys.removeCertificate.bind( | |
713 null, userToken.id, cert1a.buffer), | |
714 assertCertsStored.bind(null, userToken, [cert1b]), | |
715 chrome.enterprise.platformKeys.removeCertificate.bind( | |
716 null, userToken.id, cert1b.buffer), | |
717 assertCertsStored.bind(null, userToken, []) | |
718 ]); | |
719 } | |
539 }, | 720 }, |
540 | 721 |
541 // Imports and removes certificates for privateKeyPkcs8System, which was | 722 function getCertsInvalidToken() { |
542 // imported on C++'s side. | 723 chrome.enterprise.platformKeys.getCertificates( |
543 // Note: After this test, privateKeyPkcs8System is not stored anymore! | 724 'invalid token id', callbackFail('The token is not valid.')); |
544 function importAndRemoveCertsToSystemToken() { | |
545 runAsyncSequence([ | |
546 chrome.enterprise.platformKeys.importCertificate.bind( | |
547 null, systemToken.id, certSystem.buffer), | |
548 assertCertsStored.bind(null, systemToken, [certSystem]), | |
549 // Importing the same cert again shouldn't change anything. | |
550 chrome.enterprise.platformKeys.importCertificate.bind( | |
551 null, systemToken.id, certSystem.buffer), | |
552 assertCertsStored.bind(null, systemToken, [certSystem]), | |
553 // Shouldn't affect the user token. | |
554 assertCertsStored.bind(null, userToken, []), | |
555 chrome.enterprise.platformKeys.removeCertificate.bind( | |
556 null, systemToken.id, certSystem.buffer), | |
557 assertCertsStored.bind(null, systemToken, []), | |
558 ]); | |
559 }, | 725 }, |
560 | 726 |
561 // Call generate key with invalid algorithm parameter, missing | |
562 // modulusLength. | |
563 function algorithmParameterMissingModulusLength() { | |
564 var algorithm = { | |
565 name: "RSASSA-PKCS1-v1_5", | |
566 // Equivalent to 65537 | |
567 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
568 hash: { | |
569 name: "SHA-1", | |
570 } | |
571 }; | |
572 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | |
573 function(keyPair) { fail('generateKey was expected to fail'); }, | |
574 callbackPass(function(error) { | |
575 assertTrue(error instanceof Error); | |
576 assertEq('A required parameter was missing or out-of-range', | |
577 error.message); | |
578 })); | |
579 }, | |
580 | |
581 // Call generate key with invalid algorithm parameter, missing hash. | |
582 function algorithmParameterMissingHash() { | |
583 var algorithm = { | |
584 name: 'RSASSA-PKCS1-v1_5', | |
585 modulusLength: 512, | |
586 // Equivalent to 65537 | |
587 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | |
588 }; | |
589 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | |
590 function(keyPair) { fail('generateKey was expected to fail'); }, | |
591 callbackPass(function(error) { | |
592 assertEq( | |
593 new Error('Error: A required parameter was missing our out-of-range'), | |
594 error); | |
595 })); | |
596 }, | |
597 | |
598 // Call generate key with invalid algorithm parameter, unsupported public | |
599 // exponent. | |
600 function algorithmParameterUnsupportedPublicExponent() { | |
601 var algorithm = { | |
602 name: 'RSASSA-PKCS1-v1_5', | |
603 modulusLength: 512, | |
604 // Different from 65537. | |
605 publicExponent: new Uint8Array([0x01, 0x01]), | |
606 }; | |
607 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | |
608 function(keyPair) { fail('generateKey was expected to fail'); }, | |
609 callbackPass(function(error) { | |
610 assertTrue(error instanceof Error); | |
611 assertEq('A required parameter was missing or out-of-range', | |
612 error.message); | |
613 })); | |
614 }, | |
615 | |
616 // Imports a certificate for which no private key was imported/generated | 727 // Imports a certificate for which no private key was imported/generated |
617 // before. | 728 // before. |
618 function missingPrivateKey() { | 729 function missingPrivateKey() { |
619 chrome.enterprise.platformKeys.importCertificate( | 730 chrome.enterprise.platformKeys.importCertificate( |
620 userToken.id, cert2.buffer, callbackFail('Key not found.')); | 731 userToken.id, cert2.buffer, callbackFail('Key not found.')); |
Joao da Silva
2014/07/30 15:29:49
Can this be tested with the systemToken too?
pneubeck (no reviews)
2014/08/02 19:09:12
Done.
| |
621 }, | 732 } |
733 ]; | |
622 | 734 |
623 function importInvalidCert() { | 735 chrome.test.runTests(testsIndependentOfKeys.concat(testsNotParameterized)); |
624 var invalidCert = new ArrayBuffer(16); | |
625 chrome.enterprise.platformKeys.importCertificate( | |
626 userToken.id, | |
627 invalidCert, | |
628 callbackFail('Certificate is not a valid X.509 certificate.')); | |
629 }, | |
630 | |
631 function removeUnknownCert() { | |
632 chrome.enterprise.platformKeys.removeCertificate( | |
633 userToken.id, | |
634 cert2.buffer, | |
635 callbackFail('Certificate could not be found.')); | |
636 }, | |
637 | |
638 function removeInvalidCert() { | |
639 var invalidCert = new ArrayBuffer(16); | |
640 chrome.enterprise.platformKeys.removeCertificate( | |
641 userToken.id, | |
642 invalidCert, | |
643 callbackFail('Certificate is not a valid X.509 certificate.')); | |
644 }, | |
645 | |
646 function getCertsInvalidToken() { | |
647 chrome.enterprise.platformKeys.getCertificates( | |
648 'invalid token id', callbackFail('The token is not valid.')); | |
649 } | |
650 ]); | |
651 } | 736 } |
652 | 737 |
653 beforeTests(runTests); | 738 beforeTests(runTests); |
OLD | NEW |