Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 !(pattern_begin.empty() && pattern_end.empty())) | 569 !(pattern_begin.empty() && pattern_end.empty())) |
| 570 continue; | 570 continue; |
| 571 | 571 |
| 572 if (reference_host.starts_with(pattern_begin) && | 572 if (reference_host.starts_with(pattern_begin) && |
| 573 reference_host.ends_with(pattern_end)) | 573 reference_host.ends_with(pattern_end)) |
| 574 return true; | 574 return true; |
| 575 } | 575 } |
| 576 return false; | 576 return false; |
| 577 } | 577 } |
| 578 | 578 |
| 579 static bool IsWeakKey(X509Certificate::PublicKeyType type, size_t size_bits) { | |
|
Ryan Sleevi
2011/12/13 05:45:35
nit: Given that this file makes use of an unnamed
| |
| 580 return size_bits < 1024 && | |
| 581 (type == X509Certificate::kPublicKeyTypeRSA || | |
| 582 type == X509Certificate::kPublicKeyTypeDSA); | |
| 583 } | |
| 584 | |
| 579 int X509Certificate::Verify(const std::string& hostname, | 585 int X509Certificate::Verify(const std::string& hostname, |
| 580 int flags, | 586 int flags, |
| 581 CRLSet* crl_set, | 587 CRLSet* crl_set, |
| 582 CertVerifyResult* verify_result) const { | 588 CertVerifyResult* verify_result) const { |
| 583 verify_result->Reset(); | 589 verify_result->Reset(); |
| 584 verify_result->verified_cert = const_cast<X509Certificate*>(this); | 590 verify_result->verified_cert = const_cast<X509Certificate*>(this); |
| 585 | 591 |
| 586 if (IsBlacklisted()) { | 592 if (IsBlacklisted()) { |
| 587 verify_result->cert_status |= CERT_STATUS_REVOKED; | 593 verify_result->cert_status |= CERT_STATUS_REVOKED; |
| 588 return ERR_CERT_REVOKED; | 594 return ERR_CERT_REVOKED; |
| 589 } | 595 } |
| 590 | 596 |
| 591 int rv = VerifyInternal(hostname, flags, crl_set, verify_result); | 597 int rv = VerifyInternal(hostname, flags, crl_set, verify_result); |
| 592 | 598 |
| 599 // Check for weak keys in the entire verified chain. | |
| 600 size_t size_bits = 0; | |
| 601 PublicKeyType type = kPublicKeyTypeUnknown; | |
| 602 bool weak_key = false; | |
| 603 | |
| 604 GetPublicKeyInfo(verify_result->verified_cert->os_cert_handle(), &size_bits, | |
| 605 &type); | |
| 606 if (IsWeakKey(type, size_bits)) { | |
| 607 weak_key = true; | |
| 608 } else { | |
| 609 const OSCertHandles& intermediates = | |
| 610 verify_result->verified_cert->GetIntermediateCertificates(); | |
| 611 for (OSCertHandles::const_iterator i = intermediates.begin(); | |
| 612 i != intermediates.end(); ++i) { | |
| 613 GetPublicKeyInfo(*i, &size_bits, &type); | |
| 614 if (IsWeakKey(type, size_bits)) | |
| 615 weak_key = true; | |
| 616 } | |
| 617 } | |
| 618 | |
| 619 if (weak_key) { | |
| 620 verify_result->cert_status |= CERT_STATUS_WEAK_KEY; | |
| 621 return MapCertStatusToNetError(verify_result->cert_status); | |
| 622 } | |
| 623 | |
| 593 // This check is done after VerifyInternal so that VerifyInternal can fill in | 624 // This check is done after VerifyInternal so that VerifyInternal can fill in |
| 594 // the list of public key hashes. | 625 // the list of public key hashes. |
| 595 if (IsPublicKeyBlacklisted(verify_result->public_key_hashes)) { | 626 if (IsPublicKeyBlacklisted(verify_result->public_key_hashes)) { |
| 596 verify_result->cert_status |= CERT_STATUS_REVOKED; | 627 verify_result->cert_status |= CERT_STATUS_REVOKED; |
| 597 rv = MapCertStatusToNetError(verify_result->cert_status); | 628 rv = MapCertStatusToNetError(verify_result->cert_status); |
| 598 } | 629 } |
| 599 | 630 |
| 600 return rv; | 631 return rv; |
| 601 } | 632 } |
| 602 | 633 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 bool X509Certificate::IsSHA1HashInSortedArray(const SHA1Fingerprint& hash, | 829 bool X509Certificate::IsSHA1HashInSortedArray(const SHA1Fingerprint& hash, |
| 799 const uint8* array, | 830 const uint8* array, |
| 800 size_t array_byte_len) { | 831 size_t array_byte_len) { |
| 801 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); | 832 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); |
| 802 const size_t arraylen = array_byte_len / base::kSHA1Length; | 833 const size_t arraylen = array_byte_len / base::kSHA1Length; |
| 803 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, | 834 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, |
| 804 CompareSHA1Hashes); | 835 CompareSHA1Hashes); |
| 805 } | 836 } |
| 806 | 837 |
| 807 } // namespace net | 838 } // namespace net |
| OLD | NEW |