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

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

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

Powered by Google App Engine
This is Rietveld 408576698