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