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

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

Issue 125120: Use LOAD_VERIFY_EV_CERT to verify EV-ness in Verify().... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « net/base/x509_certificate_nss.cc ('k') | net/base/x509_certificate_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/pickle.h" 5 #include "base/pickle.h"
6 #include "net/base/cert_status_flags.h" 6 #include "net/base/cert_status_flags.h"
7 #include "net/base/cert_verify_result.h"
8 #include "net/base/net_errors.h"
7 #include "net/base/x509_certificate.h" 9 #include "net/base/x509_certificate.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 // Unit tests aren't allowed to access external resources. Unfortunately, to 12 // Unit tests aren't allowed to access external resources. Unfortunately, to
11 // properly verify the EV-ness of a cert, we need to check for its revocation 13 // properly verify the EV-ness of a cert, we need to check for its revocation
12 // through online servers. If you're manually running unit tests, feel free to 14 // through online servers. If you're manually running unit tests, feel free to
13 // turn this on to test EV certs. But leave it turned off for the automated 15 // turn this on to test EV certs. But leave it turned off for the automated
14 // testing. 16 // testing.
15 #define ALLOW_EXTERNAL_ACCESS 0 17 #define ALLOW_EXTERNAL_ACCESS 0
16 18
17 #if ALLOW_EXTERNAL_ACCESS && defined(OS_WIN) 19 #if ALLOW_EXTERNAL_ACCESS && defined(OS_WIN)
18 #define TEST_EV 1 // Test IsEV() 20 #define TEST_EV 1 // Test CERT_STATUS_IS_EV
19 #endif 21 #endif
20 22
21 using base::Time; 23 using base::Time;
22 24
23 namespace { 25 namespace {
24 26
25 // Certificates for test data. They're obtained with: 27 // Certificates for test data. They're obtained with:
26 // 28 //
27 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null 29 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null
28 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der 30 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 for (size_t i = 0; i < 20; ++i) 387 for (size_t i = 0; i < 20; ++i)
386 EXPECT_EQ(google_fingerprint[i], fingerprint.data[i]); 388 EXPECT_EQ(google_fingerprint[i], fingerprint.data[i]);
387 389
388 std::vector<std::string> dns_names; 390 std::vector<std::string> dns_names;
389 google_cert->GetDNSNames(&dns_names); 391 google_cert->GetDNSNames(&dns_names);
390 EXPECT_EQ(1U, dns_names.size()); 392 EXPECT_EQ(1U, dns_names.size());
391 EXPECT_EQ("www.google.com", dns_names[0]); 393 EXPECT_EQ("www.google.com", dns_names[0]);
392 394
393 #if TEST_EV 395 #if TEST_EV
394 // TODO(avi): turn this on for the Mac once EV checking is implemented. 396 // TODO(avi): turn this on for the Mac once EV checking is implemented.
395 EXPECT_EQ(false, google_cert->IsEV(net::CERT_STATUS_REV_CHECKING_ENABLED)); 397 CertVerifyResult verify_result;
398 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
399 X509Certificate::VERIFY_EV_CERT;
400 EXPECT_EQ(OK, google_cert->Verify("www.google.com", flags, &verify_result));
401 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV);
396 #endif 402 #endif
397 } 403 }
398 404
399 TEST(X509CertificateTest, WebkitCertParsing) { 405 TEST(X509CertificateTest, WebkitCertParsing) {
400 scoped_refptr<X509Certificate> webkit_cert = X509Certificate::CreateFromBytes( 406 scoped_refptr<X509Certificate> webkit_cert = X509Certificate::CreateFromBytes(
401 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); 407 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der));
402 408
403 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); 409 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert);
404 410
405 const X509Certificate::Principal& subject = webkit_cert->subject(); 411 const X509Certificate::Principal& subject = webkit_cert->subject();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 for (size_t i = 0; i < 20; ++i) 443 for (size_t i = 0; i < 20; ++i)
438 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]); 444 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]);
439 445
440 std::vector<std::string> dns_names; 446 std::vector<std::string> dns_names;
441 webkit_cert->GetDNSNames(&dns_names); 447 webkit_cert->GetDNSNames(&dns_names);
442 EXPECT_EQ(2U, dns_names.size()); 448 EXPECT_EQ(2U, dns_names.size());
443 EXPECT_EQ("*.webkit.org", dns_names[0]); 449 EXPECT_EQ("*.webkit.org", dns_names[0]);
444 EXPECT_EQ("webkit.org", dns_names[1]); 450 EXPECT_EQ("webkit.org", dns_names[1]);
445 451
446 #if TEST_EV 452 #if TEST_EV
447 EXPECT_EQ(false, webkit_cert->IsEV(net::CERT_STATUS_REV_CHECKING_ENABLED)); 453 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
454 X509Certificate::VERIFY_EV_CERT;
455 CertVerifyResult verify_result;
456 EXPECT_EQ(OK, webkit_cert->Verify("webkit.org", flags, &verify_result));
457 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV);
448 #endif 458 #endif
449 } 459 }
450 460
451 TEST(X509CertificateTest, ThawteCertParsing) { 461 TEST(X509CertificateTest, ThawteCertParsing) {
452 scoped_refptr<X509Certificate> thawte_cert = X509Certificate::CreateFromBytes( 462 scoped_refptr<X509Certificate> thawte_cert = X509Certificate::CreateFromBytes(
453 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); 463 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der));
454 464
455 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); 465 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert);
456 466
457 const X509Certificate::Principal& subject = thawte_cert->subject(); 467 const X509Certificate::Principal& subject = thawte_cert->subject();
(...skipping 30 matching lines...) Expand all
488 const X509Certificate::Fingerprint& fingerprint = thawte_cert->fingerprint(); 498 const X509Certificate::Fingerprint& fingerprint = thawte_cert->fingerprint();
489 for (size_t i = 0; i < 20; ++i) 499 for (size_t i = 0; i < 20; ++i)
490 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]); 500 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]);
491 501
492 std::vector<std::string> dns_names; 502 std::vector<std::string> dns_names;
493 thawte_cert->GetDNSNames(&dns_names); 503 thawte_cert->GetDNSNames(&dns_names);
494 EXPECT_EQ(1U, dns_names.size()); 504 EXPECT_EQ(1U, dns_names.size());
495 EXPECT_EQ("www.thawte.com", dns_names[0]); 505 EXPECT_EQ("www.thawte.com", dns_names[0]);
496 506
497 #if TEST_EV 507 #if TEST_EV
508 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
509 X509Certificate::VERIFY_EV_CERT;
510 CertVerifyResult verify_result;
498 // EV cert verification requires revocation checking. 511 // EV cert verification requires revocation checking.
499 EXPECT_EQ(true, thawte_cert->IsEV(net::CERT_STATUS_REV_CHECKING_ENABLED)); 512 EXPECT_EQ(OK, thawte_cert->Verify("www.thawte.com", flags, &verify_result));
513 EXPECT_NE(0, verify_result.cert_status & CERT_STATUS_IS_EV);
500 // Consequently, if we don't have revocation checking enabled, we can't claim 514 // Consequently, if we don't have revocation checking enabled, we can't claim
501 // any cert is EV. 515 // any cert is EV.
502 EXPECT_EQ(false, thawte_cert->IsEV(0)); 516 flags = X509Certificate::VERIFY_EV_CERT;
517 EXPECT_EQ(OK, thawte_cert->Verify("www.thawte.com", flags, &verify_result));
518 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV);
503 #endif 519 #endif
504 } 520 }
505 521
506 // Tests X509Certificate::Cache via X509Certificate::CreateFromHandle. We 522 // Tests X509Certificate::Cache via X509Certificate::CreateFromHandle. We
507 // call X509Certificate::CreateFromHandle several times and observe whether 523 // call X509Certificate::CreateFromHandle several times and observe whether
508 // it returns a cached or new X509Certificate object. 524 // it returns a cached or new X509Certificate object.
509 // 525 //
510 // All the OS certificate handles in this test are actually from the same 526 // All the OS certificate handles in this test are actually from the same
511 // source (the bytes of a lone certificate), but we pretend that some of them 527 // source (the bytes of a lone certificate), but we pretend that some of them
512 // come from the network. 528 // come from the network.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 615
600 policy.Allow(webkit_cert.get()); 616 policy.Allow(webkit_cert.get());
601 617
602 EXPECT_EQ(policy.Check(google_cert.get()), X509Certificate::Policy::DENIED); 618 EXPECT_EQ(policy.Check(google_cert.get()), X509Certificate::Policy::DENIED);
603 EXPECT_EQ(policy.Check(webkit_cert.get()), X509Certificate::Policy::ALLOWED); 619 EXPECT_EQ(policy.Check(webkit_cert.get()), X509Certificate::Policy::ALLOWED);
604 EXPECT_TRUE(policy.HasAllowedCert()); 620 EXPECT_TRUE(policy.HasAllowedCert());
605 EXPECT_TRUE(policy.HasDeniedCert()); 621 EXPECT_TRUE(policy.HasDeniedCert());
606 } 622 }
607 623
608 } // namespace net 624 } // namespace net
OLDNEW
« no previous file with comments | « net/base/x509_certificate_nss.cc ('k') | net/base/x509_certificate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698