OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "net/cert/internal/signature_algorithm.h" | 5 #include "net/cert/internal/signature_algorithm.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "net/base/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
10 #include "net/cert/pem_tokenizer.h" | 10 #include "net/cert/pem_tokenizer.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 EXPECT_FALSE(alg1.ParamsForRsaPss()); | 470 EXPECT_FALSE(alg1.ParamsForRsaPss()); |
471 } | 471 } |
472 | 472 |
473 // Tests that the parmeters returned for an invalid algorithm are null. | 473 // Tests that the parmeters returned for an invalid algorithm are null. |
474 TEST(SignatureAlgorithmTest, ParamsAreNullForWrongType_Invalid) { | 474 TEST(SignatureAlgorithmTest, ParamsAreNullForWrongType_Invalid) { |
475 SignatureAlgorithm alg1; | 475 SignatureAlgorithm alg1; |
476 | 476 |
477 EXPECT_FALSE(alg1.ParamsForRsaPss()); | 477 EXPECT_FALSE(alg1.ParamsForRsaPss()); |
478 } | 478 } |
479 | 479 |
| 480 // Parses a rsaPss algorithm that uses SHA1 and a salt length of 20. |
| 481 // |
| 482 // SEQUENCE (2 elem) |
| 483 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 484 // SEQUENCE (4 elem) |
| 485 // [0] (1 elem) |
| 486 // SEQUENCE (2 elem) |
| 487 // OBJECT IDENTIFIER 1.3.14.3.2.26 |
| 488 // NULL |
| 489 // [1] (1 elem) |
| 490 // SEQUENCE (2 elem) |
| 491 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 492 // SEQUENCE (2 elem) |
| 493 // OBJECT IDENTIFIER 1.3.14.3.2.26 |
| 494 // NULL |
| 495 // [2] (1 elem) |
| 496 // INTEGER 20 |
| 497 // [3] (1 elem) |
| 498 // INTEGER 1 |
| 499 TEST(SignatureAlgorithmTest, ParseDer_rsaPss) { |
| 500 // clang-format off |
| 501 const uint8_t kData[] = { |
| 502 0x30, 0x3E, // SEQUENCE (62 bytes) |
| 503 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 504 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 505 0x30, 0x31, // SEQUENCE (49 bytes) |
| 506 0xA0, 0x0B, // [0] (11 bytes) |
| 507 0x30, 0x09, // SEQUENCE (9 bytes) |
| 508 0x06, 0x05, // OBJECT IDENTIFIER (5 bytes) |
| 509 0x2B, 0x0E, 0x03, 0x02, 0x1A, |
| 510 0x05, 0x00, // NULL (0 bytes) |
| 511 0xA1, 0x18, // [1] (24 bytes) |
| 512 0x30, 0x16, // SEQUENCE (22 bytes) |
| 513 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 514 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 515 0x30, 0x09, // SEQUENCE (9 bytes) |
| 516 0x06, 0x05, // OBJECT IDENTIFIER (5 bytes) |
| 517 0x2B, 0x0E, 0x03, 0x02, 0x1A, |
| 518 0x05, 0x00, // NULL (0 bytes) |
| 519 0xA2, 0x03, // [2] (3 bytes) |
| 520 0x02, 0x01, // INTEGER (1 byte) |
| 521 0x14, |
| 522 0xA3, 0x03, // [3] (3 bytes) |
| 523 0x02, 0x01, // INTEGER (1 byte) |
| 524 0x01, |
| 525 }; |
| 526 // clang-format on |
| 527 SignatureAlgorithm algorithm; |
| 528 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 529 |
| 530 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 531 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm.digest()); |
| 532 |
| 533 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 534 |
| 535 ASSERT_TRUE(params); |
| 536 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 537 EXPECT_EQ(20u, params->salt_length()); |
| 538 } |
| 539 |
| 540 // Parses a rsaPss algorithm that has an empty parameters. It should use all the |
| 541 // default values (SHA1 and salt length of 20). |
| 542 // |
| 543 // SEQUENCE (2 elem) |
| 544 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 545 // SEQUENCE (0 elem) |
| 546 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_EmptyParams) { |
| 547 // clang-format off |
| 548 const uint8_t kData[] = { |
| 549 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 550 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 551 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 552 0x30, 0x00, // SEQUENCE (0 bytes) |
| 553 }; |
| 554 // clang-format on |
| 555 SignatureAlgorithm algorithm; |
| 556 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 557 |
| 558 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 559 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm.digest()); |
| 560 |
| 561 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 562 |
| 563 ASSERT_TRUE(params); |
| 564 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 565 EXPECT_EQ(20u, params->salt_length()); |
| 566 } |
| 567 |
| 568 // Parses a rsaPss algorithm that has NULL parameters. This fails. |
| 569 // |
| 570 // SEQUENCE (2 elem) |
| 571 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 572 // NULL |
| 573 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NullParams) { |
| 574 // clang-format off |
| 575 const uint8_t kData[] = { |
| 576 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 577 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 578 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 579 0x05, 0x00, // NULL (0 bytes) |
| 580 }; |
| 581 // clang-format on |
| 582 SignatureAlgorithm algorithm; |
| 583 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 584 } |
| 585 |
| 586 // Parses a rsaPss algorithm that has no parameters. This fails. |
| 587 // |
| 588 // SEQUENCE (1 elem) |
| 589 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 590 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NoParams) { |
| 591 // clang-format off |
| 592 const uint8_t kData[] = { |
| 593 0x30, 0x0B, // SEQUENCE (11 bytes) |
| 594 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 595 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 596 }; |
| 597 // clang-format on |
| 598 SignatureAlgorithm algorithm; |
| 599 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 600 } |
| 601 |
| 602 // Parses a rsaPss algorithm that has data after the parameters sequence. |
| 603 // |
| 604 // SEQUENCE (3 elem) |
| 605 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 606 // SEQUENCE (0 elem) |
| 607 // NULL |
| 608 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_DataAfterParams) { |
| 609 // clang-format off |
| 610 const uint8_t kData[] = { |
| 611 0x30, 0x0F, // SEQUENCE (15 bytes) |
| 612 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 613 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 614 0x30, 0x00, // SEQUENCE (0 bytes) |
| 615 0x05, 0x00, // NULL (0 bytes) |
| 616 }; |
| 617 // clang-format on |
| 618 SignatureAlgorithm algorithm; |
| 619 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 620 } |
| 621 |
| 622 // Parses a rsaPss algorithm that uses defaults (by ommitting the values) for |
| 623 // everything except the salt length. |
| 624 // |
| 625 // SEQUENCE (2 elem) |
| 626 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 627 // SEQUENCE (1 elem) |
| 628 // [2] (1 elem) |
| 629 // INTEGER 23 |
| 630 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_DefaultsExceptForSaltLength) { |
| 631 // clang-format off |
| 632 const uint8_t kData[] = { |
| 633 0x30, 0x12, // SEQUENCE (62 bytes) |
| 634 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 635 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 636 0x30, 0x05, // SEQUENCE (5 bytes) |
| 637 0xA2, 0x03, // [2] (3 bytes) |
| 638 0x02, 0x01, // INTEGER (1 byte) |
| 639 0x17, |
| 640 }; |
| 641 // clang-format on |
| 642 SignatureAlgorithm algorithm; |
| 643 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 644 |
| 645 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 646 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm.digest()); |
| 647 |
| 648 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 649 |
| 650 ASSERT_TRUE(params); |
| 651 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 652 EXPECT_EQ(23u, params->salt_length()); |
| 653 } |
| 654 |
| 655 // Parses a rsaPss algorithm that has unrecognized data (NULL) within the |
| 656 // parameters sequence. |
| 657 // |
| 658 // SEQUENCE (2 elem) |
| 659 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 660 // SEQUENCE (2 elem) |
| 661 // [2] (1 elem) |
| 662 // INTEGER 23 |
| 663 // NULL |
| 664 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NullInsideParams) { |
| 665 // clang-format off |
| 666 const uint8_t kData[] = { |
| 667 0x30, 0x14, // SEQUENCE (62 bytes) |
| 668 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 669 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 670 0x30, 0x07, // SEQUENCE (5 bytes) |
| 671 0xA2, 0x03, // [2] (3 bytes) |
| 672 0x02, 0x01, // INTEGER (1 byte) |
| 673 0x17, |
| 674 0x05, 0x00, // NULL (0 bytes) |
| 675 }; |
| 676 // clang-format on |
| 677 SignatureAlgorithm algorithm; |
| 678 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 679 } |
| 680 |
| 681 // Parses a rsaPss algorithm that has an unsupported trailer value (2). Only |
| 682 // trailer values of 1 are allowed by RFC 4055. |
| 683 // |
| 684 // SEQUENCE (2 elem) |
| 685 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 686 // SEQUENCE (1 elem) |
| 687 // [3] (1 elem) |
| 688 // INTEGER 2 |
| 689 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_UnsupportedTrailer) { |
| 690 // clang-format off |
| 691 const uint8_t kData[] = { |
| 692 0x30, 0x12, // SEQUENCE (18 bytes) |
| 693 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 694 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 695 0x30, 0x05, // SEQUENCE (5 bytes) |
| 696 0xA3, 0x03, // [3] (3 bytes) |
| 697 0x02, 0x01, // INTEGER (1 byte) |
| 698 0x02, |
| 699 }; |
| 700 // clang-format on |
| 701 SignatureAlgorithm algorithm; |
| 702 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 703 } |
| 704 |
| 705 // Parses a rsaPss algorithm that has extra data appearing after the trailer in |
| 706 // the [3] section. |
| 707 // |
| 708 // SEQUENCE (2 elem) |
| 709 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 710 // SEQUENCE (1 elem) |
| 711 // [3] (2 elem) |
| 712 // INTEGER 1 |
| 713 // NULL |
| 714 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_BadTrailer) { |
| 715 // clang-format off |
| 716 const uint8_t kData[] = { |
| 717 0x30, 0x14, // SEQUENCE (20 bytes) |
| 718 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 719 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 720 0x30, 0x07, // SEQUENCE (7 bytes) |
| 721 0xA3, 0x05, // [3] (5 bytes) |
| 722 0x02, 0x01, // INTEGER (1 byte) |
| 723 0x01, |
| 724 0x05, 0x00, // NULL (0 bytes) |
| 725 }; |
| 726 // clang-format on |
| 727 SignatureAlgorithm algorithm; |
| 728 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 729 } |
| 730 |
| 731 // Parses a rsaPss algorithm that uses SHA384 for the hash, and leaves the rest |
| 732 // as defaults (including the mask gen). |
| 733 // |
| 734 // SEQUENCE (2 elem) |
| 735 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 736 // SEQUENCE (1 elem) |
| 737 // [0] (1 elem) |
| 738 // SEQUENCE (2 elem) |
| 739 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.2 |
| 740 // NULL |
| 741 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHash) { |
| 742 // clang-format off |
| 743 const uint8_t kData[] = { |
| 744 0x30, 0x1E, // SEQUENCE (30 bytes) |
| 745 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 746 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 747 0x30, 0x11, // SEQUENCE (17 bytes) |
| 748 0xA0, 0x0F, // [0] (15 bytes) |
| 749 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 750 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 751 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, |
| 752 0x05, 0x00, // NULL (0 bytes) |
| 753 }; |
| 754 // clang-format on |
| 755 SignatureAlgorithm algorithm; |
| 756 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 757 |
| 758 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 759 EXPECT_EQ(DigestAlgorithm::Sha384, algorithm.digest()); |
| 760 |
| 761 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 762 |
| 763 ASSERT_TRUE(params); |
| 764 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 765 EXPECT_EQ(20u, params->salt_length()); |
| 766 } |
| 767 |
| 768 // Parses a rsaPss algorithm that uses SHA384 for the hash, however in the |
| 769 // AlgorithmIdentifier for the hash function the parameters are omitted instead |
| 770 // of NULL. |
| 771 // |
| 772 // SEQUENCE (2 elem) |
| 773 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 774 // SEQUENCE (1 elem) |
| 775 // [0] (1 elem) |
| 776 // SEQUENCE (1 elem) |
| 777 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.2 |
| 778 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHash_AbsentParams) { |
| 779 // clang-format off |
| 780 const uint8_t kData[] = { |
| 781 0x30, 0x1C, // SEQUENCE (28 bytes) |
| 782 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 783 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 784 0x30, 0x0F, // SEQUENCE (15 bytes) |
| 785 0xA0, 0x0D, // [0] (13 bytes) |
| 786 0x30, 0x0B, // SEQUENCE (11 bytes) |
| 787 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 788 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, |
| 789 }; |
| 790 // clang-format on |
| 791 SignatureAlgorithm algorithm; |
| 792 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 793 |
| 794 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 795 EXPECT_EQ(DigestAlgorithm::Sha384, algorithm.digest()); |
| 796 |
| 797 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 798 |
| 799 ASSERT_TRUE(params); |
| 800 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 801 EXPECT_EQ(20u, params->salt_length()); |
| 802 } |
| 803 |
| 804 // Parses a rsaPss algorithm that uses an invalid hash algorithm (twiddled the |
| 805 // bytes for the SHA-384 OID a bit). |
| 806 // |
| 807 // SEQUENCE (2 elem) |
| 808 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 809 // SEQUENCE (1 elem) |
| 810 // [0] (1 elem) |
| 811 // SEQUENCE (1 elem) |
| 812 // OBJECT IDENTIFIER 2.16.840.2.103.19.4.2.2 |
| 813 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_UnsupportedHashOid) { |
| 814 // clang-format off |
| 815 const uint8_t kData[] = { |
| 816 0x30, 0x1C, // SEQUENCE (28 bytes) |
| 817 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 818 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 819 0x30, 0x0F, // SEQUENCE (15 bytes) |
| 820 0xA0, 0x0D, // [0] (13 bytes) |
| 821 0x30, 0x0B, // SEQUENCE (11 bytes) |
| 822 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 823 0x60, 0x86, 0x48, 0x02, 0x67, 0x13, 0x04, 0x02, 0x02, |
| 824 }; |
| 825 // clang-format on |
| 826 SignatureAlgorithm algorithm; |
| 827 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 828 } |
| 829 |
| 830 // Parses a rsaPss algorithm that uses SHA512 MGF1 for the mask gen, and |
| 831 // defaults for the rest. |
| 832 // |
| 833 // SEQUENCE (2 elem) |
| 834 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 835 // SEQUENCE (1 elem) |
| 836 // [1] (1 elem) |
| 837 // SEQUENCE (2 elem) |
| 838 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 839 // SEQUENCE (2 elem) |
| 840 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 |
| 841 // NULL |
| 842 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultMaskGen) { |
| 843 // clang-format off |
| 844 const uint8_t kData[] = { |
| 845 0x30, 0x2B, // SEQUENCE (43 bytes) |
| 846 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 847 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 848 0x30, 0x1E, // SEQUENCE (30 bytes) |
| 849 0xA1, 0x1C, // [1] (28 bytes) |
| 850 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 851 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 852 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 853 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 854 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 855 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, |
| 856 0x05, 0x00, // NULL (0 bytes) |
| 857 }; |
| 858 // clang-format on |
| 859 SignatureAlgorithm algorithm; |
| 860 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 861 |
| 862 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 863 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm.digest()); |
| 864 |
| 865 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 866 |
| 867 ASSERT_TRUE(params); |
| 868 EXPECT_EQ(DigestAlgorithm::Sha512, params->mgf1_hash()); |
| 869 EXPECT_EQ(20u, params->salt_length()); |
| 870 } |
| 871 |
| 872 // Parses a rsaPss algorithm that uses a mask gen with an unrecognized OID |
| 873 // (twiddled some of the bits). |
| 874 // |
| 875 // SEQUENCE (2 elem) |
| 876 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 877 // SEQUENCE (1 elem) |
| 878 // [1] (1 elem) |
| 879 // SEQUENCE (2 elem) |
| 880 // OBJECT IDENTIFIER 1.2.840.113618.1.2.8 |
| 881 // SEQUENCE (2 elem) |
| 882 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 |
| 883 // NULL |
| 884 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_UnsupportedMaskGen) { |
| 885 // clang-format off |
| 886 const uint8_t kData[] = { |
| 887 0x30, 0x2B, // SEQUENCE (43 bytes) |
| 888 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 889 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 890 0x30, 0x1E, // SEQUENCE (30 bytes) |
| 891 0xA1, 0x1C, // [1] (28 bytes) |
| 892 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 893 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 894 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x52, 0x01, 0x02, 0x08, |
| 895 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 896 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 897 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, |
| 898 0x05, 0x00, // NULL (0 bytes) |
| 899 }; |
| 900 // clang-format on |
| 901 SignatureAlgorithm algorithm; |
| 902 ASSERT_FALSE(algorithm.ParseDer(der::Input(kData))); |
| 903 } |
| 904 |
| 905 // Parses a rsaPss algorithm that uses SHA256 for the hash, and SHA512 for the |
| 906 // MGF1. |
| 907 // |
| 908 // SEQUENCE (2 elem) |
| 909 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 910 // SEQUENCE (2 elem) |
| 911 // [0] (1 elem) |
| 912 // SEQUENCE (2 elem) |
| 913 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 |
| 914 // NULL |
| 915 // [1] (1 elem) |
| 916 // SEQUENCE (2 elem) |
| 917 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 918 // SEQUENCE (2 elem) |
| 919 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 |
| 920 // NULL |
| 921 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHashAndMaskGen) { |
| 922 // clang-format off |
| 923 const uint8_t kData[] = { |
| 924 0x30, 0x3C, // SEQUENCE (60 bytes) |
| 925 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 926 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 927 0x30, 0x2F, // SEQUENCE (47 bytes) |
| 928 0xA0, 0x0F, // [0] (15 bytes) |
| 929 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 930 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 931 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, |
| 932 0x05, 0x00, // NULL (0 bytes) |
| 933 0xA1, 0x1C, // [1] (28 bytes) |
| 934 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 935 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 936 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 937 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 938 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 939 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, |
| 940 0x05, 0x00, // NULL (0 bytes) |
| 941 }; |
| 942 // clang-format on |
| 943 SignatureAlgorithm algorithm; |
| 944 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 945 |
| 946 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 947 EXPECT_EQ(DigestAlgorithm::Sha256, algorithm.digest()); |
| 948 |
| 949 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 950 |
| 951 ASSERT_TRUE(params); |
| 952 EXPECT_EQ(DigestAlgorithm::Sha512, params->mgf1_hash()); |
| 953 EXPECT_EQ(20u, params->salt_length()); |
| 954 } |
| 955 |
| 956 // Parses a rsaPss algorithm that uses SHA256 for the hash, and SHA256 for the |
| 957 // MGF1, and a salt length of 10. |
| 958 // |
| 959 // SEQUENCE (2 elem) |
| 960 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 961 // SEQUENCE (3 elem) |
| 962 // [0] (1 elem) |
| 963 // SEQUENCE (2 elem) |
| 964 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 |
| 965 // NULL |
| 966 // [1] (1 elem) |
| 967 // SEQUENCE (2 elem) |
| 968 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 969 // SEQUENCE (2 elem) |
| 970 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 |
| 971 // NULL |
| 972 // [2] (1 elem) |
| 973 // INTEGER 10 |
| 974 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHashAndMaskGenAndSalt) { |
| 975 // clang-format off |
| 976 const uint8_t kData[] = { |
| 977 0x30, 0x41, // SEQUENCE (65 bytes) |
| 978 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 979 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 980 0x30, 0x34, // SEQUENCE (52 bytes) |
| 981 0xA0, 0x0F, // [0] (15 bytes) |
| 982 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 983 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 984 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, |
| 985 0x05, 0x00, // NULL (0 bytes) |
| 986 0xA1, 0x1C, // [1] (28 bytes) |
| 987 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 988 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 989 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 990 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 991 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 992 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, |
| 993 0x05, 0x00, // NULL (0 bytes) |
| 994 0xA2, 0x03, // [2] (3 bytes) |
| 995 0x02, 0x01, // INTEGER (1 byte) |
| 996 0x0A, |
| 997 }; |
| 998 // clang-format on |
| 999 SignatureAlgorithm algorithm; |
| 1000 ASSERT_TRUE(algorithm.ParseDer(der::Input(kData))); |
| 1001 |
| 1002 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm.algorithm()); |
| 1003 EXPECT_EQ(DigestAlgorithm::Sha256, algorithm.digest()); |
| 1004 |
| 1005 const RsaPssParameters* params = algorithm.ParamsForRsaPss(); |
| 1006 |
| 1007 ASSERT_TRUE(params); |
| 1008 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); |
| 1009 EXPECT_EQ(10u, params->salt_length()); |
| 1010 } |
| 1011 |
480 } // namespace | 1012 } // namespace |
481 | 1013 |
482 } // namespace net | 1014 } // namespace net |
OLD | NEW |