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 return tests.map(function(test) { |
| 586 var bound = test.bind(undefined, token); |
| 587 bound.generatedName = test.name; |
| 588 return bound; |
| 589 }); |
| 590 } |
| 591 |
434 function runTests(userToken, systemToken) { | 592 function runTests(userToken, systemToken) { |
435 chrome.test.runTests([ | 593 // These tests don't depend on keys being loaded on C++ side (which will be |
436 function hasSubtleCryptoMethods() { | 594 // removed by tests below) and are run for each available token. |
437 assertTrue(!!userToken.subtleCrypto.generateKey, | 595 var testsIndependentOfKeysWithTokenParameter = [ |
438 "user token has no generateKey method"); | 596 testInitiallyNoCerts, |
439 assertTrue(!!userToken.subtleCrypto.sign, | 597 testHasSubtleCryptoMethods, |
440 "user token has no sign method"); | 598 testRemoveUnknownCert, |
441 assertTrue(!!userToken.subtleCrypto.exportKey, | 599 testGenerateKeyAndSign, |
442 "user token has no exportKey method"); | 600 testGenerateKeyAndSignOtherParameters, |
443 succeed(); | 601 testAlgorithmParameterMissingModulusLength, |
444 }, | 602 testAlgorithmParameterMissingHash, |
445 | 603 testAlgorithmParameterUnsupportedPublicExponent, |
446 function initiallyNoCerts() { | 604 testImportInvalidCert, |
447 assertCertsStored(userToken, []); | 605 testRemoveInvalidCert, |
448 assertCertsStored(systemToken, []); | 606 ]; |
449 }, | 607 var testsIndependentOfKeys = |
450 | 608 bindTestsToToken(testsIndependentOfKeysWithTokenParameter, userToken); |
451 // Generates a key and signs some data with it. Verifies the signature using | 609 if (systemToken) { |
452 // WebCrypto. Verifies also that a second sign operation fails. | 610 testsIndependentOfKeys.concat(bindTestsToToken( |
453 function generateKeyAndSign() { | 611 testsIndependentOfKeysWithTokenParameter, systemToken)); |
454 var algorithm = { | 612 } |
455 name: "RSASSA-PKCS1-v1_5", | 613 |
456 // RsaHashedKeyGenParams | 614 // These tests are not parameterized and work with the keys loaded by the C++ |
457 modulusLength: 512, | 615 // side and potentially remove these keys from the tokens. |
458 // Equivalent to 65537 | 616 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 | 617 // Importing a cert should fail, if the private key is stored in another |
506 // token. | 618 // token. |
507 // This uses the cert that refers to the privateKeyPkcs8, which was imported | 619 // This uses the certs that refers to the privateKeyPkcs8User and |
508 // on C++'s side. | 620 // privateKeyPkcs8System keys, which were imported on C++'s side. |
509 function importCertWithKeyInOtherToken() { | 621 function importCertWithKeyInOtherToken() { |
510 chrome.enterprise.platformKeys.importCertificate( | 622 if (!systemToken) { |
511 systemToken.id, cert1a.buffer, callbackFail('Key not found.')); | 623 succeed(); |
| 624 return; |
| 625 } |
| 626 |
| 627 function importToSystemWithKeyInUserToken(callback) { |
| 628 chrome.enterprise.platformKeys.importCertificate( |
| 629 systemToken.id, |
| 630 cert1a.buffer, |
| 631 callbackFail('Key not found.', callback)); |
| 632 } |
| 633 function importToUserWithKeyInSystemToken(callback) { |
| 634 chrome.enterprise.platformKeys.importCertificate( |
| 635 userToken.id, |
| 636 certSystem.buffer, |
| 637 callbackFail('Key not found.', callback)); |
| 638 } |
| 639 |
| 640 importToSystemWithKeyInUserToken( |
| 641 importToUserWithKeyInSystemToken.bind(null, null)); |
512 }, | 642 }, |
513 | 643 |
514 // Imports and removes certificates for privateKeyPkcs8User, which was | 644 // Imports and removes certificates for privateKeyPkcs8User and |
| 645 // privateKeyPkcs8System (if the system token is enabled), which were |
515 // imported on C++'s side. | 646 // imported on C++'s side. |
516 // Note: After this test, privateKeyPkcs8User is not stored anymore! | 647 // Note: After this test, privateKeyPkcs8User and privateKeyPkcs8System are |
517 function importAndRemoveCertsToUserToken() { | 648 // not stored anymore! |
518 runAsyncSequence([ | 649 function importAndRemoveCerts() { |
519 chrome.enterprise.platformKeys.importCertificate.bind( | 650 if (systemToken) { |
520 null, userToken.id, cert1a.buffer), | 651 runAsyncSequence([ |
521 assertCertsStored.bind(null, userToken, [cert1a]), | 652 chrome.enterprise.platformKeys.importCertificate.bind( |
522 // Importing the same cert again shouldn't change anything. | 653 null, userToken.id, cert1a.buffer), |
523 chrome.enterprise.platformKeys.importCertificate.bind( | 654 assertCertsStored.bind(null, userToken, [cert1a]), |
524 null, userToken.id, cert1a.buffer), | 655 |
525 assertCertsStored.bind(null, userToken, [cert1a]), | 656 // Importing the same cert again shouldn't change anything. |
526 // Importing another certificate should succeed. | 657 chrome.enterprise.platformKeys.importCertificate.bind( |
527 chrome.enterprise.platformKeys.importCertificate.bind( | 658 null, userToken.id, cert1a.buffer), |
528 null, userToken.id, cert1b.buffer), | 659 assertCertsStored.bind(null, userToken, [cert1a]), |
529 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | 660 |
530 // Shouldn't affect the system token. | 661 // The system token should still be empty. |
531 assertCertsStored.bind(null, systemToken, []), | 662 assertCertsStored.bind(null, systemToken, []), |
532 chrome.enterprise.platformKeys.removeCertificate.bind( | 663 |
533 null, userToken.id, cert1a.buffer), | 664 // Importing to the system token should not affect the user token. |
534 assertCertsStored.bind(null, userToken, [cert1b]), | 665 chrome.enterprise.platformKeys.importCertificate.bind( |
535 chrome.enterprise.platformKeys.removeCertificate.bind( | 666 null, systemToken.id, certSystem.buffer), |
536 null, userToken.id, cert1b.buffer), | 667 assertCertsStored.bind(null, systemToken, [certSystem]), |
537 assertCertsStored.bind(null, userToken, []) | 668 assertCertsStored.bind(null, userToken, [cert1a]), |
538 ]); | 669 |
| 670 // Importing the same cert again to the system token shouldn't change |
| 671 // anything. |
| 672 chrome.enterprise.platformKeys.importCertificate.bind( |
| 673 null, systemToken.id, certSystem.buffer), |
| 674 assertCertsStored.bind(null, systemToken, [certSystem]), |
| 675 |
| 676 // Importing another certificate should succeed. |
| 677 chrome.enterprise.platformKeys.importCertificate.bind( |
| 678 null, userToken.id, cert1b.buffer), |
| 679 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), |
| 680 |
| 681 // Remove cert1a. |
| 682 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 683 null, userToken.id, cert1a.buffer), |
| 684 assertCertsStored.bind(null, userToken, [cert1b]), |
| 685 |
| 686 // Remove certSystem. |
| 687 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 688 null, systemToken.id, certSystem.buffer), |
| 689 assertCertsStored.bind(null, systemToken, []), |
| 690 assertCertsStored.bind(null, userToken, [cert1b]), |
| 691 |
| 692 // Remove cert1b. |
| 693 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 694 null, userToken.id, cert1b.buffer), |
| 695 assertCertsStored.bind(null, userToken, []) |
| 696 ]); |
| 697 } else { |
| 698 runAsyncSequence([ |
| 699 chrome.enterprise.platformKeys.importCertificate.bind( |
| 700 null, userToken.id, cert1a.buffer), |
| 701 assertCertsStored.bind(null, userToken, [cert1a]), |
| 702 // Importing the same cert again shouldn't change anything. |
| 703 chrome.enterprise.platformKeys.importCertificate.bind( |
| 704 null, userToken.id, cert1a.buffer), |
| 705 assertCertsStored.bind(null, userToken, [cert1a]), |
| 706 // Importing another certificate should succeed. |
| 707 chrome.enterprise.platformKeys.importCertificate.bind( |
| 708 null, userToken.id, cert1b.buffer), |
| 709 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), |
| 710 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 711 null, userToken.id, cert1a.buffer), |
| 712 assertCertsStored.bind(null, userToken, [cert1b]), |
| 713 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 714 null, userToken.id, cert1b.buffer), |
| 715 assertCertsStored.bind(null, userToken, []) |
| 716 ]); |
| 717 } |
539 }, | 718 }, |
540 | 719 |
541 // Imports and removes certificates for privateKeyPkcs8System, which was | 720 function getCertsInvalidToken() { |
542 // imported on C++'s side. | 721 chrome.enterprise.platformKeys.getCertificates( |
543 // Note: After this test, privateKeyPkcs8System is not stored anymore! | 722 '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 }, | |
560 | |
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 }, | 723 }, |
615 | 724 |
616 // Imports a certificate for which no private key was imported/generated | 725 // Imports a certificate for which no private key was imported/generated |
617 // before. | 726 // before. |
618 function missingPrivateKey() { | 727 function missingPrivateKeyUserToken() { |
619 chrome.enterprise.platformKeys.importCertificate( | 728 chrome.enterprise.platformKeys.importCertificate( |
620 userToken.id, cert2.buffer, callbackFail('Key not found.')); | 729 userToken.id, cert2.buffer, callbackFail('Key not found.')); |
621 }, | 730 }, |
622 | 731 |
623 function importInvalidCert() { | 732 function missingPrivateKeySystemToken() { |
624 var invalidCert = new ArrayBuffer(16); | 733 if (!systemToken) { |
| 734 succeed(); |
| 735 return; |
| 736 } |
625 chrome.enterprise.platformKeys.importCertificate( | 737 chrome.enterprise.platformKeys.importCertificate( |
626 userToken.id, | 738 systemToken.id, certSystem.buffer, callbackFail('Key not found.')); |
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 } | 739 } |
650 ]); | 740 ]; |
| 741 |
| 742 chrome.test.runTests(testsIndependentOfKeys.concat(testsNotParameterized)); |
651 } | 743 } |
652 | 744 |
653 beforeTests(runTests); | 745 beforeTests(runTests); |
OLD | NEW |