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 "chrome/browser/chromeos/net/client_cert_store_chromeos.h" | 5 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" |
15 #include "crypto/scoped_test_nss_db.h" | 16 #include "crypto/scoped_test_nss_db.h" |
16 #include "net/base/test_data_directory.h" | 17 #include "net/base/test_data_directory.h" |
17 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 19 #include "net/ssl/ssl_cert_request_info.h" |
18 #include "net/test/cert_test_util.h" | 20 #include "net/test/cert_test_util.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 namespace chromeos { | 23 namespace chromeos { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // "CN=B CA" - DER encoded DN of the issuer of client_1.pem | 27 // "CN=B CA" - DER encoded DN of the issuer of client_1.pem |
26 const unsigned char kAuthority1DN[] = {0x30, 0x0f, 0x31, 0x0d, 0x30, 0x0b, | 28 const unsigned char kAuthority1DN[] = {0x30, 0x0f, 0x31, 0x0d, 0x30, 0x0b, |
27 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, | 29 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 90 |
89 // Ensure that cert requests, that are started before the filter is initialized, | 91 // Ensure that cert requests, that are started before the filter is initialized, |
90 // will wait for the initialization and succeed afterwards. | 92 // will wait for the initialization and succeed afterwards. |
91 TEST_F(ClientCertStoreChromeOSTest, RequestWaitsForNSSInitAndSucceeds) { | 93 TEST_F(ClientCertStoreChromeOSTest, RequestWaitsForNSSInitAndSucceeds) { |
92 crypto::ScopedTestNSSDB test_db; | 94 crypto::ScopedTestNSSDB test_db; |
93 ASSERT_TRUE(test_db.is_open()); | 95 ASSERT_TRUE(test_db.is_open()); |
94 | 96 |
95 TestCertFilter* cert_filter = | 97 TestCertFilter* cert_filter = |
96 new TestCertFilter(false /* init asynchronously */); | 98 new TestCertFilter(false /* init asynchronously */); |
97 ClientCertStoreChromeOS store( | 99 ClientCertStoreChromeOS store( |
98 make_scoped_ptr(cert_filter), | 100 nullptr /* no additional provider */, make_scoped_ptr(cert_filter), |
99 ClientCertStoreChromeOS::PasswordDelegateFactory()); | 101 ClientCertStoreChromeOS::PasswordDelegateFactory()); |
100 | 102 |
101 scoped_refptr<net::X509Certificate> cert_1( | 103 scoped_refptr<net::X509Certificate> cert_1( |
102 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); | 104 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); |
103 ASSERT_TRUE(cert_1.get()); | 105 ASSERT_TRUE(cert_1.get()); |
104 | 106 |
105 // Request any client certificate, which is expected to match client_1. | 107 // Request any client certificate, which is expected to match client_1. |
106 scoped_refptr<net::SSLCertRequestInfo> request_all( | 108 scoped_refptr<net::SSLCertRequestInfo> request_all( |
107 new net::SSLCertRequestInfo()); | 109 new net::SSLCertRequestInfo()); |
108 | 110 |
(...skipping 15 matching lines...) Expand all Loading... |
124 ASSERT_EQ(1u, request_all->client_certs.size()); | 126 ASSERT_EQ(1u, request_all->client_certs.size()); |
125 } | 127 } |
126 | 128 |
127 // Ensure that cert requests, that are started after the filter was initialized, | 129 // Ensure that cert requests, that are started after the filter was initialized, |
128 // will succeed. | 130 // will succeed. |
129 TEST_F(ClientCertStoreChromeOSTest, RequestsAfterNSSInitSucceed) { | 131 TEST_F(ClientCertStoreChromeOSTest, RequestsAfterNSSInitSucceed) { |
130 crypto::ScopedTestNSSDB test_db; | 132 crypto::ScopedTestNSSDB test_db; |
131 ASSERT_TRUE(test_db.is_open()); | 133 ASSERT_TRUE(test_db.is_open()); |
132 | 134 |
133 ClientCertStoreChromeOS store( | 135 ClientCertStoreChromeOS store( |
| 136 nullptr, // no additional provider |
134 make_scoped_ptr(new TestCertFilter(true /* init synchronously */)), | 137 make_scoped_ptr(new TestCertFilter(true /* init synchronously */)), |
135 ClientCertStoreChromeOS::PasswordDelegateFactory()); | 138 ClientCertStoreChromeOS::PasswordDelegateFactory()); |
136 | 139 |
137 scoped_refptr<net::X509Certificate> cert_1( | 140 scoped_refptr<net::X509Certificate> cert_1( |
138 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); | 141 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); |
139 ASSERT_TRUE(cert_1.get()); | 142 ASSERT_TRUE(cert_1.get()); |
140 | 143 |
141 scoped_refptr<net::SSLCertRequestInfo> request_all( | 144 scoped_refptr<net::SSLCertRequestInfo> request_all( |
142 new net::SSLCertRequestInfo()); | 145 new net::SSLCertRequestInfo()); |
143 | 146 |
144 base::RunLoop run_loop; | 147 base::RunLoop run_loop; |
145 store.GetClientCerts(*request_all, &request_all->client_certs, | 148 store.GetClientCerts(*request_all, &request_all->client_certs, |
146 run_loop.QuitClosure()); | 149 run_loop.QuitClosure()); |
147 run_loop.Run(); | 150 run_loop.Run(); |
148 | 151 |
149 ASSERT_EQ(1u, request_all->client_certs.size()); | 152 ASSERT_EQ(1u, request_all->client_certs.size()); |
150 } | 153 } |
151 | 154 |
152 TEST_F(ClientCertStoreChromeOSTest, Filter) { | 155 TEST_F(ClientCertStoreChromeOSTest, Filter) { |
153 crypto::ScopedTestNSSDB test_db; | 156 crypto::ScopedTestNSSDB test_db; |
154 ASSERT_TRUE(test_db.is_open()); | 157 ASSERT_TRUE(test_db.is_open()); |
155 | 158 |
156 TestCertFilter* cert_filter = | 159 TestCertFilter* cert_filter = |
157 new TestCertFilter(true /* init synchronously */); | 160 new TestCertFilter(true /* init synchronously */); |
158 ClientCertStoreChromeOS store( | 161 ClientCertStoreChromeOS store( |
159 make_scoped_ptr(cert_filter), | 162 nullptr /* no additional provider */, make_scoped_ptr(cert_filter), |
160 ClientCertStoreChromeOS::PasswordDelegateFactory()); | 163 ClientCertStoreChromeOS::PasswordDelegateFactory()); |
161 | 164 |
162 scoped_refptr<net::X509Certificate> cert_1( | 165 scoped_refptr<net::X509Certificate> cert_1( |
163 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); | 166 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); |
164 ASSERT_TRUE(cert_1.get()); | 167 ASSERT_TRUE(cert_1.get()); |
165 scoped_refptr<net::X509Certificate> cert_2( | 168 scoped_refptr<net::X509Certificate> cert_2( |
166 ImportCertToSlot("client_2.pem", "client_2.pk8", test_db.slot())); | 169 ImportCertToSlot("client_2.pem", "client_2.pk8", test_db.slot())); |
167 ASSERT_TRUE(cert_2.get()); | 170 ASSERT_TRUE(cert_2.get()); |
168 | 171 |
169 scoped_refptr<net::SSLCertRequestInfo> request_all( | 172 scoped_refptr<net::SSLCertRequestInfo> request_all( |
(...skipping 24 matching lines...) Expand all Loading... |
194 | 197 |
195 // Ensure that the delegation of the request matching to the base class is | 198 // Ensure that the delegation of the request matching to the base class is |
196 // functional. | 199 // functional. |
197 TEST_F(ClientCertStoreChromeOSTest, CertRequestMatching) { | 200 TEST_F(ClientCertStoreChromeOSTest, CertRequestMatching) { |
198 crypto::ScopedTestNSSDB test_db; | 201 crypto::ScopedTestNSSDB test_db; |
199 ASSERT_TRUE(test_db.is_open()); | 202 ASSERT_TRUE(test_db.is_open()); |
200 | 203 |
201 TestCertFilter* cert_filter = | 204 TestCertFilter* cert_filter = |
202 new TestCertFilter(true /* init synchronously */); | 205 new TestCertFilter(true /* init synchronously */); |
203 ClientCertStoreChromeOS store( | 206 ClientCertStoreChromeOS store( |
| 207 nullptr, // no additional provider |
204 make_scoped_ptr(cert_filter), | 208 make_scoped_ptr(cert_filter), |
205 ClientCertStoreChromeOS::PasswordDelegateFactory()); | 209 ClientCertStoreChromeOS::PasswordDelegateFactory()); |
206 | 210 |
207 scoped_refptr<net::X509Certificate> cert_1( | 211 scoped_refptr<net::X509Certificate> cert_1( |
208 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); | 212 ImportCertToSlot("client_1.pem", "client_1.pk8", test_db.slot())); |
209 ASSERT_TRUE(cert_1.get()); | 213 ASSERT_TRUE(cert_1.get()); |
210 scoped_refptr<net::X509Certificate> cert_2( | 214 scoped_refptr<net::X509Certificate> cert_2( |
211 ImportCertToSlot("client_2.pem", "client_2.pk8", test_db.slot())); | 215 ImportCertToSlot("client_2.pem", "client_2.pk8", test_db.slot())); |
212 ASSERT_TRUE(cert_2.get()); | 216 ASSERT_TRUE(cert_2.get()); |
213 | 217 |
214 std::vector<std::string> authority_1( | 218 std::vector<std::string> authority_1( |
215 1, std::string(reinterpret_cast<const char*>(kAuthority1DN), | 219 1, std::string(reinterpret_cast<const char*>(kAuthority1DN), |
216 sizeof(kAuthority1DN))); | 220 sizeof(kAuthority1DN))); |
217 scoped_refptr<net::SSLCertRequestInfo> request(new net::SSLCertRequestInfo()); | 221 scoped_refptr<net::SSLCertRequestInfo> request(new net::SSLCertRequestInfo()); |
218 request->cert_authorities = authority_1; | 222 request->cert_authorities = authority_1; |
219 | 223 |
220 base::RunLoop run_loop; | 224 base::RunLoop run_loop; |
221 net::CertificateList selected_certs; | 225 net::CertificateList selected_certs; |
222 store.GetClientCerts(*request, &selected_certs, run_loop.QuitClosure()); | 226 store.GetClientCerts(*request, &selected_certs, run_loop.QuitClosure()); |
223 run_loop.Run(); | 227 run_loop.Run(); |
224 | 228 |
225 ASSERT_EQ(1u, selected_certs.size()); | 229 ASSERT_EQ(1u, selected_certs.size()); |
226 EXPECT_TRUE(cert_1->Equals(selected_certs[0].get())); | 230 EXPECT_TRUE(cert_1->Equals(selected_certs[0].get())); |
227 } | 231 } |
228 | 232 |
229 } // namespace chromeos | 233 } // namespace chromeos |
OLD | NEW |