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/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); | 205 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); |
206 for (size_t i = 0; i < 20; ++i) | 206 for (size_t i = 0; i < 20; ++i) |
207 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); | 207 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); |
208 | 208 |
209 std::vector<std::string> dns_names; | 209 std::vector<std::string> dns_names; |
210 google_cert->GetDNSNames(&dns_names); | 210 google_cert->GetDNSNames(&dns_names); |
211 ASSERT_EQ(1U, dns_names.size()); | 211 ASSERT_EQ(1U, dns_names.size()); |
212 EXPECT_EQ("www.google.com", dns_names[0]); | 212 EXPECT_EQ("www.google.com", dns_names[0]); |
213 } | 213 } |
214 | 214 |
215 TEST(X509CertificateTest, GoogleCertParsing) { | 215 // TODO(rsleevi): Temporary fixture while refactoring http://crbug.com/114343 |
| 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) { |
216 scoped_refptr<X509Certificate> google_cert( | 232 scoped_refptr<X509Certificate> google_cert( |
217 X509Certificate::CreateFromBytes( | 233 X509Certificate::CreateFromBytes( |
218 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 234 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
219 | 235 |
220 CheckGoogleCert(google_cert, google_fingerprint, | 236 CheckGoogleCert(google_cert, google_fingerprint, |
221 1238192407, // Mar 27 22:20:07 2009 GMT | 237 1238192407, // Mar 27 22:20:07 2009 GMT |
222 1269728407); // Mar 27 22:20:07 2010 GMT | 238 1269728407); // Mar 27 22:20:07 2010 GMT |
223 } | 239 } |
224 | 240 |
225 TEST(X509CertificateTest, WebkitCertParsing) { | 241 TEST_F(X509CertificateTest, WebkitCertParsing) { |
226 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( | 242 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
227 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 243 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
228 | 244 |
229 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); | 245 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); |
230 | 246 |
231 const CertPrincipal& subject = webkit_cert->subject(); | 247 const CertPrincipal& subject = webkit_cert->subject(); |
232 EXPECT_EQ("Cupertino", subject.locality_name); | 248 EXPECT_EQ("Cupertino", subject.locality_name); |
233 EXPECT_EQ("California", subject.state_or_province_name); | 249 EXPECT_EQ("California", subject.state_or_province_name); |
234 EXPECT_EQ("US", subject.country_name); | 250 EXPECT_EQ("US", subject.country_name); |
235 EXPECT_EQ(0U, subject.street_addresses.size()); | 251 EXPECT_EQ(0U, subject.street_addresses.size()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 EXPECT_EQ("webkit.org", dns_names[1]); | 286 EXPECT_EQ("webkit.org", dns_names[1]); |
271 | 287 |
272 // Test that the wildcard cert matches properly. | 288 // Test that the wildcard cert matches properly. |
273 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); | 289 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); |
274 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); | 290 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); |
275 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); | 291 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); |
276 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); | 292 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); |
277 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); | 293 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); |
278 } | 294 } |
279 | 295 |
280 TEST(X509CertificateTest, WithoutRevocationChecking) { | 296 TEST_F(X509CertificateTest, WithoutRevocationChecking) { |
281 // Check that verification without revocation checking works. | 297 // Check that verification without revocation checking works. |
282 CertificateList certs = CreateCertificateListFromFile( | 298 CertificateList certs = CreateCertificateListFromFile( |
283 GetTestCertsDirectory(), | 299 GetTestCertsDirectory(), |
284 "googlenew.chain.pem", | 300 "googlenew.chain.pem", |
285 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 301 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
286 | 302 |
287 X509Certificate::OSCertHandles intermediates; | 303 X509Certificate::OSCertHandles intermediates; |
288 intermediates.push_back(certs[1]->os_cert_handle()); | 304 intermediates.push_back(certs[1]->os_cert_handle()); |
289 | 305 |
290 scoped_refptr<X509Certificate> google_full_chain = | 306 scoped_refptr<X509Certificate> google_full_chain = |
291 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 307 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
292 intermediates); | 308 intermediates); |
293 | 309 |
294 CertVerifyResult verify_result; | 310 CertVerifyResult verify_result; |
295 EXPECT_EQ(OK, google_full_chain->Verify("www.google.com", 0 /* flags */, NULL, | 311 EXPECT_EQ(OK, Verify(google_full_chain, "www.google.com", 0 /* flags */, NULL, |
296 &verify_result)); | 312 &verify_result)); |
297 } | 313 } |
298 | 314 |
299 TEST(X509CertificateTest, ThawteCertParsing) { | 315 TEST_F(X509CertificateTest, ThawteCertParsing) { |
300 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( | 316 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( |
301 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); | 317 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
302 | 318 |
303 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); | 319 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); |
304 | 320 |
305 const CertPrincipal& subject = thawte_cert->subject(); | 321 const CertPrincipal& subject = thawte_cert->subject(); |
306 EXPECT_EQ("www.thawte.com", subject.common_name); | 322 EXPECT_EQ("www.thawte.com", subject.common_name); |
307 EXPECT_EQ("Mountain View", subject.locality_name); | 323 EXPECT_EQ("Mountain View", subject.locality_name); |
308 EXPECT_EQ("California", subject.state_or_province_name); | 324 EXPECT_EQ("California", subject.state_or_province_name); |
309 EXPECT_EQ("US", subject.country_name); | 325 EXPECT_EQ("US", subject.country_name); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 ASSERT_EQ(1U, dns_names.size()); | 358 ASSERT_EQ(1U, dns_names.size()); |
343 EXPECT_EQ("www.thawte.com", dns_names[0]); | 359 EXPECT_EQ("www.thawte.com", dns_names[0]); |
344 } | 360 } |
345 | 361 |
346 #if defined(OS_ANDROID) || defined(USE_OPENSSL) | 362 #if defined(OS_ANDROID) || defined(USE_OPENSSL) |
347 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. | 363 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. |
348 #define MAYBE_EVVerification DISABLED_EVVerification | 364 #define MAYBE_EVVerification DISABLED_EVVerification |
349 #else | 365 #else |
350 #define MAYBE_EVVerification EVVerification | 366 #define MAYBE_EVVerification EVVerification |
351 #endif | 367 #endif |
352 TEST(X509CertificateTest, MAYBE_EVVerification) { | 368 TEST_F(X509CertificateTest, MAYBE_EVVerification) { |
353 // This certificate will expire Jun 21, 2013. | 369 // This certificate will expire Jun 21, 2013. |
354 CertificateList certs = CreateCertificateListFromFile( | 370 CertificateList certs = CreateCertificateListFromFile( |
355 GetTestCertsDirectory(), | 371 GetTestCertsDirectory(), |
356 "comodo.chain.pem", | 372 "comodo.chain.pem", |
357 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 373 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
358 ASSERT_EQ(3U, certs.size()); | 374 ASSERT_EQ(3U, certs.size()); |
359 | 375 |
360 X509Certificate::OSCertHandles intermediates; | 376 X509Certificate::OSCertHandles intermediates; |
361 intermediates.push_back(certs[1]->os_cert_handle()); | 377 intermediates.push_back(certs[1]->os_cert_handle()); |
362 intermediates.push_back(certs[2]->os_cert_handle()); | 378 intermediates.push_back(certs[2]->os_cert_handle()); |
363 | 379 |
364 scoped_refptr<X509Certificate> comodo_chain = | 380 scoped_refptr<X509Certificate> comodo_chain = |
365 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 381 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
366 intermediates); | 382 intermediates); |
367 | 383 |
368 scoped_refptr<CRLSet> crl_set(CRLSet::EmptyCRLSetForTesting()); | 384 scoped_refptr<CRLSet> crl_set(CRLSet::EmptyCRLSetForTesting()); |
369 CertVerifyResult verify_result; | 385 CertVerifyResult verify_result; |
370 int flags = X509Certificate::VERIFY_EV_CERT; | 386 int flags = X509Certificate::VERIFY_EV_CERT; |
371 int error = comodo_chain->Verify( | 387 int error = Verify(comodo_chain, "comodo.com", flags, crl_set.get(), |
372 "comodo.com", flags, crl_set.get(), &verify_result); | 388 &verify_result); |
373 EXPECT_EQ(OK, error); | 389 EXPECT_EQ(OK, error); |
374 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 390 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
375 } | 391 } |
376 | 392 |
377 // Test that all desired AttributeAndValue pairs can be extracted when only | 393 // Test that all desired AttributeAndValue pairs can be extracted when only |
378 // a single RelativeDistinguishedName is present. "Normally" there is only | 394 // a single RelativeDistinguishedName is present. "Normally" there is only |
379 // one AVA per RDN, but some CAs place all AVAs within a single RDN. | 395 // one AVA per RDN, but some CAs place all AVAs within a single RDN. |
380 // This is a regression test for http://crbug.com/101009 | 396 // This is a regression test for http://crbug.com/101009 |
381 TEST(X509CertificateTest, MultivalueRDN) { | 397 TEST_F(X509CertificateTest, MultivalueRDN) { |
382 FilePath certs_dir = GetTestCertsDirectory(); | 398 FilePath certs_dir = GetTestCertsDirectory(); |
383 | 399 |
384 scoped_refptr<X509Certificate> multivalue_rdn_cert = | 400 scoped_refptr<X509Certificate> multivalue_rdn_cert = |
385 ImportCertFromFile(certs_dir, "multivalue_rdn.pem"); | 401 ImportCertFromFile(certs_dir, "multivalue_rdn.pem"); |
386 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert); | 402 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert); |
387 | 403 |
388 const CertPrincipal& subject = multivalue_rdn_cert->subject(); | 404 const CertPrincipal& subject = multivalue_rdn_cert->subject(); |
389 EXPECT_EQ("Multivalue RDN Test", subject.common_name); | 405 EXPECT_EQ("Multivalue RDN Test", subject.common_name); |
390 EXPECT_EQ("", subject.locality_name); | 406 EXPECT_EQ("", subject.locality_name); |
391 EXPECT_EQ("", subject.state_or_province_name); | 407 EXPECT_EQ("", subject.state_or_province_name); |
392 EXPECT_EQ("US", subject.country_name); | 408 EXPECT_EQ("US", subject.country_name); |
393 EXPECT_EQ(0U, subject.street_addresses.size()); | 409 EXPECT_EQ(0U, subject.street_addresses.size()); |
394 ASSERT_EQ(1U, subject.organization_names.size()); | 410 ASSERT_EQ(1U, subject.organization_names.size()); |
395 EXPECT_EQ("Chromium", subject.organization_names[0]); | 411 EXPECT_EQ("Chromium", subject.organization_names[0]); |
396 ASSERT_EQ(1U, subject.organization_unit_names.size()); | 412 ASSERT_EQ(1U, subject.organization_unit_names.size()); |
397 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]); | 413 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]); |
398 ASSERT_EQ(1U, subject.domain_components.size()); | 414 ASSERT_EQ(1U, subject.domain_components.size()); |
399 EXPECT_EQ("Chromium", subject.domain_components[0]); | 415 EXPECT_EQ("Chromium", subject.domain_components[0]); |
400 } | 416 } |
401 | 417 |
402 // Test that characters which would normally be escaped in the string form, | 418 // Test that characters which would normally be escaped in the string form, |
403 // such as '=' or '"', are not escaped when parsed as individual components. | 419 // such as '=' or '"', are not escaped when parsed as individual components. |
404 // This is a regression test for http://crbug.com/102839 | 420 // This is a regression test for http://crbug.com/102839 |
405 TEST(X509CertificateTest, UnescapedSpecialCharacters) { | 421 TEST_F(X509CertificateTest, UnescapedSpecialCharacters) { |
406 FilePath certs_dir = GetTestCertsDirectory(); | 422 FilePath certs_dir = GetTestCertsDirectory(); |
407 | 423 |
408 scoped_refptr<X509Certificate> unescaped_cert = | 424 scoped_refptr<X509Certificate> unescaped_cert = |
409 ImportCertFromFile(certs_dir, "unescaped.pem"); | 425 ImportCertFromFile(certs_dir, "unescaped.pem"); |
410 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert); | 426 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert); |
411 | 427 |
412 const CertPrincipal& subject = unescaped_cert->subject(); | 428 const CertPrincipal& subject = unescaped_cert->subject(); |
413 EXPECT_EQ("127.0.0.1", subject.common_name); | 429 EXPECT_EQ("127.0.0.1", subject.common_name); |
414 EXPECT_EQ("Mountain View", subject.locality_name); | 430 EXPECT_EQ("Mountain View", subject.locality_name); |
415 EXPECT_EQ("California", subject.state_or_province_name); | 431 EXPECT_EQ("California", subject.state_or_province_name); |
416 EXPECT_EQ("US", subject.country_name); | 432 EXPECT_EQ("US", subject.country_name); |
417 ASSERT_EQ(1U, subject.street_addresses.size()); | 433 ASSERT_EQ(1U, subject.street_addresses.size()); |
418 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]); | 434 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]); |
419 ASSERT_EQ(1U, subject.organization_names.size()); | 435 ASSERT_EQ(1U, subject.organization_names.size()); |
420 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]); | 436 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]); |
421 ASSERT_EQ(2U, subject.organization_unit_names.size()); | 437 ASSERT_EQ(2U, subject.organization_unit_names.size()); |
422 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]); | 438 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]); |
423 EXPECT_EQ("Chromium", subject.organization_unit_names[1]); | 439 EXPECT_EQ("Chromium", subject.organization_unit_names[1]); |
424 EXPECT_EQ(0U, subject.domain_components.size()); | 440 EXPECT_EQ(0U, subject.domain_components.size()); |
425 } | 441 } |
426 | 442 |
427 TEST(X509CertificateTest, PaypalNullCertParsing) { | 443 TEST_F(X509CertificateTest, PaypalNullCertParsing) { |
428 scoped_refptr<X509Certificate> paypal_null_cert( | 444 scoped_refptr<X509Certificate> paypal_null_cert( |
429 X509Certificate::CreateFromBytes( | 445 X509Certificate::CreateFromBytes( |
430 reinterpret_cast<const char*>(paypal_null_der), | 446 reinterpret_cast<const char*>(paypal_null_der), |
431 sizeof(paypal_null_der))); | 447 sizeof(paypal_null_der))); |
432 | 448 |
433 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); | 449 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); |
434 | 450 |
435 const SHA1Fingerprint& fingerprint = | 451 const SHA1Fingerprint& fingerprint = |
436 paypal_null_cert->fingerprint(); | 452 paypal_null_cert->fingerprint(); |
437 for (size_t i = 0; i < 20; ++i) | 453 for (size_t i = 0; i < 20; ++i) |
438 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); | 454 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); |
439 | 455 |
440 int flags = 0; | 456 int flags = 0; |
441 CertVerifyResult verify_result; | 457 CertVerifyResult verify_result; |
442 int error = paypal_null_cert->Verify("www.paypal.com", flags, NULL, | 458 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL, |
443 &verify_result); | 459 &verify_result); |
444 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) | 460 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) |
445 // TOOD(bulach): investigate why macosx and win aren't returning | 461 // TOOD(bulach): investigate why macosx and win aren't returning |
446 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 462 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. |
447 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 463 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
448 #else | 464 #else |
449 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); | 465 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); |
450 #endif | 466 #endif |
451 // Either the system crypto library should correctly report a certificate | 467 // Either the system crypto library should correctly report a certificate |
452 // name mismatch, or our certificate blacklist should cause us to report an | 468 // name mismatch, or our certificate blacklist should cause us to report an |
453 // invalid certificate. | 469 // invalid certificate. |
454 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) | 470 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) |
455 EXPECT_TRUE(verify_result.cert_status & | 471 EXPECT_TRUE(verify_result.cert_status & |
456 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 472 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); |
457 #endif | 473 #endif |
458 } | 474 } |
459 | 475 |
460 TEST(X509CertificateTest, SerialNumbers) { | 476 TEST_F(X509CertificateTest, SerialNumbers) { |
461 scoped_refptr<X509Certificate> google_cert( | 477 scoped_refptr<X509Certificate> google_cert( |
462 X509Certificate::CreateFromBytes( | 478 X509Certificate::CreateFromBytes( |
463 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 479 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
464 | 480 |
465 static const uint8 google_serial[16] = { | 481 static const uint8 google_serial[16] = { |
466 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, | 482 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, |
467 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, | 483 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, |
468 }; | 484 }; |
469 | 485 |
470 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); | 486 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); |
471 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, | 487 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, |
472 sizeof(google_serial)) == 0); | 488 sizeof(google_serial)) == 0); |
473 | 489 |
474 // We also want to check a serial number where the first byte is >= 0x80 in | 490 // We also want to check a serial number where the first byte is >= 0x80 in |
475 // case the underlying library tries to pad it. | 491 // case the underlying library tries to pad it. |
476 scoped_refptr<X509Certificate> paypal_null_cert( | 492 scoped_refptr<X509Certificate> paypal_null_cert( |
477 X509Certificate::CreateFromBytes( | 493 X509Certificate::CreateFromBytes( |
478 reinterpret_cast<const char*>(paypal_null_der), | 494 reinterpret_cast<const char*>(paypal_null_der), |
479 sizeof(paypal_null_der))); | 495 sizeof(paypal_null_der))); |
480 | 496 |
481 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; | 497 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; |
482 ASSERT_EQ(sizeof(paypal_null_serial), | 498 ASSERT_EQ(sizeof(paypal_null_serial), |
483 paypal_null_cert->serial_number().size()); | 499 paypal_null_cert->serial_number().size()); |
484 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), | 500 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), |
485 paypal_null_serial, sizeof(paypal_null_serial)) == 0); | 501 paypal_null_serial, sizeof(paypal_null_serial)) == 0); |
486 } | 502 } |
487 | 503 |
488 TEST(X509CertificateTest, CAFingerprints) { | 504 TEST_F(X509CertificateTest, CAFingerprints) { |
489 FilePath certs_dir = GetTestCertsDirectory(); | 505 FilePath certs_dir = GetTestCertsDirectory(); |
490 | 506 |
491 scoped_refptr<X509Certificate> server_cert = | 507 scoped_refptr<X509Certificate> server_cert = |
492 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); | 508 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); |
493 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 509 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
494 | 510 |
495 scoped_refptr<X509Certificate> intermediate_cert1 = | 511 scoped_refptr<X509Certificate> intermediate_cert1 = |
496 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); | 512 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); |
497 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); | 513 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); |
498 | 514 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data, | 552 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data, |
537 cert_chain2_ca_fingerprint, 20) == 0); | 553 cert_chain2_ca_fingerprint, 20) == 0); |
538 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data, | 554 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data, |
539 cert_chain3_ca_fingerprint, 20) == 0); | 555 cert_chain3_ca_fingerprint, 20) == 0); |
540 } | 556 } |
541 | 557 |
542 // A regression test for http://crbug.com/31497. | 558 // A regression test for http://crbug.com/31497. |
543 // This certificate will expire on 2012-04-08. The test will still | 559 // This certificate will expire on 2012-04-08. The test will still |
544 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test | 560 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test |
545 // certificates for this unit test. http://crbug.com/111742 | 561 // certificates for this unit test. http://crbug.com/111742 |
546 TEST(X509CertificateTest, IntermediateCARequireExplicitPolicy) { | 562 TEST_F(X509CertificateTest, IntermediateCARequireExplicitPolicy) { |
547 FilePath certs_dir = GetTestCertsDirectory(); | 563 FilePath certs_dir = GetTestCertsDirectory(); |
548 | 564 |
549 scoped_refptr<X509Certificate> server_cert = | 565 scoped_refptr<X509Certificate> server_cert = |
550 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); | 566 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); |
551 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 567 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
552 | 568 |
553 // The intermediate CA certificate's policyConstraints extension has a | 569 // The intermediate CA certificate's policyConstraints extension has a |
554 // requireExplicitPolicy field with SkipCerts=0. | 570 // requireExplicitPolicy field with SkipCerts=0. |
555 scoped_refptr<X509Certificate> intermediate_cert = | 571 scoped_refptr<X509Certificate> intermediate_cert = |
556 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); | 572 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); |
557 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 573 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
558 | 574 |
559 scoped_refptr<X509Certificate> root_cert = | 575 scoped_refptr<X509Certificate> root_cert = |
560 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); | 576 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); |
561 ScopedTestRoot scoped_root(root_cert); | 577 ScopedTestRoot scoped_root(root_cert); |
562 | 578 |
563 X509Certificate::OSCertHandles intermediates; | 579 X509Certificate::OSCertHandles intermediates; |
564 intermediates.push_back(intermediate_cert->os_cert_handle()); | 580 intermediates.push_back(intermediate_cert->os_cert_handle()); |
565 scoped_refptr<X509Certificate> cert_chain = | 581 scoped_refptr<X509Certificate> cert_chain = |
566 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 582 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
567 intermediates); | 583 intermediates); |
568 | 584 |
569 int flags = 0; | 585 int flags = 0; |
570 CertVerifyResult verify_result; | 586 CertVerifyResult verify_result; |
571 int error = cert_chain->Verify("www.us.army.mil", flags, NULL, | 587 int error = Verify(cert_chain, "www.us.army.mil", flags, NULL, |
572 &verify_result); | 588 &verify_result); |
573 if (error == OK) { | 589 if (error == OK) { |
574 EXPECT_EQ(0U, verify_result.cert_status); | 590 EXPECT_EQ(0U, verify_result.cert_status); |
575 } else { | 591 } else { |
576 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 592 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
577 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); | 593 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); |
578 } | 594 } |
579 } | 595 } |
580 | 596 |
581 // Test for bug 58437. | 597 // Test for bug 58437. |
582 // This certificate will expire on 2011-12-21. The test will still | 598 // This certificate will expire on 2011-12-21. The test will still |
583 // pass if error == ERR_CERT_DATE_INVALID. | 599 // pass if error == ERR_CERT_DATE_INVALID. |
584 // This test is DISABLED because it appears that we cannot do | 600 // This test is DISABLED because it appears that we cannot do |
585 // certificate revocation checking when running all of the net unit tests. | 601 // certificate revocation checking when running all of the net unit tests. |
586 // This test passes when run individually, but when run with all of the net | 602 // This test passes when run individually, but when run with all of the net |
587 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is | 603 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is |
588 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation | 604 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation |
589 // status, i.e. that the revocation check is failing for some reason. | 605 // status, i.e. that the revocation check is failing for some reason. |
590 TEST(X509CertificateTest, DISABLED_GlobalSignR3EVTest) { | 606 TEST_F(X509CertificateTest, DISABLED_GlobalSignR3EVTest) { |
591 FilePath certs_dir = GetTestCertsDirectory(); | 607 FilePath certs_dir = GetTestCertsDirectory(); |
592 | 608 |
593 scoped_refptr<X509Certificate> server_cert = | 609 scoped_refptr<X509Certificate> server_cert = |
594 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); | 610 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); |
595 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 611 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
596 | 612 |
597 scoped_refptr<X509Certificate> intermediate_cert = | 613 scoped_refptr<X509Certificate> intermediate_cert = |
598 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); | 614 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); |
599 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 615 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
600 | 616 |
601 X509Certificate::OSCertHandles intermediates; | 617 X509Certificate::OSCertHandles intermediates; |
602 intermediates.push_back(intermediate_cert->os_cert_handle()); | 618 intermediates.push_back(intermediate_cert->os_cert_handle()); |
603 scoped_refptr<X509Certificate> cert_chain = | 619 scoped_refptr<X509Certificate> cert_chain = |
604 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 620 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
605 intermediates); | 621 intermediates); |
606 | 622 |
607 CertVerifyResult verify_result; | 623 CertVerifyResult verify_result; |
608 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | | 624 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | |
609 X509Certificate::VERIFY_EV_CERT; | 625 X509Certificate::VERIFY_EV_CERT; |
610 int error = cert_chain->Verify("2029.globalsign.com", flags, NULL, | 626 int error = Verify(cert_chain, "2029.globalsign.com", flags, NULL, |
611 &verify_result); | 627 &verify_result); |
612 if (error == OK) | 628 if (error == OK) |
613 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 629 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
614 else | 630 else |
615 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 631 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
616 } | 632 } |
617 | 633 |
618 // Currently, only RSA and DSA keys are checked for weakness, and our example | 634 // Currently, only RSA and DSA keys are checked for weakness, and our example |
619 // weak size is 768. These could change in the future. | 635 // weak size is 768. These could change in the future. |
620 // | 636 // |
621 // Note that this means there may be false negatives: keys for other | 637 // Note that this means there may be false negatives: keys for other |
622 // algorithms and which are weak will pass this test. | 638 // algorithms and which are weak will pass this test. |
623 static bool IsWeakKeyType(const std::string& key_type) { | 639 static bool IsWeakKeyType(const std::string& key_type) { |
624 size_t pos = key_type.find("-"); | 640 size_t pos = key_type.find("-"); |
625 std::string size = key_type.substr(0, pos); | 641 std::string size = key_type.substr(0, pos); |
626 std::string type = key_type.substr(pos + 1); | 642 std::string type = key_type.substr(pos + 1); |
627 | 643 |
628 if (type == "rsa" || type == "dsa") | 644 if (type == "rsa" || type == "dsa") |
629 return size == "768"; | 645 return size == "768"; |
630 | 646 |
631 return false; | 647 return false; |
632 } | 648 } |
633 | 649 |
634 TEST(X509CertificateTest, RejectWeakKeys) { | 650 TEST_F(X509CertificateTest, RejectWeakKeys) { |
635 FilePath certs_dir = GetTestCertsDirectory(); | 651 FilePath certs_dir = GetTestCertsDirectory(); |
636 typedef std::vector<std::string> Strings; | 652 typedef std::vector<std::string> Strings; |
637 Strings key_types; | 653 Strings key_types; |
638 | 654 |
639 // generate-weak-test-chains.sh currently has: | 655 // generate-weak-test-chains.sh currently has: |
640 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" | 656 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" |
641 // We must use the same key types here. The filenames generated look like: | 657 // We must use the same key types here. The filenames generated look like: |
642 // 2048-rsa-ee-by-768-rsa-intermediate.pem | 658 // 2048-rsa-ee-by-768-rsa-intermediate.pem |
643 key_types.push_back("768-rsa"); | 659 key_types.push_back("768-rsa"); |
644 key_types.push_back("1024-rsa"); | 660 key_types.push_back("1024-rsa"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 ImportCertFromFile(certs_dir, basename); | 693 ImportCertFromFile(certs_dir, basename); |
678 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); | 694 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); |
679 | 695 |
680 X509Certificate::OSCertHandles intermediates; | 696 X509Certificate::OSCertHandles intermediates; |
681 intermediates.push_back(intermediate->os_cert_handle()); | 697 intermediates.push_back(intermediate->os_cert_handle()); |
682 scoped_refptr<X509Certificate> cert_chain = | 698 scoped_refptr<X509Certificate> cert_chain = |
683 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 699 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), |
684 intermediates); | 700 intermediates); |
685 | 701 |
686 CertVerifyResult verify_result; | 702 CertVerifyResult verify_result; |
687 int error = cert_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 703 int error = Verify(cert_chain, "127.0.0.1", 0, NULL, &verify_result); |
688 | 704 |
689 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 705 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { |
690 EXPECT_NE(OK, error); | 706 EXPECT_NE(OK, error); |
691 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 707 EXPECT_EQ(CERT_STATUS_WEAK_KEY, |
692 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 708 verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
693 } else { | 709 } else { |
694 EXPECT_EQ(OK, error); | 710 EXPECT_EQ(OK, error); |
695 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 711 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
696 } | 712 } |
697 } | 713 } |
698 } | 714 } |
699 } | 715 } |
700 | 716 |
701 // Test for bug 108514. | 717 // Test for bug 108514. |
702 // The certificate will expire on 2012-07-20. The test will still | 718 // The certificate will expire on 2012-07-20. The test will still |
703 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test | 719 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test |
704 // certificates for this unit test. http://crbug.com/111730 | 720 // certificates for this unit test. http://crbug.com/111730 |
705 TEST(X509CertificateTest, ExtraneousMD5RootCert) { | 721 TEST_F(X509CertificateTest, ExtraneousMD5RootCert) { |
706 FilePath certs_dir = GetTestCertsDirectory(); | 722 FilePath certs_dir = GetTestCertsDirectory(); |
707 | 723 |
708 scoped_refptr<X509Certificate> server_cert = | 724 scoped_refptr<X509Certificate> server_cert = |
709 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); | 725 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); |
710 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 726 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
711 | 727 |
712 scoped_refptr<X509Certificate> intermediate_cert = | 728 scoped_refptr<X509Certificate> intermediate_cert = |
713 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); | 729 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); |
714 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 730 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
715 | 731 |
716 scoped_refptr<X509Certificate> md5_root_cert = | 732 scoped_refptr<X509Certificate> md5_root_cert = |
717 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); | 733 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); |
718 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); | 734 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); |
719 | 735 |
720 X509Certificate::OSCertHandles intermediates; | 736 X509Certificate::OSCertHandles intermediates; |
721 intermediates.push_back(intermediate_cert->os_cert_handle()); | 737 intermediates.push_back(intermediate_cert->os_cert_handle()); |
722 intermediates.push_back(md5_root_cert->os_cert_handle()); | 738 intermediates.push_back(md5_root_cert->os_cert_handle()); |
723 scoped_refptr<X509Certificate> cert_chain = | 739 scoped_refptr<X509Certificate> cert_chain = |
724 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 740 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
725 intermediates); | 741 intermediates); |
726 | 742 |
727 CertVerifyResult verify_result; | 743 CertVerifyResult verify_result; |
728 int flags = 0; | 744 int flags = 0; |
729 int error = cert_chain->Verify("images.etrade.wallst.com", flags, NULL, | 745 int error = Verify(cert_chain, "images.etrade.wallst.com", flags, NULL, |
730 &verify_result); | 746 &verify_result); |
731 if (error != OK) | 747 if (error != OK) |
732 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 748 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
733 | 749 |
734 EXPECT_FALSE(verify_result.has_md5); | 750 EXPECT_FALSE(verify_result.has_md5); |
735 EXPECT_FALSE(verify_result.has_md5_ca); | 751 EXPECT_FALSE(verify_result.has_md5_ca); |
736 } | 752 } |
737 | 753 |
738 // Test for bug 94673. | 754 // Test for bug 94673. |
739 TEST(X509CertificateTest, GoogleDigiNotarTest) { | 755 TEST_F(X509CertificateTest, GoogleDigiNotarTest) { |
740 FilePath certs_dir = GetTestCertsDirectory(); | 756 FilePath certs_dir = GetTestCertsDirectory(); |
741 | 757 |
742 scoped_refptr<X509Certificate> server_cert = | 758 scoped_refptr<X509Certificate> server_cert = |
743 ImportCertFromFile(certs_dir, "google_diginotar.pem"); | 759 ImportCertFromFile(certs_dir, "google_diginotar.pem"); |
744 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 760 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
745 | 761 |
746 scoped_refptr<X509Certificate> intermediate_cert = | 762 scoped_refptr<X509Certificate> intermediate_cert = |
747 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); | 763 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); |
748 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 764 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
749 | 765 |
750 X509Certificate::OSCertHandles intermediates; | 766 X509Certificate::OSCertHandles intermediates; |
751 intermediates.push_back(intermediate_cert->os_cert_handle()); | 767 intermediates.push_back(intermediate_cert->os_cert_handle()); |
752 scoped_refptr<X509Certificate> cert_chain = | 768 scoped_refptr<X509Certificate> cert_chain = |
753 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 769 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
754 intermediates); | 770 intermediates); |
755 | 771 |
756 CertVerifyResult verify_result; | 772 CertVerifyResult verify_result; |
757 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 773 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; |
758 int error = cert_chain->Verify("mail.google.com", flags, NULL, | 774 int error = Verify(cert_chain, "mail.google.com", flags, NULL, |
759 &verify_result); | 775 &verify_result); |
760 EXPECT_NE(OK, error); | 776 EXPECT_NE(OK, error); |
761 | 777 |
762 // Now turn off revocation checking. Certificate verification should still | 778 // Now turn off revocation checking. Certificate verification should still |
763 // fail. | 779 // fail. |
764 flags = 0; | 780 flags = 0; |
765 error = cert_chain->Verify("mail.google.com", flags, NULL, &verify_result); | 781 error = Verify(cert_chain, "mail.google.com", flags, NULL, &verify_result); |
766 EXPECT_NE(OK, error); | 782 EXPECT_NE(OK, error); |
767 } | 783 } |
768 | 784 |
769 TEST(X509CertificateTest, DigiNotarCerts) { | 785 TEST_F(X509CertificateTest, DigiNotarCerts) { |
770 static const char* const kDigiNotarFilenames[] = { | 786 static const char* const kDigiNotarFilenames[] = { |
771 "diginotar_root_ca.pem", | 787 "diginotar_root_ca.pem", |
772 "diginotar_cyber_ca.pem", | 788 "diginotar_cyber_ca.pem", |
773 "diginotar_services_1024_ca.pem", | 789 "diginotar_services_1024_ca.pem", |
774 "diginotar_pkioverheid.pem", | 790 "diginotar_pkioverheid.pem", |
775 "diginotar_pkioverheid_g2.pem", | 791 "diginotar_pkioverheid_g2.pem", |
776 NULL, | 792 NULL, |
777 }; | 793 }; |
778 | 794 |
779 FilePath certs_dir = GetTestCertsDirectory(); | 795 FilePath certs_dir = GetTestCertsDirectory(); |
(...skipping 15 matching lines...) Expand all Loading... |
795 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); | 811 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); |
796 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); | 812 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); |
797 public_keys.push_back(fingerprint); | 813 public_keys.push_back(fingerprint); |
798 | 814 |
799 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) << | 815 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) << |
800 "Public key not blocked for " << kDigiNotarFilenames[i]; | 816 "Public key not blocked for " << kDigiNotarFilenames[i]; |
801 } | 817 } |
802 } | 818 } |
803 | 819 |
804 // Bug 111893: This test needs a new certificate. | 820 // Bug 111893: This test needs a new certificate. |
805 TEST(X509CertificateTest, DISABLED_TestKnownRoot) { | 821 TEST_F(X509CertificateTest, DISABLED_TestKnownRoot) { |
806 FilePath certs_dir = GetTestCertsDirectory(); | 822 FilePath certs_dir = GetTestCertsDirectory(); |
807 scoped_refptr<X509Certificate> cert = | 823 scoped_refptr<X509Certificate> cert = |
808 ImportCertFromFile(certs_dir, "nist.der"); | 824 ImportCertFromFile(certs_dir, "nist.der"); |
809 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 825 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
810 | 826 |
811 // This intermediate is only needed for old Linux machines. Modern NSS | 827 // This intermediate is only needed for old Linux machines. Modern NSS |
812 // includes it as a root already. | 828 // includes it as a root already. |
813 scoped_refptr<X509Certificate> intermediate_cert = | 829 scoped_refptr<X509Certificate> intermediate_cert = |
814 ImportCertFromFile(certs_dir, "nist_intermediate.der"); | 830 ImportCertFromFile(certs_dir, "nist_intermediate.der"); |
815 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 831 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
816 | 832 |
817 X509Certificate::OSCertHandles intermediates; | 833 X509Certificate::OSCertHandles intermediates; |
818 intermediates.push_back(intermediate_cert->os_cert_handle()); | 834 intermediates.push_back(intermediate_cert->os_cert_handle()); |
819 scoped_refptr<X509Certificate> cert_chain = | 835 scoped_refptr<X509Certificate> cert_chain = |
820 X509Certificate::CreateFromHandle(cert->os_cert_handle(), | 836 X509Certificate::CreateFromHandle(cert->os_cert_handle(), |
821 intermediates); | 837 intermediates); |
822 | 838 |
823 int flags = 0; | 839 int flags = 0; |
824 CertVerifyResult verify_result; | 840 CertVerifyResult verify_result; |
825 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug | 841 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug |
826 // against agl. Also see PublicKeyHashes in this file. | 842 // against agl. Also see PublicKeyHashes in this file. |
827 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); | 843 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result); |
828 EXPECT_EQ(OK, error); | 844 EXPECT_EQ(OK, error); |
829 EXPECT_EQ(0U, verify_result.cert_status); | 845 EXPECT_EQ(0U, verify_result.cert_status); |
830 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 846 EXPECT_TRUE(verify_result.is_issued_by_known_root); |
831 } | 847 } |
832 | 848 |
833 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der. | 849 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der. |
834 static const char nistSPKIHash[] = | 850 static const char nistSPKIHash[] = |
835 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82" | 851 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82" |
836 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35"; | 852 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35"; |
837 | 853 |
838 TEST(X509CertificateTest, ExtractSPKIFromDERCert) { | 854 TEST_F(X509CertificateTest, ExtractSPKIFromDERCert) { |
839 FilePath certs_dir = GetTestCertsDirectory(); | 855 FilePath certs_dir = GetTestCertsDirectory(); |
840 scoped_refptr<X509Certificate> cert = | 856 scoped_refptr<X509Certificate> cert = |
841 ImportCertFromFile(certs_dir, "nist.der"); | 857 ImportCertFromFile(certs_dir, "nist.der"); |
842 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 858 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
843 | 859 |
844 std::string derBytes; | 860 std::string derBytes; |
845 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), | 861 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), |
846 &derBytes)); | 862 &derBytes)); |
847 | 863 |
848 base::StringPiece spkiBytes; | 864 base::StringPiece spkiBytes; |
849 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); | 865 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); |
850 | 866 |
851 uint8 hash[base::kSHA1Length]; | 867 uint8 hash[base::kSHA1Length]; |
852 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), | 868 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), |
853 spkiBytes.size(), hash); | 869 spkiBytes.size(), hash); |
854 | 870 |
855 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash))); | 871 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash))); |
856 } | 872 } |
857 | 873 |
858 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) { | 874 TEST_F(X509CertificateTest, ExtractCRLURLsFromDERCert) { |
859 FilePath certs_dir = GetTestCertsDirectory(); | 875 FilePath certs_dir = GetTestCertsDirectory(); |
860 scoped_refptr<X509Certificate> cert = | 876 scoped_refptr<X509Certificate> cert = |
861 ImportCertFromFile(certs_dir, "nist.der"); | 877 ImportCertFromFile(certs_dir, "nist.der"); |
862 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 878 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
863 | 879 |
864 std::string derBytes; | 880 std::string derBytes; |
865 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), | 881 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), |
866 &derBytes)); | 882 &derBytes)); |
867 | 883 |
868 std::vector<base::StringPiece> crl_urls; | 884 std::vector<base::StringPiece> crl_urls; |
869 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); | 885 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); |
870 | 886 |
871 EXPECT_EQ(1u, crl_urls.size()); | 887 EXPECT_EQ(1u, crl_urls.size()); |
872 if (crl_urls.size() > 0) { | 888 if (crl_urls.size() > 0) { |
873 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", | 889 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", |
874 crl_urls[0].as_string()); | 890 crl_urls[0].as_string()); |
875 } | 891 } |
876 } | 892 } |
877 | 893 |
878 // Bug 111893: This test needs a new certificate. | 894 // Bug 111893: This test needs a new certificate. |
879 TEST(X509CertificateTest, DISABLED_PublicKeyHashes) { | 895 TEST_F(X509CertificateTest, DISABLED_PublicKeyHashes) { |
880 FilePath certs_dir = GetTestCertsDirectory(); | 896 FilePath certs_dir = GetTestCertsDirectory(); |
881 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug | 897 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug |
882 // against agl. Also see TestKnownRoot in this file. | 898 // against agl. Also see TestKnownRoot in this file. |
883 scoped_refptr<X509Certificate> cert = | 899 scoped_refptr<X509Certificate> cert = |
884 ImportCertFromFile(certs_dir, "nist.der"); | 900 ImportCertFromFile(certs_dir, "nist.der"); |
885 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 901 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
886 | 902 |
887 // This intermediate is only needed for old Linux machines. Modern NSS | 903 // This intermediate is only needed for old Linux machines. Modern NSS |
888 // includes it as a root already. | 904 // includes it as a root already. |
889 scoped_refptr<X509Certificate> intermediate_cert = | 905 scoped_refptr<X509Certificate> intermediate_cert = |
890 ImportCertFromFile(certs_dir, "nist_intermediate.der"); | 906 ImportCertFromFile(certs_dir, "nist_intermediate.der"); |
891 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 907 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
892 | 908 |
893 ScopedTestRoot scoped_intermediate(intermediate_cert); | 909 ScopedTestRoot scoped_intermediate(intermediate_cert); |
894 | 910 |
895 X509Certificate::OSCertHandles intermediates; | 911 X509Certificate::OSCertHandles intermediates; |
896 intermediates.push_back(intermediate_cert->os_cert_handle()); | 912 intermediates.push_back(intermediate_cert->os_cert_handle()); |
897 scoped_refptr<X509Certificate> cert_chain = | 913 scoped_refptr<X509Certificate> cert_chain = |
898 X509Certificate::CreateFromHandle(cert->os_cert_handle(), | 914 X509Certificate::CreateFromHandle(cert->os_cert_handle(), |
899 intermediates); | 915 intermediates); |
900 | 916 |
901 int flags = 0; | 917 int flags = 0; |
902 CertVerifyResult verify_result; | 918 CertVerifyResult verify_result; |
903 | 919 |
904 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); | 920 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result); |
905 EXPECT_EQ(OK, error); | 921 EXPECT_EQ(OK, error); |
906 EXPECT_EQ(0U, verify_result.cert_status); | 922 EXPECT_EQ(0U, verify_result.cert_status); |
907 ASSERT_LE(2u, verify_result.public_key_hashes.size()); | 923 ASSERT_LE(2u, verify_result.public_key_hashes.size()); |
908 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), | 924 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), |
909 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); | 925 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); |
910 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", | 926 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", |
911 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); | 927 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); |
912 } | 928 } |
913 | 929 |
914 // A regression test for http://crbug.com/70293. | 930 // A regression test for http://crbug.com/70293. |
915 // The Key Usage extension in this RSA SSL server certificate does not have | 931 // The Key Usage extension in this RSA SSL server certificate does not have |
916 // the keyEncipherment bit. | 932 // the keyEncipherment bit. |
917 TEST(X509CertificateTest, InvalidKeyUsage) { | 933 TEST_F(X509CertificateTest, InvalidKeyUsage) { |
918 FilePath certs_dir = GetTestCertsDirectory(); | 934 FilePath certs_dir = GetTestCertsDirectory(); |
919 | 935 |
920 scoped_refptr<X509Certificate> server_cert = | 936 scoped_refptr<X509Certificate> server_cert = |
921 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 937 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); |
922 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 938 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
923 | 939 |
924 int flags = 0; | 940 int flags = 0; |
925 CertVerifyResult verify_result; | 941 CertVerifyResult verify_result; |
926 int error = server_cert->Verify("jira.aquameta.com", flags, NULL, | 942 int error = Verify(server_cert, "jira.aquameta.com", flags, NULL, |
927 &verify_result); | 943 &verify_result); |
928 #if defined(USE_OPENSSL) | 944 #if defined(USE_OPENSSL) |
929 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 945 // This certificate has two errors: "invalid key usage" and "untrusted CA". |
930 // However, OpenSSL returns only one (the latter), and we can't detect | 946 // However, OpenSSL returns only one (the latter), and we can't detect |
931 // the other errors. | 947 // the other errors. |
932 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 948 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
933 #else | 949 #else |
934 EXPECT_EQ(ERR_CERT_INVALID, error); | 950 EXPECT_EQ(ERR_CERT_INVALID, error); |
935 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 951 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); |
936 #endif | 952 #endif |
937 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 953 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors |
938 // from NSS. | 954 // from NSS. |
939 #if !defined(USE_NSS) | 955 #if !defined(USE_NSS) |
940 // The certificate is issued by an unknown CA. | 956 // The certificate is issued by an unknown CA. |
941 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 957 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); |
942 #endif | 958 #endif |
943 } | 959 } |
944 | 960 |
945 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We | 961 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We |
946 // call X509Certificate::CreateFromHandle several times and observe whether | 962 // call X509Certificate::CreateFromHandle several times and observe whether |
947 // it returns a cached or new OSCertHandle. | 963 // it returns a cached or new OSCertHandle. |
948 TEST(X509CertificateTest, Cache) { | 964 TEST_F(X509CertificateTest, Cache) { |
949 X509Certificate::OSCertHandle google_cert_handle; | 965 X509Certificate::OSCertHandle google_cert_handle; |
950 X509Certificate::OSCertHandle thawte_cert_handle; | 966 X509Certificate::OSCertHandle thawte_cert_handle; |
951 | 967 |
952 // Add a single certificate to the certificate cache. | 968 // Add a single certificate to the certificate cache. |
953 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 969 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
954 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 970 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
955 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( | 971 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( |
956 google_cert_handle, X509Certificate::OSCertHandles())); | 972 google_cert_handle, X509Certificate::OSCertHandles())); |
957 X509Certificate::FreeOSCertHandle(google_cert_handle); | 973 X509Certificate::FreeOSCertHandle(google_cert_handle); |
958 | 974 |
(...skipping 26 matching lines...) Expand all Loading... |
985 X509Certificate::FreeOSCertHandle(thawte_cert_handle); | 1001 X509Certificate::FreeOSCertHandle(thawte_cert_handle); |
986 | 1002 |
987 // Test that the new certificate, even with intermediates, results in the | 1003 // Test that the new certificate, even with intermediates, results in the |
988 // same underlying handle being used. | 1004 // same underlying handle being used. |
989 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle()); | 1005 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle()); |
990 // Though they use the same OS handle, the intermediates should be different. | 1006 // Though they use the same OS handle, the intermediates should be different. |
991 EXPECT_NE(cert1->GetIntermediateCertificates().size(), | 1007 EXPECT_NE(cert1->GetIntermediateCertificates().size(), |
992 cert3->GetIntermediateCertificates().size()); | 1008 cert3->GetIntermediateCertificates().size()); |
993 } | 1009 } |
994 | 1010 |
995 TEST(X509CertificateTest, Pickle) { | 1011 TEST_F(X509CertificateTest, Pickle) { |
996 X509Certificate::OSCertHandle google_cert_handle = | 1012 X509Certificate::OSCertHandle google_cert_handle = |
997 X509Certificate::CreateOSCertHandleFromBytes( | 1013 X509Certificate::CreateOSCertHandleFromBytes( |
998 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 1014 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
999 X509Certificate::OSCertHandle thawte_cert_handle = | 1015 X509Certificate::OSCertHandle thawte_cert_handle = |
1000 X509Certificate::CreateOSCertHandleFromBytes( | 1016 X509Certificate::CreateOSCertHandleFromBytes( |
1001 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); | 1017 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); |
1002 | 1018 |
1003 X509Certificate::OSCertHandles intermediates; | 1019 X509Certificate::OSCertHandles intermediates; |
1004 intermediates.push_back(thawte_cert_handle); | 1020 intermediates.push_back(thawte_cert_handle); |
1005 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( | 1021 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( |
(...skipping 17 matching lines...) Expand all Loading... |
1023 cert->GetIntermediateCertificates(); | 1039 cert->GetIntermediateCertificates(); |
1024 const X509Certificate::OSCertHandles& pickle_intermediates = | 1040 const X509Certificate::OSCertHandles& pickle_intermediates = |
1025 cert_from_pickle->GetIntermediateCertificates(); | 1041 cert_from_pickle->GetIntermediateCertificates(); |
1026 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size()); | 1042 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size()); |
1027 for (size_t i = 0; i < cert_intermediates.size(); ++i) { | 1043 for (size_t i = 0; i < cert_intermediates.size(); ++i) { |
1028 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i], | 1044 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i], |
1029 pickle_intermediates[i])); | 1045 pickle_intermediates[i])); |
1030 } | 1046 } |
1031 } | 1047 } |
1032 | 1048 |
1033 TEST(X509CertificateTest, Policy) { | 1049 TEST_F(X509CertificateTest, Policy) { |
1034 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( | 1050 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( |
1035 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 1051 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
1036 | 1052 |
1037 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( | 1053 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
1038 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 1054 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
1039 | 1055 |
1040 CertPolicy policy; | 1056 CertPolicy policy; |
1041 | 1057 |
1042 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); | 1058 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); |
1043 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); | 1059 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); |
(...skipping 15 matching lines...) Expand all Loading... |
1059 EXPECT_TRUE(policy.HasDeniedCert()); | 1075 EXPECT_TRUE(policy.HasDeniedCert()); |
1060 | 1076 |
1061 policy.Allow(webkit_cert.get()); | 1077 policy.Allow(webkit_cert.get()); |
1062 | 1078 |
1063 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); | 1079 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); |
1064 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); | 1080 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); |
1065 EXPECT_TRUE(policy.HasAllowedCert()); | 1081 EXPECT_TRUE(policy.HasAllowedCert()); |
1066 EXPECT_TRUE(policy.HasDeniedCert()); | 1082 EXPECT_TRUE(policy.HasDeniedCert()); |
1067 } | 1083 } |
1068 | 1084 |
1069 TEST(X509CertificateTest, IntermediateCertificates) { | 1085 TEST_F(X509CertificateTest, IntermediateCertificates) { |
1070 scoped_refptr<X509Certificate> webkit_cert( | 1086 scoped_refptr<X509Certificate> webkit_cert( |
1071 X509Certificate::CreateFromBytes( | 1087 X509Certificate::CreateFromBytes( |
1072 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 1088 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
1073 | 1089 |
1074 scoped_refptr<X509Certificate> thawte_cert( | 1090 scoped_refptr<X509Certificate> thawte_cert( |
1075 X509Certificate::CreateFromBytes( | 1091 X509Certificate::CreateFromBytes( |
1076 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); | 1092 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
1077 | 1093 |
1078 X509Certificate::OSCertHandle google_handle; | 1094 X509Certificate::OSCertHandle google_handle; |
1079 // Create object with no intermediates: | 1095 // Create object with no intermediates: |
(...skipping 23 matching lines...) Expand all Loading... |
1103 // Cleanup | 1119 // Cleanup |
1104 X509Certificate::FreeOSCertHandle(google_handle); | 1120 X509Certificate::FreeOSCertHandle(google_handle); |
1105 } | 1121 } |
1106 | 1122 |
1107 // Basic test for returning the chain in CertVerifyResult. Note that the | 1123 // Basic test for returning the chain in CertVerifyResult. Note that the |
1108 // returned chain may just be a reflection of the originally supplied chain; | 1124 // returned chain may just be a reflection of the originally supplied chain; |
1109 // that is, if any errors occur, the default chain returned is an exact copy | 1125 // that is, if any errors occur, the default chain returned is an exact copy |
1110 // of the certificate to be verified. The remaining VerifyReturn* tests are | 1126 // of the certificate to be verified. The remaining VerifyReturn* tests are |
1111 // used to ensure that the actual, verified chain is being returned by | 1127 // used to ensure that the actual, verified chain is being returned by |
1112 // Verify(). | 1128 // Verify(). |
1113 TEST(X509CertificateTest, VerifyReturnChainBasic) { | 1129 TEST_F(X509CertificateTest, VerifyReturnChainBasic) { |
1114 FilePath certs_dir = GetTestCertsDirectory(); | 1130 FilePath certs_dir = GetTestCertsDirectory(); |
1115 CertificateList certs = CreateCertificateListFromFile( | 1131 CertificateList certs = CreateCertificateListFromFile( |
1116 certs_dir, "x509_verify_results.chain.pem", | 1132 certs_dir, "x509_verify_results.chain.pem", |
1117 X509Certificate::FORMAT_AUTO); | 1133 X509Certificate::FORMAT_AUTO); |
1118 ASSERT_EQ(3U, certs.size()); | 1134 ASSERT_EQ(3U, certs.size()); |
1119 | 1135 |
1120 X509Certificate::OSCertHandles intermediates; | 1136 X509Certificate::OSCertHandles intermediates; |
1121 intermediates.push_back(certs[1]->os_cert_handle()); | 1137 intermediates.push_back(certs[1]->os_cert_handle()); |
1122 intermediates.push_back(certs[2]->os_cert_handle()); | 1138 intermediates.push_back(certs[2]->os_cert_handle()); |
1123 | 1139 |
1124 ScopedTestRoot scoped_root(certs[2]); | 1140 ScopedTestRoot scoped_root(certs[2]); |
1125 | 1141 |
1126 scoped_refptr<X509Certificate> google_full_chain = | 1142 scoped_refptr<X509Certificate> google_full_chain = |
1127 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1143 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1128 intermediates); | 1144 intermediates); |
1129 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); | 1145 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
1130 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 1146 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); |
1131 | 1147 |
1132 CertVerifyResult verify_result; | 1148 CertVerifyResult verify_result; |
1133 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1149 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1134 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 1150 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
1135 EXPECT_EQ(OK, error); | 1151 EXPECT_EQ(OK, error); |
1136 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1152 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1137 | 1153 |
1138 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1154 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1139 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1155 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1140 google_full_chain->os_cert_handle(), | 1156 google_full_chain->os_cert_handle(), |
1141 verify_result.verified_cert->os_cert_handle())); | 1157 verify_result.verified_cert->os_cert_handle())); |
1142 const X509Certificate::OSCertHandles& return_intermediates = | 1158 const X509Certificate::OSCertHandles& return_intermediates = |
1143 verify_result.verified_cert->GetIntermediateCertificates(); | 1159 verify_result.verified_cert->GetIntermediateCertificates(); |
1144 ASSERT_EQ(2U, return_intermediates.size()); | 1160 ASSERT_EQ(2U, return_intermediates.size()); |
1145 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1161 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
1146 certs[1]->os_cert_handle())); | 1162 certs[1]->os_cert_handle())); |
1147 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1163 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
1148 certs[2]->os_cert_handle())); | 1164 certs[2]->os_cert_handle())); |
1149 } | 1165 } |
1150 | 1166 |
1151 // Test that the certificate returned in CertVerifyResult is able to reorder | 1167 // Test that the certificate returned in CertVerifyResult is able to reorder |
1152 // certificates that are not ordered from end-entity to root. While this is | 1168 // certificates that are not ordered from end-entity to root. While this is |
1153 // a protocol violation if sent during a TLS handshake, if multiple sources | 1169 // a protocol violation if sent during a TLS handshake, if multiple sources |
1154 // of intermediate certificates are combined, it's possible that order may | 1170 // of intermediate certificates are combined, it's possible that order may |
1155 // not be maintained. | 1171 // not be maintained. |
1156 TEST(X509CertificateTest, VerifyReturnChainProperlyOrdered) { | 1172 TEST_F(X509CertificateTest, VerifyReturnChainProperlyOrdered) { |
1157 FilePath certs_dir = GetTestCertsDirectory(); | 1173 FilePath certs_dir = GetTestCertsDirectory(); |
1158 CertificateList certs = CreateCertificateListFromFile( | 1174 CertificateList certs = CreateCertificateListFromFile( |
1159 certs_dir, "x509_verify_results.chain.pem", | 1175 certs_dir, "x509_verify_results.chain.pem", |
1160 X509Certificate::FORMAT_AUTO); | 1176 X509Certificate::FORMAT_AUTO); |
1161 ASSERT_EQ(3U, certs.size()); | 1177 ASSERT_EQ(3U, certs.size()); |
1162 | 1178 |
1163 // Construct the chain out of order. | 1179 // Construct the chain out of order. |
1164 X509Certificate::OSCertHandles intermediates; | 1180 X509Certificate::OSCertHandles intermediates; |
1165 intermediates.push_back(certs[2]->os_cert_handle()); | 1181 intermediates.push_back(certs[2]->os_cert_handle()); |
1166 intermediates.push_back(certs[1]->os_cert_handle()); | 1182 intermediates.push_back(certs[1]->os_cert_handle()); |
1167 | 1183 |
1168 ScopedTestRoot scoped_root(certs[2]); | 1184 ScopedTestRoot scoped_root(certs[2]); |
1169 | 1185 |
1170 scoped_refptr<X509Certificate> google_full_chain = | 1186 scoped_refptr<X509Certificate> google_full_chain = |
1171 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1187 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1172 intermediates); | 1188 intermediates); |
1173 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); | 1189 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
1174 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 1190 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); |
1175 | 1191 |
1176 CertVerifyResult verify_result; | 1192 CertVerifyResult verify_result; |
1177 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1193 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1178 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 1194 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
1179 EXPECT_EQ(OK, error); | 1195 EXPECT_EQ(OK, error); |
1180 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1196 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1181 | 1197 |
1182 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1198 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1183 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1199 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1184 google_full_chain->os_cert_handle(), | 1200 google_full_chain->os_cert_handle(), |
1185 verify_result.verified_cert->os_cert_handle())); | 1201 verify_result.verified_cert->os_cert_handle())); |
1186 const X509Certificate::OSCertHandles& return_intermediates = | 1202 const X509Certificate::OSCertHandles& return_intermediates = |
1187 verify_result.verified_cert->GetIntermediateCertificates(); | 1203 verify_result.verified_cert->GetIntermediateCertificates(); |
1188 ASSERT_EQ(2U, return_intermediates.size()); | 1204 ASSERT_EQ(2U, return_intermediates.size()); |
1189 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1205 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
1190 certs[1]->os_cert_handle())); | 1206 certs[1]->os_cert_handle())); |
1191 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1207 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
1192 certs[2]->os_cert_handle())); | 1208 certs[2]->os_cert_handle())); |
1193 } | 1209 } |
1194 | 1210 |
1195 // Test that Verify() filters out certificates which are not related to | 1211 // Test that Verify() filters out certificates which are not related to |
1196 // or part of the certificate chain being verified. | 1212 // or part of the certificate chain being verified. |
1197 TEST(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) { | 1213 TEST_F(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) { |
1198 FilePath certs_dir = GetTestCertsDirectory(); | 1214 FilePath certs_dir = GetTestCertsDirectory(); |
1199 CertificateList certs = CreateCertificateListFromFile( | 1215 CertificateList certs = CreateCertificateListFromFile( |
1200 certs_dir, "x509_verify_results.chain.pem", | 1216 certs_dir, "x509_verify_results.chain.pem", |
1201 X509Certificate::FORMAT_AUTO); | 1217 X509Certificate::FORMAT_AUTO); |
1202 ASSERT_EQ(3U, certs.size()); | 1218 ASSERT_EQ(3U, certs.size()); |
1203 ScopedTestRoot scoped_root(certs[2]); | 1219 ScopedTestRoot scoped_root(certs[2]); |
1204 | 1220 |
1205 scoped_refptr<X509Certificate> unrelated_dod_certificate = | 1221 scoped_refptr<X509Certificate> unrelated_dod_certificate = |
1206 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); | 1222 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); |
1207 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = | 1223 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = |
1208 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); | 1224 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); |
1209 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); | 1225 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); |
1210 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); | 1226 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); |
1211 | 1227 |
1212 // Interject unrelated certificates into the list of intermediates. | 1228 // Interject unrelated certificates into the list of intermediates. |
1213 X509Certificate::OSCertHandles intermediates; | 1229 X509Certificate::OSCertHandles intermediates; |
1214 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); | 1230 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); |
1215 intermediates.push_back(certs[1]->os_cert_handle()); | 1231 intermediates.push_back(certs[1]->os_cert_handle()); |
1216 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); | 1232 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); |
1217 intermediates.push_back(certs[2]->os_cert_handle()); | 1233 intermediates.push_back(certs[2]->os_cert_handle()); |
1218 | 1234 |
1219 scoped_refptr<X509Certificate> google_full_chain = | 1235 scoped_refptr<X509Certificate> google_full_chain = |
1220 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1236 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1221 intermediates); | 1237 intermediates); |
1222 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); | 1238 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
1223 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); | 1239 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); |
1224 | 1240 |
1225 CertVerifyResult verify_result; | 1241 CertVerifyResult verify_result; |
1226 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1242 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1227 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 1243 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
1228 EXPECT_EQ(OK, error); | 1244 EXPECT_EQ(OK, error); |
1229 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1245 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1230 | 1246 |
1231 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1247 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1232 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1248 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1233 google_full_chain->os_cert_handle(), | 1249 google_full_chain->os_cert_handle(), |
1234 verify_result.verified_cert->os_cert_handle())); | 1250 verify_result.verified_cert->os_cert_handle())); |
1235 const X509Certificate::OSCertHandles& return_intermediates = | 1251 const X509Certificate::OSCertHandles& return_intermediates = |
1236 verify_result.verified_cert->GetIntermediateCertificates(); | 1252 verify_result.verified_cert->GetIntermediateCertificates(); |
1237 ASSERT_EQ(2U, return_intermediates.size()); | 1253 ASSERT_EQ(2U, return_intermediates.size()); |
1238 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1254 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
1239 certs[1]->os_cert_handle())); | 1255 certs[1]->os_cert_handle())); |
1240 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1256 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
1241 certs[2]->os_cert_handle())); | 1257 certs[2]->os_cert_handle())); |
1242 } | 1258 } |
1243 | 1259 |
1244 #if defined(OS_MACOSX) | 1260 #if defined(OS_MACOSX) |
1245 TEST(X509CertificateTest, IsIssuedBy) { | 1261 TEST_F(X509CertificateTest, IsIssuedBy) { |
1246 FilePath certs_dir = GetTestCertsDirectory(); | 1262 FilePath certs_dir = GetTestCertsDirectory(); |
1247 | 1263 |
1248 // Test a client certificate from MIT. | 1264 // Test a client certificate from MIT. |
1249 scoped_refptr<X509Certificate> mit_davidben_cert( | 1265 scoped_refptr<X509Certificate> mit_davidben_cert( |
1250 ImportCertFromFile(certs_dir, "mit.davidben.der")); | 1266 ImportCertFromFile(certs_dir, "mit.davidben.der")); |
1251 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); | 1267 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); |
1252 | 1268 |
1253 CertPrincipal mit_issuer; | 1269 CertPrincipal mit_issuer; |
1254 mit_issuer.country_name = "US"; | 1270 mit_issuer.country_name = "US"; |
1255 mit_issuer.state_or_province_name = "Massachusetts"; | 1271 mit_issuer.state_or_province_name = "Massachusetts"; |
(...skipping 28 matching lines...) Expand all Loading... |
1284 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); | 1300 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); |
1285 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); | 1301 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); |
1286 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); | 1302 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); |
1287 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); | 1303 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); |
1288 } | 1304 } |
1289 #endif // defined(OS_MACOSX) | 1305 #endif // defined(OS_MACOSX) |
1290 | 1306 |
1291 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) | 1307 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
1292 // This test creates a self-signed cert from a private key and then verify the | 1308 // This test creates a self-signed cert from a private key and then verify the |
1293 // content of the certificate. | 1309 // content of the certificate. |
1294 TEST(X509CertificateTest, CreateSelfSigned) { | 1310 TEST_F(X509CertificateTest, CreateSelfSigned) { |
1295 scoped_ptr<crypto::RSAPrivateKey> private_key( | 1311 scoped_ptr<crypto::RSAPrivateKey> private_key( |
1296 crypto::RSAPrivateKey::Create(1024)); | 1312 crypto::RSAPrivateKey::Create(1024)); |
1297 scoped_refptr<X509Certificate> cert = | 1313 scoped_refptr<X509Certificate> cert = |
1298 X509Certificate::CreateSelfSigned( | 1314 X509Certificate::CreateSelfSigned( |
1299 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); | 1315 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); |
1300 | 1316 |
1301 EXPECT_EQ("subject", cert->subject().GetDisplayName()); | 1317 EXPECT_EQ("subject", cert->subject().GetDisplayName()); |
1302 EXPECT_FALSE(cert->HasExpired()); | 1318 EXPECT_FALSE(cert->HasExpired()); |
1303 | 1319 |
1304 const uint8 private_key_info[] = { | 1320 const uint8 private_key_info[] = { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); | 1407 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); |
1392 ASSERT_TRUE(private_key.get()); | 1408 ASSERT_TRUE(private_key.get()); |
1393 | 1409 |
1394 cert = X509Certificate::CreateSelfSigned( | 1410 cert = X509Certificate::CreateSelfSigned( |
1395 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); | 1411 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); |
1396 | 1412 |
1397 EXPECT_EQ("subject", cert->subject().GetDisplayName()); | 1413 EXPECT_EQ("subject", cert->subject().GetDisplayName()); |
1398 EXPECT_FALSE(cert->HasExpired()); | 1414 EXPECT_FALSE(cert->HasExpired()); |
1399 } | 1415 } |
1400 | 1416 |
1401 TEST(X509CertificateTest, GetDEREncoded) { | 1417 TEST_F(X509CertificateTest, GetDEREncoded) { |
1402 scoped_ptr<crypto::RSAPrivateKey> private_key( | 1418 scoped_ptr<crypto::RSAPrivateKey> private_key( |
1403 crypto::RSAPrivateKey::Create(1024)); | 1419 crypto::RSAPrivateKey::Create(1024)); |
1404 scoped_refptr<X509Certificate> cert = | 1420 scoped_refptr<X509Certificate> cert = |
1405 X509Certificate::CreateSelfSigned( | 1421 X509Certificate::CreateSelfSigned( |
1406 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); | 1422 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); |
1407 | 1423 |
1408 std::string der_cert; | 1424 std::string der_cert; |
1409 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), | 1425 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), |
1410 &der_cert)); | 1426 &der_cert)); |
1411 EXPECT_FALSE(der_cert.empty()); | 1427 EXPECT_FALSE(der_cert.empty()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, | 1472 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, |
1457 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, | 1473 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, |
1458 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, | 1474 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, |
1459 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, | 1475 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, |
1460 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, | 1476 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, |
1461 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, | 1477 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, |
1462 }; | 1478 }; |
1463 | 1479 |
1464 // Test that CRLSets are effective in making a certificate appear to be | 1480 // Test that CRLSets are effective in making a certificate appear to be |
1465 // revoked. | 1481 // revoked. |
1466 TEST(X509CertificateTest, CRLSet) { | 1482 TEST_F(X509CertificateTest, CRLSet) { |
1467 CertificateList certs = CreateCertificateListFromFile( | 1483 CertificateList certs = CreateCertificateListFromFile( |
1468 GetTestCertsDirectory(), | 1484 GetTestCertsDirectory(), |
1469 "googlenew.chain.pem", | 1485 "googlenew.chain.pem", |
1470 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 1486 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
1471 | 1487 |
1472 X509Certificate::OSCertHandles intermediates; | 1488 X509Certificate::OSCertHandles intermediates; |
1473 intermediates.push_back(certs[1]->os_cert_handle()); | 1489 intermediates.push_back(certs[1]->os_cert_handle()); |
1474 | 1490 |
1475 scoped_refptr<X509Certificate> google_full_chain = | 1491 scoped_refptr<X509Certificate> google_full_chain = |
1476 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1492 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1477 intermediates); | 1493 intermediates); |
1478 | 1494 |
1479 CertVerifyResult verify_result; | 1495 CertVerifyResult verify_result; |
1480 int error = google_full_chain->Verify( | 1496 int error = Verify(google_full_chain, "www.google.com", 0, NULL, |
1481 "www.google.com", 0, NULL, &verify_result); | 1497 &verify_result); |
1482 EXPECT_EQ(OK, error); | 1498 EXPECT_EQ(OK, error); |
1483 | 1499 |
1484 // First test blocking by SPKI. | 1500 // First test blocking by SPKI. |
1485 base::StringPiece crl_set_bytes( | 1501 base::StringPiece crl_set_bytes( |
1486 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), | 1502 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), |
1487 sizeof(kCRLSetThawteSPKIBlocked)); | 1503 sizeof(kCRLSetThawteSPKIBlocked)); |
1488 scoped_refptr<CRLSet> crl_set; | 1504 scoped_refptr<CRLSet> crl_set; |
1489 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); | 1505 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
1490 | 1506 |
1491 error = google_full_chain->Verify( | 1507 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
1492 "www.google.com", 0, crl_set.get(), &verify_result); | 1508 &verify_result); |
1493 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1509 EXPECT_EQ(ERR_CERT_REVOKED, error); |
1494 | 1510 |
1495 // Second, test revocation by serial number of a cert directly under the | 1511 // Second, test revocation by serial number of a cert directly under the |
1496 // root. | 1512 // root. |
1497 crl_set_bytes = base::StringPiece( | 1513 crl_set_bytes = base::StringPiece( |
1498 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), | 1514 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), |
1499 sizeof(kCRLSetThawteSerialBlocked)); | 1515 sizeof(kCRLSetThawteSerialBlocked)); |
1500 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); | 1516 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
1501 | 1517 |
1502 error = google_full_chain->Verify( | 1518 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
1503 "www.google.com", 0, crl_set.get(), &verify_result); | 1519 &verify_result); |
1504 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1520 EXPECT_EQ(ERR_CERT_REVOKED, error); |
1505 | 1521 |
1506 // Lastly, test revocation by serial number of a certificate not under the | 1522 // Lastly, test revocation by serial number of a certificate not under the |
1507 // root. | 1523 // root. |
1508 crl_set_bytes = base::StringPiece( | 1524 crl_set_bytes = base::StringPiece( |
1509 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), | 1525 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), |
1510 sizeof(kCRLSetGoogleSerialBlocked)); | 1526 sizeof(kCRLSetGoogleSerialBlocked)); |
1511 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); | 1527 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
1512 | 1528 |
1513 error = google_full_chain->Verify( | 1529 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
1514 "www.google.com", 0, crl_set.get(), &verify_result); | 1530 &verify_result); |
1515 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1531 EXPECT_EQ(ERR_CERT_REVOKED, error); |
1516 } | 1532 } |
1517 #endif | 1533 #endif |
1518 | 1534 |
1519 class X509CertificateParseTest | 1535 class X509CertificateParseTest |
1520 : public testing::TestWithParam<CertificateFormatTestData> { | 1536 : public testing::TestWithParam<CertificateFormatTestData> { |
1521 public: | 1537 public: |
1522 virtual ~X509CertificateParseTest() {} | 1538 virtual ~X509CertificateParseTest() {} |
1523 virtual void SetUp() { | 1539 virtual void SetUp() { |
1524 test_data_ = GetParam(); | 1540 test_data_ = GetParam(); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 // attempt to print out the first twenty bytes of the object, which depending | 1808 // attempt to print out the first twenty bytes of the object, which depending |
1793 // on platform and alignment, may result in an invalid read. | 1809 // on platform and alignment, may result in an invalid read. |
1794 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { | 1810 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { |
1795 *os << "root: " | 1811 *os << "root: " |
1796 << (data.root_cert_filename ? data.root_cert_filename : "none") | 1812 << (data.root_cert_filename ? data.root_cert_filename : "none") |
1797 << "; intermediate: " << data.intermediate_cert_filename | 1813 << "; intermediate: " << data.intermediate_cert_filename |
1798 << "; end-entity: " << data.ee_cert_filename; | 1814 << "; end-entity: " << data.ee_cert_filename; |
1799 } | 1815 } |
1800 | 1816 |
1801 class X509CertificateWeakDigestTest | 1817 class X509CertificateWeakDigestTest |
1802 : public testing::TestWithParam<WeakDigestTestData> { | 1818 : public X509CertificateTest, |
| 1819 public testing::WithParamInterface<WeakDigestTestData> { |
1803 public: | 1820 public: |
1804 X509CertificateWeakDigestTest() {} | 1821 X509CertificateWeakDigestTest() {} |
1805 virtual ~X509CertificateWeakDigestTest() {} | 1822 virtual ~X509CertificateWeakDigestTest() {} |
1806 }; | 1823 }; |
1807 | 1824 |
1808 TEST_P(X509CertificateWeakDigestTest, Verify) { | 1825 TEST_P(X509CertificateWeakDigestTest, Verify) { |
1809 WeakDigestTestData data = GetParam(); | 1826 WeakDigestTestData data = GetParam(); |
1810 FilePath certs_dir = GetTestCertsDirectory(); | 1827 FilePath certs_dir = GetTestCertsDirectory(); |
1811 | 1828 |
1812 ScopedTestRoot test_root; | 1829 ScopedTestRoot test_root; |
(...skipping 14 matching lines...) Expand all Loading... |
1827 X509Certificate::OSCertHandles intermediates; | 1844 X509Certificate::OSCertHandles intermediates; |
1828 intermediates.push_back(intermediate_cert->os_cert_handle()); | 1845 intermediates.push_back(intermediate_cert->os_cert_handle()); |
1829 | 1846 |
1830 scoped_refptr<X509Certificate> ee_chain = | 1847 scoped_refptr<X509Certificate> ee_chain = |
1831 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 1848 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), |
1832 intermediates); | 1849 intermediates); |
1833 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); | 1850 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); |
1834 | 1851 |
1835 int flags = 0; | 1852 int flags = 0; |
1836 CertVerifyResult verify_result; | 1853 CertVerifyResult verify_result; |
1837 int rv = ee_chain->Verify("127.0.0.1", flags, NULL, &verify_result); | 1854 int rv = Verify(ee_chain, "127.0.0.1", flags, NULL, &verify_result); |
1838 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); | 1855 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); |
1839 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); | 1856 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); |
1840 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); | 1857 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); |
1841 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); | 1858 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); |
1842 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); | 1859 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); |
1843 | 1860 |
1844 // Ensure that MD4 and MD2 are tagged as invalid. | 1861 // Ensure that MD4 and MD2 are tagged as invalid. |
1845 if (data.expected_has_md4 || data.expected_has_md2) { | 1862 if (data.expected_has_md4 || data.expected_has_md2) { |
1846 EXPECT_EQ(CERT_STATUS_INVALID, | 1863 EXPECT_EQ(CERT_STATUS_INVALID, |
1847 verify_result.cert_status & CERT_STATUS_INVALID); | 1864 verify_result.cert_status & CERT_STATUS_INVALID); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 #define MAYBE_VerifyMixed DISABLED_VerifyMixed | 2018 #define MAYBE_VerifyMixed DISABLED_VerifyMixed |
2002 #else | 2019 #else |
2003 #define MAYBE_VerifyMixed VerifyMixed | 2020 #define MAYBE_VerifyMixed VerifyMixed |
2004 #endif | 2021 #endif |
2005 WRAPPED_INSTANTIATE_TEST_CASE_P( | 2022 WRAPPED_INSTANTIATE_TEST_CASE_P( |
2006 MAYBE_VerifyMixed, | 2023 MAYBE_VerifyMixed, |
2007 X509CertificateWeakDigestTest, | 2024 X509CertificateWeakDigestTest, |
2008 testing::ValuesIn(kVerifyMixedTestData)); | 2025 testing::ValuesIn(kVerifyMixedTestData)); |
2009 | 2026 |
2010 } // namespace net | 2027 } // namespace net |
OLD | NEW |