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