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 names a concrete implemenation of CertVerifyProc. | 
| 104 enum CertVerifyProcName { | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
So I had much more feedback originally written her
 
eroman
2017/01/12 21:42:48
Before I dive into the other comments, let's hash
 
Ryan Sleevi
2017/01/13 17:22:09
VerifyProcType?
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 105 CERT_VERIFY_PROC_NSS, | |
| 106 CERT_VERIFY_PROC_OPENSSL, | |
| 107 CERT_VERIFY_PROC_ANDROID, | |
| 108 CERT_VERIFY_PROC_IOS, | |
| 109 CERT_VERIFY_PROC_MAC, | |
| 110 CERT_VERIFY_PROC_WIN, | |
| 111 | |
| 112 // TODO(crbug.com/649017): The upcoming "built-in" implementation. | |
| 113 CERT_VERIFY_PROC_BUILTIN, | |
| 
 
eroman
2017/01/12 07:26:09
I will scrub all the "built-in" stuff prior to lan
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 114 }; | |
| 115 | |
| 116 // Returns the CertVerifyProcName corresponding to what | |
| 117 // CertVerifyProc::CreateDefault() returns. | |
| 118 CertVerifyProcName GetDefaultCertVerifyProcName() { | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
I'm torn on the appropriateness of this code dupli
 
eroman
2017/02/01 01:13:55
Acknowledged.
(Renamed ProcName --> ProcType)
 
 | |
| 119 #if defined(USE_NSS_CERTS) | |
| 120 return CERT_VERIFY_PROC_NSS; | |
| 121 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | |
| 122 return CERT_VERIFY_PROC_OPENSSL; | |
| 123 #elif defined(OS_ANDROID) | |
| 124 return CERT_VERIFY_PROC_ANDROID; | |
| 125 #elif defined(OS_IOS) | |
| 126 return CERT_VERIFY_PROC_IOS; | |
| 127 #elif defined(OS_MACOSX) | |
| 128 return CERT_VERIFY_PROC_MAC; | |
| 129 #elif defined(OS_WIN) | |
| 130 return CERT_VERIFY_PROC_WIN; | |
| 131 #else | |
| 132 // Will fail to compile. | |
| 133 #endif | |
| 134 } | |
| 135 | |
| 136 const char* CertVerifyProcNameToString(CertVerifyProcName verify_proc_name) { | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
I don't believe this should be a helper function -
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 137 switch (verify_proc_name) { | |
| 138 case CERT_VERIFY_PROC_NSS: | |
| 139 return "CertVerifyProcNSS"; | |
| 140 case CERT_VERIFY_PROC_OPENSSL: | |
| 141 return "CertVerifyProcOpenSSL"; | |
| 142 case CERT_VERIFY_PROC_ANDROID: | |
| 143 return "CertVerifyProcAndroid"; | |
| 144 case CERT_VERIFY_PROC_IOS: | |
| 145 return "CertVerifyProcIOS"; | |
| 146 case CERT_VERIFY_PROC_MAC: | |
| 147 return "CertVerifyProcMac"; | |
| 148 case CERT_VERIFY_PROC_WIN: | |
| 149 return "CertVerifyProcWin"; | |
| 150 case CERT_VERIFY_PROC_BUILTIN: | |
| 151 return "CertVerifyProcBuiltin"; | |
| 152 } | |
| 153 | |
| 154 return nullptr; | |
| 155 } | |
| 156 | |
| 157 bool TargetIsIphoneSimulator() { | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
Was it necessary to make this a function? Couldn't
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 158 #if TARGET_IPHONE_SIMULATOR | |
| 159 return true; | |
| 160 #else | |
| 161 return false; | |
| 162 #endif | |
| 163 } | |
| 164 | |
| 165 bool SupportsReturningVerifiedChain(CertVerifyProcName verify_proc_name) { | |
| 
 
Ryan Sleevi
2017/01/13 17:22:09
Despite our discussion, I'm still a little hazy ab
 
eroman
2017/02/01 01:13:55
I went ahead and moved them all into the base fixt
 
 | |
| 104 #if defined(OS_ANDROID) | 166 #if defined(OS_ANDROID) | 
| 105 // Before API level 17, Android does not expose the APIs necessary to get at | 167 // Before API level 17, Android does not expose the APIs necessary to get at | 
| 106 // the verified certificate chain. | 168 // the verified certificate chain. | 
| 107 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) | 169 if (verify_proc_name == CERT_VERIFY_PROC_ANDROID && | 
| 170 base::android::BuildInfo::GetInstance()->sdk_int() < 17) | |
| 108 return false; | 171 return false; | 
| 109 #endif | 172 #endif | 
| 110 return true; | 173 return true; | 
| 111 } | 174 } | 
| 112 | 175 | 
| 113 bool SupportsDetectingKnownRoots() { | 176 bool SupportsDetectingKnownRoots(CertVerifyProcName verify_proc_name) { | 
| 114 #if defined(OS_ANDROID) | 177 #if defined(OS_ANDROID) | 
| 115 // Before API level 17, Android does not expose the APIs necessary to get at | 178 // Before API level 17, Android does not expose the APIs necessary to get at | 
| 116 // the verified certificate chain and detect known roots. | 179 // the verified certificate chain and detect known roots. | 
| 117 if (base::android::BuildInfo::GetInstance()->sdk_int() < 17) | 180 if (verify_proc_name == CERT_VERIFY_PROC_ANDROID) | 
| 181 return base::android::BuildInfo::GetInstance()->sdk_int() >= 17; | |
| 182 #endif | |
| 183 | |
| 184 // iOS does not expose the APIs necessary to get the known system roots. | |
| 185 if (verify_proc_name == CERT_VERIFY_PROC_IOS) | |
| 118 return false; | 186 return false; | 
| 119 #elif defined(OS_IOS) | 187 | 
| 120 // iOS does not expose the APIs necessary to get the known system roots. | |
| 121 return false; | |
| 122 #endif | |
| 123 return true; | 188 return true; | 
| 124 } | 189 } | 
| 125 | 190 | 
| 126 bool WeakKeysAreInvalid() { | 191 bool WeakKeysAreInvalid(CertVerifyProcName verify_proc_name) { | 
| 
 
Ryan Sleevi
2017/01/12 20:01:56
Considering you're introducing a test fixture, I'm
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 127 #if defined(OS_MACOSX) && !defined(OS_IOS) | 192 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 128 // Starting with Mac OS 10.12, certs with weak keys are treated as | 193 // Starting with Mac OS 10.12, certs with weak keys are treated as | 
| 129 // (recoverable) invalid certificate errors. | 194 // (recoverable) invalid certificate errors. | 
| 130 return base::mac::IsAtLeastOS10_12(); | 195 if (verify_proc_name == CERT_VERIFY_PROC_MAC && | 
| 131 #else | 196 base::mac::IsAtLeastOS10_12()) { | 
| 197 return true; | |
| 198 } | |
| 199 #endif | |
| 132 return false; | 200 return false; | 
| 133 #endif | |
| 134 } | 201 } | 
| 135 | 202 | 
| 136 // Template helper to load a series of certificate files into a CertificateList. | 203 // Template helper to load a series of certificate files into a CertificateList. | 
| 137 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a | 204 // Like CertTestUtil's CreateCertificateListFromFile, except it can load a | 
| 138 // series of individual certificates (to make the tests clearer). | 205 // series of individual certificates (to make the tests clearer). | 
| 139 template <size_t N> | 206 template <size_t N> | 
| 140 void LoadCertificateFiles(const char* const (&cert_files)[N], | 207 void LoadCertificateFiles(const char* const (&cert_files)[N], | 
| 141 CertificateList* certs) { | 208 CertificateList* certs) { | 
| 142 certs->clear(); | 209 certs->clear(); | 
| 143 for (size_t i = 0; i < N; ++i) { | 210 for (size_t i = 0; i < N; ++i) { | 
| 144 SCOPED_TRACE(cert_files[i]); | 211 SCOPED_TRACE(cert_files[i]); | 
| 145 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 212 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 
| 146 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO); | 213 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO); | 
| 147 ASSERT_TRUE(cert); | 214 ASSERT_TRUE(cert); | 
| 148 certs->push_back(cert); | 215 certs->push_back(cert); | 
| 149 } | 216 } | 
| 150 } | 217 } | 
| 151 | 218 | 
| 219 bool SupportsCRLSetsInPathBuilding(CertVerifyProcName verify_proc_name) { | |
| 220 // TODO(crbug.com/649017): Support for built-in | |
| 221 return verify_proc_name == CERT_VERIFY_PROC_WIN || | |
| 222 verify_proc_name == CERT_VERIFY_PROC_NSS; | |
| 223 } | |
| 224 | |
| 225 // Returns the name of the CertVerifyProc implementation that is being tested. | |
| 226 std::string VerifyProcTypeToName( | |
| 227 const testing::TestParamInfo<CertVerifyProcName>& params) { | |
| 228 return CertVerifyProcNameToString(params.param); | |
| 229 } | |
| 
 
Ryan Sleevi
2017/01/13 17:22:09
Let's definitely ditch this.
 
eroman
2017/02/01 01:13:55
It is useful to to have the test name be:
   XXX/
 
 | |
| 230 | |
| 231 // The set of all CertVerifyProcNames to be used by tests. | |
| 232 std::vector<CertVerifyProcName> AllCertVerifiers() { | |
| 233 // TODO(crbug.com/649017): Include CERT_VERIFY_PROC_BUILTIN | |
| 234 return {GetDefaultCertVerifyProcName()}; | |
| 235 } | |
| 
 
Ryan Sleevi
2017/01/13 17:22:09
Do you actually need this to be a function? Unitte
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 236 | |
| 237 scoped_refptr<CertVerifyProc> CreateCertVerifyProc( | |
| 238 CertVerifyProcName verify_proc_name) { | |
| 239 // TODO(crbug.com/649017): Handle CERT_VERIFY_PROC_BUILTIN | |
| 240 EXPECT_EQ(verify_proc_name, GetDefaultCertVerifyProcName()); | |
| 241 return CertVerifyProc::CreateDefault(); | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
My instinct is that trying to preserve this is per
 
Ryan Sleevi
2017/01/13 17:22:09
So I don't think the EXPECT_EQ does anything to pr
 
eroman
2017/02/01 01:13:55
The EXPECT_EQ() was to guard against me adding CER
 
 | |
| 242 } | |
| 243 | |
| 152 } // namespace | 244 } // namespace | 
| 153 | 245 | 
| 154 class CertVerifyProcTest : public testing::Test { | 246 // Base class for writing tests against a specific CertVerifyProc | 
| 155 public: | 247 // implementation. | 
| 156 CertVerifyProcTest() | 248 class CertVerifyProcBaseTest : public testing::Test { | 
| 157 : verify_proc_(CertVerifyProc::CreateDefault()) { | 249 protected: | 
| 158 } | 250 void SetUp() override { verify_proc_ = CreateVerifyProc(&verify_proc_name_); } | 
| 159 ~CertVerifyProcTest() override {} | |
| 160 | 251 | 
| 161 protected: | 252 // Creates the CertVerifyProc to be tested by this fixture, and fills | 
| 253 // |*verify_proc_name| with the created instance's name. | |
| 254 virtual scoped_refptr<CertVerifyProc> CreateVerifyProc( | |
| 255 CertVerifyProcName* verify_proc_name) = 0; | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
So it's unclear why you have the function return t
 
eroman
2017/02/01 01:13:55
Done.
 
 | |
| 256 | |
| 162 bool SupportsAdditionalTrustAnchors() { | 257 bool SupportsAdditionalTrustAnchors() { | 
| 163 return verify_proc_->SupportsAdditionalTrustAnchors(); | 258 return verify_proc_->SupportsAdditionalTrustAnchors(); | 
| 164 } | 259 } | 
| 165 | 260 | 
| 166 // Returns true if the underlying CertVerifyProc supports integrating CRLSets | |
| 167 // into path building logic, such as allowing the selection of alternatively | |
| 168 // valid paths when one or more are revoked. As the goal is to integrate this | |
| 169 // into all platforms, this is a temporary, test-only flag to centralize the | |
| 170 // conditionals in tests. | |
| 171 bool SupportsCRLSetsInPathBuilding() { | |
| 172 #if defined(OS_WIN) || defined(USE_NSS_CERTS) | |
| 173 return true; | |
| 174 #else | |
| 175 return false; | |
| 176 #endif | |
| 177 } | |
| 178 | |
| 179 int Verify(X509Certificate* cert, | 261 int Verify(X509Certificate* cert, | 
| 180 const std::string& hostname, | 262 const std::string& hostname, | 
| 181 int flags, | 263 int flags, | 
| 182 CRLSet* crl_set, | 264 CRLSet* crl_set, | 
| 183 const CertificateList& additional_trust_anchors, | 265 const CertificateList& additional_trust_anchors, | 
| 184 CertVerifyResult* verify_result) { | 266 CertVerifyResult* verify_result) { | 
| 185 return verify_proc_->Verify(cert, hostname, std::string(), flags, crl_set, | 267 return verify_proc_->Verify(cert, hostname, std::string(), flags, crl_set, | 
| 186 additional_trust_anchors, verify_result); | 268 additional_trust_anchors, verify_result); | 
| 187 } | 269 } | 
| 188 | 270 | 
| 189 int VerifyWithOCSPResponse(X509Certificate* cert, | 271 int VerifyWithOCSPResponse(X509Certificate* cert, | 
| 190 const std::string& hostname, | 272 const std::string& hostname, | 
| 191 const std::string& ocsp_response, | 273 const std::string& ocsp_response, | 
| 192 int flags, | 274 int flags, | 
| 193 CRLSet* crl_set, | 275 CRLSet* crl_set, | 
| 194 const CertificateList& additional_trust_anchors, | 276 const CertificateList& additional_trust_anchors, | 
| 195 CertVerifyResult* verify_result) { | 277 CertVerifyResult* verify_result) { | 
| 196 return verify_proc_->Verify(cert, hostname, ocsp_response, flags, crl_set, | 278 return verify_proc_->Verify(cert, hostname, ocsp_response, flags, crl_set, | 
| 197 additional_trust_anchors, verify_result); | 279 additional_trust_anchors, verify_result); | 
| 198 } | 280 } | 
| 199 | 281 | 
| 282 bool UsingCertVerifyProcAndroid() const { | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
We're in CertVerifyProcUnittest - the use of "Cert
 
eroman
2017/02/01 01:13:55
Removed these functions.
 
 | |
| 283 return verify_proc_name_ == CERT_VERIFY_PROC_ANDROID; | |
| 284 } | |
| 285 | |
| 286 bool UsingCertVerifyProcNSS() const { | |
| 
 
Ryan Sleevi
2017/01/13 17:22:09
If we're going to go with these helper functions (
 
eroman
2017/02/01 01:13:55
N/A
 
 | |
| 287 return verify_proc_name_ == CERT_VERIFY_PROC_NSS; | |
| 288 } | |
| 289 | |
| 290 bool UsingCertVerifyProcOpenSSL() const { | |
| 291 return verify_proc_name_ == CERT_VERIFY_PROC_OPENSSL; | |
| 292 } | |
| 293 | |
| 294 bool UsingCertVerifyProcIOS() const { | |
| 295 return verify_proc_name_ == CERT_VERIFY_PROC_IOS; | |
| 296 } | |
| 297 | |
| 298 bool UsingCertVerifyProcWin() const { | |
| 299 return verify_proc_name_ == CERT_VERIFY_PROC_WIN; | |
| 300 } | |
| 301 | |
| 302 bool UsingCertVerifyProcMac() const { | |
| 303 return verify_proc_name_ == CERT_VERIFY_PROC_MAC; | |
| 304 } | |
| 305 | |
| 200 const CertificateList empty_cert_list_; | 306 const CertificateList empty_cert_list_; | 
| 201 scoped_refptr<CertVerifyProc> verify_proc_; | 307 scoped_refptr<CertVerifyProc> verify_proc_; | 
| 308 CertVerifyProcName verify_proc_name_; | |
| 202 }; | 309 }; | 
| 203 | 310 | 
| 204 #if defined(OS_ANDROID) || defined(USE_OPENSSL_CERTS) | 311 // This test fixture is paramterized by the CertVerifyProc (which is specified | 
| 205 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. | 312 // as an enum). Used for tests which should be run for multiple CertVerifyProc | 
| 206 #define MAYBE_EVVerification DISABLED_EVVerification | 313 // implementations. | 
| 207 #else | 314 class CertVerifyProcTest | 
| 315 : public CertVerifyProcBaseTest, | |
| 316 public testing::WithParamInterface<CertVerifyProcName> { | |
| 317 protected: | |
| 318 scoped_refptr<CertVerifyProc> CreateVerifyProc( | |
| 319 CertVerifyProcName* verify_proc_name) override { | |
| 320 *verify_proc_name = GetParam(); | |
| 321 return CreateCertVerifyProc(*verify_proc_name); | |
| 322 } | |
| 323 }; | |
| 324 | |
| 325 INSTANTIATE_TEST_CASE_P(, | |
| 326 CertVerifyProcTest, | |
| 327 testing::ValuesIn(AllCertVerifiers()), | |
| 328 VerifyProcTypeToName); | |
| 329 | |
| 330 // This test fixture is used for tests that are ONLY to be run with the | |
| 331 // CertVerifyProc::CreateDefault() implementation. | |
| 
 
