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