diff options
author | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-29 15:47:17 +0000 |
---|---|---|
committer | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-29 15:47:17 +0000 |
commit | 1843ebdfbc05e6b91ce4070647271dfbe090d687 (patch) | |
tree | c81760649432aeeceaa9e5d117227388a9ffe794 /net/base/x509_certificate_unittest.cc | |
parent | 59781b1e4c4bb14c10f2784ee4bc9c35e063f5cc (diff) | |
download | chromium_src-1843ebdfbc05e6b91ce4070647271dfbe090d687.zip chromium_src-1843ebdfbc05e6b91ce4070647271dfbe090d687.tar.gz chromium_src-1843ebdfbc05e6b91ce4070647271dfbe090d687.tar.bz2 |
Update unit test to check EV functionality (Windows-only for now).
Review URL: http://codereview.chromium.org/4086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/x509_certificate_unittest.cc')
-rw-r--r-- | net/base/x509_certificate_unittest.cc | 191 |
1 files changed, 184 insertions, 7 deletions
diff --git a/net/base/x509_certificate_unittest.cc b/net/base/x509_certificate_unittest.cc index e1a3b1b..73a8337 100644 --- a/net/base/x509_certificate_unittest.cc +++ b/net/base/x509_certificate_unittest.cc @@ -3,19 +3,29 @@ // found in the LICENSE file. #include "base/port.h" +#include "net/base/cert_status_flags.h" #include "net/base/x509_certificate.h" #include "testing/gtest/include/gtest/gtest.h" +// Unit tests aren't allowed to access external resources. Unfortunately, to +// properly verify the EV-ness of a cert, we need to check for its revocation +// through online servers. If you're manually running unit tests, feel free to +// turn this on to test EV certs. But leave it turned off for the automated +// testing. +#define ALLOW_EXTERNAL_ACCESS 0 + namespace { class X509CertificateTest : public testing::Test { }; -// Google's cert (for our test data). This was obtained with: +// Certificates for test data. They're obtained with: // -// $ openssl s_client -connect www.google.com:443 -showcerts -// $ openssl x509 -inform PEM -outform DER > /tmp/google.der -// $ xxd -i /tmp/google.der +// $ openssl s_client -connect [host]:443 -showcerts +// $ openssl x509 -inform PEM -outform DER > /tmp/host.der +// $ xxd -i /tmp/host.der + +// Google's cert. unsigned char google_der[] = { 0x30, 0x82, 0x03, 0x21, 0x30, 0x82, 0x02, 0x8a, 0xa0, 0x03, 0x02, 0x01, @@ -93,7 +103,7 @@ unsigned char google_fingerprint[] = { 0xb1, 0x91, 0x69, 0x44, 0x9b, 0x36, 0x93, 0xa8 }; -// Webkit.org's cert (for our test data). +// webkit.org's cert. unsigned char webkit_der[] = { 0x30, 0x82, 0x05, 0x0d, 0x30, 0x82, 0x03, 0xf5, 0xa0, 0x03, 0x02, 0x01, @@ -212,6 +222,112 @@ unsigned char webkit_fingerprint[] = { 0x57, 0x83, 0x2d, 0xa2, 0xff, 0xbc, 0x84, 0xc2 }; +// thawte.com's cert (it's EV-licious!). + +unsigned char thawte_der[] = { + 0x30, 0x82, 0x04, 0x7b, 0x30, 0x82, 0x03, 0x63, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x15, 0xfa, 0x16, 0x0f, 0x77, 0x9e, 0x6b, 0x90, 0x02, + 0xb5, 0x63, 0x37, 0xb1, 0xfa, 0x16, 0xae, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x81, + 0x8b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x55, 0x53, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, + 0x0c, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2c, 0x20, 0x49, 0x6e, 0x63, + 0x2e, 0x31, 0x39, 0x30, 0x37, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x30, + 0x54, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x75, 0x73, 0x65, + 0x20, 0x61, 0x74, 0x20, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, + 0x77, 0x77, 0x77, 0x2e, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x63, 0x70, 0x73, 0x20, 0x28, 0x63, 0x29, 0x30, 0x36, + 0x31, 0x2a, 0x30, 0x28, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x21, 0x74, + 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, + 0x65, 0x64, 0x20, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x53, 0x53, 0x4c, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, + 0x30, 0x37, 0x30, 0x31, 0x31, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x5a, 0x17, 0x0d, 0x30, 0x39, 0x30, 0x31, 0x31, 0x37, 0x32, 0x33, 0x35, + 0x39, 0x35, 0x39, 0x5a, 0x30, 0x81, 0xc7, 0x31, 0x10, 0x30, 0x0e, 0x06, + 0x03, 0x55, 0x04, 0x05, 0x13, 0x07, 0x33, 0x38, 0x39, 0x38, 0x32, 0x36, + 0x31, 0x31, 0x13, 0x30, 0x11, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01, + 0x82, 0x37, 0x3c, 0x02, 0x01, 0x03, 0x13, 0x02, 0x55, 0x53, 0x31, 0x19, + 0x30, 0x17, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x3c, + 0x02, 0x01, 0x02, 0x13, 0x08, 0x44, 0x65, 0x6c, 0x61, 0x77, 0x61, 0x72, + 0x65, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01, + 0x82, 0x37, 0x3c, 0x02, 0x01, 0x01, 0x14, 0x0a, 0x57, 0x69, 0x6c, 0x6d, + 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, + 0x55, 0x04, 0x0a, 0x14, 0x0a, 0x54, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, + 0x49, 0x6e, 0x63, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, + 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, + 0x08, 0x13, 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, + 0x61, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x07, 0x14, 0x0d, + 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x56, 0x69, 0x65, + 0x77, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x14, 0x0e, + 0x77, 0x77, 0x77, 0x2e, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2e, 0x63, + 0x6f, 0x6d, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, + 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xe7, 0x89, 0x68, 0xb5, 0x6e, + 0x1d, 0x38, 0x19, 0xf6, 0x2d, 0x61, 0xc2, 0x00, 0xba, 0x6e, 0xab, 0x66, + 0x92, 0xd6, 0x85, 0x87, 0x2d, 0xd5, 0xa8, 0x58, 0xa9, 0x7a, 0x75, 0x27, + 0x9d, 0xed, 0x9e, 0xfe, 0x06, 0x71, 0x70, 0x2d, 0x21, 0x70, 0x4c, 0x3e, + 0x9c, 0xb6, 0xd5, 0x5d, 0x44, 0x92, 0xb4, 0xe0, 0xee, 0x7c, 0x0a, 0x50, + 0x4c, 0x0d, 0x67, 0x98, 0xaa, 0x01, 0x0e, 0x37, 0xa3, 0x2a, 0xef, 0xe6, + 0xe0, 0x11, 0x7b, 0xee, 0xb0, 0xa2, 0xb4, 0x32, 0x64, 0xa7, 0x0d, 0xda, + 0x6c, 0x15, 0xf8, 0xc5, 0xa5, 0x5a, 0x2c, 0xfc, 0xc9, 0xa6, 0x3c, 0x88, + 0x88, 0xbf, 0xdf, 0xa7, 0x38, 0xf0, 0x78, 0xed, 0x81, 0x93, 0x29, 0x0c, + 0xae, 0xc7, 0xab, 0x51, 0x21, 0x5e, 0xca, 0x95, 0xe5, 0x48, 0x52, 0x41, + 0xb6, 0x18, 0x60, 0x04, 0x19, 0x6f, 0x3d, 0x80, 0x14, 0xd3, 0xaf, 0x23, + 0x03, 0x10, 0x95, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, 0x1f, + 0x30, 0x82, 0x01, 0x1b, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, + 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x39, 0x06, 0x03, 0x55, 0x1d, + 0x1f, 0x04, 0x32, 0x30, 0x30, 0x30, 0x2e, 0xa0, 0x2c, 0xa0, 0x2a, 0x86, + 0x28, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, + 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x54, + 0x68, 0x61, 0x77, 0x74, 0x65, 0x45, 0x56, 0x43, 0x41, 0x32, 0x30, 0x30, + 0x36, 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x18, 0x06, 0x03, 0x55, 0x1d, 0x20, + 0x04, 0x11, 0x30, 0x0f, 0x30, 0x0d, 0x06, 0x0b, 0x60, 0x86, 0x48, 0x01, + 0x86, 0xf8, 0x45, 0x01, 0x07, 0x30, 0x01, 0x30, 0x1d, 0x06, 0x03, 0x55, + 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, + 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, + 0x03, 0x02, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0xcd, 0x32, 0xe2, 0xf2, 0x5d, 0x25, 0x47, 0x02, 0xaa, + 0x8f, 0x79, 0x4b, 0x32, 0xee, 0x03, 0x99, 0xfd, 0x30, 0x49, 0xd1, 0x30, + 0x76, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, + 0x6a, 0x30, 0x68, 0x30, 0x22, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, + 0x07, 0x30, 0x01, 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, + 0x6f, 0x63, 0x73, 0x70, 0x2e, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2e, + 0x63, 0x6f, 0x6d, 0x30, 0x42, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, + 0x07, 0x30, 0x02, 0x86, 0x36, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, + 0x77, 0x77, 0x77, 0x2e, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, + 0x79, 0x2f, 0x54, 0x68, 0x61, 0x77, 0x74, 0x65, 0x5f, 0x45, 0x56, 0x5f, + 0x43, 0x41, 0x5f, 0x32, 0x30, 0x30, 0x36, 0x2e, 0x63, 0x72, 0x74, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, + 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8b, 0x3a, 0x60, 0x76, 0x1d, + 0x73, 0x99, 0x40, 0x09, 0x8c, 0xc3, 0xd3, 0x2b, 0x0c, 0x10, 0xe9, 0x29, + 0x5e, 0x53, 0x07, 0xfd, 0x96, 0x7a, 0xa6, 0xde, 0x8d, 0x0f, 0xae, 0xf9, + 0x83, 0xe6, 0x4a, 0x5a, 0xc9, 0xae, 0xb2, 0x38, 0xa9, 0x05, 0xf2, 0x1e, + 0xe5, 0x2e, 0x97, 0xda, 0x61, 0x0c, 0xc7, 0xae, 0x3e, 0x77, 0xe8, 0x7c, + 0x87, 0x50, 0x25, 0x55, 0x49, 0xb5, 0xe0, 0x25, 0xec, 0x31, 0xce, 0xd7, + 0xc8, 0xfc, 0xe2, 0x80, 0xba, 0x35, 0x99, 0xb9, 0x47, 0x5c, 0x47, 0xc6, + 0x4d, 0x91, 0x59, 0x8f, 0xab, 0x17, 0x25, 0x94, 0x76, 0xe6, 0x6c, 0x89, + 0x72, 0x19, 0xc5, 0x75, 0xab, 0xff, 0x45, 0x76, 0x4b, 0x58, 0xa9, 0xd4, + 0xe0, 0xaa, 0xfc, 0x1a, 0x19, 0x05, 0x27, 0x4e, 0xa6, 0x3d, 0x15, 0x37, + 0xf5, 0xa3, 0xac, 0x2e, 0xc3, 0xd5, 0xa7, 0xa5, 0xba, 0x32, 0x2e, 0xaa, + 0xa8, 0x7e, 0xd8, 0xc4, 0xb0, 0x03, 0x08, 0xca, 0xf0, 0xc7, 0x78, 0xf4, + 0xd4, 0xb7, 0x88, 0xc4, 0x64, 0xaf, 0xf9, 0x0d, 0xd0, 0x8f, 0x00, 0x02, + 0x16, 0x42, 0x03, 0x30, 0x49, 0xad, 0x9f, 0xe5, 0x56, 0x22, 0xe2, 0x3f, + 0x0c, 0xf9, 0x1e, 0x1d, 0x85, 0xfb, 0xc7, 0xba, 0x24, 0xf9, 0xf5, 0xb0, + 0xc4, 0x4b, 0x86, 0x2e, 0x3b, 0xc6, 0x88, 0x4d, 0x28, 0x03, 0x97, 0x4b, + 0x6d, 0x29, 0x8f, 0x75, 0xfd, 0x12, 0xcf, 0xbd, 0x4e, 0x3a, 0xeb, 0x87, + 0x9f, 0x7b, 0xc7, 0x39, 0x51, 0xbd, 0xb9, 0x53, 0xf5, 0xf9, 0x43, 0xb7, + 0x69, 0xad, 0x2e, 0xe2, 0x9c, 0xd3, 0x34, 0x23, 0x41, 0x28, 0x9c, 0xed, + 0x4d, 0x53, 0xe6, 0x0e, 0x3f, 0x04, 0xc1, 0x56, 0x0e, 0x12, 0xbe, 0xc3, + 0xfb, 0x32, 0xd2, 0x67, 0xef, 0x5b, 0x82, 0xaa, 0xef, 0x5f, 0x0c, 0xc6, + 0xb2, 0x86, 0x04, 0x68, 0x06, 0xe6, 0xb6, 0x85, 0xc8, 0x9b, 0x50 +}; + +unsigned char thawte_fingerprint[] = { + 0x3a, 0xc0, 0x5d, 0x86, 0xb1, 0xd2, 0xee, 0x47, 0xc3, 0xf0, 0x4f, 0x24, + 0x13, 0xb7, 0x6b, 0x79, 0x23, 0x6d, 0x68, 0x5d +}; + } // namespace using net::X509Certificate; @@ -259,6 +375,11 @@ TEST(X509CertificateTest, GoogleCertParsing) { google_cert->GetDNSNames(&dns_names); EXPECT_EQ(1U, dns_names.size()); EXPECT_EQ("www.google.com", dns_names[0]); + +#if ALLOW_EXTERNAL_ACCESS && defined(OS_WIN) + // TODO(avi): turn this on for the Mac once EV checking is implemented. + EXPECT_EQ(false, google_cert->IsEV(net::CERT_STATUS_REV_CHECKING_ENABLED)); +#endif } TEST(X509CertificateTest, WebkitCertParsing) { @@ -307,7 +428,63 @@ TEST(X509CertificateTest, WebkitCertParsing) { EXPECT_EQ(2U, dns_names.size()); EXPECT_EQ("*.webkit.org", dns_names[0]); EXPECT_EQ("webkit.org", dns_names[1]); + +#if ALLOW_EXTERNAL_ACCESS && defined(OS_WIN) + EXPECT_EQ(false, webkit_cert->IsEV(net::CERT_STATUS_REV_CHECKING_ENABLED)); +#endif } -// TODO(avi): Tests needed -// - Test EV +TEST(X509CertificateTest, ThawteCertParsing) { + scoped_refptr<X509Certificate> thawte_cert = X509Certificate::CreateFromBytes( + reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); + + ASSERT_NE(static_cast<X509Certificate *>(NULL), thawte_cert); + + const X509Certificate::Principal& subject = thawte_cert->subject(); + EXPECT_EQ("www.thawte.com", subject.common_name); + EXPECT_EQ("Mountain View", subject.locality_name); + EXPECT_EQ("California", subject.state_or_province_name); + EXPECT_EQ("US", subject.country_name); + EXPECT_EQ(0U, subject.street_addresses.size()); + EXPECT_EQ(1U, subject.organization_names.size()); + EXPECT_EQ("Thawte Inc", subject.organization_names[0]); + EXPECT_EQ(0U, subject.organization_unit_names.size()); + EXPECT_EQ(0U, subject.domain_components.size()); + + const X509Certificate::Principal& issuer = thawte_cert->issuer(); + EXPECT_EQ("thawte Extended Validation SSL CA", issuer.common_name); + EXPECT_EQ("", issuer.locality_name); + EXPECT_EQ("", issuer.state_or_province_name); + EXPECT_EQ("US", issuer.country_name); + EXPECT_EQ(0U, issuer.street_addresses.size()); + EXPECT_EQ(1U, issuer.organization_names.size()); + EXPECT_EQ("thawte, Inc.", issuer.organization_names[0]); + EXPECT_EQ(1U, issuer.organization_unit_names.size()); + EXPECT_EQ("Terms of use at https://www.thawte.com/cps (c)06", + issuer.organization_unit_names[0]); + EXPECT_EQ(0U, issuer.domain_components.size()); + + // Use DoubleT because its epoch is the same on all platforms + const Time& valid_start = thawte_cert->valid_start(); + EXPECT_EQ(1169078400, valid_start.ToDoubleT()); + + const Time& valid_expiry = thawte_cert->valid_expiry(); + EXPECT_EQ(1232236799, valid_expiry.ToDoubleT()); + + const X509Certificate::Fingerprint& fingerprint = thawte_cert->fingerprint(); + for (size_t i = 0; i < 20; ++i) + EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]); + + std::vector<std::string> dns_names; + thawte_cert->GetDNSNames(&dns_names); + EXPECT_EQ(1U, dns_names.size()); + EXPECT_EQ("www.thawte.com", dns_names[0]); + +#if ALLOW_EXTERNAL_ACCESS && defined(OS_WIN) + // EV cert verification requires revocation checking. + EXPECT_EQ(true, thawte_cert->IsEV(net::CERT_STATUS_REV_CHECKING_ENABLED)); + // Consequently, if we don't have revocation checking enabled, we can't claim + // any cert is EV. + EXPECT_EQ(false, thawte_cert->IsEV(0)); +#endif +} |