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

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

Issue 9584041: Create stubs for system certificate validation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix across platforms Created 8 years, 9 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/sha1.h" 9 #include "base/sha1.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); 205 const SHA1Fingerprint& fingerprint = google_cert->fingerprint();
206 for (size_t i = 0; i < 20; ++i) 206 for (size_t i = 0; i < 20; ++i)
207 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); 207 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]);
208 208
209 std::vector<std::string> dns_names; 209 std::vector<std::string> dns_names;
210 google_cert->GetDNSNames(&dns_names); 210 google_cert->GetDNSNames(&dns_names);
211 ASSERT_EQ(1U, dns_names.size()); 211 ASSERT_EQ(1U, dns_names.size());
212 EXPECT_EQ("www.google.com", dns_names[0]); 212 EXPECT_EQ("www.google.com", dns_names[0]);
213 } 213 }
214 214
215 TEST(X509CertificateTest, GoogleCertParsing) { 215 // TODO(rsleevi): Temporary fixture while refactoring http://crbug.com/114343
216 class X509CertificateTest : public testing::Test {
217 public:
218 X509CertificateTest() {}
219 virtual ~X509CertificateTest() {}
220
221 protected:
222 int Verify(X509Certificate* cert,
223 const std::string& hostname,
224 int flags,
225 CRLSet* crl_set,
226 CertVerifyResult* verify_result) {
227 return cert->Verify(hostname, flags, crl_set, verify_result);
228 }
229 };
230
231 TEST_F(X509CertificateTest, GoogleCertParsing) {
216 scoped_refptr<X509Certificate> google_cert( 232 scoped_refptr<X509Certificate> google_cert(
217 X509Certificate::CreateFromBytes( 233 X509Certificate::CreateFromBytes(
218 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 234 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
219 235
220 CheckGoogleCert(google_cert, google_fingerprint, 236 CheckGoogleCert(google_cert, google_fingerprint,
221 1238192407, // Mar 27 22:20:07 2009 GMT 237 1238192407, // Mar 27 22:20:07 2009 GMT
222 1269728407); // Mar 27 22:20:07 2010 GMT 238 1269728407); // Mar 27 22:20:07 2010 GMT
223 } 239 }
224 240
225 TEST(X509CertificateTest, WebkitCertParsing) { 241 TEST_F(X509CertificateTest, WebkitCertParsing) {
226 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( 242 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes(
227 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 243 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
228 244
229 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); 245 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert);
230 246
231 const CertPrincipal& subject = webkit_cert->subject(); 247 const CertPrincipal& subject = webkit_cert->subject();
232 EXPECT_EQ("Cupertino", subject.locality_name); 248 EXPECT_EQ("Cupertino", subject.locality_name);
233 EXPECT_EQ("California", subject.state_or_province_name); 249 EXPECT_EQ("California", subject.state_or_province_name);
234 EXPECT_EQ("US", subject.country_name); 250 EXPECT_EQ("US", subject.country_name);
235 EXPECT_EQ(0U, subject.street_addresses.size()); 251 EXPECT_EQ(0U, subject.street_addresses.size());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 EXPECT_EQ("webkit.org", dns_names[1]); 286 EXPECT_EQ("webkit.org", dns_names[1]);
271 287
272 // Test that the wildcard cert matches properly. 288 // Test that the wildcard cert matches properly.
273 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); 289 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org"));
274 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); 290 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org"));
275 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); 291 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org"));
276 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); 292 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com"));
277 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); 293 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com"));
278 } 294 }
279 295
280 TEST(X509CertificateTest, WithoutRevocationChecking) { 296 TEST_F(X509CertificateTest, WithoutRevocationChecking) {
281 // Check that verification without revocation checking works. 297 // Check that verification without revocation checking works.
282 CertificateList certs = CreateCertificateListFromFile( 298 CertificateList certs = CreateCertificateListFromFile(
283 GetTestCertsDirectory(), 299 GetTestCertsDirectory(),
284 "googlenew.chain.pem", 300 "googlenew.chain.pem",
285 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 301 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
286 302
287 X509Certificate::OSCertHandles intermediates; 303 X509Certificate::OSCertHandles intermediates;
288 intermediates.push_back(certs[1]->os_cert_handle()); 304 intermediates.push_back(certs[1]->os_cert_handle());
289 305
290 scoped_refptr<X509Certificate> google_full_chain = 306 scoped_refptr<X509Certificate> google_full_chain =
291 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 307 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
292 intermediates); 308 intermediates);
293 309
294 CertVerifyResult verify_result; 310 CertVerifyResult verify_result;
295 EXPECT_EQ(OK, google_full_chain->Verify("www.google.com", 0 /* flags */, NULL, 311 EXPECT_EQ(OK, Verify(google_full_chain, "www.google.com", 0 /* flags */, NULL,
296 &verify_result)); 312 &verify_result));
297 } 313 }
298 314
299 TEST(X509CertificateTest, ThawteCertParsing) { 315 TEST_F(X509CertificateTest, ThawteCertParsing) {
300 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( 316 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes(
301 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); 317 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)));
302 318
303 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); 319 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert);
304 320
305 const CertPrincipal& subject = thawte_cert->subject(); 321 const CertPrincipal& subject = thawte_cert->subject();
306 EXPECT_EQ("www.thawte.com", subject.common_name); 322 EXPECT_EQ("www.thawte.com", subject.common_name);
307 EXPECT_EQ("Mountain View", subject.locality_name); 323 EXPECT_EQ("Mountain View", subject.locality_name);
308 EXPECT_EQ("California", subject.state_or_province_name); 324 EXPECT_EQ("California", subject.state_or_province_name);
309 EXPECT_EQ("US", subject.country_name); 325 EXPECT_EQ("US", subject.country_name);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ASSERT_EQ(1U, dns_names.size()); 358 ASSERT_EQ(1U, dns_names.size());
343 EXPECT_EQ("www.thawte.com", dns_names[0]); 359 EXPECT_EQ("www.thawte.com", dns_names[0]);
344 } 360 }
345 361
346 #if defined(OS_ANDROID) || defined(USE_OPENSSL) 362 #if defined(OS_ANDROID) || defined(USE_OPENSSL)
347 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. 363 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
348 #define MAYBE_EVVerification DISABLED_EVVerification 364 #define MAYBE_EVVerification DISABLED_EVVerification
349 #else 365 #else
350 #define MAYBE_EVVerification EVVerification 366 #define MAYBE_EVVerification EVVerification
351 #endif 367 #endif
352 TEST(X509CertificateTest, MAYBE_EVVerification) { 368 TEST_F(X509CertificateTest, MAYBE_EVVerification) {
353 // This certificate will expire Jun 21, 2013. 369 // This certificate will expire Jun 21, 2013.
354 CertificateList certs = CreateCertificateListFromFile( 370 CertificateList certs = CreateCertificateListFromFile(
355 GetTestCertsDirectory(), 371 GetTestCertsDirectory(),
356 "comodo.chain.pem", 372 "comodo.chain.pem",
357 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 373 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
358 ASSERT_EQ(3U, certs.size()); 374 ASSERT_EQ(3U, certs.size());
359 375
360 X509Certificate::OSCertHandles intermediates; 376 X509Certificate::OSCertHandles intermediates;
361 intermediates.push_back(certs[1]->os_cert_handle()); 377 intermediates.push_back(certs[1]->os_cert_handle());
362 intermediates.push_back(certs[2]->os_cert_handle()); 378 intermediates.push_back(certs[2]->os_cert_handle());
363 379
364 scoped_refptr<X509Certificate> comodo_chain = 380 scoped_refptr<X509Certificate> comodo_chain =
365 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 381 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
366 intermediates); 382 intermediates);
367 383
368 CertVerifyResult verify_result; 384 CertVerifyResult verify_result;
369 int flags = X509Certificate::VERIFY_EV_CERT; 385 int flags = X509Certificate::VERIFY_EV_CERT;
370 int error = comodo_chain->Verify( 386 int error = Verify(comodo_chain, "comodo.com", flags, NULL, &verify_result);
371 "comodo.com", flags, NULL, &verify_result);
372 EXPECT_EQ(OK, error); 387 EXPECT_EQ(OK, error);
373 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); 388 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
374 } 389 }
375 390
376 // Test that all desired AttributeAndValue pairs can be extracted when only 391 // Test that all desired AttributeAndValue pairs can be extracted when only
377 // a single RelativeDistinguishedName is present. "Normally" there is only 392 // a single RelativeDistinguishedName is present. "Normally" there is only
378 // one AVA per RDN, but some CAs place all AVAs within a single RDN. 393 // one AVA per RDN, but some CAs place all AVAs within a single RDN.
379 // This is a regression test for http://crbug.com/101009 394 // This is a regression test for http://crbug.com/101009
380 TEST(X509CertificateTest, MultivalueRDN) { 395 TEST_F(X509CertificateTest, MultivalueRDN) {
381 FilePath certs_dir = GetTestCertsDirectory(); 396 FilePath certs_dir = GetTestCertsDirectory();
382 397
383 scoped_refptr<X509Certificate> multivalue_rdn_cert = 398 scoped_refptr<X509Certificate> multivalue_rdn_cert =
384 ImportCertFromFile(certs_dir, "multivalue_rdn.pem"); 399 ImportCertFromFile(certs_dir, "multivalue_rdn.pem");
385 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert); 400 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert);
386 401
387 const CertPrincipal& subject = multivalue_rdn_cert->subject(); 402 const CertPrincipal& subject = multivalue_rdn_cert->subject();
388 EXPECT_EQ("Multivalue RDN Test", subject.common_name); 403 EXPECT_EQ("Multivalue RDN Test", subject.common_name);
389 EXPECT_EQ("", subject.locality_name); 404 EXPECT_EQ("", subject.locality_name);
390 EXPECT_EQ("", subject.state_or_province_name); 405 EXPECT_EQ("", subject.state_or_province_name);
391 EXPECT_EQ("US", subject.country_name); 406 EXPECT_EQ("US", subject.country_name);
392 EXPECT_EQ(0U, subject.street_addresses.size()); 407 EXPECT_EQ(0U, subject.street_addresses.size());
393 ASSERT_EQ(1U, subject.organization_names.size()); 408 ASSERT_EQ(1U, subject.organization_names.size());
394 EXPECT_EQ("Chromium", subject.organization_names[0]); 409 EXPECT_EQ("Chromium", subject.organization_names[0]);
395 ASSERT_EQ(1U, subject.organization_unit_names.size()); 410 ASSERT_EQ(1U, subject.organization_unit_names.size());
396 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]); 411 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]);
397 ASSERT_EQ(1U, subject.domain_components.size()); 412 ASSERT_EQ(1U, subject.domain_components.size());
398 EXPECT_EQ("Chromium", subject.domain_components[0]); 413 EXPECT_EQ("Chromium", subject.domain_components[0]);
399 } 414 }
400 415
401 // Test that characters which would normally be escaped in the string form, 416 // Test that characters which would normally be escaped in the string form,
402 // such as '=' or '"', are not escaped when parsed as individual components. 417 // such as '=' or '"', are not escaped when parsed as individual components.
403 // This is a regression test for http://crbug.com/102839 418 // This is a regression test for http://crbug.com/102839
404 TEST(X509CertificateTest, UnescapedSpecialCharacters) { 419 TEST_F(X509CertificateTest, UnescapedSpecialCharacters) {
405 FilePath certs_dir = GetTestCertsDirectory(); 420 FilePath certs_dir = GetTestCertsDirectory();
406 421
407 scoped_refptr<X509Certificate> unescaped_cert = 422 scoped_refptr<X509Certificate> unescaped_cert =
408 ImportCertFromFile(certs_dir, "unescaped.pem"); 423 ImportCertFromFile(certs_dir, "unescaped.pem");
409 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert); 424 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert);
410 425
411 const CertPrincipal& subject = unescaped_cert->subject(); 426 const CertPrincipal& subject = unescaped_cert->subject();
412 EXPECT_EQ("127.0.0.1", subject.common_name); 427 EXPECT_EQ("127.0.0.1", subject.common_name);
413 EXPECT_EQ("Mountain View", subject.locality_name); 428 EXPECT_EQ("Mountain View", subject.locality_name);
414 EXPECT_EQ("California", subject.state_or_province_name); 429 EXPECT_EQ("California", subject.state_or_province_name);
415 EXPECT_EQ("US", subject.country_name); 430 EXPECT_EQ("US", subject.country_name);
416 ASSERT_EQ(1U, subject.street_addresses.size()); 431 ASSERT_EQ(1U, subject.street_addresses.size());
417 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]); 432 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]);
418 ASSERT_EQ(1U, subject.organization_names.size()); 433 ASSERT_EQ(1U, subject.organization_names.size());
419 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]); 434 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]);
420 ASSERT_EQ(2U, subject.organization_unit_names.size()); 435 ASSERT_EQ(2U, subject.organization_unit_names.size());
421 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]); 436 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]);
422 EXPECT_EQ("Chromium", subject.organization_unit_names[1]); 437 EXPECT_EQ("Chromium", subject.organization_unit_names[1]);
423 EXPECT_EQ(0U, subject.domain_components.size()); 438 EXPECT_EQ(0U, subject.domain_components.size());
424 } 439 }
425 440
426 TEST(X509CertificateTest, PaypalNullCertParsing) { 441 TEST_F(X509CertificateTest, PaypalNullCertParsing) {
427 scoped_refptr<X509Certificate> paypal_null_cert( 442 scoped_refptr<X509Certificate> paypal_null_cert(
428 X509Certificate::CreateFromBytes( 443 X509Certificate::CreateFromBytes(
429 reinterpret_cast<const char*>(paypal_null_der), 444 reinterpret_cast<const char*>(paypal_null_der),
430 sizeof(paypal_null_der))); 445 sizeof(paypal_null_der)));
431 446
432 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); 447 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert);
433 448
434 const SHA1Fingerprint& fingerprint = 449 const SHA1Fingerprint& fingerprint =
435 paypal_null_cert->fingerprint(); 450 paypal_null_cert->fingerprint();
436 for (size_t i = 0; i < 20; ++i) 451 for (size_t i = 0; i < 20; ++i)
437 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); 452 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]);
438 453
439 int flags = 0; 454 int flags = 0;
440 CertVerifyResult verify_result; 455 CertVerifyResult verify_result;
441 int error = paypal_null_cert->Verify("www.paypal.com", flags, NULL, 456 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL,
442 &verify_result); 457 &verify_result);
443 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) 458 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN)
444 // TOOD(bulach): investigate why macosx and win aren't returning 459 // TOOD(bulach): investigate why macosx and win aren't returning
445 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. 460 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID.
446 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 461 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
447 #else 462 #else
448 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); 463 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
449 #endif 464 #endif
450 // Either the system crypto library should correctly report a certificate 465 // Either the system crypto library should correctly report a certificate
451 // name mismatch, or our certificate blacklist should cause us to report an 466 // name mismatch, or our certificate blacklist should cause us to report an
452 // invalid certificate. 467 // invalid certificate.
453 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) 468 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL)
454 EXPECT_TRUE(verify_result.cert_status & 469 EXPECT_TRUE(verify_result.cert_status &
455 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); 470 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID));
456 #endif 471 #endif
457 } 472 }
458 473
459 TEST(X509CertificateTest, SerialNumbers) { 474 TEST_F(X509CertificateTest, SerialNumbers) {
460 scoped_refptr<X509Certificate> google_cert( 475 scoped_refptr<X509Certificate> google_cert(
461 X509Certificate::CreateFromBytes( 476 X509Certificate::CreateFromBytes(
462 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 477 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
463 478
464 static const uint8 google_serial[16] = { 479 static const uint8 google_serial[16] = {
465 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, 480 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9,
466 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, 481 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a,
467 }; 482 };
468 483
469 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); 484 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size());
470 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, 485 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial,
471 sizeof(google_serial)) == 0); 486 sizeof(google_serial)) == 0);
472 487
473 // We also want to check a serial number where the first byte is >= 0x80 in 488 // We also want to check a serial number where the first byte is >= 0x80 in
474 // case the underlying library tries to pad it. 489 // case the underlying library tries to pad it.
475 scoped_refptr<X509Certificate> paypal_null_cert( 490 scoped_refptr<X509Certificate> paypal_null_cert(
476 X509Certificate::CreateFromBytes( 491 X509Certificate::CreateFromBytes(
477 reinterpret_cast<const char*>(paypal_null_der), 492 reinterpret_cast<const char*>(paypal_null_der),
478 sizeof(paypal_null_der))); 493 sizeof(paypal_null_der)));
479 494
480 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; 495 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b};
481 ASSERT_EQ(sizeof(paypal_null_serial), 496 ASSERT_EQ(sizeof(paypal_null_serial),
482 paypal_null_cert->serial_number().size()); 497 paypal_null_cert->serial_number().size());
483 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), 498 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(),
484 paypal_null_serial, sizeof(paypal_null_serial)) == 0); 499 paypal_null_serial, sizeof(paypal_null_serial)) == 0);
485 } 500 }
486 501
487 TEST(X509CertificateTest, CAFingerprints) { 502 TEST_F(X509CertificateTest, CAFingerprints) {
488 FilePath certs_dir = GetTestCertsDirectory(); 503 FilePath certs_dir = GetTestCertsDirectory();
489 504
490 scoped_refptr<X509Certificate> server_cert = 505 scoped_refptr<X509Certificate> server_cert =
491 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); 506 ImportCertFromFile(certs_dir, "salesforce_com_test.pem");
492 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 507 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
493 508
494 scoped_refptr<X509Certificate> intermediate_cert1 = 509 scoped_refptr<X509Certificate> intermediate_cert1 =
495 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); 510 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem");
496 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); 511 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1);
497 512
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data, 550 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data,
536 cert_chain2_ca_fingerprint, 20) == 0); 551 cert_chain2_ca_fingerprint, 20) == 0);
537 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data, 552 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data,
538 cert_chain3_ca_fingerprint, 20) == 0); 553 cert_chain3_ca_fingerprint, 20) == 0);
539 } 554 }
540 555
541 // A regression test for http://crbug.com/31497. 556 // A regression test for http://crbug.com/31497.
542 // This certificate will expire on 2012-04-08. The test will still 557 // This certificate will expire on 2012-04-08. The test will still
543 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test 558 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test
544 // certificates for this unit test. http://crbug.com/111742 559 // certificates for this unit test. http://crbug.com/111742
545 TEST(X509CertificateTest, IntermediateCARequireExplicitPolicy) { 560 TEST_F(X509CertificateTest, IntermediateCARequireExplicitPolicy) {
546 FilePath certs_dir = GetTestCertsDirectory(); 561 FilePath certs_dir = GetTestCertsDirectory();
547 562
548 scoped_refptr<X509Certificate> server_cert = 563 scoped_refptr<X509Certificate> server_cert =
549 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); 564 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der");
550 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 565 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
551 566
552 // The intermediate CA certificate's policyConstraints extension has a 567 // The intermediate CA certificate's policyConstraints extension has a
553 // requireExplicitPolicy field with SkipCerts=0. 568 // requireExplicitPolicy field with SkipCerts=0.
554 scoped_refptr<X509Certificate> intermediate_cert = 569 scoped_refptr<X509Certificate> intermediate_cert =
555 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); 570 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
556 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 571 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
557 572
558 scoped_refptr<X509Certificate> root_cert = 573 scoped_refptr<X509Certificate> root_cert =
559 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); 574 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
560 ScopedTestRoot scoped_root(root_cert); 575 ScopedTestRoot scoped_root(root_cert);
561 576
562 X509Certificate::OSCertHandles intermediates; 577 X509Certificate::OSCertHandles intermediates;
563 intermediates.push_back(intermediate_cert->os_cert_handle()); 578 intermediates.push_back(intermediate_cert->os_cert_handle());
564 scoped_refptr<X509Certificate> cert_chain = 579 scoped_refptr<X509Certificate> cert_chain =
565 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 580 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
566 intermediates); 581 intermediates);
567 582
568 int flags = 0; 583 int flags = 0;
569 CertVerifyResult verify_result; 584 CertVerifyResult verify_result;
570 int error = cert_chain->Verify("www.us.army.mil", flags, NULL, 585 int error = Verify(cert_chain, "www.us.army.mil", flags, NULL,
571 &verify_result); 586 &verify_result);
572 if (error == OK) { 587 if (error == OK) {
573 EXPECT_EQ(0U, verify_result.cert_status); 588 EXPECT_EQ(0U, verify_result.cert_status);
574 } else { 589 } else {
575 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 590 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
576 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); 591 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status);
577 } 592 }
578 } 593 }
579 594
580 // Test for bug 58437. 595 // Test for bug 58437.
581 // This certificate will expire on 2011-12-21. The test will still 596 // This certificate will expire on 2011-12-21. The test will still
582 // pass if error == ERR_CERT_DATE_INVALID. 597 // pass if error == ERR_CERT_DATE_INVALID.
583 // This test is DISABLED because it appears that we cannot do 598 // This test is DISABLED because it appears that we cannot do
584 // certificate revocation checking when running all of the net unit tests. 599 // certificate revocation checking when running all of the net unit tests.
585 // This test passes when run individually, but when run with all of the net 600 // This test passes when run individually, but when run with all of the net
586 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is 601 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is
587 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation 602 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation
588 // status, i.e. that the revocation check is failing for some reason. 603 // status, i.e. that the revocation check is failing for some reason.
589 TEST(X509CertificateTest, DISABLED_GlobalSignR3EVTest) { 604 TEST_F(X509CertificateTest, DISABLED_GlobalSignR3EVTest) {
590 FilePath certs_dir = GetTestCertsDirectory(); 605 FilePath certs_dir = GetTestCertsDirectory();
591 606
592 scoped_refptr<X509Certificate> server_cert = 607 scoped_refptr<X509Certificate> server_cert =
593 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); 608 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem");
594 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 609 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
595 610
596 scoped_refptr<X509Certificate> intermediate_cert = 611 scoped_refptr<X509Certificate> intermediate_cert =
597 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); 612 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem");
598 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 613 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
599 614
600 X509Certificate::OSCertHandles intermediates; 615 X509Certificate::OSCertHandles intermediates;
601 intermediates.push_back(intermediate_cert->os_cert_handle()); 616 intermediates.push_back(intermediate_cert->os_cert_handle());
602 scoped_refptr<X509Certificate> cert_chain = 617 scoped_refptr<X509Certificate> cert_chain =
603 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 618 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
604 intermediates); 619 intermediates);
605 620
606 CertVerifyResult verify_result; 621 CertVerifyResult verify_result;
607 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | 622 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
608 X509Certificate::VERIFY_EV_CERT; 623 X509Certificate::VERIFY_EV_CERT;
609 int error = cert_chain->Verify("2029.globalsign.com", flags, NULL, 624 int error = Verify(cert_chain, "2029.globalsign.com", flags, NULL,
610 &verify_result); 625 &verify_result);
611 if (error == OK) 626 if (error == OK)
612 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); 627 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
613 else 628 else
614 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 629 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
615 } 630 }
616 631
617 // Currently, only RSA and DSA keys are checked for weakness, and our example 632 // Currently, only RSA and DSA keys are checked for weakness, and our example
618 // weak size is 768. These could change in the future. 633 // weak size is 768. These could change in the future.
619 // 634 //
620 // Note that this means there may be false negatives: keys for other 635 // Note that this means there may be false negatives: keys for other
621 // algorithms and which are weak will pass this test. 636 // algorithms and which are weak will pass this test.
622 static bool IsWeakKeyType(const std::string& key_type) { 637 static bool IsWeakKeyType(const std::string& key_type) {
623 size_t pos = key_type.find("-"); 638 size_t pos = key_type.find("-");
624 std::string size = key_type.substr(0, pos); 639 std::string size = key_type.substr(0, pos);
625 std::string type = key_type.substr(pos + 1); 640 std::string type = key_type.substr(pos + 1);
626 641
627 if (type == "rsa" || type == "dsa") 642 if (type == "rsa" || type == "dsa")
628 return size == "768"; 643 return size == "768";
629 644
630 return false; 645 return false;
631 } 646 }
632 647
633 TEST(X509CertificateTest, RejectWeakKeys) { 648 TEST_F(X509CertificateTest, RejectWeakKeys) {
634 FilePath certs_dir = GetTestCertsDirectory(); 649 FilePath certs_dir = GetTestCertsDirectory();
635 typedef std::vector<std::string> Strings; 650 typedef std::vector<std::string> Strings;
636 Strings key_types; 651 Strings key_types;
637 652
638 // generate-weak-test-chains.sh currently has: 653 // generate-weak-test-chains.sh currently has:
639 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" 654 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa"
640 // We must use the same key types here. The filenames generated look like: 655 // We must use the same key types here. The filenames generated look like:
641 // 2048-rsa-ee-by-768-rsa-intermediate.pem 656 // 2048-rsa-ee-by-768-rsa-intermediate.pem
642 key_types.push_back("768-rsa"); 657 key_types.push_back("768-rsa");
643 key_types.push_back("1024-rsa"); 658 key_types.push_back("1024-rsa");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 ImportCertFromFile(certs_dir, basename); 691 ImportCertFromFile(certs_dir, basename);
677 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); 692 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate);
678 693
679 X509Certificate::OSCertHandles intermediates; 694 X509Certificate::OSCertHandles intermediates;
680 intermediates.push_back(intermediate->os_cert_handle()); 695 intermediates.push_back(intermediate->os_cert_handle());
681 scoped_refptr<X509Certificate> cert_chain = 696 scoped_refptr<X509Certificate> cert_chain =
682 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 697 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
683 intermediates); 698 intermediates);
684 699
685 CertVerifyResult verify_result; 700 CertVerifyResult verify_result;
686 int error = cert_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 701 int error = Verify(cert_chain, "127.0.0.1", 0, NULL, &verify_result);
687 702
688 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { 703 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) {
689 EXPECT_NE(OK, error); 704 EXPECT_NE(OK, error);
690 EXPECT_EQ(CERT_STATUS_WEAK_KEY, 705 EXPECT_EQ(CERT_STATUS_WEAK_KEY,
691 verify_result.cert_status & CERT_STATUS_WEAK_KEY); 706 verify_result.cert_status & CERT_STATUS_WEAK_KEY);
692 } else { 707 } else {
693 EXPECT_EQ(OK, error); 708 EXPECT_EQ(OK, error);
694 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); 709 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY);
695 } 710 }
696 } 711 }
697 } 712 }
698 } 713 }
699 714
700 // Test for bug 108514. 715 // Test for bug 108514.
701 // The certificate will expire on 2012-07-20. The test will still 716 // The certificate will expire on 2012-07-20. The test will still
702 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test 717 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test
703 // certificates for this unit test. http://crbug.com/111730 718 // certificates for this unit test. http://crbug.com/111730
704 TEST(X509CertificateTest, ExtraneousMD5RootCert) { 719 TEST_F(X509CertificateTest, ExtraneousMD5RootCert) {
705 FilePath certs_dir = GetTestCertsDirectory(); 720 FilePath certs_dir = GetTestCertsDirectory();
706 721
707 scoped_refptr<X509Certificate> server_cert = 722 scoped_refptr<X509Certificate> server_cert =
708 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); 723 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem");
709 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 724 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
710 725
711 scoped_refptr<X509Certificate> intermediate_cert = 726 scoped_refptr<X509Certificate> intermediate_cert =
712 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); 727 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem");
713 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 728 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
714 729
715 scoped_refptr<X509Certificate> md5_root_cert = 730 scoped_refptr<X509Certificate> md5_root_cert =
716 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); 731 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem");
717 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); 732 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert);
718 733
719 X509Certificate::OSCertHandles intermediates; 734 X509Certificate::OSCertHandles intermediates;
720 intermediates.push_back(intermediate_cert->os_cert_handle()); 735 intermediates.push_back(intermediate_cert->os_cert_handle());
721 intermediates.push_back(md5_root_cert->os_cert_handle()); 736 intermediates.push_back(md5_root_cert->os_cert_handle());
722 scoped_refptr<X509Certificate> cert_chain = 737 scoped_refptr<X509Certificate> cert_chain =
723 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 738 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
724 intermediates); 739 intermediates);
725 740
726 CertVerifyResult verify_result; 741 CertVerifyResult verify_result;
727 int flags = 0; 742 int flags = 0;
728 int error = cert_chain->Verify("images.etrade.wallst.com", flags, NULL, 743 int error = Verify(cert_chain, "images.etrade.wallst.com", flags, NULL,
729 &verify_result); 744 &verify_result);
730 if (error != OK) 745 if (error != OK)
731 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); 746 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
732 747
733 EXPECT_FALSE(verify_result.has_md5); 748 EXPECT_FALSE(verify_result.has_md5);
734 EXPECT_FALSE(verify_result.has_md5_ca); 749 EXPECT_FALSE(verify_result.has_md5_ca);
735 } 750 }
736 751
737 // Test for bug 94673. 752 // Test for bug 94673.
738 TEST(X509CertificateTest, GoogleDigiNotarTest) { 753 TEST_F(X509CertificateTest, GoogleDigiNotarTest) {
739 FilePath certs_dir = GetTestCertsDirectory(); 754 FilePath certs_dir = GetTestCertsDirectory();
740 755
741 scoped_refptr<X509Certificate> server_cert = 756 scoped_refptr<X509Certificate> server_cert =
742 ImportCertFromFile(certs_dir, "google_diginotar.pem"); 757 ImportCertFromFile(certs_dir, "google_diginotar.pem");
743 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 758 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
744 759
745 scoped_refptr<X509Certificate> intermediate_cert = 760 scoped_refptr<X509Certificate> intermediate_cert =
746 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); 761 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem");
747 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 762 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
748 763
749 X509Certificate::OSCertHandles intermediates; 764 X509Certificate::OSCertHandles intermediates;
750 intermediates.push_back(intermediate_cert->os_cert_handle()); 765 intermediates.push_back(intermediate_cert->os_cert_handle());
751 scoped_refptr<X509Certificate> cert_chain = 766 scoped_refptr<X509Certificate> cert_chain =
752 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 767 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
753 intermediates); 768 intermediates);
754 769
755 CertVerifyResult verify_result; 770 CertVerifyResult verify_result;
756 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; 771 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED;
757 int error = cert_chain->Verify("mail.google.com", flags, NULL, 772 int error = Verify(cert_chain, "mail.google.com", flags, NULL,
758 &verify_result); 773 &verify_result);
759 EXPECT_NE(OK, error); 774 EXPECT_NE(OK, error);
760 775
761 // Now turn off revocation checking. Certificate verification should still 776 // Now turn off revocation checking. Certificate verification should still
762 // fail. 777 // fail.
763 flags = 0; 778 flags = 0;
764 error = cert_chain->Verify("mail.google.com", flags, NULL, &verify_result); 779 error = Verify(cert_chain, "mail.google.com", flags, NULL, &verify_result);
765 EXPECT_NE(OK, error); 780 EXPECT_NE(OK, error);
766 } 781 }
767 782
768 TEST(X509CertificateTest, DigiNotarCerts) { 783 TEST_F(X509CertificateTest, DigiNotarCerts) {
769 static const char* const kDigiNotarFilenames[] = { 784 static const char* const kDigiNotarFilenames[] = {
770 "diginotar_root_ca.pem", 785 "diginotar_root_ca.pem",
771 "diginotar_cyber_ca.pem", 786 "diginotar_cyber_ca.pem",
772 "diginotar_services_1024_ca.pem", 787 "diginotar_services_1024_ca.pem",
773 "diginotar_pkioverheid.pem", 788 "diginotar_pkioverheid.pem",
774 "diginotar_pkioverheid_g2.pem", 789 "diginotar_pkioverheid_g2.pem",
775 NULL, 790 NULL,
776 }; 791 };
777 792
778 FilePath certs_dir = GetTestCertsDirectory(); 793 FilePath certs_dir = GetTestCertsDirectory();
(...skipping 15 matching lines...) Expand all
794 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); 809 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size());
795 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); 810 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size());
796 public_keys.push_back(fingerprint); 811 public_keys.push_back(fingerprint);
797 812
798 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) << 813 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) <<
799 "Public key not blocked for " << kDigiNotarFilenames[i]; 814 "Public key not blocked for " << kDigiNotarFilenames[i];
800 } 815 }
801 } 816 }
802 817
803 // Bug 111893: This test needs a new certificate. 818 // Bug 111893: This test needs a new certificate.
804 TEST(X509CertificateTest, DISABLED_TestKnownRoot) { 819 TEST_F(X509CertificateTest, DISABLED_TestKnownRoot) {
805 FilePath certs_dir = GetTestCertsDirectory(); 820 FilePath certs_dir = GetTestCertsDirectory();
806 scoped_refptr<X509Certificate> cert = 821 scoped_refptr<X509Certificate> cert =
807 ImportCertFromFile(certs_dir, "nist.der"); 822 ImportCertFromFile(certs_dir, "nist.der");
808 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 823 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
809 824
810 // This intermediate is only needed for old Linux machines. Modern NSS 825 // This intermediate is only needed for old Linux machines. Modern NSS
811 // includes it as a root already. 826 // includes it as a root already.
812 scoped_refptr<X509Certificate> intermediate_cert = 827 scoped_refptr<X509Certificate> intermediate_cert =
813 ImportCertFromFile(certs_dir, "nist_intermediate.der"); 828 ImportCertFromFile(certs_dir, "nist_intermediate.der");
814 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 829 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
815 830
816 X509Certificate::OSCertHandles intermediates; 831 X509Certificate::OSCertHandles intermediates;
817 intermediates.push_back(intermediate_cert->os_cert_handle()); 832 intermediates.push_back(intermediate_cert->os_cert_handle());
818 scoped_refptr<X509Certificate> cert_chain = 833 scoped_refptr<X509Certificate> cert_chain =
819 X509Certificate::CreateFromHandle(cert->os_cert_handle(), 834 X509Certificate::CreateFromHandle(cert->os_cert_handle(),
820 intermediates); 835 intermediates);
821 836
822 int flags = 0; 837 int flags = 0;
823 CertVerifyResult verify_result; 838 CertVerifyResult verify_result;
824 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug 839 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug
825 // against agl. Also see PublicKeyHashes in this file. 840 // against agl. Also see PublicKeyHashes in this file.
826 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); 841 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result);
827 EXPECT_EQ(OK, error); 842 EXPECT_EQ(OK, error);
828 EXPECT_EQ(0U, verify_result.cert_status); 843 EXPECT_EQ(0U, verify_result.cert_status);
829 EXPECT_TRUE(verify_result.is_issued_by_known_root); 844 EXPECT_TRUE(verify_result.is_issued_by_known_root);
830 } 845 }
831 846
832 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der. 847 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der.
833 static const char nistSPKIHash[] = 848 static const char nistSPKIHash[] =
834 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82" 849 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82"
835 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35"; 850 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35";
836 851
837 TEST(X509CertificateTest, ExtractSPKIFromDERCert) { 852 TEST_F(X509CertificateTest, ExtractSPKIFromDERCert) {
838 FilePath certs_dir = GetTestCertsDirectory(); 853 FilePath certs_dir = GetTestCertsDirectory();
839 scoped_refptr<X509Certificate> cert = 854 scoped_refptr<X509Certificate> cert =
840 ImportCertFromFile(certs_dir, "nist.der"); 855 ImportCertFromFile(certs_dir, "nist.der");
841 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 856 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
842 857
843 std::string derBytes; 858 std::string derBytes;
844 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 859 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
845 &derBytes)); 860 &derBytes));
846 861
847 base::StringPiece spkiBytes; 862 base::StringPiece spkiBytes;
848 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); 863 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes));
849 864
850 uint8 hash[base::kSHA1Length]; 865 uint8 hash[base::kSHA1Length];
851 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), 866 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()),
852 spkiBytes.size(), hash); 867 spkiBytes.size(), hash);
853 868
854 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash))); 869 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash)));
855 } 870 }
856 871
857 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) { 872 TEST_F(X509CertificateTest, ExtractCRLURLsFromDERCert) {
858 FilePath certs_dir = GetTestCertsDirectory(); 873 FilePath certs_dir = GetTestCertsDirectory();
859 scoped_refptr<X509Certificate> cert = 874 scoped_refptr<X509Certificate> cert =
860 ImportCertFromFile(certs_dir, "nist.der"); 875 ImportCertFromFile(certs_dir, "nist.der");
861 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 876 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
862 877
863 std::string derBytes; 878 std::string derBytes;
864 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 879 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
865 &derBytes)); 880 &derBytes));
866 881
867 std::vector<base::StringPiece> crl_urls; 882 std::vector<base::StringPiece> crl_urls;
868 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); 883 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls));
869 884
870 EXPECT_EQ(1u, crl_urls.size()); 885 EXPECT_EQ(1u, crl_urls.size());
871 if (crl_urls.size() > 0) { 886 if (crl_urls.size() > 0) {
872 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", 887 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl",
873 crl_urls[0].as_string()); 888 crl_urls[0].as_string());
874 } 889 }
875 } 890 }
876 891
877 // Bug 111893: This test needs a new certificate. 892 // Bug 111893: This test needs a new certificate.
878 TEST(X509CertificateTest, DISABLED_PublicKeyHashes) { 893 TEST_F(X509CertificateTest, DISABLED_PublicKeyHashes) {
879 FilePath certs_dir = GetTestCertsDirectory(); 894 FilePath certs_dir = GetTestCertsDirectory();
880 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug 895 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug
881 // against agl. Also see TestKnownRoot in this file. 896 // against agl. Also see TestKnownRoot in this file.
882 scoped_refptr<X509Certificate> cert = 897 scoped_refptr<X509Certificate> cert =
883 ImportCertFromFile(certs_dir, "nist.der"); 898 ImportCertFromFile(certs_dir, "nist.der");
884 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 899 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
885 900
886 // This intermediate is only needed for old Linux machines. Modern NSS 901 // This intermediate is only needed for old Linux machines. Modern NSS
887 // includes it as a root already. 902 // includes it as a root already.
888 scoped_refptr<X509Certificate> intermediate_cert = 903 scoped_refptr<X509Certificate> intermediate_cert =
889 ImportCertFromFile(certs_dir, "nist_intermediate.der"); 904 ImportCertFromFile(certs_dir, "nist_intermediate.der");
890 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 905 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
891 906
892 ScopedTestRoot scoped_intermediate(intermediate_cert); 907 ScopedTestRoot scoped_intermediate(intermediate_cert);
893 908
894 X509Certificate::OSCertHandles intermediates; 909 X509Certificate::OSCertHandles intermediates;
895 intermediates.push_back(intermediate_cert->os_cert_handle()); 910 intermediates.push_back(intermediate_cert->os_cert_handle());
896 scoped_refptr<X509Certificate> cert_chain = 911 scoped_refptr<X509Certificate> cert_chain =
897 X509Certificate::CreateFromHandle(cert->os_cert_handle(), 912 X509Certificate::CreateFromHandle(cert->os_cert_handle(),
898 intermediates); 913 intermediates);
899 914
900 int flags = 0; 915 int flags = 0;
901 CertVerifyResult verify_result; 916 CertVerifyResult verify_result;
902 917
903 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); 918 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result);
904 EXPECT_EQ(OK, error); 919 EXPECT_EQ(OK, error);
905 EXPECT_EQ(0U, verify_result.cert_status); 920 EXPECT_EQ(0U, verify_result.cert_status);
906 ASSERT_LE(2u, verify_result.public_key_hashes.size()); 921 ASSERT_LE(2u, verify_result.public_key_hashes.size());
907 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), 922 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length),
908 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); 923 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length));
909 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", 924 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD",
910 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); 925 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length));
911 } 926 }
912 927
913 // A regression test for http://crbug.com/70293. 928 // A regression test for http://crbug.com/70293.
914 // The Key Usage extension in this RSA SSL server certificate does not have 929 // The Key Usage extension in this RSA SSL server certificate does not have
915 // the keyEncipherment bit. 930 // the keyEncipherment bit.
916 TEST(X509CertificateTest, InvalidKeyUsage) { 931 TEST_F(X509CertificateTest, InvalidKeyUsage) {
917 FilePath certs_dir = GetTestCertsDirectory(); 932 FilePath certs_dir = GetTestCertsDirectory();
918 933
919 scoped_refptr<X509Certificate> server_cert = 934 scoped_refptr<X509Certificate> server_cert =
920 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); 935 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der");
921 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 936 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
922 937
923 int flags = 0; 938 int flags = 0;
924 CertVerifyResult verify_result; 939 CertVerifyResult verify_result;
925 int error = server_cert->Verify("jira.aquameta.com", flags, NULL, 940 int error = Verify(server_cert, "jira.aquameta.com", flags, NULL,
926 &verify_result); 941 &verify_result);
927 #if defined(USE_OPENSSL) 942 #if defined(USE_OPENSSL)
928 // This certificate has two errors: "invalid key usage" and "untrusted CA". 943 // This certificate has two errors: "invalid key usage" and "untrusted CA".
929 // However, OpenSSL returns only one (the latter), and we can't detect 944 // However, OpenSSL returns only one (the latter), and we can't detect
930 // the other errors. 945 // the other errors.
931 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); 946 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
932 #else 947 #else
933 EXPECT_EQ(ERR_CERT_INVALID, error); 948 EXPECT_EQ(ERR_CERT_INVALID, error);
934 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 949 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
935 #endif 950 #endif
936 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors 951 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors
937 // from NSS. 952 // from NSS.
938 #if !defined(USE_NSS) 953 #if !defined(USE_NSS)
939 // The certificate is issued by an unknown CA. 954 // The certificate is issued by an unknown CA.
940 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); 955 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
941 #endif 956 #endif
942 } 957 }
943 958
944 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We 959 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We
945 // call X509Certificate::CreateFromHandle several times and observe whether 960 // call X509Certificate::CreateFromHandle several times and observe whether
946 // it returns a cached or new OSCertHandle. 961 // it returns a cached or new OSCertHandle.
947 TEST(X509CertificateTest, Cache) { 962 TEST_F(X509CertificateTest, Cache) {
948 X509Certificate::OSCertHandle google_cert_handle; 963 X509Certificate::OSCertHandle google_cert_handle;
949 X509Certificate::OSCertHandle thawte_cert_handle; 964 X509Certificate::OSCertHandle thawte_cert_handle;
950 965
951 // Add a single certificate to the certificate cache. 966 // Add a single certificate to the certificate cache.
952 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( 967 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes(
953 reinterpret_cast<const char*>(google_der), sizeof(google_der)); 968 reinterpret_cast<const char*>(google_der), sizeof(google_der));
954 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( 969 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle(
955 google_cert_handle, X509Certificate::OSCertHandles())); 970 google_cert_handle, X509Certificate::OSCertHandles()));
956 X509Certificate::FreeOSCertHandle(google_cert_handle); 971 X509Certificate::FreeOSCertHandle(google_cert_handle);
957 972
(...skipping 26 matching lines...) Expand all
984 X509Certificate::FreeOSCertHandle(thawte_cert_handle); 999 X509Certificate::FreeOSCertHandle(thawte_cert_handle);
985 1000
986 // Test that the new certificate, even with intermediates, results in the 1001 // Test that the new certificate, even with intermediates, results in the
987 // same underlying handle being used. 1002 // same underlying handle being used.
988 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle()); 1003 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle());
989 // Though they use the same OS handle, the intermediates should be different. 1004 // Though they use the same OS handle, the intermediates should be different.
990 EXPECT_NE(cert1->GetIntermediateCertificates().size(), 1005 EXPECT_NE(cert1->GetIntermediateCertificates().size(),
991 cert3->GetIntermediateCertificates().size()); 1006 cert3->GetIntermediateCertificates().size());
992 } 1007 }
993 1008
994 TEST(X509CertificateTest, Pickle) { 1009 TEST_F(X509CertificateTest, Pickle) {
995 X509Certificate::OSCertHandle google_cert_handle = 1010 X509Certificate::OSCertHandle google_cert_handle =
996 X509Certificate::CreateOSCertHandleFromBytes( 1011 X509Certificate::CreateOSCertHandleFromBytes(
997 reinterpret_cast<const char*>(google_der), sizeof(google_der)); 1012 reinterpret_cast<const char*>(google_der), sizeof(google_der));
998 X509Certificate::OSCertHandle thawte_cert_handle = 1013 X509Certificate::OSCertHandle thawte_cert_handle =
999 X509Certificate::CreateOSCertHandleFromBytes( 1014 X509Certificate::CreateOSCertHandleFromBytes(
1000 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); 1015 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der));
1001 1016
1002 X509Certificate::OSCertHandles intermediates; 1017 X509Certificate::OSCertHandles intermediates;
1003 intermediates.push_back(thawte_cert_handle); 1018 intermediates.push_back(thawte_cert_handle);
1004 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( 1019 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
(...skipping 17 matching lines...) Expand all
1022 cert->GetIntermediateCertificates(); 1037 cert->GetIntermediateCertificates();
1023 const X509Certificate::OSCertHandles& pickle_intermediates = 1038 const X509Certificate::OSCertHandles& pickle_intermediates =
1024 cert_from_pickle->GetIntermediateCertificates(); 1039 cert_from_pickle->GetIntermediateCertificates();
1025 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size()); 1040 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size());
1026 for (size_t i = 0; i < cert_intermediates.size(); ++i) { 1041 for (size_t i = 0; i < cert_intermediates.size(); ++i) {
1027 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i], 1042 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i],
1028 pickle_intermediates[i])); 1043 pickle_intermediates[i]));
1029 } 1044 }
1030 } 1045 }
1031 1046
1032 TEST(X509CertificateTest, Policy) { 1047 TEST_F(X509CertificateTest, Policy) {
1033 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( 1048 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes(
1034 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 1049 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
1035 1050
1036 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( 1051 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes(
1037 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 1052 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
1038 1053
1039 CertPolicy policy; 1054 CertPolicy policy;
1040 1055
1041 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); 1056 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN);
1042 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); 1057 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN);
(...skipping 15 matching lines...) Expand all
1058 EXPECT_TRUE(policy.HasDeniedCert()); 1073 EXPECT_TRUE(policy.HasDeniedCert());
1059 1074
1060 policy.Allow(webkit_cert.get()); 1075 policy.Allow(webkit_cert.get());
1061 1076
1062 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); 1077 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED);
1063 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); 1078 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED);
1064 EXPECT_TRUE(policy.HasAllowedCert()); 1079 EXPECT_TRUE(policy.HasAllowedCert());
1065 EXPECT_TRUE(policy.HasDeniedCert()); 1080 EXPECT_TRUE(policy.HasDeniedCert());
1066 } 1081 }
1067 1082
1068 TEST(X509CertificateTest, IntermediateCertificates) { 1083 TEST_F(X509CertificateTest, IntermediateCertificates) {
1069 scoped_refptr<X509Certificate> webkit_cert( 1084 scoped_refptr<X509Certificate> webkit_cert(
1070 X509Certificate::CreateFromBytes( 1085 X509Certificate::CreateFromBytes(
1071 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 1086 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
1072 1087
1073 scoped_refptr<X509Certificate> thawte_cert( 1088 scoped_refptr<X509Certificate> thawte_cert(
1074 X509Certificate::CreateFromBytes( 1089 X509Certificate::CreateFromBytes(
1075 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); 1090 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)));
1076 1091
1077 X509Certificate::OSCertHandle google_handle; 1092 X509Certificate::OSCertHandle google_handle;
1078 // Create object with no intermediates: 1093 // Create object with no intermediates:
(...skipping 23 matching lines...) Expand all
1102 // Cleanup 1117 // Cleanup
1103 X509Certificate::FreeOSCertHandle(google_handle); 1118 X509Certificate::FreeOSCertHandle(google_handle);
1104 } 1119 }
1105 1120
1106 // Basic test for returning the chain in CertVerifyResult. Note that the 1121 // Basic test for returning the chain in CertVerifyResult. Note that the
1107 // returned chain may just be a reflection of the originally supplied chain; 1122 // returned chain may just be a reflection of the originally supplied chain;
1108 // that is, if any errors occur, the default chain returned is an exact copy 1123 // that is, if any errors occur, the default chain returned is an exact copy
1109 // of the certificate to be verified. The remaining VerifyReturn* tests are 1124 // of the certificate to be verified. The remaining VerifyReturn* tests are
1110 // used to ensure that the actual, verified chain is being returned by 1125 // used to ensure that the actual, verified chain is being returned by
1111 // Verify(). 1126 // Verify().
1112 TEST(X509CertificateTest, VerifyReturnChainBasic) { 1127 TEST_F(X509CertificateTest, VerifyReturnChainBasic) {
1113 FilePath certs_dir = GetTestCertsDirectory(); 1128 FilePath certs_dir = GetTestCertsDirectory();
1114 CertificateList certs = CreateCertificateListFromFile( 1129 CertificateList certs = CreateCertificateListFromFile(
1115 certs_dir, "x509_verify_results.chain.pem", 1130 certs_dir, "x509_verify_results.chain.pem",
1116 X509Certificate::FORMAT_AUTO); 1131 X509Certificate::FORMAT_AUTO);
1117 ASSERT_EQ(3U, certs.size()); 1132 ASSERT_EQ(3U, certs.size());
1118 1133
1119 X509Certificate::OSCertHandles intermediates; 1134 X509Certificate::OSCertHandles intermediates;
1120 intermediates.push_back(certs[1]->os_cert_handle()); 1135 intermediates.push_back(certs[1]->os_cert_handle());
1121 intermediates.push_back(certs[2]->os_cert_handle()); 1136 intermediates.push_back(certs[2]->os_cert_handle());
1122 1137
1123 ScopedTestRoot scoped_root(certs[2]); 1138 ScopedTestRoot scoped_root(certs[2]);
1124 1139
1125 scoped_refptr<X509Certificate> google_full_chain = 1140 scoped_refptr<X509Certificate> google_full_chain =
1126 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1141 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1127 intermediates); 1142 intermediates);
1128 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); 1143 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1129 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); 1144 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1130 1145
1131 CertVerifyResult verify_result; 1146 CertVerifyResult verify_result;
1132 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 1147 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1133 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 1148 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1134 EXPECT_EQ(OK, error); 1149 EXPECT_EQ(OK, error);
1135 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 1150 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1136 1151
1137 EXPECT_NE(google_full_chain, verify_result.verified_cert); 1152 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1138 EXPECT_TRUE(X509Certificate::IsSameOSCert( 1153 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1139 google_full_chain->os_cert_handle(), 1154 google_full_chain->os_cert_handle(),
1140 verify_result.verified_cert->os_cert_handle())); 1155 verify_result.verified_cert->os_cert_handle()));
1141 const X509Certificate::OSCertHandles& return_intermediates = 1156 const X509Certificate::OSCertHandles& return_intermediates =
1142 verify_result.verified_cert->GetIntermediateCertificates(); 1157 verify_result.verified_cert->GetIntermediateCertificates();
1143 ASSERT_EQ(2U, return_intermediates.size()); 1158 ASSERT_EQ(2U, return_intermediates.size());
1144 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 1159 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1145 certs[1]->os_cert_handle())); 1160 certs[1]->os_cert_handle()));
1146 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 1161 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1147 certs[2]->os_cert_handle())); 1162 certs[2]->os_cert_handle()));
1148 } 1163 }
1149 1164
1150 // Test that the certificate returned in CertVerifyResult is able to reorder 1165 // Test that the certificate returned in CertVerifyResult is able to reorder
1151 // certificates that are not ordered from end-entity to root. While this is 1166 // certificates that are not ordered from end-entity to root. While this is
1152 // a protocol violation if sent during a TLS handshake, if multiple sources 1167 // a protocol violation if sent during a TLS handshake, if multiple sources
1153 // of intermediate certificates are combined, it's possible that order may 1168 // of intermediate certificates are combined, it's possible that order may
1154 // not be maintained. 1169 // not be maintained.
1155 TEST(X509CertificateTest, VerifyReturnChainProperlyOrdered) { 1170 TEST_F(X509CertificateTest, VerifyReturnChainProperlyOrdered) {
1156 FilePath certs_dir = GetTestCertsDirectory(); 1171 FilePath certs_dir = GetTestCertsDirectory();
1157 CertificateList certs = CreateCertificateListFromFile( 1172 CertificateList certs = CreateCertificateListFromFile(
1158 certs_dir, "x509_verify_results.chain.pem", 1173 certs_dir, "x509_verify_results.chain.pem",
1159 X509Certificate::FORMAT_AUTO); 1174 X509Certificate::FORMAT_AUTO);
1160 ASSERT_EQ(3U, certs.size()); 1175 ASSERT_EQ(3U, certs.size());
1161 1176
1162 // Construct the chain out of order. 1177 // Construct the chain out of order.
1163 X509Certificate::OSCertHandles intermediates; 1178 X509Certificate::OSCertHandles intermediates;
1164 intermediates.push_back(certs[2]->os_cert_handle()); 1179 intermediates.push_back(certs[2]->os_cert_handle());
1165 intermediates.push_back(certs[1]->os_cert_handle()); 1180 intermediates.push_back(certs[1]->os_cert_handle());
1166 1181
1167 ScopedTestRoot scoped_root(certs[2]); 1182 ScopedTestRoot scoped_root(certs[2]);
1168 1183
1169 scoped_refptr<X509Certificate> google_full_chain = 1184 scoped_refptr<X509Certificate> google_full_chain =
1170 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1185 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1171 intermediates); 1186 intermediates);
1172 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); 1187 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1173 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); 1188 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1174 1189
1175 CertVerifyResult verify_result; 1190 CertVerifyResult verify_result;
1176 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 1191 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1177 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 1192 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1178 EXPECT_EQ(OK, error); 1193 EXPECT_EQ(OK, error);
1179 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 1194 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1180 1195
1181 EXPECT_NE(google_full_chain, verify_result.verified_cert); 1196 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1182 EXPECT_TRUE(X509Certificate::IsSameOSCert( 1197 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1183 google_full_chain->os_cert_handle(), 1198 google_full_chain->os_cert_handle(),
1184 verify_result.verified_cert->os_cert_handle())); 1199 verify_result.verified_cert->os_cert_handle()));
1185 const X509Certificate::OSCertHandles& return_intermediates = 1200 const X509Certificate::OSCertHandles& return_intermediates =
1186 verify_result.verified_cert->GetIntermediateCertificates(); 1201 verify_result.verified_cert->GetIntermediateCertificates();
1187 ASSERT_EQ(2U, return_intermediates.size()); 1202 ASSERT_EQ(2U, return_intermediates.size());
1188 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 1203 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1189 certs[1]->os_cert_handle())); 1204 certs[1]->os_cert_handle()));
1190 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 1205 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1191 certs[2]->os_cert_handle())); 1206 certs[2]->os_cert_handle()));
1192 } 1207 }
1193 1208
1194 // Test that Verify() filters out certificates which are not related to 1209 // Test that Verify() filters out certificates which are not related to
1195 // or part of the certificate chain being verified. 1210 // or part of the certificate chain being verified.
1196 TEST(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) { 1211 TEST_F(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) {
1197 FilePath certs_dir = GetTestCertsDirectory(); 1212 FilePath certs_dir = GetTestCertsDirectory();
1198 CertificateList certs = CreateCertificateListFromFile( 1213 CertificateList certs = CreateCertificateListFromFile(
1199 certs_dir, "x509_verify_results.chain.pem", 1214 certs_dir, "x509_verify_results.chain.pem",
1200 X509Certificate::FORMAT_AUTO); 1215 X509Certificate::FORMAT_AUTO);
1201 ASSERT_EQ(3U, certs.size()); 1216 ASSERT_EQ(3U, certs.size());
1202 ScopedTestRoot scoped_root(certs[2]); 1217 ScopedTestRoot scoped_root(certs[2]);
1203 1218
1204 scoped_refptr<X509Certificate> unrelated_dod_certificate = 1219 scoped_refptr<X509Certificate> unrelated_dod_certificate =
1205 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); 1220 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
1206 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = 1221 scoped_refptr<X509Certificate> unrelated_dod_certificate2 =
1207 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); 1222 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
1208 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); 1223 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate);
1209 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); 1224 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2);
1210 1225
1211 // Interject unrelated certificates into the list of intermediates. 1226 // Interject unrelated certificates into the list of intermediates.
1212 X509Certificate::OSCertHandles intermediates; 1227 X509Certificate::OSCertHandles intermediates;
1213 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); 1228 intermediates.push_back(unrelated_dod_certificate->os_cert_handle());
1214 intermediates.push_back(certs[1]->os_cert_handle()); 1229 intermediates.push_back(certs[1]->os_cert_handle());
1215 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); 1230 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle());
1216 intermediates.push_back(certs[2]->os_cert_handle()); 1231 intermediates.push_back(certs[2]->os_cert_handle());
1217 1232
1218 scoped_refptr<X509Certificate> google_full_chain = 1233 scoped_refptr<X509Certificate> google_full_chain =
1219 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1234 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1220 intermediates); 1235 intermediates);
1221 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); 1236 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1222 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); 1237 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size());
1223 1238
1224 CertVerifyResult verify_result; 1239 CertVerifyResult verify_result;
1225 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 1240 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1226 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); 1241 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1227 EXPECT_EQ(OK, error); 1242 EXPECT_EQ(OK, error);
1228 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); 1243 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1229 1244
1230 EXPECT_NE(google_full_chain, verify_result.verified_cert); 1245 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1231 EXPECT_TRUE(X509Certificate::IsSameOSCert( 1246 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1232 google_full_chain->os_cert_handle(), 1247 google_full_chain->os_cert_handle(),
1233 verify_result.verified_cert->os_cert_handle())); 1248 verify_result.verified_cert->os_cert_handle()));
1234 const X509Certificate::OSCertHandles& return_intermediates = 1249 const X509Certificate::OSCertHandles& return_intermediates =
1235 verify_result.verified_cert->GetIntermediateCertificates(); 1250 verify_result.verified_cert->GetIntermediateCertificates();
1236 ASSERT_EQ(2U, return_intermediates.size()); 1251 ASSERT_EQ(2U, return_intermediates.size());
1237 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 1252 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1238 certs[1]->os_cert_handle())); 1253 certs[1]->os_cert_handle()));
1239 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 1254 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1240 certs[2]->os_cert_handle())); 1255 certs[2]->os_cert_handle()));
1241 } 1256 }
1242 1257
1243 #if defined(OS_MACOSX) 1258 #if defined(OS_MACOSX)
1244 TEST(X509CertificateTest, IsIssuedBy) { 1259 TEST_F(X509CertificateTest, IsIssuedBy) {
1245 FilePath certs_dir = GetTestCertsDirectory(); 1260 FilePath certs_dir = GetTestCertsDirectory();
1246 1261
1247 // Test a client certificate from MIT. 1262 // Test a client certificate from MIT.
1248 scoped_refptr<X509Certificate> mit_davidben_cert( 1263 scoped_refptr<X509Certificate> mit_davidben_cert(
1249 ImportCertFromFile(certs_dir, "mit.davidben.der")); 1264 ImportCertFromFile(certs_dir, "mit.davidben.der"));
1250 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); 1265 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert);
1251 1266
1252 CertPrincipal mit_issuer; 1267 CertPrincipal mit_issuer;
1253 mit_issuer.country_name = "US"; 1268 mit_issuer.country_name = "US";
1254 mit_issuer.state_or_province_name = "Massachusetts"; 1269 mit_issuer.state_or_province_name = "Massachusetts";
(...skipping 28 matching lines...) Expand all
1283 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); 1298 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers));
1284 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 1299 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
1285 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 1300 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
1286 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 1301 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
1287 } 1302 }
1288 #endif // defined(OS_MACOSX) 1303 #endif // defined(OS_MACOSX)
1289 1304
1290 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 1305 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
1291 // This test creates a self-signed cert from a private key and then verify the 1306 // This test creates a self-signed cert from a private key and then verify the
1292 // content of the certificate. 1307 // content of the certificate.
1293 TEST(X509CertificateTest, CreateSelfSigned) { 1308 TEST_F(X509CertificateTest, CreateSelfSigned) {
1294 scoped_ptr<crypto::RSAPrivateKey> private_key( 1309 scoped_ptr<crypto::RSAPrivateKey> private_key(
1295 crypto::RSAPrivateKey::Create(1024)); 1310 crypto::RSAPrivateKey::Create(1024));
1296 scoped_refptr<X509Certificate> cert = 1311 scoped_refptr<X509Certificate> cert =
1297 X509Certificate::CreateSelfSigned( 1312 X509Certificate::CreateSelfSigned(
1298 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 1313 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
1299 1314
1300 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 1315 EXPECT_EQ("subject", cert->subject().GetDisplayName());
1301 EXPECT_FALSE(cert->HasExpired()); 1316 EXPECT_FALSE(cert->HasExpired());
1302 1317
1303 const uint8 private_key_info[] = { 1318 const uint8 private_key_info[] = {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); 1405 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
1391 ASSERT_TRUE(private_key.get()); 1406 ASSERT_TRUE(private_key.get());
1392 1407
1393 cert = X509Certificate::CreateSelfSigned( 1408 cert = X509Certificate::CreateSelfSigned(
1394 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 1409 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
1395 1410
1396 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 1411 EXPECT_EQ("subject", cert->subject().GetDisplayName());
1397 EXPECT_FALSE(cert->HasExpired()); 1412 EXPECT_FALSE(cert->HasExpired());
1398 } 1413 }
1399 1414
1400 TEST(X509CertificateTest, GetDEREncoded) { 1415 TEST_F(X509CertificateTest, GetDEREncoded) {
1401 scoped_ptr<crypto::RSAPrivateKey> private_key( 1416 scoped_ptr<crypto::RSAPrivateKey> private_key(
1402 crypto::RSAPrivateKey::Create(1024)); 1417 crypto::RSAPrivateKey::Create(1024));
1403 scoped_refptr<X509Certificate> cert = 1418 scoped_refptr<X509Certificate> cert =
1404 X509Certificate::CreateSelfSigned( 1419 X509Certificate::CreateSelfSigned(
1405 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 1420 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
1406 1421
1407 std::string der_cert; 1422 std::string der_cert;
1408 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 1423 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
1409 &der_cert)); 1424 &der_cert));
1410 EXPECT_FALSE(der_cert.empty()); 1425 EXPECT_FALSE(der_cert.empty());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, 1470 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1456 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, 1471 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7,
1457 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, 1472 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52,
1458 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, 1473 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5,
1459 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, 1474 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b,
1460 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, 1475 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d,
1461 }; 1476 };
1462 1477
1463 // Test that CRLSets are effective in making a certificate appear to be 1478 // Test that CRLSets are effective in making a certificate appear to be
1464 // revoked. 1479 // revoked.
1465 TEST(X509CertificateTest, CRLSet) { 1480 TEST_F(X509CertificateTest, CRLSet) {
1466 CertificateList certs = CreateCertificateListFromFile( 1481 CertificateList certs = CreateCertificateListFromFile(
1467 GetTestCertsDirectory(), 1482 GetTestCertsDirectory(),
1468 "googlenew.chain.pem", 1483 "googlenew.chain.pem",
1469 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 1484 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
1470 1485
1471 X509Certificate::OSCertHandles intermediates; 1486 X509Certificate::OSCertHandles intermediates;
1472 intermediates.push_back(certs[1]->os_cert_handle()); 1487 intermediates.push_back(certs[1]->os_cert_handle());
1473 1488
1474 scoped_refptr<X509Certificate> google_full_chain = 1489 scoped_refptr<X509Certificate> google_full_chain =
1475 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1490 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1476 intermediates); 1491 intermediates);
1477 1492
1478 CertVerifyResult verify_result; 1493 CertVerifyResult verify_result;
1479 int error = google_full_chain->Verify( 1494 int error = Verify(google_full_chain, "www.google.com", 0, NULL,
1480 "www.google.com", 0, NULL, &verify_result); 1495 &verify_result);
1481 EXPECT_EQ(OK, error); 1496 EXPECT_EQ(OK, error);
1482 1497
1483 // First test blocking by SPKI. 1498 // First test blocking by SPKI.
1484 base::StringPiece crl_set_bytes( 1499 base::StringPiece crl_set_bytes(
1485 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), 1500 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked),
1486 sizeof(kCRLSetThawteSPKIBlocked)); 1501 sizeof(kCRLSetThawteSPKIBlocked));
1487 scoped_refptr<CRLSet> crl_set; 1502 scoped_refptr<CRLSet> crl_set;
1488 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); 1503 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1489 1504
1490 error = google_full_chain->Verify( 1505 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1491 "www.google.com", 0, crl_set.get(), &verify_result); 1506 &verify_result);
1492 EXPECT_EQ(ERR_CERT_REVOKED, error); 1507 EXPECT_EQ(ERR_CERT_REVOKED, error);
1493 1508
1494 // Second, test revocation by serial number of a cert directly under the 1509 // Second, test revocation by serial number of a cert directly under the
1495 // root. 1510 // root.
1496 crl_set_bytes = base::StringPiece( 1511 crl_set_bytes = base::StringPiece(
1497 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), 1512 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked),
1498 sizeof(kCRLSetThawteSerialBlocked)); 1513 sizeof(kCRLSetThawteSerialBlocked));
1499 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); 1514 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1500 1515
1501 error = google_full_chain->Verify( 1516 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1502 "www.google.com", 0, crl_set.get(), &verify_result); 1517 &verify_result);
1503 EXPECT_EQ(ERR_CERT_REVOKED, error); 1518 EXPECT_EQ(ERR_CERT_REVOKED, error);
1504 1519
1505 // Lastly, test revocation by serial number of a certificate not under the 1520 // Lastly, test revocation by serial number of a certificate not under the
1506 // root. 1521 // root.
1507 crl_set_bytes = base::StringPiece( 1522 crl_set_bytes = base::StringPiece(
1508 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), 1523 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked),
1509 sizeof(kCRLSetGoogleSerialBlocked)); 1524 sizeof(kCRLSetGoogleSerialBlocked));
1510 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); 1525 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1511 1526
1512 error = google_full_chain->Verify( 1527 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1513 "www.google.com", 0, crl_set.get(), &verify_result); 1528 &verify_result);
1514 EXPECT_EQ(ERR_CERT_REVOKED, error); 1529 EXPECT_EQ(ERR_CERT_REVOKED, error);
1515 } 1530 }
1516 #endif 1531 #endif
1517 1532
1518 class X509CertificateParseTest 1533 class X509CertificateParseTest
1519 : public testing::TestWithParam<CertificateFormatTestData> { 1534 : public testing::TestWithParam<CertificateFormatTestData> {
1520 public: 1535 public:
1521 virtual ~X509CertificateParseTest() {} 1536 virtual ~X509CertificateParseTest() {}
1522 virtual void SetUp() { 1537 virtual void SetUp() {
1523 test_data_ = GetParam(); 1538 test_data_ = GetParam();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 // attempt to print out the first twenty bytes of the object, which depending 1806 // attempt to print out the first twenty bytes of the object, which depending
1792 // on platform and alignment, may result in an invalid read. 1807 // on platform and alignment, may result in an invalid read.
1793 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { 1808 void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
1794 *os << "root: " 1809 *os << "root: "
1795 << (data.root_cert_filename ? data.root_cert_filename : "none") 1810 << (data.root_cert_filename ? data.root_cert_filename : "none")
1796 << "; intermediate: " << data.intermediate_cert_filename 1811 << "; intermediate: " << data.intermediate_cert_filename
1797 << "; end-entity: " << data.ee_cert_filename; 1812 << "; end-entity: " << data.ee_cert_filename;
1798 } 1813 }
1799 1814
1800 class X509CertificateWeakDigestTest 1815 class X509CertificateWeakDigestTest
1801 : public testing::TestWithParam<WeakDigestTestData> { 1816 : public X509CertificateTest,
1817 public testing::WithParamInterface<WeakDigestTestData> {
1802 public: 1818 public:
1803 X509CertificateWeakDigestTest() {} 1819 X509CertificateWeakDigestTest() {}
1804 virtual ~X509CertificateWeakDigestTest() {} 1820 virtual ~X509CertificateWeakDigestTest() {}
1805 }; 1821 };
1806 1822
1807 TEST_P(X509CertificateWeakDigestTest, Verify) { 1823 TEST_P(X509CertificateWeakDigestTest, Verify) {
1808 WeakDigestTestData data = GetParam(); 1824 WeakDigestTestData data = GetParam();
1809 FilePath certs_dir = GetTestCertsDirectory(); 1825 FilePath certs_dir = GetTestCertsDirectory();
1810 1826
1811 ScopedTestRoot test_root; 1827 ScopedTestRoot test_root;
(...skipping 14 matching lines...) Expand all
1826 X509Certificate::OSCertHandles intermediates; 1842 X509Certificate::OSCertHandles intermediates;
1827 intermediates.push_back(intermediate_cert->os_cert_handle()); 1843 intermediates.push_back(intermediate_cert->os_cert_handle());
1828 1844
1829 scoped_refptr<X509Certificate> ee_chain = 1845 scoped_refptr<X509Certificate> ee_chain =
1830 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 1846 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
1831 intermediates); 1847 intermediates);
1832 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); 1848 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain);
1833 1849
1834 int flags = 0; 1850 int flags = 0;
1835 CertVerifyResult verify_result; 1851 CertVerifyResult verify_result;
1836 int rv = ee_chain->Verify("127.0.0.1", flags, NULL, &verify_result); 1852 int rv = Verify(ee_chain, "127.0.0.1", flags, NULL, &verify_result);
1837 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); 1853 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5);
1838 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); 1854 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4);
1839 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); 1855 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2);
1840 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); 1856 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca);
1841 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); 1857 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca);
1842 1858
1843 // Ensure that MD4 and MD2 are tagged as invalid. 1859 // Ensure that MD4 and MD2 are tagged as invalid.
1844 if (data.expected_has_md4 || data.expected_has_md2) { 1860 if (data.expected_has_md4 || data.expected_has_md2) {
1845 EXPECT_EQ(CERT_STATUS_INVALID, 1861 EXPECT_EQ(CERT_STATUS_INVALID,
1846 verify_result.cert_status & CERT_STATUS_INVALID); 1862 verify_result.cert_status & CERT_STATUS_INVALID);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 #define MAYBE_VerifyMixed DISABLED_VerifyMixed 2016 #define MAYBE_VerifyMixed DISABLED_VerifyMixed
2001 #else 2017 #else
2002 #define MAYBE_VerifyMixed VerifyMixed 2018 #define MAYBE_VerifyMixed VerifyMixed
2003 #endif 2019 #endif
2004 WRAPPED_INSTANTIATE_TEST_CASE_P( 2020 WRAPPED_INSTANTIATE_TEST_CASE_P(
2005 MAYBE_VerifyMixed, 2021 MAYBE_VerifyMixed,
2006 X509CertificateWeakDigestTest, 2022 X509CertificateWeakDigestTest,
2007 testing::ValuesIn(kVerifyMixedTestData)); 2023 testing::ValuesIn(kVerifyMixedTestData));
2008 2024
2009 } // namespace net 2025 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698