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

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

Issue 9553014: Move certificate verification tests from X509CertificateTest to CertVerifyProcTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h"
8 #include "base/pickle.h" 7 #include "base/pickle.h"
9 #include "base/sha1.h" 8 #include "base/sha1.h"
10 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
11 #include "base/string_split.h" 10 #include "base/string_split.h"
12 #include "crypto/rsa_private_key.h" 11 #include "crypto/rsa_private_key.h"
13 #include "net/base/asn1_util.h" 12 #include "net/base/asn1_util.h"
14 #include "net/base/cert_status_flags.h"
15 #include "net/base/cert_test_util.h" 13 #include "net/base/cert_test_util.h"
16 #include "net/base/cert_verify_result.h"
17 #include "net/base/crl_set.h"
18 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
19 #include "net/base/test_certificate_data.h" 15 #include "net/base/test_certificate_data.h"
20 #include "net/base/test_root_certs.h"
21 #include "net/base/x509_certificate.h" 16 #include "net/base/x509_certificate.h"
22 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
23 18
24 #if defined(USE_NSS) 19 #if defined(USE_NSS)
25 #include <cert.h> 20 #include <cert.h>
26 #endif 21 #endif
27 22
28 #if defined(OS_WIN)
29 #include "base/win/windows_version.h"
30 #elif defined(OS_MACOSX)
31 #include "base/mac/mac_util.h"
32 #endif
33
34 // Unit tests aren't allowed to access external resources. Unfortunately, to
35 // properly verify the EV-ness of a cert, we need to check for its revocation
36 // through online servers. If you're manually running unit tests, feel free to
37 // turn this on to test EV certs. But leave it turned off for the automated
38 // testing.
39 #define ALLOW_EXTERNAL_ACCESS 0
40
41 #if ALLOW_EXTERNAL_ACCESS && defined(OS_WIN)
42 #define TEST_EV 1 // Test CERT_STATUS_IS_EV
43 #endif
44
45 using base::HexEncode; 23 using base::HexEncode;
46 using base::Time; 24 using base::Time;
47 25
48 namespace net { 26 namespace net {
49 27
50 // Certificates for test data. They're obtained with: 28 // Certificates for test data. They're obtained with:
51 // 29 //
52 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null 30 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null
53 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der 31 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der
54 // 32 //
(...skipping 16 matching lines...) Expand all
71 0xa1, 0x4a, 0x94, 0x46, 0x22, 0x8e, 0x70, 0x66, 0x2b, 0x94, 0xf9, 0xf8, 49 0xa1, 0x4a, 0x94, 0x46, 0x22, 0x8e, 0x70, 0x66, 0x2b, 0x94, 0xf9, 0xf8,
72 0x57, 0x83, 0x2d, 0xa2, 0xff, 0xbc, 0x84, 0xc2 50 0x57, 0x83, 0x2d, 0xa2, 0xff, 0xbc, 0x84, 0xc2
73 }; 51 };
74 52
75 // thawte.com's cert (it's EV-licious!). 53 // thawte.com's cert (it's EV-licious!).
76 unsigned char thawte_fingerprint[] = { 54 unsigned char thawte_fingerprint[] = {
77 0x85, 0x04, 0x2d, 0xfd, 0x2b, 0x0e, 0xc6, 0xc8, 0xaf, 0x2d, 0x77, 0xd6, 55 0x85, 0x04, 0x2d, 0xfd, 0x2b, 0x0e, 0xc6, 0xc8, 0xaf, 0x2d, 0x77, 0xd6,
78 0xa1, 0x3a, 0x64, 0x04, 0x27, 0x90, 0x97, 0x37 56 0xa1, 0x3a, 0x64, 0x04, 0x27, 0x90, 0x97, 0x37
79 }; 57 };
80 58
81 // A certificate for www.paypal.com with a NULL byte in the common name.
82 // From http://www.gossamer-threads.com/lists/fulldisc/full-disclosure/70363
83 unsigned char paypal_null_fingerprint[] = {
84 0x4c, 0x88, 0x9e, 0x28, 0xd7, 0x7a, 0x44, 0x1e, 0x13, 0xf2, 0x6a, 0xba,
85 0x1f, 0xe8, 0x1b, 0xd6, 0xab, 0x7b, 0xe8, 0xd7
86 };
87
88 // A certificate for https://www.unosoft.hu/, whose AIA extension contains 59 // A certificate for https://www.unosoft.hu/, whose AIA extension contains
89 // an LDAP URL without a host name. 60 // an LDAP URL without a host name.
90 unsigned char unosoft_hu_fingerprint[] = { 61 unsigned char unosoft_hu_fingerprint[] = {
91 0x32, 0xff, 0xe3, 0xbe, 0x2c, 0x3b, 0xc7, 0xca, 0xbf, 0x2d, 0x64, 0xbd, 62 0x32, 0xff, 0xe3, 0xbe, 0x2c, 0x3b, 0xc7, 0xca, 0xbf, 0x2d, 0x64, 0xbd,
92 0x25, 0x66, 0xf2, 0xec, 0x8b, 0x0f, 0xbf, 0xd8 63 0x25, 0x66, 0xf2, 0xec, 0x8b, 0x0f, 0xbf, 0xd8
93 }; 64 };
94 65
95 // The fingerprint of the Google certificate used in the parsing tests, 66 // The fingerprint of the Google certificate used in the parsing tests,
96 // which is newer than the one included in the x509_certificate_data.h 67 // which is newer than the one included in the x509_certificate_data.h
97 unsigned char google_parse_fingerprint[] = { 68 unsigned char google_parse_fingerprint[] = {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); 187 const SHA1Fingerprint& fingerprint = google_cert->fingerprint();
217 for (size_t i = 0; i < 20; ++i) 188 for (size_t i = 0; i < 20; ++i)
218 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); 189 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]);
219 190
220 std::vector<std::string> dns_names; 191 std::vector<std::string> dns_names;
221 google_cert->GetDNSNames(&dns_names); 192 google_cert->GetDNSNames(&dns_names);
222 ASSERT_EQ(1U, dns_names.size()); 193 ASSERT_EQ(1U, dns_names.size());
223 EXPECT_EQ("www.google.com", dns_names[0]); 194 EXPECT_EQ("www.google.com", dns_names[0]);
224 } 195 }
225 196
226 // TODO(rsleevi): Temporary fixture while refactoring http://crbug.com/114343 197 TEST(X509CertificateTest, GoogleCertParsing) {
227 class X509CertificateTest : public testing::Test {
228 public:
229 X509CertificateTest() {}
230 virtual ~X509CertificateTest() {}
231
232 protected:
233 int Verify(X509Certificate* cert,
234 const std::string& hostname,
235 int flags,
236 CRLSet* crl_set,
237 CertVerifyResult* verify_result) {
238 return cert->Verify(hostname, flags, crl_set, verify_result);
239 }
240 };
241
242 TEST_F(X509CertificateTest, GoogleCertParsing) {
243 scoped_refptr<X509Certificate> google_cert( 198 scoped_refptr<X509Certificate> google_cert(
244 X509Certificate::CreateFromBytes( 199 X509Certificate::CreateFromBytes(
245 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 200 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
246 201
247 CheckGoogleCert(google_cert, google_fingerprint, 202 CheckGoogleCert(google_cert, google_fingerprint,
248 1238192407, // Mar 27 22:20:07 2009 GMT 203 1238192407, // Mar 27 22:20:07 2009 GMT
249 1269728407); // Mar 27 22:20:07 2010 GMT 204 1269728407); // Mar 27 22:20:07 2010 GMT
250 } 205 }
251 206
252 TEST_F(X509CertificateTest, WebkitCertParsing) { 207 TEST(X509CertificateTest, WebkitCertParsing) {
253 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( 208 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes(
254 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 209 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
255 210
256 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); 211 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert);
257 212
258 const CertPrincipal& subject = webkit_cert->subject(); 213 const CertPrincipal& subject = webkit_cert->subject();
259 EXPECT_EQ("Cupertino", subject.locality_name); 214 EXPECT_EQ("Cupertino", subject.locality_name);
260 EXPECT_EQ("California", subject.state_or_province_name); 215 EXPECT_EQ("California", subject.state_or_province_name);
261 EXPECT_EQ("US", subject.country_name); 216 EXPECT_EQ("US", subject.country_name);
262 EXPECT_EQ(0U, subject.street_addresses.size()); 217 EXPECT_EQ(0U, subject.street_addresses.size());
(...skipping 26 matching lines...) Expand all
289 const SHA1Fingerprint& fingerprint = webkit_cert->fingerprint(); 244 const SHA1Fingerprint& fingerprint = webkit_cert->fingerprint();
290 for (size_t i = 0; i < 20; ++i) 245 for (size_t i = 0; i < 20; ++i)
291 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]); 246 EXPECT_EQ(webkit_fingerprint[i], fingerprint.data[i]);
292 247
293 std::vector<std::string> dns_names; 248 std::vector<std::string> dns_names;
294 webkit_cert->GetDNSNames(&dns_names); 249 webkit_cert->GetDNSNames(&dns_names);
295 ASSERT_EQ(2U, dns_names.size()); 250 ASSERT_EQ(2U, dns_names.size());
296 EXPECT_EQ("*.webkit.org", dns_names[0]); 251 EXPECT_EQ("*.webkit.org", dns_names[0]);
297 EXPECT_EQ("webkit.org", dns_names[1]); 252 EXPECT_EQ("webkit.org", dns_names[1]);
298 253
299 #if TEST_EV
300 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
301 X509Certificate::VERIFY_EV_CERT;
302 CertVerifyResult verify_result;
303 EXPECT_EQ(OK, webkit_cert->Verify("webkit.org", flags, NULL, &verify_result));
304 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_IS_EV);
305 #endif
306
307 // Test that the wildcard cert matches properly. 254 // Test that the wildcard cert matches properly.
308 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); 255 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org"));
309 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); 256 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org"));
310 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); 257 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org"));
311 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); 258 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com"));
312 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); 259 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com"));
313 } 260 }
314 261
315 TEST_F(X509CertificateTest, WithoutRevocationChecking) { 262 TEST(X509CertificateTest, ThawteCertParsing) {
316 // Check that verification without revocation checking works.
317 CertificateList certs = CreateCertificateListFromFile(
318 GetTestCertsDirectory(),
319 "googlenew.chain.pem",
320 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
321
322 X509Certificate::OSCertHandles intermediates;
323 intermediates.push_back(certs[1]->os_cert_handle());
324
325 scoped_refptr<X509Certificate> google_full_chain =
326 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
327 intermediates);
328
329 CertVerifyResult verify_result;
330 EXPECT_EQ(OK, Verify(google_full_chain, "www.google.com", 0 /* flags */, NULL,
331 &verify_result));
332 }
333
334 TEST_F(X509CertificateTest, ThawteCertParsing) {
335 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( 263 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes(
336 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); 264 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)));
337 265
338 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); 266 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert);
339 267
340 const CertPrincipal& subject = thawte_cert->subject(); 268 const CertPrincipal& subject = thawte_cert->subject();
341 EXPECT_EQ("www.thawte.com", subject.common_name); 269 EXPECT_EQ("www.thawte.com", subject.common_name);
342 EXPECT_EQ("Mountain View", subject.locality_name); 270 EXPECT_EQ("Mountain View", subject.locality_name);
343 EXPECT_EQ("California", subject.state_or_province_name); 271 EXPECT_EQ("California", subject.state_or_province_name);
344 EXPECT_EQ("US", subject.country_name); 272 EXPECT_EQ("US", subject.country_name);
(...skipping 24 matching lines...) Expand all
369 EXPECT_EQ(1263772799, valid_expiry.ToDoubleT()); // Jan 17 23:59:59 2010 GMT 297 EXPECT_EQ(1263772799, valid_expiry.ToDoubleT()); // Jan 17 23:59:59 2010 GMT
370 298
371 const SHA1Fingerprint& fingerprint = thawte_cert->fingerprint(); 299 const SHA1Fingerprint& fingerprint = thawte_cert->fingerprint();
372 for (size_t i = 0; i < 20; ++i) 300 for (size_t i = 0; i < 20; ++i)
373 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]); 301 EXPECT_EQ(thawte_fingerprint[i], fingerprint.data[i]);
374 302
375 std::vector<std::string> dns_names; 303 std::vector<std::string> dns_names;
376 thawte_cert->GetDNSNames(&dns_names); 304 thawte_cert->GetDNSNames(&dns_names);
377 ASSERT_EQ(1U, dns_names.size()); 305 ASSERT_EQ(1U, dns_names.size());
378 EXPECT_EQ("www.thawte.com", dns_names[0]); 306 EXPECT_EQ("www.thawte.com", dns_names[0]);
379
380 #if TEST_EV
381 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
382 X509Certificate::VERIFY_EV_CERT;
383 CertVerifyResult verify_result;
384 // EV cert verification requires revocation checking.
385 EXPECT_EQ(OK, Verify(thawte_cert, "www.thawte.com", flags, NULL,
386 &verify_result);
387 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
388 // Consequently, if we don't have revocation checking enabled, we can't claim
389 // any cert is EV.
390 flags = X509Certificate::VERIFY_EV_CERT;
391 EXPECT_EQ(OK, Verify(thawte_cert, "www.thawte.com", flags, NULL,
392 &verify_result));
393 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_IS_EV);
394 #endif
395 } 307 }
396 308
397 // Test that all desired AttributeAndValue pairs can be extracted when only 309 // Test that all desired AttributeAndValue pairs can be extracted when only
398 // a single RelativeDistinguishedName is present. "Normally" there is only 310 // a single RelativeDistinguishedName is present. "Normally" there is only
399 // one AVA per RDN, but some CAs place all AVAs within a single RDN. 311 // one AVA per RDN, but some CAs place all AVAs within a single RDN.
400 // This is a regression test for http://crbug.com/101009 312 // This is a regression test for http://crbug.com/101009
401 TEST_F(X509CertificateTest, MultivalueRDN) { 313 TEST(X509CertificateTest, MultivalueRDN) {
402 FilePath certs_dir = GetTestCertsDirectory(); 314 FilePath certs_dir = GetTestCertsDirectory();
403 315
404 scoped_refptr<X509Certificate> multivalue_rdn_cert = 316 scoped_refptr<X509Certificate> multivalue_rdn_cert =
405 ImportCertFromFile(certs_dir, "multivalue_rdn.pem"); 317 ImportCertFromFile(certs_dir, "multivalue_rdn.pem");
406 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert); 318 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert);
407 319
408 const CertPrincipal& subject = multivalue_rdn_cert->subject(); 320 const CertPrincipal& subject = multivalue_rdn_cert->subject();
409 EXPECT_EQ("Multivalue RDN Test", subject.common_name); 321 EXPECT_EQ("Multivalue RDN Test", subject.common_name);
410 EXPECT_EQ("", subject.locality_name); 322 EXPECT_EQ("", subject.locality_name);
411 EXPECT_EQ("", subject.state_or_province_name); 323 EXPECT_EQ("", subject.state_or_province_name);
412 EXPECT_EQ("US", subject.country_name); 324 EXPECT_EQ("US", subject.country_name);
413 EXPECT_EQ(0U, subject.street_addresses.size()); 325 EXPECT_EQ(0U, subject.street_addresses.size());
414 ASSERT_EQ(1U, subject.organization_names.size()); 326 ASSERT_EQ(1U, subject.organization_names.size());
415 EXPECT_EQ("Chromium", subject.organization_names[0]); 327 EXPECT_EQ("Chromium", subject.organization_names[0]);
416 ASSERT_EQ(1U, subject.organization_unit_names.size()); 328 ASSERT_EQ(1U, subject.organization_unit_names.size());
417 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]); 329 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]);
418 ASSERT_EQ(1U, subject.domain_components.size()); 330 ASSERT_EQ(1U, subject.domain_components.size());
419 EXPECT_EQ("Chromium", subject.domain_components[0]); 331 EXPECT_EQ("Chromium", subject.domain_components[0]);
420 } 332 }
421 333
422 // Test that characters which would normally be escaped in the string form, 334 // Test that characters which would normally be escaped in the string form,
423 // such as '=' or '"', are not escaped when parsed as individual components. 335 // such as '=' or '"', are not escaped when parsed as individual components.
424 // This is a regression test for http://crbug.com/102839 336 // This is a regression test for http://crbug.com/102839
425 TEST_F(X509CertificateTest, UnescapedSpecialCharacters) { 337 TEST(X509CertificateTest, UnescapedSpecialCharacters) {
426 FilePath certs_dir = GetTestCertsDirectory(); 338 FilePath certs_dir = GetTestCertsDirectory();
427 339
428 scoped_refptr<X509Certificate> unescaped_cert = 340 scoped_refptr<X509Certificate> unescaped_cert =
429 ImportCertFromFile(certs_dir, "unescaped.pem"); 341 ImportCertFromFile(certs_dir, "unescaped.pem");
430 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert); 342 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert);
431 343
432 const CertPrincipal& subject = unescaped_cert->subject(); 344 const CertPrincipal& subject = unescaped_cert->subject();
433 EXPECT_EQ("127.0.0.1", subject.common_name); 345 EXPECT_EQ("127.0.0.1", subject.common_name);
434 EXPECT_EQ("Mountain View", subject.locality_name); 346 EXPECT_EQ("Mountain View", subject.locality_name);
435 EXPECT_EQ("California", subject.state_or_province_name); 347 EXPECT_EQ("California", subject.state_or_province_name);
436 EXPECT_EQ("US", subject.country_name); 348 EXPECT_EQ("US", subject.country_name);
437 ASSERT_EQ(1U, subject.street_addresses.size()); 349 ASSERT_EQ(1U, subject.street_addresses.size());
438 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]); 350 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]);
439 ASSERT_EQ(1U, subject.organization_names.size()); 351 ASSERT_EQ(1U, subject.organization_names.size());
440 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]); 352 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]);
441 ASSERT_EQ(2U, subject.organization_unit_names.size()); 353 ASSERT_EQ(2U, subject.organization_unit_names.size());
442 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]); 354 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]);
443 EXPECT_EQ("Chromium", subject.organization_unit_names[1]); 355 EXPECT_EQ("Chromium", subject.organization_unit_names[1]);
444 EXPECT_EQ(0U, subject.domain_components.size()); 356 EXPECT_EQ(0U, subject.domain_components.size());
445 } 357 }
446 358
447 TEST_F(X509CertificateTest, PaypalNullCertParsing) { 359 TEST(X509CertificateTest, SerialNumbers) {
448 scoped_refptr<X509Certificate> paypal_null_cert(
449 X509Certificate::CreateFromBytes(
450 reinterpret_cast<const char*>(paypal_null_der),
451 sizeof(paypal_null_der)));
452
453 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert);
454
455 const SHA1Fingerprint& fingerprint =
456 paypal_null_cert->fingerprint();
457 for (size_t i = 0; i < 20; ++i)
458 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]);
459
460 int flags = 0;
461 CertVerifyResult verify_result;
462 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL,
463 &verify_result);
464 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN)
465 // TOOD(bulach): investigate why macosx and win aren't returning
466 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID.
467 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
468 #else
469 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
470 #endif
471 // Either the system crypto library should correctly report a certificate
472 // name mismatch, or our certificate blacklist should cause us to report an
473 // invalid certificate.
474 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL)
475 EXPECT_TRUE(verify_result.cert_status &
476 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID));
477 #endif
478 }
479
480 TEST_F(X509CertificateTest, SerialNumbers) {
481 scoped_refptr<X509Certificate> google_cert( 360 scoped_refptr<X509Certificate> google_cert(
482 X509Certificate::CreateFromBytes( 361 X509Certificate::CreateFromBytes(
483 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 362 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
484 363
485 static const uint8 google_serial[16] = { 364 static const uint8 google_serial[16] = {
486 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, 365 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9,
487 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, 366 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a,
488 }; 367 };
489 368
490 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); 369 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size());
491 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, 370 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial,
492 sizeof(google_serial)) == 0); 371 sizeof(google_serial)) == 0);
493 372
494 // We also want to check a serial number where the first byte is >= 0x80 in 373 // We also want to check a serial number where the first byte is >= 0x80 in
495 // case the underlying library tries to pad it. 374 // case the underlying library tries to pad it.
496 scoped_refptr<X509Certificate> paypal_null_cert( 375 scoped_refptr<X509Certificate> paypal_null_cert(
497 X509Certificate::CreateFromBytes( 376 X509Certificate::CreateFromBytes(
498 reinterpret_cast<const char*>(paypal_null_der), 377 reinterpret_cast<const char*>(paypal_null_der),
499 sizeof(paypal_null_der))); 378 sizeof(paypal_null_der)));
500 379
501 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; 380 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b};
502 ASSERT_EQ(sizeof(paypal_null_serial), 381 ASSERT_EQ(sizeof(paypal_null_serial),
503 paypal_null_cert->serial_number().size()); 382 paypal_null_cert->serial_number().size());
504 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), 383 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(),
505 paypal_null_serial, sizeof(paypal_null_serial)) == 0); 384 paypal_null_serial, sizeof(paypal_null_serial)) == 0);
506 } 385 }
507 386
508 TEST_F(X509CertificateTest, CAFingerprints) { 387 TEST(X509CertificateTest, CAFingerprints) {
509 FilePath certs_dir = GetTestCertsDirectory(); 388 FilePath certs_dir = GetTestCertsDirectory();
510 389
511 scoped_refptr<X509Certificate> server_cert = 390 scoped_refptr<X509Certificate> server_cert =
512 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); 391 ImportCertFromFile(certs_dir, "salesforce_com_test.pem");
513 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 392 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
514 393
515 scoped_refptr<X509Certificate> intermediate_cert1 = 394 scoped_refptr<X509Certificate> intermediate_cert1 =
516 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); 395 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem");
517 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); 396 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1);
518 397
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 431 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09
553 }; 432 };
554 EXPECT_TRUE(memcmp(cert_chain1->ca_fingerprint().data, 433 EXPECT_TRUE(memcmp(cert_chain1->ca_fingerprint().data,
555 cert_chain1_ca_fingerprint, 20) == 0); 434 cert_chain1_ca_fingerprint, 20) == 0);
556 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data, 435 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data,
557 cert_chain2_ca_fingerprint, 20) == 0); 436 cert_chain2_ca_fingerprint, 20) == 0);
558 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data, 437 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data,
559 cert_chain3_ca_fingerprint, 20) == 0); 438 cert_chain3_ca_fingerprint, 20) == 0);
560 } 439 }
561 440
562 // A regression test for http://crbug.com/31497. 441 TEST(X509CertificateTest, DigiNotarCerts) {
563 // This certificate will expire on 2012-04-08. The test will still
564 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test
565 // certificates for this unit test. http://crbug.com/111742
566 TEST_F(X509CertificateTest, IntermediateCARequireExplicitPolicy) {
567 FilePath certs_dir = GetTestCertsDirectory();
568
569 scoped_refptr<X509Certificate> server_cert =
570 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der");
571 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
572
573 // The intermediate CA certificate's policyConstraints extension has a
574 // requireExplicitPolicy field with SkipCerts=0.
575 scoped_refptr<X509Certificate> intermediate_cert =
576 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
577 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
578
579 FilePath root_cert_path = certs_dir.AppendASCII("dod_root_ca_2_cert.der");
580 TestRootCerts* root_certs = TestRootCerts::GetInstance();
581 ASSERT_TRUE(root_certs->AddFromFile(root_cert_path));
582
583 X509Certificate::OSCertHandles intermediates;
584 intermediates.push_back(intermediate_cert->os_cert_handle());
585 scoped_refptr<X509Certificate> cert_chain =
586 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
587 intermediates);
588
589 int flags = 0;
590 CertVerifyResult verify_result;
591 int error = Verify(cert_chain, "www.us.army.mil", flags, NULL,
592 &verify_result);
593 if (error == OK) {
594 EXPECT_EQ(0U, verify_result.cert_status);
595 } else {
596 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
597 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status);
598 }
599 root_certs->Clear();
600 }
601
602 // Test for bug 58437.
603 // This certificate will expire on 2011-12-21. The test will still
604 // pass if error == ERR_CERT_DATE_INVALID.
605 // This test is DISABLED because it appears that we cannot do
606 // certificate revocation checking when running all of the net unit tests.
607 // This test passes when run individually, but when run with all of the net
608 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is
609 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation
610 // status, i.e. that the revocation check is failing for some reason.
611 TEST_F(X509CertificateTest, DISABLED_GlobalSignR3EVTest) {
612 FilePath certs_dir = GetTestCertsDirectory();
613
614 scoped_refptr<X509Certificate> server_cert =
615 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem");
616 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
617
618 scoped_refptr<X509Certificate> intermediate_cert =
619 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem");
620 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
621
622 X509Certificate::OSCertHandles intermediates;
623 intermediates.push_back(intermediate_cert->os_cert_handle());
624 scoped_refptr<X509Certificate> cert_chain =
625 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
626 intermediates);
627
628 CertVerifyResult verify_result;
629 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED |
630 X509Certificate::VERIFY_EV_CERT;
631 int error = Verify(cert_chain, "2029.globalsign.com", flags, NULL,
632 &verify_result);
633 if (error == OK)
634 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV);
635 else
636 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
637 }
638
639 // Currently, only RSA and DSA keys are checked for weakness, and our example
640 // weak size is 768. These could change in the future.
641 //
642 // Note that this means there may be false negatives: keys for other
643 // algorithms and which are weak will pass this test.
644 static bool IsWeakKeyType(const std::string& key_type) {
645 size_t pos = key_type.find("-");
646 std::string size = key_type.substr(0, pos);
647 std::string type = key_type.substr(pos + 1);
648
649 if (type == "rsa" || type == "dsa")
650 return size == "768";
651
652 return false;
653 }
654
655 TEST_F(X509CertificateTest, RejectWeakKeys) {
656 FilePath certs_dir = GetTestCertsDirectory();
657 typedef std::vector<std::string> Strings;
658 Strings key_types;
659
660 // generate-weak-test-chains.sh currently has:
661 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa"
662 // We must use the same key types here. The filenames generated look like:
663 // 2048-rsa-ee-by-768-rsa-intermediate.pem
664 key_types.push_back("768-rsa");
665 key_types.push_back("1024-rsa");
666 key_types.push_back("2048-rsa");
667
668 bool use_ecdsa = true;
669 #if defined(OS_WIN)
670 use_ecdsa = base::win::GetVersion() > base::win::VERSION_XP;
671 #elif defined(OS_MACOSX)
672 use_ecdsa = base::mac::IsOSSnowLeopardOrLater();
673 #endif
674
675 if (use_ecdsa)
676 key_types.push_back("prime256v1-ecdsa");
677
678 // Add the root that signed the intermediates for this test.
679 scoped_refptr<X509Certificate> root_cert =
680 ImportCertFromFile(certs_dir, "2048-rsa-root.pem");
681 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
682 TestRootCerts::GetInstance()->Add(root_cert.get());
683
684 // Now test each chain.
685 for (Strings::const_iterator ee_type = key_types.begin();
686 ee_type != key_types.end(); ++ee_type) {
687 for (Strings::const_iterator signer_type = key_types.begin();
688 signer_type != key_types.end(); ++signer_type) {
689 std::string basename = *ee_type + "-ee-by-" + *signer_type +
690 "-intermediate.pem";
691 SCOPED_TRACE(basename);
692 scoped_refptr<X509Certificate> ee_cert =
693 ImportCertFromFile(certs_dir, basename);
694 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
695
696 basename = *signer_type + "-intermediate.pem";
697 scoped_refptr<X509Certificate> intermediate =
698 ImportCertFromFile(certs_dir, basename);
699 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate);
700
701 X509Certificate::OSCertHandles intermediates;
702 intermediates.push_back(intermediate->os_cert_handle());
703 scoped_refptr<X509Certificate> cert_chain =
704 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
705 intermediates);
706
707 CertVerifyResult verify_result;
708 int error = Verify(cert_chain, "127.0.0.1", 0, NULL, &verify_result);
709
710 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) {
711 EXPECT_NE(OK, error);
712 EXPECT_EQ(CERT_STATUS_WEAK_KEY,
713 verify_result.cert_status & CERT_STATUS_WEAK_KEY);
714 } else {
715 EXPECT_EQ(OK, error);
716 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY);
717 }
718 }
719 }
720
721 TestRootCerts::GetInstance()->Clear();
722 }
723
724 // Test for bug 108514.
725 // The certificate will expire on 2012-07-20. The test will still
726 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test
727 // certificates for this unit test. http://crbug.com/111730
728 TEST_F(X509CertificateTest, ExtraneousMD5RootCert) {
729 FilePath certs_dir = GetTestCertsDirectory();
730
731 scoped_refptr<X509Certificate> server_cert =
732 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem");
733 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
734
735 scoped_refptr<X509Certificate> intermediate_cert =
736 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem");
737 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
738
739 scoped_refptr<X509Certificate> md5_root_cert =
740 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem");
741 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert);
742
743 X509Certificate::OSCertHandles intermediates;
744 intermediates.push_back(intermediate_cert->os_cert_handle());
745 intermediates.push_back(md5_root_cert->os_cert_handle());
746 scoped_refptr<X509Certificate> cert_chain =
747 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
748 intermediates);
749
750 CertVerifyResult verify_result;
751 int flags = 0;
752 int error = Verify(cert_chain, "images.etrade.wallst.com", flags, NULL,
753 &verify_result);
754 if (error != OK)
755 EXPECT_EQ(ERR_CERT_DATE_INVALID, error);
756
757 EXPECT_FALSE(verify_result.has_md5);
758 EXPECT_FALSE(verify_result.has_md5_ca);
759 }
760
761 // Test for bug 94673.
762 TEST_F(X509CertificateTest, GoogleDigiNotarTest) {
763 FilePath certs_dir = GetTestCertsDirectory();
764
765 scoped_refptr<X509Certificate> server_cert =
766 ImportCertFromFile(certs_dir, "google_diginotar.pem");
767 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
768
769 scoped_refptr<X509Certificate> intermediate_cert =
770 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem");
771 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
772
773 X509Certificate::OSCertHandles intermediates;
774 intermediates.push_back(intermediate_cert->os_cert_handle());
775 scoped_refptr<X509Certificate> cert_chain =
776 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(),
777 intermediates);
778
779 CertVerifyResult verify_result;
780 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED;
781 int error = Verify(cert_chain, "mail.google.com", flags, NULL,
782 &verify_result);
783 EXPECT_NE(OK, error);
784
785 // Now turn off revocation checking. Certificate verification should still
786 // fail.
787 flags = 0;
788 error = Verify(cert_chain, "mail.google.com", flags, NULL, &verify_result);
789 EXPECT_NE(OK, error);
790 }
791
792 TEST_F(X509CertificateTest, DigiNotarCerts) {
793 static const char* const kDigiNotarFilenames[] = { 442 static const char* const kDigiNotarFilenames[] = {
794 "diginotar_root_ca.pem", 443 "diginotar_root_ca.pem",
795 "diginotar_cyber_ca.pem", 444 "diginotar_cyber_ca.pem",
796 "diginotar_services_1024_ca.pem", 445 "diginotar_services_1024_ca.pem",
797 "diginotar_pkioverheid.pem", 446 "diginotar_pkioverheid.pem",
798 "diginotar_pkioverheid_g2.pem", 447 "diginotar_pkioverheid_g2.pem",
799 NULL, 448 NULL,
800 }; 449 };
801 450
802 FilePath certs_dir = GetTestCertsDirectory(); 451 FilePath certs_dir = GetTestCertsDirectory();
(...skipping 14 matching lines...) Expand all
817 SHA1Fingerprint fingerprint; 466 SHA1Fingerprint fingerprint;
818 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); 467 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size());
819 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); 468 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size());
820 public_keys.push_back(fingerprint); 469 public_keys.push_back(fingerprint);
821 470
822 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) << 471 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) <<
823 "Public key not blocked for " << kDigiNotarFilenames[i]; 472 "Public key not blocked for " << kDigiNotarFilenames[i];
824 } 473 }
825 } 474 }
826 475
827 // Bug 111893: This test needs a new certificate. 476 TEST(X509CertificateTest, ExtractSPKIFromDERCert) {
828 TEST_F(X509CertificateTest, DISABLED_TestKnownRoot) {
829 FilePath certs_dir = GetTestCertsDirectory(); 477 FilePath certs_dir = GetTestCertsDirectory();
830 scoped_refptr<X509Certificate> cert = 478 scoped_refptr<X509Certificate> cert =
831 ImportCertFromFile(certs_dir, "nist.der"); 479 ImportCertFromFile(certs_dir, "nist.der");
832 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
833
834 // This intermediate is only needed for old Linux machines. Modern NSS
835 // includes it as a root already.
836 scoped_refptr<X509Certificate> intermediate_cert =
837 ImportCertFromFile(certs_dir, "nist_intermediate.der");
838 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
839
840 X509Certificate::OSCertHandles intermediates;
841 intermediates.push_back(intermediate_cert->os_cert_handle());
842 scoped_refptr<X509Certificate> cert_chain =
843 X509Certificate::CreateFromHandle(cert->os_cert_handle(),
844 intermediates);
845
846 int flags = 0;
847 CertVerifyResult verify_result;
848 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug
849 // against agl. Also see PublicKeyHashes in this file.
850 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result);
851 EXPECT_EQ(OK, error);
852 EXPECT_EQ(0U, verify_result.cert_status);
853 EXPECT_TRUE(verify_result.is_issued_by_known_root);
854 }
855
856 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der.
857 static const char nistSPKIHash[] =
858 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82"
859 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35";
860
861 TEST_F(X509CertificateTest, ExtractSPKIFromDERCert) {
862 FilePath certs_dir = GetTestCertsDirectory();
863 scoped_refptr<X509Certificate> cert =
864 ImportCertFromFile(certs_dir, "nist.der");
865 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 480 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
866 481
867 std::string derBytes; 482 std::string derBytes;
868 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 483 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
869 &derBytes)); 484 &derBytes));
870 485
871 base::StringPiece spkiBytes; 486 base::StringPiece spkiBytes;
872 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); 487 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes));
873 488
874 uint8 hash[base::kSHA1Length]; 489 uint8 hash[base::kSHA1Length];
875 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), 490 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()),
876 spkiBytes.size(), hash); 491 spkiBytes.size(), hash);
877 492
878 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash))); 493 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash)));
879 } 494 }
880 495
881 TEST_F(X509CertificateTest, ExtractCRLURLsFromDERCert) { 496 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) {
882 FilePath certs_dir = GetTestCertsDirectory(); 497 FilePath certs_dir = GetTestCertsDirectory();
883 scoped_refptr<X509Certificate> cert = 498 scoped_refptr<X509Certificate> cert =
884 ImportCertFromFile(certs_dir, "nist.der"); 499 ImportCertFromFile(certs_dir, "nist.der");
885 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 500 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
886 501
887 std::string derBytes; 502 std::string derBytes;
888 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 503 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
889 &derBytes)); 504 &derBytes));
890 505
891 std::vector<base::StringPiece> crl_urls; 506 std::vector<base::StringPiece> crl_urls;
892 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); 507 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls));
893 508
894 EXPECT_EQ(1u, crl_urls.size()); 509 EXPECT_EQ(1u, crl_urls.size());
895 if (crl_urls.size() > 0) { 510 if (crl_urls.size() > 0) {
896 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", 511 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl",
897 crl_urls[0].as_string()); 512 crl_urls[0].as_string());
898 } 513 }
899 } 514 }
900 515
901 // Bug 111893: This test needs a new certificate.
902 TEST_F(X509CertificateTest, DISABLED_PublicKeyHashes) {
903 FilePath certs_dir = GetTestCertsDirectory();
904 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug
905 // against agl. Also see TestKnownRoot in this file.
906 scoped_refptr<X509Certificate> cert =
907 ImportCertFromFile(certs_dir, "nist.der");
908 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
909
910 // This intermediate is only needed for old Linux machines. Modern NSS
911 // includes it as a root already.
912 scoped_refptr<X509Certificate> intermediate_cert =
913 ImportCertFromFile(certs_dir, "nist_intermediate.der");
914 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
915
916 TestRootCerts::GetInstance()->Add(intermediate_cert.get());
917
918 X509Certificate::OSCertHandles intermediates;
919 intermediates.push_back(intermediate_cert->os_cert_handle());
920 scoped_refptr<X509Certificate> cert_chain =
921 X509Certificate::CreateFromHandle(cert->os_cert_handle(),
922 intermediates);
923
924 int flags = 0;
925 CertVerifyResult verify_result;
926
927 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result);
928 EXPECT_EQ(OK, error);
929 EXPECT_EQ(0U, verify_result.cert_status);
930 ASSERT_LE(2u, verify_result.public_key_hashes.size());
931 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length),
932 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length));
933 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD",
934 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length));
935
936 TestRootCerts::GetInstance()->Clear();
937 }
938
939 // A regression test for http://crbug.com/70293.
940 // The Key Usage extension in this RSA SSL server certificate does not have
941 // the keyEncipherment bit.
942 TEST_F(X509CertificateTest, InvalidKeyUsage) {
943 FilePath certs_dir = GetTestCertsDirectory();
944
945 scoped_refptr<X509Certificate> server_cert =
946 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der");
947 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
948
949 int flags = 0;
950 CertVerifyResult verify_result;
951 int error = Verify(server_cert, "jira.aquameta.com", flags, NULL,
952 &verify_result);
953 #if defined(USE_OPENSSL)
954 // This certificate has two errors: "invalid key usage" and "untrusted CA".
955 // However, OpenSSL returns only one (the latter), and we can't detect
956 // the other errors.
957 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error);
958 #else
959 EXPECT_EQ(ERR_CERT_INVALID, error);
960 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID);
961 #endif
962 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors
963 // from NSS.
964 #if !defined(USE_NSS)
965 // The certificate is issued by an unknown CA.
966 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
967 #endif
968 }
969
970 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We 516 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We
971 // call X509Certificate::CreateFromHandle several times and observe whether 517 // call X509Certificate::CreateFromHandle several times and observe whether
972 // it returns a cached or new OSCertHandle. 518 // it returns a cached or new OSCertHandle.
973 TEST_F(X509CertificateTest, Cache) { 519 TEST(X509CertificateTest, Cache) {
974 X509Certificate::OSCertHandle google_cert_handle; 520 X509Certificate::OSCertHandle google_cert_handle;
975 X509Certificate::OSCertHandle thawte_cert_handle; 521 X509Certificate::OSCertHandle thawte_cert_handle;
976 522
977 // Add a single certificate to the certificate cache. 523 // Add a single certificate to the certificate cache.
978 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( 524 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes(
979 reinterpret_cast<const char*>(google_der), sizeof(google_der)); 525 reinterpret_cast<const char*>(google_der), sizeof(google_der));
980 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( 526 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle(
981 google_cert_handle, X509Certificate::OSCertHandles())); 527 google_cert_handle, X509Certificate::OSCertHandles()));
982 X509Certificate::FreeOSCertHandle(google_cert_handle); 528 X509Certificate::FreeOSCertHandle(google_cert_handle);
983 529
(...skipping 26 matching lines...) Expand all
1010 X509Certificate::FreeOSCertHandle(thawte_cert_handle); 556 X509Certificate::FreeOSCertHandle(thawte_cert_handle);
1011 557
1012 // Test that the new certificate, even with intermediates, results in the 558 // Test that the new certificate, even with intermediates, results in the
1013 // same underlying handle being used. 559 // same underlying handle being used.
1014 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle()); 560 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle());
1015 // Though they use the same OS handle, the intermediates should be different. 561 // Though they use the same OS handle, the intermediates should be different.
1016 EXPECT_NE(cert1->GetIntermediateCertificates().size(), 562 EXPECT_NE(cert1->GetIntermediateCertificates().size(),
1017 cert3->GetIntermediateCertificates().size()); 563 cert3->GetIntermediateCertificates().size());
1018 } 564 }
1019 565
1020 TEST_F(X509CertificateTest, Pickle) { 566 TEST(X509CertificateTest, Pickle) {
1021 X509Certificate::OSCertHandle google_cert_handle = 567 X509Certificate::OSCertHandle google_cert_handle =
1022 X509Certificate::CreateOSCertHandleFromBytes( 568 X509Certificate::CreateOSCertHandleFromBytes(
1023 reinterpret_cast<const char*>(google_der), sizeof(google_der)); 569 reinterpret_cast<const char*>(google_der), sizeof(google_der));
1024 X509Certificate::OSCertHandle thawte_cert_handle = 570 X509Certificate::OSCertHandle thawte_cert_handle =
1025 X509Certificate::CreateOSCertHandleFromBytes( 571 X509Certificate::CreateOSCertHandleFromBytes(
1026 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); 572 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der));
1027 573
1028 X509Certificate::OSCertHandles intermediates; 574 X509Certificate::OSCertHandles intermediates;
1029 intermediates.push_back(thawte_cert_handle); 575 intermediates.push_back(thawte_cert_handle);
1030 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( 576 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
(...skipping 17 matching lines...) Expand all
1048 cert->GetIntermediateCertificates(); 594 cert->GetIntermediateCertificates();
1049 const X509Certificate::OSCertHandles& pickle_intermediates = 595 const X509Certificate::OSCertHandles& pickle_intermediates =
1050 cert_from_pickle->GetIntermediateCertificates(); 596 cert_from_pickle->GetIntermediateCertificates();
1051 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size()); 597 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size());
1052 for (size_t i = 0; i < cert_intermediates.size(); ++i) { 598 for (size_t i = 0; i < cert_intermediates.size(); ++i) {
1053 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i], 599 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i],
1054 pickle_intermediates[i])); 600 pickle_intermediates[i]));
1055 } 601 }
1056 } 602 }
1057 603
1058 TEST_F(X509CertificateTest, Policy) { 604 TEST(X509CertificateTest, Policy) {
1059 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( 605 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes(
1060 reinterpret_cast<const char*>(google_der), sizeof(google_der))); 606 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
1061 607
1062 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( 608 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes(
1063 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 609 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
1064 610
1065 CertPolicy policy; 611 CertPolicy policy;
1066 612
1067 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); 613 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN);
1068 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); 614 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN);
(...skipping 15 matching lines...) Expand all
1084 EXPECT_TRUE(policy.HasDeniedCert()); 630 EXPECT_TRUE(policy.HasDeniedCert());
1085 631
1086 policy.Allow(webkit_cert.get()); 632 policy.Allow(webkit_cert.get());
1087 633
1088 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); 634 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED);
1089 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); 635 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED);
1090 EXPECT_TRUE(policy.HasAllowedCert()); 636 EXPECT_TRUE(policy.HasAllowedCert());
1091 EXPECT_TRUE(policy.HasDeniedCert()); 637 EXPECT_TRUE(policy.HasDeniedCert());
1092 } 638 }
1093 639
1094 TEST_F(X509CertificateTest, IntermediateCertificates) { 640 TEST(X509CertificateTest, IntermediateCertificates) {
1095 scoped_refptr<X509Certificate> webkit_cert( 641 scoped_refptr<X509Certificate> webkit_cert(
1096 X509Certificate::CreateFromBytes( 642 X509Certificate::CreateFromBytes(
1097 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 643 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
1098 644
1099 scoped_refptr<X509Certificate> thawte_cert( 645 scoped_refptr<X509Certificate> thawte_cert(
1100 X509Certificate::CreateFromBytes( 646 X509Certificate::CreateFromBytes(
1101 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); 647 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)));
1102 648
1103 X509Certificate::OSCertHandle google_handle; 649 X509Certificate::OSCertHandle google_handle;
1104 // Create object with no intermediates: 650 // Create object with no intermediates:
(...skipping 17 matching lines...) Expand all
1122 ASSERT_EQ(2u, cert2_intermediates.size()); 668 ASSERT_EQ(2u, cert2_intermediates.size());
1123 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0], 669 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0],
1124 webkit_cert->os_cert_handle())); 670 webkit_cert->os_cert_handle()));
1125 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1], 671 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1],
1126 thawte_cert->os_cert_handle())); 672 thawte_cert->os_cert_handle()));
1127 673
1128 // Cleanup 674 // Cleanup
1129 X509Certificate::FreeOSCertHandle(google_handle); 675 X509Certificate::FreeOSCertHandle(google_handle);
1130 } 676 }
1131 677
1132 // Basic test for returning the chain in CertVerifyResult. Note that the
1133 // returned chain may just be a reflection of the originally supplied chain;
1134 // that is, if any errors occur, the default chain returned is an exact copy
1135 // of the certificate to be verified. The remaining VerifyReturn* tests are
1136 // used to ensure that the actual, verified chain is being returned by
1137 // Verify().
1138 TEST_F(X509CertificateTest, VerifyReturnChainBasic) {
1139 FilePath certs_dir = GetTestCertsDirectory();
1140 CertificateList certs = CreateCertificateListFromFile(
1141 certs_dir, "x509_verify_results.chain.pem",
1142 X509Certificate::FORMAT_AUTO);
1143 ASSERT_EQ(3U, certs.size());
1144
1145 X509Certificate::OSCertHandles intermediates;
1146 intermediates.push_back(certs[1]->os_cert_handle());
1147 intermediates.push_back(certs[2]->os_cert_handle());
1148
1149 TestRootCerts::GetInstance()->Add(certs[2]);
1150
1151 scoped_refptr<X509Certificate> google_full_chain =
1152 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1153 intermediates);
1154 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1155 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1156
1157 CertVerifyResult verify_result;
1158 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1159 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1160 EXPECT_EQ(OK, error);
1161 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1162
1163 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1164 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1165 google_full_chain->os_cert_handle(),
1166 verify_result.verified_cert->os_cert_handle()));
1167 const X509Certificate::OSCertHandles& return_intermediates =
1168 verify_result.verified_cert->GetIntermediateCertificates();
1169 ASSERT_EQ(2U, return_intermediates.size());
1170 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1171 certs[1]->os_cert_handle()));
1172 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1173 certs[2]->os_cert_handle()));
1174
1175 TestRootCerts::GetInstance()->Clear();
1176 }
1177
1178 // Test that the certificate returned in CertVerifyResult is able to reorder
1179 // certificates that are not ordered from end-entity to root. While this is
1180 // a protocol violation if sent during a TLS handshake, if multiple sources
1181 // of intermediate certificates are combined, it's possible that order may
1182 // not be maintained.
1183 TEST_F(X509CertificateTest, VerifyReturnChainProperlyOrdered) {
1184 FilePath certs_dir = GetTestCertsDirectory();
1185 CertificateList certs = CreateCertificateListFromFile(
1186 certs_dir, "x509_verify_results.chain.pem",
1187 X509Certificate::FORMAT_AUTO);
1188 ASSERT_EQ(3U, certs.size());
1189
1190 // Construct the chain out of order.
1191 X509Certificate::OSCertHandles intermediates;
1192 intermediates.push_back(certs[2]->os_cert_handle());
1193 intermediates.push_back(certs[1]->os_cert_handle());
1194
1195 TestRootCerts::GetInstance()->Add(certs[2]);
1196
1197 scoped_refptr<X509Certificate> google_full_chain =
1198 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1199 intermediates);
1200 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1201 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size());
1202
1203 CertVerifyResult verify_result;
1204 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1205 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1206 EXPECT_EQ(OK, error);
1207 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1208
1209 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1210 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1211 google_full_chain->os_cert_handle(),
1212 verify_result.verified_cert->os_cert_handle()));
1213 const X509Certificate::OSCertHandles& return_intermediates =
1214 verify_result.verified_cert->GetIntermediateCertificates();
1215 ASSERT_EQ(2U, return_intermediates.size());
1216 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1217 certs[1]->os_cert_handle()));
1218 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1219 certs[2]->os_cert_handle()));
1220
1221 TestRootCerts::GetInstance()->Clear();
1222 }
1223
1224 // Test that Verify() filters out certificates which are not related to
1225 // or part of the certificate chain being verified.
1226 TEST_F(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) {
1227 FilePath certs_dir = GetTestCertsDirectory();
1228 CertificateList certs = CreateCertificateListFromFile(
1229 certs_dir, "x509_verify_results.chain.pem",
1230 X509Certificate::FORMAT_AUTO);
1231 ASSERT_EQ(3U, certs.size());
1232 TestRootCerts::GetInstance()->Add(certs[2]);
1233
1234 scoped_refptr<X509Certificate> unrelated_dod_certificate =
1235 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der");
1236 scoped_refptr<X509Certificate> unrelated_dod_certificate2 =
1237 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
1238 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate);
1239 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2);
1240
1241 // Interject unrelated certificates into the list of intermediates.
1242 X509Certificate::OSCertHandles intermediates;
1243 intermediates.push_back(unrelated_dod_certificate->os_cert_handle());
1244 intermediates.push_back(certs[1]->os_cert_handle());
1245 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle());
1246 intermediates.push_back(certs[2]->os_cert_handle());
1247
1248 scoped_refptr<X509Certificate> google_full_chain =
1249 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1250 intermediates);
1251 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain);
1252 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size());
1253
1254 CertVerifyResult verify_result;
1255 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1256 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result);
1257 EXPECT_EQ(OK, error);
1258 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert);
1259
1260 EXPECT_NE(google_full_chain, verify_result.verified_cert);
1261 EXPECT_TRUE(X509Certificate::IsSameOSCert(
1262 google_full_chain->os_cert_handle(),
1263 verify_result.verified_cert->os_cert_handle()));
1264 const X509Certificate::OSCertHandles& return_intermediates =
1265 verify_result.verified_cert->GetIntermediateCertificates();
1266 ASSERT_EQ(2U, return_intermediates.size());
1267 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0],
1268 certs[1]->os_cert_handle()));
1269 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1],
1270 certs[2]->os_cert_handle()));
1271 TestRootCerts::GetInstance()->Clear();
1272 }
1273
1274 #if defined(OS_MACOSX) 678 #if defined(OS_MACOSX)
1275 TEST_F(X509CertificateTest, IsIssuedBy) { 679 TEST(X509CertificateTest, IsIssuedBy) {
1276 FilePath certs_dir = GetTestCertsDirectory(); 680 FilePath certs_dir = GetTestCertsDirectory();
1277 681
1278 // Test a client certificate from MIT. 682 // Test a client certificate from MIT.
1279 scoped_refptr<X509Certificate> mit_davidben_cert( 683 scoped_refptr<X509Certificate> mit_davidben_cert(
1280 ImportCertFromFile(certs_dir, "mit.davidben.der")); 684 ImportCertFromFile(certs_dir, "mit.davidben.der"));
1281 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); 685 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert);
1282 686
1283 CertPrincipal mit_issuer; 687 CertPrincipal mit_issuer;
1284 mit_issuer.country_name = "US"; 688 mit_issuer.country_name = "US";
1285 mit_issuer.state_or_province_name = "Massachusetts"; 689 mit_issuer.state_or_province_name = "Massachusetts";
(...skipping 28 matching lines...) Expand all
1314 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); 718 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers));
1315 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 719 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
1316 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 720 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
1317 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 721 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
1318 } 722 }
1319 #endif // defined(OS_MACOSX) 723 #endif // defined(OS_MACOSX)
1320 724
1321 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 725 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
1322 // This test creates a self-signed cert from a private key and then verify the 726 // This test creates a self-signed cert from a private key and then verify the
1323 // content of the certificate. 727 // content of the certificate.
1324 TEST_F(X509CertificateTest, CreateSelfSigned) { 728 TEST(X509CertificateTest, CreateSelfSigned) {
1325 scoped_ptr<crypto::RSAPrivateKey> private_key( 729 scoped_ptr<crypto::RSAPrivateKey> private_key(
1326 crypto::RSAPrivateKey::Create(1024)); 730 crypto::RSAPrivateKey::Create(1024));
1327 scoped_refptr<X509Certificate> cert = 731 scoped_refptr<X509Certificate> cert =
1328 X509Certificate::CreateSelfSigned( 732 X509Certificate::CreateSelfSigned(
1329 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 733 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
1330 734
1331 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 735 EXPECT_EQ("subject", cert->subject().GetDisplayName());
1332 EXPECT_FALSE(cert->HasExpired()); 736 EXPECT_FALSE(cert->HasExpired());
1333 737
1334 const uint8 private_key_info[] = { 738 const uint8 private_key_info[] = {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); 825 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
1422 ASSERT_TRUE(private_key.get()); 826 ASSERT_TRUE(private_key.get());
1423 827
1424 cert = X509Certificate::CreateSelfSigned( 828 cert = X509Certificate::CreateSelfSigned(
1425 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 829 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
1426 830
1427 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 831 EXPECT_EQ("subject", cert->subject().GetDisplayName());
1428 EXPECT_FALSE(cert->HasExpired()); 832 EXPECT_FALSE(cert->HasExpired());
1429 } 833 }
1430 834
1431 TEST_F(X509CertificateTest, GetDEREncoded) { 835 TEST(X509CertificateTest, GetDEREncoded) {
1432 scoped_ptr<crypto::RSAPrivateKey> private_key( 836 scoped_ptr<crypto::RSAPrivateKey> private_key(
1433 crypto::RSAPrivateKey::Create(1024)); 837 crypto::RSAPrivateKey::Create(1024));
1434 scoped_refptr<X509Certificate> cert = 838 scoped_refptr<X509Certificate> cert =
1435 X509Certificate::CreateSelfSigned( 839 X509Certificate::CreateSelfSigned(
1436 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 840 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
1437 841
1438 std::string der_cert; 842 std::string der_cert;
1439 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 843 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
1440 &der_cert)); 844 &der_cert));
1441 EXPECT_FALSE(der_cert.empty()); 845 EXPECT_FALSE(der_cert.empty());
1442 } 846 }
1443 #endif 847 #endif
1444 848
1445 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
1446 static const uint8 kCRLSetThawteSPKIBlocked[] = {
1447 0x8e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
1448 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
1449 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
1450 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
1451 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
1452 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
1453 0x30, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1454 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x36, 0x58, 0x36, 0x4d, 0x78, 0x52, 0x37,
1455 0x58, 0x70, 0x4d, 0x51, 0x4b, 0x78, 0x49, 0x41, 0x39, 0x50, 0x6a, 0x36, 0x37,
1456 0x36, 0x38, 0x76, 0x74, 0x55, 0x6b, 0x6b, 0x7a, 0x48, 0x79, 0x7a, 0x41, 0x6f,
1457 0x6d, 0x6f, 0x4f, 0x68, 0x4b, 0x55, 0x6e, 0x7a, 0x73, 0x55, 0x3d, 0x22, 0x5d,
1458 0x7d,
1459 };
1460
1461 static const uint8 kCRLSetThawteSerialBlocked[] = {
1462 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
1463 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
1464 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
1465 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
1466 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
1467 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
1468 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1469 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xb1, 0x12, 0x41, 0x42, 0xa5, 0xa1,
1470 0xa5, 0xa2, 0x88, 0x19, 0xc7, 0x35, 0x34, 0x0e, 0xff, 0x8c, 0x9e, 0x2f, 0x81,
1471 0x68, 0xfe, 0xe3, 0xba, 0x18, 0x7f, 0x25, 0x3b, 0xc1, 0xa3, 0x92, 0xd7, 0xe2,
1472 // Note that this is actually blocking two serial numbers because on XP and
1473 // Vista, CryptoAPI finds a different Thawte certificate.
1474 0x02, 0x00, 0x00, 0x00,
1475 0x04, 0x30, 0x00, 0x00, 0x02,
1476 0x04, 0x30, 0x00, 0x00, 0x06,
1477 };
1478
1479 static const uint8 kCRLSetGoogleSerialBlocked[] = {
1480 0x60, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
1481 0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
1482 0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
1483 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
1484 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
1485 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
1486 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b,
1487 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7,
1488 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52,
1489 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5,
1490 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b,
1491 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d,
1492 };
1493
1494 // Test that CRLSets are effective in making a certificate appear to be
1495 // revoked.
1496 TEST_F(X509CertificateTest, CRLSet) {
1497 CertificateList certs = CreateCertificateListFromFile(
1498 GetTestCertsDirectory(),
1499 "googlenew.chain.pem",
1500 X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
1501
1502 X509Certificate::OSCertHandles intermediates;
1503 intermediates.push_back(certs[1]->os_cert_handle());
1504
1505 scoped_refptr<X509Certificate> google_full_chain =
1506 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(),
1507 intermediates);
1508
1509 CertVerifyResult verify_result;
1510 int error = Verify(google_full_chain, "www.google.com", 0, NULL,
1511 &verify_result);
1512 EXPECT_EQ(OK, error);
1513
1514 // First test blocking by SPKI.
1515 base::StringPiece crl_set_bytes(
1516 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked),
1517 sizeof(kCRLSetThawteSPKIBlocked));
1518 scoped_refptr<CRLSet> crl_set;
1519 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1520
1521 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1522 &verify_result);
1523 EXPECT_EQ(ERR_CERT_REVOKED, error);
1524
1525 // Second, test revocation by serial number of a cert directly under the
1526 // root.
1527 crl_set_bytes = base::StringPiece(
1528 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked),
1529 sizeof(kCRLSetThawteSerialBlocked));
1530 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1531
1532 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1533 &verify_result);
1534 EXPECT_EQ(ERR_CERT_REVOKED, error);
1535
1536 // Lastly, test revocation by serial number of a certificate not under the
1537 // root.
1538 crl_set_bytes = base::StringPiece(
1539 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked),
1540 sizeof(kCRLSetGoogleSerialBlocked));
1541 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set));
1542
1543 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(),
1544 &verify_result);
1545 EXPECT_EQ(ERR_CERT_REVOKED, error);
1546 }
1547 #endif
1548
1549 class X509CertificateParseTest 849 class X509CertificateParseTest
1550 : public testing::TestWithParam<CertificateFormatTestData> { 850 : public testing::TestWithParam<CertificateFormatTestData> {
1551 public: 851 public:
1552 virtual ~X509CertificateParseTest() {} 852 virtual ~X509CertificateParseTest() {}
1553 virtual void SetUp() { 853 virtual void SetUp() {
1554 test_data_ = GetParam(); 854 test_data_ = GetParam();
1555 } 855 }
1556 virtual void TearDown() {} 856 virtual void TearDown() {}
1557 857
1558 protected: 858 protected:
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 } 1099 }
1800 } 1100 }
1801 1101
1802 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1102 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1803 test_data.hostname, common_name, dns_names, ip_addressses)); 1103 test_data.hostname, common_name, dns_names, ip_addressses));
1804 } 1104 }
1805 1105
1806 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1106 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1807 testing::ValuesIn(kNameVerifyTestData)); 1107 testing::ValuesIn(kNameVerifyTestData));
1808 1108
1809 struct WeakDigestTestData {
1810 const char* root_cert_filename;
1811 const char* intermediate_cert_filename;
1812 const char* ee_cert_filename;
1813 bool expected_has_md5;
1814 bool expected_has_md4;
1815 bool expected_has_md2;
1816 bool expected_has_md5_ca;
1817 bool expected_has_md2_ca;
1818 };
1819
1820 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how
1821 // to output the parameter that was passed. Without this, it will simply
1822 // attempt to print out the first twenty bytes of the object, which depending
1823 // on platform and alignment, may result in an invalid read.
1824 void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
1825 *os << "root: "
1826 << (data.root_cert_filename ? data.root_cert_filename : "none")
1827 << "; intermediate: " << data.intermediate_cert_filename
1828 << "; end-entity: " << data.ee_cert_filename;
1829 }
1830
1831 class X509CertificateWeakDigestTest
1832 : public X509CertificateTest,
1833 public testing::WithParamInterface<WeakDigestTestData> {
1834 public:
1835 X509CertificateWeakDigestTest() {}
1836
1837 virtual void TearDown() {
1838 TestRootCerts::GetInstance()->Clear();
1839 }
1840 };
1841
1842 TEST_P(X509CertificateWeakDigestTest, Verify) {
1843 WeakDigestTestData data = GetParam();
1844 FilePath certs_dir = GetTestCertsDirectory();
1845
1846 if (data.root_cert_filename) {
1847 scoped_refptr<X509Certificate> root_cert =
1848 ImportCertFromFile(certs_dir, data.root_cert_filename);
1849 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
1850 TestRootCerts::GetInstance()->Add(root_cert.get());
1851 }
1852
1853 scoped_refptr<X509Certificate> intermediate_cert =
1854 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1855 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
1856 scoped_refptr<X509Certificate> ee_cert =
1857 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1858 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
1859
1860 X509Certificate::OSCertHandles intermediates;
1861 intermediates.push_back(intermediate_cert->os_cert_handle());
1862
1863 scoped_refptr<X509Certificate> ee_chain =
1864 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
1865 intermediates);
1866 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain);
1867
1868 int flags = 0;
1869 CertVerifyResult verify_result;
1870 int rv = Verify(ee_chain, "127.0.0.1", flags, NULL, &verify_result);
1871 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5);
1872 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4);
1873 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2);
1874 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca);
1875 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca);
1876
1877 // Ensure that MD4 and MD2 are tagged as invalid.
1878 if (data.expected_has_md4 || data.expected_has_md2) {
1879 EXPECT_EQ(CERT_STATUS_INVALID,
1880 verify_result.cert_status & CERT_STATUS_INVALID);
1881 }
1882
1883 // Ensure that MD5 is flagged as weak.
1884 if (data.expected_has_md5) {
1885 EXPECT_EQ(
1886 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM,
1887 verify_result.cert_status & CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
1888 }
1889
1890 // If a root cert is present, then check that the chain was rejected if any
1891 // weak algorithms are present. This is only checked when a root cert is
1892 // present because the error reported for incomplete chains with weak
1893 // algorithms depends on which implementation was used to validate (NSS,
1894 // OpenSSL, CryptoAPI, Security.framework) and upon which weak algorithm
1895 // present (MD2, MD4, MD5).
1896 if (data.root_cert_filename) {
1897 if (data.expected_has_md4 || data.expected_has_md2) {
1898 EXPECT_EQ(ERR_CERT_INVALID, rv);
1899 } else if (data.expected_has_md5) {
1900 EXPECT_EQ(ERR_CERT_WEAK_SIGNATURE_ALGORITHM, rv);
1901 } else {
1902 EXPECT_EQ(OK, rv);
1903 }
1904 }
1905 }
1906
1907 // Unlike TEST/TEST_F, which are macros that expand to further macros,
1908 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
1909 // stringizes the arguments. As a result, macros passed as parameters (such as
1910 // prefix or test_case_name) will not be expanded by the preprocessor. To work
1911 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
1912 // pre-processor will expand macros such as MAYBE_test_name before
1913 // instantiating the test.
1914 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
1915 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
1916
1917 // The signature algorithm of the root CA should not matter.
1918 const WeakDigestTestData kVerifyRootCATestData[] = {
1919 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem",
1920 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1921 #if !defined(OS_MACOSX) // MD4 is not supported.
1922 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem",
1923 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1924 #endif
1925 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem",
1926 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1927 };
1928 INSTANTIATE_TEST_CASE_P(VerifyRoot, X509CertificateWeakDigestTest,
1929 testing::ValuesIn(kVerifyRootCATestData));
1930
1931 // The signature algorithm of intermediates should be properly detected.
1932 const WeakDigestTestData kVerifyIntermediateCATestData[] = {
1933 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1934 "weak_digest_sha1_ee.pem", true, false, false, true, false },
1935 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported.
1936 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1937 "weak_digest_sha1_ee.pem", false, true, false, false, false },
1938 #endif
1939 #if !defined(USE_NSS) // MD2 is disabled by default.
1940 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1941 "weak_digest_sha1_ee.pem", false, false, true, false, true },
1942 #endif
1943 };
1944 INSTANTIATE_TEST_CASE_P(VerifyIntermediate, X509CertificateWeakDigestTest,
1945 testing::ValuesIn(kVerifyIntermediateCATestData));
1946
1947 // The signature algorithm of end-entity should be properly detected.
1948 const WeakDigestTestData kVerifyEndEntityTestData[] = {
1949 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1950 "weak_digest_md5_ee.pem", true, false, false, false, false },
1951 #if !defined(USE_NSS) && !defined(OS_MACOSX) // MD4 is not supported.
1952 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1953 "weak_digest_md4_ee.pem", false, true, false, false, false },
1954 #endif
1955 #if !defined(USE_NSS) // MD2 is disabled by default.
1956 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1957 "weak_digest_md2_ee.pem", false, false, true, false, false },
1958 #endif
1959 };
1960 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot
1961 // be cleared until NSS is cleanly shutdown, which is not presently supported
1962 // in Chromium.
1963 #if defined(USE_NSS)
1964 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity
1965 #else
1966 #define MAYBE_VerifyEndEntity VerifyEndEntity
1967 #endif
1968 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity,
1969 X509CertificateWeakDigestTest,
1970 testing::ValuesIn(kVerifyEndEntityTestData));
1971
1972 // Incomplete chains should still report the status of the intermediate.
1973 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = {
1974 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem",
1975 true, false, false, true, false },
1976 #if !defined(OS_MACOSX) // MD4 is not supported.
1977 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem",
1978 false, true, false, false, false },
1979 #endif
1980 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem",
1981 false, false, true, false, true },
1982 };
1983 // Disabled on NSS - libpkix does not return constructed chains on error,
1984 // preventing us from detecting/inspecting the verified chain.
1985 #if defined(USE_NSS)
1986 #define MAYBE_VerifyIncompleteIntermediate \
1987 DISABLED_VerifyIncompleteIntermediate
1988 #else
1989 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate
1990 #endif
1991 WRAPPED_INSTANTIATE_TEST_CASE_P(
1992 MAYBE_VerifyIncompleteIntermediate,
1993 X509CertificateWeakDigestTest,
1994 testing::ValuesIn(kVerifyIncompleteIntermediateTestData));
1995
1996 // Incomplete chains should still report the status of the end-entity.
1997 const WeakDigestTestData kVerifyIncompleteEETestData[] = {
1998 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem",
1999 true, false, false, false, false },
2000 #if !defined(OS_MACOSX) // MD4 is not supported.
2001 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem",
2002 false, true, false, false, false },
2003 #endif
2004 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem",
2005 false, false, true, false, false },
2006 };
2007 // Disabled on NSS - libpkix does not return constructed chains on error,
2008 // preventing us from detecting/inspecting the verified chain.
2009 #if defined(USE_NSS)
2010 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity
2011 #else
2012 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity
2013 #endif
2014 WRAPPED_INSTANTIATE_TEST_CASE_P(
2015 MAYBE_VerifyIncompleteEndEntity,
2016 X509CertificateWeakDigestTest,
2017 testing::ValuesIn(kVerifyIncompleteEETestData));
2018
2019 // Differing algorithms between the intermediate and the EE should still be
2020 // reported.
2021 const WeakDigestTestData kVerifyMixedTestData[] = {
2022 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
2023 "weak_digest_md2_ee.pem", true, false, true, true, false },
2024 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
2025 "weak_digest_md5_ee.pem", true, false, true, false, true },
2026 #if !defined(OS_MACOSX) // MD4 is not supported.
2027 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
2028 "weak_digest_md2_ee.pem", false, true, true, false, false },
2029 #endif
2030 };
2031 // NSS does not support MD4 and does not enable MD2 by default, making all
2032 // permutations invalid.
2033 #if defined(USE_NSS)
2034 #define MAYBE_VerifyMixed DISABLED_VerifyMixed
2035 #else
2036 #define MAYBE_VerifyMixed VerifyMixed
2037 #endif
2038 WRAPPED_INSTANTIATE_TEST_CASE_P(
2039 MAYBE_VerifyMixed,
2040 X509CertificateWeakDigestTest,
2041 testing::ValuesIn(kVerifyMixedTestData));
2042
2043 } // namespace net 1109 } // namespace net
OLDNEW
« net/base/test_certificate_data.h ('K') | « net/base/x509_certificate.h ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698