OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cert/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 std::vector<base::StringPiece> crl_urls; | 485 std::vector<base::StringPiece> crl_urls; |
486 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); | 486 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); |
487 | 487 |
488 EXPECT_EQ(1u, crl_urls.size()); | 488 EXPECT_EQ(1u, crl_urls.size()); |
489 if (crl_urls.size() > 0) { | 489 if (crl_urls.size() > 0) { |
490 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", | 490 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", |
491 crl_urls[0].as_string()); | 491 crl_urls[0].as_string()); |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
| 495 TEST(X509CertificateTest, HasTLSFeatureExtension) { |
| 496 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 497 scoped_refptr<X509Certificate> cert = |
| 498 ImportCertFromFile(certs_dir, "tls_feature_extension.pem"); |
| 499 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert.get()); |
| 500 |
| 501 std::string derBytes; |
| 502 EXPECT_TRUE( |
| 503 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &derBytes)); |
| 504 |
| 505 bool has_tls_feature_extension = true; |
| 506 EXPECT_TRUE( |
| 507 asn1::HasTLSFeatureExtension(derBytes, &has_tls_feature_extension)); |
| 508 EXPECT_TRUE(has_tls_feature_extension); |
| 509 } |
| 510 |
| 511 TEST(X509CertificateTest, DoesNotHaveTLSFeatureExtension) { |
| 512 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 513 scoped_refptr<X509Certificate> cert = |
| 514 ImportCertFromFile(certs_dir, "ok_cert.pem"); |
| 515 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert.get()); |
| 516 |
| 517 std::string derBytes; |
| 518 EXPECT_TRUE( |
| 519 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &derBytes)); |
| 520 |
| 521 bool has_tls_feature_extension = true; |
| 522 EXPECT_TRUE( |
| 523 asn1::HasTLSFeatureExtension(derBytes, &has_tls_feature_extension)); |
| 524 EXPECT_FALSE(has_tls_feature_extension); |
| 525 } |
| 526 |
495 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We | 527 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We |
496 // call X509Certificate::CreateFromHandle several times and observe whether | 528 // call X509Certificate::CreateFromHandle several times and observe whether |
497 // it returns a cached or new OSCertHandle. | 529 // it returns a cached or new OSCertHandle. |
498 TEST(X509CertificateTest, Cache) { | 530 TEST(X509CertificateTest, Cache) { |
499 X509Certificate::OSCertHandle google_cert_handle; | 531 X509Certificate::OSCertHandle google_cert_handle; |
500 X509Certificate::OSCertHandle thawte_cert_handle; | 532 X509Certificate::OSCertHandle thawte_cert_handle; |
501 | 533 |
502 // Add a single certificate to the certificate cache. | 534 // Add a single certificate to the certificate cache. |
503 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 535 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
504 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 536 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 &actual_type); | 1200 &actual_type); |
1169 | 1201 |
1170 EXPECT_EQ(data.expected_bits, actual_bits); | 1202 EXPECT_EQ(data.expected_bits, actual_bits); |
1171 EXPECT_EQ(data.expected_type, actual_type); | 1203 EXPECT_EQ(data.expected_type, actual_type); |
1172 } | 1204 } |
1173 | 1205 |
1174 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1206 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
1175 testing::ValuesIn(kPublicKeyInfoTestData)); | 1207 testing::ValuesIn(kPublicKeyInfoTestData)); |
1176 | 1208 |
1177 } // namespace net | 1209 } // namespace net |
OLD | NEW |