OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 663 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
664 scoped_refptr<X509Certificate> cert5(X509Certificate::CreateFromHandle( | 664 scoped_refptr<X509Certificate> cert5(X509Certificate::CreateFromHandle( |
665 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, | 665 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, |
666 X509Certificate::OSCertHandles())); | 666 X509Certificate::OSCertHandles())); |
667 X509Certificate::FreeOSCertHandle(google_cert_handle); | 667 X509Certificate::FreeOSCertHandle(google_cert_handle); |
668 | 668 |
669 EXPECT_EQ(cert3, cert5); | 669 EXPECT_EQ(cert3, cert5); |
670 } | 670 } |
671 | 671 |
672 TEST(X509CertificateTest, Pickle) { | 672 TEST(X509CertificateTest, Pickle) { |
673 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromBytes( | 673 X509Certificate::OSCertHandle google_cert_handle = |
674 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 674 X509Certificate::CreateOSCertHandleFromBytes( |
| 675 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
| 676 X509Certificate::OSCertHandle thawte_cert_handle = |
| 677 X509Certificate::CreateOSCertHandleFromBytes( |
| 678 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); |
| 679 |
| 680 X509Certificate::OSCertHandles intermediates; |
| 681 intermediates.push_back(thawte_cert_handle); |
| 682 // Faking SOURCE_LONE_CERT_IMPORT so that when the pickled certificate is |
| 683 // read, it successfully evicts |cert| from the X509Certificate::Cache. |
| 684 // This will be fixed when http://crbug.com/49377 is fixed. |
| 685 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( |
| 686 google_cert_handle, |
| 687 X509Certificate::SOURCE_LONE_CERT_IMPORT, |
| 688 intermediates); |
| 689 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert.get()); |
| 690 |
| 691 X509Certificate::FreeOSCertHandle(google_cert_handle); |
| 692 X509Certificate::FreeOSCertHandle(thawte_cert_handle); |
675 | 693 |
676 Pickle pickle; | 694 Pickle pickle; |
677 cert1->Persist(&pickle); | 695 cert->Persist(&pickle); |
678 | 696 |
679 void* iter = NULL; | 697 void* iter = NULL; |
680 scoped_refptr<X509Certificate> cert2( | 698 scoped_refptr<X509Certificate> cert_from_pickle = |
681 X509Certificate::CreateFromPickle(pickle, &iter)); | 699 X509Certificate::CreateFromPickle( |
682 | 700 pickle, &iter, X509Certificate::PICKLETYPE_CERTIFICATE_CHAIN); |
683 EXPECT_EQ(cert1, cert2); | 701 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert_from_pickle); |
| 702 EXPECT_NE(cert.get(), cert_from_pickle.get()); |
| 703 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
| 704 cert->os_cert_handle(), cert_from_pickle->os_cert_handle())); |
| 705 EXPECT_TRUE(cert->HasIntermediateCertificates( |
| 706 cert_from_pickle->GetIntermediateCertificates())); |
684 } | 707 } |
685 | 708 |
686 TEST(X509CertificateTest, Policy) { | 709 TEST(X509CertificateTest, Policy) { |
687 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( | 710 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( |
688 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 711 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
689 | 712 |
690 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( | 713 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
691 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 714 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
692 | 715 |
693 CertPolicy policy; | 716 CertPolicy policy; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 EXPECT_EQ(test_data.expected, | 1112 EXPECT_EQ(test_data.expected, |
1090 X509Certificate::VerifyHostname(test_data.hostname, cert_names)) | 1113 X509Certificate::VerifyHostname(test_data.hostname, cert_names)) |
1091 << "Host [" << test_data.hostname | 1114 << "Host [" << test_data.hostname |
1092 << "], cert name [" << test_data.cert_names << "]"; | 1115 << "], cert name [" << test_data.cert_names << "]"; |
1093 } | 1116 } |
1094 | 1117 |
1095 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, | 1118 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, |
1096 testing::ValuesIn(kNameVerifyTestData)); | 1119 testing::ValuesIn(kNameVerifyTestData)); |
1097 | 1120 |
1098 } // namespace net | 1121 } // namespace net |
OLD | NEW |