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 tests that on successful certificate verification, | 
| 743 TEST_P(CertVerifyProcInternalTest, DISABLED_PublicKeyHashes) { | 743 // CertVerifyResult::public_key_hashes is filled with a SHA1 and SHA256 hash | 
| 744 // for each of the certificates in the chain. | |
| 745 TEST_P(CertVerifyProcInternalTest, PublicKeyHashes) { | |
| 744 if (!SupportsReturningVerifiedChain()) { | 746 if (!SupportsReturningVerifiedChain()) { | 
| 745 LOG(INFO) << "Skipping this test in this platform."; | 747 LOG(INFO) << "Skipping this test in this platform."; | 
| 746 return; | 748 return; | 
| 747 } | 749 } | 
| 748 | 750 | 
| 749 base::FilePath certs_dir = GetTestCertsDirectory(); | 751 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 750 CertificateList certs = CreateCertificateListFromFile( | 752 CertificateList certs = CreateCertificateListFromFile( | 
| 751 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 753 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO); | 
| 752 ASSERT_EQ(3U, certs.size()); | 754 ASSERT_EQ(3U, certs.size()); | 
| 753 | 755 | 
| 754 X509Certificate::OSCertHandles intermediates; | 756 X509Certificate::OSCertHandles intermediates; | 
| 755 intermediates.push_back(certs[1]->os_cert_handle()); | 757 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 758 intermediates.push_back(certs[2]->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 // There are 2 hashes each of the 3 certificates in the verified chain. | 
| 770 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 773 EXPECT_EQ(6u, verify_result.public_key_hashes.size()); | 
| 771 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) | |
| 772 continue; | |
| 773 sha1_hashes.push_back(verify_result.public_key_hashes[i]); | |
| 774 } | |
| 775 ASSERT_LE(3u, sha1_hashes.size()); | |
| 776 | 774 | 
| 777 for (size_t i = 0; i < 3; ++i) { | 775 // Convert |public_key_hashes| to strings for ease of comparison. | 
| 778 EXPECT_EQ(HexEncode(kTwitterSPKIs[i], base::kSHA1Length), | 776 std::vector<std::string> public_key_hash_strings; | 
| 779 HexEncode(sha1_hashes[i].data(), base::kSHA1Length)); | 777 for (const auto& public_key_hash : verify_result.public_key_hashes) | 
| 780 } | 778 public_key_hash_strings.push_back(public_key_hash.ToString()); | 
| 781 | 779 | 
| 782 HashValueVector sha256_hashes; | 780 std::vector<std::string> expected_public_key_hashes = { | 
| 783 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { | 781 // Target | 
| 784 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA256) | 782 "sha1/fSQl8GTgpmark/9mDK9qzIIGfFE=", | 
| 785 continue; | 783 "sha256/5I5+4ndAhwDiWd1WqfBgDkKAAIEhsq0MfAx25Hoc+dA=", | 
| 786 sha256_hashes.push_back(verify_result.public_key_hashes[i]); | |
| 787 } | |
| 788 ASSERT_LE(3u, sha256_hashes.size()); | |
| 789 | 784 | 
| 790 for (size_t i = 0; i < 3; ++i) { | 785 // Intermediate | 
| 791 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), | 786 "sha1/7+0Ms07hEkAc6zVPOo+uLtMEwfU=", | 
| 792 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 787 "sha256/MtnqgdSwAIgEjse7SpxnmyKoo/RTiL9CDIWwFnz4nas=", | 
| 793 } | 788 | 
| 789 // Trust anchor | |
| 790 "sha1/dJwvO4gEVIZvretArGyBNggjlrQ=", | |
| 791 "sha256/z7x1Szes+eQOqJp6rBK3u/tQMs55FYojZHUCFiBcjuc="}; | |
| 792 | |
| 793 // |public_key_hashes| does not have an ordering guarantee. | |
| 794 std::sort(public_key_hash_strings.begin(), public_key_hash_strings.end()); | |
| 795 std::sort(expected_public_key_hashes.begin(), | |
| 796 expected_public_key_hashes.end()); | |
| 797 | |
| 798 EXPECT_EQ(expected_public_key_hashes, public_key_hash_strings); | |
| 
 
Ryan Sleevi
2017/02/04 01:47:02
So, to be clear: This totally works for me as is,
 
eroman
2017/02/04 01:59:55
Done.
 
 | |
| 794 } | 799 } | 
| 795 | 800 | 
| 796 // A regression test for http://crbug.com/70293. | 801 // A regression test for http://crbug.com/70293. | 
| 797 // The Key Usage extension in this RSA SSL server certificate does not have | 802 // The Key Usage extension in this RSA SSL server certificate does not have | 
| 798 // the keyEncipherment bit. | 803 // the keyEncipherment bit. | 
| 799 TEST_P(CertVerifyProcInternalTest, InvalidKeyUsage) { | 804 TEST_P(CertVerifyProcInternalTest, InvalidKeyUsage) { | 
| 800 base::FilePath certs_dir = GetTestCertsDirectory(); | 805 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 801 | 806 | 
| 802 scoped_refptr<X509Certificate> server_cert = | 807 scoped_refptr<X509Certificate> server_cert = | 
| 803 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 808 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; | 2124 int flags = 0; | 
| 2120 CertVerifyResult verify_result; | 2125 CertVerifyResult verify_result; | 
| 2121 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 2126 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags, | 
| 2122 NULL, CertificateList(), &verify_result); | 2127 NULL, CertificateList(), &verify_result); | 
| 2123 EXPECT_EQ(OK, error); | 2128 EXPECT_EQ(OK, error); | 
| 2124 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2129 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2125 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2130 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2126 } | 2131 } | 
| 2127 | 2132 | 
| 2128 } // namespace net | 2133 } // namespace net | 
| OLD | NEW |