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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 596 |
597 // Tests that the parmeters returned for an RSA PKCS#1 v1.5 algorithm are null | 597 // Tests that the parmeters returned for an RSA PKCS#1 v1.5 algorithm are null |
598 // for non-RSA PKCS#1 v1.5 algorithms. | 598 // for non-RSA PKCS#1 v1.5 algorithms. |
599 TEST(SignatureAlgorithmTest, ParamsAreNullForWrongType_RsaPkcs1) { | 599 TEST(SignatureAlgorithmTest, ParamsAreNullForWrongType_RsaPkcs1) { |
600 scoped_ptr<SignatureAlgorithm> alg1 = | 600 scoped_ptr<SignatureAlgorithm> alg1 = |
601 SignatureAlgorithm::CreateRsaPkcs1(DigestAlgorithm::Sha1); | 601 SignatureAlgorithm::CreateRsaPkcs1(DigestAlgorithm::Sha1); |
602 | 602 |
603 EXPECT_FALSE(alg1->ParamsForRsaPss()); | 603 EXPECT_FALSE(alg1->ParamsForRsaPss()); |
604 } | 604 } |
605 | 605 |
| 606 // Parses a rsaPss algorithm that uses SHA1 and a salt length of 20. |
| 607 // |
| 608 // SEQUENCE (2 elem) |
| 609 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 610 // SEQUENCE (4 elem) |
| 611 // [0] (1 elem) |
| 612 // SEQUENCE (2 elem) |
| 613 // OBJECT IDENTIFIER 1.3.14.3.2.26 |
| 614 // NULL |
| 615 // [1] (1 elem) |
| 616 // SEQUENCE (2 elem) |
| 617 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 618 // SEQUENCE (2 elem) |
| 619 // OBJECT IDENTIFIER 1.3.14.3.2.26 |
| 620 // NULL |
| 621 // [2] (1 elem) |
| 622 // INTEGER 20 |
| 623 // [3] (1 elem) |
| 624 // INTEGER 1 |
| 625 TEST(SignatureAlgorithmTest, ParseDer_rsaPss) { |
| 626 // clang-format off |
| 627 const uint8_t kData[] = { |
| 628 0x30, 0x3E, // SEQUENCE (62 bytes) |
| 629 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 630 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 631 0x30, 0x31, // SEQUENCE (49 bytes) |
| 632 0xA0, 0x0B, // [0] (11 bytes) |
| 633 0x30, 0x09, // SEQUENCE (9 bytes) |
| 634 0x06, 0x05, // OBJECT IDENTIFIER (5 bytes) |
| 635 0x2B, 0x0E, 0x03, 0x02, 0x1A, |
| 636 0x05, 0x00, // NULL (0 bytes) |
| 637 0xA1, 0x18, // [1] (24 bytes) |
| 638 0x30, 0x16, // SEQUENCE (22 bytes) |
| 639 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 640 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 641 0x30, 0x09, // SEQUENCE (9 bytes) |
| 642 0x06, 0x05, // OBJECT IDENTIFIER (5 bytes) |
| 643 0x2B, 0x0E, 0x03, 0x02, 0x1A, |
| 644 0x05, 0x00, // NULL (0 bytes) |
| 645 0xA2, 0x03, // [2] (3 bytes) |
| 646 0x02, 0x01, // INTEGER (1 byte) |
| 647 0x14, |
| 648 0xA3, 0x03, // [3] (3 bytes) |
| 649 0x02, 0x01, // INTEGER (1 byte) |
| 650 0x01, |
| 651 }; |
| 652 // clang-format on |
| 653 scoped_ptr<SignatureAlgorithm> algorithm; |
| 654 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 655 |
| 656 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 657 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm->digest()); |
| 658 |
| 659 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 660 |
| 661 ASSERT_TRUE(params); |
| 662 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 663 EXPECT_EQ(20u, params->salt_length()); |
| 664 } |
| 665 |
| 666 // Parses a rsaPss algorithm that has an empty parameters. It should use all the |
| 667 // default values (SHA1 and salt length of 20). |
| 668 // |
| 669 // SEQUENCE (2 elem) |
| 670 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 671 // SEQUENCE (0 elem) |
| 672 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_EmptyParams) { |
| 673 // clang-format off |
| 674 const uint8_t kData[] = { |
| 675 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 676 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 677 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 678 0x30, 0x00, // SEQUENCE (0 bytes) |
| 679 }; |
| 680 // clang-format on |
| 681 scoped_ptr<SignatureAlgorithm> algorithm; |
| 682 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 683 |
| 684 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 685 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm->digest()); |
| 686 |
| 687 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 688 |
| 689 ASSERT_TRUE(params); |
| 690 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 691 EXPECT_EQ(20u, params->salt_length()); |
| 692 } |
| 693 |
| 694 // Parses a rsaPss algorithm that has NULL parameters. This fails. |
| 695 // |
| 696 // SEQUENCE (2 elem) |
| 697 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 698 // NULL |
| 699 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NullParams) { |
| 700 // clang-format off |
| 701 const uint8_t kData[] = { |
| 702 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 703 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 704 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 705 0x05, 0x00, // NULL (0 bytes) |
| 706 }; |
| 707 // clang-format on |
| 708 scoped_ptr<SignatureAlgorithm> algorithm; |
| 709 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 710 } |
| 711 |
| 712 // Parses a rsaPss algorithm that has no parameters. This fails. |
| 713 // |
| 714 // SEQUENCE (1 elem) |
| 715 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 716 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NoParams) { |
| 717 // clang-format off |
| 718 const uint8_t kData[] = { |
| 719 0x30, 0x0B, // SEQUENCE (11 bytes) |
| 720 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 721 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 722 }; |
| 723 // clang-format on |
| 724 scoped_ptr<SignatureAlgorithm> algorithm; |
| 725 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 726 } |
| 727 |
| 728 // Parses a rsaPss algorithm that has data after the parameters sequence. |
| 729 // |
| 730 // SEQUENCE (3 elem) |
| 731 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 732 // SEQUENCE (0 elem) |
| 733 // NULL |
| 734 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_DataAfterParams) { |
| 735 // clang-format off |
| 736 const uint8_t kData[] = { |
| 737 0x30, 0x0F, // SEQUENCE (15 bytes) |
| 738 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 739 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 740 0x30, 0x00, // SEQUENCE (0 bytes) |
| 741 0x05, 0x00, // NULL (0 bytes) |
| 742 }; |
| 743 // clang-format on |
| 744 scoped_ptr<SignatureAlgorithm> algorithm; |
| 745 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 746 } |
| 747 |
| 748 // Parses a rsaPss algorithm that uses defaults (by ommitting the values) for |
| 749 // everything except the salt length. |
| 750 // |
| 751 // SEQUENCE (2 elem) |
| 752 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 753 // SEQUENCE (1 elem) |
| 754 // [2] (1 elem) |
| 755 // INTEGER 23 |
| 756 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_DefaultsExceptForSaltLength) { |
| 757 // clang-format off |
| 758 const uint8_t kData[] = { |
| 759 0x30, 0x12, // SEQUENCE (62 bytes) |
| 760 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 761 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 762 0x30, 0x05, // SEQUENCE (5 bytes) |
| 763 0xA2, 0x03, // [2] (3 bytes) |
| 764 0x02, 0x01, // INTEGER (1 byte) |
| 765 0x17, |
| 766 }; |
| 767 // clang-format on |
| 768 scoped_ptr<SignatureAlgorithm> algorithm; |
| 769 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 770 |
| 771 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 772 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm->digest()); |
| 773 |
| 774 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 775 |
| 776 ASSERT_TRUE(params); |
| 777 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 778 EXPECT_EQ(23u, params->salt_length()); |
| 779 } |
| 780 |
| 781 // Parses a rsaPss algorithm that has unrecognized data (NULL) within the |
| 782 // parameters sequence. |
| 783 // |
| 784 // SEQUENCE (2 elem) |
| 785 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 786 // SEQUENCE (2 elem) |
| 787 // [2] (1 elem) |
| 788 // INTEGER 23 |
| 789 // NULL |
| 790 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NullInsideParams) { |
| 791 // clang-format off |
| 792 const uint8_t kData[] = { |
| 793 0x30, 0x14, // SEQUENCE (62 bytes) |
| 794 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 795 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 796 0x30, 0x07, // SEQUENCE (5 bytes) |
| 797 0xA2, 0x03, // [2] (3 bytes) |
| 798 0x02, 0x01, // INTEGER (1 byte) |
| 799 0x17, |
| 800 0x05, 0x00, // NULL (0 bytes) |
| 801 }; |
| 802 // clang-format on |
| 803 scoped_ptr<SignatureAlgorithm> algorithm; |
| 804 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 805 } |
| 806 |
| 807 // Parses a rsaPss algorithm that has an unsupported trailer value (2). Only |
| 808 // trailer values of 1 are allowed by RFC 4055. |
| 809 // |
| 810 // SEQUENCE (2 elem) |
| 811 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 812 // SEQUENCE (1 elem) |
| 813 // [3] (1 elem) |
| 814 // INTEGER 2 |
| 815 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_UnsupportedTrailer) { |
| 816 // clang-format off |
| 817 const uint8_t kData[] = { |
| 818 0x30, 0x12, // SEQUENCE (18 bytes) |
| 819 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 820 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 821 0x30, 0x05, // SEQUENCE (5 bytes) |
| 822 0xA3, 0x03, // [3] (3 bytes) |
| 823 0x02, 0x01, // INTEGER (1 byte) |
| 824 0x02, |
| 825 }; |
| 826 // clang-format on |
| 827 scoped_ptr<SignatureAlgorithm> algorithm; |
| 828 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 829 } |
| 830 |
| 831 // Parses a rsaPss algorithm that has extra data appearing after the trailer in |
| 832 // the [3] section. |
| 833 // |
| 834 // SEQUENCE (2 elem) |
| 835 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 836 // SEQUENCE (1 elem) |
| 837 // [3] (2 elem) |
| 838 // INTEGER 1 |
| 839 // NULL |
| 840 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_BadTrailer) { |
| 841 // clang-format off |
| 842 const uint8_t kData[] = { |
| 843 0x30, 0x14, // SEQUENCE (20 bytes) |
| 844 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 845 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 846 0x30, 0x07, // SEQUENCE (7 bytes) |
| 847 0xA3, 0x05, // [3] (5 bytes) |
| 848 0x02, 0x01, // INTEGER (1 byte) |
| 849 0x01, |
| 850 0x05, 0x00, // NULL (0 bytes) |
| 851 }; |
| 852 // clang-format on |
| 853 scoped_ptr<SignatureAlgorithm> algorithm; |
| 854 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 855 } |
| 856 |
| 857 // Parses a rsaPss algorithm that uses SHA384 for the hash, and leaves the rest |
| 858 // as defaults (including the mask gen). |
| 859 // |
| 860 // SEQUENCE (2 elem) |
| 861 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 862 // SEQUENCE (1 elem) |
| 863 // [0] (1 elem) |
| 864 // SEQUENCE (2 elem) |
| 865 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.2 |
| 866 // NULL |
| 867 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHash) { |
| 868 // clang-format off |
| 869 const uint8_t kData[] = { |
| 870 0x30, 0x1E, // SEQUENCE (30 bytes) |
| 871 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 872 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 873 0x30, 0x11, // SEQUENCE (17 bytes) |
| 874 0xA0, 0x0F, // [0] (15 bytes) |
| 875 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 876 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 877 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, |
| 878 0x05, 0x00, // NULL (0 bytes) |
| 879 }; |
| 880 // clang-format on |
| 881 scoped_ptr<SignatureAlgorithm> algorithm; |
| 882 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 883 |
| 884 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 885 EXPECT_EQ(DigestAlgorithm::Sha384, algorithm->digest()); |
| 886 |
| 887 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 888 |
| 889 ASSERT_TRUE(params); |
| 890 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 891 EXPECT_EQ(20u, params->salt_length()); |
| 892 } |
| 893 |
| 894 // Parses a rsaPss algorithm that uses SHA384 for the hash, however in the |
| 895 // AlgorithmIdentifier for the hash function the parameters are omitted instead |
| 896 // of NULL. |
| 897 // |
| 898 // SEQUENCE (2 elem) |
| 899 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 900 // SEQUENCE (1 elem) |
| 901 // [0] (1 elem) |
| 902 // SEQUENCE (1 elem) |
| 903 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.2 |
| 904 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHash_AbsentParams) { |
| 905 // clang-format off |
| 906 const uint8_t kData[] = { |
| 907 0x30, 0x1C, // SEQUENCE (28 bytes) |
| 908 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 909 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 910 0x30, 0x0F, // SEQUENCE (15 bytes) |
| 911 0xA0, 0x0D, // [0] (13 bytes) |
| 912 0x30, 0x0B, // SEQUENCE (11 bytes) |
| 913 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 914 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, |
| 915 }; |
| 916 // clang-format on |
| 917 scoped_ptr<SignatureAlgorithm> algorithm; |
| 918 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 919 |
| 920 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 921 EXPECT_EQ(DigestAlgorithm::Sha384, algorithm->digest()); |
| 922 |
| 923 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 924 |
| 925 ASSERT_TRUE(params); |
| 926 EXPECT_EQ(DigestAlgorithm::Sha1, params->mgf1_hash()); |
| 927 EXPECT_EQ(20u, params->salt_length()); |
| 928 } |
| 929 |
| 930 // Parses a rsaPss algorithm that uses an invalid hash algorithm (twiddled the |
| 931 // bytes for the SHA-384 OID a bit). |
| 932 // |
| 933 // SEQUENCE (2 elem) |
| 934 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 935 // SEQUENCE (1 elem) |
| 936 // [0] (1 elem) |
| 937 // SEQUENCE (1 elem) |
| 938 // OBJECT IDENTIFIER 2.16.840.2.103.19.4.2.2 |
| 939 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_UnsupportedHashOid) { |
| 940 // clang-format off |
| 941 const uint8_t kData[] = { |
| 942 0x30, 0x1C, // SEQUENCE (28 bytes) |
| 943 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 944 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 945 0x30, 0x0F, // SEQUENCE (15 bytes) |
| 946 0xA0, 0x0D, // [0] (13 bytes) |
| 947 0x30, 0x0B, // SEQUENCE (11 bytes) |
| 948 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 949 0x60, 0x86, 0x48, 0x02, 0x67, 0x13, 0x04, 0x02, 0x02, |
| 950 }; |
| 951 // clang-format on |
| 952 scoped_ptr<SignatureAlgorithm> algorithm; |
| 953 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 954 } |
| 955 |
| 956 // Parses a rsaPss algorithm that uses SHA512 MGF1 for the mask gen, and |
| 957 // defaults for the rest. |
| 958 // |
| 959 // SEQUENCE (2 elem) |
| 960 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 961 // SEQUENCE (1 elem) |
| 962 // [1] (1 elem) |
| 963 // SEQUENCE (2 elem) |
| 964 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 965 // SEQUENCE (2 elem) |
| 966 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 |
| 967 // NULL |
| 968 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultMaskGen) { |
| 969 // clang-format off |
| 970 const uint8_t kData[] = { |
| 971 0x30, 0x2B, // SEQUENCE (43 bytes) |
| 972 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 973 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 974 0x30, 0x1E, // SEQUENCE (30 bytes) |
| 975 0xA1, 0x1C, // [1] (28 bytes) |
| 976 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 977 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 978 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 979 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 980 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 981 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, |
| 982 0x05, 0x00, // NULL (0 bytes) |
| 983 }; |
| 984 // clang-format on |
| 985 scoped_ptr<SignatureAlgorithm> algorithm; |
| 986 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 987 |
| 988 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 989 EXPECT_EQ(DigestAlgorithm::Sha1, algorithm->digest()); |
| 990 |
| 991 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 992 |
| 993 ASSERT_TRUE(params); |
| 994 EXPECT_EQ(DigestAlgorithm::Sha512, params->mgf1_hash()); |
| 995 EXPECT_EQ(20u, params->salt_length()); |
| 996 } |
| 997 |
| 998 // Parses a rsaPss algorithm that uses a mask gen with an unrecognized OID |
| 999 // (twiddled some of the bits). |
| 1000 // |
| 1001 // SEQUENCE (2 elem) |
| 1002 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 1003 // SEQUENCE (1 elem) |
| 1004 // [1] (1 elem) |
| 1005 // SEQUENCE (2 elem) |
| 1006 // OBJECT IDENTIFIER 1.2.840.113618.1.2.8 |
| 1007 // SEQUENCE (2 elem) |
| 1008 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 |
| 1009 // NULL |
| 1010 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_UnsupportedMaskGen) { |
| 1011 // clang-format off |
| 1012 const uint8_t kData[] = { |
| 1013 0x30, 0x2B, // SEQUENCE (43 bytes) |
| 1014 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1015 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 1016 0x30, 0x1E, // SEQUENCE (30 bytes) |
| 1017 0xA1, 0x1C, // [1] (28 bytes) |
| 1018 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 1019 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1020 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x52, 0x01, 0x02, 0x08, |
| 1021 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1022 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1023 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, |
| 1024 0x05, 0x00, // NULL (0 bytes) |
| 1025 }; |
| 1026 // clang-format on |
| 1027 scoped_ptr<SignatureAlgorithm> algorithm; |
| 1028 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 1029 } |
| 1030 |
| 1031 // Parses a rsaPss algorithm that uses SHA256 for the hash, and SHA512 for the |
| 1032 // MGF1. |
| 1033 // |
| 1034 // SEQUENCE (2 elem) |
| 1035 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 1036 // SEQUENCE (2 elem) |
| 1037 // [0] (1 elem) |
| 1038 // SEQUENCE (2 elem) |
| 1039 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 |
| 1040 // NULL |
| 1041 // [1] (1 elem) |
| 1042 // SEQUENCE (2 elem) |
| 1043 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 1044 // SEQUENCE (2 elem) |
| 1045 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.3 |
| 1046 // NULL |
| 1047 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHashAndMaskGen) { |
| 1048 // clang-format off |
| 1049 const uint8_t kData[] = { |
| 1050 0x30, 0x3C, // SEQUENCE (60 bytes) |
| 1051 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1052 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 1053 0x30, 0x2F, // SEQUENCE (47 bytes) |
| 1054 0xA0, 0x0F, // [0] (15 bytes) |
| 1055 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1056 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1057 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, |
| 1058 0x05, 0x00, // NULL (0 bytes) |
| 1059 0xA1, 0x1C, // [1] (28 bytes) |
| 1060 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 1061 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1062 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 1063 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1064 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1065 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, |
| 1066 0x05, 0x00, // NULL (0 bytes) |
| 1067 }; |
| 1068 // clang-format on |
| 1069 scoped_ptr<SignatureAlgorithm> algorithm; |
| 1070 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 1071 |
| 1072 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 1073 EXPECT_EQ(DigestAlgorithm::Sha256, algorithm->digest()); |
| 1074 |
| 1075 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 1076 |
| 1077 ASSERT_TRUE(params); |
| 1078 EXPECT_EQ(DigestAlgorithm::Sha512, params->mgf1_hash()); |
| 1079 EXPECT_EQ(20u, params->salt_length()); |
| 1080 } |
| 1081 |
| 1082 // Parses a rsaPss algorithm that uses SHA256 for the hash, and SHA256 for the |
| 1083 // MGF1, and a salt length of 10. |
| 1084 // |
| 1085 // SEQUENCE (2 elem) |
| 1086 // OBJECT IDENTIFIER 1.2.840.113549.1.1.10 |
| 1087 // SEQUENCE (3 elem) |
| 1088 // [0] (1 elem) |
| 1089 // SEQUENCE (2 elem) |
| 1090 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 |
| 1091 // NULL |
| 1092 // [1] (1 elem) |
| 1093 // SEQUENCE (2 elem) |
| 1094 // OBJECT IDENTIFIER 1.2.840.113549.1.1.8 |
| 1095 // SEQUENCE (2 elem) |
| 1096 // OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 |
| 1097 // NULL |
| 1098 // [2] (1 elem) |
| 1099 // INTEGER 10 |
| 1100 TEST(SignatureAlgorithmTest, ParseDer_rsaPss_NonDefaultHashAndMaskGenAndSalt) { |
| 1101 // clang-format off |
| 1102 const uint8_t kData[] = { |
| 1103 0x30, 0x41, // SEQUENCE (65 bytes) |
| 1104 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1105 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A, |
| 1106 0x30, 0x34, // SEQUENCE (52 bytes) |
| 1107 0xA0, 0x0F, // [0] (15 bytes) |
| 1108 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1109 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1110 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, |
| 1111 0x05, 0x00, // NULL (0 bytes) |
| 1112 0xA1, 0x1C, // [1] (28 bytes) |
| 1113 0x30, 0x1A, // SEQUENCE (26 bytes) |
| 1114 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1115 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, |
| 1116 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1117 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1118 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, |
| 1119 0x05, 0x00, // NULL (0 bytes) |
| 1120 0xA2, 0x03, // [2] (3 bytes) |
| 1121 0x02, 0x01, // INTEGER (1 byte) |
| 1122 0x0A, |
| 1123 }; |
| 1124 // clang-format on |
| 1125 scoped_ptr<SignatureAlgorithm> algorithm; |
| 1126 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 1127 |
| 1128 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
| 1129 EXPECT_EQ(DigestAlgorithm::Sha256, algorithm->digest()); |
| 1130 |
| 1131 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 1132 |
| 1133 ASSERT_TRUE(params); |
| 1134 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); |
| 1135 EXPECT_EQ(10u, params->salt_length()); |
| 1136 } |
| 1137 |
606 } // namespace | 1138 } // namespace |
607 | 1139 |
608 } // namespace net | 1140 } // namespace net |
OLD | NEW |