Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Side by Side Diff: net/base/origin_bound_cert_service_unittest.cc

Issue 8662036: Support EC certs in OriginBoundCertService and OriginBoundCertStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "net/base/origin_bound_cert_service.h" 5 #include "net/base/origin_bound_cert_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #if !defined(USE_OPENSSL)
Ryan Sleevi 2011/11/25 00:07:02 nit: Move this to the bottom of the includes ( htt
11 #include <cert.h>
12 #endif
13
10 #include "base/bind.h" 14 #include "base/bind.h"
11 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "crypto/ec_private_key.h"
12 #include "crypto/rsa_private_key.h" 17 #include "crypto/rsa_private_key.h"
13 #include "net/base/default_origin_bound_cert_store.h" 18 #include "net/base/default_origin_bound_cert_store.h"
14 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
15 #include "net/base/test_completion_callback.h" 20 #include "net/base/test_completion_callback.h"
16 #include "net/base/x509_certificate.h" 21 #include "net/base/x509_certificate.h"
17 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
18 23
19 namespace net { 24 namespace net {
20 25
21 namespace { 26 namespace {
22 27
23 void FailTest(int /* result */) { 28 void FailTest(int /* result */) {
24 FAIL(); 29 FAIL();
25 } 30 }
26 31
27 // See http://crbug.com/91512 - implement OpenSSL version of CreateSelfSigned. 32 // See http://crbug.com/91512 - implement OpenSSL version of CreateSelfSigned.
28 #if !defined(USE_OPENSSL) 33 #if !defined(USE_OPENSSL)
29 34
30 TEST(OriginBoundCertServiceTest, CacheHit) { 35 TEST(OriginBoundCertServiceTest, CacheHit) {
31 scoped_ptr<OriginBoundCertService> service( 36 scoped_ptr<OriginBoundCertService> service(
32 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL))); 37 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
33 std::string origin("https://encrypted.google.com:443"); 38 std::string origin("https://encrypted.google.com:443");
34 39
35 int error; 40 int error;
41 std::vector<OriginBoundCertType> types;
42 types.push_back(ORIGIN_BOUND_RSA_CERT);
36 TestCompletionCallback callback; 43 TestCompletionCallback callback;
37 OriginBoundCertService::RequestHandle request_handle; 44 OriginBoundCertService::RequestHandle request_handle;
38 45
39 // Asynchronous completion. 46 // Asynchronous completion.
47 OriginBoundCertType type1;
40 std::string private_key_info1, der_cert1; 48 std::string private_key_info1, der_cert1;
41 EXPECT_EQ(0, service->cert_count()); 49 EXPECT_EQ(0, service->cert_count());
42 error = service->GetOriginBoundCert( 50 error = service->GetOriginBoundCert(
43 origin, &private_key_info1, &der_cert1, callback.callback(), 51 origin, types, &type1, &private_key_info1, &der_cert1,
44 &request_handle); 52 callback.callback(), &request_handle);
45 EXPECT_EQ(ERR_IO_PENDING, error); 53 EXPECT_EQ(ERR_IO_PENDING, error);
46 EXPECT_TRUE(request_handle != NULL); 54 EXPECT_TRUE(request_handle != NULL);
47 error = callback.WaitForResult(); 55 error = callback.WaitForResult();
48 EXPECT_EQ(OK, error); 56 EXPECT_EQ(OK, error);
49 EXPECT_EQ(1, service->cert_count()); 57 EXPECT_EQ(1, service->cert_count());
58 EXPECT_EQ(ORIGIN_BOUND_RSA_CERT, type1);
50 EXPECT_FALSE(private_key_info1.empty()); 59 EXPECT_FALSE(private_key_info1.empty());
51 EXPECT_FALSE(der_cert1.empty()); 60 EXPECT_FALSE(der_cert1.empty());
52 61
53 // Synchronous completion. 62 // Synchronous completion.
63 OriginBoundCertType type2;
64 // If we request EC and RSA, should still retrieve the RSA cert.
65 types.insert(types.begin(), ORIGIN_BOUND_EC_CERT);
54 std::string private_key_info2, der_cert2; 66 std::string private_key_info2, der_cert2;
55 error = service->GetOriginBoundCert( 67 error = service->GetOriginBoundCert(
56 origin, &private_key_info2, &der_cert2, callback.callback(), 68 origin, types, &type2, &private_key_info2, &der_cert2,
57 &request_handle); 69 callback.callback(), &request_handle);
58 EXPECT_TRUE(request_handle == NULL); 70 EXPECT_TRUE(request_handle == NULL);
59 EXPECT_EQ(OK, error); 71 EXPECT_EQ(OK, error);
60 EXPECT_EQ(1, service->cert_count()); 72 EXPECT_EQ(1, service->cert_count());
61 73 EXPECT_EQ(ORIGIN_BOUND_RSA_CERT, type2);
62 EXPECT_EQ(private_key_info1, private_key_info2); 74 EXPECT_EQ(private_key_info1, private_key_info2);
63 EXPECT_EQ(der_cert1, der_cert2); 75 EXPECT_EQ(der_cert1, der_cert2);
64 76
65 EXPECT_EQ(2u, service->requests()); 77 // Request only EC. Should generate a new EC cert and discard the old RSA
66 EXPECT_EQ(1u, service->cert_store_hits()); 78 // cert.
79 OriginBoundCertType type3;
80 types.pop_back(); // Remove ORIGIN_BOUND_RSA_CERT from requested types.
81 std::string private_key_info3, der_cert3;
82 EXPECT_EQ(1, service->cert_count());
83 error = service->GetOriginBoundCert(
84 origin, types, &type3, &private_key_info3, &der_cert3,
85 callback.callback(), &request_handle);
86 EXPECT_EQ(ERR_IO_PENDING, error);
87 EXPECT_TRUE(request_handle != NULL);
88 error = callback.WaitForResult();
89 EXPECT_EQ(OK, error);
90 EXPECT_EQ(1, service->cert_count());
91 EXPECT_EQ(ORIGIN_BOUND_EC_CERT, type3);
92 EXPECT_FALSE(private_key_info1.empty());
93 EXPECT_FALSE(der_cert1.empty());
94 EXPECT_NE(private_key_info1, private_key_info3);
95 EXPECT_NE(der_cert1, der_cert3);
96
97 // Synchronous completion.
98 // If we request RSA and EC, should now retrieve the EC cert.
99 OriginBoundCertType type4;
100 types.insert(types.begin(), ORIGIN_BOUND_RSA_CERT);
101 std::string private_key_info4, der_cert4;
102 error = service->GetOriginBoundCert(
103 origin, types, &type4, &private_key_info4, &der_cert4,
104 callback.callback(), &request_handle);
105 EXPECT_TRUE(request_handle == NULL);
106 EXPECT_EQ(OK, error);
107 EXPECT_EQ(1, service->cert_count());
108 EXPECT_EQ(ORIGIN_BOUND_EC_CERT, type4);
109 EXPECT_EQ(private_key_info3, private_key_info4);
110 EXPECT_EQ(der_cert3, der_cert4);
111
112 EXPECT_EQ(4u, service->requests());
113 EXPECT_EQ(2u, service->cert_store_hits());
67 EXPECT_EQ(0u, service->inflight_joins()); 114 EXPECT_EQ(0u, service->inflight_joins());
68 } 115 }
69 116
70 TEST(OriginBoundCertServiceTest, StoreCerts) { 117 TEST(OriginBoundCertServiceTest, StoreCerts) {
71 scoped_ptr<OriginBoundCertService> service( 118 scoped_ptr<OriginBoundCertService> service(
72 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL))); 119 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
73 int error; 120 int error;
121 std::vector<OriginBoundCertType> types;
122 types.push_back(ORIGIN_BOUND_RSA_CERT);
74 TestCompletionCallback callback; 123 TestCompletionCallback callback;
75 OriginBoundCertService::RequestHandle request_handle; 124 OriginBoundCertService::RequestHandle request_handle;
76 125
77 std::string origin1("https://encrypted.google.com:443"); 126 std::string origin1("https://encrypted.google.com:443");
127 OriginBoundCertType type1;
78 std::string private_key_info1, der_cert1; 128 std::string private_key_info1, der_cert1;
79 EXPECT_EQ(0, service->cert_count()); 129 EXPECT_EQ(0, service->cert_count());
80 error = service->GetOriginBoundCert( 130 error = service->GetOriginBoundCert(
81 origin1, &private_key_info1, &der_cert1, callback.callback(), 131 origin1, types, &type1, &private_key_info1, &der_cert1,
82 &request_handle); 132 callback.callback(), &request_handle);
83 EXPECT_EQ(ERR_IO_PENDING, error); 133 EXPECT_EQ(ERR_IO_PENDING, error);
84 EXPECT_TRUE(request_handle != NULL); 134 EXPECT_TRUE(request_handle != NULL);
85 error = callback.WaitForResult(); 135 error = callback.WaitForResult();
86 EXPECT_EQ(OK, error); 136 EXPECT_EQ(OK, error);
87 EXPECT_EQ(1, service->cert_count()); 137 EXPECT_EQ(1, service->cert_count());
88 138
89 std::string origin2("https://www.verisign.com:443"); 139 std::string origin2("https://www.verisign.com:443");
140 OriginBoundCertType type2;
90 std::string private_key_info2, der_cert2; 141 std::string private_key_info2, der_cert2;
91 error = service->GetOriginBoundCert( 142 error = service->GetOriginBoundCert(
92 origin2, &private_key_info2, &der_cert2, callback.callback(), 143 origin2, types, &type2, &private_key_info2, &der_cert2,
93 &request_handle); 144 callback.callback(), &request_handle);
94 EXPECT_EQ(ERR_IO_PENDING, error); 145 EXPECT_EQ(ERR_IO_PENDING, error);
95 EXPECT_TRUE(request_handle != NULL); 146 EXPECT_TRUE(request_handle != NULL);
96 error = callback.WaitForResult(); 147 error = callback.WaitForResult();
97 EXPECT_EQ(OK, error); 148 EXPECT_EQ(OK, error);
98 EXPECT_EQ(2, service->cert_count()); 149 EXPECT_EQ(2, service->cert_count());
99 150
100 std::string origin3("https://www.twitter.com:443"); 151 std::string origin3("https://www.twitter.com:443");
152 OriginBoundCertType type3;
101 std::string private_key_info3, der_cert3; 153 std::string private_key_info3, der_cert3;
154 types[0] = ORIGIN_BOUND_EC_CERT;
102 error = service->GetOriginBoundCert( 155 error = service->GetOriginBoundCert(
103 origin3, &private_key_info3, &der_cert3, callback.callback(), 156 origin3, types, &type3, &private_key_info3, &der_cert3,
104 &request_handle); 157 callback.callback(), &request_handle);
105 EXPECT_EQ(ERR_IO_PENDING, error); 158 EXPECT_EQ(ERR_IO_PENDING, error);
106 EXPECT_TRUE(request_handle != NULL); 159 EXPECT_TRUE(request_handle != NULL);
107 error = callback.WaitForResult(); 160 error = callback.WaitForResult();
108 EXPECT_EQ(OK, error); 161 EXPECT_EQ(OK, error);
109 EXPECT_EQ(3, service->cert_count()); 162 EXPECT_EQ(3, service->cert_count());
110 163
111 EXPECT_NE(private_key_info1, private_key_info2); 164 EXPECT_NE(private_key_info1, private_key_info2);
112 EXPECT_NE(der_cert1, der_cert2); 165 EXPECT_NE(der_cert1, der_cert2);
113 EXPECT_NE(private_key_info1, private_key_info3); 166 EXPECT_NE(private_key_info1, private_key_info3);
114 EXPECT_NE(der_cert1, der_cert3); 167 EXPECT_NE(der_cert1, der_cert3);
115 EXPECT_NE(private_key_info2, private_key_info3); 168 EXPECT_NE(private_key_info2, private_key_info3);
116 EXPECT_NE(der_cert2, der_cert3); 169 EXPECT_NE(der_cert2, der_cert3);
170 EXPECT_EQ(ORIGIN_BOUND_RSA_CERT, type1);
171 EXPECT_EQ(ORIGIN_BOUND_RSA_CERT, type2);
172 EXPECT_EQ(ORIGIN_BOUND_EC_CERT, type3);
117 } 173 }
118 174
119 // Tests an inflight join. 175 // Tests an inflight join.
120 TEST(OriginBoundCertServiceTest, InflightJoin) { 176 TEST(OriginBoundCertServiceTest, InflightJoin) {
121 scoped_ptr<OriginBoundCertService> service( 177 scoped_ptr<OriginBoundCertService> service(
122 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL))); 178 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
123 std::string origin("https://encrypted.google.com:443"); 179 std::string origin("https://encrypted.google.com:443");
124 int error; 180 int error;
181 std::vector<OriginBoundCertType> types;
182 types.push_back(ORIGIN_BOUND_RSA_CERT);
125 183
184 OriginBoundCertType type1;
126 std::string private_key_info1, der_cert1; 185 std::string private_key_info1, der_cert1;
127 TestCompletionCallback callback1; 186 TestCompletionCallback callback1;
128 OriginBoundCertService::RequestHandle request_handle1; 187 OriginBoundCertService::RequestHandle request_handle1;
129 188
189 OriginBoundCertType type2;
130 std::string private_key_info2, der_cert2; 190 std::string private_key_info2, der_cert2;
131 TestCompletionCallback callback2; 191 TestCompletionCallback callback2;
132 OriginBoundCertService::RequestHandle request_handle2; 192 OriginBoundCertService::RequestHandle request_handle2;
133 193
134 error = service->GetOriginBoundCert( 194 error = service->GetOriginBoundCert(
135 origin, &private_key_info1, &der_cert1, callback1.callback(), 195 origin, types, &type1, &private_key_info1, &der_cert1,
136 &request_handle1); 196 callback1.callback(), &request_handle1);
137 EXPECT_EQ(ERR_IO_PENDING, error); 197 EXPECT_EQ(ERR_IO_PENDING, error);
138 EXPECT_TRUE(request_handle1 != NULL); 198 EXPECT_TRUE(request_handle1 != NULL);
199 // If we request EC and RSA in the 2nd request, should still join with the
200 // original request.
201 types.insert(types.begin(), ORIGIN_BOUND_EC_CERT);
139 error = service->GetOriginBoundCert( 202 error = service->GetOriginBoundCert(
140 origin, &private_key_info2, &der_cert2, callback2.callback(), 203 origin, types, &type2, &private_key_info2, &der_cert2,
141 &request_handle2); 204 callback2.callback(), &request_handle2);
142 EXPECT_EQ(ERR_IO_PENDING, error); 205 EXPECT_EQ(ERR_IO_PENDING, error);
143 EXPECT_TRUE(request_handle2 != NULL); 206 EXPECT_TRUE(request_handle2 != NULL);
144 207
145 error = callback1.WaitForResult(); 208 error = callback1.WaitForResult();
146 EXPECT_EQ(OK, error); 209 EXPECT_EQ(OK, error);
147 error = callback2.WaitForResult(); 210 error = callback2.WaitForResult();
148 EXPECT_EQ(OK, error); 211 EXPECT_EQ(OK, error);
149 212
213 EXPECT_EQ(ORIGIN_BOUND_RSA_CERT, type1);
214 EXPECT_EQ(ORIGIN_BOUND_RSA_CERT, type2);
150 EXPECT_EQ(2u, service->requests()); 215 EXPECT_EQ(2u, service->requests());
151 EXPECT_EQ(0u, service->cert_store_hits()); 216 EXPECT_EQ(0u, service->cert_store_hits());
152 EXPECT_EQ(1u, service->inflight_joins()); 217 EXPECT_EQ(1u, service->inflight_joins());
153 } 218 }
154 219
155 TEST(OriginBoundCertServiceTest, ExtractValuesFromBytes) { 220 // Tests an inflight join with mismatching request types.
221 TEST(OriginBoundCertServiceTest, InflightJoinCancel) {
156 scoped_ptr<OriginBoundCertService> service( 222 scoped_ptr<OriginBoundCertService> service(
157 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL))); 223 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
158 std::string origin("https://encrypted.google.com:443"); 224 std::string origin("https://encrypted.google.com:443");
225 int error;
226 std::vector<OriginBoundCertType> types1;
227 types1.push_back(ORIGIN_BOUND_RSA_CERT);
228 std::vector<OriginBoundCertType> types2;
229 types2.push_back(ORIGIN_BOUND_EC_CERT);
230
231 OriginBoundCertType type1;
232 std::string private_key_info1, der_cert1;
233 TestCompletionCallback callback1;
234 OriginBoundCertService::RequestHandle request_handle1;
235
236 OriginBoundCertType type2;
237 std::string private_key_info2, der_cert2;
238 TestCompletionCallback callback2;
239 OriginBoundCertService::RequestHandle request_handle2;
240
241 error = service->GetOriginBoundCert(
242 origin, types1, &type1, &private_key_info1, &der_cert1,
243 callback1.callback(), &request_handle1);
244 EXPECT_EQ(ERR_IO_PENDING, error);
245 EXPECT_TRUE(request_handle1 != NULL);
246 // If we request only EC in the 2nd request, it should cancel the original
247 // request.
248 error = service->GetOriginBoundCert(
249 origin, types2, &type2, &private_key_info2, &der_cert2,
250 callback2.callback(), &request_handle2);
251 EXPECT_EQ(ERR_IO_PENDING, error);
252 EXPECT_TRUE(request_handle2 != NULL);
253
254 error = callback1.WaitForResult();
255 EXPECT_EQ(ERR_ABORTED, error);
256 error = callback2.WaitForResult();
257 EXPECT_EQ(OK, error);
258
259 EXPECT_TRUE(private_key_info1.empty());
260 EXPECT_TRUE(der_cert1.empty());
261 EXPECT_FALSE(private_key_info2.empty());
262 EXPECT_FALSE(der_cert2.empty());
263 EXPECT_EQ(ORIGIN_BOUND_INVALID_CERT_TYPE, type1);
264 EXPECT_EQ(ORIGIN_BOUND_EC_CERT, type2);
265 EXPECT_EQ(2u, service->requests());
266 EXPECT_EQ(0u, service->cert_store_hits());
267 EXPECT_EQ(1u, service->inflight_joins());
268 }
269
270 TEST(OriginBoundCertServiceTest, ExtractValuesFromBytesRSA) {
271 scoped_ptr<OriginBoundCertService> service(
272 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
273 std::string origin("https://encrypted.google.com:443");
274 OriginBoundCertType type;
159 std::string private_key_info, der_cert; 275 std::string private_key_info, der_cert;
160 int error; 276 int error;
277 std::vector<OriginBoundCertType> types;
278 types.push_back(ORIGIN_BOUND_RSA_CERT);
161 TestCompletionCallback callback; 279 TestCompletionCallback callback;
162 OriginBoundCertService::RequestHandle request_handle; 280 OriginBoundCertService::RequestHandle request_handle;
163 281
164 error = service->GetOriginBoundCert( 282 error = service->GetOriginBoundCert(
165 origin, &private_key_info, &der_cert, callback.callback(), 283 origin, types, &type, &private_key_info, &der_cert, callback.callback(),
166 &request_handle); 284 &request_handle);
167 EXPECT_EQ(ERR_IO_PENDING, error); 285 EXPECT_EQ(ERR_IO_PENDING, error);
168 EXPECT_TRUE(request_handle != NULL); 286 EXPECT_TRUE(request_handle != NULL);
169 error = callback.WaitForResult(); 287 error = callback.WaitForResult();
170 EXPECT_EQ(OK, error); 288 EXPECT_EQ(OK, error);
171 289
172 // Check that we can retrieve the key from the bytes. 290 // Check that we can retrieve the key from the bytes.
173 std::vector<uint8> key_vec(private_key_info.begin(), private_key_info.end()); 291 std::vector<uint8> key_vec(private_key_info.begin(), private_key_info.end());
174 scoped_ptr<crypto::RSAPrivateKey> private_key( 292 scoped_ptr<crypto::RSAPrivateKey> private_key(
175 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vec)); 293 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vec));
176 EXPECT_TRUE(private_key != NULL); 294 EXPECT_TRUE(private_key != NULL);
177 295
178 // Check that we can retrieve the cert from the bytes. 296 // Check that we can retrieve the cert from the bytes.
179 scoped_refptr<X509Certificate> x509cert( 297 scoped_refptr<X509Certificate> x509cert(
180 X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size())); 298 X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size()));
181 EXPECT_TRUE(x509cert != NULL); 299 EXPECT_TRUE(x509cert != NULL);
182 } 300 }
183 301
302 TEST(OriginBoundCertServiceTest, ExtractValuesFromBytesEC) {
303 scoped_ptr<OriginBoundCertService> service(
304 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
305 std::string origin("https://encrypted.google.com:443");
306 OriginBoundCertType type;
307 std::string private_key_info, der_cert;
308 int error;
309 std::vector<OriginBoundCertType> types;
310 types.push_back(ORIGIN_BOUND_EC_CERT);
311 TestCompletionCallback callback;
312 OriginBoundCertService::RequestHandle request_handle;
313
314 error = service->GetOriginBoundCert(
315 origin, types, &type, &private_key_info, &der_cert, callback.callback(),
316 &request_handle);
317 EXPECT_EQ(ERR_IO_PENDING, error);
318 EXPECT_TRUE(request_handle != NULL);
319 error = callback.WaitForResult();
320 EXPECT_EQ(OK, error);
321
322 #if !defined(USE_OPENSSL)
323 // The SubjectPublicKeyInfo can be extracted from the certificate data, so the
324 // OriginBoundCertService doesn't store it independently. It takes a little
325 // work to extract so we use some NSS functions here to do it.
wtc 2011/11/30 23:29:04 I seem to remember agl wrote some code to extract
Ryan Sleevi 2011/11/30 23:35:48 asn1::ExtractSPKIFromDERCert() Lives in net/base/
mattm 2011/12/02 01:55:59 Done.
mattm 2011/12/02 01:55:59 Thanks!
326 SECItem cert_item;
327 cert_item.data = (unsigned char*) der_cert.data();
328 cert_item.len = der_cert.size();
329 CERTCertificate* cert = CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
330 &cert_item,
331 NULL,
332 PR_FALSE,
333 PR_TRUE);
334 ASSERT_TRUE(cert);
335
336 std::vector<uint8> spki(
337 cert->derPublicKey.data,
338 cert->derPublicKey.data + cert->derPublicKey.len);
339
340 CERT_DestroyCertificate(cert);
341 #else
342 #error "not implemented"
Ryan Sleevi 2011/11/25 00:07:02 Is this necessary, given the #if !defined(USE_OPEN
mattm 2011/12/02 01:55:59 Nope, it was more of a documentation thing (like,
343 #endif
344
345 // Check that we can retrieve the key from the bytes.
346 std::vector<uint8> key_vec(private_key_info.begin(), private_key_info.end());
347 scoped_ptr<crypto::ECPrivateKey> private_key(
348 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
349 OriginBoundCertService::kEPKIPassword, key_vec, spki));
350 EXPECT_TRUE(private_key != NULL);
351
352 // Check that we can retrieve the cert from the bytes.
353 scoped_refptr<X509Certificate> x509cert(
354 X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size()));
355 EXPECT_TRUE(x509cert != NULL);
356 }
357
184 // Tests that the callback of a canceled request is never made. 358 // Tests that the callback of a canceled request is never made.
185 TEST(OriginBoundCertServiceTest, CancelRequest) { 359 TEST(OriginBoundCertServiceTest, CancelRequest) {
186 scoped_ptr<OriginBoundCertService> service( 360 scoped_ptr<OriginBoundCertService> service(
187 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL))); 361 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
188 std::string origin("https://encrypted.google.com:443"); 362 std::string origin("https://encrypted.google.com:443");
363 OriginBoundCertType type;
189 std::string private_key_info, der_cert; 364 std::string private_key_info, der_cert;
190 int error; 365 int error;
366 std::vector<OriginBoundCertType> types;
367 types.push_back(ORIGIN_BOUND_RSA_CERT);
191 OriginBoundCertService::RequestHandle request_handle; 368 OriginBoundCertService::RequestHandle request_handle;
192 369
193 error = service->GetOriginBoundCert(origin, 370 error = service->GetOriginBoundCert(origin,
371 types,
372 &type,
194 &private_key_info, 373 &private_key_info,
195 &der_cert, 374 &der_cert,
196 base::Bind(&FailTest), 375 base::Bind(&FailTest),
197 &request_handle); 376 &request_handle);
198 EXPECT_EQ(ERR_IO_PENDING, error); 377 EXPECT_EQ(ERR_IO_PENDING, error);
199 EXPECT_TRUE(request_handle != NULL); 378 EXPECT_TRUE(request_handle != NULL);
200 service->CancelRequest(request_handle); 379 service->CancelRequest(request_handle);
201 380
202 // Issue a few more requests to the worker pool and wait for their 381 // Issue a few more requests to the worker pool and wait for their
203 // completion, so that the task of the canceled request (which runs on a 382 // completion, so that the task of the canceled request (which runs on a
204 // worker thread) is likely to complete by the end of this test. 383 // worker thread) is likely to complete by the end of this test.
205 TestCompletionCallback callback; 384 TestCompletionCallback callback;
206 for (int i = 0; i < 5; ++i) { 385 for (int i = 0; i < 5; ++i) {
207 error = service->GetOriginBoundCert( 386 error = service->GetOriginBoundCert(
208 "https://encrypted.google.com:" + std::string(1, (char) ('1' + i)), 387 "https://encrypted.google.com:" + std::string(1, (char) ('1' + i)),
388 types,
389 &type,
209 &private_key_info, 390 &private_key_info,
210 &der_cert, 391 &der_cert,
211 callback.callback(), 392 callback.callback(),
212 &request_handle); 393 &request_handle);
213 EXPECT_EQ(ERR_IO_PENDING, error); 394 EXPECT_EQ(ERR_IO_PENDING, error);
214 EXPECT_TRUE(request_handle != NULL); 395 EXPECT_TRUE(request_handle != NULL);
215 error = callback.WaitForResult(); 396 error = callback.WaitForResult();
216 } 397 }
398
399 // Even though the original request was cancelled, the service will still
400 // store the result, it just doesn't call the callback.
401 EXPECT_EQ(6, service->cert_count());
217 } 402 }
218 403
219 #endif // !defined(USE_OPENSSL) 404 #endif // !defined(USE_OPENSSL)
220 405
221 } // namespace 406 } // namespace
222 407
223 } // namespace net 408 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698