OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "net/base/test_data_directory.h" | 8 #include "net/base/test_data_directory.h" |
9 #include "net/cert/cert_status_flags.h" | 9 #include "net/cert/cert_status_flags.h" |
10 #include "net/cert/cert_verify_proc.h" | 10 #include "net/cert/cert_verify_proc.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 scoped_refptr<X509Certificate> test_cert = | 83 scoped_refptr<X509Certificate> test_cert = |
84 ImportCertFromFile(GetTestCertsDirectory(), kGoodCertificateFile); | 84 ImportCertFromFile(GetTestCertsDirectory(), kGoodCertificateFile); |
85 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert.get()); | 85 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert.get()); |
86 | 86 |
87 // Test that the good certificate fails verification, because the root | 87 // Test that the good certificate fails verification, because the root |
88 // certificate should not yet be trusted. | 88 // certificate should not yet be trusted. |
89 int flags = 0; | 89 int flags = 0; |
90 CertVerifyResult bad_verify_result; | 90 CertVerifyResult bad_verify_result; |
91 scoped_refptr<CertVerifyProc> verify_proc(CertVerifyProc::CreateDefault()); | 91 scoped_refptr<CertVerifyProc> verify_proc(CertVerifyProc::CreateDefault()); |
92 int bad_status = verify_proc->Verify(test_cert.get(), | 92 int bad_status = |
93 "127.0.0.1", | 93 verify_proc->Verify(test_cert.get(), "127.0.0.1", std::string(), flags, |
94 flags, | 94 NULL, CertificateList(), &bad_verify_result); |
95 NULL, | |
96 CertificateList(), | |
97 &bad_verify_result); | |
98 EXPECT_NE(OK, bad_status); | 95 EXPECT_NE(OK, bad_status); |
99 EXPECT_NE(0u, bad_verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 96 EXPECT_NE(0u, bad_verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); |
100 | 97 |
101 // Add the root certificate and mark it as trusted. | 98 // Add the root certificate and mark it as trusted. |
102 EXPECT_TRUE(test_roots->AddFromFile( | 99 EXPECT_TRUE(test_roots->AddFromFile( |
103 GetTestCertsDirectory().AppendASCII(kRootCertificateFile))); | 100 GetTestCertsDirectory().AppendASCII(kRootCertificateFile))); |
104 EXPECT_FALSE(test_roots->IsEmpty()); | 101 EXPECT_FALSE(test_roots->IsEmpty()); |
105 | 102 |
106 // Test that the certificate verification now succeeds, because the | 103 // Test that the certificate verification now succeeds, because the |
107 // TestRootCerts is successfully imbuing trust. | 104 // TestRootCerts is successfully imbuing trust. |
108 CertVerifyResult good_verify_result; | 105 CertVerifyResult good_verify_result; |
109 int good_status = verify_proc->Verify(test_cert.get(), | 106 int good_status = |
110 "127.0.0.1", | 107 verify_proc->Verify(test_cert.get(), "127.0.0.1", std::string(), flags, |
111 flags, | 108 NULL, CertificateList(), &good_verify_result); |
112 NULL, | |
113 CertificateList(), | |
114 &good_verify_result); | |
115 EXPECT_EQ(OK, good_status); | 109 EXPECT_EQ(OK, good_status); |
116 EXPECT_EQ(0u, good_verify_result.cert_status); | 110 EXPECT_EQ(0u, good_verify_result.cert_status); |
117 | 111 |
118 test_roots->Clear(); | 112 test_roots->Clear(); |
119 EXPECT_TRUE(test_roots->IsEmpty()); | 113 EXPECT_TRUE(test_roots->IsEmpty()); |
120 | 114 |
121 // Ensure that when the TestRootCerts is cleared, the trust settings | 115 // Ensure that when the TestRootCerts is cleared, the trust settings |
122 // revert to their original state, and don't linger. If trust status | 116 // revert to their original state, and don't linger. If trust status |
123 // lingers, it will likely break other tests in net_unittests. | 117 // lingers, it will likely break other tests in net_unittests. |
124 CertVerifyResult restored_verify_result; | 118 CertVerifyResult restored_verify_result; |
125 int restored_status = verify_proc->Verify(test_cert.get(), | 119 int restored_status = |
126 "127.0.0.1", | 120 verify_proc->Verify(test_cert.get(), "127.0.0.1", std::string(), flags, |
127 flags, | 121 NULL, CertificateList(), &restored_verify_result); |
128 NULL, | |
129 CertificateList(), | |
130 &restored_verify_result); | |
131 EXPECT_NE(OK, restored_status); | 122 EXPECT_NE(OK, restored_status); |
132 EXPECT_NE(0u, | 123 EXPECT_NE(0u, |
133 restored_verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 124 restored_verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); |
134 EXPECT_EQ(bad_status, restored_status); | 125 EXPECT_EQ(bad_status, restored_status); |
135 EXPECT_EQ(bad_verify_result.cert_status, restored_verify_result.cert_status); | 126 EXPECT_EQ(bad_verify_result.cert_status, restored_verify_result.cert_status); |
136 } | 127 } |
137 | 128 |
138 #if defined(USE_NSS_CERTS) || \ | 129 #if defined(USE_NSS_CERTS) || \ |
139 (defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)) | 130 (defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)) |
140 TEST(TestRootCertsTest, Contains) { | 131 TEST(TestRootCertsTest, Contains) { |
(...skipping 26 matching lines...) Expand all Loading... |
167 EXPECT_FALSE(test_roots->Contains(root_cert_1->os_cert_handle())); | 158 EXPECT_FALSE(test_roots->Contains(root_cert_1->os_cert_handle())); |
168 EXPECT_FALSE(test_roots->Contains(root_cert_2->os_cert_handle())); | 159 EXPECT_FALSE(test_roots->Contains(root_cert_2->os_cert_handle())); |
169 } | 160 } |
170 #endif | 161 #endif |
171 | 162 |
172 // TODO(rsleevi): Add tests for revocation checking via CRLs, ensuring that | 163 // TODO(rsleevi): Add tests for revocation checking via CRLs, ensuring that |
173 // TestRootCerts properly injects itself into the validation process. See | 164 // TestRootCerts properly injects itself into the validation process. See |
174 // http://crbug.com/63958 | 165 // http://crbug.com/63958 |
175 | 166 |
176 } // namespace net | 167 } // namespace net |
OLD | NEW |