| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ssl/client_cert_store_nss.h" | 5 #include "net/ssl/client_cert_store_nss.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certt.h> | 8 #include <certt.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | |
| 15 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 16 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 17 #include "crypto/scoped_test_nss_db.h" | 16 #include "crypto/scoped_test_nss_db.h" |
| 18 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
| 19 #include "net/ssl/client_cert_store_unittest-inl.h" | 18 #include "net/ssl/client_cert_store_unittest-inl.h" |
| 20 #include "net/ssl/ssl_cert_request_info.h" | 19 #include "net/ssl/ssl_cert_request_info.h" |
| 21 #include "net/test/cert_test_util.h" | 20 #include "net/test/cert_test_util.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 24 namespace net { | 23 namespace net { |
| 25 | 24 |
| 26 namespace { | |
| 27 | |
| 28 void SaveCertsAndQuitCallback(CertificateList* out_certs, | |
| 29 base::Closure quit_closure, | |
| 30 CertificateList in_certs) { | |
| 31 *out_certs = std::move(in_certs); | |
| 32 quit_closure.Run(); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 class ClientCertStoreNSSTestDelegate { | 25 class ClientCertStoreNSSTestDelegate { |
| 38 public: | 26 public: |
| 39 ClientCertStoreNSSTestDelegate() {} | 27 ClientCertStoreNSSTestDelegate() {} |
| 40 | 28 |
| 41 bool SelectClientCerts(const CertificateList& input_certs, | 29 bool SelectClientCerts(const CertificateList& input_certs, |
| 42 const SSLCertRequestInfo& cert_request_info, | 30 const SSLCertRequestInfo& cert_request_info, |
| 43 CertificateList* selected_certs) { | 31 CertificateList* selected_certs) { |
| 44 // Filters |input_certs| using the logic being used to filter the system | 32 // Filters |input_certs| using the logic being used to filter the system |
| 45 // store when GetClientCerts() is called. | 33 // store when GetClientCerts() is called. |
| 46 ClientCertStoreNSS::FilterCertsOnWorkerThread( | 34 ClientCertStoreNSS::FilterCertsOnWorkerThread( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 new ClientCertStoreNSS(ClientCertStoreNSS::PasswordDelegateFactory())); | 61 new ClientCertStoreNSS(ClientCertStoreNSS::PasswordDelegateFactory())); |
| 74 | 62 |
| 75 { | 63 { |
| 76 // Request certificates matching B CA, |client_1|'s issuer. | 64 // Request certificates matching B CA, |client_1|'s issuer. |
| 77 scoped_refptr<SSLCertRequestInfo> request(new SSLCertRequestInfo); | 65 scoped_refptr<SSLCertRequestInfo> request(new SSLCertRequestInfo); |
| 78 request->cert_authorities.push_back(std::string( | 66 request->cert_authorities.push_back(std::string( |
| 79 reinterpret_cast<const char*>(kAuthority1DN), sizeof(kAuthority1DN))); | 67 reinterpret_cast<const char*>(kAuthority1DN), sizeof(kAuthority1DN))); |
| 80 | 68 |
| 81 CertificateList selected_certs; | 69 CertificateList selected_certs; |
| 82 base::RunLoop loop; | 70 base::RunLoop loop; |
| 83 store->GetClientCerts(*request.get(), | 71 store->GetClientCerts(*request.get(), &selected_certs, loop.QuitClosure()); |
| 84 base::Bind(SaveCertsAndQuitCallback, &selected_certs, | |
| 85 loop.QuitClosure())); | |
| 86 loop.Run(); | 72 loop.Run(); |
| 87 | 73 |
| 88 // The result be |client_1| with no intermediates. | 74 // The result be |client_1| with no intermediates. |
| 89 ASSERT_EQ(1u, selected_certs.size()); | 75 ASSERT_EQ(1u, selected_certs.size()); |
| 90 scoped_refptr<X509Certificate> selected_cert = selected_certs[0]; | 76 scoped_refptr<X509Certificate> selected_cert = selected_certs[0]; |
| 91 EXPECT_TRUE(X509Certificate::IsSameOSCert(client_1->os_cert_handle(), | 77 EXPECT_TRUE(X509Certificate::IsSameOSCert(client_1->os_cert_handle(), |
| 92 selected_cert->os_cert_handle())); | 78 selected_cert->os_cert_handle())); |
| 93 ASSERT_EQ(0u, selected_cert->GetIntermediateCertificates().size()); | 79 ASSERT_EQ(0u, selected_cert->GetIntermediateCertificates().size()); |
| 94 } | 80 } |
| 95 | 81 |
| 96 { | 82 { |
| 97 // Request certificates matching C Root CA, |client_1_ca|'s issuer. | 83 // Request certificates matching C Root CA, |client_1_ca|'s issuer. |
| 98 scoped_refptr<SSLCertRequestInfo> request(new SSLCertRequestInfo); | 84 scoped_refptr<SSLCertRequestInfo> request(new SSLCertRequestInfo); |
| 99 request->cert_authorities.push_back( | 85 request->cert_authorities.push_back( |
| 100 std::string(reinterpret_cast<const char*>(kAuthorityRootDN), | 86 std::string(reinterpret_cast<const char*>(kAuthorityRootDN), |
| 101 sizeof(kAuthorityRootDN))); | 87 sizeof(kAuthorityRootDN))); |
| 102 | 88 |
| 103 CertificateList selected_certs; | 89 CertificateList selected_certs; |
| 104 base::RunLoop loop; | 90 base::RunLoop loop; |
| 105 store->GetClientCerts(*request.get(), | 91 store->GetClientCerts(*request.get(), &selected_certs, loop.QuitClosure()); |
| 106 base::Bind(SaveCertsAndQuitCallback, &selected_certs, | |
| 107 loop.QuitClosure())); | |
| 108 loop.Run(); | 92 loop.Run(); |
| 109 | 93 |
| 110 // The result be |client_1| with |client_1_ca| as an intermediate. | 94 // The result be |client_1| with |client_1_ca| as an intermediate. |
| 111 ASSERT_EQ(1u, selected_certs.size()); | 95 ASSERT_EQ(1u, selected_certs.size()); |
| 112 scoped_refptr<X509Certificate> selected_cert = selected_certs[0]; | 96 scoped_refptr<X509Certificate> selected_cert = selected_certs[0]; |
| 113 EXPECT_TRUE(X509Certificate::IsSameOSCert(client_1->os_cert_handle(), | 97 EXPECT_TRUE(X509Certificate::IsSameOSCert(client_1->os_cert_handle(), |
| 114 selected_cert->os_cert_handle())); | 98 selected_cert->os_cert_handle())); |
| 115 ASSERT_EQ(1u, selected_cert->GetIntermediateCertificates().size()); | 99 ASSERT_EQ(1u, selected_cert->GetIntermediateCertificates().size()); |
| 116 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 100 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
| 117 client_1_ca->os_cert_handle(), | 101 client_1_ca->os_cert_handle(), |
| 118 selected_cert->GetIntermediateCertificates()[0])); | 102 selected_cert->GetIntermediateCertificates()[0])); |
| 119 } | 103 } |
| 120 } | 104 } |
| 121 | 105 |
| 122 } // namespace net | 106 } // namespace net |
| OLD | NEW |