OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 for (size_t i = 0; i < 20; ++i) | 183 for (size_t i = 0; i < 20; ++i) |
184 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]); | 184 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]); |
185 | 185 |
186 std::vector<std::string> dns_names; | 186 std::vector<std::string> dns_names; |
187 webkit_cert->GetDNSNames(&dns_names); | 187 webkit_cert->GetDNSNames(&dns_names); |
188 ASSERT_EQ(2U, dns_names.size()); | 188 ASSERT_EQ(2U, dns_names.size()); |
189 EXPECT_EQ("*.webkit.org", dns_names[0]); | 189 EXPECT_EQ("*.webkit.org", dns_names[0]); |
190 EXPECT_EQ("webkit.org", dns_names[1]); | 190 EXPECT_EQ("webkit.org", dns_names[1]); |
191 | 191 |
192 // Test that the wildcard cert matches properly. | 192 // Test that the wildcard cert matches properly. |
193 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); | 193 bool unused = false; |
194 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); | 194 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org", &unused)); |
195 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); | 195 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org", &unused)); |
196 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); | 196 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org", &unused)); |
197 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); | 197 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com", &unused)); |
| 198 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com", &unused)); |
198 } | 199 } |
199 | 200 |
200 TEST(X509CertificateTest, ThawteCertParsing) { | 201 TEST(X509CertificateTest, ThawteCertParsing) { |
201 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( | 202 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( |
202 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); | 203 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
203 | 204 |
204 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); | 205 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); |
205 | 206 |
206 const CertPrincipal& subject = thawte_cert->subject(); | 207 const CertPrincipal& subject = thawte_cert->subject(); |
207 EXPECT_EQ("www.thawte.com", subject.common_name); | 208 EXPECT_EQ("www.thawte.com", subject.common_name); |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 EXPECT_GE(decimal_value, 0); | 1133 EXPECT_GE(decimal_value, 0); |
1133 EXPECT_LE(decimal_value, 255); | 1134 EXPECT_LE(decimal_value, 255); |
1134 addr_bytes.push_back(static_cast<char>(decimal_value)); | 1135 addr_bytes.push_back(static_cast<char>(decimal_value)); |
1135 } | 1136 } |
1136 ip_addressses.push_back(addr_bytes); | 1137 ip_addressses.push_back(addr_bytes); |
1137 ASSERT_EQ(4U, ip_addressses.back().size()) << i; | 1138 ASSERT_EQ(4U, ip_addressses.back().size()) << i; |
1138 } | 1139 } |
1139 } | 1140 } |
1140 } | 1141 } |
1141 | 1142 |
| 1143 bool unused = false; |
1142 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( | 1144 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( |
1143 test_data.hostname, common_name, dns_names, ip_addressses)); | 1145 test_data.hostname, common_name, dns_names, ip_addressses, &unused)); |
1144 } | 1146 } |
1145 | 1147 |
1146 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, | 1148 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, |
1147 testing::ValuesIn(kNameVerifyTestData)); | 1149 testing::ValuesIn(kNameVerifyTestData)); |
1148 | 1150 |
1149 const struct PublicKeyInfoTestData { | 1151 const struct PublicKeyInfoTestData { |
1150 const char* cert_file; | 1152 const char* cert_file; |
1151 size_t expected_bits; | 1153 size_t expected_bits; |
1152 X509Certificate::PublicKeyType expected_type; | 1154 X509Certificate::PublicKeyType expected_type; |
1153 } kPublicKeyInfoTestData[] = { | 1155 } kPublicKeyInfoTestData[] = { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 &actual_type); | 1188 &actual_type); |
1187 | 1189 |
1188 EXPECT_EQ(data.expected_bits, actual_bits); | 1190 EXPECT_EQ(data.expected_bits, actual_bits); |
1189 EXPECT_EQ(data.expected_type, actual_type); | 1191 EXPECT_EQ(data.expected_type, actual_type); |
1190 } | 1192 } |
1191 | 1193 |
1192 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1194 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
1193 testing::ValuesIn(kPublicKeyInfoTestData)); | 1195 testing::ValuesIn(kPublicKeyInfoTestData)); |
1194 | 1196 |
1195 } // namespace net | 1197 } // namespace net |
OLD | NEW |