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. | |
Ryan Sleevi
2017/01/10 03:00:41
"then the leaf is trusted or verification failed."
eroman
2017/01/10 03:06:12
Done.
| |
414 if (intermediates.empty()) | |
415 return; | |
416 | |
417 DCHECK(!verify_result->has_sha1); | |
418 | |
419 // Fill in hash algorithms for the leaf certificate. | |
420 MapHashAlgorithmToBool(X509Certificate::GetSignatureHashAlgorithm( | |
421 verify_result->verified_cert->os_cert_handle()), | |
422 verify_result); | |
423 verify_result->has_sha1_leaf = verify_result->has_sha1; | |
424 | |
425 // Fill in hash algorithms for the intermediate cerificates, excluding the | |
426 // final one (which is the trust anchor). | |
427 for (size_t i = 0; i + 1 < intermediates.size(); ++i) { | |
428 MapHashAlgorithmToBool( | |
429 X509Certificate::GetSignatureHashAlgorithm(intermediates[i]), | |
430 verify_result); | |
431 } | |
432 } | |
433 | |
372 } // namespace | 434 } // namespace |
373 | 435 |
374 // static | 436 // static |
375 CertVerifyProc* CertVerifyProc::CreateDefault() { | 437 CertVerifyProc* CertVerifyProc::CreateDefault() { |
376 #if defined(USE_NSS_CERTS) | 438 #if defined(USE_NSS_CERTS) |
377 return new CertVerifyProcNSS(); | 439 return new CertVerifyProcNSS(); |
378 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | 440 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) |
379 return new CertVerifyProcOpenSSL(); | 441 return new CertVerifyProcOpenSSL(); |
380 #elif defined(OS_ANDROID) | 442 #elif defined(OS_ANDROID) |
381 return new CertVerifyProcAndroid(); | 443 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 | 475 // We do online revocation checking for EV certificates that aren't covered |
414 // by a fresh CRLSet. | 476 // by a fresh CRLSet. |
415 // TODO(rsleevi): http://crbug.com/142974 - Allow preferences to fully | 477 // TODO(rsleevi): http://crbug.com/142974 - Allow preferences to fully |
416 // disable revocation checking. | 478 // disable revocation checking. |
417 if (flags & CertVerifier::VERIFY_EV_CERT) | 479 if (flags & CertVerifier::VERIFY_EV_CERT) |
418 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED_EV_ONLY; | 480 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED_EV_ONLY; |
419 | 481 |
420 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, | 482 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, |
421 additional_trust_anchors, verify_result); | 483 additional_trust_anchors, verify_result); |
422 | 484 |
485 ComputeSignatureHashAlgorithms(verify_result); | |
486 | |
423 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", | 487 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", |
424 verify_result->common_name_fallback_used); | 488 verify_result->common_name_fallback_used); |
425 if (!verify_result->is_issued_by_known_root) { | 489 if (!verify_result->is_issued_by_known_root) { |
426 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", | 490 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", |
427 verify_result->common_name_fallback_used); | 491 verify_result->common_name_fallback_used); |
428 } | 492 } |
429 | 493 |
430 CheckOCSP(ocsp_response, *verify_result->verified_cert, | 494 CheckOCSP(ocsp_response, *verify_result->verified_cert, |
431 &verify_result->ocsp_result); | 495 &verify_result->ocsp_result); |
432 | 496 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 if (start >= time_2015_04_01 && month_diff > 39) | 831 if (start >= time_2015_04_01 && month_diff > 39) |
768 return true; | 832 return true; |
769 | 833 |
770 return false; | 834 return false; |
771 } | 835 } |
772 | 836 |
773 // static | 837 // static |
774 const base::Feature CertVerifyProc::kSHA1LegacyMode{ | 838 const base::Feature CertVerifyProc::kSHA1LegacyMode{ |
775 "SHA1LegacyMode", base::FEATURE_DISABLED_BY_DEFAULT}; | 839 "SHA1LegacyMode", base::FEATURE_DISABLED_BY_DEFAULT}; |
776 | 840 |
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 | 841 } // namespace net |
OLD | NEW |