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

Side by Side Diff: net/cert/cert_verify_proc.cc

Issue 2627523002: Refactor the assignment of CertVerifyResult::has_md2, etc. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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
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 weak signature hash fields of |verify_result| to true if
373 // applicable for |cert|, otherwise does not modify them.
374 void FillCertVerifyResultWeakHashAlgorithms(X509Certificate::OSCertHandle cert,
375 bool is_leaf,
Ryan Sleevi 2017/01/10 01:53:24 Two suggested changes: 1) It seems like using the
eroman 2017/01/10 02:48:46 Done.
376 CertVerifyResult* verify_result) {
377 X509Certificate::SignatureHashAlgorithm hash =
378 X509Certificate::GetSignatureHashAlgorithm(cert);
379 switch (hash) {
380 case X509Certificate::kSignatureHashAlgorithmMd2:
381 verify_result->has_md2 = true;
382 break;
383 case X509Certificate::kSignatureHashAlgorithmMd4:
384 verify_result->has_md4 = true;
385 break;
386 case X509Certificate::kSignatureHashAlgorithmMd5:
387 verify_result->has_md5 = true;
388 break;
389 case X509Certificate::kSignatureHashAlgorithmSha1:
390 verify_result->has_sha1 = true;
391 if (is_leaf)
392 verify_result->has_sha1_leaf = true;
393 break;
394 case X509Certificate::kSignatureHashAlgorithmOther:
395 break;
396 }
397 }
398
399 // Fills in the booleans on |verify_result| relating to weak hashing algorithms
400 // used by the certificate chain:
401 void CheckWeakHashAlgorithms(CertVerifyResult* verify_result) {
Ryan Sleevi 2017/01/10 01:53:24 Naming wise, I think CheckWeakHashAlgorithms and F
eroman 2017/01/10 02:48:46 Done.
402 const X509Certificate::OSCertHandles& intermediates =
403 verify_result->verified_cert->GetIntermediateCertificates();
404
405 // Consider weak hash algorithms in all certificates except trusted
406 // certificates.
407 //
408 // There is some loss of information as to which certificate is the trust
409 // anchor:
410 //
411 // * If verification was successful, and |!intermediates.empty()|, the trust
412 // anchor is |intermediates.back()|.
413 //
414 // * If verification was successful, and |intermediates.empty()|, the leaf
415 // certificate is trusted.
416 //
417 // * However, if verification was not successful, there may or may not be a
418 // trust anchor.
419 //
420 // The following code assumes that the final certificate in the chain is the
421 // trust anchor (which may not be true for the case of failed verifications,
422 // when a partial chain was returned).
423 //
424 // This inaccuracy should not be harmful, as it just impacts the final error.
425 if (!intermediates.empty()) {
Ryan Sleevi 2017/01/10 01:53:24 Does it make sense to make this error-short circui
eroman 2017/01/10 02:48:46 Done.
426 for (size_t i = 0; i + 1 < intermediates.size(); ++i) {
427 FillCertVerifyResultWeakHashAlgorithms(intermediates[i],
428 false /*is_leaf*/, verify_result);
429 }
430
431 FillCertVerifyResultWeakHashAlgorithms(
432 verify_result->verified_cert->os_cert_handle(), true /*is_leaf*/,
433 verify_result);
434 }
435 }
436
372 } // namespace 437 } // namespace
373 438
374 // static 439 // static
375 CertVerifyProc* CertVerifyProc::CreateDefault() { 440 CertVerifyProc* CertVerifyProc::CreateDefault() {
376 #if defined(USE_NSS_CERTS) 441 #if defined(USE_NSS_CERTS)
377 return new CertVerifyProcNSS(); 442 return new CertVerifyProcNSS();
378 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) 443 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
379 return new CertVerifyProcOpenSSL(); 444 return new CertVerifyProcOpenSSL();
380 #elif defined(OS_ANDROID) 445 #elif defined(OS_ANDROID)
381 return new CertVerifyProcAndroid(); 446 return new CertVerifyProcAndroid();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // We do online revocation checking for EV certificates that aren't covered 478 // We do online revocation checking for EV certificates that aren't covered
414 // by a fresh CRLSet. 479 // by a fresh CRLSet.
415 // TODO(rsleevi): http://crbug.com/142974 - Allow preferences to fully 480 // TODO(rsleevi): http://crbug.com/142974 - Allow preferences to fully
416 // disable revocation checking. 481 // disable revocation checking.
417 if (flags & CertVerifier::VERIFY_EV_CERT) 482 if (flags & CertVerifier::VERIFY_EV_CERT)
418 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED_EV_ONLY; 483 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED_EV_ONLY;
419 484
420 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, 485 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set,
421 additional_trust_anchors, verify_result); 486 additional_trust_anchors, verify_result);
422 487
488 // Fill in verify_result->has_md2 and related booleans early so that
489 // subsequent code can rely on it being meaningful.
Ryan Sleevi 2017/01/10 01:53:24 Seems like an unnecessary comment (or perhaps unne
eroman 2017/01/10 02:48:46 Done.
490 CheckWeakHashAlgorithms(verify_result);
491
423 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", 492 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback",
424 verify_result->common_name_fallback_used); 493 verify_result->common_name_fallback_used);
425 if (!verify_result->is_issued_by_known_root) { 494 if (!verify_result->is_issued_by_known_root) {
426 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", 495 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA",
427 verify_result->common_name_fallback_used); 496 verify_result->common_name_fallback_used);
428 } 497 }
429 498
430 CheckOCSP(ocsp_response, *verify_result->verified_cert, 499 CheckOCSP(ocsp_response, *verify_result->verified_cert,
431 &verify_result->ocsp_result); 500 &verify_result->ocsp_result);
432 501
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 if (start >= time_2015_04_01 && month_diff > 39) 836 if (start >= time_2015_04_01 && month_diff > 39)
768 return true; 837 return true;
769 838
770 return false; 839 return false;
771 } 840 }
772 841
773 // static 842 // static
774 const base::Feature CertVerifyProc::kSHA1LegacyMode{ 843 const base::Feature CertVerifyProc::kSHA1LegacyMode{
775 "SHA1LegacyMode", base::FEATURE_DISABLED_BY_DEFAULT}; 844 "SHA1LegacyMode", base::FEATURE_DISABLED_BY_DEFAULT};
776 845
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 846 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698