| 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 "net/cert/cert_verify_proc.h" | 5 #include "net/cert/cert_verify_proc.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 #if defined(OS_WIN) | 362 #if defined(OS_WIN) |
| 363 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved | 363 // TODO(rsleevi): Remove this once https://crbug.com/588789 is resolved |
| 364 // for Windows 7/2008 users. | 364 // for Windows 7/2008 users. |
| 365 // Note: This must be kept in sync with cert_verify_proc_unittest.cc | 365 // Note: This must be kept in sync with cert_verify_proc_unittest.cc |
| 366 return base::win::GetVersion() < base::win::VERSION_WIN8; | 366 return base::win::GetVersion() < base::win::VERSION_WIN8; |
| 367 #else | 367 #else |
| 368 return false; | 368 return false; |
| 369 #endif | 369 #endif |
| 370 }; | 370 }; |
| 371 | 371 |
| 372 // Sets the "has_*" boolean members in |verify_result| that correspond with |
| 373 // the the presence of |hash| somewhere in the certificate chain (excluding the |
| 374 // trust anchor). |
| 375 void MapHashAlgorithmToBool(X509Certificate::SignatureHashAlgorithm hash, |
| 376 CertVerifyResult* verify_result) { |
| 377 switch (hash) { |
| 378 case X509Certificate::kSignatureHashAlgorithmMd2: |
| 379 verify_result->has_md2 = true; |
| 380 break; |
| 381 case X509Certificate::kSignatureHashAlgorithmMd4: |
| 382 verify_result->has_md4 = true; |
| 383 break; |
| 384 case X509Certificate::kSignatureHashAlgorithmMd5: |
| 385 verify_result->has_md5 = true; |
| 386 break; |
| 387 case X509Certificate::kSignatureHashAlgorithmSha1: |
| 388 verify_result->has_sha1 = true; |
| 389 break; |
| 390 case X509Certificate::kSignatureHashAlgorithmOther: |
| 391 break; |
| 392 } |
| 393 } |
| 394 |
| 395 // Sets to true the |verify_result->has_*| boolean members for the hash |
| 396 // algorithms present in the certificate chain. |
| 397 // |
| 398 // This considers the hash algorithms in all certificates except trusted |
| 399 // certificates. |
| 400 // |
| 401 // In the case of a successful verification the trust anchor is the final |
| 402 // certificate in the chain (either the final intermediate, or the leaf |
| 403 // certificate). |
| 404 // |
| 405 // Whereas if verification was uncessful, the chain may be partial, and the |
| 406 // final certificate may not be a trust anchor. This heuristic is used |
| 407 // in both successful and failed verifications, despite this ambiguity (failure |
| 408 // to tag one of the signature algorithms should only affect the final error). |
| 409 void ComputeSignatureHashAlgorithms(CertVerifyResult* verify_result) { |
| 410 const X509Certificate::OSCertHandles& intermediates = |
| 411 verify_result->verified_cert->GetIntermediateCertificates(); |
| 412 |
| 413 // If there are no intermediates, then the leaf is trusted or verification |
| 414 // failed. |
| 415 if (intermediates.empty()) |
| 416 return; |
| 417 |
| 418 DCHECK(!verify_result->has_sha1); |
| 419 |
| 420 // Fill in hash algorithms for the leaf certificate. |
| 421 MapHashAlgorithmToBool(X509Certificate::GetSignatureHashAlgorithm( |
| 422 verify_result->verified_cert->os_cert_handle()), |
| 423 verify_result); |
| 424 verify_result->has_sha1_leaf = verify_result->has_sha1; |
| 425 |
| 426 // Fill in hash algorithms for the intermediate cerificates, excluding the |
| 427 // final one (which is the trust anchor). |
| 428 for (size_t i = 0; i + 1 < intermediates.size(); ++i) { |
| 429 MapHashAlgorithmToBool( |
| 430 X509Certificate::GetSignatureHashAlgorithm(intermediates[i]), |
| 431 verify_result); |
| 432 } |
| 433 } |
| 434 |
| 372 } // namespace | 435 } // namespace |
| 373 | 436 |
| 374 // static | 437 // static |
| 375 CertVerifyProc* CertVerifyProc::CreateDefault() { | 438 CertVerifyProc* CertVerifyProc::CreateDefault() { |
| 376 #if defined(USE_NSS_CERTS) | 439 #if defined(USE_NSS_CERTS) |
| 377 return new CertVerifyProcNSS(); | 440 return new CertVerifyProcNSS(); |
| 378 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | 441 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) |
| 379 return new CertVerifyProcOpenSSL(); | 442 return new CertVerifyProcOpenSSL(); |
| 380 #elif defined(OS_ANDROID) | 443 #elif defined(OS_ANDROID) |
| 381 return new CertVerifyProcAndroid(); | 444 return new CertVerifyProcAndroid(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // We do online revocation checking for EV certificates that aren't covered | 476 // We do online revocation checking for EV certificates that aren't covered |
| 414 // by a fresh CRLSet. | 477 // by a fresh CRLSet. |
| 415 // TODO(rsleevi): http://crbug.com/142974 - Allow preferences to fully | 478 // TODO(rsleevi): http://crbug.com/142974 - Allow preferences to fully |
| 416 // disable revocation checking. | 479 // disable revocation checking. |
| 417 if (flags & CertVerifier::VERIFY_EV_CERT) | 480 if (flags & CertVerifier::VERIFY_EV_CERT) |
| 418 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED_EV_ONLY; | 481 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED_EV_ONLY; |
| 419 | 482 |
| 420 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, | 483 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, |
| 421 additional_trust_anchors, verify_result); | 484 additional_trust_anchors, verify_result); |
| 422 | 485 |
| 486 ComputeSignatureHashAlgorithms(verify_result); |
| 487 |
| 423 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", | 488 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", |
| 424 verify_result->common_name_fallback_used); | 489 verify_result->common_name_fallback_used); |
| 425 if (!verify_result->is_issued_by_known_root) { | 490 if (!verify_result->is_issued_by_known_root) { |
| 426 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", | 491 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", |
| 427 verify_result->common_name_fallback_used); | 492 verify_result->common_name_fallback_used); |
| 428 } | 493 } |
| 429 | 494 |
| 430 CheckOCSP(ocsp_response, *verify_result->verified_cert, | 495 CheckOCSP(ocsp_response, *verify_result->verified_cert, |
| 431 &verify_result->ocsp_result); | 496 &verify_result->ocsp_result); |
| 432 | 497 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 if (start >= time_2015_04_01 && month_diff > 39) | 832 if (start >= time_2015_04_01 && month_diff > 39) |
| 768 return true; | 833 return true; |
| 769 | 834 |
| 770 return false; | 835 return false; |
| 771 } | 836 } |
| 772 | 837 |
| 773 // static | 838 // static |
| 774 const base::Feature CertVerifyProc::kSHA1LegacyMode{ | 839 const base::Feature CertVerifyProc::kSHA1LegacyMode{ |
| 775 "SHA1LegacyMode", base::FEATURE_DISABLED_BY_DEFAULT}; | 840 "SHA1LegacyMode", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 776 | 841 |
| 777 X509Certificate::SignatureHashAlgorithm FillCertVerifyResultWeakSignature( | |
| 778 X509Certificate::OSCertHandle cert, | |
| 779 bool is_leaf, | |
| 780 CertVerifyResult* verify_result) { | |
| 781 X509Certificate::SignatureHashAlgorithm hash = | |
| 782 X509Certificate::GetSignatureHashAlgorithm(cert); | |
| 783 switch (hash) { | |
| 784 case X509Certificate::kSignatureHashAlgorithmMd2: | |
| 785 verify_result->has_md2 = true; | |
| 786 break; | |
| 787 case X509Certificate::kSignatureHashAlgorithmMd4: | |
| 788 verify_result->has_md4 = true; | |
| 789 break; | |
| 790 case X509Certificate::kSignatureHashAlgorithmMd5: | |
| 791 verify_result->has_md5 = true; | |
| 792 break; | |
| 793 case X509Certificate::kSignatureHashAlgorithmSha1: | |
| 794 verify_result->has_sha1 = true; | |
| 795 if (is_leaf) | |
| 796 verify_result->has_sha1_leaf = true; | |
| 797 break; | |
| 798 case X509Certificate::kSignatureHashAlgorithmOther: | |
| 799 break; | |
| 800 } | |
| 801 | |
| 802 return hash; | |
| 803 } | |
| 804 | |
| 805 } // namespace net | 842 } // namespace net |
| OLD | NEW |