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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); | 1057 ASSERT_EQ(SignatureAlgorithmId::RsaPss, algorithm->algorithm()); |
1058 EXPECT_EQ(DigestAlgorithm::Sha256, algorithm->digest()); | 1058 EXPECT_EQ(DigestAlgorithm::Sha256, algorithm->digest()); |
1059 | 1059 |
1060 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); | 1060 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
1061 | 1061 |
1062 ASSERT_TRUE(params); | 1062 ASSERT_TRUE(params); |
1063 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); | 1063 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); |
1064 EXPECT_EQ(10u, params->salt_length()); | 1064 EXPECT_EQ(10u, params->salt_length()); |
1065 } | 1065 } |
1066 | 1066 |
| 1067 // Parses a md5WithRSAEncryption which contains a NULL parameters field. |
| 1068 // |
| 1069 // SEQUENCE (2 elem) |
| 1070 // OBJECT IDENTIFIER 1.2.840.113549.1.1.4 |
| 1071 // NULL |
| 1072 TEST(SignatureAlgorithmTest, ParseDerMd5WithRsaEncryptionNullParams) { |
| 1073 // clang-format off |
| 1074 const uint8_t kData[] = { |
| 1075 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1076 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1077 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x04, |
| 1078 0x05, 0x00, // NULL (0 bytes) |
| 1079 }; |
| 1080 // clang-format on |
| 1081 std::unique_ptr<SignatureAlgorithm> algorithm; |
| 1082 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 1083 |
| 1084 EXPECT_EQ(SignatureAlgorithmId::RsaPkcs1, algorithm->algorithm()); |
| 1085 EXPECT_EQ(DigestAlgorithm::Md5, algorithm->digest()); |
| 1086 } |
| 1087 |
| 1088 // Parses a md4WithRSAEncryption which contains a NULL parameters field. |
| 1089 // |
| 1090 // SEQUENCE (2 elem) |
| 1091 // OBJECT IDENTIFIER 1.2.840.113549.1.1.3 |
| 1092 // NULL |
| 1093 TEST(SignatureAlgorithmTest, ParseDerMd4WithRsaEncryptionNullParams) { |
| 1094 // clang-format off |
| 1095 const uint8_t kData[] = { |
| 1096 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1097 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1098 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x03, |
| 1099 0x05, 0x00, // NULL (0 bytes) |
| 1100 }; |
| 1101 // clang-format on |
| 1102 std::unique_ptr<SignatureAlgorithm> algorithm; |
| 1103 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 1104 |
| 1105 EXPECT_EQ(SignatureAlgorithmId::RsaPkcs1, algorithm->algorithm()); |
| 1106 EXPECT_EQ(DigestAlgorithm::Md4, algorithm->digest()); |
| 1107 } |
| 1108 |
| 1109 // Parses a md2WithRSAEncryption which contains a NULL parameters field. |
| 1110 // |
| 1111 // SEQUENCE (2 elem) |
| 1112 // OBJECT IDENTIFIER 1.2.840.113549.1.1.2 |
| 1113 // NULL |
| 1114 TEST(SignatureAlgorithmTest, ParseDerMd2WithRsaEncryptionNullParams) { |
| 1115 // clang-format off |
| 1116 const uint8_t kData[] = { |
| 1117 0x30, 0x0D, // SEQUENCE (13 bytes) |
| 1118 0x06, 0x09, // OBJECT IDENTIFIER (9 bytes) |
| 1119 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x02, |
| 1120 0x05, 0x00, // NULL (0 bytes) |
| 1121 }; |
| 1122 // clang-format on |
| 1123 std::unique_ptr<SignatureAlgorithm> algorithm; |
| 1124 ASSERT_TRUE(ParseDer(kData, &algorithm)); |
| 1125 |
| 1126 EXPECT_EQ(SignatureAlgorithmId::RsaPkcs1, algorithm->algorithm()); |
| 1127 EXPECT_EQ(DigestAlgorithm::Md2, algorithm->digest()); |
| 1128 } |
| 1129 |
1067 } // namespace | 1130 } // namespace |
1068 | 1131 |
1069 } // namespace net | 1132 } // namespace net |
OLD | NEW |