Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: net/cert/cert_verify_proc_unittest.cc

Issue 2629093002: Parameterize the CertVerifyProc tests so they can be run with (Closed)
Patch Set: Address sleevi comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const std::string& ocsp_response, 93 const std::string& ocsp_response,
94 int flags, 94 int flags,
95 CRLSet* crl_set, 95 CRLSet* crl_set,
96 const CertificateList& additional_trust_anchors, 96 const CertificateList& additional_trust_anchors,
97 CertVerifyResult* verify_result) { 97 CertVerifyResult* verify_result) {
98 *verify_result = result_; 98 *verify_result = result_;
99 verify_result->verified_cert = cert; 99 verify_result->verified_cert = cert;
100 return OK; 100 return OK;
101 } 101 }
102 102
103 bool SupportsReturningVerifiedChain() { 103 // This enum identifies a concrete implemenation of CertVerifyProc.
104 #if defined(OS_ANDROID) 104 //
105 // Before API level 17, Android does not expose the APIs necessary to get at 105 // The type is erased by CertVerifyProc::CreateDefault(), however
106 // the verified certificate chain. 106 // needs to be known for some of the test expectations.
107 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) 107 enum CertVerifyProcType {
108 return false; 108 CERT_VERIFY_PROC_NSS,
109 #endif 109 CERT_VERIFY_PROC_OPENSSL,
110 return true; 110 CERT_VERIFY_PROC_ANDROID,
111 } 111 CERT_VERIFY_PROC_IOS,
112 CERT_VERIFY_PROC_MAC,
113 CERT_VERIFY_PROC_WIN,
114 };
112 115
113 bool SupportsDetectingKnownRoots() { 116 // Returns the CertVerifyProcType corresponding to what
114 #if defined(OS_ANDROID) 117 // CertVerifyProc::CreateDefault() returns. This needs to be kept in sync with
115 // Before API level 17, Android does not expose the APIs necessary to get at 118 // CreateDefault().
116 // the verified certificate chain and detect known roots. 119 CertVerifyProcType GetDefaultCertVerifyProcType() {
117 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) 120 #if defined(USE_NSS_CERTS)
118 return false; 121 return CERT_VERIFY_PROC_NSS;
122 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
123 return CERT_VERIFY_PROC_OPENSSL;
124 #elif defined(OS_ANDROID)
125 return CERT_VERIFY_PROC_ANDROID;
119 #elif defined(OS_IOS) 126 #elif defined(OS_IOS)
120 // iOS does not expose the APIs necessary to get the known system roots. 127 return CERT_VERIFY_PROC_IOS;
121 return false; 128 #elif defined(OS_MACOSX)
122 #endif 129 return CERT_VERIFY_PROC_MAC;
123 return true; 130 #elif defined(OS_WIN)
124 } 131 return CERT_VERIFY_PROC_WIN;
125
126 bool WeakKeysAreInvalid() {
127 #if defined(OS_MACOSX) && !defined(OS_IOS)
128 // Starting with Mac OS 10.12, certs with weak keys are treated as
129 // (recoverable) invalid certificate errors.
130 return base::mac::IsAtLeastOS10_12();
131 #else 132 #else
132 return false; 133 // Will fail to compile.
133 #endif 134 #endif
134 } 135 }
135 136
137 // Whether the test is running within the iphone simulator.
138 const bool kTargetIsIphoneSimulator =
139 #if TARGET_IPHONE_SIMULATOR
140 true;
141 #else
142 false;
143 #endif
144
136 // Template helper to load a series of certificate files into a CertificateList. 145 // Template helper to load a series of certificate files into a CertificateList.
137 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a 146 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a
138 // series of individual certificates (to make the tests clearer). 147 // series of individual certificates (to make the tests clearer).
139 template <size_t N> 148 template <size_t N>
140 void LoadCertificateFiles(const char* const (&cert_files)[N], 149 void LoadCertificateFiles(const char* const (&cert_files)[N],
141 CertificateList* certs) { 150 CertificateList* certs) {
142 certs->clear(); 151 certs->clear();
143 for (size_t i = 0; i < N; ++i) { 152 for (size_t i = 0; i < N; ++i) {
144 SCOPED_TRACE(cert_files[i]); 153 SCOPED_TRACE(cert_files[i]);
145 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( 154 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile(
146 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO); 155 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO);
147 ASSERT_TRUE(cert); 156 ASSERT_TRUE(cert);
148 certs->push_back(cert); 157 certs->push_back(cert);
149 } 158 }
150 } 159 }
151 160
161 // Returns a textual description of the CertVerifyProc implementation
162 // that is being tested, used to give better names to parameterized
163 // tests.
164 std::string VerifyProcTypeToName(
165 const testing::TestParamInfo<CertVerifyProcType>& params) {
166 switch (params.param) {
167 case CERT_VERIFY_PROC_NSS:
168 return "CertVerifyProcNSS";
169 case CERT_VERIFY_PROC_OPENSSL:
170 return "CertVerifyProcOpenSSL";
171 case CERT_VERIFY_PROC_ANDROID:
172 return "CertVerifyProcAndroid";
173 case CERT_VERIFY_PROC_IOS:
174 return "CertVerifyProcIOS";
175 case CERT_VERIFY_PROC_MAC:
176 return "CertVerifyProcMac";
177 case CERT_VERIFY_PROC_WIN:
178 return "CertVerifyProcWin";
179 }
180
181 return nullptr;
182 }
183
184 // The set of all CertVerifyProcTypes that tests should be
185 // parameterized on.
186 const std::vector<CertVerifyProcType> kAllCertVerifiers = {
187 GetDefaultCertVerifyProcType()};
188
152 } // namespace 189 } // namespace
153 190
154 class CertVerifyProcTest : public testing::Test { 191 // This fixture is for tests that apply to concrete implementations of
155 public: 192 // CertVerifyProc. It will be run for all of the concrete
156 CertVerifyProcTest() 193 // CertVerifyProc types.
157 : verify_proc_(CertVerifyProc::CreateDefault()) { 194 //
158 } 195 // It is called "Internal" as it tests the internal methods like
159 ~CertVerifyProcTest() override {} 196 // "VerifyInternal()".
160 197 class CertVerifyProcInternalTest
198 : public testing::TestWithParam<CertVerifyProcType> {
161 protected: 199 protected:
162 bool SupportsAdditionalTrustAnchors() { 200 void SetUp() override {
163 return verify_proc_->SupportsAdditionalTrustAnchors(); 201 EXPECT_EQ(verify_proc_type(), GetDefaultCertVerifyProcType());
164 } 202 verify_proc_ = CertVerifyProc::CreateDefault();
165
166 // Returns true if the underlying CertVerifyProc supports integrating CRLSets
167 // into path building logic, such as allowing the selection of alternatively
168 // valid paths when one or more are revoked. As the goal is to integrate this
169 // into all platforms, this is a temporary, test-only flag to centralize the
170 // conditionals in tests.
171 bool SupportsCRLSetsInPathBuilding() {
172 #if defined(OS_WIN) || defined(USE_NSS_CERTS)
173 return true;
174 #else
175 return false;
176 #endif
177 } 203 }
178 204
179 int Verify(X509Certificate* cert, 205 int Verify(X509Certificate* cert,
180 const std::string& hostname, 206 const std::string& hostname,
181 int flags, 207 int flags,
182 CRLSet* crl_set, 208 CRLSet* crl_set,
183 const CertificateList& additional_trust_anchors, 209 const CertificateList& additional_trust_anchors,
184 CertVerifyResult* verify_result) { 210 CertVerifyResult* verify_result) {
185 return verify_proc_->Verify(cert, hostname, std::string(), flags, crl_set, 211 return verify_proc_->Verify(cert, hostname, std::string(), flags, crl_set,
186 additional_trust_anchors, verify_result); 212 additional_trust_anchors, verify_result);
187 } 213 }
188 214
189 int VerifyWithOCSPResponse(X509Certificate* cert, 215 CertVerifyProcType verify_proc_type() const { return GetParam(); }
190 const std::string& hostname, 216
191 const std::string& ocsp_response, 217 bool SupportsAdditionalTrustAnchors() const {
192 int flags, 218 return verify_proc_->SupportsAdditionalTrustAnchors();
193 CRLSet* crl_set,
194 const CertificateList& additional_trust_anchors,
195 CertVerifyResult* verify_result) {
196 return verify_proc_->Verify(cert, hostname, ocsp_response, flags, crl_set,
197 additional_trust_anchors, verify_result);
198 } 219 }
199 220
200 const CertificateList empty_cert_list_; 221 bool SupportsReturningVerifiedChain() const {
222 #if defined(OS_ANDROID)
223 // Before API level 17, Android does not expose the APIs necessary to get at
224 // the verified certificate chain.
225 if (verify_proc_type() == CERT_VERIFY_PROC_ANDROID &&
226 base::android::BuildInfo::GetInstance()->sdk_int() < 17)
227 return false;
228 #endif
229 return true;
230 }
231
232 bool SupportsDetectingKnownRoots() const {
233 #if defined(OS_ANDROID)
234 // Before API level 17, Android does not expose the APIs necessary to get at
235 // the verified certificate chain and detect known roots.
236 if (verify_proc_type() == CERT_VERIFY_PROC_ANDROID)
237 return base::android::BuildInfo::GetInstance()->sdk_int() >= 17;
238 #endif
239
240 // iOS does not expose the APIs necessary to get the known system roots.
241 if (verify_proc_type() == CERT_VERIFY_PROC_IOS)
242 return false;
243
244 return true;
245 }
246
247 bool WeakKeysAreInvalid() const {
248 #if defined(OS_MACOSX) && !defined(OS_IOS)
249 // Starting with Mac OS 10.12, certs with weak keys are treated as
250 // (recoverable) invalid certificate errors.
251 if (verify_proc_type() == CERT_VERIFY_PROC_MAC &&
252 base::mac::IsAtLeastOS10_12()) {
253 return true;
254 }
255 #endif
256 return false;
257 }
258
259 bool SupportsCRLSet() const {
260 return verify_proc_type() == CERT_VERIFY_PROC_NSS ||
261 verify_proc_type() == CERT_VERIFY_PROC_WIN ||
262 verify_proc_type() == CERT_VERIFY_PROC_MAC;
263 }
264
265 bool SupportsCRLSetsInPathBuilding() const {
266 return verify_proc_type() == CERT_VERIFY_PROC_WIN ||
267 verify_proc_type() == CERT_VERIFY_PROC_NSS;
268 }
269
270 CertVerifyProc* verify_proc() const { return verify_proc_.get(); }
271
272 private:
201 scoped_refptr<CertVerifyProc> verify_proc_; 273 scoped_refptr<CertVerifyProc> verify_proc_;
202 }; 274 };
203 275
204 #if defined(OS_ANDROID) || defined(USE_OPENSSL_CERTS) 276 INSTANTIATE_TEST_CASE_P(,
205 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. 277 CertVerifyProcInternalTest,
206 #define MAYBE_EVVerification DISABLED_EVVerification 278 testing::ValuesIn(kAllCertVerifiers),
207 #else 279 VerifyProcTypeToName);
280
208 // TODO(rsleevi): Reenable this test once comodo.chaim.pem is no longer 281 // TODO(rsleevi): Reenable this test once comodo.chaim.pem is no longer
209 // expired, http://crbug.com/502818 282 // expired, http://crbug.com/502818
210 #define MAYBE_EVVerification DISABLED_EVVerification 283 TEST_P(CertVerifyProcInternalTest, DISABLED_EVVerification) {
211 #endif 284 if (verify_proc_type() == CERT_VERIFY_PROC_ANDROID ||
212 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) { 285 verify_proc_type() == CERT_VERIFY_PROC_OPENSSL) {
213 CertificateList certs = CreateCertificateListFromFile( 286 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet
214 GetTestCertsDirectory(), 287 // supported.
215 "comodo.chain.pem", 288 LOG(INFO) << "Skipping test as EV verification is not yet supported";
216 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 289 return;
290 }
291
292 CertificateList certs =
293 CreateCertificateListFromFile(GetTestCertsDirectory(), "comodo.chain.pem",
294 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
217 ASSERT_EQ(3U, certs.size()); 295 ASSERT_EQ(3U, certs.size());
218 296
219 X509Certificate::OSCertHandles intermediates; 297 X509Certificate::OSCertHandles intermediates;
220 intermediates.push_back(certs[1]->os_cert_handle()); 298 intermediates.push_back(certs[1]->os_cert_handle());
221 intermediates.push_back(certs[2]->os_cert_handle()); 299 intermediates.push_back(certs[2]->os_cert_handle());
222 300
223 scoped_refptr<X509Certificate> comodo_chain = 301 scoped_refptr<X509Certificate> comodo_chain =
224 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 302 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
225 intermediates); 303 intermediates);
226 304
227 scoped_refptr<CRLSet> crl_set(CRLSet::ForTesting(false, NULL, "")); 305 scoped_refptr<CRLSet> crl_set(CRLSet::ForTesting(false, NULL, ""));
228 CertVerifyResult verify_result; 306 CertVerifyResult verify_result;
229 int flags = CertVerifier::VERIFY_EV_CERT; 307 int flags = CertVerifier::VERIFY_EV_CERT;
230 int error = Verify(comodo_chain.get(), 308 int error = Verify(comodo_chain.get(), "comodo.com", flags, crl_set.get(),
231 "comodo.com", 309 CertificateList(), &verify_result);
232 flags,
233 crl_set.get(),
234 empty_cert_list_,
235 &verify_result);
236 EXPECT_THAT(error, IsOk()); 310 EXPECT_THAT(error, IsOk());
237 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); 311 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
238 } 312 }
239 313
240 // TODO(crbug.com/605457): the test expectation was incorrect on some 314 // TODO(crbug.com/605457): the test expectation was incorrect on some
241 // configurations, so disable the test until it is fixed (better to have 315 // configurations, so disable the test until it is fixed (better to have
242 // a bug to track a failing test than a false sense of security due to 316 // a bug to track a failing test than a false sense of security due to
243 // false positive). 317 // false positive).
244 TEST_F(CertVerifyProcTest, DISABLED_PaypalNullCertParsing) { 318 TEST_P(CertVerifyProcInternalTest, DISABLED_PaypalNullCertParsing) {
245 // A certificate for www.paypal.com with a NULL byte in the common name. 319 // A certificate for www.paypal.com with a NULL byte in the common name.
246 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 320 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363
247 SHA256HashValue paypal_null_fingerprint = {{0x00}}; 321 SHA256HashValue paypal_null_fingerprint = {{0x00}};
248 322
249 scoped_refptr<X509Certificate> paypal_null_cert( 323 scoped_refptr<X509Certificate> paypal_null_cert(
250 X509Certificate::CreateFromBytes( 324 X509Certificate::CreateFromBytes(
251 reinterpret_cast<const char*>(paypal_null_der), 325 reinterpret_cast<const char*>(paypal_null_der),
252 sizeof(paypal_null_der))); 326 sizeof(paypal_null_der)));
253 327
254 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert.get()); 328 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert.get());
255 329
256 EXPECT_EQ(paypal_null_fingerprint, X509Certificate::CalculateFingerprint256( 330 EXPECT_EQ(paypal_null_fingerprint, X509Certificate::CalculateFingerprint256(
257 paypal_null_cert->os_cert_handle())); 331 paypal_null_cert->os_cert_handle()));
258 332
259 int flags = 0; 333 int flags = 0;
260 CertVerifyResult verify_result; 334 CertVerifyResult verify_result;
261 int error = Verify(paypal_null_cert.get(), 335 int error = Verify(paypal_null_cert.get(), "www.paypal.com", flags, NULL,
262 "www.paypal.com", 336 CertificateList(), &verify_result);
263 flags, 337
264 NULL, 338 if (verify_proc_type() == CERT_VERIFY_PROC_NSS ||
265 empty_cert_list_, 339 verify_proc_type() == CERT_VERIFY_PROC_ANDROID) {
266 &verify_result); 340 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID));
267 #if defined(USE_NSS_CERTS) || defined(OS_ANDROID) 341 } else if (verify_proc_type() == CERT_VERIFY_PROC_IOS &&
268 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); 342 kTargetIsIphoneSimulator) {
269 #elif defined(OS_IOS) && TARGET_IPHONE_SIMULATOR 343 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning
270 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning 344 // ERR_CERT_AUTHORITY_INVALID on the real device.
271 // ERR_CERT_AUTHORITY_INVALID on the real device. 345 EXPECT_THAT(error, IsError(ERR_CERT_INVALID));
272 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); 346 } else {
273 #else 347 // TOOD(bulach): investigate why macosx and win aren't returning
274 // TOOD(bulach): investigate why macosx and win aren't returning 348 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID.
275 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. 349 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID));
276 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); 350 }
277 #endif 351
278 // Either the system crypto library should correctly report a certificate 352 // Either the system crypto library should correctly report a certificate
279 // name mismatch, or our certificate blacklist should cause us to report an 353 // name mismatch, or our certificate blacklist should cause us to report an
280 // invalid certificate. 354 // invalid certificate.
281 #if defined(USE_NSS_CERTS) || defined(OS_WIN) 355 if (verify_proc_type() == CERT_VERIFY_PROC_NSS ||
282 EXPECT_TRUE(verify_result.cert_status & 356 verify_proc_type() == CERT_VERIFY_PROC_WIN) {
283 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); 357 EXPECT_TRUE(verify_result.cert_status &
284 #endif 358 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID));
359 }
360
361 // TODO(crbug.com/649017): What expectations to use for the other verifiers?
285 } 362 }
286 363
287 // A regression test for http://crbug.com/31497. 364 // A regression test for http://crbug.com/31497.
288 #if defined(OS_ANDROID) 365 TEST_P(CertVerifyProcInternalTest, IntermediateCARequireExplicitPolicy) {
289 // Disabled on Android, as the Android verification libraries require an 366 if (verify_proc_type() == CERT_VERIFY_PROC_ANDROID) {
290 // explicit policy to be specified, even when anyPolicy is permitted. 367 // Disabled on Android, as the Android verification libraries require an
291 #define MAYBE_IntermediateCARequireExplicitPolicy \ 368 // explicit policy to be specified, even when anyPolicy is permitted.
292 DISABLED_IntermediateCARequireExplicitPolicy 369 LOG(INFO) << "Skipping test on Android";
293 #else 370 return;
294 #define MAYBE_IntermediateCARequireExplicitPolicy \ 371 }
295 IntermediateCARequireExplicitPolicy 372
296 #endif
297 TEST_F(CertVerifyProcTest, MAYBE_IntermediateCARequireExplicitPolicy) {
298 base::FilePath certs_dir = GetTestCertsDirectory(); 373 base::FilePath certs_dir = GetTestCertsDirectory();
299 374
300 CertificateList certs = CreateCertificateListFromFile( 375 CertificateList certs = CreateCertificateListFromFile(
301 certs_dir, "explicit-policy-chain.pem", 376 certs_dir, "explicit-policy-chain.pem", X509Certificate::FORMAT_AUTO);
302 X509Certificate::FORMAT_AUTO);
303 ASSERT_EQ(3U, certs.size()); 377 ASSERT_EQ(3U, certs.size());
304 378
305 X509Certificate::OSCertHandles intermediates; 379 X509Certificate::OSCertHandles intermediates;
306 intermediates.push_back(certs[1]->os_cert_handle()); 380 intermediates.push_back(certs[1]->os_cert_handle());
307 381
308 scoped_refptr<X509Certificate> cert = 382 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
309 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 383 certs[0]->os_cert_handle(), intermediates);
310 intermediates);
311 ASSERT_TRUE(cert.get()); 384 ASSERT_TRUE(cert.get());
312 385
313 ScopedTestRoot scoped_root(certs[2].get()); 386 ScopedTestRoot scoped_root(certs[2].get());
314 387
315 int flags = 0; 388 int flags = 0;
316 CertVerifyResult verify_result; 389 CertVerifyResult verify_result;
317 int error = Verify(cert.get(), 390 int error = Verify(cert.get(), "policy_test.example", flags, NULL,
318 "policy_test.example", 391 CertificateList(), &verify_result);
319 flags,
320 NULL,
321 empty_cert_list_,
322 &verify_result);
323 EXPECT_THAT(error, IsOk()); 392 EXPECT_THAT(error, IsOk());
324 EXPECT_EQ(0u, verify_result.cert_status); 393 EXPECT_EQ(0u, verify_result.cert_status);
325 } 394 }
326 395
327 TEST_F(CertVerifyProcTest, RejectExpiredCert) { 396 TEST_P(CertVerifyProcInternalTest, RejectExpiredCert) {
328 base::FilePath certs_dir = GetTestCertsDirectory(); 397 base::FilePath certs_dir = GetTestCertsDirectory();
329 398
330 // Load root_ca_cert.pem into the test root store. 399 // Load root_ca_cert.pem into the test root store.
331 ScopedTestRoot test_root( 400 ScopedTestRoot test_root(
332 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); 401 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get());
333 402
334 CertificateList certs = CreateCertificateListFromFile( 403 CertificateList certs = CreateCertificateListFromFile(
335 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); 404 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO);
336 ASSERT_EQ(1U, certs.size()); 405 ASSERT_EQ(1U, certs.size());
337 406
338 X509Certificate::OSCertHandles intermediates; 407 X509Certificate::OSCertHandles intermediates;
339 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( 408 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
340 certs[0]->os_cert_handle(), intermediates); 409 certs[0]->os_cert_handle(), intermediates);
341 410
342 int flags = 0; 411 int flags = 0;
343 CertVerifyResult verify_result; 412 CertVerifyResult verify_result;
344 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 413 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, CertificateList(),
345 &verify_result); 414 &verify_result);
346 EXPECT_THAT(error, IsError(ERR_CERT_DATE_INVALID)); 415 EXPECT_THAT(error, IsError(ERR_CERT_DATE_INVALID));
347 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_DATE_INVALID); 416 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_DATE_INVALID);
348 } 417 }
349 418
350 // Currently, only RSA and DSA keys are checked for weakness, and our example 419 // Currently, only RSA and DSA keys are checked for weakness, and our example
351 // weak size is 768. These could change in the future. 420 // weak size is 768. These could change in the future.
352 // 421 //
353 // Note that this means there may be false negatives: keys for other 422 // Note that this means there may be false negatives: keys for other
354 // algorithms and which are weak will pass this test. 423 // algorithms and which are weak will pass this test.
355 static bool IsWeakKeyType(const std::string& key_type) { 424 static bool IsWeakKeyType(const std::string& key_type) {
356 size_t pos = key_type.find("-"); 425 size_t pos = key_type.find("-");
357 std::string size = key_type.substr(0, pos); 426 std::string size = key_type.substr(0, pos);
358 std::string type = key_type.substr(pos + 1); 427 std::string type = key_type.substr(pos + 1);
359 428
360 if (type == "rsa" || type == "dsa") 429 if (type == "rsa" || type == "dsa")
361 return size == "768"; 430 return size == "768";
362 431
363 return false; 432 return false;
364 } 433 }
365 434
366 TEST_F(CertVerifyProcTest, RejectWeakKeys) { 435 TEST_P(CertVerifyProcInternalTest, RejectWeakKeys) {
367 base::FilePath certs_dir = GetTestCertsDirectory(); 436 base::FilePath certs_dir = GetTestCertsDirectory();
368 typedef std::vector<std::string> Strings; 437 typedef std::vector<std::string> Strings;
369 Strings key_types; 438 Strings key_types;
370 439
371 // generate-weak-test-chains.sh currently has: 440 // generate-weak-test-chains.sh currently has:
372 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" 441 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa"
373 // We must use the same key types here. The filenames generated look like: 442 // We must use the same key types here. The filenames generated look like:
374 // 2048-rsa-ee-by-768-rsa-intermediate.pem 443 // 2048-rsa-ee-by-768-rsa-intermediate.pem
375 key_types.push_back("768-rsa"); 444 key_types.push_back("768-rsa");
376 key_types.push_back("1024-rsa"); 445 key_types.push_back("1024-rsa");
377 key_types.push_back("2048-rsa"); 446 key_types.push_back("2048-rsa");
378 key_types.push_back("prime256v1-ecdsa"); 447 key_types.push_back("prime256v1-ecdsa");
379 448
380 // Add the root that signed the intermediates for this test. 449 // Add the root that signed the intermediates for this test.
381 scoped_refptr<X509Certificate> root_cert = 450 scoped_refptr<X509Certificate> root_cert =
382 ImportCertFromFile(certs_dir, "2048-rsa-root.pem"); 451 ImportCertFromFile(certs_dir, "2048-rsa-root.pem");
383 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); 452 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get());
384 ScopedTestRoot scoped_root(root_cert.get()); 453 ScopedTestRoot scoped_root(root_cert.get());
385 454
386 // Now test each chain. 455 // Now test each chain.
387 for (Strings::const_iterator ee_type = key_types.begin(); 456 for (Strings::const_iterator ee_type = key_types.begin();
388 ee_type != key_types.end(); ++ee_type) { 457 ee_type != key_types.end(); ++ee_type) {
389 for (Strings::const_iterator signer_type = key_types.begin(); 458 for (Strings::const_iterator signer_type = key_types.begin();
390 signer_type != key_types.end(); ++signer_type) { 459 signer_type != key_types.end(); ++signer_type) {
391 std::string basename = *ee_type + "-ee-by-" + *signer_type + 460 std::string basename =
392 "-intermediate.pem"; 461 *ee_type + "-ee-by-" + *signer_type + "-intermediate.pem";
393 SCOPED_TRACE(basename); 462 SCOPED_TRACE(basename);
394 scoped_refptr<X509Certificate> ee_cert = 463 scoped_refptr<X509Certificate> ee_cert =
395 ImportCertFromFile(certs_dir, basename); 464 ImportCertFromFile(certs_dir, basename);
396 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert.get()); 465 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert.get());
397 466
398 basename = *signer_type + "-intermediate.pem"; 467 basename = *signer_type + "-intermediate.pem";
399 scoped_refptr<X509Certificate> intermediate = 468 scoped_refptr<X509Certificate> intermediate =
400 ImportCertFromFile(certs_dir, basename); 469 ImportCertFromFile(certs_dir, basename);
401 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate.get()); 470 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate.get());
402 471
403 X509Certificate::OSCertHandles intermediates; 472 X509Certificate::OSCertHandles intermediates;
404 intermediates.push_back(intermediate->os_cert_handle()); 473 intermediates.push_back(intermediate->os_cert_handle());
405 scoped_refptr<X509Certificate> cert_chain = 474 scoped_refptr<X509Certificate> cert_chain =
406 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 475 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
407 intermediates); 476 intermediates);
408 477
409 CertVerifyResult verify_result; 478 CertVerifyResult verify_result;
410 int error = Verify(cert_chain.get(), 479 int error = Verify(cert_chain.get(), "127.0.0.1", 0, NULL,
411 "127.0.0.1", 480 CertificateList(), &verify_result);
412 0,
413 NULL,
414 empty_cert_list_,
415 &verify_result);
416 481
417 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { 482 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) {
418 EXPECT_NE(OK, error); 483 EXPECT_NE(OK, error);
419 EXPECT_EQ(CERT_STATUS_WEAK_KEY, 484 EXPECT_EQ(CERT_STATUS_WEAK_KEY,
420 verify_result.cert_status & CERT_STATUS_WEAK_KEY); 485 verify_result.cert_status & CERT_STATUS_WEAK_KEY);
421 EXPECT_EQ(WeakKeysAreInvalid() ? CERT_STATUS_INVALID : 0, 486 EXPECT_EQ(WeakKeysAreInvalid() ? CERT_STATUS_INVALID : 0,
422 verify_result.cert_status & CERT_STATUS_INVALID); 487 verify_result.cert_status & CERT_STATUS_INVALID);
423 } else { 488 } else {
424 EXPECT_THAT(error, IsOk()); 489 EXPECT_THAT(error, IsOk());
425 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); 490 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY);
426 } 491 }
427 } 492 }
428 } 493 }
429 } 494 }
430 495
431 // Regression test for http://crbug.com/108514. 496 // Regression test for http://crbug.com/108514.
432 #if defined(OS_MACOSX) && !defined(OS_IOS) 497 TEST_P(CertVerifyProcInternalTest, ExtraneousMD5RootCert) {
433 // Disabled on OS X - Security.framework doesn't ignore superflous certificates
434 // provided by servers. See CertVerifyProcTest.CybertrustGTERoot for further
435 // details.
436 #define MAYBE_ExtraneousMD5RootCert DISABLED_ExtraneousMD5RootCert
437 #else
438 #define MAYBE_ExtraneousMD5RootCert ExtraneousMD5RootCert
439 #endif
440 TEST_F(CertVerifyProcTest, MAYBE_ExtraneousMD5RootCert) {
441 if (!SupportsReturningVerifiedChain()) { 498 if (!SupportsReturningVerifiedChain()) {
442 LOG(INFO) << "Skipping this test in this platform."; 499 LOG(INFO) << "Skipping this test in this platform.";
443 return; 500 return;
444 } 501 }
445 502
503 if (verify_proc_type() == CERT_VERIFY_PROC_MAC) {
504 // Disabled on OS X - Security.framework doesn't ignore superflous
505 // certificates provided by servers.
506 // TODO(eroman): Is this still needed?
507 LOG(INFO) << "Skipping this test as Security.framework doesn't ignore "
508 "superflous certificates provided by servers.";
509 return;
510 }
511
446 base::FilePath certs_dir = GetTestCertsDirectory(); 512 base::FilePath certs_dir = GetTestCertsDirectory();
447 513
448 scoped_refptr<X509Certificate> server_cert = 514 scoped_refptr<X509Certificate> server_cert =
449 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); 515 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem");
450 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); 516 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get());
451 517
452 scoped_refptr<X509Certificate> extra_cert = 518 scoped_refptr<X509Certificate> extra_cert =
453 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); 519 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem");
454 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); 520 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get());
455 521
456 scoped_refptr<X509Certificate> root_cert = 522 scoped_refptr<X509Certificate> root_cert =
457 ImportCertFromFile(certs_dir, "cross-signed-root-sha256.pem"); 523 ImportCertFromFile(certs_dir, "cross-signed-root-sha256.pem");
458 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); 524 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert.get());
459 525
460 ScopedTestRoot scoped_root(root_cert.get()); 526 ScopedTestRoot scoped_root(root_cert.get());
461 527
462 X509Certificate::OSCertHandles intermediates; 528 X509Certificate::OSCertHandles intermediates;
463 intermediates.push_back(extra_cert->os_cert_handle()); 529 intermediates.push_back(extra_cert->os_cert_handle());
464 scoped_refptr<X509Certificate> cert_chain = 530 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
465 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 531 server_cert->os_cert_handle(), intermediates);
466 intermediates);
467 532
468 CertVerifyResult verify_result; 533 CertVerifyResult verify_result;
469 int flags = 0; 534 int flags = 0;
470 int error = Verify(cert_chain.get(), 535 int error = Verify(cert_chain.get(), "127.0.0.1", flags, NULL,
471 "127.0.0.1", 536 CertificateList(), &verify_result);
472 flags,
473 NULL,
474 empty_cert_list_,
475 &verify_result);
476 EXPECT_THAT(error, IsOk()); 537 EXPECT_THAT(error, IsOk());
477 538
478 // The extra MD5 root should be discarded 539 // The extra MD5 root should be discarded
479 ASSERT_TRUE(verify_result.verified_cert.get()); 540 ASSERT_TRUE(verify_result.verified_cert.get());
480 ASSERT_EQ(1u, 541 ASSERT_EQ(1u,
481 verify_result.verified_cert->GetIntermediateCertificates().size()); 542 verify_result.verified_cert->GetIntermediateCertificates().size());
482 EXPECT_TRUE(X509Certificate::IsSameOSCert( 543 EXPECT_TRUE(X509Certificate::IsSameOSCert(
483 verify_result.verified_cert->GetIntermediateCertificates().front(), 544 verify_result.verified_cert->GetIntermediateCertificates().front(),
484 root_cert->os_cert_handle())); 545 root_cert->os_cert_handle()));
485 546
486 EXPECT_FALSE(verify_result.has_md5); 547 EXPECT_FALSE(verify_result.has_md5);
487 } 548 }
488 549
489 // Test for bug 94673. 550 // Test for bug 94673.
490 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) { 551 TEST_P(CertVerifyProcInternalTest, GoogleDigiNotarTest) {
491 base::FilePath certs_dir = GetTestCertsDirectory(); 552 base::FilePath certs_dir = GetTestCertsDirectory();
492 553
493 scoped_refptr<X509Certificate> server_cert = 554 scoped_refptr<X509Certificate> server_cert =
494 ImportCertFromFile(certs_dir, "google_diginotar.pem"); 555 ImportCertFromFile(certs_dir, "google_diginotar.pem");
495 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); 556 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get());
496 557
497 scoped_refptr<X509Certificate> intermediate_cert = 558 scoped_refptr<X509Certificate> intermediate_cert =
498 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); 559 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem");
499 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert.get()); 560 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert.get());
500 561
501 X509Certificate::OSCertHandles intermediates; 562 X509Certificate::OSCertHandles intermediates;
502 intermediates.push_back(intermediate_cert->os_cert_handle()); 563 intermediates.push_back(intermediate_cert->os_cert_handle());
503 scoped_refptr<X509Certificate> cert_chain = 564 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
504 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 565 server_cert->os_cert_handle(), intermediates);
505 intermediates);
506 566
507 CertVerifyResult verify_result; 567 CertVerifyResult verify_result;
508 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED; 568 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED;
509 int error = Verify(cert_chain.get(), 569 int error = Verify(cert_chain.get(), "mail.google.com", flags, NULL,
510 "mail.google.com", 570 CertificateList(), &verify_result);
511 flags,
512 NULL,
513 empty_cert_list_,
514 &verify_result);
515 EXPECT_NE(OK, error); 571 EXPECT_NE(OK, error);
516 572
517 // Now turn off revocation checking. Certificate verification should still 573 // Now turn off revocation checking. Certificate verification should still
518 // fail. 574 // fail.
519 flags = 0; 575 flags = 0;
520 error = Verify(cert_chain.get(), 576 error = Verify(cert_chain.get(), "mail.google.com", flags, NULL,
521 "mail.google.com", 577 CertificateList(), &verify_result);
522 flags,
523 NULL,
524 empty_cert_list_,
525 &verify_result);
526 EXPECT_NE(OK, error); 578 EXPECT_NE(OK, error);
527 } 579 }
528 580
529 // Ensures the CertVerifyProc blacklist remains in sorted order, so that it 581 // Ensures the CertVerifyProc blacklist remains in sorted order, so that it
530 // can be binary-searched. 582 // can be binary-searched.
531 TEST_F(CertVerifyProcTest, BlacklistIsSorted) { 583 TEST(CertVerifyProcTest, BlacklistIsSorted) {
532 // Defines kBlacklistedSPKIs. 584 // Defines kBlacklistedSPKIs.
533 #include "net/cert/cert_verify_proc_blacklist.inc" 585 #include "net/cert/cert_verify_proc_blacklist.inc"
534 for (size_t i = 0; i < arraysize(kBlacklistedSPKIs) - 1; ++i) { 586 for (size_t i = 0; i < arraysize(kBlacklistedSPKIs) - 1; ++i) {
535 EXPECT_GT(0, memcmp(kBlacklistedSPKIs[i], kBlacklistedSPKIs[i + 1], 587 EXPECT_GT(0, memcmp(kBlacklistedSPKIs[i], kBlacklistedSPKIs[i + 1],
536 crypto::kSHA256Length)) 588 crypto::kSHA256Length))
537 << " at index " << i; 589 << " at index " << i;
538 } 590 }
539 } 591 }
540 592
541 TEST_F(CertVerifyProcTest, DigiNotarCerts) { 593 TEST(CertVerifyProcTest, DigiNotarCerts) {
542 static const char* const kDigiNotarFilenames[] = { 594 static const char* const kDigiNotarFilenames[] = {
543 "diginotar_root_ca.pem", 595 "diginotar_root_ca.pem", "diginotar_cyber_ca.pem",
544 "diginotar_cyber_ca.pem", 596 "diginotar_services_1024_ca.pem", "diginotar_pkioverheid.pem",
545 "diginotar_services_1024_ca.pem", 597 "diginotar_pkioverheid_g2.pem", NULL,
546 "diginotar_pkioverheid.pem",
547 "diginotar_pkioverheid_g2.pem",
548 NULL,
549 }; 598 };
550 599
551 base::FilePath certs_dir = GetTestCertsDirectory(); 600 base::FilePath certs_dir = GetTestCertsDirectory();
552 601
553 for (size_t i = 0; kDigiNotarFilenames[i]; i++) { 602 for (size_t i = 0; kDigiNotarFilenames[i]; i++) {
554 scoped_refptr<X509Certificate> diginotar_cert = 603 scoped_refptr<X509Certificate> diginotar_cert =
555 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]); 604 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]);
556 std::string der_bytes; 605 std::string der_bytes;
557 ASSERT_TRUE(X509Certificate::GetDEREncoded( 606 ASSERT_TRUE(X509Certificate::GetDEREncoded(diginotar_cert->os_cert_handle(),
558 diginotar_cert->os_cert_handle(), &der_bytes)); 607 &der_bytes));
559 608
560 base::StringPiece spki; 609 base::StringPiece spki;
561 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki)); 610 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki));
562 611
563 std::string spki_sha256 = crypto::SHA256HashString(spki.as_string()); 612 std::string spki_sha256 = crypto::SHA256HashString(spki.as_string());
564 613
565 HashValueVector public_keys; 614 HashValueVector public_keys;
566 HashValue hash(HASH_VALUE_SHA256); 615 HashValue hash(HASH_VALUE_SHA256);
567 ASSERT_EQ(hash.size(), spki_sha256.size()); 616 ASSERT_EQ(hash.size(), spki_sha256.size());
568 memcpy(hash.data(), spki_sha256.data(), spki_sha256.size()); 617 memcpy(hash.data(), spki_sha256.data(), spki_sha256.size());
569 public_keys.push_back(hash); 618 public_keys.push_back(hash);
570 619
571 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) << 620 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys))
572 "Public key not blocked for " << kDigiNotarFilenames[i]; 621 << "Public key not blocked for " << kDigiNotarFilenames[i];
573 } 622 }
574 } 623 }
575 624
576 TEST_F(CertVerifyProcTest, NameConstraintsOk) { 625 TEST_P(CertVerifyProcInternalTest, NameConstraintsOk) {
577 CertificateList ca_cert_list = 626 CertificateList ca_cert_list =
578 CreateCertificateListFromFile(GetTestCertsDirectory(), 627 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem",
579 "root_ca_cert.pem",
580 X509Certificate::FORMAT_AUTO); 628 X509Certificate::FORMAT_AUTO);
581 ASSERT_EQ(1U, ca_cert_list.size()); 629 ASSERT_EQ(1U, ca_cert_list.size());
582 ScopedTestRoot test_root(ca_cert_list[0].get()); 630 ScopedTestRoot test_root(ca_cert_list[0].get());
583 631
584 CertificateList cert_list = CreateCertificateListFromFile( 632 CertificateList cert_list = CreateCertificateListFromFile(
585 GetTestCertsDirectory(), "name_constraint_good.pem", 633 GetTestCertsDirectory(), "name_constraint_good.pem",
586 X509Certificate::FORMAT_AUTO); 634 X509Certificate::FORMAT_AUTO);
587 ASSERT_EQ(1U, cert_list.size()); 635 ASSERT_EQ(1U, cert_list.size());
588 636
589 X509Certificate::OSCertHandles intermediates; 637 X509Certificate::OSCertHandles intermediates;
590 scoped_refptr<X509Certificate> leaf = 638 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle(
591 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), 639 cert_list[0]->os_cert_handle(), intermediates);
592 intermediates);
593 640
594 int flags = 0; 641 int flags = 0;
595 CertVerifyResult verify_result; 642 CertVerifyResult verify_result;
596 int error = Verify(leaf.get(), 643 int error = Verify(leaf.get(), "test.example.com", flags, NULL,
597 "test.example.com", 644 CertificateList(), &verify_result);
598 flags,
599 NULL,
600 empty_cert_list_,
601 &verify_result);
602 EXPECT_THAT(error, IsOk()); 645 EXPECT_THAT(error, IsOk());
603 EXPECT_EQ(0U, verify_result.cert_status); 646 EXPECT_EQ(0U, verify_result.cert_status);
604 647
605 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL, 648 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL,
606 empty_cert_list_, &verify_result); 649 CertificateList(), &verify_result);
607 EXPECT_THAT(error, IsOk()); 650 EXPECT_THAT(error, IsOk());
608 EXPECT_EQ(0U, verify_result.cert_status); 651 EXPECT_EQ(0U, verify_result.cert_status);
609 } 652 }
610 653
611 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { 654 TEST_P(CertVerifyProcInternalTest, NameConstraintsFailure) {
612 if (!SupportsReturningVerifiedChain()) { 655 if (!SupportsReturningVerifiedChain()) {
613 LOG(INFO) << "Skipping this test in this platform."; 656 LOG(INFO) << "Skipping this test in this platform.";
614 return; 657 return;
615 } 658 }
616 659
617 CertificateList ca_cert_list = 660 CertificateList ca_cert_list =
618 CreateCertificateListFromFile(GetTestCertsDirectory(), 661 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem",
619 "root_ca_cert.pem",
620 X509Certificate::FORMAT_AUTO); 662 X509Certificate::FORMAT_AUTO);
621 ASSERT_EQ(1U, ca_cert_list.size()); 663 ASSERT_EQ(1U, ca_cert_list.size());
622 ScopedTestRoot test_root(ca_cert_list[0].get()); 664 ScopedTestRoot test_root(ca_cert_list[0].get());
623 665
624 CertificateList cert_list = CreateCertificateListFromFile( 666 CertificateList cert_list = CreateCertificateListFromFile(
625 GetTestCertsDirectory(), "name_constraint_bad.pem", 667 GetTestCertsDirectory(), "name_constraint_bad.pem",
626 X509Certificate::FORMAT_AUTO); 668 X509Certificate::FORMAT_AUTO);
627 ASSERT_EQ(1U, cert_list.size()); 669 ASSERT_EQ(1U, cert_list.size());
628 670
629 X509Certificate::OSCertHandles intermediates; 671 X509Certificate::OSCertHandles intermediates;
630 scoped_refptr<X509Certificate> leaf = 672 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle(
631 X509Certificate::CreateFromHandle(cert_list[0]->os_cert_handle(), 673 cert_list[0]->os_cert_handle(), intermediates);
632 intermediates);
633 674
634 int flags = 0; 675 int flags = 0;
635 CertVerifyResult verify_result; 676 CertVerifyResult verify_result;
636 int error = Verify(leaf.get(), 677 int error = Verify(leaf.get(), "test.example.com", flags, NULL,
637 "test.example.com", 678 CertificateList(), &verify_result);
638 flags,
639 NULL,
640 empty_cert_list_,
641 &verify_result);
642 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION)); 679 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION));
643 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, 680 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION,
644 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); 681 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION);
645 } 682 }
646 683
647 TEST_F(CertVerifyProcTest, TestHasTooLongValidity) { 684 TEST(CertVerifyProcTest, TestHasTooLongValidity) {
648 struct { 685 struct {
649 const char* const file; 686 const char* const file;
650 bool is_valid_too_long; 687 bool is_valid_too_long;
651 } tests[] = { 688 } tests[] = {
652 {"twitter-chain.pem", false}, 689 {"twitter-chain.pem", false},
653 {"start_after_expiry.pem", true}, 690 {"start_after_expiry.pem", true},
654 {"pre_br_validity_ok.pem", false}, 691 {"pre_br_validity_ok.pem", false},
655 {"pre_br_validity_bad_121.pem", true}, 692 {"pre_br_validity_bad_121.pem", true},
656 {"pre_br_validity_bad_2020.pem", true}, 693 {"pre_br_validity_bad_2020.pem", true},
657 {"10_year_validity.pem", false}, 694 {"10_year_validity.pem", false},
(...skipping 10 matching lines...) Expand all
668 scoped_refptr<X509Certificate> certificate = 705 scoped_refptr<X509Certificate> certificate =
669 ImportCertFromFile(certs_dir, tests[i].file); 706 ImportCertFromFile(certs_dir, tests[i].file);
670 SCOPED_TRACE(tests[i].file); 707 SCOPED_TRACE(tests[i].file);
671 ASSERT_TRUE(certificate); 708 ASSERT_TRUE(certificate);
672 EXPECT_EQ(tests[i].is_valid_too_long, 709 EXPECT_EQ(tests[i].is_valid_too_long,
673 CertVerifyProc::HasTooLongValidity(*certificate)); 710 CertVerifyProc::HasTooLongValidity(*certificate));
674 } 711 }
675 } 712 }
676 713
677 // TODO(crbug.com/610546): Fix and re-enable this test. 714 // TODO(crbug.com/610546): Fix and re-enable this test.
678 TEST_F(CertVerifyProcTest, DISABLED_TestKnownRoot) { 715 TEST_P(CertVerifyProcInternalTest, DISABLED_TestKnownRoot) {
679 if (!SupportsDetectingKnownRoots()) { 716 if (!SupportsDetectingKnownRoots()) {
680 LOG(INFO) << "Skipping this test on this platform."; 717 LOG(INFO) << "Skipping this test on this platform.";
681 return; 718 return;
682 } 719 }
683 720
684 base::FilePath certs_dir = GetTestCertsDirectory(); 721 base::FilePath certs_dir = GetTestCertsDirectory();
685 CertificateList certs = CreateCertificateListFromFile( 722 CertificateList certs = CreateCertificateListFromFile(
686 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); 723 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO);
687 ASSERT_EQ(3U, certs.size()); 724 ASSERT_EQ(3U, certs.size());
688 725
689 X509Certificate::OSCertHandles intermediates; 726 X509Certificate::OSCertHandles intermediates;
690 intermediates.push_back(certs[1]->os_cert_handle()); 727 intermediates.push_back(certs[1]->os_cert_handle());
691 728
692 scoped_refptr<X509Certificate> cert_chain = 729 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
693 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 730 certs[0]->os_cert_handle(), intermediates);
694 intermediates);
695 731
696 int flags = 0; 732 int flags = 0;
697 CertVerifyResult verify_result; 733 CertVerifyResult verify_result;
698 // 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
699 // against agl. See also PublicKeyHashes. 735 // against agl. See also PublicKeyHashes.
700 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, 736 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL,
701 empty_cert_list_, &verify_result); 737 CertificateList(), &verify_result);
702 EXPECT_THAT(error, IsOk()); 738 EXPECT_THAT(error, IsOk());
703 EXPECT_TRUE(verify_result.is_issued_by_known_root); 739 EXPECT_TRUE(verify_result.is_issued_by_known_root);
704 } 740 }
705 741
706 // TODO(crbug.com/610546): Fix and re-enable this test. 742 // TODO(crbug.com/610546): Fix and re-enable this test.
707 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) { 743 TEST_P(CertVerifyProcInternalTest, DISABLED_PublicKeyHashes) {
708 if (!SupportsReturningVerifiedChain()) { 744 if (!SupportsReturningVerifiedChain()) {
709 LOG(INFO) << "Skipping this test in this platform."; 745 LOG(INFO) << "Skipping this test in this platform.";
710 return; 746 return;
711 } 747 }
712 748
713 base::FilePath certs_dir = GetTestCertsDirectory(); 749 base::FilePath certs_dir = GetTestCertsDirectory();
714 CertificateList certs = CreateCertificateListFromFile( 750 CertificateList certs = CreateCertificateListFromFile(
715 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); 751 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO);
716 ASSERT_EQ(3U, certs.size()); 752 ASSERT_EQ(3U, certs.size());
717 753
718 X509Certificate::OSCertHandles intermediates; 754 X509Certificate::OSCertHandles intermediates;
719 intermediates.push_back(certs[1]->os_cert_handle()); 755 intermediates.push_back(certs[1]->os_cert_handle());
720 756
721 scoped_refptr<X509Certificate> cert_chain = 757 scoped_refptr<X509Certificate> cert_chain = X509Certificate::CreateFromHandle(
722 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 758 certs[0]->os_cert_handle(), intermediates);
723 intermediates);
724 int flags = 0; 759 int flags = 0;
725 CertVerifyResult verify_result; 760 CertVerifyResult verify_result;
726 761
727 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug 762 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug
728 // against agl. See also TestKnownRoot. 763 // against agl. See also TestKnownRoot.
729 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, 764 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL,
730 empty_cert_list_, &verify_result); 765 CertificateList(), &verify_result);
731 EXPECT_THAT(error, IsOk()); 766 EXPECT_THAT(error, IsOk());
732 ASSERT_LE(3U, verify_result.public_key_hashes.size()); 767 ASSERT_LE(3U, verify_result.public_key_hashes.size());
733 768
734 HashValueVector sha1_hashes; 769 HashValueVector sha1_hashes;
735 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) { 770 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) {
736 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1) 771 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1)
737 continue; 772 continue;
738 sha1_hashes.push_back(verify_result.public_key_hashes[i]); 773 sha1_hashes.push_back(verify_result.public_key_hashes[i]);
739 } 774 }
740 ASSERT_LE(3u, sha1_hashes.size()); 775 ASSERT_LE(3u, sha1_hashes.size());
(...skipping 13 matching lines...) Expand all
754 789
755 for (size_t i = 0; i < 3; ++i) { 790 for (size_t i = 0; i < 3; ++i) {
756 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), 791 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length),
757 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); 792 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length));
758 } 793 }
759 } 794 }
760 795
761 // A regression test for http://crbug.com/70293. 796 // A regression test for http://crbug.com/70293.
762 // The Key Usage extension in this RSA SSL server certificate does not have 797 // The Key Usage extension in this RSA SSL server certificate does not have
763 // the keyEncipherment bit. 798 // the keyEncipherment bit.
764 TEST_F(CertVerifyProcTest, InvalidKeyUsage) { 799 TEST_P(CertVerifyProcInternalTest, InvalidKeyUsage) {
765 base::FilePath certs_dir = GetTestCertsDirectory(); 800 base::FilePath certs_dir = GetTestCertsDirectory();
766 801
767 scoped_refptr<X509Certificate> server_cert = 802 scoped_refptr<X509Certificate> server_cert =
768 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); 803 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der");
769 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); 804 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get());
770 805
771 int flags = 0; 806 int flags = 0;
772 CertVerifyResult verify_result; 807 CertVerifyResult verify_result;
773 int error = Verify(server_cert.get(), 808 int error = Verify(server_cert.get(), "jira.aquameta.com", flags, NULL,
774 "jira.aquameta.com", 809 CertificateList(), &verify_result);
775 flags, 810
776 NULL, 811 // TODO(eroman): Change the test data so results are consistent across
777 empty_cert_list_, 812 // verifiers.
778 &verify_result); 813 if (verify_proc_type() == CERT_VERIFY_PROC_OPENSSL) {
779 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) 814 // This certificate has two errors: "invalid key usage" and "untrusted CA".
780 // This certificate has two errors: "invalid key usage" and "untrusted CA". 815 // However, OpenSSL returns only one (the latter), and we can't detect
781 // However, OpenSSL returns only one (the latter), and we can't detect 816 // the other errors.
782 // the other errors. 817 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID));
783 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); 818 } else {
784 #else 819 EXPECT_THAT(error, IsError(ERR_CERT_INVALID));
785 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); 820 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
786 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 821 }
787 #endif
788 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors 822 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors
789 // from NSS. 823 // from NSS.
790 #if !defined(USE_NSS_CERTS) && !defined(OS_IOS) && !defined(OS_ANDROID) 824 if (verify_proc_type() != CERT_VERIFY_PROC_NSS &&
791 // The certificate is issued by an unknown CA. 825 verify_proc_type() != CERT_VERIFY_PROC_IOS &&
792 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); 826 verify_proc_type() != CERT_VERIFY_PROC_ANDROID) {
793 #endif 827 // The certificate is issued by an unknown CA.
828 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
829 }
794 } 830 }
795 831
796 // Basic test for returning the chain in CertVerifyResult. Note that the 832 // Basic test for returning the chain in CertVerifyResult. Note that the
797 // returned chain may just be a reflection of the originally supplied chain; 833 // returned chain may just be a reflection of the originally supplied chain;
798 // that is, if any errors occur, the default chain returned is an exact copy 834 // that is, if any errors occur, the default chain returned is an exact copy
799 // of the certificate to be verified. The remaining VerifyReturn* tests are 835 // of the certificate to be verified. The remaining VerifyReturn* tests are
800 // used to ensure that the actual, verified chain is being returned by 836 // used to ensure that the actual, verified chain is being returned by
801 // Verify(). 837 // Verify().
802 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { 838 TEST_P(CertVerifyProcInternalTest, VerifyReturnChainBasic) {
803 if (!SupportsReturningVerifiedChain()) { 839 if (!SupportsReturningVerifiedChain()) {
804 LOG(INFO) << "Skipping this test in this platform."; 840 LOG(INFO) << "Skipping this test in this platform.";
805 return; 841 return;
806 } 842 }
807 843
808 base::FilePath certs_dir = GetTestCertsDirectory(); 844 base::FilePath certs_dir = GetTestCertsDirectory();
809 CertificateList certs = CreateCertificateListFromFile( 845 CertificateList certs = CreateCertificateListFromFile(
810 certs_dir, "x509_verify_results.chain.pem", 846 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO);
811 X509Certificate::FORMAT_AUTO);
812 ASSERT_EQ(3U, certs.size()); 847 ASSERT_EQ(3U, certs.size());
813 848
814 X509Certificate::OSCertHandles intermediates; 849 X509Certificate::OSCertHandles intermediates;
815 intermediates.push_back(certs[1]->os_cert_handle()); 850 intermediates.push_back(certs[1]->os_cert_handle());
816 intermediates.push_back(certs[2]->os_cert_handle()); 851 intermediates.push_back(certs[2]->os_cert_handle());
817 852
818 ScopedTestRoot scoped_root(certs[2].get()); 853 ScopedTestRoot scoped_root(certs[2].get());
819 854
820 scoped_refptr<X509Certificate> google_full_chain = 855 scoped_refptr<X509Certificate> google_full_chain =
821 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 856 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
822 intermediates); 857 intermediates);
823 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); 858 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get());
824 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); 859 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
825 860
826 CertVerifyResult verify_result; 861 CertVerifyResult verify_result;
827 EXPECT_EQ(static_cast<X509Certificate*>(NULL), 862 EXPECT_EQ(static_cast<X509Certificate*>(NULL),
828 verify_result.verified_cert.get()); 863 verify_result.verified_cert.get());
829 int error = Verify(google_full_chain.get(), 864 int error = Verify(google_full_chain.get(), "127.0.0.1", 0, NULL,
830 "127.0.0.1", 865 CertificateList(), &verify_result);
831 0,
832 NULL,
833 empty_cert_list_,
834 &verify_result);
835 EXPECT_THAT(error, IsOk()); 866 EXPECT_THAT(error, IsOk());
836 ASSERT_NE(static_cast<X509Certificate*>(NULL), 867 ASSERT_NE(static_cast<X509Certificate*>(NULL),
837 verify_result.verified_cert.get()); 868 verify_result.verified_cert.get());
838 869
839 EXPECT_NE(google_full_chain, verify_result.verified_cert); 870 EXPECT_NE(google_full_chain, verify_result.verified_cert);
840 EXPECT_TRUE(X509Certificate::IsSameOSCert( 871 EXPECT_TRUE(X509Certificate::IsSameOSCert(
841 google_full_chain->os_cert_handle(), 872 google_full_chain->os_cert_handle(),
842 verify_result.verified_cert->os_cert_handle())); 873 verify_result.verified_cert->os_cert_handle()));
843 const X509Certificate::OSCertHandles& return_intermediates = 874 const X509Certificate::OSCertHandles& return_intermediates =
844 verify_result.verified_cert->GetIntermediateCertificates(); 875 verify_result.verified_cert->GetIntermediateCertificates();
845 ASSERT_EQ(2U, return_intermediates.size()); 876 ASSERT_EQ(2U, return_intermediates.size());
846 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 877 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
847 certs[1]->os_cert_handle())); 878 certs[1]->os_cert_handle()));
848 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 879 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
849 certs[2]->os_cert_handle())); 880 certs[2]->os_cert_handle()));
850 } 881 }
851 882
852 // Test that certificates issued for 'intranet' names (that is, containing no 883 // Test that certificates issued for 'intranet' names (that is, containing no
853 // known public registry controlled domain information) issued by well-known 884 // known public registry controlled domain information) issued by well-known
854 // CAs are flagged appropriately, while certificates that are issued by 885 // CAs are flagged appropriately, while certificates that are issued by
855 // internal CAs are not flagged. 886 // internal CAs are not flagged.
856 TEST_F(CertVerifyProcTest, IntranetHostsRejected) { 887 TEST(CertVerifyProcTest, IntranetHostsRejected) {
857 if (!SupportsDetectingKnownRoots()) {
858 LOG(INFO) << "Skipping this test in this platform.";
859 return;
860 }
861
862 CertificateList cert_list = CreateCertificateListFromFile( 888 CertificateList cert_list = CreateCertificateListFromFile(
863 GetTestCertsDirectory(), "reject_intranet_hosts.pem", 889 GetTestCertsDirectory(), "reject_intranet_hosts.pem",
864 X509Certificate::FORMAT_AUTO); 890 X509Certificate::FORMAT_AUTO);
865 ASSERT_EQ(1U, cert_list.size()); 891 ASSERT_EQ(1U, cert_list.size());
866 scoped_refptr<X509Certificate> cert(cert_list[0]); 892 scoped_refptr<X509Certificate> cert(cert_list[0]);
867 893
868 CertVerifyResult verify_result; 894 CertVerifyResult verify_result;
869 int error = 0; 895 int error = 0;
870 896
871 // Intranet names for public CAs should be flagged: 897 // Intranet names for public CAs should be flagged:
872 CertVerifyResult dummy_result; 898 CertVerifyResult dummy_result;
873 dummy_result.is_issued_by_known_root = true; 899 dummy_result.is_issued_by_known_root = true;
874 verify_proc_ = new MockCertVerifyProc(dummy_result); 900 scoped_refptr<CertVerifyProc> verify_proc =
875 error = 901 new MockCertVerifyProc(dummy_result);
876 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); 902 error = verify_proc->Verify(cert.get(), "intranet", std::string(), 0, NULL,
903 CertificateList(), &verify_result);
877 EXPECT_THAT(error, IsOk()); 904 EXPECT_THAT(error, IsOk());
878 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); 905 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME);
879 906
880 // However, if the CA is not well known, these should not be flagged: 907 // However, if the CA is not well known, these should not be flagged:
881 dummy_result.Reset(); 908 dummy_result.Reset();
882 dummy_result.is_issued_by_known_root = false; 909 dummy_result.is_issued_by_known_root = false;
883 verify_proc_ = new MockCertVerifyProc(dummy_result); 910 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result));
884 error = 911 error = verify_proc->Verify(cert.get(), "intranet", std::string(), 0, NULL,
885 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result); 912 CertificateList(), &verify_result);
886 EXPECT_THAT(error, IsOk()); 913 EXPECT_THAT(error, IsOk());
887 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); 914 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME);
888 } 915 }
889 916
890 // While all SHA-1 certificates should be rejected, in the event that there 917 // While all SHA-1 certificates should be rejected, in the event that there
891 // emerges some unexpected bug, test that the 'legacy' behaviour works 918 // emerges some unexpected bug, test that the 'legacy' behaviour works
892 // correctly - rejecting all SHA-1 certificates from publicly trusted CAs 919 // correctly - rejecting all SHA-1 certificates from publicly trusted CAs
893 // that were issued after 1 January 2016, while still allowing those from 920 // that were issued after 1 January 2016, while still allowing those from
894 // before that date, with SHA-1 in the intermediate, or from an enterprise 921 // before that date, with SHA-1 in the intermediate, or from an enterprise
895 // CA. 922 // CA.
896 TEST_F(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecationLegacyMode) { 923 TEST(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecationLegacyMode) {
897 base::test::ScopedFeatureList scoped_feature_list; 924 base::test::ScopedFeatureList scoped_feature_list;
898 scoped_feature_list.InitAndEnableFeature(CertVerifyProc::kSHA1LegacyMode); 925 scoped_feature_list.InitAndEnableFeature(CertVerifyProc::kSHA1LegacyMode);
899 926
900 CertVerifyResult dummy_result; 927 CertVerifyResult dummy_result;
901 CertVerifyResult verify_result; 928 CertVerifyResult verify_result;
902 int error = 0; 929 int error = 0;
903 scoped_refptr<X509Certificate> cert; 930 scoped_refptr<X509Certificate> cert;
904 931
905 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 932 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016
906 // are accepted. 933 // are accepted.
907 verify_result.Reset(); 934 verify_result.Reset();
908 dummy_result.Reset(); 935 dummy_result.Reset();
909 dummy_result.is_issued_by_known_root = true; 936 dummy_result.is_issued_by_known_root = true;
910 dummy_result.has_sha1 = true; 937 dummy_result.has_sha1 = true;
911 dummy_result.has_sha1_leaf = true; 938 dummy_result.has_sha1_leaf = true;
912 verify_proc_ = new MockCertVerifyProc(dummy_result); 939 scoped_refptr<CertVerifyProc> verify_proc =
940 new MockCertVerifyProc(dummy_result);
913 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), 941 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(),
914 "sha1_dec_2015.pem", 942 "sha1_dec_2015.pem",
915 X509Certificate::FORMAT_AUTO); 943 X509Certificate::FORMAT_AUTO);
916 ASSERT_TRUE(cert); 944 ASSERT_TRUE(cert);
917 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, 945 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL,
918 &verify_result); 946 CertificateList(), &verify_result);
919 EXPECT_THAT(error, IsOk()); 947 EXPECT_THAT(error, IsOk());
920 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); 948 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT);
921 949
922 // Publicly trusted SHA-1 leaf certificates issued on/after 1 January 2016 950 // Publicly trusted SHA-1 leaf certificates issued on/after 1 January 2016
923 // are rejected. 951 // are rejected.
924 verify_result.Reset(); 952 verify_result.Reset();
925 dummy_result.Reset(); 953 dummy_result.Reset();
926 dummy_result.is_issued_by_known_root = true; 954 dummy_result.is_issued_by_known_root = true;
927 dummy_result.has_sha1 = true; 955 dummy_result.has_sha1 = true;
928 dummy_result.has_sha1_leaf = true; 956 dummy_result.has_sha1_leaf = true;
929 verify_proc_ = new MockCertVerifyProc(dummy_result); 957 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result));
930 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), 958 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(),
931 "sha1_jan_2016.pem", 959 "sha1_jan_2016.pem",
932 X509Certificate::FORMAT_AUTO); 960 X509Certificate::FORMAT_AUTO);
933 ASSERT_TRUE(cert); 961 ASSERT_TRUE(cert);
934 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, 962 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL,
935 &verify_result); 963 CertificateList(), &verify_result);
936 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); 964 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM));
937 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); 965 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
938 966
939 // Enterprise issued SHA-1 leaf certificates issued on/after 1 January 2016 967 // Enterprise issued SHA-1 leaf certificates issued on/after 1 January 2016
940 // remain accepted. 968 // remain accepted.
941 verify_result.Reset(); 969 verify_result.Reset();
942 dummy_result.Reset(); 970 dummy_result.Reset();
943 dummy_result.is_issued_by_known_root = false; 971 dummy_result.is_issued_by_known_root = false;
944 dummy_result.has_sha1 = true; 972 dummy_result.has_sha1 = true;
945 dummy_result.has_sha1_leaf = true; 973 dummy_result.has_sha1_leaf = true;
946 verify_proc_ = new MockCertVerifyProc(dummy_result); 974 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result));
947 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), 975 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(),
948 "sha1_jan_2016.pem", 976 "sha1_jan_2016.pem",
949 X509Certificate::FORMAT_AUTO); 977 X509Certificate::FORMAT_AUTO);
950 ASSERT_TRUE(cert); 978 ASSERT_TRUE(cert);
951 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, 979 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL,
952 &verify_result); 980 CertificateList(), &verify_result);
953 EXPECT_THAT(error, IsOk()); 981 EXPECT_THAT(error, IsOk());
954 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); 982 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT);
955 983
956 // Publicly trusted SHA-1 intermediates issued on/after 1 January 2016 are, 984 // Publicly trusted SHA-1 intermediates issued on/after 1 January 2016 are,
957 // unfortunately, accepted. This can arise due to OS path building quirks. 985 // unfortunately, accepted. This can arise due to OS path building quirks.
958 verify_result.Reset(); 986 verify_result.Reset();
959 dummy_result.Reset(); 987 dummy_result.Reset();
960 dummy_result.is_issued_by_known_root = true; 988 dummy_result.is_issued_by_known_root = true;
961 dummy_result.has_sha1 = true; 989 dummy_result.has_sha1 = true;
962 dummy_result.has_sha1_leaf = false; 990 dummy_result.has_sha1_leaf = false;
963 verify_proc_ = new MockCertVerifyProc(dummy_result); 991 verify_proc = make_scoped_refptr(new MockCertVerifyProc(dummy_result));
964 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(), 992 cert = CreateCertificateChainFromFile(GetTestCertsDirectory(),
965 "sha1_jan_2016.pem", 993 "sha1_jan_2016.pem",
966 X509Certificate::FORMAT_AUTO); 994 X509Certificate::FORMAT_AUTO);
967 ASSERT_TRUE(cert); 995 ASSERT_TRUE(cert);
968 error = Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, 996 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), 0, NULL,
969 &verify_result); 997 CertificateList(), &verify_result);
970 EXPECT_THAT(error, IsOk()); 998 EXPECT_THAT(error, IsOk());
971 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); 999 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT);
972 } 1000 }
973 1001
974 // Test that the certificate returned in CertVerifyResult is able to reorder 1002 // Test that the certificate returned in CertVerifyResult is able to reorder
975 // certificates that are not ordered from end-entity to root. While this is 1003 // certificates that are not ordered from end-entity to root. While this is
976 // a protocol violation if sent during a TLS handshake, if multiple sources 1004 // a protocol violation if sent during a TLS handshake, if multiple sources
977 // of intermediate certificates are combined, it's possible that order may 1005 // of intermediate certificates are combined, it's possible that order may
978 // not be maintained. 1006 // not be maintained.
979 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { 1007 TEST_P(CertVerifyProcInternalTest, VerifyReturnChainProperlyOrdered) {
980 if (!SupportsReturningVerifiedChain()) { 1008 if (!SupportsReturningVerifiedChain()) {
981 LOG(INFO) << "Skipping this test in this platform."; 1009 LOG(INFO) << "Skipping this test in this platform.";
982 return; 1010 return;
983 } 1011 }
984 1012
985 base::FilePath certs_dir = GetTestCertsDirectory(); 1013 base::FilePath certs_dir = GetTestCertsDirectory();
986 CertificateList certs = CreateCertificateListFromFile( 1014 CertificateList certs = CreateCertificateListFromFile(
987 certs_dir, "x509_verify_results.chain.pem", 1015 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO);
988 X509Certificate::FORMAT_AUTO);
989 ASSERT_EQ(3U, certs.size()); 1016 ASSERT_EQ(3U, certs.size());
990 1017
991 // Construct the chain out of order. 1018 // Construct the chain out of order.
992 X509Certificate::OSCertHandles intermediates; 1019 X509Certificate::OSCertHandles intermediates;
993 intermediates.push_back(certs[2]->os_cert_handle()); 1020 intermediates.push_back(certs[2]->os_cert_handle());
994 intermediates.push_back(certs[1]->os_cert_handle()); 1021 intermediates.push_back(certs[1]->os_cert_handle());
995 1022
996 ScopedTestRoot scoped_root(certs[2].get()); 1023 ScopedTestRoot scoped_root(certs[2].get());
997 1024
998 scoped_refptr<X509Certificate> google_full_chain = 1025 scoped_refptr<X509Certificate> google_full_chain =
999 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1026 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1000 intermediates); 1027 intermediates);
1001 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); 1028 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get());
1002 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); 1029 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1003 1030
1004 CertVerifyResult verify_result; 1031 CertVerifyResult verify_result;
1005 EXPECT_EQ(static_cast<X509Certificate*>(NULL), 1032 EXPECT_EQ(static_cast<X509Certificate*>(NULL),
1006 verify_result.verified_cert.get()); 1033 verify_result.verified_cert.get());
1007 int error = Verify(google_full_chain.get(), 1034 int error = Verify(google_full_chain.get(), "127.0.0.1", 0, NULL,
1008 "127.0.0.1", 1035 CertificateList(), &verify_result);
1009 0,
1010 NULL,
1011 empty_cert_list_,
1012 &verify_result);
1013 EXPECT_THAT(error, IsOk()); 1036 EXPECT_THAT(error, IsOk());
1014 ASSERT_NE(static_cast<X509Certificate*>(NULL), 1037 ASSERT_NE(static_cast<X509Certificate*>(NULL),
1015 verify_result.verified_cert.get()); 1038 verify_result.verified_cert.get());
1016 1039
1017 EXPECT_NE(google_full_chain, verify_result.verified_cert); 1040 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1018 EXPECT_TRUE(X509Certificate::IsSameOSCert( 1041 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1019 google_full_chain->os_cert_handle(), 1042 google_full_chain->os_cert_handle(),
1020 verify_result.verified_cert->os_cert_handle())); 1043 verify_result.verified_cert->os_cert_handle()));
1021 const X509Certificate::OSCertHandles& return_intermediates = 1044 const X509Certificate::OSCertHandles& return_intermediates =
1022 verify_result.verified_cert->GetIntermediateCertificates(); 1045 verify_result.verified_cert->GetIntermediateCertificates();
1023 ASSERT_EQ(2U, return_intermediates.size()); 1046 ASSERT_EQ(2U, return_intermediates.size());
1024 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 1047 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1025 certs[1]->os_cert_handle())); 1048 certs[1]->os_cert_handle()));
1026 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 1049 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1027 certs[2]->os_cert_handle())); 1050 certs[2]->os_cert_handle()));
1028 } 1051 }
1029 1052
1030 // Test that Verify() filters out certificates which are not related to 1053 // Test that Verify() filters out certificates which are not related to
1031 // or part of the certificate chain being verified. 1054 // or part of the certificate chain being verified.
1032 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { 1055 TEST_P(CertVerifyProcInternalTest, VerifyReturnChainFiltersUnrelatedCerts) {
1033 if (!SupportsReturningVerifiedChain()) { 1056 if (!SupportsReturningVerifiedChain()) {
1034 LOG(INFO) << "Skipping this test in this platform."; 1057 LOG(INFO) << "Skipping this test in this platform.";
1035 return; 1058 return;
1036 } 1059 }
1037 1060
1038 base::FilePath certs_dir = GetTestCertsDirectory(); 1061 base::FilePath certs_dir = GetTestCertsDirectory();
1039 CertificateList certs = CreateCertificateListFromFile( 1062 CertificateList certs = CreateCertificateListFromFile(
1040 certs_dir, "x509_verify_results.chain.pem", 1063 certs_dir, "x509_verify_results.chain.pem", X509Certificate::FORMAT_AUTO);
1041 X509Certificate::FORMAT_AUTO);
1042 ASSERT_EQ(3U, certs.size()); 1064 ASSERT_EQ(3U, certs.size());
1043 ScopedTestRoot scoped_root(certs[2].get()); 1065 ScopedTestRoot scoped_root(certs[2].get());
1044 1066
1045 scoped_refptr<X509Certificate> unrelated_certificate = 1067 scoped_refptr<X509Certificate> unrelated_certificate =
1046 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem"); 1068 ImportCertFromFile(certs_dir, "duplicate_cn_1.pem");
1047 scoped_refptr<X509Certificate> unrelated_certificate2 = 1069 scoped_refptr<X509Certificate> unrelated_certificate2 =
1048 ImportCertFromFile(certs_dir, "aia-cert.pem"); 1070 ImportCertFromFile(certs_dir, "aia-cert.pem");
1049 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate.get()); 1071 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate.get());
1050 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate2.get()); 1072 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_certificate2.get());
1051 1073
1052 // Interject unrelated certificates into the list of intermediates. 1074 // Interject unrelated certificates into the list of intermediates.
1053 X509Certificate::OSCertHandles intermediates; 1075 X509Certificate::OSCertHandles intermediates;
1054 intermediates.push_back(unrelated_certificate->os_cert_handle()); 1076 intermediates.push_back(unrelated_certificate->os_cert_handle());
1055 intermediates.push_back(certs[1]->os_cert_handle()); 1077 intermediates.push_back(certs[1]->os_cert_handle());
1056 intermediates.push_back(unrelated_certificate2->os_cert_handle()); 1078 intermediates.push_back(unrelated_certificate2->os_cert_handle());
1057 intermediates.push_back(certs[2]->os_cert_handle()); 1079 intermediates.push_back(certs[2]->os_cert_handle());
1058 1080
1059 scoped_refptr<X509Certificate> google_full_chain = 1081 scoped_refptr<X509Certificate> google_full_chain =
1060 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), 1082 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1061 intermediates); 1083 intermediates);
1062 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get()); 1084 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain.get());
1063 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); 1085 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size());
1064 1086
1065 CertVerifyResult verify_result; 1087 CertVerifyResult verify_result;
1066 EXPECT_EQ(static_cast<X509Certificate*>(NULL), 1088 EXPECT_EQ(static_cast<X509Certificate*>(NULL),
1067 verify_result.verified_cert.get()); 1089 verify_result.verified_cert.get());
1068 int error = Verify(google_full_chain.get(), 1090 int error = Verify(google_full_chain.get(), "127.0.0.1", 0, NULL,
1069 "127.0.0.1", 1091 CertificateList(), &verify_result);
1070 0,
1071 NULL,
1072 empty_cert_list_,
1073 &verify_result);
1074 EXPECT_THAT(error, IsOk()); 1092 EXPECT_THAT(error, IsOk());
1075 ASSERT_NE(static_cast<X509Certificate*>(NULL), 1093 ASSERT_NE(static_cast<X509Certificate*>(NULL),
1076 verify_result.verified_cert.get()); 1094 verify_result.verified_cert.get());
1077 1095
1078 EXPECT_NE(google_full_chain, verify_result.verified_cert); 1096 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1079 EXPECT_TRUE(X509Certificate::IsSameOSCert( 1097 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1080 google_full_chain->os_cert_handle(), 1098 google_full_chain->os_cert_handle(),
1081 verify_result.verified_cert->os_cert_handle())); 1099 verify_result.verified_cert->os_cert_handle()));
1082 const X509Certificate::OSCertHandles& return_intermediates = 1100 const X509Certificate::OSCertHandles& return_intermediates =
1083 verify_result.verified_cert->GetIntermediateCertificates(); 1101 verify_result.verified_cert->GetIntermediateCertificates();
1084 ASSERT_EQ(2U, return_intermediates.size()); 1102 ASSERT_EQ(2U, return_intermediates.size());
1085 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], 1103 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1086 certs[1]->os_cert_handle())); 1104 certs[1]->os_cert_handle()));
1087 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], 1105 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1088 certs[2]->os_cert_handle())); 1106 certs[2]->os_cert_handle()));
1089 } 1107 }
1090 1108
1091 TEST_F(CertVerifyProcTest, AdditionalTrustAnchors) { 1109 TEST_P(CertVerifyProcInternalTest, AdditionalTrustAnchors) {
1092 if (!SupportsAdditionalTrustAnchors()) { 1110 if (!SupportsAdditionalTrustAnchors()) {
1093 LOG(INFO) << "Skipping this test in this platform."; 1111 LOG(INFO) << "Skipping this test in this platform.";
1094 return; 1112 return;
1095 } 1113 }
1096 1114
1097 // |ca_cert| is the issuer of |cert|. 1115 // |ca_cert| is the issuer of |cert|.
1098 CertificateList ca_cert_list = CreateCertificateListFromFile( 1116 CertificateList ca_cert_list =
1099 GetTestCertsDirectory(), "root_ca_cert.pem", 1117 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem",
1100 X509Certificate::FORMAT_AUTO); 1118 X509Certificate::FORMAT_AUTO);
1101 ASSERT_EQ(1U, ca_cert_list.size()); 1119 ASSERT_EQ(1U, ca_cert_list.size());
1102 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]); 1120 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]);
1103 1121
1104 CertificateList cert_list = CreateCertificateListFromFile( 1122 CertificateList cert_list = CreateCertificateListFromFile(
1105 GetTestCertsDirectory(), "ok_cert.pem", 1123 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO);
1106 X509Certificate::FORMAT_AUTO);
1107 ASSERT_EQ(1U, cert_list.size()); 1124 ASSERT_EQ(1U, cert_list.size());
1108 scoped_refptr<X509Certificate> cert(cert_list[0]); 1125 scoped_refptr<X509Certificate> cert(cert_list[0]);
1109 1126
1110 // Verification of |cert| fails when |ca_cert| is not in the trust anchors 1127 // Verification of |cert| fails when |ca_cert| is not in the trust anchors
1111 // list. 1128 // list.
1112 int flags = 0; 1129 int flags = 0;
1113 CertVerifyResult verify_result; 1130 CertVerifyResult verify_result;
1114 int error = Verify( 1131 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, CertificateList(),
1115 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); 1132 &verify_result);
1116 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); 1133 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID));
1117 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); 1134 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status);
1118 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); 1135 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor);
1119 1136
1120 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass. 1137 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass.
1121 CertificateList trust_anchors; 1138 CertificateList trust_anchors;
1122 trust_anchors.push_back(ca_cert); 1139 trust_anchors.push_back(ca_cert);
1123 error = Verify( 1140 error = Verify(cert.get(), "127.0.0.1", flags, NULL, trust_anchors,
1124 cert.get(), "127.0.0.1", flags, NULL, trust_anchors, &verify_result); 1141 &verify_result);
1125 EXPECT_THAT(error, IsOk()); 1142 EXPECT_THAT(error, IsOk());
1126 EXPECT_EQ(0U, verify_result.cert_status); 1143 EXPECT_EQ(0U, verify_result.cert_status);
1127 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor); 1144 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor);
1128 1145
1129 // Clearing the |trust_anchors| makes verification fail again (the cache 1146 // Clearing the |trust_anchors| makes verification fail again (the cache
1130 // should be skipped). 1147 // should be skipped).
1131 error = Verify( 1148 error = Verify(cert.get(), "127.0.0.1", flags, NULL, CertificateList(),
1132 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); 1149 &verify_result);
1133 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); 1150 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID));
1134 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); 1151 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status);
1135 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); 1152 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor);
1136 } 1153 }
1137 1154
1138 // Tests that certificates issued by user-supplied roots are not flagged as 1155 // Tests that certificates issued by user-supplied roots are not flagged as
1139 // issued by a known root. This should pass whether or not the platform supports 1156 // issued by a known root. This should pass whether or not the platform supports
1140 // detecting known roots. 1157 // detecting known roots.
1141 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { 1158 TEST_P(CertVerifyProcInternalTest, IsIssuedByKnownRootIgnoresTestRoots) {
1142 // Load root_ca_cert.pem into the test root store. 1159 // Load root_ca_cert.pem into the test root store.
1143 ScopedTestRoot test_root( 1160 ScopedTestRoot test_root(
1144 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); 1161 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get());
1145 1162
1146 scoped_refptr<X509Certificate> cert( 1163 scoped_refptr<X509Certificate> cert(
1147 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 1164 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
1148 1165
1149 // Verification should pass. 1166 // Verification should pass.
1150 int flags = 0; 1167 int flags = 0;
1151 CertVerifyResult verify_result; 1168 CertVerifyResult verify_result;
1152 int error = Verify( 1169 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, CertificateList(),
1153 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); 1170 &verify_result);
1154 EXPECT_THAT(error, IsOk()); 1171 EXPECT_THAT(error, IsOk());
1155 EXPECT_EQ(0U, verify_result.cert_status); 1172 EXPECT_EQ(0U, verify_result.cert_status);
1156 // But should not be marked as a known root. 1173 // But should not be marked as a known root.
1157 EXPECT_FALSE(verify_result.is_issued_by_known_root); 1174 EXPECT_FALSE(verify_result.is_issued_by_known_root);
1158 } 1175 }
1159 1176
1160 #if defined(USE_NSS_CERTS) || defined(OS_WIN) || \
1161 (defined(OS_MACOSX) && !defined(OS_IOS))
1162 // Test that CRLSets are effective in making a certificate appear to be 1177 // Test that CRLSets are effective in making a certificate appear to be
1163 // revoked. 1178 // revoked.
1164 TEST_F(CertVerifyProcTest, CRLSet) { 1179 TEST_P(CertVerifyProcInternalTest, CRLSet) {
1180 if (!SupportsCRLSet()) {
1181 LOG(INFO) << "Skipping test as verifier doesn't support CRLSet";
1182 return;
1183 }
1184
1165 CertificateList ca_cert_list = 1185 CertificateList ca_cert_list =
1166 CreateCertificateListFromFile(GetTestCertsDirectory(), 1186 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem",
1167 "root_ca_cert.pem",
1168 X509Certificate::FORMAT_AUTO); 1187 X509Certificate::FORMAT_AUTO);
1169 ASSERT_EQ(1U, ca_cert_list.size()); 1188 ASSERT_EQ(1U, ca_cert_list.size());
1170 ScopedTestRoot test_root(ca_cert_list[0].get()); 1189 ScopedTestRoot test_root(ca_cert_list[0].get());
1171 1190
1172 CertificateList cert_list = CreateCertificateListFromFile( 1191 CertificateList cert_list = CreateCertificateListFromFile(
1173 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); 1192 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO);
1174 ASSERT_EQ(1U, cert_list.size()); 1193 ASSERT_EQ(1U, cert_list.size());
1175 scoped_refptr<X509Certificate> cert(cert_list[0]); 1194 scoped_refptr<X509Certificate> cert(cert_list[0]);
1176 1195
1177 int flags = 0; 1196 int flags = 0;
1178 CertVerifyResult verify_result; 1197 CertVerifyResult verify_result;
1179 int error = Verify( 1198 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, CertificateList(),
1180 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); 1199 &verify_result);
1181 EXPECT_THAT(error, IsOk()); 1200 EXPECT_THAT(error, IsOk());
1182 EXPECT_EQ(0U, verify_result.cert_status); 1201 EXPECT_EQ(0U, verify_result.cert_status);
1183 1202
1184 scoped_refptr<CRLSet> crl_set; 1203 scoped_refptr<CRLSet> crl_set;
1185 std::string crl_set_bytes; 1204 std::string crl_set_bytes;
1186 1205
1187 // First test blocking by SPKI. 1206 // First test blocking by SPKI.
1188 EXPECT_TRUE(base::ReadFileToString( 1207 EXPECT_TRUE(base::ReadFileToString(
1189 GetTestCertsDirectory().AppendASCII("crlset_by_leaf_spki.raw"), 1208 GetTestCertsDirectory().AppendASCII("crlset_by_leaf_spki.raw"),
1190 &crl_set_bytes)); 1209 &crl_set_bytes));
1191 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); 1210 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set));
1192 1211
1193 error = Verify(cert.get(), 1212 error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(),
1194 "127.0.0.1", 1213 CertificateList(), &verify_result);
1195 flags,
1196 crl_set.get(),
1197 empty_cert_list_,
1198 &verify_result);
1199 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); 1214 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED));
1200 1215
1201 // Second, test revocation by serial number of a cert directly under the 1216 // Second, test revocation by serial number of a cert directly under the
1202 // root. 1217 // root.
1203 crl_set_bytes.clear(); 1218 crl_set_bytes.clear();
1204 EXPECT_TRUE(base::ReadFileToString( 1219 EXPECT_TRUE(base::ReadFileToString(
1205 GetTestCertsDirectory().AppendASCII("crlset_by_root_serial.raw"), 1220 GetTestCertsDirectory().AppendASCII("crlset_by_root_serial.raw"),
1206 &crl_set_bytes)); 1221 &crl_set_bytes));
1207 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); 1222 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set));
1208 1223
1209 error = Verify(cert.get(), 1224 error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(),
1210 "127.0.0.1", 1225 CertificateList(), &verify_result);
1211 flags,
1212 crl_set.get(),
1213 empty_cert_list_,
1214 &verify_result);
1215 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); 1226 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED));
1216 } 1227 }
1217 1228
1218 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) { 1229 TEST_P(CertVerifyProcInternalTest, CRLSetLeafSerial) {
1230 if (!SupportsCRLSet()) {
1231 LOG(INFO) << "Skipping test as verifier doesn't support CRLSet";
1232 return;
1233 }
1234
1219 CertificateList ca_cert_list = 1235 CertificateList ca_cert_list =
1220 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", 1236 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem",
1221 X509Certificate::FORMAT_AUTO); 1237 X509Certificate::FORMAT_AUTO);
1222 ASSERT_EQ(1U, ca_cert_list.size()); 1238 ASSERT_EQ(1U, ca_cert_list.size());
1223 ScopedTestRoot test_root(ca_cert_list[0].get()); 1239 ScopedTestRoot test_root(ca_cert_list[0].get());
1224 1240
1225 CertificateList intermediate_cert_list = CreateCertificateListFromFile( 1241 CertificateList intermediate_cert_list = CreateCertificateListFromFile(
1226 GetTestCertsDirectory(), "intermediate_ca_cert.pem", 1242 GetTestCertsDirectory(), "intermediate_ca_cert.pem",
1227 X509Certificate::FORMAT_AUTO); 1243 X509Certificate::FORMAT_AUTO);
1228 ASSERT_EQ(1U, intermediate_cert_list.size()); 1244 ASSERT_EQ(1U, intermediate_cert_list.size());
1229 X509Certificate::OSCertHandles intermediates; 1245 X509Certificate::OSCertHandles intermediates;
1230 intermediates.push_back(intermediate_cert_list[0]->os_cert_handle()); 1246 intermediates.push_back(intermediate_cert_list[0]->os_cert_handle());
1231 1247
1232 CertificateList cert_list = CreateCertificateListFromFile( 1248 CertificateList cert_list = CreateCertificateListFromFile(
1233 GetTestCertsDirectory(), "ok_cert_by_intermediate.pem", 1249 GetTestCertsDirectory(), "ok_cert_by_intermediate.pem",
1234 X509Certificate::FORMAT_AUTO); 1250 X509Certificate::FORMAT_AUTO);
1235 ASSERT_EQ(1U, cert_list.size()); 1251 ASSERT_EQ(1U, cert_list.size());
1236 1252
1237 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle( 1253 scoped_refptr<X509Certificate> leaf = X509Certificate::CreateFromHandle(
1238 cert_list[0]->os_cert_handle(), intermediates); 1254 cert_list[0]->os_cert_handle(), intermediates);
1239 ASSERT_TRUE(leaf); 1255 ASSERT_TRUE(leaf);
1240 1256
1241 int flags = 0; 1257 int flags = 0;
1242 CertVerifyResult verify_result; 1258 CertVerifyResult verify_result;
1243 int error = Verify(leaf.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 1259 int error = Verify(leaf.get(), "127.0.0.1", flags, NULL, CertificateList(),
1244 &verify_result); 1260 &verify_result);
1245 EXPECT_THAT(error, IsOk()); 1261 EXPECT_THAT(error, IsOk());
1246 1262
1247 // Test revocation by serial number of a certificate not under the root. 1263 // Test revocation by serial number of a certificate not under the root.
1248 scoped_refptr<CRLSet> crl_set; 1264 scoped_refptr<CRLSet> crl_set;
1249 std::string crl_set_bytes; 1265 std::string crl_set_bytes;
1250 ASSERT_TRUE(base::ReadFileToString( 1266 ASSERT_TRUE(base::ReadFileToString(
1251 GetTestCertsDirectory().AppendASCII("crlset_by_intermediate_serial.raw"), 1267 GetTestCertsDirectory().AppendASCII("crlset_by_intermediate_serial.raw"),
1252 &crl_set_bytes)); 1268 &crl_set_bytes));
1253 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); 1269 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set));
1254 1270
1255 error = Verify(leaf.get(), "127.0.0.1", flags, crl_set.get(), 1271 error = Verify(leaf.get(), "127.0.0.1", flags, crl_set.get(),
1256 empty_cert_list_, &verify_result); 1272 CertificateList(), &verify_result);
1257 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); 1273 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED));
1258 } 1274 }
1259 1275
1260 // Tests that CRLSets participate in path building functions, and that as 1276 // Tests that CRLSets participate in path building functions, and that as
1261 // long as a valid path exists within the verification graph, verification 1277 // long as a valid path exists within the verification graph, verification
1262 // succeeds. 1278 // succeeds.
1263 // 1279 //
1264 // In this test, there are two roots (D and E), and three possible paths 1280 // In this test, there are two roots (D and E), and three possible paths
1265 // to validate a leaf (A): 1281 // to validate a leaf (A):
1266 // 1. A(B) -> B(C) -> C(D) -> D(D) 1282 // 1. A(B) -> B(C) -> C(D) -> D(D)
1267 // 2. A(B) -> B(C) -> C(E) -> E(E) 1283 // 2. A(B) -> B(C) -> C(E) -> E(E)
1268 // 3. A(B) -> B(F) -> F(E) -> E(E) 1284 // 3. A(B) -> B(F) -> F(E) -> E(E)
1269 // 1285 //
1270 // Each permutation of revocation is tried: 1286 // Each permutation of revocation is tried:
1271 // 1. Revoking E by SPKI, so that only Path 1 is valid (as E is in Paths 2 & 3) 1287 // 1. Revoking E by SPKI, so that only Path 1 is valid (as E is in Paths 2 & 3)
1272 // 2. Revoking C(D) and F(E) by serial, so that only Path 2 is valid. 1288 // 2. Revoking C(D) and F(E) by serial, so that only Path 2 is valid.
1273 // 3. Revoking C by SPKI, so that only Path 3 is valid (as C is in Paths 1 & 2) 1289 // 3. Revoking C by SPKI, so that only Path 3 is valid (as C is in Paths 1 & 2)
1274 TEST_F(CertVerifyProcTest, CRLSetDuringPathBuilding) { 1290 TEST_P(CertVerifyProcInternalTest, CRLSetDuringPathBuilding) {
1275 if (!SupportsCRLSetsInPathBuilding()) { 1291 if (!SupportsCRLSetsInPathBuilding()) {
1276 LOG(INFO) << "Skipping this test on this platform."; 1292 LOG(INFO) << "Skipping this test on this platform.";
1277 return; 1293 return;
1278 } 1294 }
1279 1295
1280 const char* const kPath1Files[] = { 1296 const char* const kPath1Files[] = {
1281 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-D.pem", 1297 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-D.pem",
1282 "multi-root-D-by-D.pem"}; 1298 "multi-root-D-by-D.pem"};
1283 const char* const kPath2Files[] = { 1299 const char* const kPath2Files[] = {
1284 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", 1300 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem",
1285 "multi-root-E-by-E.pem"}; 1301 "multi-root-E-by-E.pem"};
1286 const char* const kPath3Files[] = { 1302 const char* const kPath3Files[] = {
1287 "multi-root-A-by-B.pem", "multi-root-B-by-F.pem", "multi-root-F-by-E.pem", 1303 "multi-root-A-by-B.pem", "multi-root-B-by-F.pem", "multi-root-F-by-E.pem",
1288 "multi-root-E-by-E.pem"}; 1304 "multi-root-E-by-E.pem"};
1289 1305
1290 CertificateList path_1_certs; 1306 CertificateList path_1_certs;
1291 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath1Files, &path_1_certs)); 1307 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath1Files, &path_1_certs));
1292 1308
1293 CertificateList path_2_certs; 1309 CertificateList path_2_certs;
1294 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); 1310 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs));
1295 1311
1296 CertificateList path_3_certs; 1312 CertificateList path_3_certs;
1297 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath3Files, &path_3_certs)); 1313 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath3Files, &path_3_certs));
1298 1314
1299 // Add D and E as trust anchors. 1315 // Add D and E as trust anchors.
1300 ScopedTestRoot test_root_D(path_1_certs[3].get()); // D-by-D 1316 ScopedTestRoot test_root_D(path_1_certs[3].get()); // D-by-D
1301 ScopedTestRoot test_root_E(path_2_certs[3].get()); // E-by-E 1317 ScopedTestRoot test_root_E(path_2_certs[3].get()); // E-by-E
1302 1318
1303 // Create a chain that contains all the certificate paths possible. 1319 // Create a chain that contains all the certificate paths possible.
1304 // CertVerifyProcTest.VerifyReturnChainFiltersUnrelatedCerts already 1320 // CertVerifyProcInternalTest.VerifyReturnChainFiltersUnrelatedCerts already
1305 // ensures that it's safe to send additional certificates as inputs, and 1321 // ensures that it's safe to send additional certificates as inputs, and
1306 // that they're ignored if not necessary. 1322 // that they're ignored if not necessary.
1307 // This is to avoid relying on AIA or internal object caches when 1323 // This is to avoid relying on AIA or internal object caches when
1308 // interacting with the underlying library. 1324 // interacting with the underlying library.
1309 X509Certificate::OSCertHandles intermediates; 1325 X509Certificate::OSCertHandles intermediates;
1310 intermediates.push_back(path_1_certs[1]->os_cert_handle()); // B-by-C 1326 intermediates.push_back(path_1_certs[1]->os_cert_handle()); // B-by-C
1311 intermediates.push_back(path_1_certs[2]->os_cert_handle()); // C-by-D 1327 intermediates.push_back(path_1_certs[2]->os_cert_handle()); // C-by-D
1312 intermediates.push_back(path_2_certs[2]->os_cert_handle()); // C-by-E 1328 intermediates.push_back(path_2_certs[2]->os_cert_handle()); // C-by-E
1313 intermediates.push_back(path_3_certs[1]->os_cert_handle()); // B-by-F 1329 intermediates.push_back(path_3_certs[1]->os_cert_handle()); // B-by-F
1314 intermediates.push_back(path_3_certs[2]->os_cert_handle()); // F-by-E 1330 intermediates.push_back(path_3_certs[2]->os_cert_handle()); // F-by-E
(...skipping 16 matching lines...) Expand all
1331 SCOPED_TRACE(testcase.crlset); 1347 SCOPED_TRACE(testcase.crlset);
1332 scoped_refptr<CRLSet> crl_set; 1348 scoped_refptr<CRLSet> crl_set;
1333 std::string crl_set_bytes; 1349 std::string crl_set_bytes;
1334 EXPECT_TRUE(base::ReadFileToString( 1350 EXPECT_TRUE(base::ReadFileToString(
1335 GetTestCertsDirectory().AppendASCII(testcase.crlset), &crl_set_bytes)); 1351 GetTestCertsDirectory().AppendASCII(testcase.crlset), &crl_set_bytes));
1336 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); 1352 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set));
1337 1353
1338 int flags = 0; 1354 int flags = 0;
1339 CertVerifyResult verify_result; 1355 CertVerifyResult verify_result;
1340 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), 1356 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(),
1341 empty_cert_list_, &verify_result); 1357 CertificateList(), &verify_result);
1342 1358
1343 if (!testcase.expect_valid) { 1359 if (!testcase.expect_valid) {
1344 EXPECT_NE(OK, error); 1360 EXPECT_NE(OK, error);
1345 EXPECT_NE(0U, verify_result.cert_status); 1361 EXPECT_NE(0U, verify_result.cert_status);
1346 continue; 1362 continue;
1347 } 1363 }
1348 1364
1349 ASSERT_THAT(error, IsOk()); 1365 ASSERT_THAT(error, IsOk());
1350 ASSERT_EQ(0U, verify_result.cert_status); 1366 ASSERT_EQ(0U, verify_result.cert_status);
1351 ASSERT_TRUE(verify_result.verified_cert.get()); 1367 ASSERT_TRUE(verify_result.verified_cert.get());
(...skipping 11 matching lines...) Expand all
1363 ASSERT_TRUE(intermediate); 1379 ASSERT_TRUE(intermediate);
1364 1380
1365 EXPECT_TRUE(testcase.expected_intermediate->Equals(intermediate.get())) 1381 EXPECT_TRUE(testcase.expected_intermediate->Equals(intermediate.get()))
1366 << "Expected: " << testcase.expected_intermediate->subject().common_name 1382 << "Expected: " << testcase.expected_intermediate->subject().common_name
1367 << " issued by " << testcase.expected_intermediate->issuer().common_name 1383 << " issued by " << testcase.expected_intermediate->issuer().common_name
1368 << "; Got: " << intermediate->subject().common_name << " issued by " 1384 << "; Got: " << intermediate->subject().common_name << " issued by "
1369 << intermediate->issuer().common_name; 1385 << intermediate->issuer().common_name;
1370 } 1386 }
1371 } 1387 }
1372 1388
1373 #endif
1374
1375 #if defined(OS_MACOSX) && !defined(OS_IOS) 1389 #if defined(OS_MACOSX) && !defined(OS_IOS)
1376 // Test that a CRLSet blocking one of the intermediates supplied by the server 1390 // Test that a CRLSet blocking one of the intermediates supplied by the server
1377 // can be worked around by the chopping workaround for path building. (Once the 1391 // can be worked around by the chopping workaround for path building. (Once the
1378 // supplied chain is chopped back to just the target, a better path can be 1392 // supplied chain is chopped back to just the target, a better path can be
1379 // found out-of-band. Normally that would be by AIA fetching, for the purposes 1393 // found out-of-band. Normally that would be by AIA fetching, for the purposes
1380 // of this test the better path is supplied by a test keychain.) 1394 // of this test the better path is supplied by a test keychain.)
1381 // 1395 //
1382 // In this test, there are two possible paths to validate a leaf (A): 1396 // In this test, there are two possible paths to validate a leaf (A):
1383 // 1. A(B) -> B(C) -> C(E) -> E(E) 1397 // 1. A(B) -> B(C) -> C(E) -> E(E)
1384 // 2. A(B) -> B(F) -> F(E) -> E(E) 1398 // 2. A(B) -> B(F) -> F(E) -> E(E)
1385 // 1399 //
1386 // A(B) -> B(C) -> C(E) is supplied to the verifier. 1400 // A(B) -> B(C) -> C(E) is supplied to the verifier.
1387 // B(F) and F(E) are supplied in a test keychain. 1401 // B(F) and F(E) are supplied in a test keychain.
1388 // C is blocked by a CRLset. 1402 // C is blocked by a CRLset.
1389 // 1403 //
1390 // The verifier should rollback until it just tries A(B) alone, at which point 1404 // The verifier should rollback until it just tries A(B) alone, at which point
1391 // it will pull B(F) & F(E) from the keychain and succeed. 1405 // it will pull B(F) & F(E) from the keychain and succeed.
1392 TEST_F(CertVerifyProcTest, MacCRLIntermediate) { 1406 TEST(CertVerifyProcMacTest, MacCRLIntermediate) {
1393 if (base::mac::IsAtLeastOS10_12()) { 1407 if (base::mac::IsAtLeastOS10_12()) {
1394 // TODO(crbug.com/671889): Investigate SecTrustSetKeychains issue on Sierra. 1408 // TODO(crbug.com/671889): Investigate SecTrustSetKeychains issue on Sierra.
1395 LOG(INFO) << "Skipping test, SecTrustSetKeychains does not work on 10.12"; 1409 LOG(INFO) << "Skipping test, SecTrustSetKeychains does not work on 10.12";
1396 return; 1410 return;
1397 } 1411 }
1398 const char* const kPath2Files[] = { 1412 const char* const kPath2Files[] = {
1399 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", 1413 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem",
1400 "multi-root-E-by-E.pem"}; 1414 "multi-root-E-by-E.pem"};
1401 CertificateList path_2_certs; 1415 CertificateList path_2_certs;
1402 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); 1416 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 scoped_refptr<CRLSet> crl_set; 1452 scoped_refptr<CRLSet> crl_set;
1439 std::string crl_set_bytes; 1453 std::string crl_set_bytes;
1440 // CRL which blocks C by SPKI. 1454 // CRL which blocks C by SPKI.
1441 EXPECT_TRUE(base::ReadFileToString( 1455 EXPECT_TRUE(base::ReadFileToString(
1442 GetTestCertsDirectory().AppendASCII("multi-root-crlset-C.raw"), 1456 GetTestCertsDirectory().AppendASCII("multi-root-crlset-C.raw"),
1443 &crl_set_bytes)); 1457 &crl_set_bytes));
1444 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set)); 1458 ASSERT_TRUE(CRLSetStorage::Parse(crl_set_bytes, &crl_set));
1445 1459
1446 int flags = 0; 1460 int flags = 0;
1447 CertVerifyResult verify_result; 1461 CertVerifyResult verify_result;
1448 int error = Verify(cert.get(), "127.0.0.1", flags, crl_set.get(), 1462
1449 empty_cert_list_, &verify_result); 1463 scoped_refptr<CertVerifyProc> verify_proc = CertVerifyProc::CreateDefault();
1464 int error =
1465 verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1466 crl_set.get(), CertificateList(), &verify_result);
1450 1467
1451 ASSERT_EQ(OK, error); 1468 ASSERT_EQ(OK, error);
1452 ASSERT_EQ(0U, verify_result.cert_status); 1469 ASSERT_EQ(0U, verify_result.cert_status);
1453 ASSERT_TRUE(verify_result.verified_cert.get()); 1470 ASSERT_TRUE(verify_result.verified_cert.get());
1454 1471
1455 const X509Certificate::OSCertHandles& verified_intermediates = 1472 const X509Certificate::OSCertHandles& verified_intermediates =
1456 verify_result.verified_cert->GetIntermediateCertificates(); 1473 verify_result.verified_cert->GetIntermediateCertificates();
1457 ASSERT_EQ(3U, verified_intermediates.size()); 1474 ASSERT_EQ(3U, verified_intermediates.size());
1458 1475
1459 scoped_refptr<X509Certificate> intermediate = 1476 scoped_refptr<X509Certificate> intermediate =
1460 X509Certificate::CreateFromHandle(verified_intermediates[1], 1477 X509Certificate::CreateFromHandle(verified_intermediates[1],
1461 X509Certificate::OSCertHandles()); 1478 X509Certificate::OSCertHandles());
1462 ASSERT_TRUE(intermediate); 1479 ASSERT_TRUE(intermediate);
1463 1480
1464 scoped_refptr<X509Certificate> expected_intermediate = path_3_certs[2]; 1481 scoped_refptr<X509Certificate> expected_intermediate = path_3_certs[2];
1465 EXPECT_TRUE(expected_intermediate->Equals(intermediate.get())) 1482 EXPECT_TRUE(expected_intermediate->Equals(intermediate.get()))
1466 << "Expected: " << expected_intermediate->subject().common_name 1483 << "Expected: " << expected_intermediate->subject().common_name
1467 << " issued by " << expected_intermediate->issuer().common_name 1484 << " issued by " << expected_intermediate->issuer().common_name
1468 << "; Got: " << intermediate->subject().common_name << " issued by " 1485 << "; Got: " << intermediate->subject().common_name << " issued by "
1469 << intermediate->issuer().common_name; 1486 << intermediate->issuer().common_name;
1470 } 1487 }
1471 1488
1472 // Test that if a keychain is present which trusts a less-desirable root (ex, 1489 // Test that if a keychain is present which trusts a less-desirable root (ex,
1473 // one using SHA1), that the keychain reordering hack will cause the better 1490 // one using SHA1), that the keychain reordering hack will cause the better
1474 // root in the System Roots to be used instead. 1491 // root in the System Roots to be used instead.
1475 TEST_F(CertVerifyProcTest, MacKeychainReordering) { 1492 TEST(CertVerifyProcMacTest, MacKeychainReordering) {
1476 // Note: target cert expires Apr 2 23:59:59 2018 GMT 1493 // Note: target cert expires Apr 2 23:59:59 2018 GMT
1477 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( 1494 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile(
1478 GetTestCertsDirectory(), "tripadvisor-verisign-chain.pem", 1495 GetTestCertsDirectory(), "tripadvisor-verisign-chain.pem",
1479 X509Certificate::FORMAT_AUTO); 1496 X509Certificate::FORMAT_AUTO);
1480 ASSERT_TRUE(cert); 1497 ASSERT_TRUE(cert);
1481 1498
1482 // Create a test keychain search list that will Always Trust the SHA1 1499 // Create a test keychain search list that will Always Trust the SHA1
1483 // cross-signed VeriSign Class 3 Public Primary Certification Authority - G5 1500 // cross-signed VeriSign Class 3 Public Primary Certification Authority - G5
1484 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list( 1501 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list(
1485 TestKeychainSearchList::Create()); 1502 TestKeychainSearchList::Create());
1486 ASSERT_TRUE(test_keychain_search_list); 1503 ASSERT_TRUE(test_keychain_search_list);
1487 1504
1488 base::FilePath keychain_path(GetTestCertsDirectory().AppendASCII( 1505 base::FilePath keychain_path(GetTestCertsDirectory().AppendASCII(
1489 "verisign_class3_g5_crosssigned-trusted.keychain")); 1506 "verisign_class3_g5_crosssigned-trusted.keychain"));
1490 // SecKeychainOpen does not fail if the file doesn't exist, so assert it here 1507 // SecKeychainOpen does not fail if the file doesn't exist, so assert it here
1491 // for easier debugging. 1508 // for easier debugging.
1492 ASSERT_TRUE(base::PathExists(keychain_path)); 1509 ASSERT_TRUE(base::PathExists(keychain_path));
1493 SecKeychainRef keychain; 1510 SecKeychainRef keychain;
1494 OSStatus status = 1511 OSStatus status =
1495 SecKeychainOpen(keychain_path.MaybeAsASCII().c_str(), &keychain); 1512 SecKeychainOpen(keychain_path.MaybeAsASCII().c_str(), &keychain);
1496 ASSERT_EQ(errSecSuccess, status); 1513 ASSERT_EQ(errSecSuccess, status);
1497 ASSERT_TRUE(keychain); 1514 ASSERT_TRUE(keychain);
1498 base::ScopedCFTypeRef<SecKeychainRef> scoped_keychain(keychain); 1515 base::ScopedCFTypeRef<SecKeychainRef> scoped_keychain(keychain);
1499 test_keychain_search_list->AddKeychain(keychain); 1516 test_keychain_search_list->AddKeychain(keychain);
1500 1517
1501 int flags = 0; 1518 int flags = 0;
1502 CertVerifyResult verify_result; 1519 CertVerifyResult verify_result;
1503 int error = Verify(cert.get(), "www.tripadvisor.com", flags, 1520 scoped_refptr<CertVerifyProc> verify_proc = CertVerifyProc::CreateDefault();
1504 nullptr /* crl_set */, empty_cert_list_, &verify_result); 1521 int error = verify_proc->Verify(cert.get(), "www.tripadvisor.com",
1522 std::string(), flags, nullptr /* crl_set */,
1523 CertificateList(), &verify_result);
1505 1524
1506 ASSERT_EQ(OK, error); 1525 ASSERT_EQ(OK, error);
1507 EXPECT_EQ(0U, verify_result.cert_status); 1526 EXPECT_EQ(0U, verify_result.cert_status);
1508 EXPECT_FALSE(verify_result.has_sha1); 1527 EXPECT_FALSE(verify_result.has_sha1);
1509 ASSERT_TRUE(verify_result.verified_cert.get()); 1528 ASSERT_TRUE(verify_result.verified_cert.get());
1510 1529
1511 const X509Certificate::OSCertHandles& verified_intermediates = 1530 const X509Certificate::OSCertHandles& verified_intermediates =
1512 verify_result.verified_cert->GetIntermediateCertificates(); 1531 verify_result.verified_cert->GetIntermediateCertificates();
1513 ASSERT_EQ(2U, verified_intermediates.size()); 1532 ASSERT_EQ(2U, verified_intermediates.size());
1514 } 1533 }
1515 1534
1516 // Test that the system root certificate keychain is in the expected location 1535 // Test that the system root certificate keychain is in the expected location
1517 // and can be opened. Other tests would fail if this was not true, but this 1536 // and can be opened. Other tests would fail if this was not true, but this
1518 // test makes the reason for the failure obvious. 1537 // test makes the reason for the failure obvious.
1519 TEST_F(CertVerifyProcTest, MacSystemRootCertificateKeychainLocation) { 1538 TEST(CertVerifyProcMacTest, MacSystemRootCertificateKeychainLocation) {
1520 const char* root_keychain_path = 1539 const char* root_keychain_path =
1521 "/System/Library/Keychains/SystemRootCertificates.keychain"; 1540 "/System/Library/Keychains/SystemRootCertificates.keychain";
1522 ASSERT_TRUE(base::PathExists(base::FilePath(root_keychain_path))); 1541 ASSERT_TRUE(base::PathExists(base::FilePath(root_keychain_path)));
1523 1542
1524 SecKeychainRef keychain; 1543 SecKeychainRef keychain;
1525 OSStatus status = SecKeychainOpen(root_keychain_path, &keychain); 1544 OSStatus status = SecKeychainOpen(root_keychain_path, &keychain);
1526 ASSERT_EQ(errSecSuccess, status); 1545 ASSERT_EQ(errSecSuccess, status);
1527 CFRelease(keychain); 1546 CFRelease(keychain);
1528 } 1547 }
1529 #endif 1548 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
1530 1549
1550 // TODO(crbug.com/649017): This is not parameterized by the CertVerifyProc
1551 // because the CertVerifyProc::Verify() does this unconditionally based on the
1552 // platform.
1531 bool AreSHA1IntermediatesAllowed() { 1553 bool AreSHA1IntermediatesAllowed() {
1532 #if defined(OS_WIN) 1554 #if defined(OS_WIN)
1533 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved 1555 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved
1534 // for Windows 7/2008 users. 1556 // for Windows 7/2008 users.
1535 // Note: This must be kept in sync with cert_verify_proc.cc 1557 // Note: This must be kept in sync with cert_verify_proc.cc
1536 return base::win::GetVersion() < base::win::VERSION_WIN8; 1558 return base::win::GetVersion() < base::win::VERSION_WIN8;
1537 #else 1559 #else
1538 return false; 1560 return false;
1539 #endif 1561 #endif
1540 } 1562 }
1541 1563
1542 TEST_F(CertVerifyProcTest, RejectsMD2) { 1564 TEST(CertVerifyProcTest, RejectsMD2) {
1543 scoped_refptr<X509Certificate> cert( 1565 scoped_refptr<X509Certificate> cert(
1544 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 1566 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
1545 ASSERT_TRUE(cert); 1567 ASSERT_TRUE(cert);
1546 1568
1547 CertVerifyResult result; 1569 CertVerifyResult result;
1548 result.has_md2 = true; 1570 result.has_md2 = true;
1549 verify_proc_ = new MockCertVerifyProc(result); 1571 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1550 1572
1551 int flags = 0; 1573 int flags = 0;
1552 CertVerifyResult verify_result; 1574 CertVerifyResult verify_result;
1553 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1575 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1554 empty_cert_list_, &verify_result); 1576 nullptr /* crl_set */, CertificateList(),
1577 &verify_result);
1555 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); 1578 EXPECT_THAT(error, IsError(ERR_CERT_INVALID));
1556 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 1579 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
1557 } 1580 }
1558 1581
1559 TEST_F(CertVerifyProcTest, RejectsMD4) { 1582 TEST(CertVerifyProcTest, RejectsMD4) {
1560 scoped_refptr<X509Certificate> cert( 1583 scoped_refptr<X509Certificate> cert(
1561 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 1584 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
1562 ASSERT_TRUE(cert); 1585 ASSERT_TRUE(cert);
1563 1586
1564 CertVerifyResult result; 1587 CertVerifyResult result;
1565 result.has_md4 = true; 1588 result.has_md4 = true;
1566 verify_proc_ = new MockCertVerifyProc(result); 1589 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1567 1590
1568 int flags = 0; 1591 int flags = 0;
1569 CertVerifyResult verify_result; 1592 CertVerifyResult verify_result;
1570 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1593 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1571 empty_cert_list_, &verify_result); 1594 nullptr /* crl_set */, CertificateList(),
1595 &verify_result);
1572 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); 1596 EXPECT_THAT(error, IsError(ERR_CERT_INVALID));
1573 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 1597 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
1574 } 1598 }
1575 1599
1576 TEST_F(CertVerifyProcTest, RejectsMD5) { 1600 TEST(CertVerifyProcTest, RejectsMD5) {
1577 scoped_refptr<X509Certificate> cert( 1601 scoped_refptr<X509Certificate> cert(
1578 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 1602 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
1579 ASSERT_TRUE(cert); 1603 ASSERT_TRUE(cert);
1580 1604
1581 CertVerifyResult result; 1605 CertVerifyResult result;
1582 result.has_md5 = true; 1606 result.has_md5 = true;
1583 verify_proc_ = new MockCertVerifyProc(result); 1607 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1584 1608
1585 int flags = 0; 1609 int flags = 0;
1586 CertVerifyResult verify_result; 1610 CertVerifyResult verify_result;
1587 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1611 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1588 empty_cert_list_, &verify_result); 1612 nullptr /* crl_set */, CertificateList(),
1613 &verify_result);
1589 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); 1614 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM));
1590 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); 1615 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1591 } 1616 }
1592 1617
1593 TEST_F(CertVerifyProcTest, RejectsPublicSHA1Leaves) { 1618 TEST(CertVerifyProcTest, RejectsPublicSHA1Leaves) {
1594 scoped_refptr<X509Certificate> cert( 1619 scoped_refptr<X509Certificate> cert(
1595 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 1620 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
1596 ASSERT_TRUE(cert); 1621 ASSERT_TRUE(cert);
1597 1622
1598 CertVerifyResult result; 1623 CertVerifyResult result;
1599 result.has_sha1 = true; 1624 result.has_sha1 = true;
1600 result.has_sha1_leaf = true; 1625 result.has_sha1_leaf = true;
1601 result.is_issued_by_known_root = true; 1626 result.is_issued_by_known_root = true;
1602 verify_proc_ = new MockCertVerifyProc(result); 1627 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1603 1628
1604 int flags = 0; 1629 int flags = 0;
1605 CertVerifyResult verify_result; 1630 CertVerifyResult verify_result;
1606 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1631 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1607 empty_cert_list_, &verify_result); 1632 nullptr /* crl_set */, CertificateList(),
1633 &verify_result);
1608 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); 1634 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM));
1609 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); 1635 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1610 } 1636 }
1611 1637
1612 TEST_F(CertVerifyProcTest, RejectsPublicSHA1IntermediatesUnlessAllowed) { 1638 TEST(CertVerifyProcTest, RejectsPublicSHA1IntermediatesUnlessAllowed) {
1613 scoped_refptr<X509Certificate> cert(ImportCertFromFile( 1639 scoped_refptr<X509Certificate> cert(ImportCertFromFile(
1614 GetTestCertsDirectory(), "39_months_after_2015_04.pem")); 1640 GetTestCertsDirectory(), "39_months_after_2015_04.pem"));
1615 ASSERT_TRUE(cert); 1641 ASSERT_TRUE(cert);
1616 1642
1617 CertVerifyResult result; 1643 CertVerifyResult result;
1618 result.has_sha1 = true; 1644 result.has_sha1 = true;
1619 result.has_sha1_leaf = false; 1645 result.has_sha1_leaf = false;
1620 result.is_issued_by_known_root = true; 1646 result.is_issued_by_known_root = true;
1621 verify_proc_ = new MockCertVerifyProc(result); 1647 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1622 1648
1623 int flags = 0; 1649 int flags = 0;
1624 CertVerifyResult verify_result; 1650 CertVerifyResult verify_result;
1625 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1651 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1626 empty_cert_list_, &verify_result); 1652 nullptr /* crl_set */, CertificateList(),
1653 &verify_result);
1627 if (AreSHA1IntermediatesAllowed()) { 1654 if (AreSHA1IntermediatesAllowed()) {
1628 EXPECT_THAT(error, IsOk()); 1655 EXPECT_THAT(error, IsOk());
1629 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); 1656 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT);
1630 } else { 1657 } else {
1631 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); 1658 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM));
1632 EXPECT_TRUE(verify_result.cert_status & 1659 EXPECT_TRUE(verify_result.cert_status &
1633 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); 1660 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1634 } 1661 }
1635 } 1662 }
1636 1663
1637 TEST_F(CertVerifyProcTest, RejectsPrivateSHA1UnlessFlag) { 1664 TEST(CertVerifyProcTest, RejectsPrivateSHA1UnlessFlag) {
1638 scoped_refptr<X509Certificate> cert( 1665 scoped_refptr<X509Certificate> cert(
1639 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 1666 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
1640 ASSERT_TRUE(cert); 1667 ASSERT_TRUE(cert);
1641 1668
1642 CertVerifyResult result; 1669 CertVerifyResult result;
1643 result.has_sha1 = true; 1670 result.has_sha1 = true;
1644 result.has_sha1_leaf = true; 1671 result.has_sha1_leaf = true;
1645 result.is_issued_by_known_root = false; 1672 result.is_issued_by_known_root = false;
1646 verify_proc_ = new MockCertVerifyProc(result); 1673 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1647 1674
1648 // SHA-1 should be rejected by default for private roots... 1675 // SHA-1 should be rejected by default for private roots...
1649 int flags = 0; 1676 int flags = 0;
1650 CertVerifyResult verify_result; 1677 CertVerifyResult verify_result;
1651 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1678 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1652 empty_cert_list_, &verify_result); 1679 nullptr /* crl_set */, CertificateList(),
1680 &verify_result);
1653 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); 1681 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM));
1654 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); 1682 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT);
1655 1683
1656 // ... unless VERIFY_ENABLE_SHA1_LOCAL_ANCHORS was supplied. 1684 // ... unless VERIFY_ENABLE_SHA1_LOCAL_ANCHORS was supplied.
1657 flags = CertVerifier::VERIFY_ENABLE_SHA1_LOCAL_ANCHORS; 1685 flags = CertVerifier::VERIFY_ENABLE_SHA1_LOCAL_ANCHORS;
1658 verify_result.Reset(); 1686 verify_result.Reset();
1659 error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, 1687 error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1660 empty_cert_list_, &verify_result); 1688 nullptr /* crl_set */, CertificateList(),
1689 &verify_result);
1661 EXPECT_THAT(error, IsOk()); 1690 EXPECT_THAT(error, IsOk());
1662 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); 1691 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT);
1663 } 1692 }
1664 1693
1665 enum ExpectedAlgorithms { 1694 enum ExpectedAlgorithms {
1666 EXPECT_MD2 = 1 << 0, 1695 EXPECT_MD2 = 1 << 0,
1667 EXPECT_MD4 = 1 << 1, 1696 EXPECT_MD4 = 1 << 1,
1668 EXPECT_MD5 = 1 << 2, 1697 EXPECT_MD5 = 1 << 2,
1669 EXPECT_SHA1 = 1 << 3, 1698 EXPECT_SHA1 = 1 << 3,
1670 EXPECT_SHA1_LEAF = 1 << 4, 1699 EXPECT_SHA1_LEAF = 1 << 4,
(...skipping 17 matching lines...) Expand all
1688 // attempt to print out the first twenty bytes of the object, which depending 1717 // attempt to print out the first twenty bytes of the object, which depending
1689 // on platform and alignment, may result in an invalid read. 1718 // on platform and alignment, may result in an invalid read.
1690 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { 1719 void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
1691 *os << "root: " << StringOrDefault(data.root_cert_filename, "none") 1720 *os << "root: " << StringOrDefault(data.root_cert_filename, "none")
1692 << "; intermediate: " 1721 << "; intermediate: "
1693 << StringOrDefault(data.intermediate_cert_filename, "none") 1722 << StringOrDefault(data.intermediate_cert_filename, "none")
1694 << "; end-entity: " << data.ee_cert_filename; 1723 << "; end-entity: " << data.ee_cert_filename;
1695 } 1724 }
1696 1725
1697 class CertVerifyProcWeakDigestTest 1726 class CertVerifyProcWeakDigestTest
1698 : public CertVerifyProcTest, 1727 : public testing::TestWithParam<WeakDigestTestData> {
1699 public testing::WithParamInterface<WeakDigestTestData> {
1700 public: 1728 public:
1701 CertVerifyProcWeakDigestTest() {} 1729 CertVerifyProcWeakDigestTest() {}
1702 virtual ~CertVerifyProcWeakDigestTest() {} 1730 virtual ~CertVerifyProcWeakDigestTest() {}
1703 }; 1731 };
1704 1732
1705 // Test that the CertVerifyProc::Verify() properly surfaces the (weak) hashing 1733 // Tests that the CertVerifyProc::Verify() properly surfaces the (weak) hash
1706 // algorithms used in the chain. 1734 // algorithms used in the chain.
1707 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) { 1735 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) {
1708 WeakDigestTestData data = GetParam(); 1736 WeakDigestTestData data = GetParam();
1709 base::FilePath certs_dir = GetTestCertsDirectory(); 1737 base::FilePath certs_dir = GetTestCertsDirectory();
1710 1738
1711 scoped_refptr<X509Certificate> intermediate_cert; 1739 scoped_refptr<X509Certificate> intermediate_cert;
1712 scoped_refptr<X509Certificate> root_cert; 1740 scoped_refptr<X509Certificate> root_cert;
1713 1741
1714 // Build |intermediates| as the full chain (including trust anchor). 1742 // Build |intermediates| as the full chain (including trust anchor).
1715 X509Certificate::OSCertHandles intermediates; 1743 X509Certificate::OSCertHandles intermediates;
1716 1744
1717 if (data.intermediate_cert_filename) { 1745 if (data.intermediate_cert_filename) {
1718 intermediate_cert = 1746 intermediate_cert =
1719 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); 1747 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1720 ASSERT_TRUE(intermediate_cert); 1748 ASSERT_TRUE(intermediate_cert);
1721 intermediates.push_back(intermediate_cert->os_cert_handle()); 1749 intermediates.push_back(intermediate_cert->os_cert_handle());
1722 } 1750 }
1723 1751
1724 if (data.root_cert_filename) { 1752 if (data.root_cert_filename) {
1725 root_cert = ImportCertFromFile(certs_dir, data.root_cert_filename); 1753 root_cert = ImportCertFromFile(certs_dir, data.root_cert_filename);
1726 ASSERT_TRUE(root_cert); 1754 ASSERT_TRUE(root_cert);
1727 intermediates.push_back(root_cert->os_cert_handle()); 1755 intermediates.push_back(root_cert->os_cert_handle());
1728 } 1756 }
1729 1757
1730 scoped_refptr<X509Certificate> ee_cert = 1758 scoped_refptr<X509Certificate> ee_cert =
1731 ImportCertFromFile(certs_dir, data.ee_cert_filename); 1759 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1732 ASSERT_TRUE(ee_cert); 1760 ASSERT_TRUE(ee_cert);
1733 1761
1734 scoped_refptr<X509Certificate> ee_chain = 1762 scoped_refptr<X509Certificate> ee_chain = X509Certificate::CreateFromHandle(
1735 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 1763 ee_cert->os_cert_handle(), intermediates);
1736 intermediates);
1737 ASSERT_TRUE(ee_chain); 1764 ASSERT_TRUE(ee_chain);
1738 1765
1739 int flags = 0; 1766 int flags = 0;
1740 CertVerifyResult verify_result; 1767 CertVerifyResult verify_result;
1741 1768
1742 // Use a mock CertVerifyProc that returns success with a verified_cert of 1769 // Use a mock CertVerifyProc that returns success with a verified_cert of
1743 // |ee_chain|. 1770 // |ee_chain|.
1744 // 1771 //
1745 // This is sufficient for the purposes of this test, as the checking for weak 1772 // This is sufficient for the purposes of this test, as the checking for weak
1746 // hashing algorithms is done by CertVerifyProc::Verify(). 1773 // hash algorithms is done by CertVerifyProc::Verify().
1747 scoped_refptr<CertVerifyProc> proc = 1774 scoped_refptr<CertVerifyProc> proc =
1748 new MockCertVerifyProc(CertVerifyResult()); 1775 new MockCertVerifyProc(CertVerifyResult());
1749 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr, 1776 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr,
1750 empty_cert_list_, &verify_result); 1777 CertificateList(), &verify_result);
1751 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2); 1778 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2);
1752 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4); 1779 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4);
1753 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5); 1780 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5);
1754 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1); 1781 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1);
1755 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF), 1782 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF),
1756 verify_result.has_sha1_leaf); 1783 verify_result.has_sha1_leaf);
1757 } 1784 }
1758 1785
1759 // The signature algorithm of the root CA should not matter. 1786 // The signature algorithm of the root CA should not matter.
1760 const WeakDigestTestData kVerifyRootCATestData[] = { 1787 const WeakDigestTestData kVerifyRootCATestData[] = {
(...skipping 17 matching lines...) Expand all
1778 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 1805 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1779 "weak_digest_sha1_ee.pem", EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1806 "weak_digest_sha1_ee.pem", EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1780 }; 1807 };
1781 1808
1782 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, 1809 INSTANTIATE_TEST_CASE_P(VerifyIntermediate,
1783 CertVerifyProcWeakDigestTest, 1810 CertVerifyProcWeakDigestTest,
1784 testing::ValuesIn(kVerifyIntermediateCATestData)); 1811 testing::ValuesIn(kVerifyIntermediateCATestData));
1785 1812
1786 // The signature algorithm of end-entity should be properly detected. 1813 // The signature algorithm of end-entity should be properly detected.
1787 const WeakDigestTestData kVerifyEndEntityTestData[] = { 1814 const WeakDigestTestData kVerifyEndEntityTestData[] = {
1788 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1815 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1789 "weak_digest_md5_ee.pem", EXPECT_MD5 | EXPECT_SHA1 }, 1816 "weak_digest_md5_ee.pem", EXPECT_MD5 | EXPECT_SHA1},
1790 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1817 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1791 "weak_digest_md4_ee.pem", EXPECT_MD4 | EXPECT_SHA1 }, 1818 "weak_digest_md4_ee.pem", EXPECT_MD4 | EXPECT_SHA1},
1792 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1819 {"weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1793 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_SHA1 }, 1820 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_SHA1},
1794 }; 1821 };
1795 1822
1796 INSTANTIATE_TEST_CASE_P(VerifyEndEntity, 1823 INSTANTIATE_TEST_CASE_P(VerifyEndEntity,
1797 CertVerifyProcWeakDigestTest, 1824 CertVerifyProcWeakDigestTest,
1798 testing::ValuesIn(kVerifyEndEntityTestData)); 1825 testing::ValuesIn(kVerifyEndEntityTestData));
1799 1826
1800 // Incomplete chains do not report the status of the intermediate. 1827 // Incomplete chains do not report the status of the intermediate.
1801 // Note: really each of these tests should also expect the digest algorithm of 1828 // Note: really each of these tests should also expect the digest algorithm of
1802 // the intermediate (included as a comment). However CertVerifyProc::Verify() is 1829 // the intermediate (included as a comment). However CertVerifyProc::Verify() is
1803 // unable to distinguish that this is an intermediate and not a trust anchor, so 1830 // unable to distinguish that this is an intermediate and not a trust anchor, so
(...skipping 26 matching lines...) Expand all
1830 /*EXPECT_SHA1 |*/ EXPECT_MD2}, 1857 /*EXPECT_SHA1 |*/ EXPECT_MD2},
1831 }; 1858 };
1832 1859
1833 INSTANTIATE_TEST_CASE_P(VerifyIncompleteEndEntity, 1860 INSTANTIATE_TEST_CASE_P(VerifyIncompleteEndEntity,
1834 CertVerifyProcWeakDigestTest, 1861 CertVerifyProcWeakDigestTest,
1835 testing::ValuesIn(kVerifyIncompleteEETestData)); 1862 testing::ValuesIn(kVerifyIncompleteEETestData));
1836 1863
1837 // Differing algorithms between the intermediate and the EE should still be 1864 // Differing algorithms between the intermediate and the EE should still be
1838 // reported. 1865 // reported.
1839 const WeakDigestTestData kVerifyMixedTestData[] = { 1866 const WeakDigestTestData kVerifyMixedTestData[] = {
1840 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 1867 {"weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1841 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD5 }, 1868 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD5},
1842 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 1869 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1843 "weak_digest_md5_ee.pem", EXPECT_MD2 | EXPECT_MD5 }, 1870 "weak_digest_md5_ee.pem", EXPECT_MD2 | EXPECT_MD5},
1844 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 1871 {"weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1845 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD4 }, 1872 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD4},
1846 }; 1873 };
1847 1874
1848 INSTANTIATE_TEST_CASE_P(VerifyMixed, 1875 INSTANTIATE_TEST_CASE_P(VerifyMixed,
1849 CertVerifyProcWeakDigestTest, 1876 CertVerifyProcWeakDigestTest,
1850 testing::ValuesIn(kVerifyMixedTestData)); 1877 testing::ValuesIn(kVerifyMixedTestData));
1851 1878
1852 // The EE is a trusted certificate. Even though it uses weak hashes, these 1879 // The EE is a trusted certificate. Even though it uses weak hashes, these
1853 // should not be reported. 1880 // should not be reported.
1854 const WeakDigestTestData kVerifyTrustedEETestData[] = { 1881 const WeakDigestTestData kVerifyTrustedEETestData[] = {
1855 {NULL, NULL, "weak_digest_md5_ee.pem", 0}, 1882 {NULL, NULL, "weak_digest_md5_ee.pem", 0},
1856 {NULL, NULL, "weak_digest_md4_ee.pem", 0}, 1883 {NULL, NULL, "weak_digest_md4_ee.pem", 0},
1857 {NULL, NULL, "weak_digest_md2_ee.pem", 0}, 1884 {NULL, NULL, "weak_digest_md2_ee.pem", 0},
1858 {NULL, NULL, "weak_digest_sha1_ee.pem", 0}, 1885 {NULL, NULL, "weak_digest_sha1_ee.pem", 0},
1859 }; 1886 };
1860 1887
1861 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE, 1888 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE,
1862 CertVerifyProcWeakDigestTest, 1889 CertVerifyProcWeakDigestTest,
1863 testing::ValuesIn(kVerifyTrustedEETestData)); 1890 testing::ValuesIn(kVerifyTrustedEETestData));
1864 1891
1865 // For the list of valid hostnames, see 1892 // For the list of valid hostnames, see
1866 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem 1893 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem
1867 static const struct CertVerifyProcNameData { 1894 struct CertVerifyProcNameData {
1868 const char* hostname; 1895 const char* hostname;
1869 bool valid; // Whether or not |hostname| matches a subjectAltName. 1896 bool valid; // Whether or not |hostname| matches a subjectAltName.
1870 } kVerifyNameData[] = {
1871 { "127.0.0.1", false }, // Don't match the common name
1872 { "127.0.0.2", true }, // Matches the iPAddress SAN (IPv4)
1873 { "FE80:0:0:0:0:0:0:1", true }, // Matches the iPAddress SAN (IPv6)
1874 { "[FE80:0:0:0:0:0:0:1]", false }, // Should not match the iPAddress SAN
1875 { "FE80::1", true }, // Compressed form matches the iPAddress SAN (IPv6)
1876 { "::127.0.0.2", false }, // IPv6 mapped form should NOT match iPAddress SAN
1877 { "test.example", true }, // Matches the dNSName SAN
1878 { "test.example.", true }, // Matches the dNSName SAN (trailing . ignored)
1879 { "www.test.example", false }, // Should not match the dNSName SAN
1880 { "test..example", false }, // Should not match the dNSName SAN
1881 { "test.example..", false }, // Should not match the dNSName SAN
1882 { ".test.example.", false }, // Should not match the dNSName SAN
1883 { ".test.example", false }, // Should not match the dNSName SAN
1884 }; 1897 };
1885 1898
1886 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how 1899 // Test fixture for verifying certificate names. These tests are run for each
1887 // to output the parameter that was passed. Without this, it will simply 1900 // of the CertVerify implementations.
1888 // attempt to print out the first twenty bytes of the object, which depending 1901 class CertVerifyProcNameTest : public CertVerifyProcInternalTest {
1889 // on platform and alignment, may result in an invalid read.
1890 void PrintTo(const CertVerifyProcNameData& data, std::ostream* os) {
1891 *os << "Hostname: " << data.hostname << "; valid=" << data.valid;
1892 }
1893
1894 class CertVerifyProcNameTest
1895 : public CertVerifyProcTest,
1896 public testing::WithParamInterface<CertVerifyProcNameData> {
1897 public: 1902 public:
1898 CertVerifyProcNameTest() {} 1903 CertVerifyProcNameTest() {}
1899 virtual ~CertVerifyProcNameTest() {} 1904 virtual ~CertVerifyProcNameTest() {}
1905
1906 protected:
1907 void VerifyCertName(const char* hostname, bool valid) {
1908 CertificateList cert_list = CreateCertificateListFromFile(
1909 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem",
1910 X509Certificate::FORMAT_AUTO);
1911 ASSERT_EQ(1U, cert_list.size());
1912 scoped_refptr<X509Certificate> cert(cert_list[0]);
1913
1914 ScopedTestRoot scoped_root(cert.get());
1915
1916 CertVerifyResult verify_result;
1917 int error = Verify(cert.get(), hostname, 0, NULL, CertificateList(),
1918 &verify_result);
1919 if (valid) {
1920 EXPECT_THAT(error, IsOk());
1921 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID);
1922 } else {
1923 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID));
1924 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID);
1925 }
1926 }
1900 }; 1927 };
1901 1928
1902 TEST_P(CertVerifyProcNameTest, VerifyCertName) { 1929 // Don't match the common name
1903 CertVerifyProcNameData data = GetParam(); 1930 TEST_P(CertVerifyProcNameTest, DontMatchCommonName) {
1931 VerifyCertName("127.0.0.1", false);
1932 }
1904 1933
1905 CertificateList cert_list = CreateCertificateListFromFile( 1934 // Matches the iPAddress SAN (IPv4)
1906 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem", 1935 TEST_P(CertVerifyProcNameTest, MatchesIpSanIpv4) {
1907 X509Certificate::FORMAT_AUTO); 1936 VerifyCertName("127.0.0.2", true);
1908 ASSERT_EQ(1U, cert_list.size()); 1937 }
1909 scoped_refptr<X509Certificate> cert(cert_list[0]);
1910 1938
1911 ScopedTestRoot scoped_root(cert.get()); 1939 // Matches the iPAddress SAN (IPv6)
1940 TEST_P(CertVerifyProcNameTest, MatchesIpSanIpv6) {
1941 VerifyCertName("FE80:0:0:0:0:0:0:1", true);
1942 }
1912 1943
1913 CertVerifyResult verify_result; 1944 // Should not match the iPAddress SAN
1914 int error = Verify(cert.get(), data.hostname, 0, NULL, empty_cert_list_, 1945 TEST_P(CertVerifyProcNameTest, DoesntMatchIpSanIpv6) {
1915 &verify_result); 1946 VerifyCertName("[FE80:0:0:0:0:0:0:1]", false);
1916 if (data.valid) { 1947 }
1917 EXPECT_THAT(error, IsOk()); 1948
1918 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); 1949 // Compressed form matches the iPAddress SAN (IPv6)
1919 } else { 1950 TEST_P(CertVerifyProcNameTest, MatchesIpSanCompressedIpv6) {
1920 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); 1951 VerifyCertName("FE80::1", true);
1921 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); 1952 }
1922 } 1953
1954 // IPv6 mapped form should NOT match iPAddress SAN
1955 TEST_P(CertVerifyProcNameTest, DoesntMatchIpSanIPv6Mapped) {
1956 VerifyCertName("::127.0.0.2", false);
1957 }
1958
1959 // Matches the dNSName SAN
1960 TEST_P(CertVerifyProcNameTest, MatchesDnsSan) {
1961 VerifyCertName("test.example", true);
1962 }
1963
1964 // Matches the dNSName SAN (trailing . ignored)
1965 TEST_P(CertVerifyProcNameTest, MatchesDnsSanTrailingDot) {
1966 VerifyCertName("test.example.", true);
1967 }
1968
1969 // Should not match the dNSName SAN
1970 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSan) {
1971 VerifyCertName("www.test.example", false);
1972 }
1973
1974 // Should not match the dNSName SAN
1975 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanInvalid) {
1976 VerifyCertName("test..example", false);
1977 }
1978
1979 // Should not match the dNSName SAN
1980 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanTwoTrailingDots) {
1981 VerifyCertName("test.example..", false);
1982 }
1983
1984 // Should not match the dNSName SAN
1985 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanLeadingAndTrailingDot) {
1986 VerifyCertName(".test.example.", false);
1987 }
1988
1989 // Should not match the dNSName SAN
1990 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanTrailingDot) {
1991 VerifyCertName(".test.example", false);
1923 } 1992 }
1924 1993
1925 INSTANTIATE_TEST_CASE_P(VerifyName, 1994 INSTANTIATE_TEST_CASE_P(VerifyName,
1926 CertVerifyProcNameTest, 1995 CertVerifyProcNameTest,
1927 testing::ValuesIn(kVerifyNameData)); 1996 testing::ValuesIn(kAllCertVerifiers),
1997 VerifyProcTypeToName);
1928 1998
1929 #if defined(OS_MACOSX) && !defined(OS_IOS) 1999 #if defined(OS_MACOSX) && !defined(OS_IOS)
1930 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate 2000 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate
1931 // verifier rejects a certificate with a fatal error. This is a regression 2001 // verifier rejects a certificate with a fatal error. This is a regression
1932 // test for https://crbug.com/472291. 2002 // test for https://crbug.com/472291.
1933 // (Since 10.12, this causes a recoverable error instead of a fatal one.) 2003 // (Since 10.12, this causes a recoverable error instead of a fatal one.)
1934 // TODO(mattm): Try to find a different way to cause a fatal error that works 2004 // TODO(mattm): Try to find a different way to cause a fatal error that works
1935 // on 10.12. 2005 // on 10.12.
1936 TEST_F(CertVerifyProcTest, LargeKey) { 2006 TEST(CertVerifyProcMacTest, LargeKey) {
1937 // Load root_ca_cert.pem into the test root store. 2007 // Load root_ca_cert.pem into the test root store.
1938 ScopedTestRoot test_root( 2008 ScopedTestRoot test_root(
1939 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); 2009 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get());
1940 2010
1941 scoped_refptr<X509Certificate> cert( 2011 scoped_refptr<X509Certificate> cert(
1942 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); 2012 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem"));
1943 2013
1944 // Apple's verifier rejects this certificate as invalid because the 2014 // Apple's verifier rejects this certificate as invalid because the
1945 // RSA key is too large. If a future version of OS X changes this, 2015 // RSA key is too large. If a future version of OS X changes this,
1946 // large_key.pem may need to be regenerated with a larger key. 2016 // large_key.pem may need to be regenerated with a larger key.
1947 int flags = 0; 2017 int flags = 0;
1948 CertVerifyResult verify_result; 2018 CertVerifyResult verify_result;
1949 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 2019 scoped_refptr<CertVerifyProc> verify_proc = CertVerifyProc::CreateDefault();
1950 &verify_result); 2020 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
2021 NULL, CertificateList(), &verify_result);
1951 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); 2022 EXPECT_THAT(error, IsError(ERR_CERT_INVALID));
1952 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); 2023 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
1953 } 2024 }
1954 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 2025 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
1955 2026
1956 // Tests that CertVerifyProc records a histogram correctly when a 2027 // Tests that CertVerifyProc records a histogram correctly when a
1957 // certificate chaining to a private root contains the TLS feature 2028 // certificate chaining to a private root contains the TLS feature
1958 // extension and does not have a stapled OCSP response. 2029 // extension and does not have a stapled OCSP response.
1959 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionUMA) { 2030 TEST(CertVerifyProcTest, HasTLSFeatureExtensionUMA) {
1960 base::HistogramTester histograms; 2031 base::HistogramTester histograms;
1961 scoped_refptr<X509Certificate> cert( 2032 scoped_refptr<X509Certificate> cert(
1962 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); 2033 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem"));
1963 ASSERT_TRUE(cert); 2034 ASSERT_TRUE(cert);
1964 CertVerifyResult result; 2035 CertVerifyResult result;
1965 result.is_issued_by_known_root = false; 2036 result.is_issued_by_known_root = false;
1966 verify_proc_ = new MockCertVerifyProc(result); 2037 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1967 2038
1968 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); 2039 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0);
1969 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); 2040 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0);
1970 2041
1971 int flags = 0; 2042 int flags = 0;
1972 CertVerifyResult verify_result; 2043 CertVerifyResult verify_result;
1973 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 2044 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
1974 &verify_result); 2045 NULL, CertificateList(), &verify_result);
1975 EXPECT_EQ(OK, error); 2046 EXPECT_EQ(OK, error);
1976 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); 2047 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1);
1977 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); 2048 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1);
1978 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); 2049 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1);
1979 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, false, 1); 2050 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, false, 1);
1980 } 2051 }
1981 2052
1982 // Tests that CertVerifyProc records a histogram correctly when a 2053 // Tests that CertVerifyProc records a histogram correctly when a
1983 // certificate chaining to a private root contains the TLS feature 2054 // certificate chaining to a private root contains the TLS feature
1984 // extension and does have a stapled OCSP response. 2055 // extension and does have a stapled OCSP response.
1985 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionWithStapleUMA) { 2056 TEST(CertVerifyProcTest, HasTLSFeatureExtensionWithStapleUMA) {
1986 base::HistogramTester histograms; 2057 base::HistogramTester histograms;
1987 scoped_refptr<X509Certificate> cert( 2058 scoped_refptr<X509Certificate> cert(
1988 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); 2059 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem"));
1989 ASSERT_TRUE(cert); 2060 ASSERT_TRUE(cert);
1990 CertVerifyResult result; 2061 CertVerifyResult result;
1991 result.is_issued_by_known_root = false; 2062 result.is_issued_by_known_root = false;
1992 verify_proc_ = new MockCertVerifyProc(result); 2063 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
1993 2064
1994 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); 2065 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0);
1995 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); 2066 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0);
1996 2067
1997 int flags = 0; 2068 int flags = 0;
1998 CertVerifyResult verify_result; 2069 CertVerifyResult verify_result;
1999 int error = 2070 int error =
2000 VerifyWithOCSPResponse(cert.get(), "127.0.0.1", "dummy response", flags, 2071 verify_proc->Verify(cert.get(), "127.0.0.1", "dummy response", flags,
2001 NULL, empty_cert_list_, &verify_result); 2072 nullptr, CertificateList(), &verify_result);
2002 EXPECT_EQ(OK, error); 2073 EXPECT_EQ(OK, error);
2003 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); 2074 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1);
2004 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); 2075 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1);
2005 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); 2076 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1);
2006 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, true, 1); 2077 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, true, 1);
2007 } 2078 }
2008 2079
2009 // Tests that CertVerifyProc records a histogram correctly when a 2080 // Tests that CertVerifyProc records a histogram correctly when a
2010 // certificate chaining to a private root does not contain the TLS feature 2081 // certificate chaining to a private root does not contain the TLS feature
2011 // extension. 2082 // extension.
2012 TEST_F(CertVerifyProcTest, DoesNotHaveTLSFeatureExtensionUMA) { 2083 TEST(CertVerifyProcTest, DoesNotHaveTLSFeatureExtensionUMA) {
2013 base::HistogramTester histograms; 2084 base::HistogramTester histograms;
2014 scoped_refptr<X509Certificate> cert( 2085 scoped_refptr<X509Certificate> cert(
2015 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); 2086 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"));
2016 ASSERT_TRUE(cert); 2087 ASSERT_TRUE(cert);
2017 CertVerifyResult result; 2088 CertVerifyResult result;
2018 result.is_issued_by_known_root = false; 2089 result.is_issued_by_known_root = false;
2019 verify_proc_ = new MockCertVerifyProc(result); 2090 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
2020 2091
2021 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); 2092 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0);
2022 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); 2093 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0);
2023 2094
2024 int flags = 0; 2095 int flags = 0;
2025 CertVerifyResult verify_result; 2096 CertVerifyResult verify_result;
2026 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 2097 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
2027 &verify_result); 2098 NULL, CertificateList(), &verify_result);
2028 EXPECT_EQ(OK, error); 2099 EXPECT_EQ(OK, error);
2029 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); 2100 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1);
2030 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, false, 1); 2101 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, false, 1);
2031 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); 2102 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0);
2032 } 2103 }
2033 2104
2034 // Tests that CertVerifyProc does not record a histogram when a 2105 // Tests that CertVerifyProc does not record a histogram when a
2035 // certificate contains the TLS feature extension but chains to a public 2106 // certificate contains the TLS feature extension but chains to a public
2036 // root. 2107 // root.
2037 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionWithPublicRootUMA) { 2108 TEST(CertVerifyProcTest, HasTLSFeatureExtensionWithPublicRootUMA) {
2038 base::HistogramTester histograms; 2109 base::HistogramTester histograms;
2039 scoped_refptr<X509Certificate> cert( 2110 scoped_refptr<X509Certificate> cert(
2040 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); 2111 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem"));
2041 ASSERT_TRUE(cert); 2112 ASSERT_TRUE(cert);
2042 CertVerifyResult result; 2113 CertVerifyResult result;
2043 result.is_issued_by_known_root = true; 2114 result.is_issued_by_known_root = true;
2044 verify_proc_ = new MockCertVerifyProc(result); 2115 scoped_refptr<CertVerifyProc> verify_proc = new MockCertVerifyProc(result);
2045 2116
2046 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); 2117 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0);
2047 2118
2048 int flags = 0; 2119 int flags = 0;
2049 CertVerifyResult verify_result; 2120 CertVerifyResult verify_result;
2050 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 2121 int error = verify_proc->Verify(cert.get(), "127.0.0.1", std::string(), flags,
2051 &verify_result); 2122 NULL, CertificateList(), &verify_result);
2052 EXPECT_EQ(OK, error); 2123 EXPECT_EQ(OK, error);
2053 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); 2124 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0);
2054 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); 2125 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0);
2055 } 2126 }
2056 2127
2057 } // namespace net 2128 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698