blob: 3c6024420738c959f9c5b23c67901f0cd8f1cac7 [file] [log] [blame]
[email protected]66d9b6e32012-03-22 03:04:321// 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
[email protected]6e7845ae2013-03-29 21:48:115#include "net/cert/cert_verify_proc.h"
[email protected]66d9b6e32012-03-22 03:04:326
7#include <vector>
8
[email protected]57999812013-02-24 05:40:529#include "base/files/file_path.h"
[email protected]ef155122013-03-23 19:11:2410#include "base/logging.h"
[email protected]66d9b6e32012-03-22 03:04:3211#include "base/sha1.h"
[email protected]4b355212013-06-11 10:35:1912#include "base/strings/string_number_conversions.h"
[email protected]bfea55d2013-04-04 11:06:0413#include "crypto/sha2.h"
[email protected]66d9b6e32012-03-22 03:04:3214#include "net/base/net_errors.h"
[email protected]42fdb452012-11-01 12:44:4015#include "net/base/test_data_directory.h"
[email protected]6e7845ae2013-03-29 21:48:1116#include "net/cert/asn1_util.h"
17#include "net/cert/cert_status_flags.h"
18#include "net/cert/cert_verifier.h"
19#include "net/cert/cert_verify_result.h"
20#include "net/cert/crl_set.h"
21#include "net/cert/test_root_certs.h"
22#include "net/cert/x509_certificate.h"
23#include "net/test/cert_test_util.h"
24#include "net/test/test_certificate_data.h"
[email protected]66d9b6e32012-03-22 03:04:3225#include "testing/gtest/include/gtest/gtest.h"
26
27#if defined(OS_WIN)
28#include "base/win/windows_version.h"
[email protected]12b3c8822012-09-26 11:51:1829#elif defined(OS_MACOSX) && !defined(OS_IOS)
[email protected]66d9b6e32012-03-22 03:04:3230#include "base/mac/mac_util.h"
31#endif
32
33using base::HexEncode;
34
35namespace net {
36
37namespace {
38
39// A certificate for www.paypal.com with a NULL byte in the common name.
40// From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363
41unsigned char paypal_null_fingerprint[] = {
42 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2, 0x6a, 0xba,
43 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7
44};
45
[email protected]ff353212013-05-17 02:09:0846// Mock CertVerifyProc that will set |verify_result->is_issued_by_known_root|
47// for all certificates that are Verified.
48class WellKnownCaCertVerifyProc : public CertVerifyProc {
49 public:
50 // Initialize a CertVerifyProc that will set
51 // |verify_result->is_issued_by_known_root| to |is_well_known|.
52 explicit WellKnownCaCertVerifyProc(bool is_well_known)
53 : is_well_known_(is_well_known) {}
54
55 // CertVerifyProc implementation:
56 virtual bool SupportsAdditionalTrustAnchors() const OVERRIDE { return false; }
57
58 protected:
59 virtual ~WellKnownCaCertVerifyProc() {}
60
61 private:
62 virtual int VerifyInternal(X509Certificate* cert,
63 const std::string& hostname,
64 int flags,
65 CRLSet* crl_set,
66 const CertificateList& additional_trust_anchors,
67 CertVerifyResult* verify_result) OVERRIDE;
68
69 const bool is_well_known_;
70
71 DISALLOW_COPY_AND_ASSIGN(WellKnownCaCertVerifyProc);
72};
73
74int WellKnownCaCertVerifyProc::VerifyInternal(
75 X509Certificate* cert,
76 const std::string& hostname,
77 int flags,
78 CRLSet* crl_set,
79 const CertificateList& additional_trust_anchors,
80 CertVerifyResult* verify_result) {
81 verify_result->is_issued_by_known_root = is_well_known_;
82 return OK;
83}
84
[email protected]66d9b6e32012-03-22 03:04:3285} // namespace
86
87class CertVerifyProcTest : public testing::Test {
88 public:
89 CertVerifyProcTest()
90 : verify_proc_(CertVerifyProc::CreateDefault()) {
91 }
92 virtual ~CertVerifyProcTest() {}
93
94 protected:
[email protected]ef155122013-03-23 19:11:2495 bool SupportsAdditionalTrustAnchors() {
96 return verify_proc_->SupportsAdditionalTrustAnchors();
97 }
98
[email protected]66d9b6e32012-03-22 03:04:3299 int Verify(X509Certificate* cert,
100 const std::string& hostname,
101 int flags,
102 CRLSet* crl_set,
[email protected]ef155122013-03-23 19:11:24103 const CertificateList& additional_trust_anchors,
[email protected]66d9b6e32012-03-22 03:04:32104 CertVerifyResult* verify_result) {
105 return verify_proc_->Verify(cert, hostname, flags, crl_set,
[email protected]ef155122013-03-23 19:11:24106 additional_trust_anchors, verify_result);
[email protected]66d9b6e32012-03-22 03:04:32107 }
108
[email protected]ef155122013-03-23 19:11:24109 const CertificateList empty_cert_list_;
[email protected]66d9b6e32012-03-22 03:04:32110 scoped_refptr<CertVerifyProc> verify_proc_;
111};
112
113TEST_F(CertVerifyProcTest, WithoutRevocationChecking) {
114 // Check that verification without revocation checking works.
115 CertificateList certs = CreateCertificateListFromFile(
116 GetTestCertsDirectory(),
117 "googlenew.chain.pem",
118 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
119
120 X509Certificate::OSCertHandles intermediates;
121 intermediates.push_back(certs[1]->os_cert_handle());
122
123 scoped_refptr<X509Certificate> google_full_chain =
124 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
125 intermediates);
126
127 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50128 EXPECT_EQ(OK,
129 Verify(google_full_chain.get(),
130 "www.google.com",
131 0 /* flags */,
132 NULL,
133 empty_cert_list_,
134 &verify_result));
[email protected]66d9b6e32012-03-22 03:04:32135}
136
137#if defined(OS_ANDROID) || defined(USE_OPENSSL)
138// TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
139#define MAYBE_EVVerification DISABLED_EVVerification
140#else
141#define MAYBE_EVVerification EVVerification
142#endif
[email protected]a12393332013-06-22 00:20:59143TEST_F(CertVerifyProcTest, DISABLED_EVVerification) {
144 // DISABLED: This certificate expired Jun 21, 2013.
[email protected]66d9b6e32012-03-22 03:04:32145 CertificateList certs = CreateCertificateListFromFile(
146 GetTestCertsDirectory(),
147 "comodo.chain.pem",
148 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
149 ASSERT_EQ(3U, certs.size());
150
151 X509Certificate::OSCertHandles intermediates;
152 intermediates.push_back(certs[1]->os_cert_handle());
153 intermediates.push_back(certs[2]->os_cert_handle());
154
155 scoped_refptr<X509Certificate> comodo_chain =
156 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
157 intermediates);
158
159 scoped_refptr<CRLSet> crl_set(CRLSet::EmptyCRLSetForTesting());
160 CertVerifyResult verify_result;
[email protected]8738e0d72012-08-23 02:00:47161 int flags = CertVerifier::VERIFY_EV_CERT;
[email protected]90499482013-06-01 00:39:50162 int error = Verify(comodo_chain.get(),
163 "comodo.com",
164 flags,
165 crl_set.get(),
166 empty_cert_list_,
167 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32168 EXPECT_EQ(OK, error);
169 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
170}
171
172TEST_F(CertVerifyProcTest, PaypalNullCertParsing) {
173 scoped_refptr<X509Certificate> paypal_null_cert(
174 X509Certificate::CreateFromBytes(
175 reinterpret_cast<const char*>(paypal_null_der),
176 sizeof(paypal_null_der)));
177
178 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert);
179
[email protected]ede03212012-09-07 12:52:26180 const SHA1HashValue& fingerprint =
[email protected]66d9b6e32012-03-22 03:04:32181 paypal_null_cert->fingerprint();
182 for (size_t i = 0; i < 20; ++i)
183 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]);
184
185 int flags = 0;
186 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50187 int error = Verify(paypal_null_cert.get(),
188 "www.paypal.com",
189 flags,
190 NULL,
191 empty_cert_list_,
192 &verify_result);
[email protected]71f4b272013-02-13 19:13:49193#if defined(USE_NSS) || defined(OS_IOS) || defined(OS_ANDROID)
[email protected]317dbc72012-04-03 18:45:14194 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
195#else
[email protected]66d9b6e32012-03-22 03:04:32196 // TOOD(bulach): investigate why macosx and win aren't returning
197 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID.
198 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
[email protected]66d9b6e32012-03-22 03:04:32199#endif
200 // Either the system crypto library should correctly report a certificate
201 // name mismatch, or our certificate blacklist should cause us to report an
202 // invalid certificate.
[email protected]12b3c8822012-09-26 11:51:18203#if defined(USE_NSS) || defined(OS_WIN) || defined(OS_IOS)
[email protected]66d9b6e32012-03-22 03:04:32204 EXPECT_TRUE(verify_result.cert_status &
205 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID));
206#endif
207}
208
209// A regression test for http://crbug.com/31497.
210// This certificate will expire on 2012-04-08. The test will still
211// pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test
212// certificates for this unit test. http://crbug.com/111742
213TEST_F(CertVerifyProcTest, IntermediateCARequireExplicitPolicy) {
[email protected]6cdfd7f2013-02-08 20:40:15214 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32215
216 scoped_refptr<X509Certificate> server_cert =
217 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der");
218 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
219
220 // The intermediate CA certificate's policyConstraints extension has a
221 // requireExplicitPolicy field with SkipCerts=0.
222 scoped_refptr<X509Certificate> intermediate_cert =
223 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
224 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
225
226 scoped_refptr<X509Certificate> root_cert =
227 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
[email protected]90499482013-06-01 00:39:50228 ScopedTestRoot scoped_root(root_cert.get());
[email protected]66d9b6e32012-03-22 03:04:32229
230 X509Certificate::OSCertHandles intermediates;
231 intermediates.push_back(intermediate_cert->os_cert_handle());
232 scoped_refptr<X509Certificate> cert_chain =
233 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
234 intermediates);
235
236 int flags = 0;
237 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50238 int error = Verify(cert_chain.get(),
239 "www.us.army.mil",
240 flags,
241 NULL,
242 empty_cert_list_,
243 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32244 if (error == OK) {
245 EXPECT_EQ(0U, verify_result.cert_status);
246 } else {
247 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
248 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status);
249 }
250}
251
252
253// Test for bug 58437.
254// This certificate will expire on 2011-12-21. The test will still
255// pass if error == ERR_CERT_DATE_INVALID.
256// This test is DISABLED because it appears that we cannot do
257// certificate revocation checking when running all of the net unit tests.
258// This test passes when run individually, but when run with all of the net
259// unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is
260// SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation
261// status, i.e. that the revocation check is failing for some reason.
262TEST_F(CertVerifyProcTest, DISABLED_GlobalSignR3EVTest) {
[email protected]6cdfd7f2013-02-08 20:40:15263 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32264
265 scoped_refptr<X509Certificate> server_cert =
266 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem");
267 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
268
269 scoped_refptr<X509Certificate> intermediate_cert =
270 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem");
271 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
272
273 X509Certificate::OSCertHandles intermediates;
274 intermediates.push_back(intermediate_cert->os_cert_handle());
275 scoped_refptr<X509Certificate> cert_chain =
276 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
277 intermediates);
278
279 CertVerifyResult verify_result;
[email protected]8738e0d72012-08-23 02:00:47280 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED |
281 CertVerifier::VERIFY_EV_CERT;
[email protected]90499482013-06-01 00:39:50282 int error = Verify(cert_chain.get(),
283 "2029.globalsign.com",
284 flags,
285 NULL,
286 empty_cert_list_,
287 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32288 if (error == OK)
289 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
290 else
291 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
292}
293
[email protected]fe845ab62012-08-24 16:03:29294// Test that verifying an ECDSA certificate doesn't crash on XP. (See
295// crbug.com/144466).
296TEST_F(CertVerifyProcTest, ECDSA_RSA) {
[email protected]6cdfd7f2013-02-08 20:40:15297 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]fe845ab62012-08-24 16:03:29298
299 scoped_refptr<X509Certificate> cert =
300 ImportCertFromFile(certs_dir,
301 "prime256v1-ecdsa-ee-by-1024-rsa-intermediate.pem");
302
303 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50304 Verify(cert.get(), "127.0.0.1", 0, NULL, empty_cert_list_, &verify_result);
[email protected]fe845ab62012-08-24 16:03:29305
306 // We don't check verify_result because the certificate is signed by an
307 // unknown CA and will be considered invalid on XP because of the ECDSA
308 // public key.
309}
310
[email protected]66d9b6e32012-03-22 03:04:32311// Currently, only RSA and DSA keys are checked for weakness, and our example
312// weak size is 768. These could change in the future.
313//
314// Note that this means there may be false negatives: keys for other
315// algorithms and which are weak will pass this test.
316static bool IsWeakKeyType(const std::string& key_type) {
317 size_t pos = key_type.find("-");
318 std::string size = key_type.substr(0, pos);
319 std::string type = key_type.substr(pos + 1);
320
321 if (type == "rsa" || type == "dsa")
322 return size == "768";
323
324 return false;
325}
326
327TEST_F(CertVerifyProcTest, RejectWeakKeys) {
[email protected]6cdfd7f2013-02-08 20:40:15328 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32329 typedef std::vector<std::string> Strings;
330 Strings key_types;
331
332 // generate-weak-test-chains.sh currently has:
333 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa"
334 // We must use the same key types here. The filenames generated look like:
335 // 2048-rsa-ee-by-768-rsa-intermediate.pem
336 key_types.push_back("768-rsa");
337 key_types.push_back("1024-rsa");
338 key_types.push_back("2048-rsa");
339
340 bool use_ecdsa = true;
341#if defined(OS_WIN)
342 use_ecdsa = base::win::GetVersion() > base::win::VERSION_XP;
[email protected]66d9b6e32012-03-22 03:04:32343#endif
344
345 if (use_ecdsa)
346 key_types.push_back("prime256v1-ecdsa");
347
348 // Add the root that signed the intermediates for this test.
349 scoped_refptr<X509Certificate> root_cert =
350 ImportCertFromFile(certs_dir, "2048-rsa-root.pem");
351 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
[email protected]90499482013-06-01 00:39:50352 ScopedTestRoot scoped_root(root_cert.get());
[email protected]66d9b6e32012-03-22 03:04:32353
354 // Now test each chain.
355 for (Strings::const_iterator ee_type = key_types.begin();
356 ee_type != key_types.end(); ++ee_type) {
357 for (Strings::const_iterator signer_type = key_types.begin();
358 signer_type != key_types.end(); ++signer_type) {
359 std::string basename = *ee_type + "-ee-by-" + *signer_type +
360 "-intermediate.pem";
361 SCOPED_TRACE(basename);
362 scoped_refptr<X509Certificate> ee_cert =
363 ImportCertFromFile(certs_dir, basename);
364 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
365
366 basename = *signer_type + "-intermediate.pem";
367 scoped_refptr<X509Certificate> intermediate =
368 ImportCertFromFile(certs_dir, basename);
369 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate);
370
371 X509Certificate::OSCertHandles intermediates;
372 intermediates.push_back(intermediate->os_cert_handle());
373 scoped_refptr<X509Certificate> cert_chain =
374 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
375 intermediates);
376
377 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50378 int error = Verify(cert_chain.get(),
379 "127.0.0.1",
380 0,
381 NULL,
382 empty_cert_list_,
383 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32384
385 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) {
386 EXPECT_NE(OK, error);
387 EXPECT_EQ(CERT_STATUS_WEAK_KEY,
388 verify_result.cert_status & CERT_STATUS_WEAK_KEY);
[email protected]58484ca2012-05-29 21:56:34389 EXPECT_NE(CERT_STATUS_INVALID,
390 verify_result.cert_status & CERT_STATUS_INVALID);
[email protected]66d9b6e32012-03-22 03:04:32391 } else {
392 EXPECT_EQ(OK, error);
393 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY);
394 }
395 }
396 }
397}
398
399// Test for bug 108514.
400// The certificate will expire on 2012-07-20. The test will still
401// pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test
402// certificates for this unit test. http://crbug.com/111730
403TEST_F(CertVerifyProcTest, ExtraneousMD5RootCert) {
[email protected]6cdfd7f2013-02-08 20:40:15404 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32405
406 scoped_refptr<X509Certificate> server_cert =
407 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem");
408 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
409
410 scoped_refptr<X509Certificate> intermediate_cert =
411 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem");
412 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
413
414 scoped_refptr<X509Certificate> md5_root_cert =
415 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem");
416 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert);
417
418 X509Certificate::OSCertHandles intermediates;
419 intermediates.push_back(intermediate_cert->os_cert_handle());
420 intermediates.push_back(md5_root_cert->os_cert_handle());
421 scoped_refptr<X509Certificate> cert_chain =
422 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
423 intermediates);
424
425 CertVerifyResult verify_result;
426 int flags = 0;
[email protected]90499482013-06-01 00:39:50427 int error = Verify(cert_chain.get(),
428 "images.etrade.wallst.com",
429 flags,
430 NULL,
431 empty_cert_list_,
432 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32433 if (error != OK)
434 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
435
436 EXPECT_FALSE(verify_result.has_md5);
[email protected]66d9b6e32012-03-22 03:04:32437}
438
439// Test for bug 94673.
440TEST_F(CertVerifyProcTest, GoogleDigiNotarTest) {
[email protected]6cdfd7f2013-02-08 20:40:15441 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32442
443 scoped_refptr<X509Certificate> server_cert =
444 ImportCertFromFile(certs_dir, "google_diginotar.pem");
445 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
446
447 scoped_refptr<X509Certificate> intermediate_cert =
448 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem");
449 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
450
451 X509Certificate::OSCertHandles intermediates;
452 intermediates.push_back(intermediate_cert->os_cert_handle());
453 scoped_refptr<X509Certificate> cert_chain =
454 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
455 intermediates);
456
457 CertVerifyResult verify_result;
[email protected]8738e0d72012-08-23 02:00:47458 int flags = CertVerifier::VERIFY_REV_CHECKING_ENABLED;
[email protected]90499482013-06-01 00:39:50459 int error = Verify(cert_chain.get(),
460 "mail.google.com",
461 flags,
462 NULL,
463 empty_cert_list_,
464 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32465 EXPECT_NE(OK, error);
466
467 // Now turn off revocation checking. Certificate verification should still
468 // fail.
469 flags = 0;
[email protected]90499482013-06-01 00:39:50470 error = Verify(cert_chain.get(),
471 "mail.google.com",
472 flags,
473 NULL,
474 empty_cert_list_,
475 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32476 EXPECT_NE(OK, error);
477}
478
[email protected]62b23c22012-03-22 04:50:24479TEST_F(CertVerifyProcTest, DigiNotarCerts) {
480 static const char* const kDigiNotarFilenames[] = {
481 "diginotar_root_ca.pem",
482 "diginotar_cyber_ca.pem",
483 "diginotar_services_1024_ca.pem",
484 "diginotar_pkioverheid.pem",
485 "diginotar_pkioverheid_g2.pem",
486 NULL,
487 };
488
[email protected]6cdfd7f2013-02-08 20:40:15489 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]62b23c22012-03-22 04:50:24490
491 for (size_t i = 0; kDigiNotarFilenames[i]; i++) {
492 scoped_refptr<X509Certificate> diginotar_cert =
493 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]);
494 std::string der_bytes;
495 ASSERT_TRUE(X509Certificate::GetDEREncoded(
496 diginotar_cert->os_cert_handle(), &der_bytes));
497
498 base::StringPiece spki;
499 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki));
500
501 std::string spki_sha1 = base::SHA1HashString(spki.as_string());
502
[email protected]ede03212012-09-07 12:52:26503 HashValueVector public_keys;
504 HashValue hash(HASH_VALUE_SHA1);
505 ASSERT_EQ(hash.size(), spki_sha1.size());
506 memcpy(hash.data(), spki_sha1.data(), spki_sha1.size());
507 public_keys.push_back(hash);
[email protected]62b23c22012-03-22 04:50:24508
509 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) <<
510 "Public key not blocked for " << kDigiNotarFilenames[i];
511 }
512}
513
[email protected]a6b4ee042012-07-24 20:52:46514TEST_F(CertVerifyProcTest, TestKnownRoot) {
[email protected]6cdfd7f2013-02-08 20:40:15515 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]a6b4ee042012-07-24 20:52:46516 CertificateList certs = CreateCertificateListFromFile(
517 certs_dir, "certse.pem", X509Certificate::FORMAT_AUTO);
518 ASSERT_EQ(3U, certs.size());
[email protected]66d9b6e32012-03-22 03:04:32519
520 X509Certificate::OSCertHandles intermediates;
[email protected]a6b4ee042012-07-24 20:52:46521 intermediates.push_back(certs[1]->os_cert_handle());
522 intermediates.push_back(certs[2]->os_cert_handle());
523
[email protected]66d9b6e32012-03-22 03:04:32524 scoped_refptr<X509Certificate> cert_chain =
[email protected]a6b4ee042012-07-24 20:52:46525 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
[email protected]66d9b6e32012-03-22 03:04:32526 intermediates);
527
528 int flags = 0;
529 CertVerifyResult verify_result;
[email protected]a6b4ee042012-07-24 20:52:46530 // This will blow up, June 8th, 2014. Sorry! Please disable and file a bug
531 // against agl. See also PublicKeyHashes.
[email protected]90499482013-06-01 00:39:50532 int error = Verify(cert_chain.get(),
533 "cert.se",
534 flags,
535 NULL,
536 empty_cert_list_,
537 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32538 EXPECT_EQ(OK, error);
539 EXPECT_EQ(0U, verify_result.cert_status);
540 EXPECT_TRUE(verify_result.is_issued_by_known_root);
541}
542
[email protected]a6b4ee042012-07-24 20:52:46543TEST_F(CertVerifyProcTest, PublicKeyHashes) {
[email protected]6cdfd7f2013-02-08 20:40:15544 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]a6b4ee042012-07-24 20:52:46545 CertificateList certs = CreateCertificateListFromFile(
546 certs_dir, "certse.pem", X509Certificate::FORMAT_AUTO);
547 ASSERT_EQ(3U, certs.size());
[email protected]66d9b6e32012-03-22 03:04:32548
549 X509Certificate::OSCertHandles intermediates;
[email protected]a6b4ee042012-07-24 20:52:46550 intermediates.push_back(certs[1]->os_cert_handle());
551 intermediates.push_back(certs[2]->os_cert_handle());
[email protected]66d9b6e32012-03-22 03:04:32552
[email protected]a6b4ee042012-07-24 20:52:46553 scoped_refptr<X509Certificate> cert_chain =
554 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
555 intermediates);
[email protected]66d9b6e32012-03-22 03:04:32556 int flags = 0;
557 CertVerifyResult verify_result;
558
[email protected]a6b4ee042012-07-24 20:52:46559 // This will blow up, June 8th, 2014. Sorry! Please disable and file a bug
560 // against agl. See also TestKnownRoot.
[email protected]90499482013-06-01 00:39:50561 int error = Verify(cert_chain.get(),
562 "cert.se",
563 flags,
564 NULL,
565 empty_cert_list_,
566 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32567 EXPECT_EQ(OK, error);
568 EXPECT_EQ(0U, verify_result.cert_status);
[email protected]bc0d7b82012-08-08 06:32:23569 ASSERT_LE(3u, verify_result.public_key_hashes.size());
[email protected]ede03212012-09-07 12:52:26570
571 HashValueVector sha1_hashes;
[email protected]bfea55d2013-04-04 11:06:04572 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) {
[email protected]ede03212012-09-07 12:52:26573 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1)
574 continue;
575 sha1_hashes.push_back(verify_result.public_key_hashes[i]);
576 }
577 ASSERT_LE(3u, sha1_hashes.size());
578
[email protected]bfea55d2013-04-04 11:06:04579 for (size_t i = 0; i < 3; ++i) {
[email protected]a6b4ee042012-07-24 20:52:46580 EXPECT_EQ(HexEncode(kCertSESPKIs[i], base::kSHA1Length),
[email protected]ede03212012-09-07 12:52:26581 HexEncode(sha1_hashes[i].data(), base::kSHA1Length));
[email protected]a6b4ee042012-07-24 20:52:46582 }
[email protected]bfea55d2013-04-04 11:06:04583
584 HashValueVector sha256_hashes;
585 for (size_t i = 0; i < verify_result.public_key_hashes.size(); ++i) {
586 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA256)
587 continue;
588 sha256_hashes.push_back(verify_result.public_key_hashes[i]);
589 }
590 ASSERT_LE(3u, sha256_hashes.size());
591
592 for (size_t i = 0; i < 3; ++i) {
593 EXPECT_EQ(HexEncode(kCertSESPKIsSHA256[i], crypto::kSHA256Length),
594 HexEncode(sha256_hashes[i].data(), crypto::kSHA256Length));
595 }
[email protected]66d9b6e32012-03-22 03:04:32596}
597
598// A regression test for http://crbug.com/70293.
599// The Key Usage extension in this RSA SSL server certificate does not have
600// the keyEncipherment bit.
601TEST_F(CertVerifyProcTest, InvalidKeyUsage) {
[email protected]6cdfd7f2013-02-08 20:40:15602 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32603
604 scoped_refptr<X509Certificate> server_cert =
605 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der");
606 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
607
608 int flags = 0;
609 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50610 int error = Verify(server_cert.get(),
611 "jira.aquameta.com",
612 flags,
613 NULL,
614 empty_cert_list_,
615 &verify_result);
[email protected]c97dc552013-04-25 21:29:56616#if defined(USE_OPENSSL) && !defined(OS_ANDROID)
[email protected]66d9b6e32012-03-22 03:04:32617 // This certificate has two errors: "invalid key usage" and "untrusted CA".
618 // However, OpenSSL returns only one (the latter), and we can't detect
619 // the other errors.
620 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
621#else
622 EXPECT_EQ(ERR_CERT_INVALID, error);
623 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
624#endif
625 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors
626 // from NSS.
[email protected]c97dc552013-04-25 21:29:56627#if !defined(USE_NSS) && !defined(OS_IOS) && !defined(OS_ANDROID)
[email protected]66d9b6e32012-03-22 03:04:32628 // The certificate is issued by an unknown CA.
629 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
630#endif
631}
632
633// Basic test for returning the chain in CertVerifyResult. Note that the
634// returned chain may just be a reflection of the originally supplied chain;
635// that is, if any errors occur, the default chain returned is an exact copy
636// of the certificate to be verified. The remaining VerifyReturn* tests are
637// used to ensure that the actual, verified chain is being returned by
638// Verify().
639TEST_F(CertVerifyProcTest, VerifyReturnChainBasic) {
[email protected]6cdfd7f2013-02-08 20:40:15640 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32641 CertificateList certs = CreateCertificateListFromFile(
642 certs_dir, "x509_verify_results.chain.pem",
643 X509Certificate::FORMAT_AUTO);
644 ASSERT_EQ(3U, certs.size());
645
646 X509Certificate::OSCertHandles intermediates;
647 intermediates.push_back(certs[1]->os_cert_handle());
648 intermediates.push_back(certs[2]->os_cert_handle());
649
[email protected]90499482013-06-01 00:39:50650 ScopedTestRoot scoped_root(certs[2].get());
[email protected]66d9b6e32012-03-22 03:04:32651
652 scoped_refptr<X509Certificate> google_full_chain =
653 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
654 intermediates);
655 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
656 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
657
658 CertVerifyResult verify_result;
659 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
[email protected]90499482013-06-01 00:39:50660 int error = Verify(google_full_chain.get(),
661 "127.0.0.1",
662 0,
663 NULL,
664 empty_cert_list_,
665 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32666 EXPECT_EQ(OK, error);
667 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
668
669 EXPECT_NE(google_full_chain, verify_result.verified_cert);
670 EXPECT_TRUE(X509Certificate::IsSameOSCert(
671 google_full_chain->os_cert_handle(),
672 verify_result.verified_cert->os_cert_handle()));
673 const X509Certificate::OSCertHandles& return_intermediates =
674 verify_result.verified_cert->GetIntermediateCertificates();
675 ASSERT_EQ(2U, return_intermediates.size());
676 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
677 certs[1]->os_cert_handle()));
678 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
679 certs[2]->os_cert_handle()));
680}
681
[email protected]ff353212013-05-17 02:09:08682// Test that certificates issued for 'intranet' names (that is, containing no
683// known public registry controlled domain information) issued by well-known
684// CAs are flagged appropriately, while certificates that are issued by
685// internal CAs are not flagged.
686TEST_F(CertVerifyProcTest, IntranetHostsRejected) {
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 CertVerifyResult verify_result;
694 int error = 0;
695
696 // Intranet names for public CAs should be flagged:
697 verify_proc_ = new WellKnownCaCertVerifyProc(true);
[email protected]90499482013-06-01 00:39:50698 error =
699 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result);
[email protected]ff353212013-05-17 02:09:08700 EXPECT_EQ(OK, error);
701 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME);
702
703 // However, if the CA is not well known, these should not be flagged:
704 verify_proc_ = new WellKnownCaCertVerifyProc(false);
[email protected]90499482013-06-01 00:39:50705 error =
706 Verify(cert.get(), "intranet", 0, NULL, empty_cert_list_, &verify_result);
[email protected]ff353212013-05-17 02:09:08707 EXPECT_EQ(OK, error);
708 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_NON_UNIQUE_NAME);
709}
710
[email protected]66d9b6e32012-03-22 03:04:32711// Test that the certificate returned in CertVerifyResult is able to reorder
712// certificates that are not ordered from end-entity to root. While this is
713// a protocol violation if sent during a TLS handshake, if multiple sources
714// of intermediate certificates are combined, it's possible that order may
715// not be maintained.
716TEST_F(CertVerifyProcTest, VerifyReturnChainProperlyOrdered) {
[email protected]6cdfd7f2013-02-08 20:40:15717 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32718 CertificateList certs = CreateCertificateListFromFile(
719 certs_dir, "x509_verify_results.chain.pem",
720 X509Certificate::FORMAT_AUTO);
721 ASSERT_EQ(3U, certs.size());
722
723 // Construct the chain out of order.
724 X509Certificate::OSCertHandles intermediates;
725 intermediates.push_back(certs[2]->os_cert_handle());
726 intermediates.push_back(certs[1]->os_cert_handle());
727
[email protected]90499482013-06-01 00:39:50728 ScopedTestRoot scoped_root(certs[2].get());
[email protected]66d9b6e32012-03-22 03:04:32729
730 scoped_refptr<X509Certificate> google_full_chain =
731 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
732 intermediates);
733 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
734 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
735
736 CertVerifyResult verify_result;
737 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
[email protected]90499482013-06-01 00:39:50738 int error = Verify(google_full_chain.get(),
739 "127.0.0.1",
740 0,
741 NULL,
742 empty_cert_list_,
743 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32744 EXPECT_EQ(OK, error);
745 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
746
747 EXPECT_NE(google_full_chain, verify_result.verified_cert);
748 EXPECT_TRUE(X509Certificate::IsSameOSCert(
749 google_full_chain->os_cert_handle(),
750 verify_result.verified_cert->os_cert_handle()));
751 const X509Certificate::OSCertHandles& return_intermediates =
752 verify_result.verified_cert->GetIntermediateCertificates();
753 ASSERT_EQ(2U, return_intermediates.size());
754 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
755 certs[1]->os_cert_handle()));
756 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
757 certs[2]->os_cert_handle()));
758}
759
760// Test that Verify() filters out certificates which are not related to
761// or part of the certificate chain being verified.
762TEST_F(CertVerifyProcTest, VerifyReturnChainFiltersUnrelatedCerts) {
[email protected]6cdfd7f2013-02-08 20:40:15763 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:32764 CertificateList certs = CreateCertificateListFromFile(
765 certs_dir, "x509_verify_results.chain.pem",
766 X509Certificate::FORMAT_AUTO);
767 ASSERT_EQ(3U, certs.size());
[email protected]90499482013-06-01 00:39:50768 ScopedTestRoot scoped_root(certs[2].get());
[email protected]66d9b6e32012-03-22 03:04:32769
770 scoped_refptr<X509Certificate> unrelated_dod_certificate =
771 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
772 scoped_refptr<X509Certificate> unrelated_dod_certificate2 =
773 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
774 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate);
775 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2);
776
777 // Interject unrelated certificates into the list of intermediates.
778 X509Certificate::OSCertHandles intermediates;
779 intermediates.push_back(unrelated_dod_certificate->os_cert_handle());
780 intermediates.push_back(certs[1]->os_cert_handle());
781 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle());
782 intermediates.push_back(certs[2]->os_cert_handle());
783
784 scoped_refptr<X509Certificate> google_full_chain =
785 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
786 intermediates);
787 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
788 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size());
789
790 CertVerifyResult verify_result;
791 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
[email protected]90499482013-06-01 00:39:50792 int error = Verify(google_full_chain.get(),
793 "127.0.0.1",
794 0,
795 NULL,
796 empty_cert_list_,
797 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:32798 EXPECT_EQ(OK, error);
799 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
800
801 EXPECT_NE(google_full_chain, verify_result.verified_cert);
802 EXPECT_TRUE(X509Certificate::IsSameOSCert(
803 google_full_chain->os_cert_handle(),
804 verify_result.verified_cert->os_cert_handle()));
805 const X509Certificate::OSCertHandles& return_intermediates =
806 verify_result.verified_cert->GetIntermediateCertificates();
807 ASSERT_EQ(2U, return_intermediates.size());
808 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
809 certs[1]->os_cert_handle()));
810 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
811 certs[2]->os_cert_handle()));
812}
813
[email protected]ef155122013-03-23 19:11:24814TEST_F(CertVerifyProcTest, AdditionalTrustAnchors) {
815 if (!SupportsAdditionalTrustAnchors()) {
816 LOG(INFO) << "Skipping this test in this platform.";
817 return;
818 }
819
820 // |ca_cert| is the issuer of |cert|.
821 CertificateList ca_cert_list = CreateCertificateListFromFile(
[email protected]d321e742013-06-20 16:28:44822 GetTestCertsDirectory(), "root_ca_cert.pem",
[email protected]ef155122013-03-23 19:11:24823 X509Certificate::FORMAT_AUTO);
824 ASSERT_EQ(1U, ca_cert_list.size());
825 scoped_refptr<X509Certificate> ca_cert(ca_cert_list[0]);
826
827 CertificateList cert_list = CreateCertificateListFromFile(
828 GetTestCertsDirectory(), "ok_cert.pem",
829 X509Certificate::FORMAT_AUTO);
830 ASSERT_EQ(1U, cert_list.size());
831 scoped_refptr<X509Certificate> cert(cert_list[0]);
832
833 // Verification of |cert| fails when |ca_cert| is not in the trust anchors
834 // list.
835 int flags = 0;
836 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:50837 int error = Verify(
838 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result);
[email protected]ef155122013-03-23 19:11:24839 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
840 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status);
[email protected]0d20bad2013-03-24 04:56:48841 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor);
[email protected]ef155122013-03-23 19:11:24842
843 // Now add the |ca_cert| to the |trust_anchors|, and verification should pass.
844 CertificateList trust_anchors;
845 trust_anchors.push_back(ca_cert);
[email protected]90499482013-06-01 00:39:50846 error = Verify(
847 cert.get(), "127.0.0.1", flags, NULL, trust_anchors, &verify_result);
[email protected]ef155122013-03-23 19:11:24848 EXPECT_EQ(OK, error);
849 EXPECT_EQ(0U, verify_result.cert_status);
[email protected]0d20bad2013-03-24 04:56:48850 EXPECT_TRUE(verify_result.is_issued_by_additional_trust_anchor);
[email protected]ef155122013-03-23 19:11:24851
852 // Clearing the |trust_anchors| makes verification fail again (the cache
853 // should be skipped).
[email protected]90499482013-06-01 00:39:50854 error = Verify(
855 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result);
[email protected]ef155122013-03-23 19:11:24856 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
857 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, verify_result.cert_status);
[email protected]0d20bad2013-03-24 04:56:48858 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor);
[email protected]ef155122013-03-23 19:11:24859}
860
[email protected]339e17e2013-06-14 02:48:29861#if defined(OS_MACOSX) && !defined(OS_IOS)
862// Tests that, on OS X, issues with a cross-certified Baltimore CyberTrust
863// Root can be successfully worked around once Apple completes removing the
864// older GTE CyberTrust Root from its trusted root store.
865//
866// The issue is caused by servers supplying the cross-certified intermediate
867// (necessary for certain mobile platforms), which OS X does not recognize
868// as already existing within its trust store.
869TEST_F(CertVerifyProcTest, CybertrustGTERoot) {
870 CertificateList certs = CreateCertificateListFromFile(
871 GetTestCertsDirectory(),
872 "cybertrust_omniroot_chain.pem",
873 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
874 ASSERT_EQ(2U, certs.size());
875
876 X509Certificate::OSCertHandles intermediates;
877 intermediates.push_back(certs[1]->os_cert_handle());
878
879 scoped_refptr<X509Certificate> cybertrust_basic =
880 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
881 intermediates);
882 ASSERT_TRUE(cybertrust_basic.get());
883
884 scoped_refptr<X509Certificate> baltimore_root =
885 ImportCertFromFile(GetTestCertsDirectory(),
886 "cybertrust_baltimore_root.pem");
887 ASSERT_TRUE(baltimore_root.get());
888
889 ScopedTestRoot scoped_root(baltimore_root);
890
891 // Ensure that ONLY the Baltimore CyberTrust Root is trusted. This
892 // simulates Keychain removing support for the GTE CyberTrust Root.
893 TestRootCerts::GetInstance()->SetAllowSystemTrust(false);
894 base::ScopedClosureRunner reset_system_trust(
895 base::Bind(&TestRootCerts::SetAllowSystemTrust,
896 base::Unretained(TestRootCerts::GetInstance()),
897 true));
898
899 // First, make sure a simple certificate chain from
900 // EE -> Public SureServer SV -> Baltimore CyberTrust
901 // works. Only the first two certificates are included in the chain.
902 int flags = 0;
903 CertVerifyResult verify_result;
904 int error = Verify(cybertrust_basic, "cacert.omniroot.com", flags, NULL,
905 empty_cert_list_, &verify_result);
906 EXPECT_EQ(OK, error);
907 EXPECT_EQ(0U, verify_result.cert_status);
908
909 // Attempt to verify with the first known cross-certified intermediate
910 // provided.
911 scoped_refptr<X509Certificate> baltimore_intermediate_1 =
912 ImportCertFromFile(GetTestCertsDirectory(),
913 "cybertrust_baltimore_cross_certified_1.pem");
914 ASSERT_TRUE(baltimore_intermediate_1.get());
915
916 X509Certificate::OSCertHandles intermediate_chain_1 =
917 cybertrust_basic->GetIntermediateCertificates();
918 intermediate_chain_1.push_back(baltimore_intermediate_1->os_cert_handle());
919
920 scoped_refptr<X509Certificate> baltimore_chain_1 =
921 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(),
922 intermediate_chain_1);
923 error = Verify(baltimore_chain_1, "cacert.omniroot.com", flags, NULL,
924 empty_cert_list_, &verify_result);
925 EXPECT_EQ(OK, error);
926 EXPECT_EQ(0U, verify_result.cert_status);
927
928 // Attempt to verify with the second known cross-certified intermediate
929 // provided.
930 scoped_refptr<X509Certificate> baltimore_intermediate_2 =
931 ImportCertFromFile(GetTestCertsDirectory(),
932 "cybertrust_baltimore_cross_certified_2.pem");
933 ASSERT_TRUE(baltimore_intermediate_2.get());
934
935 X509Certificate::OSCertHandles intermediate_chain_2 =
936 cybertrust_basic->GetIntermediateCertificates();
937 intermediate_chain_2.push_back(baltimore_intermediate_2->os_cert_handle());
938
939 scoped_refptr<X509Certificate> baltimore_chain_2 =
940 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(),
941 intermediate_chain_2);
942 error = Verify(baltimore_chain_2, "cacert.omniroot.com", flags, NULL,
943 empty_cert_list_, &verify_result);
944 EXPECT_EQ(OK, error);
945 EXPECT_EQ(0U, verify_result.cert_status);
946
947 // Attempt to verify when both a cross-certified intermediate AND
948 // the legacy GTE root are provided.
949 scoped_refptr<X509Certificate> cybertrust_root =
950 ImportCertFromFile(GetTestCertsDirectory(),
951 "cybertrust_gte_root.pem");
952 ASSERT_TRUE(cybertrust_root.get());
953
954 intermediate_chain_2.push_back(cybertrust_root->os_cert_handle());
955 scoped_refptr<X509Certificate> baltimore_chain_with_root =
956 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(),
957 intermediate_chain_2);
958 error = Verify(baltimore_chain_with_root, "cacert.omniroot.com", flags,
959 NULL, empty_cert_list_, &verify_result);
960 EXPECT_EQ(OK, error);
961 EXPECT_EQ(0U, verify_result.cert_status);
962
963}
964#endif
965
[email protected]12b3c8822012-09-26 11:51:18966#if defined(USE_NSS) || defined(OS_IOS) || defined(OS_WIN) || defined(OS_MACOSX)
[email protected]66d9b6e32012-03-22 03:04:32967static const uint8 kCRLSetThawteSPKIBlocked[] = {
968 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
969 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
970 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
971 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
972 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
973 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
974 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
975 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x36, 0x58, 0x36, 0x4d, 0x78, 0x52, 0x37,
976 0x58, 0x70, 0x4d, 0x51, 0x4b, 0x78, 0x49, 0x41, 0x39, 0x50, 0x6a, 0x36, 0x37,
977 0x36, 0x38, 0x76, 0x74, 0x55, 0x6b, 0x6b, 0x7a, 0x48, 0x79, 0x7a, 0x41, 0x6f,
978 0x6d, 0x6f, 0x4f, 0x68, 0x4b, 0x55, 0x6e, 0x7a, 0x73, 0x55, 0x3d, 0x22, 0x5d,
979 0x7d,
980};
981
982static const uint8 kCRLSetThawteSerialBlocked[] = {
983 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
984 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
985 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
986 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
987 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
988 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
989 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
990 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xb1, 0x12, 0x41, 0x42, 0xa5, 0xa1,
991 0xa5, 0xa2, 0x88, 0x19, 0xc7, 0x35, 0x34, 0x0e, 0xff, 0x8c, 0x9e, 0x2f, 0x81,
992 0x68, 0xfe, 0xe3, 0xba, 0x18, 0x7f, 0x25, 0x3b, 0xc1, 0xa3, 0x92, 0xd7, 0xe2,
993 // Note that this is actually blocking two serial numbers because on XP and
994 // Vista, CryptoAPI finds a different Thawte certificate.
995 0x02, 0x00, 0x00, 0x00,
996 0x04, 0x30, 0x00, 0x00, 0x02,
997 0x04, 0x30, 0x00, 0x00, 0x06,
998};
999
1000static const uint8 kCRLSetGoogleSerialBlocked[] = {
1001 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
1002 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
1003 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
1004 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
1005 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
1006 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
1007 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1008 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7,
1009 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52,
1010 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5,
1011 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b,
1012 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d,
1013};
1014
1015// Test that CRLSets are effective in making a certificate appear to be
1016// revoked.
1017TEST_F(CertVerifyProcTest, CRLSet) {
1018 CertificateList certs = CreateCertificateListFromFile(
1019 GetTestCertsDirectory(),
1020 "googlenew.chain.pem",
1021 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
1022
1023 X509Certificate::OSCertHandles intermediates;
1024 intermediates.push_back(certs[1]->os_cert_handle());
1025
1026 scoped_refptr<X509Certificate> google_full_chain =
1027 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1028 intermediates);
1029
1030 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:501031 int error = Verify(google_full_chain.get(),
1032 "www.google.com",
1033 0,
1034 NULL,
1035 empty_cert_list_,
1036 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:321037 EXPECT_EQ(OK, error);
1038
1039 // First test blocking by SPKI.
1040 base::StringPiece crl_set_bytes(
1041 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked),
1042 sizeof(kCRLSetThawteSPKIBlocked));
1043 scoped_refptr<CRLSet> crl_set;
1044 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1045
[email protected]90499482013-06-01 00:39:501046 error = Verify(google_full_chain.get(),
1047 "www.google.com",
1048 0,
1049 crl_set.get(),
1050 empty_cert_list_,
1051 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:321052 EXPECT_EQ(ERR_CERT_REVOKED, error);
1053
1054 // Second, test revocation by serial number of a cert directly under the
1055 // root.
1056 crl_set_bytes = base::StringPiece(
1057 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked),
1058 sizeof(kCRLSetThawteSerialBlocked));
1059 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1060
[email protected]90499482013-06-01 00:39:501061 error = Verify(google_full_chain.get(),
1062 "www.google.com",
1063 0,
1064 crl_set.get(),
1065 empty_cert_list_,
1066 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:321067 EXPECT_EQ(ERR_CERT_REVOKED, error);
1068
1069 // Lastly, test revocation by serial number of a certificate not under the
1070 // root.
1071 crl_set_bytes = base::StringPiece(
1072 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked),
1073 sizeof(kCRLSetGoogleSerialBlocked));
1074 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1075
[email protected]90499482013-06-01 00:39:501076 error = Verify(google_full_chain.get(),
1077 "www.google.com",
1078 0,
1079 crl_set.get(),
1080 empty_cert_list_,
1081 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:321082 EXPECT_EQ(ERR_CERT_REVOKED, error);
1083}
1084#endif
1085
1086struct WeakDigestTestData {
1087 const char* root_cert_filename;
1088 const char* intermediate_cert_filename;
1089 const char* ee_cert_filename;
1090 bool expected_has_md5;
1091 bool expected_has_md4;
1092 bool expected_has_md2;
[email protected]66d9b6e32012-03-22 03:04:321093};
1094
1095// GTest 'magic' pretty-printer, so that if/when a test fails, it knows how
1096// to output the parameter that was passed. Without this, it will simply
1097// attempt to print out the first twenty bytes of the object, which depending
1098// on platform and alignment, may result in an invalid read.
1099void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
1100 *os << "root: "
1101 << (data.root_cert_filename ? data.root_cert_filename : "none")
1102 << "; intermediate: " << data.intermediate_cert_filename
1103 << "; end-entity: " << data.ee_cert_filename;
1104}
1105
1106class CertVerifyProcWeakDigestTest
1107 : public CertVerifyProcTest,
1108 public testing::WithParamInterface<WeakDigestTestData> {
1109 public:
1110 CertVerifyProcWeakDigestTest() {}
1111 virtual ~CertVerifyProcWeakDigestTest() {}
1112};
1113
1114TEST_P(CertVerifyProcWeakDigestTest, Verify) {
1115 WeakDigestTestData data = GetParam();
[email protected]6cdfd7f2013-02-08 20:40:151116 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]66d9b6e32012-03-22 03:04:321117
1118 ScopedTestRoot test_root;
1119 if (data.root_cert_filename) {
1120 scoped_refptr<X509Certificate> root_cert =
1121 ImportCertFromFile(certs_dir, data.root_cert_filename);
1122 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
[email protected]90499482013-06-01 00:39:501123 test_root.Reset(root_cert.get());
[email protected]66d9b6e32012-03-22 03:04:321124 }
1125
1126 scoped_refptr<X509Certificate> intermediate_cert =
1127 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1128 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
1129 scoped_refptr<X509Certificate> ee_cert =
1130 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1131 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
1132
1133 X509Certificate::OSCertHandles intermediates;
1134 intermediates.push_back(intermediate_cert->os_cert_handle());
1135
1136 scoped_refptr<X509Certificate> ee_chain =
1137 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
1138 intermediates);
1139 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain);
1140
1141 int flags = 0;
1142 CertVerifyResult verify_result;
[email protected]90499482013-06-01 00:39:501143 int rv = Verify(ee_chain.get(),
1144 "127.0.0.1",
1145 flags,
1146 NULL,
1147 empty_cert_list_,
1148 &verify_result);
[email protected]66d9b6e32012-03-22 03:04:321149 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5);
1150 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4);
1151 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2);
[email protected]0d20bad2013-03-24 04:56:481152 EXPECT_FALSE(verify_result.is_issued_by_additional_trust_anchor);
[email protected]66d9b6e32012-03-22 03:04:321153
1154 // Ensure that MD4 and MD2 are tagged as invalid.
1155 if (data.expected_has_md4 || data.expected_has_md2) {
1156 EXPECT_EQ(CERT_STATUS_INVALID,
1157 verify_result.cert_status & CERT_STATUS_INVALID);
1158 }
1159
1160 // Ensure that MD5 is flagged as weak.
1161 if (data.expected_has_md5) {
1162 EXPECT_EQ(
1163 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM,
1164 verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1165 }
1166
1167 // If a root cert is present, then check that the chain was rejected if any
1168 // weak algorithms are present. This is only checked when a root cert is
1169 // present because the error reported for incomplete chains with weak
1170 // algorithms depends on which implementation was used to validate (NSS,
1171 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm
1172 // present (MD2, MD4, MD5).
1173 if (data.root_cert_filename) {
1174 if (data.expected_has_md4 || data.expected_has_md2) {
1175 EXPECT_EQ(ERR_CERT_INVALID, rv);
1176 } else if (data.expected_has_md5) {
1177 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, rv);
1178 } else {
1179 EXPECT_EQ(OK, rv);
1180 }
1181 }
1182}
1183
1184// Unlike TEST/TEST_F, which are macros that expand to further macros,
1185// INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
1186// stringizes the arguments. As a result, macros passed as parameters (such as
1187// prefix or test_case_name) will not be expanded by the preprocessor. To work
1188// around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
1189// pre-processor will expand macros such as MAYBE_test_name before
1190// instantiating the test.
1191#define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
1192 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
1193
1194// The signature algorithm of the root CA should not matter.
1195const WeakDigestTestData kVerifyRootCATestData[] = {
1196 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501197 "weak_digest_sha1_ee.pem", false, false, false },
[email protected]317dbc72012-04-03 18:45:141198#if defined(USE_OPENSSL) || defined(OS_WIN)
1199 // MD4 is not supported by OS X / NSS
[email protected]66d9b6e32012-03-22 03:04:321200 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501201 "weak_digest_sha1_ee.pem", false, false, false },
[email protected]66d9b6e32012-03-22 03:04:321202#endif
1203 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501204 "weak_digest_sha1_ee.pem", false, false, false },
[email protected]66d9b6e32012-03-22 03:04:321205};
1206INSTANTIATE_TEST_CASE_P(VerifyRoot, CertVerifyProcWeakDigestTest,
1207 testing::ValuesIn(kVerifyRootCATestData));
1208
1209// The signature algorithm of intermediates should be properly detected.
1210const WeakDigestTestData kVerifyIntermediateCATestData[] = {
1211 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501212 "weak_digest_sha1_ee.pem", true, false, false },
[email protected]317dbc72012-04-03 18:45:141213#if defined(USE_OPENSSL) || defined(OS_WIN)
1214 // MD4 is not supported by OS X / NSS
[email protected]66d9b6e32012-03-22 03:04:321215 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501216 "weak_digest_sha1_ee.pem", false, true, false },
[email protected]66d9b6e32012-03-22 03:04:321217#endif
[email protected]66d9b6e32012-03-22 03:04:321218 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501219 "weak_digest_sha1_ee.pem", false, false, true },
[email protected]66d9b6e32012-03-22 03:04:321220};
[email protected]fa2d3dc2012-11-20 07:58:441221// Disabled on NSS - MD4 is not supported, and MD2 and MD5 are disabled.
1222#if defined(USE_NSS) || defined(OS_IOS)
1223#define MAYBE_VerifyIntermediate DISABLED_VerifyIntermediate
1224#else
1225#define MAYBE_VerifyIntermediate VerifyIntermediate
1226#endif
1227WRAPPED_INSTANTIATE_TEST_CASE_P(
1228 MAYBE_VerifyIntermediate,
1229 CertVerifyProcWeakDigestTest,
1230 testing::ValuesIn(kVerifyIntermediateCATestData));
[email protected]66d9b6e32012-03-22 03:04:321231
1232// The signature algorithm of end-entity should be properly detected.
1233const WeakDigestTestData kVerifyEndEntityTestData[] = {
1234 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501235 "weak_digest_md5_ee.pem", true, false, false },
[email protected]317dbc72012-04-03 18:45:141236#if defined(USE_OPENSSL) || defined(OS_WIN)
1237 // MD4 is not supported by OS X / NSS
[email protected]66d9b6e32012-03-22 03:04:321238 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501239 "weak_digest_md4_ee.pem", false, true, false },
[email protected]66d9b6e32012-03-22 03:04:321240#endif
[email protected]66d9b6e32012-03-22 03:04:321241 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501242 "weak_digest_md2_ee.pem", false, false, true },
[email protected]66d9b6e32012-03-22 03:04:321243};
1244// Disabled on NSS - NSS caches chains/signatures in such a way that cannot
1245// be cleared until NSS is cleanly shutdown, which is not presently supported
1246// in Chromium.
[email protected]12b3c8822012-09-26 11:51:181247#if defined(USE_NSS) || defined(OS_IOS)
[email protected]66d9b6e32012-03-22 03:04:321248#define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity
1249#else
1250#define MAYBE_VerifyEndEntity VerifyEndEntity
1251#endif
1252WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity,
1253 CertVerifyProcWeakDigestTest,
1254 testing::ValuesIn(kVerifyEndEntityTestData));
1255
1256// Incomplete chains should still report the status of the intermediate.
1257const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = {
1258 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem",
[email protected]4aba74c2013-06-28 01:35:501259 true, false, false },
[email protected]317dbc72012-04-03 18:45:141260#if defined(USE_OPENSSL) || defined(OS_WIN)
1261 // MD4 is not supported by OS X / NSS
[email protected]66d9b6e32012-03-22 03:04:321262 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem",
[email protected]4aba74c2013-06-28 01:35:501263 false, true, false },
[email protected]66d9b6e32012-03-22 03:04:321264#endif
1265 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem",
[email protected]4aba74c2013-06-28 01:35:501266 false, false, true },
[email protected]66d9b6e32012-03-22 03:04:321267};
1268// Disabled on NSS - libpkix does not return constructed chains on error,
1269// preventing us from detecting/inspecting the verified chain.
[email protected]12b3c8822012-09-26 11:51:181270#if defined(USE_NSS) || defined(OS_IOS)
[email protected]66d9b6e32012-03-22 03:04:321271#define MAYBE_VerifyIncompleteIntermediate \
1272 DISABLED_VerifyIncompleteIntermediate
1273#else
1274#define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate
1275#endif
1276WRAPPED_INSTANTIATE_TEST_CASE_P(
1277 MAYBE_VerifyIncompleteIntermediate,
1278 CertVerifyProcWeakDigestTest,
1279 testing::ValuesIn(kVerifyIncompleteIntermediateTestData));
1280
1281// Incomplete chains should still report the status of the end-entity.
1282const WeakDigestTestData kVerifyIncompleteEETestData[] = {
1283 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem",
[email protected]4aba74c2013-06-28 01:35:501284 true, false, false },
[email protected]317dbc72012-04-03 18:45:141285#if defined(USE_OPENSSL) || defined(OS_WIN)
1286 // MD4 is not supported by OS X / NSS
[email protected]66d9b6e32012-03-22 03:04:321287 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem",
[email protected]4aba74c2013-06-28 01:35:501288 false, true, false },
[email protected]66d9b6e32012-03-22 03:04:321289#endif
1290 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem",
[email protected]4aba74c2013-06-28 01:35:501291 false, false, true },
[email protected]66d9b6e32012-03-22 03:04:321292};
1293// Disabled on NSS - libpkix does not return constructed chains on error,
1294// preventing us from detecting/inspecting the verified chain.
[email protected]12b3c8822012-09-26 11:51:181295#if defined(USE_NSS) || defined(OS_IOS)
[email protected]66d9b6e32012-03-22 03:04:321296#define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity
1297#else
1298#define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity
1299#endif
1300WRAPPED_INSTANTIATE_TEST_CASE_P(
1301 MAYBE_VerifyIncompleteEndEntity,
1302 CertVerifyProcWeakDigestTest,
1303 testing::ValuesIn(kVerifyIncompleteEETestData));
1304
1305// Differing algorithms between the intermediate and the EE should still be
1306// reported.
1307const WeakDigestTestData kVerifyMixedTestData[] = {
1308 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501309 "weak_digest_md2_ee.pem", true, false, true },
[email protected]66d9b6e32012-03-22 03:04:321310 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501311 "weak_digest_md5_ee.pem", true, false, true },
[email protected]317dbc72012-04-03 18:45:141312#if defined(USE_OPENSSL) || defined(OS_WIN)
1313 // MD4 is not supported by OS X / NSS
[email protected]66d9b6e32012-03-22 03:04:321314 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
[email protected]4aba74c2013-06-28 01:35:501315 "weak_digest_md2_ee.pem", false, true, true },
[email protected]66d9b6e32012-03-22 03:04:321316#endif
1317};
1318// NSS does not support MD4 and does not enable MD2 by default, making all
1319// permutations invalid.
[email protected]12b3c8822012-09-26 11:51:181320#if defined(USE_NSS) || defined(OS_IOS)
[email protected]66d9b6e32012-03-22 03:04:321321#define MAYBE_VerifyMixed DISABLED_VerifyMixed
1322#else
1323#define MAYBE_VerifyMixed VerifyMixed
1324#endif
1325WRAPPED_INSTANTIATE_TEST_CASE_P(
1326 MAYBE_VerifyMixed,
1327 CertVerifyProcWeakDigestTest,
1328 testing::ValuesIn(kVerifyMixedTestData));
1329
[email protected]ff353212013-05-17 02:09:081330struct NonUniqueNameTestData {
1331 bool is_unique;
1332 const char* hostname;
1333};
1334
1335// Google Test pretty-printer.
1336void PrintTo(const NonUniqueNameTestData& data, std::ostream* os) {
1337 ASSERT_TRUE(data.hostname);
1338 *os << " hostname: " << testing::PrintToString(data.hostname)
1339 << "; is_unique: " << testing::PrintToString(data.is_unique);
1340}
1341
1342const NonUniqueNameTestData kNonUniqueNameTestData[] = {
1343 // Domains under ICANN-assigned domains.
1344 { true, "google.com" },
1345 { true, "google.co.uk" },
1346 // Domains under private registries.
1347 { true, "appspot.com" },
1348 { true, "test.appspot.com" },
1349 // IPv4 addresses (in various forms).
1350 { true, "8.8.8.8" },
1351 { true, "1.2.3" },
1352 { true, "14.15" },
1353 { true, "676768" },
1354 // IPv6 addresses.
1355 { true, "FEDC:ba98:7654:3210:FEDC:BA98:7654:3210" },
1356 { true, "::192.9.5.5" },
1357 { true, "FEED::BEEF" },
1358 // 'internal'/non-IANA assigned domains.
1359 { false, "intranet" },
1360 { false, "intranet." },
1361 { false, "intranet.example" },
1362 { false, "host.intranet.example" },
1363 // gTLDs under discussion, but not yet assigned.
1364 { false, "intranet.corp" },
1365 { false, "example.tech" },
1366 { false, "intranet.internal" },
1367 // Invalid host names are treated as unique - but expected to be
1368 // filtered out before then.
1369 { true, "junk)(£)$*!@~#" },
1370 { true, "w$w.example.com" },
1371 { true, "nocolonsallowed:example" },
1372 { true, "[::4.5.6.9]" },
1373};
1374
1375class CertVerifyProcNonUniqueNameTest
1376 : public testing::TestWithParam<NonUniqueNameTestData> {
1377 public:
1378 virtual ~CertVerifyProcNonUniqueNameTest() {}
1379
1380 protected:
1381 bool IsUnique(const std::string& hostname) {
1382 return !CertVerifyProc::IsHostnameNonUnique(hostname);
1383 }
1384};
1385
1386// Test that internal/non-unique names are properly identified as such, but
1387// that IP addresses and hosts beneath registry-controlled domains are flagged
1388// as unique names.
1389TEST_P(CertVerifyProcNonUniqueNameTest, IsHostnameNonUnique) {
1390 const NonUniqueNameTestData& test_data = GetParam();
1391
1392 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname));
1393}
1394
1395INSTANTIATE_TEST_CASE_P(, CertVerifyProcNonUniqueNameTest,
1396 testing::ValuesIn(kNonUniqueNameTestData));
1397
[email protected]66d9b6e32012-03-22 03:04:321398} // namespace net