Chromium Code Reviews| 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/cert_verify_proc.h" | 5 #include "net/cert/cert_verify_proc.h" | 
| 6 | 6 | 
| 7 #include <vector> | 7 #include <vector> | 
| 8 | 8 | 
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" | 
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" | 
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 | 725 | 
| 726 X509Certificate::OSCertHandles intermediates; | 726 X509Certificate::OSCertHandles intermediates; | 
| 727 intermediates.push_back(certs[1]->os_cert_handle()); | 727 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 728 | 728 | 
| 729 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 729 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 
| 730 certs[0]->os_cert_handle(), intermediates); | 730 certs[0]->os_cert_handle(), intermediates); | 
| 731 | 731 | 
| 732 int flags = 0; | 732 int flags = 0; | 
| 733 CertVerifyResult verify_result; | 733 CertVerifyResult verify_result; | 
| 734 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 734 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 
| 735 // against agl. See also PublicKeyHashes. | 735 // against agl. | 
| 736 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 736 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 
| 737 CertificateList(), &verify_result); | 737 CertificateList(), &verify_result); | 
| 738 EXPECT_THAT(error, IsOk()); | 738 EXPECT_THAT(error, IsOk()); | 
| 739 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 739 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 
| 740 } | 740 } | 
| 741 | 741 | 
| 742 // TODO(crbug.com/610546): Fix and re-enable this test. | 742 // This test uses a similar setup to VerifyReturnChainProperlyOrdered, however | 
| 743 TEST_P(CertVerifyProcInternalTest, DISABLED_PublicKeyHashes) { | 743 // verifies the public key hashes chain rather than the chain itself. | 
| 
 
Ryan Sleevi
2017/02/03 23:54:21
This isn't necessary to match that. We're really j
 
eroman
2017/02/04 00:59:28
Done.
 
 | |
| 744 TEST_P(CertVerifyProcInternalTest, PublicKeyHashes) { | |
| 744 if (!SupportsReturningVerifiedChain()) { | 745 if (!SupportsReturningVerifiedChain()) { | 
| 745 LOG(INFO) << "Skipping this test in this platform."; | 746 LOG(INFO) << "Skipping this test in this platform."; | 
| 746 return; | 747 return; | 
| 747 } | 748 } | 
| 748 | 749 | 
| 749 base::FilePath certs_dir = GetTestCertsDirectory(); | 750 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 750 CertificateList certs = CreateCertificateListFromFile( | 751 CertificateList certs = CreateCertificateListFromFile( | 
| 751 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 752 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO); | 
| 752 ASSERT_EQ(3U, certs.size()); | 753 ASSERT_EQ(3U, certs.size()); | 
| 753 | 754 | 
| 755 // Construct the chain out of order. | |
| 
 
Ryan Sleevi
2017/02/03 23:54:21
This isn't necessary for the test
 
eroman
2017/02/04 00:59:28
Done.
 
 | |
| 754 X509Certificate::OSCertHandles intermediates; | 756 X509Certificate::OSCertHandles intermediates; | 
| 757 intermediates.push_back(certs[2]->os_cert_handle()); | |
| 755 intermediates.push_back(certs[1]->os_cert_handle()); | 758 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 756 | 759 | 
| 760 ScopedTestRoot scoped_root(certs[2].get()); | |
| 757 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 761 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle( | 
| 758 certs[0]->os_cert_handle(), intermediates); | 762 certs[0]->os_cert_handle(), intermediates); | 
| 763 ASSERT_TRUE(cert_chain); | |
| 764 ASSERT_EQ(2U, cert_chain->GetIntermediateCertificates().size()); | |
| 765 | |
| 759 int flags = 0; | 766 int flags = 0; | 
| 760 CertVerifyResult verify_result; | 767 CertVerifyResult verify_result; | 
| 761 | 768 int error = Verify(cert_chain.get(), "127.0.0.1", flags, NULL, | 
| 762 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | |
| 763 // against agl. See also TestKnownRoot. | |
| 764 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | |
| 765 CertificateList(), &verify_result); | 769 CertificateList(), &verify_result); | 
| 766 EXPECT_THAT(error, IsOk()); | 770 EXPECT_THAT(error, IsOk()); | 
| 767 ASSERT_LE(3U, verify_result.public_key_hashes.size()); | |
| 768 | 771 | 
| 769 HashValueVector sha1_hashes; | 772 HashValueVector sha1_hashes; | 
| 770 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 773 HashValueVector sha256_hashes; | 
| 
 
Ryan Sleevi
2017/02/03 23:54:21
concrete suggestion: vector<SHA1HashValue> and vec
 
eroman
2017/02/04 00:59:28
no longer applicable
 
 | |
| 771 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) | 774 for (const auto& public_key_hash : verify_result.public_key_hashes) { | 
| 772 continue; | 775 if (public_key_hash.tag == HASH_VALUE_SHA1) { | 
| 773 sha1_hashes.push_back(verify_result.public_key_hashes[i]); | 776 sha1_hashes.push_back(public_key_hash); | 
| 777 } else if (public_key_hash.tag == HASH_VALUE_SHA256) { | |
| 778 sha256_hashes.push_back(public_key_hash); | |
| 779 } | |
| 774 } | 780 } | 
| 775 ASSERT_LE(3u, sha1_hashes.size()); | |
| 776 | 781 | 
| 777 for (size_t i = 0; i < 3; ++i) { | 782 const char* kExpectedSha1HashesHex[] = { | 
| 778 EXPECT_EQ(HexEncode(kTwitterSPKIs[i], base::kSHA1Length), | 783 "7D2425F064E0A666AB93FF660CAF6ACC82067C51", | 
| 784 "EFED0CB34EE112401CEB354F3A8FAE2ED304C1F5", | |
| 785 "749C2F3B880454866FADEB40AC6C8136082396B4", | |
| 786 }; | |
| 787 | |
| 788 const char* kExpectedSha256HashesHex[] = { | |
| 789 "E48E7EE277408700E259DD56A9F0600E4280008121B2AD0C7C0C76E47A1CF9D0", | |
| 790 "32D9EA81D4B00088048EC7BB4A9C679B22A8A3F45388BF420C85B0167CF89DAB", | |
| 791 "CFBC754B37ACF9E40EA89A7AAC12B7BBFB5032CE79158A2364750216205C8EE7", | |
| 792 }; | |
| 793 | |
| 794 ASSERT_EQ(arraysize(kExpectedSha1HashesHex), sha1_hashes.size()); | |
| 795 for (size_t i = 0; i < sha1_hashes.size(); ++i) { | |
| 796 EXPECT_EQ(std::string(kExpectedSha1HashesHex[i]), | |
| 779 HexEncode(sha1_hashes[i].data(), base::kSHA1Length)); | 797 HexEncode(sha1_hashes[i].data(), base::kSHA1Length)); | 
| 780 } | 798 } | 
| 781 | 799 | 
| 782 HashValueVector sha256_hashes; | 800 ASSERT_EQ(arraysize(kExpectedSha256HashesHex), sha256_hashes.size()); | 
| 783 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 801 for (size_t i = 0; i < sha256_hashes.size(); ++i) { | 
| 784 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA256) | 802 EXPECT_EQ(std::string(kExpectedSha256HashesHex[i]), | 
| 785 continue; | |
| 786 sha256_hashes.push_back(verify_result.public_key_hashes[i]); | |
| 787 } | |
| 788 ASSERT_LE(3u, sha256_hashes.size()); | |
| 789 | |
| 790 for (size_t i = 0; i < 3; ++i) { | |
| 791 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), | |
| 792 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 803 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 
| 793 } | 804 } | 
| 
 
