OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/file_path.h" |
| 6 #include "base/string_number_conversions.h" |
| 7 #include "base/sha1.h" |
| 8 #include "net/base/cert_status_flags.h" |
| 9 #include "net/base/cert_test_util.h" |
| 10 #include "net/base/cert_verify_proc.h" |
| 11 #include "net/base/cert_verify_result.h" |
| 12 #include "net/base/crl_set.h" |
| 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/test_certificate_data.h" |
| 15 #include "net/base/test_root_certs.h" |
| 16 #include "net/base/x509_certificate.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 #if defined(OS_WIN) |
| 20 #include "base/win/windows_version.h" |
| 21 #elif defined(OS_MACOSX) |
| 22 #include "base/mac/mac_util.h" |
| 23 #endif |
| 24 |
| 25 using base::HexEncode; |
| 26 |
| 27 namespace net { |
| 28 |
| 29 namespace { |
| 30 |
| 31 // A certificate for www.paypal.com with a NULL byte in the common name. |
| 32 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363 |
| 33 unsigned char paypal_null_fingerprint[] = { |
| 34 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2, 0x6a, 0xba, |
| 35 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7 |
| 36 }; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 class CertVerifyProcTest : public testing::Test { |
| 41 public: |
| 42 CertVerifyProcTest() |
| 43 : verify_proc_(CertVerifyProc::CreateDefault()) { |
| 44 } |
| 45 virtual ~CertVerifyProcTest() {} |
| 46 |
| 47 protected: |
| 48 int Verify(X509Certificate* cert, |
| 49 const std::string& hostname, |
| 50 int flags, |
| 51 CRLSet* crl_set, |
| 52 CertVerifyResult* verify_result) { |
| 53 return verify_proc_->Verify(cert, hostname, flags, crl_set, |
| 54 verify_result); |
| 55 } |
| 56 |
| 57 private: |
| 58 scoped_refptr<CertVerifyProc> verify_proc_; |
| 59 }; |
| 60 |
| 61 TEST_F(CertVerifyProcTest, WithoutRevocationChecking) { |
| 62 // Check that verification without revocation checking works. |
| 63 CertificateList certs = CreateCertificateListFromFile( |
| 64 GetTestCertsDirectory(), |
| 65 "googlenew.chain.pem", |
| 66 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
| 67 |
| 68 X509Certificate::OSCertHandles intermediates; |
| 69 intermediates.push_back(certs[1]->os_cert_handle()); |
| 70 |
| 71 scoped_refptr<X509Certificate> google_full_chain = |
| 72 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
| 73 intermediates); |
| 74 |
| 75 CertVerifyResult verify_result; |
| 76 EXPECT_EQ(OK, Verify(google_full_chain, "www.google.com", 0 /* flags */, |
| 77 NULL, &verify_result)); |
| 78 } |
| 79 |
| 80 #if defined(OS_ANDROID) || defined(USE_OPENSSL) |
| 81 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. |
| 82 #define MAYBE_EVVerification DISABLED_EVVerification |
| 83 #else |
| 84 #define MAYBE_EVVerification EVVerification |
| 85 #endif |
| 86 TEST_F(CertVerifyProcTest, MAYBE_EVVerification) { |
| 87 // This certificate will expire Jun 21, 2013. |
| 88 CertificateList certs = CreateCertificateListFromFile( |
| 89 GetTestCertsDirectory(), |
| 90 "comodo.chain.pem", |
| 91 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
| 92 ASSERT_EQ(3U, certs.size()); |
| 93 |
| 94 X509Certificate::OSCertHandles intermediates; |
| 95 intermediates.push_back(certs[1]->os_cert_handle()); |
| 96 intermediates.push_back(certs[2]->os_cert_handle()); |
| 97 |
| 98 scoped_refptr<X509Certificate> comodo_chain = |
| 99 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
| 100 intermediates); |
| 101 |
| 102 CertVerifyResult verify_result; |
| 103 int flags = X509Certificate::VERIFY_EV_CERT; |
| 104 int error = Verify(comodo_chain, "comodo.com", flags, NULL, &verify_result); |
| 105 EXPECT_EQ(OK, error); |
| 106 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
| 107 } |
| 108 |
| 109 TEST_F(CertVerifyProcTest, PaypalNullCertParsing) { |
| 110 scoped_refptr<X509Certificate> paypal_null_cert( |
| 111 X509Certificate::CreateFromBytes( |
| 112 reinterpret_cast<const char*>(paypal_null_der), |
| 113 sizeof(paypal_null_der))); |
| 114 |
| 115 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); |
| 116 |
| 117 const SHA1Fingerprint& fingerprint = |
| 118 paypal_null_cert->fingerprint(); |
| 119 for (size_t i = 0; i < 20; ++i) |
| 120 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); |
| 121 |
| 122 int flags = 0; |
| 123 CertVerifyResult verify_result; |
| 124 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL, |
| 125 &verify_result); |
| 126 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) |
| 127 // TOOD(bulach): investigate why macosx and win aren't returning |
| 128 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. |
| 129 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
| 130 #else |
| 131 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); |
| 132 #endif |
| 133 // Either the system crypto library should correctly report a certificate |
| 134 // name mismatch, or our certificate blacklist should cause us to report an |
| 135 // invalid certificate. |
| 136 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) |
| 137 EXPECT_TRUE(verify_result.cert_status & |
| 138 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); |
| 139 #endif |
| 140 } |
| 141 |
| 142 // A regression test for http://crbug.com/31497. |
| 143 // This certificate will expire on 2012-04-08. The test will still |
| 144 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test |
| 145 // certificates for this unit test. http://crbug.com/111742 |
| 146 TEST_F(CertVerifyProcTest, IntermediateCARequireExplicitPolicy) { |
| 147 FilePath certs_dir = GetTestCertsDirectory(); |
| 148 |
| 149 scoped_refptr<X509Certificate> server_cert = |
| 150 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); |
| 151 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 152 |
| 153 // The intermediate CA certificate's policyConstraints extension has a |
| 154 // requireExplicitPolicy field with SkipCerts=0. |
| 155 scoped_refptr<X509Certificate> intermediate_cert = |
| 156 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); |
| 157 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 158 |
| 159 scoped_refptr<X509Certificate> root_cert = |
| 160 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); |
| 161 ScopedTestRoot scoped_root(root_cert); |
| 162 |
| 163 X509Certificate::OSCertHandles intermediates; |
| 164 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 165 scoped_refptr<X509Certificate> cert_chain = |
| 166 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
| 167 intermediates); |
| 168 |
| 169 int flags = 0; |
| 170 CertVerifyResult verify_result; |
| 171 int error = Verify(cert_chain, "www.us.army.mil", flags, NULL, |
| 172 &verify_result); |
| 173 if (error == OK) { |
| 174 EXPECT_EQ(0U, verify_result.cert_status); |
| 175 } else { |
| 176 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
| 177 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); |
| 178 } |
| 179 } |
| 180 |
| 181 |
| 182 // Test for bug 58437. |
| 183 // This certificate will expire on 2011-12-21. The test will still |
| 184 // pass if error == ERR_CERT_DATE_INVALID. |
| 185 // This test is DISABLED because it appears that we cannot do |
| 186 // certificate revocation checking when running all of the net unit tests. |
| 187 // This test passes when run individually, but when run with all of the net |
| 188 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is |
| 189 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation |
| 190 // status, i.e. that the revocation check is failing for some reason. |
| 191 TEST_F(CertVerifyProcTest, DISABLED_GlobalSignR3EVTest) { |
| 192 FilePath certs_dir = GetTestCertsDirectory(); |
| 193 |
| 194 scoped_refptr<X509Certificate> server_cert = |
| 195 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); |
| 196 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 197 |
| 198 scoped_refptr<X509Certificate> intermediate_cert = |
| 199 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); |
| 200 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 201 |
| 202 X509Certificate::OSCertHandles intermediates; |
| 203 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 204 scoped_refptr<X509Certificate> cert_chain = |
| 205 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
| 206 intermediates); |
| 207 |
| 208 CertVerifyResult verify_result; |
| 209 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | |
| 210 X509Certificate::VERIFY_EV_CERT; |
| 211 int error = Verify(cert_chain, "2029.globalsign.com", flags, NULL, |
| 212 &verify_result); |
| 213 if (error == OK) |
| 214 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
| 215 else |
| 216 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
| 217 } |
| 218 |
| 219 // Currently, only RSA and DSA keys are checked for weakness, and our example |
| 220 // weak size is 768. These could change in the future. |
| 221 // |
| 222 // Note that this means there may be false negatives: keys for other |
| 223 // algorithms and which are weak will pass this test. |
| 224 static bool IsWeakKeyType(const std::string& key_type) { |
| 225 size_t pos = key_type.find("-"); |
| 226 std::string size = key_type.substr(0, pos); |
| 227 std::string type = key_type.substr(pos + 1); |
| 228 |
| 229 if (type == "rsa" || type == "dsa") |
| 230 return size == "768"; |
| 231 |
| 232 return false; |
| 233 } |
| 234 |
| 235 TEST_F(CertVerifyProcTest, RejectWeakKeys) { |
| 236 FilePath certs_dir = GetTestCertsDirectory(); |
| 237 typedef std::vector<std::string> Strings; |
| 238 Strings key_types; |
| 239 |
| 240 // generate-weak-test-chains.sh currently has: |
| 241 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" |
| 242 // We must use the same key types here. The filenames generated look like: |
| 243 // 2048-rsa-ee-by-768-rsa-intermediate.pem |
| 244 key_types.push_back("768-rsa"); |
| 245 key_types.push_back("1024-rsa"); |
| 246 key_types.push_back("2048-rsa"); |
| 247 |
| 248 bool use_ecdsa = true; |
| 249 #if defined(OS_WIN) |
| 250 use_ecdsa = base::win::GetVersion() > base::win::VERSION_XP; |
| 251 #elif defined(OS_MACOSX) |
| 252 use_ecdsa = base::mac::IsOSSnowLeopardOrLater(); |
| 253 #endif |
| 254 |
| 255 if (use_ecdsa) |
| 256 key_types.push_back("prime256v1-ecdsa"); |
| 257 |
| 258 // Add the root that signed the intermediates for this test. |
| 259 scoped_refptr<X509Certificate> root_cert = |
| 260 ImportCertFromFile(certs_dir, "2048-rsa-root.pem"); |
| 261 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert); |
| 262 ScopedTestRoot scoped_root(root_cert); |
| 263 |
| 264 // Now test each chain. |
| 265 for (Strings::const_iterator ee_type = key_types.begin(); |
| 266 ee_type != key_types.end(); ++ee_type) { |
| 267 for (Strings::const_iterator signer_type = key_types.begin(); |
| 268 signer_type != key_types.end(); ++signer_type) { |
| 269 std::string basename = *ee_type + "-ee-by-" + *signer_type + |
| 270 "-intermediate.pem"; |
| 271 SCOPED_TRACE(basename); |
| 272 scoped_refptr<X509Certificate> ee_cert = |
| 273 ImportCertFromFile(certs_dir, basename); |
| 274 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert); |
| 275 |
| 276 basename = *signer_type + "-intermediate.pem"; |
| 277 scoped_refptr<X509Certificate> intermediate = |
| 278 ImportCertFromFile(certs_dir, basename); |
| 279 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); |
| 280 |
| 281 X509Certificate::OSCertHandles intermediates; |
| 282 intermediates.push_back(intermediate->os_cert_handle()); |
| 283 scoped_refptr<X509Certificate> cert_chain = |
| 284 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), |
| 285 intermediates); |
| 286 |
| 287 CertVerifyResult verify_result; |
| 288 int error = Verify(cert_chain, "127.0.0.1", 0, NULL, &verify_result); |
| 289 |
| 290 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { |
| 291 EXPECT_NE(OK, error); |
| 292 EXPECT_EQ(CERT_STATUS_WEAK_KEY, |
| 293 verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
| 294 } else { |
| 295 EXPECT_EQ(OK, error); |
| 296 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
| 297 } |
| 298 } |
| 299 } |
| 300 } |
| 301 |
| 302 // Test for bug 108514. |
| 303 // The certificate will expire on 2012-07-20. The test will still |
| 304 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test |
| 305 // certificates for this unit test. http://crbug.com/111730 |
| 306 TEST_F(CertVerifyProcTest, ExtraneousMD5RootCert) { |
| 307 FilePath certs_dir = GetTestCertsDirectory(); |
| 308 |
| 309 scoped_refptr<X509Certificate> server_cert = |
| 310 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); |
| 311 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 312 |
| 313 scoped_refptr<X509Certificate> intermediate_cert = |
| 314 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); |
| 315 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 316 |
| 317 scoped_refptr<X509Certificate> md5_root_cert = |
| 318 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); |
| 319 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); |
| 320 |
| 321 X509Certificate::OSCertHandles intermediates; |
| 322 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 323 intermediates.push_back(md5_root_cert->os_cert_handle()); |
| 324 scoped_refptr<X509Certificate> cert_chain = |
| 325 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
| 326 intermediates); |
| 327 |
| 328 CertVerifyResult verify_result; |
| 329 int flags = 0; |
| 330 int error = Verify(cert_chain, "images.etrade.wallst.com", flags, NULL, |
| 331 &verify_result); |
| 332 if (error != OK) |
| 333 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
| 334 |
| 335 EXPECT_FALSE(verify_result.has_md5); |
| 336 EXPECT_FALSE(verify_result.has_md5_ca); |
| 337 } |
| 338 |
| 339 // Test for bug 94673. |
| 340 TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) { |
| 341 FilePath certs_dir = GetTestCertsDirectory(); |
| 342 |
| 343 scoped_refptr<X509Certificate> server_cert = |
| 344 ImportCertFromFile(certs_dir, "google_diginotar.pem"); |
| 345 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 346 |
| 347 scoped_refptr<X509Certificate> intermediate_cert = |
| 348 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); |
| 349 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 350 |
| 351 X509Certificate::OSCertHandles intermediates; |
| 352 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 353 scoped_refptr<X509Certificate> cert_chain = |
| 354 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
| 355 intermediates); |
| 356 |
| 357 CertVerifyResult verify_result; |
| 358 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; |
| 359 int error = Verify(cert_chain, "mail.google.com", flags, NULL, |
| 360 &verify_result); |
| 361 EXPECT_NE(OK, error); |
| 362 |
| 363 // Now turn off revocation checking. Certificate verification should still |
| 364 // fail. |
| 365 flags = 0; |
| 366 error = Verify(cert_chain, "mail.google.com", flags, NULL, &verify_result); |
| 367 EXPECT_NE(OK, error); |
| 368 } |
| 369 |
| 370 // Bug 111893: This test needs a new certificate. |
| 371 TEST_F(CertVerifyProcTest, DISABLED_TestKnownRoot) { |
| 372 FilePath certs_dir = GetTestCertsDirectory(); |
| 373 scoped_refptr<X509Certificate> cert = |
| 374 ImportCertFromFile(certs_dir, "nist.der"); |
| 375 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
| 376 |
| 377 // This intermediate is only needed for old Linux machines. Modern NSS |
| 378 // includes it as a root already. |
| 379 scoped_refptr<X509Certificate> intermediate_cert = |
| 380 ImportCertFromFile(certs_dir, "nist_intermediate.der"); |
| 381 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 382 |
| 383 X509Certificate::OSCertHandles intermediates; |
| 384 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 385 scoped_refptr<X509Certificate> cert_chain = |
| 386 X509Certificate::CreateFromHandle(cert->os_cert_handle(), |
| 387 intermediates); |
| 388 |
| 389 int flags = 0; |
| 390 CertVerifyResult verify_result; |
| 391 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug |
| 392 // against agl. Also see PublicKeyHashes in this file. |
| 393 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result); |
| 394 EXPECT_EQ(OK, error); |
| 395 EXPECT_EQ(0U, verify_result.cert_status); |
| 396 EXPECT_TRUE(verify_result.is_issued_by_known_root); |
| 397 } |
| 398 |
| 399 // Bug 111893: This test needs a new certificate. |
| 400 TEST_F(CertVerifyProcTest, DISABLED_PublicKeyHashes) { |
| 401 FilePath certs_dir = GetTestCertsDirectory(); |
| 402 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug |
| 403 // against agl. Also see TestKnownRoot in this file. |
| 404 scoped_refptr<X509Certificate> cert = |
| 405 ImportCertFromFile(certs_dir, "nist.der"); |
| 406 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
| 407 |
| 408 // This intermediate is only needed for old Linux machines. Modern NSS |
| 409 // includes it as a root already. |
| 410 scoped_refptr<X509Certificate> intermediate_cert = |
| 411 ImportCertFromFile(certs_dir, "nist_intermediate.der"); |
| 412 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 413 |
| 414 ScopedTestRoot scoped_intermediate(intermediate_cert); |
| 415 |
| 416 X509Certificate::OSCertHandles intermediates; |
| 417 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 418 scoped_refptr<X509Certificate> cert_chain = |
| 419 X509Certificate::CreateFromHandle(cert->os_cert_handle(), |
| 420 intermediates); |
| 421 |
| 422 int flags = 0; |
| 423 CertVerifyResult verify_result; |
| 424 |
| 425 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result); |
| 426 EXPECT_EQ(OK, error); |
| 427 EXPECT_EQ(0U, verify_result.cert_status); |
| 428 ASSERT_LE(2u, verify_result.public_key_hashes.size()); |
| 429 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), |
| 430 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); |
| 431 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", |
| 432 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); |
| 433 } |
| 434 |
| 435 // A regression test for http://crbug.com/70293. |
| 436 // The Key Usage extension in this RSA SSL server certificate does not have |
| 437 // the keyEncipherment bit. |
| 438 TEST_F(CertVerifyProcTest, InvalidKeyUsage) { |
| 439 FilePath certs_dir = GetTestCertsDirectory(); |
| 440 |
| 441 scoped_refptr<X509Certificate> server_cert = |
| 442 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); |
| 443 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 444 |
| 445 int flags = 0; |
| 446 CertVerifyResult verify_result; |
| 447 int error = Verify(server_cert, "jira.aquameta.com", flags, NULL, |
| 448 &verify_result); |
| 449 #if defined(USE_OPENSSL) |
| 450 // This certificate has two errors: "invalid key usage" and "untrusted CA". |
| 451 // However, OpenSSL returns only one (the latter), and we can't detect |
| 452 // the other errors. |
| 453 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
| 454 #else |
| 455 EXPECT_EQ(ERR_CERT_INVALID, error); |
| 456 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); |
| 457 #endif |
| 458 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors |
| 459 // from NSS. |
| 460 #if !defined(USE_NSS) |
| 461 // The certificate is issued by an unknown CA. |
| 462 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); |
| 463 #endif |
| 464 } |
| 465 |
| 466 // Basic test for returning the chain in CertVerifyResult. Note that the |
| 467 // returned chain may just be a reflection of the originally supplied chain; |
| 468 // that is, if any errors occur, the default chain returned is an exact copy |
| 469 // of the certificate to be verified. The remaining VerifyReturn* tests are |
| 470 // used to ensure that the actual, verified chain is being returned by |
| 471 // Verify(). |
| 472 TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) { |
| 473 FilePath certs_dir = GetTestCertsDirectory(); |
| 474 CertificateList certs = CreateCertificateListFromFile( |
| 475 certs_dir, "x509_verify_results.chain.pem", |
| 476 X509Certificate::FORMAT_AUTO); |
| 477 ASSERT_EQ(3U, certs.size()); |
| 478 |
| 479 X509Certificate::OSCertHandles intermediates; |
| 480 intermediates.push_back(certs[1]->os_cert_handle()); |
| 481 intermediates.push_back(certs[2]->os_cert_handle()); |
| 482 |
| 483 ScopedTestRoot scoped_root(certs[2]); |
| 484 |
| 485 scoped_refptr<X509Certificate> google_full_chain = |
| 486 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
| 487 intermediates); |
| 488 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
| 489 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); |
| 490 |
| 491 CertVerifyResult verify_result; |
| 492 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
| 493 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
| 494 EXPECT_EQ(OK, error); |
| 495 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
| 496 |
| 497 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
| 498 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
| 499 google_full_chain->os_cert_handle(), |
| 500 verify_result.verified_cert->os_cert_handle())); |
| 501 const X509Certificate::OSCertHandles& return_intermediates = |
| 502 verify_result.verified_cert->GetIntermediateCertificates(); |
| 503 ASSERT_EQ(2U, return_intermediates.size()); |
| 504 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
| 505 certs[1]->os_cert_handle())); |
| 506 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
| 507 certs[2]->os_cert_handle())); |
| 508 } |
| 509 |
| 510 // Test that the certificate returned in CertVerifyResult is able to reorder |
| 511 // certificates that are not ordered from end-entity to root. While this is |
| 512 // a protocol violation if sent during a TLS handshake, if multiple sources |
| 513 // of intermediate certificates are combined, it's possible that order may |
| 514 // not be maintained. |
| 515 TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) { |
| 516 FilePath certs_dir = GetTestCertsDirectory(); |
| 517 CertificateList certs = CreateCertificateListFromFile( |
| 518 certs_dir, "x509_verify_results.chain.pem", |
| 519 X509Certificate::FORMAT_AUTO); |
| 520 ASSERT_EQ(3U, certs.size()); |
| 521 |
| 522 // Construct the chain out of order. |
| 523 X509Certificate::OSCertHandles intermediates; |
| 524 intermediates.push_back(certs[2]->os_cert_handle()); |
| 525 intermediates.push_back(certs[1]->os_cert_handle()); |
| 526 |
| 527 ScopedTestRoot scoped_root(certs[2]); |
| 528 |
| 529 scoped_refptr<X509Certificate> google_full_chain = |
| 530 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
| 531 intermediates); |
| 532 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
| 533 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); |
| 534 |
| 535 CertVerifyResult verify_result; |
| 536 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
| 537 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
| 538 EXPECT_EQ(OK, error); |
| 539 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
| 540 |
| 541 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
| 542 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
| 543 google_full_chain->os_cert_handle(), |
| 544 verify_result.verified_cert->os_cert_handle())); |
| 545 const X509Certificate::OSCertHandles& return_intermediates = |
| 546 verify_result.verified_cert->GetIntermediateCertificates(); |
| 547 ASSERT_EQ(2U, return_intermediates.size()); |
| 548 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
| 549 certs[1]->os_cert_handle())); |
| 550 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
| 551 certs[2]->os_cert_handle())); |
| 552 } |
| 553 |
| 554 // Test that Verify() filters out certificates which are not related to |
| 555 // or part of the certificate chain being verified. |
| 556 TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) { |
| 557 FilePath certs_dir = GetTestCertsDirectory(); |
| 558 CertificateList certs = CreateCertificateListFromFile( |
| 559 certs_dir, "x509_verify_results.chain.pem", |
| 560 X509Certificate::FORMAT_AUTO); |
| 561 ASSERT_EQ(3U, certs.size()); |
| 562 ScopedTestRoot scoped_root(certs[2]); |
| 563 |
| 564 scoped_refptr<X509Certificate> unrelated_dod_certificate = |
| 565 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); |
| 566 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = |
| 567 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); |
| 568 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); |
| 569 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); |
| 570 |
| 571 // Interject unrelated certificates into the list of intermediates. |
| 572 X509Certificate::OSCertHandles intermediates; |
| 573 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); |
| 574 intermediates.push_back(certs[1]->os_cert_handle()); |
| 575 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); |
| 576 intermediates.push_back(certs[2]->os_cert_handle()); |
| 577 |
| 578 scoped_refptr<X509Certificate> google_full_chain = |
| 579 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
| 580 intermediates); |
| 581 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
| 582 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); |
| 583 |
| 584 CertVerifyResult verify_result; |
| 585 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
| 586 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
| 587 EXPECT_EQ(OK, error); |
| 588 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
| 589 |
| 590 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
| 591 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
| 592 google_full_chain->os_cert_handle(), |
| 593 verify_result.verified_cert->os_cert_handle())); |
| 594 const X509Certificate::OSCertHandles& return_intermediates = |
| 595 verify_result.verified_cert->GetIntermediateCertificates(); |
| 596 ASSERT_EQ(2U, return_intermediates.size()); |
| 597 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
| 598 certs[1]->os_cert_handle())); |
| 599 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
| 600 certs[2]->os_cert_handle())); |
| 601 } |
| 602 |
| 603 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
| 604 static const uint8 kCRLSetThawteSPKIBlocked[] = { |
| 605 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, |
| 606 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, |
| 607 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, |
| 608 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, |
| 609 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, |
| 610 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, |
| 611 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, |
| 612 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x36, 0x58, 0x36, 0x4d, 0x78, 0x52, 0x37, |
| 613 0x58, 0x70, 0x4d, 0x51, 0x4b, 0x78, 0x49, 0x41, 0x39, 0x50, 0x6a, 0x36, 0x37, |
| 614 0x36, 0x38, 0x76, 0x74, 0x55, 0x6b, 0x6b, 0x7a, 0x48, 0x79, 0x7a, 0x41, 0x6f, |
| 615 0x6d, 0x6f, 0x4f, 0x68, 0x4b, 0x55, 0x6e, 0x7a, 0x73, 0x55, 0x3d, 0x22, 0x5d, |
| 616 0x7d, |
| 617 }; |
| 618 |
| 619 static const uint8 kCRLSetThawteSerialBlocked[] = { |
| 620 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, |
| 621 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, |
| 622 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, |
| 623 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, |
| 624 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, |
| 625 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, |
| 626 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, |
| 627 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xb1, 0x12, 0x41, 0x42, 0xa5, 0xa1, |
| 628 0xa5, 0xa2, 0x88, 0x19, 0xc7, 0x35, 0x34, 0x0e, 0xff, 0x8c, 0x9e, 0x2f, 0x81, |
| 629 0x68, 0xfe, 0xe3, 0xba, 0x18, 0x7f, 0x25, 0x3b, 0xc1, 0xa3, 0x92, 0xd7, 0xe2, |
| 630 // Note that this is actually blocking two serial numbers because on XP and |
| 631 // Vista, CryptoAPI finds a different Thawte certificate. |
| 632 0x02, 0x00, 0x00, 0x00, |
| 633 0x04, 0x30, 0x00, 0x00, 0x02, |
| 634 0x04, 0x30, 0x00, 0x00, 0x06, |
| 635 }; |
| 636 |
| 637 static const uint8 kCRLSetGoogleSerialBlocked[] = { |
| 638 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a, |
| 639 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, |
| 640 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22, |
| 641 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22, |
| 642 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c, |
| 643 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a, |
| 644 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, |
| 645 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, |
| 646 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, |
| 647 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, |
| 648 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, |
| 649 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, |
| 650 }; |
| 651 |
| 652 // Test that CRLSets are effective in making a certificate appear to be |
| 653 // revoked. |
| 654 TEST_F(CertVerifyProcTest, CRLSet) { |
| 655 CertificateList certs = CreateCertificateListFromFile( |
| 656 GetTestCertsDirectory(), |
| 657 "googlenew.chain.pem", |
| 658 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
| 659 |
| 660 X509Certificate::OSCertHandles intermediates; |
| 661 intermediates.push_back(certs[1]->os_cert_handle()); |
| 662 |
| 663 scoped_refptr<X509Certificate> google_full_chain = |
| 664 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
| 665 intermediates); |
| 666 |
| 667 CertVerifyResult verify_result; |
| 668 int error = Verify(google_full_chain, "www.google.com", 0, NULL, |
| 669 &verify_result); |
| 670 EXPECT_EQ(OK, error); |
| 671 |
| 672 // First test blocking by SPKI. |
| 673 base::StringPiece crl_set_bytes( |
| 674 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), |
| 675 sizeof(kCRLSetThawteSPKIBlocked)); |
| 676 scoped_refptr<CRLSet> crl_set; |
| 677 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
| 678 |
| 679 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
| 680 &verify_result); |
| 681 EXPECT_EQ(ERR_CERT_REVOKED, error); |
| 682 |
| 683 // Second, test revocation by serial number of a cert directly under the |
| 684 // root. |
| 685 crl_set_bytes = base::StringPiece( |
| 686 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), |
| 687 sizeof(kCRLSetThawteSerialBlocked)); |
| 688 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
| 689 |
| 690 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
| 691 &verify_result); |
| 692 EXPECT_EQ(ERR_CERT_REVOKED, error); |
| 693 |
| 694 // Lastly, test revocation by serial number of a certificate not under the |
| 695 // root. |
| 696 crl_set_bytes = base::StringPiece( |
| 697 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), |
| 698 sizeof(kCRLSetGoogleSerialBlocked)); |
| 699 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
| 700 |
| 701 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
| 702 &verify_result); |
| 703 EXPECT_EQ(ERR_CERT_REVOKED, error); |
| 704 } |
| 705 #endif |
| 706 |
| 707 struct WeakDigestTestData { |
| 708 const char* root_cert_filename; |
| 709 const char* intermediate_cert_filename; |
| 710 const char* ee_cert_filename; |
| 711 bool expected_has_md5; |
| 712 bool expected_has_md4; |
| 713 bool expected_has_md2; |
| 714 bool expected_has_md5_ca; |
| 715 bool expected_has_md2_ca; |
| 716 }; |
| 717 |
| 718 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how |
| 719 // to output the parameter that was passed. Without this, it will simply |
| 720 // attempt to print out the first twenty bytes of the object, which depending |
| 721 // on platform and alignment, may result in an invalid read. |
| 722 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { |
| 723 *os << "root: " |
| 724 << (data.root_cert_filename ? data.root_cert_filename : "none") |
| 725 << "; intermediate: " << data.intermediate_cert_filename |
| 726 << "; end-entity: " << data.ee_cert_filename; |
| 727 } |
| 728 |
| 729 class CertVerifyProcWeakDigestTest |
| 730 : public CertVerifyProcTest, |
| 731 public testing::WithParamInterface<WeakDigestTestData> { |
| 732 public: |
| 733 CertVerifyProcWeakDigestTest() {} |
| 734 virtual ~CertVerifyProcWeakDigestTest() {} |
| 735 }; |
| 736 |
| 737 TEST_P(CertVerifyProcWeakDigestTest, Verify) { |
| 738 WeakDigestTestData data = GetParam(); |
| 739 FilePath certs_dir = GetTestCertsDirectory(); |
| 740 |
| 741 ScopedTestRoot test_root; |
| 742 if (data.root_cert_filename) { |
| 743 scoped_refptr<X509Certificate> root_cert = |
| 744 ImportCertFromFile(certs_dir, data.root_cert_filename); |
| 745 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert); |
| 746 test_root.Reset(root_cert); |
| 747 } |
| 748 |
| 749 scoped_refptr<X509Certificate> intermediate_cert = |
| 750 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); |
| 751 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
| 752 scoped_refptr<X509Certificate> ee_cert = |
| 753 ImportCertFromFile(certs_dir, data.ee_cert_filename); |
| 754 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert); |
| 755 |
| 756 X509Certificate::OSCertHandles intermediates; |
| 757 intermediates.push_back(intermediate_cert->os_cert_handle()); |
| 758 |
| 759 scoped_refptr<X509Certificate> ee_chain = |
| 760 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), |
| 761 intermediates); |
| 762 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); |
| 763 |
| 764 int flags = 0; |
| 765 CertVerifyResult verify_result; |
| 766 int rv = Verify(ee_chain, "127.0.0.1", flags, NULL, &verify_result); |
| 767 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); |
| 768 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); |
| 769 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); |
| 770 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); |
| 771 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); |
| 772 |
| 773 // Ensure that MD4 and MD2 are tagged as invalid. |
| 774 if (data.expected_has_md4 || data.expected_has_md2) { |
| 775 EXPECT_EQ(CERT_STATUS_INVALID, |
| 776 verify_result.cert_status & CERT_STATUS_INVALID); |
| 777 } |
| 778 |
| 779 // Ensure that MD5 is flagged as weak. |
| 780 if (data.expected_has_md5) { |
| 781 EXPECT_EQ( |
| 782 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM, |
| 783 verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM); |
| 784 } |
| 785 |
| 786 // If a root cert is present, then check that the chain was rejected if any |
| 787 // weak algorithms are present. This is only checked when a root cert is |
| 788 // present because the error reported for incomplete chains with weak |
| 789 // algorithms depends on which implementation was used to validate (NSS, |
| 790 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm |
| 791 // present (MD2, MD4, MD5). |
| 792 if (data.root_cert_filename) { |
| 793 if (data.expected_has_md4 || data.expected_has_md2) { |
| 794 EXPECT_EQ(ERR_CERT_INVALID, rv); |
| 795 } else if (data.expected_has_md5) { |
| 796 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, rv); |
| 797 } else { |
| 798 EXPECT_EQ(OK, rv); |
| 799 } |
| 800 } |
| 801 } |
| 802 |
| 803 // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 804 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that |
| 805 // stringizes the arguments. As a result, macros passed as parameters (such as |
| 806 // prefix or test_case_name) will not be expanded by the preprocessor. To work |
| 807 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the |
| 808 // pre-processor will expand macros such as MAYBE_test_name before |
| 809 // instantiating the test. |
| 810 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ |
| 811 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) |
| 812 |
| 813 // The signature algorithm of the root CA should not matter. |
| 814 const WeakDigestTestData kVerifyRootCATestData[] = { |
| 815 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem", |
| 816 "weak_digest_sha1_ee.pem", false, false, false, false, false }, |
| 817 #if !defined(OS_MACOSX) // MD4 is not supported. |
| 818 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem", |
| 819 "weak_digest_sha1_ee.pem", false, false, false, false, false }, |
| 820 #endif |
| 821 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem", |
| 822 "weak_digest_sha1_ee.pem", false, false, false, false, false }, |
| 823 }; |
| 824 INSTANTIATE_TEST_CASE_P(VerifyRoot, CertVerifyProcWeakDigestTest, |
| 825 testing::ValuesIn(kVerifyRootCATestData)); |
| 826 |
| 827 // The signature algorithm of intermediates should be properly detected. |
| 828 const WeakDigestTestData kVerifyIntermediateCATestData[] = { |
| 829 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", |
| 830 "weak_digest_sha1_ee.pem", true, false, false, true, false }, |
| 831 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported. |
| 832 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", |
| 833 "weak_digest_sha1_ee.pem", false, true, false, false, false }, |
| 834 #endif |
| 835 #if !defined(USE_NSS) // MD2 is disabled by default. |
| 836 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", |
| 837 "weak_digest_sha1_ee.pem", false, false, true, false, true }, |
| 838 #endif |
| 839 }; |
| 840 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, CertVerifyProcWeakDigestTest, |
| 841 testing::ValuesIn(kVerifyIntermediateCATestData)); |
| 842 |
| 843 // The signature algorithm of end-entity should be properly detected. |
| 844 const WeakDigestTestData kVerifyEndEntityTestData[] = { |
| 845 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", |
| 846 "weak_digest_md5_ee.pem", true, false, false, false, false }, |
| 847 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported. |
| 848 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", |
| 849 "weak_digest_md4_ee.pem", false, true, false, false, false }, |
| 850 #endif |
| 851 #if !defined(USE_NSS) // MD2 is disabled by default. |
| 852 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", |
| 853 "weak_digest_md2_ee.pem", false, false, true, false, false }, |
| 854 #endif |
| 855 }; |
| 856 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot |
| 857 // be cleared until NSS is cleanly shutdown, which is not presently supported |
| 858 // in Chromium. |
| 859 #if defined(USE_NSS) |
| 860 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity |
| 861 #else |
| 862 #define MAYBE_VerifyEndEntity VerifyEndEntity |
| 863 #endif |
| 864 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity, |
| 865 CertVerifyProcWeakDigestTest, |
| 866 testing::ValuesIn(kVerifyEndEntityTestData)); |
| 867 |
| 868 // Incomplete chains should still report the status of the intermediate. |
| 869 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = { |
| 870 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem", |
| 871 true, false, false, true, false }, |
| 872 #if !defined(OS_MACOSX) // MD4 is not supported. |
| 873 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem", |
| 874 false, true, false, false, false }, |
| 875 #endif |
| 876 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem", |
| 877 false, false, true, false, true }, |
| 878 }; |
| 879 // Disabled on NSS - libpkix does not return constructed chains on error, |
| 880 // preventing us from detecting/inspecting the verified chain. |
| 881 #if defined(USE_NSS) |
| 882 #define MAYBE_VerifyIncompleteIntermediate \ |
| 883 DISABLED_VerifyIncompleteIntermediate |
| 884 #else |
| 885 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate |
| 886 #endif |
| 887 WRAPPED_INSTANTIATE_TEST_CASE_P( |
| 888 MAYBE_VerifyIncompleteIntermediate, |
| 889 CertVerifyProcWeakDigestTest, |
| 890 testing::ValuesIn(kVerifyIncompleteIntermediateTestData)); |
| 891 |
| 892 // Incomplete chains should still report the status of the end-entity. |
| 893 const WeakDigestTestData kVerifyIncompleteEETestData[] = { |
| 894 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem", |
| 895 true, false, false, false, false }, |
| 896 #if !defined(OS_MACOSX) // MD4 is not supported. |
| 897 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem", |
| 898 false, true, false, false, false }, |
| 899 #endif |
| 900 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem", |
| 901 false, false, true, false, false }, |
| 902 }; |
| 903 // Disabled on NSS - libpkix does not return constructed chains on error, |
| 904 // preventing us from detecting/inspecting the verified chain. |
| 905 #if defined(USE_NSS) |
| 906 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity |
| 907 #else |
| 908 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity |
| 909 #endif |
| 910 WRAPPED_INSTANTIATE_TEST_CASE_P( |
| 911 MAYBE_VerifyIncompleteEndEntity, |
| 912 CertVerifyProcWeakDigestTest, |
| 913 testing::ValuesIn(kVerifyIncompleteEETestData)); |
| 914 |
| 915 // Differing algorithms between the intermediate and the EE should still be |
| 916 // reported. |
| 917 const WeakDigestTestData kVerifyMixedTestData[] = { |
| 918 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", |
| 919 "weak_digest_md2_ee.pem", true, false, true, true, false }, |
| 920 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", |
| 921 "weak_digest_md5_ee.pem", true, false, true, false, true }, |
| 922 #if !defined(OS_MACOSX) // MD4 is not supported. |
| 923 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", |
| 924 "weak_digest_md2_ee.pem", false, true, true, false, false }, |
| 925 #endif |
| 926 }; |
| 927 // NSS does not support MD4 and does not enable MD2 by default, making all |
| 928 // permutations invalid. |
| 929 #if defined(USE_NSS) |
| 930 #define MAYBE_VerifyMixed DISABLED_VerifyMixed |
| 931 #else |
| 932 #define MAYBE_VerifyMixed VerifyMixed |
| 933 #endif |
| 934 WRAPPED_INSTANTIATE_TEST_CASE_P( |
| 935 MAYBE_VerifyMixed, |
| 936 CertVerifyProcWeakDigestTest, |
| 937 testing::ValuesIn(kVerifyMixedTestData)); |
| 938 |
| 939 } // namespace net |
OLD | NEW |