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/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_path.h" | 8 #include "base/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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 EXPECT_EQ(0U, issuer.organization_unit_names.size()); | 179 EXPECT_EQ(0U, issuer.organization_unit_names.size()); |
180 EXPECT_EQ(0U, issuer.domain_components.size()); | 180 EXPECT_EQ(0U, issuer.domain_components.size()); |
181 | 181 |
182 // Use DoubleT because its epoch is the same on all platforms | 182 // Use DoubleT because its epoch is the same on all platforms |
183 const Time& valid_start = google_cert->valid_start(); | 183 const Time& valid_start = google_cert->valid_start(); |
184 EXPECT_EQ(valid_from, valid_start.ToDoubleT()); | 184 EXPECT_EQ(valid_from, valid_start.ToDoubleT()); |
185 | 185 |
186 const Time& valid_expiry = google_cert->valid_expiry(); | 186 const Time& valid_expiry = google_cert->valid_expiry(); |
187 EXPECT_EQ(valid_to, valid_expiry.ToDoubleT()); | 187 EXPECT_EQ(valid_to, valid_expiry.ToDoubleT()); |
188 | 188 |
189 const SHA1HashValue& fingerprint = google_cert->fingerprint(); | 189 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); |
190 for (size_t i = 0; i < 20; ++i) | 190 for (size_t i = 0; i < 20; ++i) |
191 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); | 191 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); |
192 | 192 |
193 std::vector<std::string> dns_names; | 193 std::vector<std::string> dns_names; |
194 google_cert->GetDNSNames(&dns_names); | 194 google_cert->GetDNSNames(&dns_names); |
195 ASSERT_EQ(1U, dns_names.size()); | 195 ASSERT_EQ(1U, dns_names.size()); |
196 EXPECT_EQ("www.google.com", dns_names[0]); | 196 EXPECT_EQ("www.google.com", dns_names[0]); |
197 } | 197 } |
198 | 198 |
199 TEST(X509CertificateTest, GoogleCertParsing) { | 199 TEST(X509CertificateTest, GoogleCertParsing) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 issuer.organization_unit_names[0]); | 236 issuer.organization_unit_names[0]); |
237 EXPECT_EQ(0U, issuer.domain_components.size()); | 237 EXPECT_EQ(0U, issuer.domain_components.size()); |
238 | 238 |
239 // Use DoubleT because its epoch is the same on all platforms | 239 // Use DoubleT because its epoch is the same on all platforms |
240 const Time& valid_start = webkit_cert->valid_start(); | 240 const Time& valid_start = webkit_cert->valid_start(); |
241 EXPECT_EQ(1205883319, valid_start.ToDoubleT()); // Mar 18 23:35:19 2008 GMT | 241 EXPECT_EQ(1205883319, valid_start.ToDoubleT()); // Mar 18 23:35:19 2008 GMT |
242 | 242 |
243 const Time& valid_expiry = webkit_cert->valid_expiry(); | 243 const Time& valid_expiry = webkit_cert->valid_expiry(); |
244 EXPECT_EQ(1300491319, valid_expiry.ToDoubleT()); // Mar 18 23:35:19 2011 GMT | 244 EXPECT_EQ(1300491319, valid_expiry.ToDoubleT()); // Mar 18 23:35:19 2011 GMT |
245 | 245 |
246 const SHA1HashValue& fingerprint = webkit_cert->fingerprint(); | 246 const SHA1Fingerprint& fingerprint = webkit_cert->fingerprint(); |
247 for (size_t i = 0; i < 20; ++i) | 247 for (size_t i = 0; i < 20; ++i) |
248 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]); | 248 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]); |
249 | 249 |
250 std::vector<std::string> dns_names; | 250 std::vector<std::string> dns_names; |
251 webkit_cert->GetDNSNames(&dns_names); | 251 webkit_cert->GetDNSNames(&dns_names); |
252 ASSERT_EQ(2U, dns_names.size()); | 252 ASSERT_EQ(2U, dns_names.size()); |
253 EXPECT_EQ("*.webkit.org", dns_names[0]); | 253 EXPECT_EQ("*.webkit.org", dns_names[0]); |
254 EXPECT_EQ("webkit.org", dns_names[1]); | 254 EXPECT_EQ("webkit.org", dns_names[1]); |
255 | 255 |
256 // Test that the wildcard cert matches properly. | 256 // Test that the wildcard cert matches properly. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 issuer.organization_unit_names[0]); | 291 issuer.organization_unit_names[0]); |
292 EXPECT_EQ(0U, issuer.domain_components.size()); | 292 EXPECT_EQ(0U, issuer.domain_components.size()); |
293 | 293 |
294 // Use DoubleT because its epoch is the same on all platforms | 294 // Use DoubleT because its epoch is the same on all platforms |
295 const Time& valid_start = thawte_cert->valid_start(); | 295 const Time& valid_start = thawte_cert->valid_start(); |
296 EXPECT_EQ(1227052800, valid_start.ToDoubleT()); // Nov 19 00:00:00 2008 GMT | 296 EXPECT_EQ(1227052800, valid_start.ToDoubleT()); // Nov 19 00:00:00 2008 GMT |
297 | 297 |
298 const Time& valid_expiry = thawte_cert->valid_expiry(); | 298 const Time& valid_expiry = thawte_cert->valid_expiry(); |
299 EXPECT_EQ(1263772799, valid_expiry.ToDoubleT()); // Jan 17 23:59:59 2010 GMT | 299 EXPECT_EQ(1263772799, valid_expiry.ToDoubleT()); // Jan 17 23:59:59 2010 GMT |
300 | 300 |
301 const SHA1HashValue& fingerprint = thawte_cert->fingerprint(); | 301 const SHA1Fingerprint& fingerprint = thawte_cert->fingerprint(); |
302 for (size_t i = 0; i < 20; ++i) | 302 for (size_t i = 0; i < 20; ++i) |
303 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]); | 303 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]); |
304 | 304 |
305 std::vector<std::string> dns_names; | 305 std::vector<std::string> dns_names; |
306 thawte_cert->GetDNSNames(&dns_names); | 306 thawte_cert->GetDNSNames(&dns_names); |
307 ASSERT_EQ(1U, dns_names.size()); | 307 ASSERT_EQ(1U, dns_names.size()); |
308 EXPECT_EQ("www.thawte.com", dns_names[0]); | 308 EXPECT_EQ("www.thawte.com", dns_names[0]); |
309 } | 309 } |
310 | 310 |
311 // Test that all desired AttributeAndValue pairs can be extracted when only | 311 // Test that all desired AttributeAndValue pairs can be extracted when only |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 EXPECT_EQ(i, certs.size()); | 881 EXPECT_EQ(i, certs.size()); |
882 break; | 882 break; |
883 } | 883 } |
884 | 884 |
885 // A cert is expected - make sure that one was parsed. | 885 // A cert is expected - make sure that one was parsed. |
886 ASSERT_LT(i, certs.size()); | 886 ASSERT_LT(i, certs.size()); |
887 | 887 |
888 // Compare the parsed certificate with the expected certificate, by | 888 // Compare the parsed certificate with the expected certificate, by |
889 // comparing fingerprints. | 889 // comparing fingerprints. |
890 const X509Certificate* cert = certs[i]; | 890 const X509Certificate* cert = certs[i]; |
891 const SHA1HashValue& actual_fingerprint = cert->fingerprint(); | 891 const SHA1Fingerprint& actual_fingerprint = cert->fingerprint(); |
892 uint8* expected_fingerprint = test_data_.chain_fingerprints[i]; | 892 uint8* expected_fingerprint = test_data_.chain_fingerprints[i]; |
893 | 893 |
894 for (size_t j = 0; j < 20; ++j) | 894 for (size_t j = 0; j < 20; ++j) |
895 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); | 895 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); |
896 } | 896 } |
897 } | 897 } |
898 | 898 |
899 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, | 899 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, |
900 testing::ValuesIn(FormatTestData)); | 900 testing::ValuesIn(FormatTestData)); |
901 | 901 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 } | 1105 } |
1106 | 1106 |
1107 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( | 1107 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( |
1108 test_data.hostname, common_name, dns_names, ip_addressses)); | 1108 test_data.hostname, common_name, dns_names, ip_addressses)); |
1109 } | 1109 } |
1110 | 1110 |
1111 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, | 1111 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, |
1112 testing::ValuesIn(kNameVerifyTestData)); | 1112 testing::ValuesIn(kNameVerifyTestData)); |
1113 | 1113 |
1114 } // namespace net | 1114 } // namespace net |
OLD | NEW |