Ryan Sleevi
2017/02/03 23:54:21
Interesting, the original test was relying on a (n
 
eroman
2017/02/04 00:59:28
Done -- removed ordering requirement in test, and
 
 | |
| 794 } | 805 } | 
| 795 | 806 | 
| 796 // A regression test for http://crbug.com/70293. | 807 // A regression test for http://crbug.com/70293. | 
| 797 // The Key Usage extension in this RSA SSL server certificate does not have | 808 // The Key Usage extension in this RSA SSL server certificate does not have | 
| 798 // the keyEncipherment bit. | 809 // the keyEncipherment bit. | 
| 799 TEST_P(CertVerifyProcInternalTest, InvalidKeyUsage) { | 810 TEST_P(CertVerifyProcInternalTest, InvalidKeyUsage) { | 
| 800 base::FilePath certs_dir = GetTestCertsDirectory(); | 811 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 801 | 812 | 
| 802 scoped_refptr<X509Certificate> server_cert = | 813 scoped_refptr<X509Certificate> server_cert = | 
| 803 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 814 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 
| (...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2119 int flags = 0; | 2130 int flags = 0; | 
| 2120 CertVerifyResult verify_result; | 2131 CertVerifyResult verify_result; | 
| 2121 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 2132 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 2122 NULL, CertificateList(), &verify_result); | 2133 NULL, CertificateList(), &verify_result); | 
| 2123 EXPECT_EQ(OK, error); | 2134 EXPECT_EQ(OK, error); | 
| 2124 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2135 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2125 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2136 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2126 } | 2137 } | 
| 2127 | 2138 | 
| 2128 } // namespace net | 2139 } // namespace net | 
| OLD | NEW |