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

Side by Side Diff: net/cert/cert_verify_proc_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/cert/cert_verify_proc.h" 5 #include "net/cert/cert_verify_proc.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 24 matching lines...) Expand all
35 35
36 using base::HexEncode; 36 using base::HexEncode;
37 37
38 namespace net { 38 namespace net {
39 39
40 namespace { 40 namespace {
41 41
42 // A certificate for www.paypal.com with a NULL byte in the common name. 42 // A certificate for www.paypal.com with a NULL byte in the common name.
43 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 43 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363
44 unsigned char paypal_null_fingerprint[] = { 44 unsigned char paypal_null_fingerprint[] = {
45 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2, 0x6a, 0xba, 45 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2,
46 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7 46 0x6a, 0xba, 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7};
47 };
48 47
49 // Mock CertVerifyProc that will set |verify_result->is_issued_by_known_root| 48 // Mock CertVerifyProc that will set |verify_result->is_issued_by_known_root|
50 // for all certificates that are Verified. 49 // for all certificates that are Verified.
51 class WellKnownCaCertVerifyProc : public CertVerifyProc { 50 class WellKnownCaCertVerifyProc : public CertVerifyProc {
52 public: 51 public:
53 // Initialize a CertVerifyProc that will set 52 // Initialize a CertVerifyProc that will set
54 // |verify_result->is_issued_by_known_root| to |is_well_known|. 53 // |verify_result->is_issued_by_known_root| to |is_well_known|.
55 explicit WellKnownCaCertVerifyProc(bool is_well_known) 54 explicit WellKnownCaCertVerifyProc(bool is_well_known)
56 : is_well_known_(is_well_known) {} 55 : is_well_known_(is_well_known) {}
57 56
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // http://crbug.com/361166 99 // http://crbug.com/361166
101 return false; 100 return false;
102 #endif 101 #endif
103 return true; 102 return true;
104 } 103 }
105 104
106 } // namespace 105 } // namespace
107 106
108 class CertVerifyProcTest : public testing::Test { 107 class CertVerifyProcTest : public testing::Test {
109 public: 108 public:
110 CertVerifyProcTest() 109 CertVerifyProcTest() : verify_proc_(CertVerifyProc::CreateDefault()) {}
111 : verify_proc_(CertVerifyProc::CreateDefault()) {
112 }
113 virtual ~CertVerifyProcTest() {} 110 virtual ~CertVerifyProcTest() {}
114 111
115 protected: 112 protected:
116 bool SupportsAdditionalTrustAnchors() { 113 bool SupportsAdditionalTrustAnchors() {
117 return verify_proc_->SupportsAdditionalTrustAnchors(); 114 return verify_proc_->SupportsAdditionalTrustAnchors();
118 } 115 }
119 116
120 int Verify(X509Certificate* cert, 117 int Verify(X509Certificate* cert,
121 const std::string& hostname, 118 const std::string& hostname,
122 int flags, 119 int flags,
123 CRLSet* crl_set, 120 CRLSet* crl_set,
124 const CertificateList& additional_trust_anchors, 121 const CertificateList& additional_trust_anchors,
125 CertVerifyResult* verify_result) { 122 CertVerifyResult* verify_result) {
126 return verify_proc_->Verify(cert, hostname, flags, crl_set, 123 return verify_proc_->Verify(cert,
127 additional_trust_anchors, verify_result); 124 hostname,
125 flags,
126 crl_set,
127 additional_trust_anchors,
128 verify_result);
128 } 129 }
129 130
130 const CertificateList empty_cert_list_; 131 const CertificateList empty_cert_list_;
131 scoped_refptr<CertVerifyProc> verify_proc_; 132 scoped_refptr<CertVerifyProc> verify_proc_;
132 }; 133 };
133 134
134 TEST_F(CertVerifyProcTest, DISABLED_WithoutRevocationChecking) { 135 TEST_F(CertVerifyProcTest, DISABLED_WithoutRevocationChecking) {
135 // Check that verification without revocation checking works. 136 // Check that verification without revocation checking works.
136 CertificateList certs = CreateCertificateListFromFile( 137 CertificateList certs =
137 GetTestCertsDirectory(), 138 CreateCertificateListFromFile(GetTestCertsDirectory(),
138 "googlenew.chain.pem", 139 "googlenew.chain.pem",
139 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 140 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
140 141
141 X509Certificate::OSCertHandles intermediates; 142 X509Certificate::OSCertHandles intermediates;
142 intermediates.push_back(certs[1]->os_cert_handle()); 143 intermediates.push_back(certs[1]->os_cert_handle());
143 144
144 scoped_refptr<X509Certificate> google_full_chain = 145 scoped_refptr<X509Certificate> google_full_chain =
145 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 146 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
146 intermediates); 147 intermediates);
147 148
148 CertVerifyResult verify_result; 149 CertVerifyResult verify_result;
149 EXPECT_EQ(OK, 150 EXPECT_EQ(OK,
150 Verify(google_full_chain.get(), 151 Verify(google_full_chain.get(),
151 "www.google.com", 152 "www.google.com",
152 0 /* flags */, 153 0 /* flags */,
153 NULL, 154 NULL,
154 empty_cert_list_, 155 empty_cert_list_,
155 &verify_result)); 156 &verify_result));
156 } 157 }
157 158
158 #if defined(OS_ANDROID) || defined(USE_OPENSSL_CERTS) 159 #if defined(OS_ANDROID) || defined(USE_OPENSSL_CERTS)
159 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. 160 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
160 #define MAYBE_EVVerification DISABLED_EVVerification 161 #define MAYBE_EVVerification DISABLED_EVVerification
161 #else 162 #else
162 #define MAYBE_EVVerification EVVerification 163 #define MAYBE_EVVerification EVVerification
163 #endif 164 #endif
164 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) { 165 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) {
165 CertificateList certs = CreateCertificateListFromFile( 166 CertificateList certs =
166 GetTestCertsDirectory(), 167 CreateCertificateListFromFile(GetTestCertsDirectory(),
167 "comodo.chain.pem", 168 "comodo.chain.pem",
168 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 169 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
169 ASSERT_EQ(3U, certs.size()); 170 ASSERT_EQ(3U, certs.size());
170 171
171 X509Certificate::OSCertHandles intermediates; 172 X509Certificate::OSCertHandles intermediates;
172 intermediates.push_back(certs[1]->os_cert_handle()); 173 intermediates.push_back(certs[1]->os_cert_handle());
173 intermediates.push_back(certs[2]->os_cert_handle()); 174 intermediates.push_back(certs[2]->os_cert_handle());
174 175
175 scoped_refptr<X509Certificate> comodo_chain = 176 scoped_refptr<X509Certificate> comodo_chain =
176 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 177 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
177 intermediates); 178 intermediates);
178 179
(...skipping 11 matching lines...) Expand all
190 } 191 }
191 192
192 TEST_F(CertVerifyProcTest, PaypalNullCertParsing) { 193 TEST_F(CertVerifyProcTest, PaypalNullCertParsing) {
193 scoped_refptr<X509Certificate> paypal_null_cert( 194 scoped_refptr<X509Certificate> paypal_null_cert(
194 X509Certificate::CreateFromBytes( 195 X509Certificate::CreateFromBytes(
195 reinterpret_cast<const char*>(paypal_null_der), 196 reinterpret_cast<const char*>(paypal_null_der),
196 sizeof(paypal_null_der))); 197 sizeof(paypal_null_der)));
197 198
198 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); 199 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert);
199 200
200 const SHA1HashValue& fingerprint = 201 const SHA1HashValue& fingerprint = paypal_null_cert->fingerprint();
201 paypal_null_cert->fingerprint();
202 for (size_t i = 0; i < 20; ++i) 202 for (size_t i = 0; i < 20; ++i)
203 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); 203 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]);
204 204
205 int flags = 0; 205 int flags = 0;
206 CertVerifyResult verify_result; 206 CertVerifyResult verify_result;
207 int error = Verify(paypal_null_cert.get(), 207 int error = Verify(paypal_null_cert.get(),
208 "www.paypal.com", 208 "www.paypal.com",
209 flags, 209 flags,
210 NULL, 210 NULL,
211 empty_cert_list_, 211 empty_cert_list_,
212 &verify_result); 212 &verify_result);
213 #if defined(USE_NSS) || defined(OS_IOS) || defined(OS_ANDROID) 213 #if defined(USE_NSS) || defined(OS_IOS) || defined(OS_ANDROID)
214 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); 214 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
215 #else 215 #else
216 // TOOD(bulach): investigate why macosx and win aren't returning 216 // TOOD(bulach): investigate why macosx and win aren't returning
217 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. 217 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID.
218 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 218 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
219 #endif 219 #endif
220 // Either the system crypto library should correctly report a certificate 220 // Either the system crypto library should correctly report a certificate
221 // name mismatch, or our certificate blacklist should cause us to report an 221 // name mismatch, or our certificate blacklist should cause us to report an
222 // invalid certificate. 222 // invalid certificate.
223 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_IOS) 223 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_IOS)
224 EXPECT_TRUE(verify_result.cert_status & 224 EXPECT_TRUE(verify_result.cert_status &
225 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); 225 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID));
226 #endif 226 #endif
227 } 227 }
228 228
229 // A regression test for http://crbug.com/31497. 229 // A regression test for http://crbug.com/31497.
230 #if defined(OS_ANDROID) 230 #if defined(OS_ANDROID)
231 // Disabled on Android, as the Android verification libraries require an 231 // Disabled on Android, as the Android verification libraries require an
232 // explicit policy to be specified, even when anyPolicy is permitted. 232 // explicit policy to be specified, even when anyPolicy is permitted.
233 #define MAYBE_IntermediateCARequireExplicitPolicy \ 233 #define MAYBE_IntermediateCARequireExplicitPolicy \
234 DISABLED_IntermediateCARequireExplicitPolicy 234 DISABLED_IntermediateCARequireExplicitPolicy
235 #else 235 #else
236 #define MAYBE_IntermediateCARequireExplicitPolicy \ 236 #define MAYBE_IntermediateCARequireExplicitPolicy \
237 IntermediateCARequireExplicitPolicy 237 IntermediateCARequireExplicitPolicy
238 #endif 238 #endif
239 TEST_F(CertVerifyProcTest, MAYBE_IntermediateCARequireExplicitPolicy) { 239 TEST_F(CertVerifyProcTest, MAYBE_IntermediateCARequireExplicitPolicy) {
240 base::FilePath certs_dir = GetTestCertsDirectory(); 240 base::FilePath certs_dir = GetTestCertsDirectory();
241 241
242 CertificateList certs = CreateCertificateListFromFile( 242 CertificateList certs = CreateCertificateListFromFile(
243 certs_dir, "explicit-policy-chain.pem", 243 certs_dir, "explicit-policy-chain.pem", X509Certificate::FORMAT_AUTO);
244 X509Certificate::FORMAT_AUTO);
245 ASSERT_EQ(3U, certs.size()); 244 ASSERT_EQ(3U, certs.size());
246 245
247 X509Certificate::OSCertHandles intermediates; 246 X509Certificate::OSCertHandles intermediates;
248 intermediates.push_back(certs[1]->os_cert_handle()); 247 intermediates.push_back(certs[1]->os_cert_handle());
249 248
250 scoped_refptr<X509Certificate> cert = 249 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
251 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 250 certs[0]->os_cert_handle(), intermediates);
252 intermediates);
253 ASSERT_TRUE(cert.get()); 251 ASSERT_TRUE(cert.get());
254 252
255 ScopedTestRoot scoped_root(certs[2].get()); 253 ScopedTestRoot scoped_root(certs[2].get());
256 254
257 int flags = 0; 255 int flags = 0;
258 CertVerifyResult verify_result; 256 CertVerifyResult verify_result;
259 int error = Verify(cert.get(), 257 int error = Verify(cert.get(),
260 "policy_test.example", 258 "policy_test.example",
261 flags, 259 flags,
262 NULL, 260 NULL,
(...skipping 18 matching lines...) Expand all
281 scoped_refptr<X509Certificate> server_cert = 279 scoped_refptr<X509Certificate> server_cert =
282 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); 280 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem");
283 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 281 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
284 282
285 scoped_refptr<X509Certificate> intermediate_cert = 283 scoped_refptr<X509Certificate> intermediate_cert =
286 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); 284 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem");
287 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 285 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
288 286
289 X509Certificate::OSCertHandles intermediates; 287 X509Certificate::OSCertHandles intermediates;
290 intermediates.push_back(intermediate_cert->os_cert_handle()); 288 intermediates.push_back(intermediate_cert->os_cert_handle());
291 scoped_refptr<X509Certificate> cert_chain = 289 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
292 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 290 server_cert->os_cert_handle(), intermediates);
293 intermediates);
294 291
295 CertVerifyResult verify_result; 292 CertVerifyResult verify_result;
296 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED | 293 int flags =
297 CertVerifier::VERIFY_EV_CERT; 294 CertVerifier::VERIFY_REV_CHECKING_ENABLED | CertVerifier::VERIFY_EV_CERT;
298 int error = Verify(cert_chain.get(), 295 int error = Verify(cert_chain.get(),
299 "2029.globalsign.com", 296 "2029.globalsign.com",
300 flags, 297 flags,
301 NULL, 298 NULL,
302 empty_cert_list_, 299 empty_cert_list_,
303 &verify_result); 300 &verify_result);
304 if (error == OK) 301 if (error == OK)
305 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); 302 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
306 else 303 else
307 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 304 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
308 } 305 }
309 306
310 // Test that verifying an ECDSA certificate doesn't crash on XP. (See 307 // Test that verifying an ECDSA certificate doesn't crash on XP. (See
311 // crbug.com/144466). 308 // crbug.com/144466).
312 TEST_F(CertVerifyProcTest, ECDSA_RSA) { 309 TEST_F(CertVerifyProcTest, ECDSA_RSA) {
313 base::FilePath certs_dir = GetTestCertsDirectory(); 310 base::FilePath certs_dir = GetTestCertsDirectory();
314 311
315 scoped_refptr<X509Certificate> cert = 312 scoped_refptr<X509Certificate> cert = ImportCertFromFile(
316 ImportCertFromFile(certs_dir, 313 certs_dir, "prime256v1-ecdsa-ee-by-1024-rsa-intermediate.pem");
317 "prime256v1-ecdsa-ee-by-1024-rsa-intermediate.pem");
318 314
319 CertVerifyResult verify_result; 315 CertVerifyResult verify_result;
320 Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, &verify_result); 316 Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, &verify_result);
321 317
322 // We don't check verify_result because the certificate is signed by an 318 // We don't check verify_result because the certificate is signed by an
323 // unknown CA and will be considered invalid on XP because of the ECDSA 319 // unknown CA and will be considered invalid on XP because of the ECDSA
324 // public key. 320 // public key.
325 } 321 }
326 322
327 // Currently, only RSA and DSA keys are checked for weakness, and our example 323 // Currently, only RSA and DSA keys are checked for weakness, and our example
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 key_types.push_back("prime256v1-ecdsa"); 358 key_types.push_back("prime256v1-ecdsa");
363 359
364 // Add the root that signed the intermediates for this test. 360 // Add the root that signed the intermediates for this test.
365 scoped_refptr<X509Certificate> root_cert = 361 scoped_refptr<X509Certificate> root_cert =
366 ImportCertFromFile(certs_dir, "2048-rsa-root.pem"); 362 ImportCertFromFile(certs_dir, "2048-rsa-root.pem");
367 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert); 363 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
368 ScopedTestRoot scoped_root(root_cert.get()); 364 ScopedTestRoot scoped_root(root_cert.get());
369 365
370 // Now test each chain. 366 // Now test each chain.
371 for (Strings::const_iterator ee_type = key_types.begin(); 367 for (Strings::const_iterator ee_type = key_types.begin();
372 ee_type != key_types.end(); ++ee_type) { 368 ee_type != key_types.end();
369 ++ee_type) {
373 for (Strings::const_iterator signer_type = key_types.begin(); 370 for (Strings::const_iterator signer_type = key_types.begin();
374 signer_type != key_types.end(); ++signer_type) { 371 signer_type != key_types.end();
375 std::string basename = *ee_type + "-ee-by-" + *signer_type + 372 ++signer_type) {
376 "-intermediate.pem"; 373 std::string basename =
374 *ee_type + "-ee-by-" + *signer_type + "-intermediate.pem";
377 SCOPED_TRACE(basename); 375 SCOPED_TRACE(basename);
378 scoped_refptr<X509Certificate> ee_cert = 376 scoped_refptr<X509Certificate> ee_cert =
379 ImportCertFromFile(certs_dir, basename); 377 ImportCertFromFile(certs_dir, basename);
380 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert); 378 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
381 379
382 basename = *signer_type + "-intermediate.pem"; 380 basename = *signer_type + "-intermediate.pem";
383 scoped_refptr<X509Certificate> intermediate = 381 scoped_refptr<X509Certificate> intermediate =
384 ImportCertFromFile(certs_dir, basename); 382 ImportCertFromFile(certs_dir, basename);
385 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); 383 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate);
386 384
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); 436 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get());
439 437
440 scoped_refptr<X509Certificate> root_cert = 438 scoped_refptr<X509Certificate> root_cert =
441 ImportCertFromFile(certs_dir, "cross-signed-root-sha1.pem"); 439 ImportCertFromFile(certs_dir, "cross-signed-root-sha1.pem");
442 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); 440 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get());
443 441
444 ScopedTestRoot scoped_root(root_cert.get()); 442 ScopedTestRoot scoped_root(root_cert.get());
445 443
446 X509Certificate::OSCertHandles intermediates; 444 X509Certificate::OSCertHandles intermediates;
447 intermediates.push_back(extra_cert->os_cert_handle()); 445 intermediates.push_back(extra_cert->os_cert_handle());
448 scoped_refptr<X509Certificate> cert_chain = 446 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
449 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 447 server_cert->os_cert_handle(), intermediates);
450 intermediates);
451 448
452 CertVerifyResult verify_result; 449 CertVerifyResult verify_result;
453 int flags = 0; 450 int flags = 0;
454 int error = Verify(cert_chain.get(), 451 int error = Verify(cert_chain.get(),
455 "127.0.0.1", 452 "127.0.0.1",
456 flags, 453 flags,
457 NULL, 454 NULL,
458 empty_cert_list_, 455 empty_cert_list_,
459 &verify_result); 456 &verify_result);
460 EXPECT_EQ(OK, error); 457 EXPECT_EQ(OK, error);
461 458
462 // The extra MD5 root should be discarded 459 // The extra MD5 root should be discarded
463 ASSERT_TRUE(verify_result.verified_cert.get()); 460 ASSERT_TRUE(verify_result.verified_cert.get());
464 ASSERT_EQ(1u, 461 ASSERT_EQ(1u,
465 verify_result.verified_cert->GetIntermediateCertificates().size()); 462 verify_result.verified_cert->GetIntermediateCertificates().size());
466 EXPECT_TRUE(X509Certificate::IsSameOSCert( 463 EXPECT_TRUE(X509Certificate::IsSameOSCert(
467 verify_result.verified_cert->GetIntermediateCertificates().front(), 464 verify_result.verified_cert->GetIntermediateCertificates().front(),
468 root_cert->os_cert_handle())); 465 root_cert->os_cert_handle()));
469 466
470 EXPECT_FALSE(verify_result.has_md5); 467 EXPECT_FALSE(verify_result.has_md5);
471 } 468 }
472 469
473 // Test for bug 94673. 470 // Test for bug 94673.
474 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) { 471 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) {
475 base::FilePath certs_dir = GetTestCertsDirectory(); 472 base::FilePath certs_dir = GetTestCertsDirectory();
476 473
477 scoped_refptr<X509Certificate> server_cert = 474 scoped_refptr<X509Certificate> server_cert =
478 ImportCertFromFile(certs_dir, "google_diginotar.pem"); 475 ImportCertFromFile(certs_dir, "google_diginotar.pem");
479 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 476 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
480 477
481 scoped_refptr<X509Certificate> intermediate_cert = 478 scoped_refptr<X509Certificate> intermediate_cert =
482 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); 479 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem");
483 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 480 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
484 481
485 X509Certificate::OSCertHandles intermediates; 482 X509Certificate::OSCertHandles intermediates;
486 intermediates.push_back(intermediate_cert->os_cert_handle()); 483 intermediates.push_back(intermediate_cert->os_cert_handle());
487 scoped_refptr<X509Certificate> cert_chain = 484 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
488 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 485 server_cert->os_cert_handle(), intermediates);
489 intermediates);
490 486
491 CertVerifyResult verify_result; 487 CertVerifyResult verify_result;
492 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED; 488 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED;
493 int error = Verify(cert_chain.get(), 489 int error = Verify(cert_chain.get(),
494 "mail.google.com", 490 "mail.google.com",
495 flags, 491 flags,
496 NULL, 492 NULL,
497 empty_cert_list_, 493 empty_cert_list_,
498 &verify_result); 494 &verify_result);
499 EXPECT_NE(OK, error); 495 EXPECT_NE(OK, error);
500 496
501 // Now turn off revocation checking. Certificate verification should still 497 // Now turn off revocation checking. Certificate verification should still
502 // fail. 498 // fail.
503 flags = 0; 499 flags = 0;
504 error = Verify(cert_chain.get(), 500 error = Verify(cert_chain.get(),
505 "mail.google.com", 501 "mail.google.com",
506 flags, 502 flags,
507 NULL, 503 NULL,
508 empty_cert_list_, 504 empty_cert_list_,
509 &verify_result); 505 &verify_result);
510 EXPECT_NE(OK, error); 506 EXPECT_NE(OK, error);
511 } 507 }
512 508
513 TEST_F(CertVerifyProcTest, DigiNotarCerts) { 509 TEST_F(CertVerifyProcTest, DigiNotarCerts) {
514 static const char* const kDigiNotarFilenames[] = { 510 static const char* const kDigiNotarFilenames[] = {
515 "diginotar_root_ca.pem", 511 "diginotar_root_ca.pem", "diginotar_cyber_ca.pem",
516 "diginotar_cyber_ca.pem", 512 "diginotar_services_1024_ca.pem", "diginotar_pkioverheid.pem",
517 "diginotar_services_1024_ca.pem", 513 "diginotar_pkioverheid_g2.pem", NULL,
518 "diginotar_pkioverheid.pem",
519 "diginotar_pkioverheid_g2.pem",
520 NULL,
521 }; 514 };
522 515
523 base::FilePath certs_dir = GetTestCertsDirectory(); 516 base::FilePath certs_dir = GetTestCertsDirectory();
524 517
525 for (size_t i = 0; kDigiNotarFilenames[i]; i++) { 518 for (size_t i = 0; kDigiNotarFilenames[i]; i++) {
526 scoped_refptr<X509Certificate> diginotar_cert = 519 scoped_refptr<X509Certificate> diginotar_cert =
527 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]); 520 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]);
528 std::string der_bytes; 521 std::string der_bytes;
529 ASSERT_TRUE(X509Certificate::GetDEREncoded( 522 ASSERT_TRUE(X509Certificate::GetDEREncoded(diginotar_cert->os_cert_handle(),
530 diginotar_cert->os_cert_handle(), &der_bytes)); 523 &der_bytes));
531 524
532 base::StringPiece spki; 525 base::StringPiece spki;
533 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki)); 526 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki));
534 527
535 std::string spki_sha1 = base::SHA1HashString(spki.as_string()); 528 std::string spki_sha1 = base::SHA1HashString(spki.as_string());
536 529
537 HashValueVector public_keys; 530 HashValueVector public_keys;
538 HashValue hash(HASH_VALUE_SHA1); 531 HashValue hash(HASH_VALUE_SHA1);
539 ASSERT_EQ(hash.size(), spki_sha1.size()); 532 ASSERT_EQ(hash.size(), spki_sha1.size());
540 memcpy(hash.data(), spki_sha1.data(), spki_sha1.size()); 533 memcpy(hash.data(), spki_sha1.data(), spki_sha1.size());
541 public_keys.push_back(hash); 534 public_keys.push_back(hash);
542 535
543 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) << 536 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys))
544 "Public key not blocked for " << kDigiNotarFilenames[i]; 537 << "Public key not blocked for " << kDigiNotarFilenames[i];
545 } 538 }
546 } 539 }
547 540
548 TEST_F(CertVerifyProcTest, NameConstraintsOk) { 541 TEST_F(CertVerifyProcTest, NameConstraintsOk) {
549 CertificateList ca_cert_list = 542 CertificateList ca_cert_list =
550 CreateCertificateListFromFile(GetTestCertsDirectory(), 543 CreateCertificateListFromFile(GetTestCertsDirectory(),
551 "root_ca_cert.pem", 544 "root_ca_cert.pem",
552 X509Certificate::FORMAT_AUTO); 545 X509Certificate::FORMAT_AUTO);
553 ASSERT_EQ(1U, ca_cert_list.size()); 546 ASSERT_EQ(1U, ca_cert_list.size());
554 ScopedTestRoot test_root(ca_cert_list[0]); 547 ScopedTestRoot test_root(ca_cert_list[0]);
555 548
556 CertificateList cert_list = CreateCertificateListFromFile( 549 CertificateList cert_list =
557 GetTestCertsDirectory(), "name_constraint_ok.crt", 550 CreateCertificateListFromFile(GetTestCertsDirectory(),
558 X509Certificate::FORMAT_AUTO); 551 "name_constraint_ok.crt",
552 X509Certificate::FORMAT_AUTO);
559 ASSERT_EQ(1U, cert_list.size()); 553 ASSERT_EQ(1U, cert_list.size());
560 554
561 X509Certificate::OSCertHandles intermediates; 555 X509Certificate::OSCertHandles intermediates;
562 scoped_refptr<X509Certificate> leaf = 556 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle(
563 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), 557 cert_list[0]->os_cert_handle(), intermediates);
564 intermediates);
565 558
566 int flags = 0; 559 int flags = 0;
567 CertVerifyResult verify_result; 560 CertVerifyResult verify_result;
568 int error = Verify(leaf.get(), 561 int error = Verify(leaf.get(),
569 "test.example.com", 562 "test.example.com",
570 flags, 563 flags,
571 NULL, 564 NULL,
572 empty_cert_list_, 565 empty_cert_list_,
573 &verify_result); 566 &verify_result);
574 EXPECT_EQ(OK, error); 567 EXPECT_EQ(OK, error);
575 EXPECT_EQ(0U, verify_result.cert_status); 568 EXPECT_EQ(0U, verify_result.cert_status);
576 } 569 }
577 570
578 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { 571 TEST_F(CertVerifyProcTest, NameConstraintsFailure) {
579 if (!SupportsReturningVerifiedChain()) { 572 if (!SupportsReturningVerifiedChain()) {
580 LOG(INFO) << "Skipping this test in this platform."; 573 LOG(INFO) << "Skipping this test in this platform.";
581 return; 574 return;
582 } 575 }
583 576
584 CertificateList ca_cert_list = 577 CertificateList ca_cert_list =
585 CreateCertificateListFromFile(GetTestCertsDirectory(), 578 CreateCertificateListFromFile(GetTestCertsDirectory(),
586 "root_ca_cert.pem", 579 "root_ca_cert.pem",
587 X509Certificate::FORMAT_AUTO); 580 X509Certificate::FORMAT_AUTO);
588 ASSERT_EQ(1U, ca_cert_list.size()); 581 ASSERT_EQ(1U, ca_cert_list.size());
589 ScopedTestRoot test_root(ca_cert_list[0]); 582 ScopedTestRoot test_root(ca_cert_list[0]);
590 583
591 CertificateList cert_list = CreateCertificateListFromFile( 584 CertificateList cert_list =
592 GetTestCertsDirectory(), "name_constraint_bad.crt", 585 CreateCertificateListFromFile(GetTestCertsDirectory(),
593 X509Certificate::FORMAT_AUTO); 586 "name_constraint_bad.crt",
587 X509Certificate::FORMAT_AUTO);
594 ASSERT_EQ(1U, cert_list.size()); 588 ASSERT_EQ(1U, cert_list.size());
595 589
596 X509Certificate::OSCertHandles intermediates; 590 X509Certificate::OSCertHandles intermediates;
597 scoped_refptr<X509Certificate> leaf = 591 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle(
598 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), 592 cert_list[0]->os_cert_handle(), intermediates);
599 intermediates);
600 593
601 int flags = 0; 594 int flags = 0;
602 CertVerifyResult verify_result; 595 CertVerifyResult verify_result;
603 int error = Verify(leaf.get(), 596 int error = Verify(leaf.get(),
604 "test.example.com", 597 "test.example.com",
605 flags, 598 flags,
606 NULL, 599 NULL,
607 empty_cert_list_, 600 empty_cert_list_,
608 &verify_result); 601 &verify_result);
609 EXPECT_EQ(ERR_CERT_NAME_CONSTRAINT_VIOLATION, error); 602 EXPECT_EQ(ERR_CERT_NAME_CONSTRAINT_VIOLATION, error);
610 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, 603 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION,
611 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); 604 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION);
612 } 605 }
613 606
614 TEST_F(CertVerifyProcTest, TestKnownRoot) { 607 TEST_F(CertVerifyProcTest, TestKnownRoot) {
615 if (!SupportsDetectingKnownRoots()) { 608 if (!SupportsDetectingKnownRoots()) {
616 LOG(INFO) << "Skipping this test in this platform."; 609 LOG(INFO) << "Skipping this test in this platform.";
617 return; 610 return;
618 } 611 }
619 612
620 base::FilePath certs_dir = GetTestCertsDirectory(); 613 base::FilePath certs_dir = GetTestCertsDirectory();
621 CertificateList certs = CreateCertificateListFromFile( 614 CertificateList certs = CreateCertificateListFromFile(
622 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO); 615 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO);
623 ASSERT_EQ(2U, certs.size()); 616 ASSERT_EQ(2U, certs.size());
624 617
625 X509Certificate::OSCertHandles intermediates; 618 X509Certificate::OSCertHandles intermediates;
626 intermediates.push_back(certs[1]->os_cert_handle()); 619 intermediates.push_back(certs[1]->os_cert_handle());
627 620
628 scoped_refptr<X509Certificate> cert_chain = 621 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
629 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 622 certs[0]->os_cert_handle(), intermediates);
630 intermediates);
631 623
632 int flags = 0; 624 int flags = 0;
633 CertVerifyResult verify_result; 625 CertVerifyResult verify_result;
634 // This will blow up, May 24th, 2019. Sorry! Please disable and file a bug 626 // This will blow up, May 24th, 2019. Sorry! Please disable and file a bug
635 // against agl. See also PublicKeyHashes. 627 // against agl. See also PublicKeyHashes.
636 int error = Verify(cert_chain.get(), 628 int error = Verify(cert_chain.get(),
637 "satveda.com", 629 "satveda.com",
638 flags, 630 flags,
639 NULL, 631 NULL,
640 empty_cert_list_, 632 empty_cert_list_,
(...skipping 11 matching lines...) Expand all
652 } 644 }
653 645
654 base::FilePath certs_dir = GetTestCertsDirectory(); 646 base::FilePath certs_dir = GetTestCertsDirectory();
655 CertificateList certs = CreateCertificateListFromFile( 647 CertificateList certs = CreateCertificateListFromFile(
656 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO); 648 certs_dir, "satveda.pem", X509Certificate::FORMAT_AUTO);
657 ASSERT_EQ(2U, certs.size()); 649 ASSERT_EQ(2U, certs.size());
658 650
659 X509Certificate::OSCertHandles intermediates; 651 X509Certificate::OSCertHandles intermediates;
660 intermediates.push_back(certs[1]->os_cert_handle()); 652 intermediates.push_back(certs[1]->os_cert_handle());
661 653
662 scoped_refptr<X509Certificate> cert_chain = 654 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
663 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 655 certs[0]->os_cert_handle(), intermediates);
664 intermediates);
665 int flags = 0; 656 int flags = 0;
666 CertVerifyResult verify_result; 657 CertVerifyResult verify_result;
667 658
668 // This will blow up, May 24th, 2019. Sorry! Please disable and file a bug 659 // This will blow up, May 24th, 2019. Sorry! Please disable and file a bug
669 // against agl. See also TestKnownRoot. 660 // against agl. See also TestKnownRoot.
670 int error = Verify(cert_chain.get(), 661 int error = Verify(cert_chain.get(),
671 "satveda.com", 662 "satveda.com",
672 flags, 663 flags,
673 NULL, 664 NULL,
674 empty_cert_list_, 665 empty_cert_list_,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 &verify_result); 715 &verify_result);
725 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) 716 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
726 // This certificate has two errors: "invalid key usage" and "untrusted CA". 717 // This certificate has two errors: "invalid key usage" and "untrusted CA".
727 // However, OpenSSL returns only one (the latter), and we can't detect 718 // However, OpenSSL returns only one (the latter), and we can't detect
728 // the other errors. 719 // the other errors.
729 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 720 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
730 #else 721 #else
731 EXPECT_EQ(ERR_CERT_INVALID, error); 722 EXPECT_EQ(ERR_CERT_INVALID, error);
732 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 723 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
733 #endif 724 #endif
734 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors 725 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors
735 // from NSS. 726 // from NSS.
736 #if !defined(USE_NSS) && !defined(OS_IOS) && !defined(OS_ANDROID) 727 #if !defined(USE_NSS) && !defined(OS_IOS) && !defined(OS_ANDROID)
737 // The certificate is issued by an unknown CA. 728 // The certificate is issued by an unknown CA.
738 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); 729 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
739 #endif 730 #endif
740 } 731 }
741 732
742 // Basic test for returning the chain in CertVerifyResult. Note that the 733 // Basic test for returning the chain in CertVerifyResult. Note that the
743 // returned chain may just be a reflection of the originally supplied chain; 734 // returned chain may just be a reflection of the originally supplied chain;
744 // that is, if any errors occur, the default chain returned is an exact copy 735 // that is, if any errors occur, the default chain returned is an exact copy
745 // of the certificate to be verified. The remaining VerifyReturn* tests are 736 // of the certificate to be verified. The remaining VerifyReturn* tests are
746 // used to ensure that the actual, verified chain is being returned by 737 // used to ensure that the actual, verified chain is being returned by
747 // Verify(). 738 // Verify().
748 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { 739 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) {
749 if (!SupportsReturningVerifiedChain()) { 740 if (!SupportsReturningVerifiedChain()) {
750 LOG(INFO) << "Skipping this test in this platform."; 741 LOG(INFO) << "Skipping this test in this platform.";
751 return; 742 return;
752 } 743 }
753 744
754 base::FilePath certs_dir = GetTestCertsDirectory(); 745 base::FilePath certs_dir = GetTestCertsDirectory();
755 CertificateList certs = CreateCertificateListFromFile( 746 CertificateList certs = CreateCertificateListFromFile(
756 certs_dir, "x509_verify_results.chain.pem", 747 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO);
757 X509Certificate::FORMAT_AUTO);
758 ASSERT_EQ(3U, certs.size()); 748 ASSERT_EQ(3U, certs.size());
759 749
760 X509Certificate::OSCertHandles intermediates; 750 X509Certificate::OSCertHandles intermediates;
761 intermediates.push_back(certs[1]->os_cert_handle()); 751 intermediates.push_back(certs[1]->os_cert_handle());
762 intermediates.push_back(certs[2]->os_cert_handle()); 752 intermediates.push_back(certs[2]->os_cert_handle());
763 753
764 ScopedTestRoot scoped_root(certs[2].get()); 754 ScopedTestRoot scoped_root(certs[2].get());
765 755
766 scoped_refptr<X509Certificate> google_full_chain = 756 scoped_refptr<X509Certificate> google_full_chain =
767 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 757 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
(...skipping 29 matching lines...) Expand all
797 // known public registry controlled domain information) issued by well-known 787 // known public registry controlled domain information) issued by well-known
798 // CAs are flagged appropriately, while certificates that are issued by 788 // CAs are flagged appropriately, while certificates that are issued by
799 // internal CAs are not flagged. 789 // internal CAs are not flagged.
800 TEST_F(CertVerifyProcTest, IntranetHostsRejected) { 790 TEST_F(CertVerifyProcTest, IntranetHostsRejected) {
801 if (!SupportsDetectingKnownRoots()) { 791 if (!SupportsDetectingKnownRoots()) {
802 LOG(INFO) << "Skipping this test in this platform."; 792 LOG(INFO) << "Skipping this test in this platform.";
803 return; 793 return;
804 } 794 }
805 795
806 CertificateList cert_list = CreateCertificateListFromFile( 796 CertificateList cert_list = CreateCertificateListFromFile(
807 GetTestCertsDirectory(), "ok_cert.pem", 797 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO);
808 X509Certificate::FORMAT_AUTO);
809 ASSERT_EQ(1U, cert_list.size()); 798 ASSERT_EQ(1U, cert_list.size());
810 scoped_refptr<X509Certificate> cert(cert_list[0]); 799 scoped_refptr<X509Certificate> cert(cert_list[0]);
811 800
812 CertVerifyResult verify_result; 801 CertVerifyResult verify_result;
813 int error = 0; 802 int error = 0;
814 803
815 // Intranet names for public CAs should be flagged: 804 // Intranet names for public CAs should be flagged:
816 verify_proc_ = new WellKnownCaCertVerifyProc(true); 805 verify_proc_ = new WellKnownCaCertVerifyProc(true);
817 error = 806 error =
818 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); 807 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result);
(...skipping 14 matching lines...) Expand all
833 // of intermediate certificates are combined, it's possible that order may 822 // of intermediate certificates are combined, it's possible that order may
834 // not be maintained. 823 // not be maintained.
835 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { 824 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) {
836 if (!SupportsReturningVerifiedChain()) { 825 if (!SupportsReturningVerifiedChain()) {
837 LOG(INFO) << "Skipping this test in this platform."; 826 LOG(INFO) << "Skipping this test in this platform.";
838 return; 827 return;
839 } 828 }
840 829
841 base::FilePath certs_dir = GetTestCertsDirectory(); 830 base::FilePath certs_dir = GetTestCertsDirectory();
842 CertificateList certs = CreateCertificateListFromFile( 831 CertificateList certs = CreateCertificateListFromFile(
843 certs_dir, "x509_verify_results.chain.pem", 832 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO);
844 X509Certificate::FORMAT_AUTO);
845 ASSERT_EQ(3U, certs.size()); 833 ASSERT_EQ(3U, certs.size());
846 834
847 // Construct the chain out of order. 835 // Construct the chain out of order.
848 X509Certificate::OSCertHandles intermediates; 836 X509Certificate::OSCertHandles intermediates;
849 intermediates.push_back(certs[2]->os_cert_handle()); 837 intermediates.push_back(certs[2]->os_cert_handle());
850 intermediates.push_back(certs[1]->os_cert_handle()); 838 intermediates.push_back(certs[1]->os_cert_handle());
851 839
852 ScopedTestRoot scoped_root(certs[2].get()); 840 ScopedTestRoot scoped_root(certs[2].get());
853 841
854 scoped_refptr<X509Certificate> google_full_chain = 842 scoped_refptr<X509Certificate> google_full_chain =
(...skipping 29 matching lines...) Expand all
884 // Test that Verify() filters out certificates which are not related to 872 // Test that Verify() filters out certificates which are not related to
885 // or part of the certificate chain being verified. 873 // or part of the certificate chain being verified.
886 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { 874 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) {
887 if (!SupportsReturningVerifiedChain()) { 875 if (!SupportsReturningVerifiedChain()) {
888 LOG(INFO) << "Skipping this test in this platform."; 876 LOG(INFO) << "Skipping this test in this platform.";
889 return; 877 return;
890 } 878 }
891 879
892 base::FilePath certs_dir = GetTestCertsDirectory(); 880 base::FilePath certs_dir = GetTestCertsDirectory();
893 CertificateList certs = CreateCertificateListFromFile( 881 CertificateList certs = CreateCertificateListFromFile(
894 certs_dir, "x509_verify_results.chain.pem", 882 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO);
895 X509Certificate::FORMAT_AUTO);
896 ASSERT_EQ(3U, certs.size()); 883 ASSERT_EQ(3U, certs.size());
897 ScopedTestRoot scoped_root(certs[2].get()); 884 ScopedTestRoot scoped_root(certs[2].get());
898 885
899 scoped_refptr<X509Certificate> unrelated_certificate = 886 scoped_refptr<X509Certificate> unrelated_certificate =
900 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem"); 887 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem");
901 scoped_refptr<X509Certificate> unrelated_certificate2 = 888 scoped_refptr<X509Certificate> unrelated_certificate2 =
902 ImportCertFromFile(certs_dir, "aia-cert.pem"); 889 ImportCertFromFile(certs_dir, "aia-cert.pem");
903 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate); 890 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate);
904 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate2); 891 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate2);
905 892
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 certs[2]->os_cert_handle())); 927 certs[2]->os_cert_handle()));
941 } 928 }
942 929
943 TEST_F(CertVerifyProcTest, AdditionalTrustAnchors) { 930 TEST_F(CertVerifyProcTest, AdditionalTrustAnchors) {
944 if (!SupportsAdditionalTrustAnchors()) { 931 if (!SupportsAdditionalTrustAnchors()) {
945 LOG(INFO) << "Skipping this test in this platform."; 932 LOG(INFO) << "Skipping this test in this platform.";
946 return; 933 return;
947 } 934 }
948 935
949 // |ca_cert| is the issuer of |cert|. 936 // |ca_cert| is the issuer of |cert|.
950 CertificateList ca_cert_list = CreateCertificateListFromFile( 937 CertificateList ca_cert_list =
951 GetTestCertsDirectory(), "root_ca_cert.pem", 938 CreateCertificateListFromFile(GetTestCertsDirectory(),
952 X509Certificate::FORMAT_AUTO); 939 "root_ca_cert.pem",
940 X509Certificate::FORMAT_AUTO);
953 ASSERT_EQ(1U, ca_cert_list.size()); 941 ASSERT_EQ(1U, ca_cert_list.size());
954 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]); 942 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]);
955 943
956 CertificateList cert_list = CreateCertificateListFromFile( 944 CertificateList cert_list = CreateCertificateListFromFile(
957 GetTestCertsDirectory(), "ok_cert.pem", 945 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO);
958 X509Certificate::FORMAT_AUTO);
959 ASSERT_EQ(1U, cert_list.size()); 946 ASSERT_EQ(1U, cert_list.size());
960 scoped_refptr<X509Certificate> cert(cert_list[0]); 947 scoped_refptr<X509Certificate> cert(cert_list[0]);
961 948
962 // Verification of |cert| fails when |ca_cert| is not in the trust anchors 949 // Verification of |cert| fails when |ca_cert| is not in the trust anchors
963 // list. 950 // list.
964 int flags = 0; 951 int flags = 0;
965 CertVerifyResult verify_result; 952 CertVerifyResult verify_result;
966 int error = Verify( 953 int error = Verify(
967 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); 954 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result);
968 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 955 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
(...skipping 21 matching lines...) Expand all
990 // Tests that certificates issued by user-supplied roots are not flagged as 977 // Tests that certificates issued by user-supplied roots are not flagged as
991 // issued by a known root. This should pass whether or not the platform supports 978 // issued by a known root. This should pass whether or not the platform supports
992 // detecting known roots. 979 // detecting known roots.
993 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { 980 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) {
994 // Load root_ca_cert.pem into the test root store. 981 // Load root_ca_cert.pem into the test root store.
995 TestRootCerts* root_certs = TestRootCerts::GetInstance(); 982 TestRootCerts* root_certs = TestRootCerts::GetInstance();
996 root_certs->AddFromFile( 983 root_certs->AddFromFile(
997 GetTestCertsDirectory().AppendASCII("root_ca_cert.pem")); 984 GetTestCertsDirectory().AppendASCII("root_ca_cert.pem"));
998 985
999 CertificateList cert_list = CreateCertificateListFromFile( 986 CertificateList cert_list = CreateCertificateListFromFile(
1000 GetTestCertsDirectory(), "ok_cert.pem", 987 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO);
1001 X509Certificate::FORMAT_AUTO);
1002 ASSERT_EQ(1U, cert_list.size()); 988 ASSERT_EQ(1U, cert_list.size());
1003 scoped_refptr<X509Certificate> cert(cert_list[0]); 989 scoped_refptr<X509Certificate> cert(cert_list[0]);
1004 990
1005 // Verification should pass. 991 // Verification should pass.
1006 int flags = 0; 992 int flags = 0;
1007 CertVerifyResult verify_result; 993 CertVerifyResult verify_result;
1008 int error = Verify( 994 int error = Verify(
1009 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); 995 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result);
1010 EXPECT_EQ(OK, error); 996 EXPECT_EQ(OK, error);
1011 EXPECT_EQ(0U, verify_result.cert_status); 997 EXPECT_EQ(0U, verify_result.cert_status);
1012 // But should not be marked as a known root. 998 // But should not be marked as a known root.
1013 EXPECT_FALSE(verify_result.is_issued_by_known_root); 999 EXPECT_FALSE(verify_result.is_issued_by_known_root);
1014 1000
1015 root_certs->Clear(); 1001 root_certs->Clear();
1016 EXPECT_TRUE(root_certs->IsEmpty()); 1002 EXPECT_TRUE(root_certs->IsEmpty());
1017 } 1003 }
1018 1004
1019 #if defined(OS_MACOSX) && !defined(OS_IOS) 1005 #if defined(OS_MACOSX) && !defined(OS_IOS)
1020 // Tests that, on OS X, issues with a cross-certified Baltimore CyberTrust 1006 // Tests that, on OS X, issues with a cross-certified Baltimore CyberTrust
1021 // Root can be successfully worked around once Apple completes removing the 1007 // Root can be successfully worked around once Apple completes removing the
1022 // older GTE CyberTrust Root from its trusted root store. 1008 // older GTE CyberTrust Root from its trusted root store.
1023 // 1009 //
1024 // The issue is caused by servers supplying the cross-certified intermediate 1010 // The issue is caused by servers supplying the cross-certified intermediate
1025 // (necessary for certain mobile platforms), which OS X does not recognize 1011 // (necessary for certain mobile platforms), which OS X does not recognize
1026 // as already existing within its trust store. 1012 // as already existing within its trust store.
1027 TEST_F(CertVerifyProcTest, CybertrustGTERoot) { 1013 TEST_F(CertVerifyProcTest, CybertrustGTERoot) {
1028 CertificateList certs = CreateCertificateListFromFile( 1014 CertificateList certs =
1029 GetTestCertsDirectory(), 1015 CreateCertificateListFromFile(GetTestCertsDirectory(),
1030 "cybertrust_omniroot_chain.pem", 1016 "cybertrust_omniroot_chain.pem",
1031 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 1017 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
1032 ASSERT_EQ(2U, certs.size()); 1018 ASSERT_EQ(2U, certs.size());
1033 1019
1034 X509Certificate::OSCertHandles intermediates; 1020 X509Certificate::OSCertHandles intermediates;
1035 intermediates.push_back(certs[1]->os_cert_handle()); 1021 intermediates.push_back(certs[1]->os_cert_handle());
1036 1022
1037 scoped_refptr<X509Certificate> cybertrust_basic = 1023 scoped_refptr<X509Certificate> cybertrust_basic =
1038 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1024 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1039 intermediates); 1025 intermediates);
1040 ASSERT_TRUE(cybertrust_basic.get()); 1026 ASSERT_TRUE(cybertrust_basic.get());
1041 1027
1042 scoped_refptr<X509Certificate> baltimore_root = 1028 scoped_refptr<X509Certificate> baltimore_root = ImportCertFromFile(
1043 ImportCertFromFile(GetTestCertsDirectory(), 1029 GetTestCertsDirectory(), "cybertrust_baltimore_root.pem");
1044 "cybertrust_baltimore_root.pem");
1045 ASSERT_TRUE(baltimore_root.get()); 1030 ASSERT_TRUE(baltimore_root.get());
1046 1031
1047 ScopedTestRoot scoped_root(baltimore_root.get()); 1032 ScopedTestRoot scoped_root(baltimore_root.get());
1048 1033
1049 // Ensure that ONLY the Baltimore CyberTrust Root is trusted. This 1034 // Ensure that ONLY the Baltimore CyberTrust Root is trusted. This
1050 // simulates Keychain removing support for the GTE CyberTrust Root. 1035 // simulates Keychain removing support for the GTE CyberTrust Root.
1051 TestRootCerts::GetInstance()->SetAllowSystemTrust(false); 1036 TestRootCerts::GetInstance()->SetAllowSystemTrust(false);
1052 base::ScopedClosureRunner reset_system_trust( 1037 base::ScopedClosureRunner reset_system_trust(
1053 base::Bind(&TestRootCerts::SetAllowSystemTrust, 1038 base::Bind(&TestRootCerts::SetAllowSystemTrust,
1054 base::Unretained(TestRootCerts::GetInstance()), 1039 base::Unretained(TestRootCerts::GetInstance()),
1055 true)); 1040 true));
1056 1041
1057 // First, make sure a simple certificate chain from 1042 // First, make sure a simple certificate chain from
1058 // EE -> Public SureServer SV -> Baltimore CyberTrust 1043 // EE -> Public SureServer SV -> Baltimore CyberTrust
1059 // works. Only the first two certificates are included in the chain. 1044 // works. Only the first two certificates are included in the chain.
1060 int flags = 0; 1045 int flags = 0;
1061 CertVerifyResult verify_result; 1046 CertVerifyResult verify_result;
1062 int error = Verify(cybertrust_basic.get(), 1047 int error = Verify(cybertrust_basic.get(),
1063 "cacert.omniroot.com", 1048 "cacert.omniroot.com",
1064 flags, 1049 flags,
1065 NULL, 1050 NULL,
1066 empty_cert_list_, 1051 empty_cert_list_,
1067 &verify_result); 1052 &verify_result);
1068 EXPECT_EQ(OK, error); 1053 EXPECT_EQ(OK, error);
1069 EXPECT_EQ(0U, verify_result.cert_status); 1054 EXPECT_EQ(0U, verify_result.cert_status);
1070 1055
1071 // Attempt to verify with the first known cross-certified intermediate 1056 // Attempt to verify with the first known cross-certified intermediate
1072 // provided. 1057 // provided.
1073 scoped_refptr<X509Certificate> baltimore_intermediate_1 = 1058 scoped_refptr<X509Certificate> baltimore_intermediate_1 = ImportCertFromFile(
1074 ImportCertFromFile(GetTestCertsDirectory(), 1059 GetTestCertsDirectory(), "cybertrust_baltimore_cross_certified_1.pem");
1075 "cybertrust_baltimore_cross_certified_1.pem");
1076 ASSERT_TRUE(baltimore_intermediate_1.get()); 1060 ASSERT_TRUE(baltimore_intermediate_1.get());
1077 1061
1078 X509Certificate::OSCertHandles intermediate_chain_1 = 1062 X509Certificate::OSCertHandles intermediate_chain_1 =
1079 cybertrust_basic->GetIntermediateCertificates(); 1063 cybertrust_basic->GetIntermediateCertificates();
1080 intermediate_chain_1.push_back(baltimore_intermediate_1->os_cert_handle()); 1064 intermediate_chain_1.push_back(baltimore_intermediate_1->os_cert_handle());
1081 1065
1082 scoped_refptr<X509Certificate> baltimore_chain_1 = 1066 scoped_refptr<X509Certificate> baltimore_chain_1 =
1083 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(), 1067 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(),
1084 intermediate_chain_1); 1068 intermediate_chain_1);
1085 error = Verify(baltimore_chain_1.get(), 1069 error = Verify(baltimore_chain_1.get(),
1086 "cacert.omniroot.com", 1070 "cacert.omniroot.com",
1087 flags, 1071 flags,
1088 NULL, 1072 NULL,
1089 empty_cert_list_, 1073 empty_cert_list_,
1090 &verify_result); 1074 &verify_result);
1091 EXPECT_EQ(OK, error); 1075 EXPECT_EQ(OK, error);
1092 EXPECT_EQ(0U, verify_result.cert_status); 1076 EXPECT_EQ(0U, verify_result.cert_status);
1093 1077
1094 // Attempt to verify with the second known cross-certified intermediate 1078 // Attempt to verify with the second known cross-certified intermediate
1095 // provided. 1079 // provided.
1096 scoped_refptr<X509Certificate> baltimore_intermediate_2 = 1080 scoped_refptr<X509Certificate> baltimore_intermediate_2 = ImportCertFromFile(
1097 ImportCertFromFile(GetTestCertsDirectory(), 1081 GetTestCertsDirectory(), "cybertrust_baltimore_cross_certified_2.pem");
1098 "cybertrust_baltimore_cross_certified_2.pem");
1099 ASSERT_TRUE(baltimore_intermediate_2.get()); 1082 ASSERT_TRUE(baltimore_intermediate_2.get());
1100 1083
1101 X509Certificate::OSCertHandles intermediate_chain_2 = 1084 X509Certificate::OSCertHandles intermediate_chain_2 =
1102 cybertrust_basic->GetIntermediateCertificates(); 1085 cybertrust_basic->GetIntermediateCertificates();
1103 intermediate_chain_2.push_back(baltimore_intermediate_2->os_cert_handle()); 1086 intermediate_chain_2.push_back(baltimore_intermediate_2->os_cert_handle());
1104 1087
1105 scoped_refptr<X509Certificate> baltimore_chain_2 = 1088 scoped_refptr<X509Certificate> baltimore_chain_2 =
1106 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(), 1089 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(),
1107 intermediate_chain_2); 1090 intermediate_chain_2);
1108 error = Verify(baltimore_chain_2.get(), 1091 error = Verify(baltimore_chain_2.get(),
1109 "cacert.omniroot.com", 1092 "cacert.omniroot.com",
1110 flags, 1093 flags,
1111 NULL, 1094 NULL,
1112 empty_cert_list_, 1095 empty_cert_list_,
1113 &verify_result); 1096 &verify_result);
1114 EXPECT_EQ(OK, error); 1097 EXPECT_EQ(OK, error);
1115 EXPECT_EQ(0U, verify_result.cert_status); 1098 EXPECT_EQ(0U, verify_result.cert_status);
1116 1099
1117 // Attempt to verify when both a cross-certified intermediate AND 1100 // Attempt to verify when both a cross-certified intermediate AND
1118 // the legacy GTE root are provided. 1101 // the legacy GTE root are provided.
1119 scoped_refptr<X509Certificate> cybertrust_root = 1102 scoped_refptr<X509Certificate> cybertrust_root =
1120 ImportCertFromFile(GetTestCertsDirectory(), 1103 ImportCertFromFile(GetTestCertsDirectory(), "cybertrust_gte_root.pem");
1121 "cybertrust_gte_root.pem");
1122 ASSERT_TRUE(cybertrust_root.get()); 1104 ASSERT_TRUE(cybertrust_root.get());
1123 1105
1124 intermediate_chain_2.push_back(cybertrust_root->os_cert_handle()); 1106 intermediate_chain_2.push_back(cybertrust_root->os_cert_handle());
1125 scoped_refptr<X509Certificate> baltimore_chain_with_root = 1107 scoped_refptr<X509Certificate> baltimore_chain_with_root =
1126 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(), 1108 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(),
1127 intermediate_chain_2); 1109 intermediate_chain_2);
1128 error = Verify(baltimore_chain_with_root.get(), 1110 error = Verify(baltimore_chain_with_root.get(),
1129 "cacert.omniroot.com", 1111 "cacert.omniroot.com",
1130 flags, 1112 flags,
1131 NULL, 1113 NULL,
1132 empty_cert_list_, 1114 empty_cert_list_,
1133 &verify_result); 1115 &verify_result);
1134 EXPECT_EQ(OK, error); 1116 EXPECT_EQ(OK, error);
1135 EXPECT_EQ(0U, verify_result.cert_status); 1117 EXPECT_EQ(0U, verify_result.cert_status);
1136 1118
1137 TestRootCerts::GetInstance()->Clear(); 1119 TestRootCerts::GetInstance()->Clear();
1138 EXPECT_TRUE(TestRootCerts::GetInstance()->IsEmpty()); 1120 EXPECT_TRUE(TestRootCerts::GetInstance()->IsEmpty());
1139 } 1121 }
1140 #endif 1122 #endif
1141 1123
1142 #if defined(USE_NSS) || defined(OS_IOS) || defined(OS_WIN) || defined(OS_MACOSX) 1124 #if defined(USE_NSS) || defined(OS_IOS) || defined(OS_WIN) || defined(OS_MACOSX)
1143 static const uint8 kCRLSetLeafSPKIBlocked[] = { 1125 static const uint8 kCRLSetLeafSPKIBlocked[] = {
1144 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 1126 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22,
1145 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 1127 0x3a, 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54,
1146 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, 1128 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74,
1147 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, 1129 0x22, 0x2c, 0x22, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22,
1148 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, 1130 0x3a, 0x30, 0x2c, 0x22, 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f,
1149 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 1131 0x6d, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72,
1150 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 1132 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f,
1151 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x43, 0x38, 0x4d, 0x4a, 0x46, 0x55, 0x55, 1133 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 0x49, 0x73, 0x22, 0x3a, 0x5b,
1152 0x5a, 0x38, 0x43, 0x79, 0x54, 0x2b, 0x4e, 0x57, 0x64, 0x68, 0x69, 0x7a, 0x51, 1134 0x22, 0x43, 0x38, 0x4d, 0x4a, 0x46, 0x55, 0x55, 0x5a, 0x38, 0x43, 0x79,
1153 0x68, 0x54, 0x49, 0x65, 0x46, 0x49, 0x37, 0x76, 0x41, 0x77, 0x7a, 0x64, 0x54, 1135 0x54, 0x2b, 0x4e, 0x57, 0x64, 0x68, 0x69, 0x7a, 0x51, 0x68, 0x54, 0x49,
1154 0x79, 0x52, 0x59, 0x45, 0x6e, 0x78, 0x6c, 0x33, 0x62, 0x67, 0x3d, 0x22, 0x5d, 1136 0x65, 0x46, 0x49, 0x37, 0x76, 0x41, 0x77, 0x7a, 0x64, 0x54, 0x79, 0x52,
1155 0x7d, 1137 0x59, 0x45, 0x6e, 0x78, 0x6c, 0x33, 0x62, 0x67, 0x3d, 0x22, 0x5d, 0x7d,
1156 }; 1138 };
1157 1139
1158 static const uint8 kCRLSetLeafSerialBlocked[] = { 1140 static const uint8 kCRLSetLeafSerialBlocked[] = {
1159 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 1141 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22,
1160 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 1142 0x3a, 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54,
1161 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, 1143 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74,
1162 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, 1144 0x22, 0x2c, 0x22, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22,
1163 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, 1145 0x3a, 0x30, 0x2c, 0x22, 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f,
1164 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 1146 0x6d, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72,
1165 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 1147 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f,
1166 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x0f, 0x87, 0xe4, 0xc7, 0x75, 0xea, 1148 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 0x49, 0x73, 0x22, 0x3a, 0x5b,
1167 0x46, 0x7e, 0xf3, 0xfd, 0x82, 0xb7, 0x46, 0x7b, 0x10, 0xda, 0xc5, 0xbf, 0xd8, 1149 0x5d, 0x7d, 0x0f, 0x87, 0xe4, 0xc7, 0x75, 0xea, 0x46, 0x7e, 0xf3, 0xfd,
1168 0xd1, 0x29, 0xb2, 0xc6, 0xac, 0x7f, 0x51, 0x42, 0x15, 0x28, 0x51, 0x06, 0x7f, 1150 0x82, 0xb7, 0x46, 0x7b, 0x10, 0xda, 0xc5, 0xbf, 0xd8, 0xd1, 0x29, 0xb2,
1169 0x01, 0x00, 0x00, 0x00, // number of serials 1151 0xc6, 0xac, 0x7f, 0x51, 0x42, 0x15, 0x28, 0x51, 0x06, 0x7f, 0x01, 0x00,
1170 0x01, 0xed, // serial 0xed 1152 0x00, 0x00, // number of serials
1153 0x01, 0xed, // serial 0xed
1171 }; 1154 };
1172 1155
1173 static const uint8 kCRLSetQUICSerialBlocked[] = { 1156 static const uint8 kCRLSetQUICSerialBlocked[] = {
1174 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 1157 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
1175 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 1158 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
1176 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, 1159 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c,
1177 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, 1160 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, 0x53, 0x65, 0x71, 0x75, 0x65,
1178 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, 1161 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x44, 0x65, 0x6c,
1179 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, 1162 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, 0x22,
1180 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 1163 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22,
1181 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 1164 0x3a, 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64,
1182 // Issuer SPKI SHA-256 hash: 1165 0x53, 0x50, 0x4b, 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d,
1183 0xe4, 0x3a, 0xa3, 0xdb, 0x98, 0x31, 0x61, 0x05, 0xdd, 0x57, 0x6d, 0xc6, 0x2f, 1166 // Issuer SPKI SHA-256 hash:
1184 0x71, 0x26, 0xba, 0xdd, 0xf4, 0x98, 0x3e, 0x62, 0x22, 0xf8, 0xf9, 0xe4, 0x18, 1167 0xe4, 0x3a, 0xa3, 0xdb, 0x98, 0x31, 0x61, 0x05, 0xdd, 0x57, 0x6d,
1185 0x62, 0x77, 0x79, 0xdb, 0x9b, 0x31, 1168 0xc6, 0x2f, 0x71, 0x26, 0xba, 0xdd, 0xf4, 0x98, 0x3e, 0x62, 0x22,
1186 0x01, 0x00, 0x00, 0x00, // number of serials 1169 0xf8, 0xf9, 0xe4, 0x18, 0x62, 0x77, 0x79, 0xdb, 0x9b, 0x31, 0x01,
1187 0x01, 0x03, // serial 3 1170 0x00, 0x00, 0x00, // number of serials
1171 0x01, 0x03, // serial 3
1188 }; 1172 };
1189 1173
1190 // Test that CRLSets are effective in making a certificate appear to be 1174 // Test that CRLSets are effective in making a certificate appear to be
1191 // revoked. 1175 // revoked.
1192 TEST_F(CertVerifyProcTest, CRLSet) { 1176 TEST_F(CertVerifyProcTest, CRLSet) {
1193 CertificateList ca_cert_list = 1177 CertificateList ca_cert_list =
1194 CreateCertificateListFromFile(GetTestCertsDirectory(), 1178 CreateCertificateListFromFile(GetTestCertsDirectory(),
1195 "root_ca_cert.pem", 1179 "root_ca_cert.pem",
1196 X509Certificate::FORMAT_AUTO); 1180 X509Certificate::FORMAT_AUTO);
1197 ASSERT_EQ(1U, ca_cert_list.size()); 1181 ASSERT_EQ(1U, ca_cert_list.size());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 error = Verify(cert.get(), 1218 error = Verify(cert.get(),
1235 "127.0.0.1", 1219 "127.0.0.1",
1236 flags, 1220 flags,
1237 crl_set.get(), 1221 crl_set.get(),
1238 empty_cert_list_, 1222 empty_cert_list_,
1239 &verify_result); 1223 &verify_result);
1240 EXPECT_EQ(ERR_CERT_REVOKED, error); 1224 EXPECT_EQ(ERR_CERT_REVOKED, error);
1241 } 1225 }
1242 1226
1243 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) { 1227 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) {
1244 CertificateList ca_cert_list = 1228 CertificateList ca_cert_list = CreateCertificateListFromFile(
1245 CreateCertificateListFromFile(GetTestCertsDirectory(), 1229 GetTestCertsDirectory(), "quic_root.crt", X509Certificate::FORMAT_AUTO);
1246 "quic_root.crt",
1247 X509Certificate::FORMAT_AUTO);
1248 ASSERT_EQ(1U, ca_cert_list.size()); 1230 ASSERT_EQ(1U, ca_cert_list.size());
1249 ScopedTestRoot test_root(ca_cert_list[0]); 1231 ScopedTestRoot test_root(ca_cert_list[0]);
1250 1232
1251 CertificateList intermediate_cert_list = 1233 CertificateList intermediate_cert_list =
1252 CreateCertificateListFromFile(GetTestCertsDirectory(), 1234 CreateCertificateListFromFile(GetTestCertsDirectory(),
1253 "quic_intermediate.crt", 1235 "quic_intermediate.crt",
1254 X509Certificate::FORMAT_AUTO); 1236 X509Certificate::FORMAT_AUTO);
1255 ASSERT_EQ(1U, intermediate_cert_list.size()); 1237 ASSERT_EQ(1U, intermediate_cert_list.size());
1256 X509Certificate::OSCertHandles intermediates; 1238 X509Certificate::OSCertHandles intermediates;
1257 intermediates.push_back(intermediate_cert_list[0]->os_cert_handle()); 1239 intermediates.push_back(intermediate_cert_list[0]->os_cert_handle());
1258 1240
1259 CertificateList cert_list = CreateCertificateListFromFile( 1241 CertificateList cert_list =
1260 GetTestCertsDirectory(), "quic_test.example.com.crt", 1242 CreateCertificateListFromFile(GetTestCertsDirectory(),
1261 X509Certificate::FORMAT_AUTO); 1243 "quic_test.example.com.crt",
1244 X509Certificate::FORMAT_AUTO);
1262 ASSERT_EQ(1U, cert_list.size()); 1245 ASSERT_EQ(1U, cert_list.size());
1263 1246
1264 scoped_refptr<X509Certificate> leaf = 1247 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle(
1265 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), 1248 cert_list[0]->os_cert_handle(), intermediates);
1266 intermediates);
1267 1249
1268 int flags = 0; 1250 int flags = 0;
1269 CertVerifyResult verify_result; 1251 CertVerifyResult verify_result;
1270 int error = Verify(leaf.get(), 1252 int error = Verify(leaf.get(),
1271 "test.example.com", 1253 "test.example.com",
1272 flags, 1254 flags,
1273 NULL, 1255 NULL,
1274 empty_cert_list_, 1256 empty_cert_list_,
1275 &verify_result); 1257 &verify_result);
1276 EXPECT_EQ(OK, error); 1258 EXPECT_EQ(OK, error);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 CertVerifyProcWeakDigestTest() {} 1302 CertVerifyProcWeakDigestTest() {}
1321 virtual ~CertVerifyProcWeakDigestTest() {} 1303 virtual ~CertVerifyProcWeakDigestTest() {}
1322 }; 1304 };
1323 1305
1324 TEST_P(CertVerifyProcWeakDigestTest, Verify) { 1306 TEST_P(CertVerifyProcWeakDigestTest, Verify) {
1325 WeakDigestTestData data = GetParam(); 1307 WeakDigestTestData data = GetParam();
1326 base::FilePath certs_dir = GetTestCertsDirectory(); 1308 base::FilePath certs_dir = GetTestCertsDirectory();
1327 1309
1328 ScopedTestRoot test_root; 1310 ScopedTestRoot test_root;
1329 if (data.root_cert_filename) { 1311 if (data.root_cert_filename) {
1330 scoped_refptr<X509Certificate> root_cert = 1312 scoped_refptr<X509Certificate> root_cert =
1331 ImportCertFromFile(certs_dir, data.root_cert_filename); 1313 ImportCertFromFile(certs_dir, data.root_cert_filename);
1332 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert); 1314 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
1333 test_root.Reset(root_cert.get()); 1315 test_root.Reset(root_cert.get());
1334 } 1316 }
1335 1317
1336 scoped_refptr<X509Certificate> intermediate_cert = 1318 scoped_refptr<X509Certificate> intermediate_cert =
1337 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); 1319 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1338 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 1320 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
1339 scoped_refptr<X509Certificate> ee_cert = 1321 scoped_refptr<X509Certificate> ee_cert =
1340 ImportCertFromFile(certs_dir, data.ee_cert_filename); 1322 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1341 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert); 1323 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
1342 1324
1343 X509Certificate::OSCertHandles intermediates; 1325 X509Certificate::OSCertHandles intermediates;
1344 intermediates.push_back(intermediate_cert->os_cert_handle()); 1326 intermediates.push_back(intermediate_cert->os_cert_handle());
1345 1327
1346 scoped_refptr<X509Certificate> ee_chain = 1328 scoped_refptr<X509Certificate> ee_chain = X509Certificate::CreateFromHandle(
1347 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 1329 ee_cert->os_cert_handle(), intermediates);
1348 intermediates);
1349 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); 1330 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain);
1350 1331
1351 int flags = 0; 1332 int flags = 0;
1352 CertVerifyResult verify_result; 1333 CertVerifyResult verify_result;
1353 int rv = Verify(ee_chain.get(), 1334 int rv = Verify(ee_chain.get(),
1354 "127.0.0.1", 1335 "127.0.0.1",
1355 flags, 1336 flags,
1356 NULL, 1337 NULL,
1357 empty_cert_list_, 1338 empty_cert_list_,
1358 &verify_result); 1339 &verify_result);
1359 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); 1340 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5);
1360 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); 1341 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4);
1361 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); 1342 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2);
1362 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); 1343 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor);
1363 1344
1364 // Ensure that MD4 and MD2 are tagged as invalid. 1345 // Ensure that MD4 and MD2 are tagged as invalid.
1365 if (data.expected_has_md4 || data.expected_has_md2) { 1346 if (data.expected_has_md4 || data.expected_has_md2) {
1366 EXPECT_EQ(CERT_STATUS_INVALID, 1347 EXPECT_EQ(CERT_STATUS_INVALID,
1367 verify_result.cert_status & CERT_STATUS_INVALID); 1348 verify_result.cert_status & CERT_STATUS_INVALID);
1368 } 1349 }
1369 1350
1370 // Ensure that MD5 is flagged as weak. 1351 // Ensure that MD5 is flagged as weak.
1371 if (data.expected_has_md5) { 1352 if (data.expected_has_md5) {
1372 EXPECT_EQ( 1353 EXPECT_EQ(CERT_STATUS_WEAK_SIGNATURE_ALGORITHM,
1373 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM, 1354 verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1374 verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1375 } 1355 }
1376 1356
1377 // If a root cert is present, then check that the chain was rejected if any 1357 // If a root cert is present, then check that the chain was rejected if any
1378 // weak algorithms are present. This is only checked when a root cert is 1358 // weak algorithms are present. This is only checked when a root cert is
1379 // present because the error reported for incomplete chains with weak 1359 // present because the error reported for incomplete chains with weak
1380 // algorithms depends on which implementation was used to validate (NSS, 1360 // algorithms depends on which implementation was used to validate (NSS,
1381 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm 1361 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm
1382 // present (MD2, MD4, MD5). 1362 // present (MD2, MD4, MD5).
1383 if (data.root_cert_filename) { 1363 if (data.root_cert_filename) {
1384 if (data.expected_has_md4 || data.expected_has_md2) { 1364 if (data.expected_has_md4 || data.expected_has_md2) {
1385 EXPECT_EQ(ERR_CERT_INVALID, rv); 1365 EXPECT_EQ(ERR_CERT_INVALID, rv);
1386 } else if (data.expected_has_md5) { 1366 } else if (data.expected_has_md5) {
1387 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, rv); 1367 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, rv);
1388 } else { 1368 } else {
1389 EXPECT_EQ(OK, rv); 1369 EXPECT_EQ(OK, rv);
1390 } 1370 }
1391 } 1371 }
1392 } 1372 }
1393 1373
1394 // Unlike TEST/TEST_F, which are macros that expand to further macros, 1374 // Unlike TEST/TEST_F, which are macros that expand to further macros,
1395 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that 1375 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
1396 // stringizes the arguments. As a result, macros passed as parameters (such as 1376 // stringizes the arguments. As a result, macros passed as parameters (such as
1397 // prefix or test_case_name) will not be expanded by the preprocessor. To work 1377 // prefix or test_case_name) will not be expanded by the preprocessor. To work
1398 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the 1378 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
1399 // pre-processor will expand macros such as MAYBE_test_name before 1379 // pre-processor will expand macros such as MAYBE_test_name before
1400 // instantiating the test. 1380 // instantiating the test.
1401 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ 1381 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
1402 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) 1382 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
1403 1383
1404 // The signature algorithm of the root CA should not matter. 1384 // The signature algorithm of the root CA should not matter.
1405 const WeakDigestTestData kVerifyRootCATestData[] = { 1385 const WeakDigestTestData kVerifyRootCATestData[] = {
1406 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem", 1386 {"weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem",
1407 "weak_digest_sha1_ee.pem", false, false, false }, 1387 "weak_digest_sha1_ee.pem", false, false, false},
1408 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1388 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1409 // MD4 is not supported by OS X / NSS 1389 // MD4 is not supported by OS X / NSS
1410 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem", 1390 {"weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem",
1411 "weak_digest_sha1_ee.pem", false, false, false }, 1391 "weak_digest_sha1_ee.pem", false, false, false},
1412 #endif 1392 #endif
1413 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem", 1393 {"weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem",
1414 "weak_digest_sha1_ee.pem", false, false, false }, 1394 "weak_digest_sha1_ee.pem", false, false, false},
1415 }; 1395 };
1416 INSTANTIATE_TEST_CASE_P(VerifyRoot, CertVerifyProcWeakDigestTest, 1396 INSTANTIATE_TEST_CASE_P(VerifyRoot,
1397 CertVerifyProcWeakDigestTest,
1417 testing::ValuesIn(kVerifyRootCATestData)); 1398 testing::ValuesIn(kVerifyRootCATestData));
1418 1399
1419 // The signature algorithm of intermediates should be properly detected. 1400 // The signature algorithm of intermediates should be properly detected.
1420 const WeakDigestTestData kVerifyIntermediateCATestData[] = { 1401 const WeakDigestTestData kVerifyIntermediateCATestData[] = {
1421 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 1402 {"weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1422 "weak_digest_sha1_ee.pem", true, false, false }, 1403 "weak_digest_sha1_ee.pem", true, false, false},
1423 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1404 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1424 // MD4 is not supported by OS X / NSS 1405 // MD4 is not supported by OS X / NSS
1425 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 1406 {"weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1426 "weak_digest_sha1_ee.pem", false, true, false }, 1407 "weak_digest_sha1_ee.pem", false, true, false},
1427 #endif 1408 #endif
1428 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 1409 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1429 "weak_digest_sha1_ee.pem", false, false, true }, 1410 "weak_digest_sha1_ee.pem", false, false, true},
1430 }; 1411 };
1431 // Disabled on NSS - MD4 is not supported, and MD2 and MD5 are disabled. 1412 // Disabled on NSS - MD4 is not supported, and MD2 and MD5 are disabled.
1432 #if defined(USE_NSS) || defined(OS_IOS) 1413 #if defined(USE_NSS) || defined(OS_IOS)
1433 #define MAYBE_VerifyIntermediate DISABLED_VerifyIntermediate 1414 #define MAYBE_VerifyIntermediate DISABLED_VerifyIntermediate
1434 #else 1415 #else
1435 #define MAYBE_VerifyIntermediate VerifyIntermediate 1416 #define MAYBE_VerifyIntermediate VerifyIntermediate
1436 #endif 1417 #endif
1437 WRAPPED_INSTANTIATE_TEST_CASE_P( 1418 WRAPPED_INSTANTIATE_TEST_CASE_P(
1438 MAYBE_VerifyIntermediate, 1419 MAYBE_VerifyIntermediate,
1439 CertVerifyProcWeakDigestTest, 1420 CertVerifyProcWeakDigestTest,
1440 testing::ValuesIn(kVerifyIntermediateCATestData)); 1421 testing::ValuesIn(kVerifyIntermediateCATestData));
1441 1422
1442 // The signature algorithm of end-entity should be properly detected. 1423 // The signature algorithm of end-entity should be properly detected.
1443 const WeakDigestTestData kVerifyEndEntityTestData[] = { 1424 const WeakDigestTestData kVerifyEndEntityTestData[] = {
1444 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1425 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1445 "weak_digest_md5_ee.pem", true, false, false }, 1426 "weak_digest_md5_ee.pem", true, false, false},
1446 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1427 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1447 // MD4 is not supported by OS X / NSS 1428 // MD4 is not supported by OS X / NSS
1448 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1429 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1449 "weak_digest_md4_ee.pem", false, true, false }, 1430 "weak_digest_md4_ee.pem", false, true, false},
1450 #endif 1431 #endif
1451 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1432 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1452 "weak_digest_md2_ee.pem", false, false, true }, 1433 "weak_digest_md2_ee.pem", false, false, true},
1453 }; 1434 };
1454 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot 1435 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot
1455 // be cleared until NSS is cleanly shutdown, which is not presently supported 1436 // be cleared until NSS is cleanly shutdown, which is not presently supported
1456 // in Chromium. 1437 // in Chromium.
1457 #if defined(USE_NSS) || defined(OS_IOS) 1438 #if defined(USE_NSS) || defined(OS_IOS)
1458 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity 1439 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity
1459 #else 1440 #else
1460 #define MAYBE_VerifyEndEntity VerifyEndEntity 1441 #define MAYBE_VerifyEndEntity VerifyEndEntity
1461 #endif 1442 #endif
1462 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity, 1443 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity,
1463 CertVerifyProcWeakDigestTest, 1444 CertVerifyProcWeakDigestTest,
1464 testing::ValuesIn(kVerifyEndEntityTestData)); 1445 testing::ValuesIn(kVerifyEndEntityTestData));
1465 1446
1466 // Incomplete chains should still report the status of the intermediate. 1447 // Incomplete chains should still report the status of the intermediate.
1467 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = { 1448 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = {
1468 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem", 1449 {NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem", true,
1469 true, false, false }, 1450 false, false},
1470 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1451 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1471 // MD4 is not supported by OS X / NSS 1452 // MD4 is not supported by OS X / NSS
1472 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem", 1453 {NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem", false,
1473 false, true, false }, 1454 true, false},
1474 #endif 1455 #endif
1475 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem", 1456 {NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem", false,
1476 false, false, true }, 1457 false, true},
1477 }; 1458 };
1478 // Disabled on NSS - libpkix does not return constructed chains on error, 1459 // Disabled on NSS - libpkix does not return constructed chains on error,
1479 // preventing us from detecting/inspecting the verified chain. 1460 // preventing us from detecting/inspecting the verified chain.
1480 #if defined(USE_NSS) || defined(OS_IOS) 1461 #if defined(USE_NSS) || defined(OS_IOS)
1481 #define MAYBE_VerifyIncompleteIntermediate \ 1462 #define MAYBE_VerifyIncompleteIntermediate DISABLED_VerifyIncompleteIntermediate
1482 DISABLED_VerifyIncompleteIntermediate
1483 #else 1463 #else
1484 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate 1464 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate
1485 #endif 1465 #endif
1486 WRAPPED_INSTANTIATE_TEST_CASE_P( 1466 WRAPPED_INSTANTIATE_TEST_CASE_P(
1487 MAYBE_VerifyIncompleteIntermediate, 1467 MAYBE_VerifyIncompleteIntermediate,
1488 CertVerifyProcWeakDigestTest, 1468 CertVerifyProcWeakDigestTest,
1489 testing::ValuesIn(kVerifyIncompleteIntermediateTestData)); 1469 testing::ValuesIn(kVerifyIncompleteIntermediateTestData));
1490 1470
1491 // Incomplete chains should still report the status of the end-entity. 1471 // Incomplete chains should still report the status of the end-entity.
1492 const WeakDigestTestData kVerifyIncompleteEETestData[] = { 1472 const WeakDigestTestData kVerifyIncompleteEETestData[] = {
1493 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem", 1473 {NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem", true,
1494 true, false, false }, 1474 false, false},
1495 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1475 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1496 // MD4 is not supported by OS X / NSS 1476 // MD4 is not supported by OS X / NSS
1497 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem", 1477 {NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem", false,
1498 false, true, false }, 1478 true, false},
1499 #endif 1479 #endif
1500 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem", 1480 {NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem", false,
1501 false, false, true }, 1481 false, true},
1502 }; 1482 };
1503 // Disabled on NSS - libpkix does not return constructed chains on error, 1483 // Disabled on NSS - libpkix does not return constructed chains on error,
1504 // preventing us from detecting/inspecting the verified chain. 1484 // preventing us from detecting/inspecting the verified chain.
1505 #if defined(USE_NSS) || defined(OS_IOS) 1485 #if defined(USE_NSS) || defined(OS_IOS)
1506 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity 1486 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity
1507 #else 1487 #else
1508 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity 1488 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity
1509 #endif 1489 #endif
1510 WRAPPED_INSTANTIATE_TEST_CASE_P( 1490 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyIncompleteEndEntity,
1511 MAYBE_VerifyIncompleteEndEntity, 1491 CertVerifyProcWeakDigestTest,
1512 CertVerifyProcWeakDigestTest, 1492 testing::ValuesIn(kVerifyIncompleteEETestData));
1513 testing::ValuesIn(kVerifyIncompleteEETestData));
1514 1493
1515 // Differing algorithms between the intermediate and the EE should still be 1494 // Differing algorithms between the intermediate and the EE should still be
1516 // reported. 1495 // reported.
1517 const WeakDigestTestData kVerifyMixedTestData[] = { 1496 const WeakDigestTestData kVerifyMixedTestData[] = {
1518 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 1497 {"weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1519 "weak_digest_md2_ee.pem", true, false, true }, 1498 "weak_digest_md2_ee.pem", true, false, true},
1520 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 1499 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1521 "weak_digest_md5_ee.pem", true, false, true }, 1500 "weak_digest_md5_ee.pem", true, false, true},
1522 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1501 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1523 // MD4 is not supported by OS X / NSS 1502 // MD4 is not supported by OS X / NSS
1524 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 1503 {"weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1525 "weak_digest_md2_ee.pem", false, true, true }, 1504 "weak_digest_md2_ee.pem", false, true, true},
1526 #endif 1505 #endif
1527 }; 1506 };
1528 // NSS does not support MD4 and does not enable MD2 by default, making all 1507 // NSS does not support MD4 and does not enable MD2 by default, making all
1529 // permutations invalid. 1508 // permutations invalid.
1530 #if defined(USE_NSS) || defined(OS_IOS) 1509 #if defined(USE_NSS) || defined(OS_IOS)
1531 #define MAYBE_VerifyMixed DISABLED_VerifyMixed 1510 #define MAYBE_VerifyMixed DISABLED_VerifyMixed
1532 #else 1511 #else
1533 #define MAYBE_VerifyMixed VerifyMixed 1512 #define MAYBE_VerifyMixed VerifyMixed
1534 #endif 1513 #endif
1535 WRAPPED_INSTANTIATE_TEST_CASE_P( 1514 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyMixed,
1536 MAYBE_VerifyMixed, 1515 CertVerifyProcWeakDigestTest,
1537 CertVerifyProcWeakDigestTest, 1516 testing::ValuesIn(kVerifyMixedTestData));
1538 testing::ValuesIn(kVerifyMixedTestData));
1539 1517
1540 // For the list of valid hostnames, see 1518 // For the list of valid hostnames, see
1541 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem 1519 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem
1542 static const struct CertVerifyProcNameData { 1520 static const struct CertVerifyProcNameData {
1543 const char* hostname; 1521 const char* hostname;
1544 bool valid; // Whether or not |hostname| matches a subjectAltName. 1522 bool valid; // Whether or not |hostname| matches a subjectAltName.
1545 } kVerifyNameData[] = { 1523 } kVerifyNameData[] = {
1546 { "127.0.0.1", false }, // Don't match the common name 1524 {"127.0.0.1", false}, // Don't match the common name
1547 { "127.0.0.2", true }, // Matches the iPAddress SAN (IPv4) 1525 {"127.0.0.2", true}, // Matches the iPAddress SAN (IPv4)
1548 { "FE80:0:0:0:0:0:0:1", true }, // Matches the iPAddress SAN (IPv6) 1526 {"FE80:0:0:0:0:0:0:1", true}, // Matches the iPAddress SAN (IPv6)
1549 { "[FE80:0:0:0:0:0:0:1]", false }, // Should not match the iPAddress SAN 1527 {"[FE80:0:0:0:0:0:0:1]", false}, // Should not match the iPAddress SAN
1550 { "FE80::1", true }, // Compressed form matches the iPAddress SAN (IPv6) 1528 {"FE80::1", true}, // Compressed form matches the iPAddress SAN (IPv6)
1551 { "::127.0.0.2", false }, // IPv6 mapped form should NOT match iPAddress SAN 1529 {"::127.0.0.2",
1552 { "test.example", true }, // Matches the dNSName SAN 1530 false}, // IPv6 mapped form should NOT match iPAddress SAN
1553 { "test.example.", true }, // Matches the dNSName SAN (trailing . ignored) 1531 {"test.example", true}, // Matches the dNSName SAN
1554 { "www.test.example", false }, // Should not match the dNSName SAN 1532 {"test.example.", true}, // Matches the dNSName SAN (trailing . ignored)
1555 { "test..example", false }, // Should not match the dNSName SAN 1533 {"www.test.example", false}, // Should not match the dNSName SAN
1556 { "test.example..", false }, // Should not match the dNSName SAN 1534 {"test..example", false}, // Should not match the dNSName SAN
1557 { ".test.example.", false }, // Should not match the dNSName SAN 1535 {"test.example..", false}, // Should not match the dNSName SAN
1558 { ".test.example", false }, // Should not match the dNSName SAN 1536 {".test.example.", false}, // Should not match the dNSName SAN
1537 {".test.example", false}, // Should not match the dNSName SAN
1559 }; 1538 };
1560 1539
1561 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how 1540 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how
1562 // to output the parameter that was passed. Without this, it will simply 1541 // to output the parameter that was passed. Without this, it will simply
1563 // attempt to print out the first twenty bytes of the object, which depending 1542 // attempt to print out the first twenty bytes of the object, which depending
1564 // on platform and alignment, may result in an invalid read. 1543 // on platform and alignment, may result in an invalid read.
1565 void PrintTo(const CertVerifyProcNameData& data, std::ostream* os) { 1544 void PrintTo(const CertVerifyProcNameData& data, std::ostream* os) {
1566 *os << "Hostname: " << data.hostname << "; valid=" << data.valid; 1545 *os << "Hostname: " << data.hostname << "; valid=" << data.valid;
1567 } 1546 }
1568 1547
1569 class CertVerifyProcNameTest 1548 class CertVerifyProcNameTest
1570 : public CertVerifyProcTest, 1549 : public CertVerifyProcTest,
1571 public testing::WithParamInterface<CertVerifyProcNameData> { 1550 public testing::WithParamInterface<CertVerifyProcNameData> {
1572 public: 1551 public:
1573 CertVerifyProcNameTest() {} 1552 CertVerifyProcNameTest() {}
1574 virtual ~CertVerifyProcNameTest() {} 1553 virtual ~CertVerifyProcNameTest() {}
1575 }; 1554 };
1576 1555
1577 TEST_P(CertVerifyProcNameTest, VerifyCertName) { 1556 TEST_P(CertVerifyProcNameTest, VerifyCertName) {
1578 CertVerifyProcNameData data = GetParam(); 1557 CertVerifyProcNameData data = GetParam();
1579 1558
1580 CertificateList cert_list = CreateCertificateListFromFile( 1559 CertificateList cert_list =
1581 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem", 1560 CreateCertificateListFromFile(GetTestCertsDirectory(),
1582 X509Certificate::FORMAT_AUTO); 1561 "subjectAltName_sanity_check.pem",
1562 X509Certificate::FORMAT_AUTO);
1583 ASSERT_EQ(1U, cert_list.size()); 1563 ASSERT_EQ(1U, cert_list.size());
1584 scoped_refptr<X509Certificate> cert(cert_list[0]); 1564 scoped_refptr<X509Certificate> cert(cert_list[0]);
1585 1565
1586 ScopedTestRoot scoped_root(cert.get()); 1566 ScopedTestRoot scoped_root(cert.get());
1587 1567
1588 CertVerifyResult verify_result; 1568 CertVerifyResult verify_result;
1589 int error = Verify(cert.get(), data.hostname, 0, NULL, empty_cert_list_, 1569 int error = Verify(
1590 &verify_result); 1570 cert.get(), data.hostname, 0, NULL, empty_cert_list_, &verify_result);
1591 if (data.valid) { 1571 if (data.valid) {
1592 EXPECT_EQ(OK, error); 1572 EXPECT_EQ(OK, error);
1593 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); 1573 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID);
1594 } else { 1574 } else {
1595 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); 1575 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
1596 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); 1576 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID);
1597 } 1577 }
1598 } 1578 }
1599 1579
1600 WRAPPED_INSTANTIATE_TEST_CASE_P( 1580 WRAPPED_INSTANTIATE_TEST_CASE_P(VerifyName,
1601 VerifyName, 1581 CertVerifyProcNameTest,
1602 CertVerifyProcNameTest, 1582 testing::ValuesIn(kVerifyNameData));
1603 testing::ValuesIn(kVerifyNameData));
1604 1583
1605 } // namespace net 1584 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698