Ryan Sleevi
2017/01/13 17:22:09
Did you consider making an explicit fixture for ea
 
eroman
2017/02/01 01:13:55
That entails duplicating fixtures in at least 4 pl
 
 | |
| 332 class CertVerifyProcDefaultTest : public CertVerifyProcBaseTest { | |
| 333 public: | |
| 334 scoped_refptr<CertVerifyProc> CreateVerifyProc( | |
| 335 CertVerifyProcName* verify_proc_name) override { | |
| 336 *verify_proc_name = GetDefaultCertVerifyProcName(); | |
| 337 return CreateCertVerifyProc(*verify_proc_name); | |
| 338 } | |
| 339 }; | |
| 340 | |
| 208 // TODO(rsleevi): Reenable this test once comodo.chaim.pem is no longer | 341 // TODO(rsleevi): Reenable this test once comodo.chaim.pem is no longer | 
| 209 // expired, http://crbug.com/502818 | 342 // expired, http://crbug.com/502818 | 
| 210 #define MAYBE_EVVerification DISABLED_EVVerification | 343 TEST_P(CertVerifyProcTest, DISABLED_EVVerification) { | 
| 211 #endif | 344 if (UsingCertVerifyProcAndroid() || UsingCertVerifyProcOpenSSL()) { | 
| 212 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) { | 345 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet | 
| 346 // supported. | |
| 347 LOG(INFO) << "Skipping test as EV verification is not yet supported"; | |
| 348 return; | |
| 349 } | |
| 350 | |
| 213 CertificateList certs = CreateCertificateListFromFile( | 351 CertificateList certs = CreateCertificateListFromFile( | 
| 214 GetTestCertsDirectory(), | 352 GetTestCertsDirectory(), | 
| 215 "comodo.chain.pem", | 353 "comodo.chain.pem", | 
| 216 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 354 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 
| 217 ASSERT_EQ(3U, certs.size()); | 355 ASSERT_EQ(3U, certs.size()); | 
| 218 | 356 | 
| 219 X509Certificate::OSCertHandles intermediates; | 357 X509Certificate::OSCertHandles intermediates; | 
| 220 intermediates.push_back(certs[1]->os_cert_handle()); | 358 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 221 intermediates.push_back(certs[2]->os_cert_handle()); | 359 intermediates.push_back(certs[2]->os_cert_handle()); | 
| 222 | 360 | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 234 empty_cert_list_, | 372 empty_cert_list_, | 
| 235 &verify_result); | 373 &verify_result); | 
| 236 EXPECT_THAT(error, IsOk()); | 374 EXPECT_THAT(error, IsOk()); | 
| 237 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 375 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 
| 238 } | 376 } | 
| 239 | 377 | 
| 240 // TODO(crbug.com/605457): the test expectation was incorrect on some | 378 // TODO(crbug.com/605457): the test expectation was incorrect on some | 
| 241 // configurations, so disable the test until it is fixed (better to have | 379 // 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 | 380 // a bug to track a failing test than a false sense of security due to | 
| 243 // false positive). | 381 // false positive). | 
| 244 TEST_F(CertVerifyProcTest, DISABLED_PaypalNullCertParsing) { | 382 TEST_P(CertVerifyProcTest, DISABLED_PaypalNullCertParsing) { | 
| 245 // A certificate for www.paypal.com with a NULL byte in the common name. | 383 // 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 | 384 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 | 
| 247 SHA256HashValue paypal_null_fingerprint = {{0x00}}; | 385 SHA256HashValue paypal_null_fingerprint = {{0x00}}; | 
| 248 | 386 | 
| 249 scoped_refptr<X509Certificate> paypal_null_cert( | 387 scoped_refptr<X509Certificate> paypal_null_cert( | 
| 250 X509Certificate::CreateFromBytes( | 388 X509Certificate::CreateFromBytes( | 
| 251 reinterpret_cast<const char*>(paypal_null_der), | 389 reinterpret_cast<const char*>(paypal_null_der), | 
| 252 sizeof(paypal_null_der))); | 390 sizeof(paypal_null_der))); | 
| 253 | 391 | 
| 254 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert.get()); | 392 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert.get()); | 
| 255 | 393 | 
| 256 EXPECT_EQ(paypal_null_fingerprint, X509Certificate::CalculateFingerprint256( | 394 EXPECT_EQ(paypal_null_fingerprint, X509Certificate::CalculateFingerprint256( | 
| 257 paypal_null_cert->os_cert_handle())); | 395 paypal_null_cert->os_cert_handle())); | 
| 258 | 396 | 
| 259 int flags = 0; | 397 int flags = 0; | 
| 260 CertVerifyResult verify_result; | 398 CertVerifyResult verify_result; | 
| 261 int error = Verify(paypal_null_cert.get(), | 399 int error = Verify(paypal_null_cert.get(), | 
| 262 "www.paypal.com", | 400 "www.paypal.com", | 
| 263 flags, | 401 flags, | 
| 264 NULL, | 402 NULL, | 
| 265 empty_cert_list_, | 403 empty_cert_list_, | 
| 266 &verify_result); | 404 &verify_result); | 
| 267 #if defined(USE_NSS_CERTS) || defined(OS_ANDROID) | 405 | 
| 268 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | 406 if (UsingCertVerifyProcNSS() || UsingCertVerifyProcAndroid()) { | 
| 269 #elif defined(OS_IOS) && TARGET_IPHONE_SIMULATOR | 407 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | 
| 270 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning | 408 } else if (UsingCertVerifyProcIOS() && TargetIsIphoneSimulator()) { | 
| 271 // ERR_CERT_AUTHORITY_INVALID on the real device. | 409 // iOS returns a ERR_CERT_INVALID error on the simulator, while returning | 
| 272 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 410 // ERR_CERT_AUTHORITY_INVALID on the real device. | 
| 273 #else | 411 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 274 // TOOD(bulach): investigate why macosx and win aren't returning | 412 } else { | 
| 275 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 413 // TOOD(bulach): investigate why macosx and win aren't returning | 
| 276 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 414 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 
| 277 #endif | 415 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 416 } | |
| 417 | |
| 278 // Either the system crypto library should correctly report a certificate | 418 // Either the system crypto library should correctly report a certificate | 
| 279 // name mismatch, or our certificate blacklist should cause us to report an | 419 // name mismatch, or our certificate blacklist should cause us to report an | 
| 280 // invalid certificate. | 420 // invalid certificate. | 
| 281 #if defined(USE_NSS_CERTS) || defined(OS_WIN) | 421 if (UsingCertVerifyProcNSS() || UsingCertVerifyProcWin()) { | 
| 282 EXPECT_TRUE(verify_result.cert_status & | 422 EXPECT_TRUE(verify_result.cert_status & | 
| 283 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 423 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 
| 284 #endif | 424 } | 
| 425 | |
| 426 // TODO(crbug.com/649017): What expectations to use for the other verifiers? | |
| 285 } | 427 } | 
| 286 | 428 | 
| 287 // A regression test for http://crbug.com/31497. | 429 // A regression test for http://crbug.com/31497. | 
| 288 #if defined(OS_ANDROID) | 430 TEST_P(CertVerifyProcTest, IntermediateCARequireExplicitPolicy) { | 
| 289 // Disabled on Android, as the Android verification libraries require an | 431 if (UsingCertVerifyProcAndroid()) { | 
| 290 // explicit policy to be specified, even when anyPolicy is permitted. | 432 // Disabled on Android, as the Android verification libraries require an | 
| 291 #define MAYBE_IntermediateCARequireExplicitPolicy \ | 433 // explicit policy to be specified, even when anyPolicy is permitted. | 
| 292 DISABLED_IntermediateCARequireExplicitPolicy | 434 LOG(INFO) << "Skipping test on Android"; | 
| 293 #else | 435 return; | 
| 294 #define MAYBE_IntermediateCARequireExplicitPolicy \ | 436 } | 
| 295 IntermediateCARequireExplicitPolicy | 437 | 
| 296 #endif | |
| 297 TEST_F(CertVerifyProcTest, MAYBE_IntermediateCARequireExplicitPolicy) { | |
| 298 base::FilePath certs_dir = GetTestCertsDirectory(); | 438 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 299 | 439 | 
| 300 CertificateList certs = CreateCertificateListFromFile( | 440 CertificateList certs = CreateCertificateListFromFile( | 
| 301 certs_dir, "explicit-policy-chain.pem", | 441 certs_dir, "explicit-policy-chain.pem", | 
| 302 X509Certificate::FORMAT_AUTO); | 442 X509Certificate::FORMAT_AUTO); | 
| 303 ASSERT_EQ(3U, certs.size()); | 443 ASSERT_EQ(3U, certs.size()); | 
| 304 | 444 | 
| 305 X509Certificate::OSCertHandles intermediates; | 445 X509Certificate::OSCertHandles intermediates; | 
| 306 intermediates.push_back(certs[1]->os_cert_handle()); | 446 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 307 | 447 | 
| 308 scoped_refptr<X509Certificate> cert = | 448 scoped_refptr<X509Certificate> cert = | 
| 309 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 449 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 
| 310 intermediates); | 450 intermediates); | 
| 311 ASSERT_TRUE(cert.get()); | 451 ASSERT_TRUE(cert.get()); | 
| 312 | 452 | 
| 313 ScopedTestRoot scoped_root(certs[2].get()); | 453 ScopedTestRoot scoped_root(certs[2].get()); | 
| 314 | 454 | 
| 315 int flags = 0; | 455 int flags = 0; | 
| 316 CertVerifyResult verify_result; | 456 CertVerifyResult verify_result; | 
| 317 int error = Verify(cert.get(), | 457 int error = Verify(cert.get(), | 
| 318 "policy_test.example", | 458 "policy_test.example", | 
| 319 flags, | 459 flags, | 
| 320 NULL, | 460 NULL, | 
| 321 empty_cert_list_, | 461 empty_cert_list_, | 
| 322 &verify_result); | 462 &verify_result); | 
| 323 EXPECT_THAT(error, IsOk()); | 463 EXPECT_THAT(error, IsOk()); | 
| 324 EXPECT_EQ(0u, verify_result.cert_status); | 464 EXPECT_EQ(0u, verify_result.cert_status); | 
| 325 } | 465 } | 
| 326 | 466 | 
| 327 TEST_F(CertVerifyProcTest, RejectExpiredCert) { | 467 TEST_P(CertVerifyProcTest, RejectExpiredCert) { | 
| 328 base::FilePath certs_dir = GetTestCertsDirectory(); | 468 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 329 | 469 | 
| 330 // Load root_ca_cert.pem into the test root store. | 470 // Load root_ca_cert.pem into the test root store. | 
| 331 ScopedTestRoot test_root( | 471 ScopedTestRoot test_root( | 
| 332 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); | 472 ImportCertFromFile(certs_dir, "root_ca_cert.pem").get()); | 
| 333 | 473 | 
| 334 CertificateList certs = CreateCertificateListFromFile( | 474 CertificateList certs = CreateCertificateListFromFile( | 
| 335 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); | 475 certs_dir, "expired_cert.pem", X509Certificate::FORMAT_AUTO); | 
| 336 ASSERT_EQ(1U, certs.size()); | 476 ASSERT_EQ(1U, certs.size()); | 
| 337 | 477 | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 356 size_t pos = key_type.find("-"); | 496 size_t pos = key_type.find("-"); | 
| 357 std::string size = key_type.substr(0, pos); | 497 std::string size = key_type.substr(0, pos); | 
| 358 std::string type = key_type.substr(pos + 1); | 498 std::string type = key_type.substr(pos + 1); | 
| 359 | 499 | 
| 360 if (type == "rsa" || type == "dsa") | 500 if (type == "rsa" || type == "dsa") | 
| 361 return size == "768"; | 501 return size == "768"; | 
| 362 | 502 | 
| 363 return false; | 503 return false; | 
| 364 } | 504 } | 
| 365 | 505 | 
| 366 TEST_F(CertVerifyProcTest, RejectWeakKeys) { | 506 TEST_P(CertVerifyProcTest, RejectWeakKeys) { | 
| 367 base::FilePath certs_dir = GetTestCertsDirectory(); | 507 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 368 typedef std::vector<std::string> Strings; | 508 typedef std::vector<std::string> Strings; | 
| 369 Strings key_types; | 509 Strings key_types; | 
| 370 | 510 | 
| 371 // generate-weak-test-chains.sh currently has: | 511 // generate-weak-test-chains.sh currently has: | 
| 372 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" | 512 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" | 
| 373 // We must use the same key types here. The filenames generated look like: | 513 // We must use the same key types here. The filenames generated look like: | 
| 374 // 2048-rsa-ee-by-768-rsa-intermediate.pem | 514 // 2048-rsa-ee-by-768-rsa-intermediate.pem | 
| 375 key_types.push_back("768-rsa"); | 515 key_types.push_back("768-rsa"); | 
| 376 key_types.push_back("1024-rsa"); | 516 key_types.push_back("1024-rsa"); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 "127.0.0.1", | 551 "127.0.0.1", | 
| 412 0, | 552 0, | 
| 413 NULL, | 553 NULL, | 
| 414 empty_cert_list_, | 554 empty_cert_list_, | 
| 415 &verify_result); | 555 &verify_result); | 
| 416 | 556 | 
| 417 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 557 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 
| 418 EXPECT_NE(OK, error); | 558 EXPECT_NE(OK, error); | 
| 419 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 559 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 
| 420 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 560 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 
| 421 EXPECT_EQ(WeakKeysAreInvalid() ? CERT_STATUS_INVALID : 0, | 561 EXPECT_EQ( | 
| 422 verify_result.cert_status & CERT_STATUS_INVALID); | 562 WeakKeysAreInvalid(verify_proc_name_) ? CERT_STATUS_INVALID : 0, | 
| 563 verify_result.cert_status & CERT_STATUS_INVALID); | |
| 423 } else { | 564 } else { | 
| 424 EXPECT_THAT(error, IsOk()); | 565 EXPECT_THAT(error, IsOk()); | 
| 425 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 566 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 
| 426 } | 567 } | 
| 427 } | 568 } | 
| 428 } | 569 } | 
| 429 } | 570 } | 
| 430 | 571 | 
| 431 // Regression test for http://crbug.com/108514. | 572 // Regression test for http://crbug.com/108514. | 
| 432 #if defined(OS_MACOSX) && !defined(OS_IOS) | 573 TEST_P(CertVerifyProcTest, ExtraneousMD5RootCert) { | 
| 433 // Disabled on OS X - Security.framework doesn't ignore superflous certificates | 574 if (!SupportsReturningVerifiedChain(verify_proc_name_)) { | 
| 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()) { | |
| 442 LOG(INFO) << "Skipping this test in this platform."; | 575 LOG(INFO) << "Skipping this test in this platform."; | 
| 443 return; | 576 return; | 
| 444 } | 577 } | 
| 445 | 578 | 
| 579 if (UsingCertVerifyProcMac()) { | |
| 580 // Disabled on OS X - Security.framework doesn't ignore superflous | |
| 581 // certificates provided by servers. | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
This is probably fixed by mattm's changes.
 
eroman
2017/02/01 01:13:55
Acknowledged -- left a TODO
 
 | |
| 582 LOG(INFO) << "Skipping this test as Security.framework doesn't ignore " | |
| 583 "superflous certificates provided by servers."; | |
| 584 return; | |
| 585 } | |
| 586 | |
| 446 base::FilePath certs_dir = GetTestCertsDirectory(); | 587 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 447 | 588 | 
| 448 scoped_refptr<X509Certificate> server_cert = | 589 scoped_refptr<X509Certificate> server_cert = | 
| 449 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); | 590 ImportCertFromFile(certs_dir, "cross-signed-leaf.pem"); | 
| 450 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 591 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 
| 451 | 592 | 
| 452 scoped_refptr<X509Certificate> extra_cert = | 593 scoped_refptr<X509Certificate> extra_cert = | 
| 453 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); | 594 ImportCertFromFile(certs_dir, "cross-signed-root-md5.pem"); | 
| 454 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); | 595 ASSERT_NE(static_cast<X509Certificate*>(NULL), extra_cert.get()); | 
| 455 | 596 | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 480 ASSERT_EQ(1u, | 621 ASSERT_EQ(1u, | 
| 481 verify_result.verified_cert->GetIntermediateCertificates().size()); | 622 verify_result.verified_cert->GetIntermediateCertificates().size()); | 
| 482 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 623 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 
| 483 verify_result.verified_cert->GetIntermediateCertificates().front(), | 624 verify_result.verified_cert->GetIntermediateCertificates().front(), | 
| 484 root_cert->os_cert_handle())); | 625 root_cert->os_cert_handle())); | 
| 485 | 626 | 
| 486 EXPECT_FALSE(verify_result.has_md5); | 627 EXPECT_FALSE(verify_result.has_md5); | 
| 487 } | 628 } | 
| 488 | 629 | 
| 489 // Test for bug 94673. | 630 // Test for bug 94673. | 
| 490 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) { | 631 TEST_P(CertVerifyProcTest, GoogleDigiNotarTest) { | 
| 491 base::FilePath certs_dir = GetTestCertsDirectory(); | 632 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 492 | 633 | 
| 493 scoped_refptr<X509Certificate> server_cert = | 634 scoped_refptr<X509Certificate> server_cert = | 
| 494 ImportCertFromFile(certs_dir, "google_diginotar.pem"); | 635 ImportCertFromFile(certs_dir, "google_diginotar.pem"); | 
| 495 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 636 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 
| 496 | 637 | 
| 497 scoped_refptr<X509Certificate> intermediate_cert = | 638 scoped_refptr<X509Certificate> intermediate_cert = | 
| 498 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); | 639 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); | 
| 499 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert.get()); | 640 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert.get()); | 
| 500 | 641 | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 521 "mail.google.com", | 662 "mail.google.com", | 
| 522 flags, | 663 flags, | 
| 523 NULL, | 664 NULL, | 
| 524 empty_cert_list_, | 665 empty_cert_list_, | 
| 525 &verify_result); | 666 &verify_result); | 
| 526 EXPECT_NE(OK, error); | 667 EXPECT_NE(OK, error); | 
| 527 } | 668 } | 
| 528 | 669 | 
| 529 // Ensures the CertVerifyProc blacklist remains in sorted order, so that it | 670 // Ensures the CertVerifyProc blacklist remains in sorted order, so that it | 
| 530 // can be binary-searched. | 671 // can be binary-searched. | 
| 531 TEST_F(CertVerifyProcTest, BlacklistIsSorted) { | 672 TEST_P(CertVerifyProcTest, BlacklistIsSorted) { | 
| 532 // Defines kBlacklistedSPKIs. | 673 // Defines kBlacklistedSPKIs. | 
| 533 #include "net/cert/cert_verify_proc_blacklist.inc" | 674 #include "net/cert/cert_verify_proc_blacklist.inc" | 
| 534 for (size_t i = 0; i < arraysize(kBlacklistedSPKIs) - 1; ++i) { | 675 for (size_t i = 0; i < arraysize(kBlacklistedSPKIs) - 1; ++i) { | 
| 535 EXPECT_GT(0, memcmp(kBlacklistedSPKIs[i], kBlacklistedSPKIs[i + 1], | 676 EXPECT_GT(0, memcmp(kBlacklistedSPKIs[i], kBlacklistedSPKIs[i + 1], | 
| 536 crypto::kSHA256Length)) | 677 crypto::kSHA256Length)) | 
| 537 << " at index " << i; | 678 << " at index " << i; | 
| 538 } | 679 } | 
| 539 } | 680 } | 
| 540 | 681 | 
| 541 TEST_F(CertVerifyProcTest, DigiNotarCerts) { | 682 TEST_P(CertVerifyProcTest, DigiNotarCerts) { | 
| 542 static const char* const kDigiNotarFilenames[] = { | 683 static const char* const kDigiNotarFilenames[] = { | 
| 543 "diginotar_root_ca.pem", | 684 "diginotar_root_ca.pem", | 
| 544 "diginotar_cyber_ca.pem", | 685 "diginotar_cyber_ca.pem", | 
| 545 "diginotar_services_1024_ca.pem", | 686 "diginotar_services_1024_ca.pem", | 
| 546 "diginotar_pkioverheid.pem", | 687 "diginotar_pkioverheid.pem", | 
| 547 "diginotar_pkioverheid_g2.pem", | 688 "diginotar_pkioverheid_g2.pem", | 
| 548 NULL, | 689 NULL, | 
| 549 }; | 690 }; | 
| 550 | 691 | 
| 551 base::FilePath certs_dir = GetTestCertsDirectory(); | 692 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 566 HashValue hash(HASH_VALUE_SHA256); | 707 HashValue hash(HASH_VALUE_SHA256); | 
| 567 ASSERT_EQ(hash.size(), spki_sha256.size()); | 708 ASSERT_EQ(hash.size(), spki_sha256.size()); | 
| 568 memcpy(hash.data(), spki_sha256.data(), spki_sha256.size()); | 709 memcpy(hash.data(), spki_sha256.data(), spki_sha256.size()); | 
| 569 public_keys.push_back(hash); | 710 public_keys.push_back(hash); | 
| 570 | 711 | 
| 571 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) << | 712 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) << | 
| 572 "Public key not blocked for " << kDigiNotarFilenames[i]; | 713 "Public key not blocked for " << kDigiNotarFilenames[i]; | 
| 573 } | 714 } | 
| 574 } | 715 } | 
| 575 | 716 | 
| 576 TEST_F(CertVerifyProcTest, NameConstraintsOk) { | 717 TEST_P(CertVerifyProcTest, NameConstraintsOk) { | 
| 577 CertificateList ca_cert_list = | 718 CertificateList ca_cert_list = | 
| 578 CreateCertificateListFromFile(GetTestCertsDirectory(), | 719 CreateCertificateListFromFile(GetTestCertsDirectory(), | 
| 579 "root_ca_cert.pem", | 720 "root_ca_cert.pem", | 
| 580 X509Certificate::FORMAT_AUTO); | 721 X509Certificate::FORMAT_AUTO); | 
| 581 ASSERT_EQ(1U, ca_cert_list.size()); | 722 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 582 ScopedTestRoot test_root(ca_cert_list[0].get()); | 723 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 583 | 724 | 
| 584 CertificateList cert_list = CreateCertificateListFromFile( | 725 CertificateList cert_list = CreateCertificateListFromFile( | 
| 585 GetTestCertsDirectory(), "name_constraint_good.pem", | 726 GetTestCertsDirectory(), "name_constraint_good.pem", | 
| 586 X509Certificate::FORMAT_AUTO); | 727 X509Certificate::FORMAT_AUTO); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 601 &verify_result); | 742 &verify_result); | 
| 602 EXPECT_THAT(error, IsOk()); | 743 EXPECT_THAT(error, IsOk()); | 
| 603 EXPECT_EQ(0U, verify_result.cert_status); | 744 EXPECT_EQ(0U, verify_result.cert_status); | 
| 604 | 745 | 
| 605 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL, | 746 error = Verify(leaf.get(), "foo.test2.example.com", flags, NULL, | 
| 606 empty_cert_list_, &verify_result); | 747 empty_cert_list_, &verify_result); | 
| 607 EXPECT_THAT(error, IsOk()); | 748 EXPECT_THAT(error, IsOk()); | 
| 608 EXPECT_EQ(0U, verify_result.cert_status); | 749 EXPECT_EQ(0U, verify_result.cert_status); | 
| 609 } | 750 } | 
| 610 | 751 | 
| 611 TEST_F(CertVerifyProcTest, NameConstraintsFailure) { | 752 TEST_P(CertVerifyProcTest, NameConstraintsFailure) { | 
| 612 if (!SupportsReturningVerifiedChain()) { | 753 if (!SupportsReturningVerifiedChain(verify_proc_name_)) { | 
| 613 LOG(INFO) << "Skipping this test in this platform."; | 754 LOG(INFO) << "Skipping this test in this platform."; | 
| 614 return; | 755 return; | 
| 615 } | 756 } | 
| 616 | 757 | 
| 617 CertificateList ca_cert_list = | 758 CertificateList ca_cert_list = | 
| 618 CreateCertificateListFromFile(GetTestCertsDirectory(), | 759 CreateCertificateListFromFile(GetTestCertsDirectory(), | 
| 619 "root_ca_cert.pem", | 760 "root_ca_cert.pem", | 
| 620 X509Certificate::FORMAT_AUTO); | 761 X509Certificate::FORMAT_AUTO); | 
| 621 ASSERT_EQ(1U, ca_cert_list.size()); | 762 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 622 ScopedTestRoot test_root(ca_cert_list[0].get()); | 763 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 637 "test.example.com", | 778 "test.example.com", | 
| 638 flags, | 779 flags, | 
| 639 NULL, | 780 NULL, | 
| 640 empty_cert_list_, | 781 empty_cert_list_, | 
| 641 &verify_result); | 782 &verify_result); | 
| 642 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION)); | 783 EXPECT_THAT(error, IsError(ERR_CERT_NAME_CONSTRAINT_VIOLATION)); | 
| 643 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, | 784 EXPECT_EQ(CERT_STATUS_NAME_CONSTRAINT_VIOLATION, | 
| 644 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); | 785 verify_result.cert_status & CERT_STATUS_NAME_CONSTRAINT_VIOLATION); | 
| 645 } | 786 } | 
| 646 | 787 | 
| 647 TEST_F(CertVerifyProcTest, TestHasTooLongValidity) { | 788 TEST_P(CertVerifyProcTest, TestHasTooLongValidity) { | 
| 648 struct { | 789 struct { | 
| 649 const char* const file; | 790 const char* const file; | 
| 650 bool is_valid_too_long; | 791 bool is_valid_too_long; | 
| 651 } tests[] = { | 792 } tests[] = { | 
| 652 {"twitter-chain.pem", false}, | 793 {"twitter-chain.pem", false}, | 
| 653 {"start_after_expiry.pem", true}, | 794 {"start_after_expiry.pem", true}, | 
| 654 {"pre_br_validity_ok.pem", false}, | 795 {"pre_br_validity_ok.pem", false}, | 
| 655 {"pre_br_validity_bad_121.pem", true}, | 796 {"pre_br_validity_bad_121.pem", true}, | 
| 656 {"pre_br_validity_bad_2020.pem", true}, | 797 {"pre_br_validity_bad_2020.pem", true}, | 
| 657 {"10_year_validity.pem", false}, | 798 {"10_year_validity.pem", false}, | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 668 scoped_refptr<X509Certificate> certificate = | 809 scoped_refptr<X509Certificate> certificate = | 
| 669 ImportCertFromFile(certs_dir, tests[i].file); | 810 ImportCertFromFile(certs_dir, tests[i].file); | 
| 670 SCOPED_TRACE(tests[i].file); | 811 SCOPED_TRACE(tests[i].file); | 
| 671 ASSERT_TRUE(certificate); | 812 ASSERT_TRUE(certificate); | 
| 672 EXPECT_EQ(tests[i].is_valid_too_long, | 813 EXPECT_EQ(tests[i].is_valid_too_long, | 
| 673 CertVerifyProc::HasTooLongValidity(*certificate)); | 814 CertVerifyProc::HasTooLongValidity(*certificate)); | 
| 674 } | 815 } | 
| 675 } | 816 } | 
| 676 | 817 | 
| 677 // TODO(crbug.com/610546): Fix and re-enable this test. | 818 // TODO(crbug.com/610546): Fix and re-enable this test. | 
| 678 TEST_F(CertVerifyProcTest, DISABLED_TestKnownRoot) { | 819 TEST_P(CertVerifyProcTest, DISABLED_TestKnownRoot) { | 
| 679 if (!SupportsDetectingKnownRoots()) { | 820 if (!SupportsDetectingKnownRoots(verify_proc_name_)) { | 
| 680 LOG(INFO) << "Skipping this test on this platform."; | 821 LOG(INFO) << "Skipping this test on this platform."; | 
| 681 return; | 822 return; | 
| 682 } | 823 } | 
| 683 | 824 | 
| 684 base::FilePath certs_dir = GetTestCertsDirectory(); | 825 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 685 CertificateList certs = CreateCertificateListFromFile( | 826 CertificateList certs = CreateCertificateListFromFile( | 
| 686 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 827 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 
| 687 ASSERT_EQ(3U, certs.size()); | 828 ASSERT_EQ(3U, certs.size()); | 
| 688 | 829 | 
| 689 X509Certificate::OSCertHandles intermediates; | 830 X509Certificate::OSCertHandles intermediates; | 
| 690 intermediates.push_back(certs[1]->os_cert_handle()); | 831 intermediates.push_back(certs[1]->os_cert_handle()); | 
| 691 | 832 | 
| 692 scoped_refptr<X509Certificate> cert_chain = | 833 scoped_refptr<X509Certificate> cert_chain = | 
| 693 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 834 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 
| 694 intermediates); | 835 intermediates); | 
| 695 | 836 | 
| 696 int flags = 0; | 837 int flags = 0; | 
| 697 CertVerifyResult verify_result; | 838 CertVerifyResult verify_result; | 
| 698 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 839 // This will blow up, May 9th, 2016. Sorry! Please disable and file a bug | 
| 699 // against agl. See also PublicKeyHashes. | 840 // against agl. See also PublicKeyHashes. | 
| 700 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 841 int error = Verify(cert_chain.get(), "twitter.com", flags, NULL, | 
| 701 empty_cert_list_, &verify_result); | 842 empty_cert_list_, &verify_result); | 
| 702 EXPECT_THAT(error, IsOk()); | 843 EXPECT_THAT(error, IsOk()); | 
| 703 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 844 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 
| 704 } | 845 } | 
| 705 | 846 | 
| 706 // TODO(crbug.com/610546): Fix and re-enable this test. | 847 // TODO(crbug.com/610546): Fix and re-enable this test. | 
| 707 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) { | 848 TEST_P(CertVerifyProcTest, DISABLED_PublicKeyHashes) { | 
| 708 if (!SupportsReturningVerifiedChain()) { | 849 if (!SupportsReturningVerifiedChain(verify_proc_name_)) { | 
| 709 LOG(INFO) << "Skipping this test in this platform."; | 850 LOG(INFO) << "Skipping this test in this platform."; | 
| 710 return; | 851 return; | 
| 711 } | 852 } | 
| 712 | 853 | 
| 713 base::FilePath certs_dir = GetTestCertsDirectory(); | 854 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 714 CertificateList certs = CreateCertificateListFromFile( | 855 CertificateList certs = CreateCertificateListFromFile( | 
| 715 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 856 certs_dir, "twitter-chain.pem", X509Certificate::FORMAT_AUTO); | 
| 716 ASSERT_EQ(3U, certs.size()); | 857 ASSERT_EQ(3U, certs.size()); | 
| 717 | 858 | 
| 718 X509Certificate::OSCertHandles intermediates; | 859 X509Certificate::OSCertHandles intermediates; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 | 895 | 
| 755 for (size_t i = 0; i < 3; ++i) { | 896 for (size_t i = 0; i < 3; ++i) { | 
| 756 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), | 897 EXPECT_EQ(HexEncode(kTwitterSPKIsSHA256[i], crypto::kSHA256Length), | 
| 757 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 898 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length)); | 
| 758 } | 899 } | 
| 759 } | 900 } | 
| 760 | 901 | 
| 761 // A regression test for http://crbug.com/70293. | 902 // A regression test for http://crbug.com/70293. | 
| 762 // The Key Usage extension in this RSA SSL server certificate does not have | 903 // The Key Usage extension in this RSA SSL server certificate does not have | 
| 763 // the keyEncipherment bit. | 904 // the keyEncipherment bit. | 
| 764 TEST_F(CertVerifyProcTest, InvalidKeyUsage) { | 905 TEST_P(CertVerifyProcTest, InvalidKeyUsage) { | 
| 
 
Ryan Sleevi
2017/01/12 20:01:56
This seems like one of those tests we should be us
 
eroman
2017/02/01 01:13:55
Acknowledged -- left a TODO
 
 | |
| 765 base::FilePath certs_dir = GetTestCertsDirectory(); | 906 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 766 | 907 | 
| 767 scoped_refptr<X509Certificate> server_cert = | 908 scoped_refptr<X509Certificate> server_cert = | 
| 768 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 909 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 
| 769 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 910 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 
| 770 | 911 | 
| 771 int flags = 0; | 912 int flags = 0; | 
| 772 CertVerifyResult verify_result; | 913 CertVerifyResult verify_result; | 
| 773 int error = Verify(server_cert.get(), | 914 int error = Verify(server_cert.get(), "jira.aquameta.com", flags, NULL, | 
| 774 "jira.aquameta.com", | 915 empty_cert_list_, &verify_result); | 
| 775 flags, | 916 | 
| 776 NULL, | 917 if (UsingCertVerifyProcOpenSSL()) { | 
| 777 empty_cert_list_, | 918 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 
| 778 &verify_result); | 919 // However, OpenSSL returns only one (the latter), and we can't detect | 
| 779 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | 920 // the other errors. | 
| 780 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 921 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 781 // However, OpenSSL returns only one (the latter), and we can't detect | 922 } else { | 
| 782 // the other errors. | 923 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 783 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 924 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 784 #else | 925 } | 
| 785 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | |
| 786 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | |
| 787 #endif | |
| 788 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 926 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 
| 789 // from NSS. | 927 // from NSS. | 
| 790 #if !defined(USE_NSS_CERTS) && !defined(OS_IOS) && !defined(OS_ANDROID) | 928 if (!UsingCertVerifyProcNSS() && !UsingCertVerifyProcIOS() && | 
| 791 // The certificate is issued by an unknown CA. | 929 !UsingCertVerifyProcAndroid()) { | 
| 792 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 930 // The certificate is issued by an unknown CA. | 
| 793 #endif | 931 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 
| 932 } | |
| 933 | |
| 934 // TODO(crbug.com/649017): What expectations to use for the other verifiers? | |
| 794 } | 935 } | 
| 795 | 936 | 
| 796 // Basic test for returning the chain in CertVerifyResult. Note that the | 937 // Basic test for returning the chain in CertVerifyResult. Note that the | 
| 797 // returned chain may just be a reflection of the originally supplied chain; | 938 // 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 | 939 // 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 | 940 // of the certificate to be verified. The remaining VerifyReturn* tests are | 
| 800 // used to ensure that the actual, verified chain is being returned by | 941 // used to ensure that the actual, verified chain is being returned by | 
| 801 // Verify(). | 942 // Verify(). | 
| 802 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { | 943 TEST_P(CertVerifyProcTest, VerifyReturnChainBasic) { | 
| 803 if (!SupportsReturningVerifiedChain()) { | 944 if (!SupportsReturningVerifiedChain(verify_proc_name_)) { | 
| 804 LOG(INFO) << "Skipping this test in this platform."; | 945 LOG(INFO) << "Skipping this test in this platform."; | 
| 805 return; | 946 return; | 
| 806 } | 947 } | 
| 807 | 948 | 
| 808 base::FilePath certs_dir = GetTestCertsDirectory(); | 949 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 809 CertificateList certs = CreateCertificateListFromFile( | 950 CertificateList certs = CreateCertificateListFromFile( | 
| 810 certs_dir, "x509_verify_results.chain.pem", | 951 certs_dir, "x509_verify_results.chain.pem", | 
| 811 X509Certificate::FORMAT_AUTO); | 952 X509Certificate::FORMAT_AUTO); | 
| 812 ASSERT_EQ(3U, certs.size()); | 953 ASSERT_EQ(3U, certs.size()); | 
| 813 | 954 | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 987 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 
| 847 certs[1]->os_cert_handle())); | 988 certs[1]->os_cert_handle())); | 
| 848 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 989 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 
| 849 certs[2]->os_cert_handle())); | 990 certs[2]->os_cert_handle())); | 
| 850 } | 991 } | 
| 851 | 992 | 
| 852 // Test that certificates issued for 'intranet' names (that is, containing no | 993 // Test that certificates issued for 'intranet' names (that is, containing no | 
| 853 // known public registry controlled domain information) issued by well-known | 994 // known public registry controlled domain information) issued by well-known | 
| 854 // CAs are flagged appropriately, while certificates that are issued by | 995 // CAs are flagged appropriately, while certificates that are issued by | 
| 855 // internal CAs are not flagged. | 996 // internal CAs are not flagged. | 
| 856 TEST_F(CertVerifyProcTest, IntranetHostsRejected) { | 997 TEST_P(CertVerifyProcTest, IntranetHostsRejected) { | 
| 857 if (!SupportsDetectingKnownRoots()) { | 998 if (!SupportsDetectingKnownRoots(verify_proc_name_)) { | 
| 858 LOG(INFO) << "Skipping this test in this platform."; | 999 LOG(INFO) << "Skipping this test in this platform."; | 
| 859 return; | 1000 return; | 
| 860 } | 1001 } | 
| 861 | 1002 | 
| 862 CertificateList cert_list = CreateCertificateListFromFile( | 1003 CertificateList cert_list = CreateCertificateListFromFile( | 
| 863 GetTestCertsDirectory(), "reject_intranet_hosts.pem", | 1004 GetTestCertsDirectory(), "reject_intranet_hosts.pem", | 
| 864 X509Certificate::FORMAT_AUTO); | 1005 X509Certificate::FORMAT_AUTO); | 
| 865 ASSERT_EQ(1U, cert_list.size()); | 1006 ASSERT_EQ(1U, cert_list.size()); | 
| 866 scoped_refptr<X509Certificate> cert(cert_list[0]); | 1007 scoped_refptr<X509Certificate> cert(cert_list[0]); | 
| 867 | 1008 | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 886 EXPECT_THAT(error, IsOk()); | 1027 EXPECT_THAT(error, IsOk()); | 
| 887 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 1028 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME); | 
| 888 } | 1029 } | 
| 889 | 1030 | 
| 890 // While all SHA-1 certificates should be rejected, in the event that there | 1031 // While all SHA-1 certificates should be rejected, in the event that there | 
| 891 // emerges some unexpected bug, test that the 'legacy' behaviour works | 1032 // emerges some unexpected bug, test that the 'legacy' behaviour works | 
| 892 // correctly - rejecting all SHA-1 certificates from publicly trusted CAs | 1033 // correctly - rejecting all SHA-1 certificates from publicly trusted CAs | 
| 893 // that were issued after 1 January 2016, while still allowing those from | 1034 // 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 | 1035 // before that date, with SHA-1 in the intermediate, or from an enterprise | 
| 895 // CA. | 1036 // CA. | 
| 896 TEST_F(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecationLegacyMode) { | 1037 TEST_P(CertVerifyProcTest, VerifyRejectsSHA1AfterDeprecationLegacyMode) { | 
| 897 base::test::ScopedFeatureList scoped_feature_list; | 1038 base::test::ScopedFeatureList scoped_feature_list; | 
| 898 scoped_feature_list.InitAndEnableFeature(CertVerifyProc::kSHA1LegacyMode); | 1039 scoped_feature_list.InitAndEnableFeature(CertVerifyProc::kSHA1LegacyMode); | 
| 899 | 1040 | 
| 900 CertVerifyResult dummy_result; | 1041 CertVerifyResult dummy_result; | 
| 901 CertVerifyResult verify_result; | 1042 CertVerifyResult verify_result; | 
| 902 int error = 0; | 1043 int error = 0; | 
| 903 scoped_refptr<X509Certificate> cert; | 1044 scoped_refptr<X509Certificate> cert; | 
| 904 | 1045 | 
| 905 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 | 1046 // Publicly trusted SHA-1 leaf certificates issued before 1 January 2016 | 
| 906 // are accepted. | 1047 // are accepted. | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 &verify_result); | 1110 &verify_result); | 
| 970 EXPECT_THAT(error, IsOk()); | 1111 EXPECT_THAT(error, IsOk()); | 
| 971 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1112 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 972 } | 1113 } | 
| 973 | 1114 | 
| 974 // Test that the certificate returned in CertVerifyResult is able to reorder | 1115 // 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 | 1116 // 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 | 1117 // a protocol violation if sent during a TLS handshake, if multiple sources | 
| 977 // of intermediate certificates are combined, it's possible that order may | 1118 // of intermediate certificates are combined, it's possible that order may | 
| 978 // not be maintained. | 1119 // not be maintained. | 
| 979 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { | 1120 TEST_P(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { | 
| 980 if (!SupportsReturningVerifiedChain()) { | 1121 if (!SupportsReturningVerifiedChain(verify_proc_name_)) { | 
| 981 LOG(INFO) << "Skipping this test in this platform."; | 1122 LOG(INFO) << "Skipping this test in this platform."; | 
| 982 return; | 1123 return; | 
| 983 } | 1124 } | 
| 984 | 1125 | 
| 985 base::FilePath certs_dir = GetTestCertsDirectory(); | 1126 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 986 CertificateList certs = CreateCertificateListFromFile( | 1127 CertificateList certs = CreateCertificateListFromFile( | 
| 987 certs_dir, "x509_verify_results.chain.pem", | 1128 certs_dir, "x509_verify_results.chain.pem", | 
| 988 X509Certificate::FORMAT_AUTO); | 1129 X509Certificate::FORMAT_AUTO); | 
| 989 ASSERT_EQ(3U, certs.size()); | 1130 ASSERT_EQ(3U, certs.size()); | 
| 990 | 1131 | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 verify_result.verified_cert->GetIntermediateCertificates(); | 1163 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1023 ASSERT_EQ(2U, return_intermediates.size()); | 1164 ASSERT_EQ(2U, return_intermediates.size()); | 
| 1024 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1165 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 
| 1025 certs[1]->os_cert_handle())); | 1166 certs[1]->os_cert_handle())); | 
| 1026 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1167 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 
| 1027 certs[2]->os_cert_handle())); | 1168 certs[2]->os_cert_handle())); | 
| 1028 } | 1169 } | 
| 1029 | 1170 | 
| 1030 // Test that Verify() filters out certificates which are not related to | 1171 // Test that Verify() filters out certificates which are not related to | 
| 1031 // or part of the certificate chain being verified. | 1172 // or part of the certificate chain being verified. | 
| 1032 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { | 1173 TEST_P(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { | 
| 1033 if (!SupportsReturningVerifiedChain()) { | 1174 if (!SupportsReturningVerifiedChain(verify_proc_name_)) { | 
| 1034 LOG(INFO) << "Skipping this test in this platform."; | 1175 LOG(INFO) << "Skipping this test in this platform."; | 
| 1035 return; | 1176 return; | 
| 1036 } | 1177 } | 
| 1037 | 1178 | 
| 1038 base::FilePath certs_dir = GetTestCertsDirectory(); | 1179 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 1039 CertificateList certs = CreateCertificateListFromFile( | 1180 CertificateList certs = CreateCertificateListFromFile( | 
| 1040 certs_dir, "x509_verify_results.chain.pem", | 1181 certs_dir, "x509_verify_results.chain.pem", | 
| 1041 X509Certificate::FORMAT_AUTO); | 1182 X509Certificate::FORMAT_AUTO); | 
| 1042 ASSERT_EQ(3U, certs.size()); | 1183 ASSERT_EQ(3U, certs.size()); | 
| 1043 ScopedTestRoot scoped_root(certs[2].get()); | 1184 ScopedTestRoot scoped_root(certs[2].get()); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 verify_result.verified_cert->os_cert_handle())); | 1222 verify_result.verified_cert->os_cert_handle())); | 
| 1082 const X509Certificate::OSCertHandles& return_intermediates = | 1223 const X509Certificate::OSCertHandles& return_intermediates = | 
| 1083 verify_result.verified_cert->GetIntermediateCertificates(); | 1224 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1084 ASSERT_EQ(2U, return_intermediates.size()); | 1225 ASSERT_EQ(2U, return_intermediates.size()); | 
| 1085 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1226 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 
| 1086 certs[1]->os_cert_handle())); | 1227 certs[1]->os_cert_handle())); | 
| 1087 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1228 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 
| 1088 certs[2]->os_cert_handle())); | 1229 certs[2]->os_cert_handle())); | 
| 1089 } | 1230 } | 
| 1090 | 1231 | 
| 1091 TEST_F(CertVerifyProcTest, AdditionalTrustAnchors) { | 1232 TEST_P(CertVerifyProcTest, AdditionalTrustAnchors) { | 
| 1092 if (!SupportsAdditionalTrustAnchors()) { | 1233 if (!SupportsAdditionalTrustAnchors()) { | 
| 1093 LOG(INFO) << "Skipping this test in this platform."; | 1234 LOG(INFO) << "Skipping this test in this platform."; | 
| 1094 return; | 1235 return; | 
| 1095 } | 1236 } | 
| 1096 | 1237 | 
| 1097 // |ca_cert| is the issuer of |cert|. | 1238 // |ca_cert| is the issuer of |cert|. | 
| 1098 CertificateList ca_cert_list = CreateCertificateListFromFile( | 1239 CertificateList ca_cert_list = CreateCertificateListFromFile( | 
| 1099 GetTestCertsDirectory(), "root_ca_cert.pem", | 1240 GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 1100 X509Certificate::FORMAT_AUTO); | 1241 X509Certificate::FORMAT_AUTO); | 
| 1101 ASSERT_EQ(1U, ca_cert_list.size()); | 1242 ASSERT_EQ(1U, ca_cert_list.size()); | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1131 error = Verify( | 1272 error = Verify( | 
| 1132 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1273 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 
| 1133 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 1274 EXPECT_THAT(error, IsError(ERR_CERT_AUTHORITY_INVALID)); | 
| 1134 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 1275 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status); | 
| 1135 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 1276 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor); | 
| 1136 } | 1277 } | 
| 1137 | 1278 | 
| 1138 // Tests that certificates issued by user-supplied roots are not flagged as | 1279 // 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 | 1280 // issued by a known root. This should pass whether or not the platform supports | 
| 1140 // detecting known roots. | 1281 // detecting known roots. | 
| 1141 TEST_F(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { | 1282 TEST_P(CertVerifyProcTest, IsIssuedByKnownRootIgnoresTestRoots) { | 
| 1142 // Load root_ca_cert.pem into the test root store. | 1283 // Load root_ca_cert.pem into the test root store. | 
| 1143 ScopedTestRoot test_root( | 1284 ScopedTestRoot test_root( | 
| 1144 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 1285 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 
| 1145 | 1286 | 
| 1146 scoped_refptr<X509Certificate> cert( | 1287 scoped_refptr<X509Certificate> cert( | 
| 1147 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1288 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1148 | 1289 | 
| 1149 // Verification should pass. | 1290 // Verification should pass. | 
| 1150 int flags = 0; | 1291 int flags = 0; | 
| 1151 CertVerifyResult verify_result; | 1292 CertVerifyResult verify_result; | 
| 1152 int error = Verify( | 1293 int error = Verify( | 
| 1153 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1294 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 
| 1154 EXPECT_THAT(error, IsOk()); | 1295 EXPECT_THAT(error, IsOk()); | 
| 1155 EXPECT_EQ(0U, verify_result.cert_status); | 1296 EXPECT_EQ(0U, verify_result.cert_status); | 
| 1156 // But should not be marked as a known root. | 1297 // But should not be marked as a known root. | 
| 1157 EXPECT_FALSE(verify_result.is_issued_by_known_root); | 1298 EXPECT_FALSE(verify_result.is_issued_by_known_root); | 
| 1158 } | 1299 } | 
| 1159 | 1300 | 
| 1160 #if defined(USE_NSS_CERTS) || defined(OS_WIN) || \ | 1301 bool SupportsCRLSet(CertVerifyProcName verify_proc_name) { | 
| 1161 (defined(OS_MACOSX) && !defined(OS_IOS)) | 1302 // TODO(crbug.com/649017): Support for built-in. | 
| 1303 return verify_proc_name == CERT_VERIFY_PROC_NSS || | |
| 1304 verify_proc_name == CERT_VERIFY_PROC_WIN || | |
| 1305 verify_proc_name == CERT_VERIFY_PROC_MAC; | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
I wonder whether these should be different tests (
 
eroman
2017/02/01 01:13:54
When you say "tests" do you mean unit-tests, or do
 
 | |
| 1306 } | |
| 1307 | |
| 1162 // Test that CRLSets are effective in making a certificate appear to be | 1308 // Test that CRLSets are effective in making a certificate appear to be | 
| 1163 // revoked. | 1309 // revoked. | 
| 1164 TEST_F(CertVerifyProcTest, CRLSet) { | 1310 TEST_P(CertVerifyProcTest, CRLSet) { | 
| 1311 if (!SupportsCRLSet(verify_proc_name_)) { | |
| 1312 LOG(INFO) << "Skipping test as verifier doesn't support CRLSet"; | |
| 1313 return; | |
| 1314 } | |
| 1315 | |
| 1165 CertificateList ca_cert_list = | 1316 CertificateList ca_cert_list = | 
| 1166 CreateCertificateListFromFile(GetTestCertsDirectory(), | 1317 CreateCertificateListFromFile(GetTestCertsDirectory(), | 
| 1167 "root_ca_cert.pem", | 1318 "root_ca_cert.pem", | 
| 1168 X509Certificate::FORMAT_AUTO); | 1319 X509Certificate::FORMAT_AUTO); | 
| 1169 ASSERT_EQ(1U, ca_cert_list.size()); | 1320 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 1170 ScopedTestRoot test_root(ca_cert_list[0].get()); | 1321 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 1171 | 1322 | 
| 1172 CertificateList cert_list = CreateCertificateListFromFile( | 1323 CertificateList cert_list = CreateCertificateListFromFile( | 
| 1173 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); | 1324 GetTestCertsDirectory(), "ok_cert.pem", X509Certificate::FORMAT_AUTO); | 
| 1174 ASSERT_EQ(1U, cert_list.size()); | 1325 ASSERT_EQ(1U, cert_list.size()); | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1208 | 1359 | 
| 1209 error = Verify(cert.get(), | 1360 error = Verify(cert.get(), | 
| 1210 "127.0.0.1", | 1361 "127.0.0.1", | 
| 1211 flags, | 1362 flags, | 
| 1212 crl_set.get(), | 1363 crl_set.get(), | 
| 1213 empty_cert_list_, | 1364 empty_cert_list_, | 
| 1214 &verify_result); | 1365 &verify_result); | 
| 1215 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 1366 EXPECT_THAT(error, IsError(ERR_CERT_REVOKED)); | 
| 1216 } | 1367 } | 
| 1217 | 1368 | 
| 1218 TEST_F(CertVerifyProcTest, CRLSetLeafSerial) { | 1369 TEST_P(CertVerifyProcTest, CRLSetLeafSerial) { | 
| 1370 if (!SupportsCRLSet(verify_proc_name_)) { | |
| 1371 LOG(INFO) << "Skipping test as verifier doesn't support CRLSet"; | |
| 1372 return; | |
| 1373 } | |
| 1374 | |
| 1219 CertificateList ca_cert_list = | 1375 CertificateList ca_cert_list = | 
| 1220 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 1376 CreateCertificateListFromFile(GetTestCertsDirectory(), "root_ca_cert.pem", | 
| 1221 X509Certificate::FORMAT_AUTO); | 1377 X509Certificate::FORMAT_AUTO); | 
| 1222 ASSERT_EQ(1U, ca_cert_list.size()); | 1378 ASSERT_EQ(1U, ca_cert_list.size()); | 
| 1223 ScopedTestRoot test_root(ca_cert_list[0].get()); | 1379 ScopedTestRoot test_root(ca_cert_list[0].get()); | 
| 1224 | 1380 | 
| 1225 CertificateList intermediate_cert_list = CreateCertificateListFromFile( | 1381 CertificateList intermediate_cert_list = CreateCertificateListFromFile( | 
| 1226 GetTestCertsDirectory(), "intermediate_ca_cert.pem", | 1382 GetTestCertsDirectory(), "intermediate_ca_cert.pem", | 
| 1227 X509Certificate::FORMAT_AUTO); | 1383 X509Certificate::FORMAT_AUTO); | 
| 1228 ASSERT_EQ(1U, intermediate_cert_list.size()); | 1384 ASSERT_EQ(1U, intermediate_cert_list.size()); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 // In this test, there are two roots (D and E), and three possible paths | 1420 // In this test, there are two roots (D and E), and three possible paths | 
| 1265 // to validate a leaf (A): | 1421 // to validate a leaf (A): | 
| 1266 // 1. A(B) -> B(C) -> C(D) -> D(D) | 1422 // 1. A(B) -> B(C) -> C(D) -> D(D) | 
| 1267 // 2. A(B) -> B(C) -> C(E) -> E(E) | 1423 // 2. A(B) -> B(C) -> C(E) -> E(E) | 
| 1268 // 3. A(B) -> B(F) -> F(E) -> E(E) | 1424 // 3. A(B) -> B(F) -> F(E) -> E(E) | 
| 1269 // | 1425 // | 
| 1270 // Each permutation of revocation is tried: | 1426 // 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) | 1427 // 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. | 1428 // 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) | 1429 // 3. Revoking C by SPKI, so that only Path 3 is valid (as C is in Paths 1 & 2) | 
| 1274 TEST_F(CertVerifyProcTest, CRLSetDuringPathBuilding) { | 1430 TEST_P(CertVerifyProcTest, CRLSetDuringPathBuilding) { | 
| 1275 if (!SupportsCRLSetsInPathBuilding()) { | 1431 if (!SupportsCRLSetsInPathBuilding(verify_proc_name_)) { | 
| 1276 LOG(INFO) << "Skipping this test on this platform."; | 1432 LOG(INFO) << "Skipping this test on this platform."; | 
| 1277 return; | 1433 return; | 
| 1278 } | 1434 } | 
| 1279 | 1435 | 
| 1280 const char* const kPath1Files[] = { | 1436 const char* const kPath1Files[] = { | 
| 1281 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-D.pem", | 1437 "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"}; | 1438 "multi-root-D-by-D.pem"}; | 
| 1283 const char* const kPath2Files[] = { | 1439 const char* const kPath2Files[] = { | 
| 1284 "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", | 
| 1285 "multi-root-E-by-E.pem"}; | 1441 "multi-root-E-by-E.pem"}; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1363 ASSERT_TRUE(intermediate); | 1519 ASSERT_TRUE(intermediate); | 
| 1364 | 1520 | 
| 1365 EXPECT_TRUE(testcase.expected_intermediate->Equals(intermediate.get())) | 1521 EXPECT_TRUE(testcase.expected_intermediate->Equals(intermediate.get())) | 
| 1366 << "Expected: " << testcase.expected_intermediate->subject().common_name | 1522 << "Expected: " << testcase.expected_intermediate->subject().common_name | 
| 1367 << " issued by " << testcase.expected_intermediate->issuer().common_name | 1523 << " issued by " << testcase.expected_intermediate->issuer().common_name | 
| 1368 << "; Got: " << intermediate->subject().common_name << " issued by " | 1524 << "; Got: " << intermediate->subject().common_name << " issued by " | 
| 1369 << intermediate->issuer().common_name; | 1525 << intermediate->issuer().common_name; | 
| 1370 } | 1526 } | 
| 1371 } | 1527 } | 
| 1372 | 1528 | 
| 1373 #endif | |
| 1374 | |
| 1375 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1529 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1376 // Test that a CRLSet blocking one of the intermediates supplied by the server | 1530 // 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 | 1531 // 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 | 1532 // 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 | 1533 // 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.) | 1534 // of this test the better path is supplied by a test keychain.) | 
| 1381 // | 1535 // | 
| 1382 // In this test, there are two possible paths to validate a leaf (A): | 1536 // In this test, there are two possible paths to validate a leaf (A): | 
| 1383 // 1. A(B) -> B(C) -> C(E) -> E(E) | 1537 // 1. A(B) -> B(C) -> C(E) -> E(E) | 
| 1384 // 2. A(B) -> B(F) -> F(E) -> E(E) | 1538 // 2. A(B) -> B(F) -> F(E) -> E(E) | 
| 1385 // | 1539 // | 
| 1386 // A(B) -> B(C) -> C(E) is supplied to the verifier. | 1540 // A(B) -> B(C) -> C(E) is supplied to the verifier. | 
| 1387 // B(F) and F(E) are supplied in a test keychain. | 1541 // B(F) and F(E) are supplied in a test keychain. | 
| 1388 // C is blocked by a CRLset. | 1542 // C is blocked by a CRLset. | 
| 1389 // | 1543 // | 
| 1390 // The verifier should rollback until it just tries A(B) alone, at which point | 1544 // 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. | 1545 // it will pull B(F) & F(E) from the keychain and succeed. | 
| 1392 TEST_F(CertVerifyProcTest, MacCRLIntermediate) { | 1546 TEST_F(CertVerifyProcDefaultTest, MacCRLIntermediate) { | 
| 1393 if (base::mac::IsAtLeastOS10_12()) { | 1547 if (base::mac::IsAtLeastOS10_12()) { | 
| 1394 // TODO(crbug.com/671889): Investigate SecTrustSetKeychains issue on Sierra. | 1548 // TODO(crbug.com/671889): Investigate SecTrustSetKeychains issue on Sierra. | 
| 1395 LOG(INFO) << "Skipping test, SecTrustSetKeychains does not work on 10.12"; | 1549 LOG(INFO) << "Skipping test, SecTrustSetKeychains does not work on 10.12"; | 
| 1396 return; | 1550 return; | 
| 1397 } | 1551 } | 
| 1398 const char* const kPath2Files[] = { | 1552 const char* const kPath2Files[] = { | 
| 1399 "multi-root-A-by-B.pem", "multi-root-B-by-C.pem", "multi-root-C-by-E.pem", | 1553 "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"}; | 1554 "multi-root-E-by-E.pem"}; | 
| 1401 CertificateList path_2_certs; | 1555 CertificateList path_2_certs; | 
| 1402 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); | 1556 ASSERT_NO_FATAL_FAILURE(LoadCertificateFiles(kPath2Files, &path_2_certs)); | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 EXPECT_TRUE(expected_intermediate->Equals(intermediate.get())) | 1619 EXPECT_TRUE(expected_intermediate->Equals(intermediate.get())) | 
| 1466 << "Expected: " << expected_intermediate->subject().common_name | 1620 << "Expected: " << expected_intermediate->subject().common_name | 
| 1467 << " issued by " << expected_intermediate->issuer().common_name | 1621 << " issued by " << expected_intermediate->issuer().common_name | 
| 1468 << "; Got: " << intermediate->subject().common_name << " issued by " | 1622 << "; Got: " << intermediate->subject().common_name << " issued by " | 
| 1469 << intermediate->issuer().common_name; | 1623 << intermediate->issuer().common_name; | 
| 1470 } | 1624 } | 
| 1471 | 1625 | 
| 1472 // Test that if a keychain is present which trusts a less-desirable root (ex, | 1626 // 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 | 1627 // one using SHA1), that the keychain reordering hack will cause the better | 
| 1474 // root in the System Roots to be used instead. | 1628 // root in the System Roots to be used instead. | 
| 1475 TEST_F(CertVerifyProcTest, MacKeychainReordering) { | 1629 TEST_F(CertVerifyProcDefaultTest, MacKeychainReordering) { | 
| 1476 // Note: target cert expires Apr 2 23:59:59 2018 GMT | 1630 // Note: target cert expires Apr 2 23:59:59 2018 GMT | 
| 1477 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 1631 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | 
| 1478 GetTestCertsDirectory(), "tripadvisor-verisign-chain.pem", | 1632 GetTestCertsDirectory(), "tripadvisor-verisign-chain.pem", | 
| 1479 X509Certificate::FORMAT_AUTO); | 1633 X509Certificate::FORMAT_AUTO); | 
| 1480 ASSERT_TRUE(cert); | 1634 ASSERT_TRUE(cert); | 
| 1481 | 1635 | 
| 1482 // Create a test keychain search list that will Always Trust the SHA1 | 1636 // Create a test keychain search list that will Always Trust the SHA1 | 
| 1483 // cross-signed VeriSign Class 3 Public Primary Certification Authority - G5 | 1637 // cross-signed VeriSign Class 3 Public Primary Certification Authority - G5 | 
| 1484 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list( | 1638 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list( | 
| 1485 TestKeychainSearchList::Create()); | 1639 TestKeychainSearchList::Create()); | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1509 ASSERT_TRUE(verify_result.verified_cert.get()); | 1663 ASSERT_TRUE(verify_result.verified_cert.get()); | 
| 1510 | 1664 | 
| 1511 const X509Certificate::OSCertHandles& verified_intermediates = | 1665 const X509Certificate::OSCertHandles& verified_intermediates = | 
| 1512 verify_result.verified_cert->GetIntermediateCertificates(); | 1666 verify_result.verified_cert->GetIntermediateCertificates(); | 
| 1513 ASSERT_EQ(2U, verified_intermediates.size()); | 1667 ASSERT_EQ(2U, verified_intermediates.size()); | 
| 1514 } | 1668 } | 
| 1515 | 1669 | 
| 1516 // Test that the system root certificate keychain is in the expected location | 1670 // 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 | 1671 // and can be opened. Other tests would fail if this was not true, but this | 
| 1518 // test makes the reason for the failure obvious. | 1672 // test makes the reason for the failure obvious. | 
| 1519 TEST_F(CertVerifyProcTest, MacSystemRootCertificateKeychainLocation) { | 1673 TEST_F(CertVerifyProcDefaultTest, MacSystemRootCertificateKeychainLocation) { | 
| 1520 const char* root_keychain_path = | 1674 const char* root_keychain_path = | 
| 1521 "/System/Library/Keychains/SystemRootCertificates.keychain"; | 1675 "/System/Library/Keychains/SystemRootCertificates.keychain"; | 
| 1522 ASSERT_TRUE(base::PathExists(base::FilePath(root_keychain_path))); | 1676 ASSERT_TRUE(base::PathExists(base::FilePath(root_keychain_path))); | 
| 1523 | 1677 | 
| 1524 SecKeychainRef keychain; | 1678 SecKeychainRef keychain; | 
| 1525 OSStatus status = SecKeychainOpen(root_keychain_path, &keychain); | 1679 OSStatus status = SecKeychainOpen(root_keychain_path, &keychain); | 
| 1526 ASSERT_EQ(errSecSuccess, status); | 1680 ASSERT_EQ(errSecSuccess, status); | 
| 1527 CFRelease(keychain); | 1681 CFRelease(keychain); | 
| 1528 } | 1682 } | 
| 1529 #endif | 1683 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1530 | 1684 | 
| 1531 bool AreSHA1IntermediatesAllowed() { | 1685 bool AreSHA1IntermediatesAllowed(CertVerifyProcName verify_proc_name) { | 
| 1532 #if defined(OS_WIN) | 1686 #if defined(OS_WIN) | 
| 1533 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved | 1687 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved | 
| 1534 // for Windows 7/2008 users. | 1688 // for Windows 7/2008 users. | 
| 1535 // Note: This must be kept in sync with cert_verify_proc.cc | 1689 // Note: This must be kept in sync with cert_verify_proc.cc | 
| 1536 return base::win::GetVersion() < base::win::VERSION_WIN8; | 1690 return verify_proc_name == CERT_VERIFY_PROC_WIN && | 
| 1691 base::win::GetVersion() < base::win::VERSION_WIN8; | |
| 1537 #else | 1692 #else | 
| 1538 return false; | 1693 return false; | 
| 1539 #endif | 1694 #endif | 
| 1540 } | 1695 } | 
| 1541 | 1696 | 
| 1542 TEST_F(CertVerifyProcTest, RejectsMD2) { | 1697 TEST_P(CertVerifyProcTest, RejectsMD2) { | 
| 1543 scoped_refptr<X509Certificate> cert( | 1698 scoped_refptr<X509Certificate> cert( | 
| 1544 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1699 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1545 ASSERT_TRUE(cert); | 1700 ASSERT_TRUE(cert); | 
| 1546 | 1701 | 
| 1547 CertVerifyResult result; | 1702 CertVerifyResult result; | 
| 1548 result.has_md2 = true; | 1703 result.has_md2 = true; | 
| 1549 verify_proc_ = new MockCertVerifyProc(result); | 1704 verify_proc_ = new MockCertVerifyProc(result); | 
| 1550 | 1705 | 
| 1551 int flags = 0; | 1706 int flags = 0; | 
| 1552 CertVerifyResult verify_result; | 1707 CertVerifyResult verify_result; | 
| 1553 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1708 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 
| 1554 empty_cert_list_, &verify_result); | 1709 empty_cert_list_, &verify_result); | 
| 1555 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 1710 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 1556 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 1711 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 1557 } | 1712 } | 
| 1558 | 1713 | 
| 1559 TEST_F(CertVerifyProcTest, RejectsMD4) { | 1714 TEST_P(CertVerifyProcTest, RejectsMD4) { | 
| 1560 scoped_refptr<X509Certificate> cert( | 1715 scoped_refptr<X509Certificate> cert( | 
| 1561 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1716 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1562 ASSERT_TRUE(cert); | 1717 ASSERT_TRUE(cert); | 
| 1563 | 1718 | 
| 1564 CertVerifyResult result; | 1719 CertVerifyResult result; | 
| 1565 result.has_md4 = true; | 1720 result.has_md4 = true; | 
| 1566 verify_proc_ = new MockCertVerifyProc(result); | 1721 verify_proc_ = new MockCertVerifyProc(result); | 
| 1567 | 1722 | 
| 1568 int flags = 0; | 1723 int flags = 0; | 
| 1569 CertVerifyResult verify_result; | 1724 CertVerifyResult verify_result; | 
| 1570 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1725 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 
| 1571 empty_cert_list_, &verify_result); | 1726 empty_cert_list_, &verify_result); | 
| 1572 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 1727 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 1573 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 1728 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 1574 } | 1729 } | 
| 1575 | 1730 | 
| 1576 TEST_F(CertVerifyProcTest, RejectsMD5) { | 1731 TEST_P(CertVerifyProcTest, RejectsMD5) { | 
| 1577 scoped_refptr<X509Certificate> cert( | 1732 scoped_refptr<X509Certificate> cert( | 
| 1578 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1733 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1579 ASSERT_TRUE(cert); | 1734 ASSERT_TRUE(cert); | 
| 1580 | 1735 | 
| 1581 CertVerifyResult result; | 1736 CertVerifyResult result; | 
| 1582 result.has_md5 = true; | 1737 result.has_md5 = true; | 
| 1583 verify_proc_ = new MockCertVerifyProc(result); | 1738 verify_proc_ = new MockCertVerifyProc(result); | 
| 1584 | 1739 | 
| 1585 int flags = 0; | 1740 int flags = 0; | 
| 1586 CertVerifyResult verify_result; | 1741 CertVerifyResult verify_result; | 
| 1587 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1742 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 
| 1588 empty_cert_list_, &verify_result); | 1743 empty_cert_list_, &verify_result); | 
| 1589 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1744 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1590 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1745 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 1591 } | 1746 } | 
| 1592 | 1747 | 
| 1593 TEST_F(CertVerifyProcTest, RejectsPublicSHA1Leaves) { | 1748 TEST_P(CertVerifyProcTest, RejectsPublicSHA1Leaves) { | 
| 1594 scoped_refptr<X509Certificate> cert( | 1749 scoped_refptr<X509Certificate> cert( | 
| 1595 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1750 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1596 ASSERT_TRUE(cert); | 1751 ASSERT_TRUE(cert); | 
| 1597 | 1752 | 
| 1598 CertVerifyResult result; | 1753 CertVerifyResult result; | 
| 1599 result.has_sha1 = true; | 1754 result.has_sha1 = true; | 
| 1600 result.has_sha1_leaf = true; | 1755 result.has_sha1_leaf = true; | 
| 1601 result.is_issued_by_known_root = true; | 1756 result.is_issued_by_known_root = true; | 
| 1602 verify_proc_ = new MockCertVerifyProc(result); | 1757 verify_proc_ = new MockCertVerifyProc(result); | 
| 1603 | 1758 | 
| 1604 int flags = 0; | 1759 int flags = 0; | 
| 1605 CertVerifyResult verify_result; | 1760 CertVerifyResult verify_result; | 
| 1606 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1761 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 
| 1607 empty_cert_list_, &verify_result); | 1762 empty_cert_list_, &verify_result); | 
| 1608 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1763 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1609 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1764 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 1610 } | 1765 } | 
| 1611 | 1766 | 
| 1612 TEST_F(CertVerifyProcTest, RejectsPublicSHA1IntermediatesUnlessAllowed) { | 1767 TEST_P(CertVerifyProcTest, RejectsPublicSHA1IntermediatesUnlessAllowed) { | 
| 1613 scoped_refptr<X509Certificate> cert(ImportCertFromFile( | 1768 scoped_refptr<X509Certificate> cert(ImportCertFromFile( | 
| 1614 GetTestCertsDirectory(), "39_months_after_2015_04.pem")); | 1769 GetTestCertsDirectory(), "39_months_after_2015_04.pem")); | 
| 1615 ASSERT_TRUE(cert); | 1770 ASSERT_TRUE(cert); | 
| 1616 | 1771 | 
| 1617 CertVerifyResult result; | 1772 CertVerifyResult result; | 
| 1618 result.has_sha1 = true; | 1773 result.has_sha1 = true; | 
| 1619 result.has_sha1_leaf = false; | 1774 result.has_sha1_leaf = false; | 
| 1620 result.is_issued_by_known_root = true; | 1775 result.is_issued_by_known_root = true; | 
| 1621 verify_proc_ = new MockCertVerifyProc(result); | 1776 verify_proc_ = new MockCertVerifyProc(result); | 
| 1622 | 1777 | 
| 1623 int flags = 0; | 1778 int flags = 0; | 
| 1624 CertVerifyResult verify_result; | 1779 CertVerifyResult verify_result; | 
| 1625 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 1780 int error = Verify(cert.get(), "127.0.0.1", flags, nullptr /* crl_set */, | 
| 1626 empty_cert_list_, &verify_result); | 1781 empty_cert_list_, &verify_result); | 
| 1627 if (AreSHA1IntermediatesAllowed()) { | 1782 if (AreSHA1IntermediatesAllowed(verify_proc_name_)) { | 
| 1628 EXPECT_THAT(error, IsOk()); | 1783 EXPECT_THAT(error, IsOk()); | 
| 1629 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 1784 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_SHA1_SIGNATURE_PRESENT); | 
| 1630 } else { | 1785 } else { | 
| 1631 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 1786 EXPECT_THAT(error, IsError(ERR_CERT_WEAK_SIGNATURE_ALGORITHM)); | 
| 1632 EXPECT_TRUE(verify_result.cert_status & | 1787 EXPECT_TRUE(verify_result.cert_status & | 
| 1633 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 1788 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); | 
| 1634 } | 1789 } | 
| 1635 } | 1790 } | 
| 1636 | 1791 | 
| 1637 TEST_F(CertVerifyProcTest, RejectsPrivateSHA1UnlessFlag) { | 1792 TEST_P(CertVerifyProcTest, RejectsPrivateSHA1UnlessFlag) { | 
| 1638 scoped_refptr<X509Certificate> cert( | 1793 scoped_refptr<X509Certificate> cert( | 
| 1639 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 1794 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 1640 ASSERT_TRUE(cert); | 1795 ASSERT_TRUE(cert); | 
| 1641 | 1796 | 
| 1642 CertVerifyResult result; | 1797 CertVerifyResult result; | 
| 1643 result.has_sha1 = true; | 1798 result.has_sha1 = true; | 
| 1644 result.has_sha1_leaf = true; | 1799 result.has_sha1_leaf = true; | 
| 1645 result.is_issued_by_known_root = false; | 1800 result.is_issued_by_known_root = false; | 
| 1646 verify_proc_ = new MockCertVerifyProc(result); | 1801 verify_proc_ = new MockCertVerifyProc(result); | 
| 1647 | 1802 | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1687 // to output the parameter that was passed. Without this, it will simply | 1842 // to output the parameter that was passed. Without this, it will simply | 
| 1688 // attempt to print out the first twenty bytes of the object, which depending | 1843 // attempt to print out the first twenty bytes of the object, which depending | 
| 1689 // on platform and alignment, may result in an invalid read. | 1844 // on platform and alignment, may result in an invalid read. | 
| 1690 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { | 1845 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { | 
| 1691 *os << "root: " << StringOrDefault(data.root_cert_filename, "none") | 1846 *os << "root: " << StringOrDefault(data.root_cert_filename, "none") | 
| 1692 << "; intermediate: " | 1847 << "; intermediate: " | 
| 1693 << StringOrDefault(data.intermediate_cert_filename, "none") | 1848 << StringOrDefault(data.intermediate_cert_filename, "none") | 
| 1694 << "; end-entity: " << data.ee_cert_filename; | 1849 << "; end-entity: " << data.ee_cert_filename; | 
| 1695 } | 1850 } | 
| 1696 | 1851 | 
| 1852 // This test fixture does not subclass CertVerifyProcBaseTest as it is testing | |
| 1853 // a mock CertVerifyProc rather than one of the concrete types. | |
| 
 
Ryan Sleevi
2017/01/12 20:01:56
My two cents is I'm not sure that this comment is
 
eroman
2017/02/01 01:13:54
Done (removed)
Alternately I could re-write it as
 
 | |
| 1697 class CertVerifyProcWeakDigestTest | 1854 class CertVerifyProcWeakDigestTest | 
| 1698 : public CertVerifyProcTest, | 1855 : public testing::TestWithParam<WeakDigestTestData> { | 
| 1699 public testing::WithParamInterface<WeakDigestTestData> { | |
| 1700 public: | 1856 public: | 
| 1701 CertVerifyProcWeakDigestTest() {} | 1857 CertVerifyProcWeakDigestTest() {} | 
| 1702 virtual ~CertVerifyProcWeakDigestTest() {} | 1858 virtual ~CertVerifyProcWeakDigestTest() {} | 
| 1703 }; | 1859 }; | 
| 1704 | 1860 | 
| 1705 // Test that the CertVerifyProc::Verify() properly surfaces the (weak) hashing | 1861 // Tests that the CertVerifyProc::Verify() properly surfaces the (weak) hash | 
| 1706 // algorithms used in the chain. | 1862 // algorithms used in the chain. | 
| 1707 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) { | 1863 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) { | 
| 1708 WeakDigestTestData data = GetParam(); | 1864 WeakDigestTestData data = GetParam(); | 
| 1709 base::FilePath certs_dir = GetTestCertsDirectory(); | 1865 base::FilePath certs_dir = GetTestCertsDirectory(); | 
| 1710 | 1866 | 
| 1711 scoped_refptr<X509Certificate> intermediate_cert; | 1867 scoped_refptr<X509Certificate> intermediate_cert; | 
| 1712 scoped_refptr<X509Certificate> root_cert; | 1868 scoped_refptr<X509Certificate> root_cert; | 
| 1713 | 1869 | 
| 1714 // Build |intermediates| as the full chain (including trust anchor). | 1870 // Build |intermediates| as the full chain (including trust anchor). | 
| 1715 X509Certificate::OSCertHandles intermediates; | 1871 X509Certificate::OSCertHandles intermediates; | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1736 intermediates); | 1892 intermediates); | 
| 1737 ASSERT_TRUE(ee_chain); | 1893 ASSERT_TRUE(ee_chain); | 
| 1738 | 1894 | 
| 1739 int flags = 0; | 1895 int flags = 0; | 
| 1740 CertVerifyResult verify_result; | 1896 CertVerifyResult verify_result; | 
| 1741 | 1897 | 
| 1742 // Use a mock CertVerifyProc that returns success with a verified_cert of | 1898 // Use a mock CertVerifyProc that returns success with a verified_cert of | 
| 1743 // |ee_chain|. | 1899 // |ee_chain|. | 
| 1744 // | 1900 // | 
| 1745 // This is sufficient for the purposes of this test, as the checking for weak | 1901 // This is sufficient for the purposes of this test, as the checking for weak | 
| 1746 // hashing algorithms is done by CertVerifyProc::Verify(). | 1902 // hash algorithms is done by CertVerifyProc::Verify(). | 
| 1747 scoped_refptr<CertVerifyProc> proc = | 1903 scoped_refptr<CertVerifyProc> proc = | 
| 1748 new MockCertVerifyProc(CertVerifyResult()); | 1904 new MockCertVerifyProc(CertVerifyResult()); | 
| 1749 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr, | 1905 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr, | 
| 1750 empty_cert_list_, &verify_result); | 1906 CertificateList(), &verify_result); | 
| 1751 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2); | 1907 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2); | 
| 1752 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4); | 1908 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4); | 
| 1753 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5); | 1909 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5); | 
| 1754 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1); | 1910 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1); | 
| 1755 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF), | 1911 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF), | 
| 1756 verify_result.has_sha1_leaf); | 1912 verify_result.has_sha1_leaf); | 
| 1757 } | 1913 } | 
| 1758 | 1914 | 
| 1759 // The signature algorithm of the root CA should not matter. | 1915 // The signature algorithm of the root CA should not matter. | 
| 1760 const WeakDigestTestData kVerifyRootCATestData[] = { | 1916 const WeakDigestTestData kVerifyRootCATestData[] = { | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1857 {NULL, NULL, "weak_digest_md2_ee.pem", 0}, | 2013 {NULL, NULL, "weak_digest_md2_ee.pem", 0}, | 
| 1858 {NULL, NULL, "weak_digest_sha1_ee.pem", 0}, | 2014 {NULL, NULL, "weak_digest_sha1_ee.pem", 0}, | 
| 1859 }; | 2015 }; | 
| 1860 | 2016 | 
| 1861 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE, | 2017 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE, | 
| 1862 CertVerifyProcWeakDigestTest, | 2018 CertVerifyProcWeakDigestTest, | 
| 1863 testing::ValuesIn(kVerifyTrustedEETestData)); | 2019 testing::ValuesIn(kVerifyTrustedEETestData)); | 
| 1864 | 2020 | 
| 1865 // For the list of valid hostnames, see | 2021 // For the list of valid hostnames, see | 
| 1866 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem | 2022 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem | 
| 1867 static const struct CertVerifyProcNameData { | 2023 struct CertVerifyProcNameData { | 
| 1868 const char* hostname; | 2024 const char* hostname; | 
| 1869 bool valid; // Whether or not |hostname| matches a subjectAltName. | 2025 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 }; | 2026 }; | 
| 1885 | 2027 | 
| 1886 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how | 2028 // Test fixture for verifying certificate names. | 
| 1887 // to output the parameter that was passed. Without this, it will simply | 2029 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: | 2030 public: | 
| 1898 CertVerifyProcNameTest() {} | 2031 CertVerifyProcNameTest() {} | 
| 1899 virtual ~CertVerifyProcNameTest() {} | 2032 virtual ~CertVerifyProcNameTest() {} | 
| 2033 | |
| 2034 protected: | |
| 2035 void VerifyCertName(const char* hostname, bool valid) { | |
| 2036 CertificateList cert_list = CreateCertificateListFromFile( | |
| 2037 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem", | |
| 2038 X509Certificate::FORMAT_AUTO); | |
| 2039 ASSERT_EQ(1U, cert_list.size()); | |
| 2040 scoped_refptr<X509Certificate> cert(cert_list[0]); | |
| 2041 | |
| 2042 ScopedTestRoot scoped_root(cert.get()); | |
| 2043 | |
| 2044 CertVerifyResult verify_result; | |
| 2045 int error = | |
| 2046 Verify(cert.get(), hostname, 0, NULL, empty_cert_list_, &verify_result); | |
| 2047 if (valid) { | |
| 2048 EXPECT_THAT(error, IsOk()); | |
| 2049 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | |
| 2050 } else { | |
| 2051 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | |
| 2052 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | |
| 2053 } | |
| 2054 } | |
| 1900 }; | 2055 }; | 
| 1901 | 2056 | 
| 1902 TEST_P(CertVerifyProcNameTest, VerifyCertName) { | 2057 // Don't match the common name | 
| 1903 CertVerifyProcNameData data = GetParam(); | 2058 TEST_P(CertVerifyProcNameTest, DontMatchCommonName) { | 
| 2059 VerifyCertName("127.0.0.1", false); | |
| 2060 } | |
| 1904 | 2061 | 
| 1905 CertificateList cert_list = CreateCertificateListFromFile( | 2062 // Matches the iPAddress SAN (IPv4) | 
| 1906 GetTestCertsDirectory(), "subjectAltName_sanity_check.pem", | 2063 TEST_P(CertVerifyProcNameTest, MatchesIpSanIpv4) { | 
| 1907 X509Certificate::FORMAT_AUTO); | 2064 VerifyCertName("127.0.0.2", true); | 
| 1908 ASSERT_EQ(1U, cert_list.size()); | 2065 } | 
| 1909 scoped_refptr<X509Certificate> cert(cert_list[0]); | |
| 1910 | 2066 | 
| 1911 ScopedTestRoot scoped_root(cert.get()); | 2067 // Matches the iPAddress SAN (IPv6) | 
| 2068 TEST_P(CertVerifyProcNameTest, MatchesIpSanIpv6) { | |
| 2069 VerifyCertName("FE80:0:0:0:0:0:0:1", true); | |
| 2070 } | |
| 1912 | 2071 | 
| 1913 CertVerifyResult verify_result; | 2072 // Should not match the iPAddress SAN | 
| 1914 int error = Verify(cert.get(), data.hostname, 0, NULL, empty_cert_list_, | 2073 TEST_P(CertVerifyProcNameTest, DoesntMatchIpSanIpv6) { | 
| 1915 &verify_result); | 2074 VerifyCertName("[FE80:0:0:0:0:0:0:1]", false); | 
| 1916 if (data.valid) { | 2075 } | 
| 1917 EXPECT_THAT(error, IsOk()); | 2076 | 
| 1918 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | 2077 // Compressed form matches the iPAddress SAN (IPv6) | 
| 1919 } else { | 2078 TEST_P(CertVerifyProcNameTest, MatchesIpSanCompressedIpv6) { | 
| 1920 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); | 2079 VerifyCertName("FE80::1", true); | 
| 1921 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); | 2080 } | 
| 1922 } | 2081 | 
| 2082 // IPv6 mapped form should NOT match iPAddress SAN | |
| 2083 TEST_P(CertVerifyProcNameTest, DoesntMatchIpSanIPv6Mapped) { | |
| 2084 VerifyCertName("::127.0.0.2", false); | |
| 2085 } | |
| 2086 | |
| 2087 // Matches the dNSName SAN | |
| 2088 TEST_P(CertVerifyProcNameTest, MatchesDnsSan) { | |
| 2089 VerifyCertName("test.example", true); | |
| 2090 } | |
| 2091 | |
| 2092 // Matches the dNSName SAN (trailing . ignored) | |
| 2093 TEST_P(CertVerifyProcNameTest, MatchesDnsSanTrailingDot) { | |
| 2094 VerifyCertName("test.example.", true); | |
| 2095 } | |
| 2096 | |
| 2097 // Should not match the dNSName SAN | |
| 2098 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSan) { | |
| 2099 VerifyCertName("www.test.example", false); | |
| 2100 } | |
| 2101 | |
| 2102 // Should not match the dNSName SAN | |
| 2103 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanInvalid) { | |
| 2104 VerifyCertName("test..example", false); | |
| 2105 } | |
| 2106 | |
| 2107 // Should not match the dNSName SAN | |
| 2108 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanTwoTrailingDots) { | |
| 2109 VerifyCertName("test.example..", false); | |
| 2110 } | |
| 2111 | |
| 2112 // Should not match the dNSName SAN | |
| 2113 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanLeadingAndTrailingDot) { | |
| 2114 VerifyCertName(".test.example.", false); | |
| 2115 } | |
| 2116 | |
| 2117 // Should not match the dNSName SAN | |
| 2118 TEST_P(CertVerifyProcNameTest, DoesntMatchDnsSanTrailingDot) { | |
| 2119 VerifyCertName(".test.example", false); | |
| 1923 } | 2120 } | 
| 1924 | 2121 | 
| 1925 INSTANTIATE_TEST_CASE_P(VerifyName, | 2122 INSTANTIATE_TEST_CASE_P(VerifyName, | 
| 1926 CertVerifyProcNameTest, | 2123 CertVerifyProcNameTest, | 
| 1927 testing::ValuesIn(kVerifyNameData)); | 2124 testing::ValuesIn(AllCertVerifiers()), | 
| 2125 VerifyProcTypeToName); | |
| 1928 | 2126 | 
| 1929 #if defined(OS_MACOSX) && !defined(OS_IOS) | 2127 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1930 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate | 2128 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate | 
| 1931 // verifier rejects a certificate with a fatal error. This is a regression | 2129 // verifier rejects a certificate with a fatal error. This is a regression | 
| 1932 // test for https://crbug.com/472291. | 2130 // test for https://crbug.com/472291. | 
| 1933 // (Since 10.12, this causes a recoverable error instead of a fatal one.) | 2131 // (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 | 2132 // TODO(mattm): Try to find a different way to cause a fatal error that works | 
| 1935 // on 10.12. | 2133 // on 10.12. | 
| 1936 TEST_F(CertVerifyProcTest, LargeKey) { | 2134 TEST_F(CertVerifyProcDefaultTest, LargeKey) { | 
| 1937 // Load root_ca_cert.pem into the test root store. | 2135 // Load root_ca_cert.pem into the test root store. | 
| 1938 ScopedTestRoot test_root( | 2136 ScopedTestRoot test_root( | 
| 1939 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 2137 ImportCertFromFile(GetTestCertsDirectory(), "root_ca_cert.pem").get()); | 
| 1940 | 2138 | 
| 1941 scoped_refptr<X509Certificate> cert( | 2139 scoped_refptr<X509Certificate> cert( | 
| 1942 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); | 2140 ImportCertFromFile(GetTestCertsDirectory(), "large_key.pem")); | 
| 1943 | 2141 | 
| 1944 // Apple's verifier rejects this certificate as invalid because the | 2142 // 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, | 2143 // 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. | 2144 // large_key.pem may need to be regenerated with a larger key. | 
| 1947 int flags = 0; | 2145 int flags = 0; | 
| 1948 CertVerifyResult verify_result; | 2146 CertVerifyResult verify_result; | 
| 1949 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2147 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 
| 1950 &verify_result); | 2148 &verify_result); | 
| 1951 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 2149 EXPECT_THAT(error, IsError(ERR_CERT_INVALID)); | 
| 1952 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 2150 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 
| 1953 } | 2151 } | 
| 1954 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 2152 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 
| 1955 | 2153 | 
| 1956 // Tests that CertVerifyProc records a histogram correctly when a | 2154 // Tests that CertVerifyProc records a histogram correctly when a | 
| 1957 // certificate chaining to a private root contains the TLS feature | 2155 // certificate chaining to a private root contains the TLS feature | 
| 1958 // extension and does not have a stapled OCSP response. | 2156 // extension and does not have a stapled OCSP response. | 
| 1959 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionUMA) { | 2157 TEST_P(CertVerifyProcTest, HasTLSFeatureExtensionUMA) { | 
| 1960 base::HistogramTester histograms; | 2158 base::HistogramTester histograms; | 
| 1961 scoped_refptr<X509Certificate> cert( | 2159 scoped_refptr<X509Certificate> cert( | 
| 1962 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 2160 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 
| 1963 ASSERT_TRUE(cert); | 2161 ASSERT_TRUE(cert); | 
| 1964 CertVerifyResult result; | 2162 CertVerifyResult result; | 
| 1965 result.is_issued_by_known_root = false; | 2163 result.is_issued_by_known_root = false; | 
| 1966 verify_proc_ = new MockCertVerifyProc(result); | 2164 verify_proc_ = new MockCertVerifyProc(result); | 
| 1967 | 2165 | 
| 1968 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2166 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 1969 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2167 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 1970 | 2168 | 
| 1971 int flags = 0; | 2169 int flags = 0; | 
| 1972 CertVerifyResult verify_result; | 2170 CertVerifyResult verify_result; | 
| 1973 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2171 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 
| 1974 &verify_result); | 2172 &verify_result); | 
| 1975 EXPECT_EQ(OK, error); | 2173 EXPECT_EQ(OK, error); | 
| 1976 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 2174 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 
| 1977 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 2175 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 
| 1978 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 2176 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 
| 1979 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, false, 1); | 2177 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, false, 1); | 
| 1980 } | 2178 } | 
| 1981 | 2179 | 
| 1982 // Tests that CertVerifyProc records a histogram correctly when a | 2180 // Tests that CertVerifyProc records a histogram correctly when a | 
| 1983 // certificate chaining to a private root contains the TLS feature | 2181 // certificate chaining to a private root contains the TLS feature | 
| 1984 // extension and does have a stapled OCSP response. | 2182 // extension and does have a stapled OCSP response. | 
| 1985 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionWithStapleUMA) { | 2183 TEST_P(CertVerifyProcTest, HasTLSFeatureExtensionWithStapleUMA) { | 
| 1986 base::HistogramTester histograms; | 2184 base::HistogramTester histograms; | 
| 1987 scoped_refptr<X509Certificate> cert( | 2185 scoped_refptr<X509Certificate> cert( | 
| 1988 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 2186 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 
| 1989 ASSERT_TRUE(cert); | 2187 ASSERT_TRUE(cert); | 
| 1990 CertVerifyResult result; | 2188 CertVerifyResult result; | 
| 1991 result.is_issued_by_known_root = false; | 2189 result.is_issued_by_known_root = false; | 
| 1992 verify_proc_ = new MockCertVerifyProc(result); | 2190 verify_proc_ = new MockCertVerifyProc(result); | 
| 1993 | 2191 | 
| 1994 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2192 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 1995 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2193 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 1996 | 2194 | 
| 1997 int flags = 0; | 2195 int flags = 0; | 
| 1998 CertVerifyResult verify_result; | 2196 CertVerifyResult verify_result; | 
| 1999 int error = | 2197 int error = | 
| 2000 VerifyWithOCSPResponse(cert.get(), "127.0.0.1", "dummy response", flags, | 2198 VerifyWithOCSPResponse(cert.get(), "127.0.0.1", "dummy response", flags, | 
| 2001 NULL, empty_cert_list_, &verify_result); | 2199 NULL, empty_cert_list_, &verify_result); | 
| 2002 EXPECT_EQ(OK, error); | 2200 EXPECT_EQ(OK, error); | 
| 2003 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 2201 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 
| 2004 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 2202 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, true, 1); | 
| 2005 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 2203 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 1); | 
| 2006 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, true, 1); | 2204 histograms.ExpectBucketCount(kTLSFeatureExtensionOCSPHistogram, true, 1); | 
| 2007 } | 2205 } | 
| 2008 | 2206 | 
| 2009 // Tests that CertVerifyProc records a histogram correctly when a | 2207 // Tests that CertVerifyProc records a histogram correctly when a | 
| 2010 // certificate chaining to a private root does not contain the TLS feature | 2208 // certificate chaining to a private root does not contain the TLS feature | 
| 2011 // extension. | 2209 // extension. | 
| 2012 TEST_F(CertVerifyProcTest, DoesNotHaveTLSFeatureExtensionUMA) { | 2210 TEST_P(CertVerifyProcTest, DoesNotHaveTLSFeatureExtensionUMA) { | 
| 2013 base::HistogramTester histograms; | 2211 base::HistogramTester histograms; | 
| 2014 scoped_refptr<X509Certificate> cert( | 2212 scoped_refptr<X509Certificate> cert( | 
| 2015 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 2213 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 
| 2016 ASSERT_TRUE(cert); | 2214 ASSERT_TRUE(cert); | 
| 2017 CertVerifyResult result; | 2215 CertVerifyResult result; | 
| 2018 result.is_issued_by_known_root = false; | 2216 result.is_issued_by_known_root = false; | 
| 2019 verify_proc_ = new MockCertVerifyProc(result); | 2217 verify_proc_ = new MockCertVerifyProc(result); | 
| 2020 | 2218 | 
| 2021 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2219 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2022 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2220 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2023 | 2221 | 
| 2024 int flags = 0; | 2222 int flags = 0; | 
| 2025 CertVerifyResult verify_result; | 2223 CertVerifyResult verify_result; | 
| 2026 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2224 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 
| 2027 &verify_result); | 2225 &verify_result); | 
| 2028 EXPECT_EQ(OK, error); | 2226 EXPECT_EQ(OK, error); | 
| 2029 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 2227 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 1); | 
| 2030 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, false, 1); | 2228 histograms.ExpectBucketCount(kTLSFeatureExtensionHistogram, false, 1); | 
| 2031 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2229 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2032 } | 2230 } | 
| 2033 | 2231 | 
| 2034 // Tests that CertVerifyProc does not record a histogram when a | 2232 // Tests that CertVerifyProc does not record a histogram when a | 
| 2035 // certificate contains the TLS feature extension but chains to a public | 2233 // certificate contains the TLS feature extension but chains to a public | 
| 2036 // root. | 2234 // root. | 
| 2037 TEST_F(CertVerifyProcTest, HasTLSFeatureExtensionWithPublicRootUMA) { | 2235 TEST_P(CertVerifyProcTest, HasTLSFeatureExtensionWithPublicRootUMA) { | 
| 2038 base::HistogramTester histograms; | 2236 base::HistogramTester histograms; | 
| 2039 scoped_refptr<X509Certificate> cert( | 2237 scoped_refptr<X509Certificate> cert( | 
| 2040 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 2238 ImportCertFromFile(GetTestCertsDirectory(), "tls_feature_extension.pem")); | 
| 2041 ASSERT_TRUE(cert); | 2239 ASSERT_TRUE(cert); | 
| 2042 CertVerifyResult result; | 2240 CertVerifyResult result; | 
| 2043 result.is_issued_by_known_root = true; | 2241 result.is_issued_by_known_root = true; | 
| 2044 verify_proc_ = new MockCertVerifyProc(result); | 2242 verify_proc_ = new MockCertVerifyProc(result); | 
| 2045 | 2243 | 
| 2046 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2244 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2047 | 2245 | 
| 2048 int flags = 0; | 2246 int flags = 0; | 
| 2049 CertVerifyResult verify_result; | 2247 CertVerifyResult verify_result; | 
| 2050 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 2248 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 
| 2051 &verify_result); | 2249 &verify_result); | 
| 2052 EXPECT_EQ(OK, error); | 2250 EXPECT_EQ(OK, error); | 
| 2053 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 2251 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); | 
| 2054 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 2252 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); | 
| 2055 } | 2253 } | 
| 2056 | 2254 | 
| 2057 } // namespace net | 2255 } // namespace net | 
| OLD | NEW |