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

Side by Side Diff: components/ssl_errors/error_info.cc

Issue 2777383002: Update SSL error handling code to account for Subject CN deprecation (Closed)
Patch Set: Address Mark Feedback Created 3 years, 8 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
« no previous file with comments | « components/ssl_errors/error_classification_unittest.cc ('k') | net/BUILD.gn » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/ssl_errors/error_info.h" 5 #include "components/ssl_errors/error_info.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/i18n/message_formatter.h" 9 #include "base/i18n/message_formatter.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 14 matching lines...) Expand all
25 const base::string16& short_description) 25 const base::string16& short_description)
26 : details_(details), short_description_(short_description) {} 26 : details_(details), short_description_(short_description) {}
27 27
28 // static 28 // static
29 ErrorInfo ErrorInfo::CreateError(ErrorType error_type, 29 ErrorInfo ErrorInfo::CreateError(ErrorType error_type,
30 net::X509Certificate* cert, 30 net::X509Certificate* cert,
31 const GURL& request_url) { 31 const GURL& request_url) {
32 base::string16 details, short_description; 32 base::string16 details, short_description;
33 switch (error_type) { 33 switch (error_type) {
34 case CERT_COMMON_NAME_INVALID: { 34 case CERT_COMMON_NAME_INVALID: {
35 // If the certificate contains multiple DNS names, we choose the most
36 // representative one -- either the DNS name that's also in the subject
37 // field, or the first one. If this heuristic turns out to be
38 // inadequate, we can consider choosing the DNS name that is the
39 // "closest match" to the host name in the request URL, or listing all
40 // the DNS names with an HTML <ul>.
41 std::vector<std::string> dns_names; 35 std::vector<std::string> dns_names;
42 cert->GetDNSNames(&dns_names); 36 cert->GetSubjectAltName(&dns_names, nullptr);
43 DCHECK(!dns_names.empty()); 37
44 size_t i = 0; 38 size_t i = 0;
45 for (; i < dns_names.size(); ++i) { 39 if (dns_names.empty()) {
46 if (dns_names[i] == cert->subject().common_name) 40 // The certificate had no DNS names, display an explanatory string.
47 break; 41 // TODO(elawrence): Change the error messsage instead of just the
42 // placeholder string; see https://crbug.com/708268
43 dns_names.push_back("[missing_subjectAltName]");
44 } else {
45 // If the certificate contains multiple DNS names, we choose the most
46 // representative one -- either the DNS name that's also in the subject
47 // field, or the first one. If this heuristic turns out to be
48 // inadequate, we can consider choosing the DNS name that is the
49 // "closest match" to the host name in the request URL, or listing all
50 // the DNS names with an HTML <ul>.
51 for (; i < dns_names.size(); ++i) {
52 if (dns_names[i] == cert->subject().common_name)
53 break;
54 }
55 if (i == dns_names.size())
56 i = 0;
48 } 57 }
49 if (i == dns_names.size()) 58
50 i = 0;
51 details = l10n_util::GetStringFUTF16( 59 details = l10n_util::GetStringFUTF16(
52 IDS_CERT_ERROR_COMMON_NAME_INVALID_DETAILS, 60 IDS_CERT_ERROR_COMMON_NAME_INVALID_DETAILS,
53 UTF8ToUTF16(request_url.host()), 61 UTF8ToUTF16(request_url.host()),
54 net::EscapeForHTML(UTF8ToUTF16(dns_names[i]))); 62 net::EscapeForHTML(UTF8ToUTF16(dns_names[i])));
55 short_description = l10n_util::GetStringUTF16( 63 short_description = l10n_util::GetStringUTF16(
56 IDS_CERT_ERROR_COMMON_NAME_INVALID_DESCRIPTION); 64 IDS_CERT_ERROR_COMMON_NAME_INVALID_DESCRIPTION);
57 break; 65 break;
58 } 66 }
59 case CERT_DATE_INVALID: 67 case CERT_DATE_INVALID:
60 if (cert->HasExpired()) { 68 if (cert->HasExpired()) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 260
253 for (size_t i = 0; i < arraysize(kErrorFlags); ++i) { 261 for (size_t i = 0; i < arraysize(kErrorFlags); ++i) {
254 if ((cert_status & kErrorFlags[i]) && errors) { 262 if ((cert_status & kErrorFlags[i]) && errors) {
255 errors->push_back( 263 errors->push_back(
256 ErrorInfo::CreateError(kErrorTypes[i], cert.get(), url)); 264 ErrorInfo::CreateError(kErrorTypes[i], cert.get(), url));
257 } 265 }
258 } 266 }
259 } 267 }
260 268
261 } // namespace ssl_errors 269 } // namespace ssl_errors
OLDNEW
« no previous file with comments | « components/ssl_errors/error_classification_unittest.cc ('k') | net/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698