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

Side by Side Diff: net/base/x509_certificate.cc

Issue 8438024: Revert 107679 - Broke https for appspot.com - http://crbug.com/102507 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/x509_certificate_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/pickle.h" 18 #include "base/pickle.h"
19 #include "base/sha1.h" 19 #include "base/sha1.h"
20 #include "base/string_piece.h" 20 #include "base/string_piece.h"
21 #include "base/string_util.h" 21 #include "base/string_util.h"
22 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
23 #include "base/time.h" 23 #include "base/time.h"
24 #include "googleurl/src/url_canon_ip.h" 24 #include "googleurl/src/url_canon_ip.h"
25 #include "net/base/cert_status_flags.h" 25 #include "net/base/cert_status_flags.h"
26 #include "net/base/cert_verify_result.h" 26 #include "net/base/cert_verify_result.h"
27 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
28 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
29 #include "net/base/pem_tokenizer.h" 29 #include "net/base/pem_tokenizer.h"
30 #include "net/base/registry_controlled_domain.h"
31 30
32 namespace net { 31 namespace net {
33 32
34 namespace { 33 namespace {
35 34
36 // Indicates the order to use when trying to decode binary data, which is 35 // Indicates the order to use when trying to decode binary data, which is
37 // based on (speculation) as to what will be most common -> least common 36 // based on (speculation) as to what will be most common -> least common
38 const X509Certificate::Format kFormatDecodePriority[] = { 37 const X509Certificate::Format kFormatDecodePriority[] = {
39 X509Certificate::FORMAT_SINGLE_CERTIFICATE, 38 X509Certificate::FORMAT_SINGLE_CERTIFICATE,
40 X509Certificate::FORMAT_PKCS7 39 X509Certificate::FORMAT_PKCS7
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 base::StringPiece ip_addr_string( 501 base::StringPiece ip_addr_string(
503 reinterpret_cast<const char*>(host_info.address), 502 reinterpret_cast<const char*>(host_info.address),
504 host_info.AddressLength()); 503 host_info.AddressLength());
505 return std::find(cert_san_ip_addrs.begin(), cert_san_ip_addrs.end(), 504 return std::find(cert_san_ip_addrs.begin(), cert_san_ip_addrs.end(),
506 ip_addr_string) != cert_san_ip_addrs.end(); 505 ip_addr_string) != cert_san_ip_addrs.end();
507 } 506 }
508 507
509 // |reference_domain| is the remainder of |host| after the leading host 508 // |reference_domain| is the remainder of |host| after the leading host
510 // component is stripped off, but includes the leading dot e.g. 509 // component is stripped off, but includes the leading dot e.g.
511 // "www.f.com" -> ".f.com". 510 // "www.f.com" -> ".f.com".
512 // If there is no meaningful domain part to |host| (e.g. it contains no 511 // If there is no meaningful domain part to |host| (e.g. it contains no dots)
513 // dots) then |reference_domain| will be empty. 512 // then |reference_domain| will be empty.
514 base::StringPiece reference_host, reference_domain; 513 base::StringPiece reference_host, reference_domain;
515 SplitOnChar(reference_name, '.', &reference_host, &reference_domain); 514 SplitOnChar(reference_name, '.', &reference_host, &reference_domain);
516 bool allow_wildcards = false; 515 bool allow_wildcards = false;
517 if (!reference_domain.empty()) { 516 if (!reference_domain.empty()) {
518 DCHECK(reference_domain.starts_with(".")); 517 DCHECK(reference_domain.starts_with("."));
519 518 // We required at least 3 components (i.e. 2 dots) as a basic protection
520 // Do not allow wildcards for registry controlled domains, so as to 519 // against too-broad wild-carding.
521 // prevent accepting *.com or *.co.uk as valid presented names. Passing 520 // Also we don't attempt wildcard matching on a purely numerical hostname.
522 // true for |allow_unknown_registries| so that top-level domains which are 521 allow_wildcards = reference_domain.rfind('.') != 0 &&
523 // unknown (intranet domains, new TLDs/gTLDs not yet recognized) are
524 // treated as registry-controlled domains. Because the |reference_domain|
525 // must contain at least one name component that is not registry
526 // controlled, this ensures that all reference names have at least three
527 // domain components in order to permit wildcards.
528 size_t registry_length =
529 RegistryControlledDomainService::GetRegistryLength(reference_name,
530 true);
531 // As the |reference_name| was already canonicalized, this should never
532 // happen.
533 CHECK_NE(registry_length, std::string::npos);
534
535 // Subtracting 1 to account for the leading dot in |reference_domain|.
536 bool is_registry_controlled = registry_length != 0 &&
537 registry_length == (reference_domain.size() - 1);
538
539 // Additionally, do not attempt wildcard matching for purely numeric
540 // hostnames.
541 allow_wildcards = !is_registry_controlled &&
542 reference_name.find_first_not_of("0123456789.") != std::string::npos; 522 reference_name.find_first_not_of("0123456789.") != std::string::npos;
543 } 523 }
544 524
545 // Now step through the DNS names doing wild card comparison (if necessary) 525 // Now step through the DNS names doing wild card comparison (if necessary)
546 // on each against the reference name. If subjectAltName is empty, then 526 // on each against the reference name. If subjectAltName is empty, then
547 // fallback to use the common name instead. 527 // fallback to use the common name instead.
548 std::vector<std::string> common_name_as_vector; 528 std::vector<std::string> common_name_as_vector;
549 const std::vector<std::string>* presented_names = &cert_san_dns_names; 529 const std::vector<std::string>* presented_names = &cert_san_dns_names;
550 if (common_name_fallback) { 530 if (common_name_fallback) {
551 // Note: there's a small possibility cert_common_name is an international 531 // Note: there's a small possibility cert_common_name is an international
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 bool X509Certificate::IsSHA1HashInSortedArray(const SHA1Fingerprint& hash, 757 bool X509Certificate::IsSHA1HashInSortedArray(const SHA1Fingerprint& hash,
778 const uint8* array, 758 const uint8* array,
779 size_t array_byte_len) { 759 size_t array_byte_len) {
780 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); 760 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length);
781 const size_t arraylen = array_byte_len / base::kSHA1Length; 761 const size_t arraylen = array_byte_len / base::kSHA1Length;
782 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, 762 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length,
783 CompareSHA1Hashes); 763 CompareSHA1Hashes);
784 } 764 }
785 765
786 } // namespace net 766 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/x509_certificate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698