Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, NULL); |
|
Ryan Sleevi
2017/03/31 14:51:34
nullptr ;)
elawrence
2017/03/31 16:09:41
Done.
| |
| 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 // If the certificate contains multiple DNS names, we choose the most |
| 47 break; | 41 // representative one -- either the DNS name that's also in the subject |
| 42 // field, or the first one. If this heuristic turns out to be | |
| 43 // inadequate, we can consider choosing the DNS name that is the | |
| 44 // "closest match" to the host name in the request URL, or listing all | |
| 45 // the DNS names with an HTML <ul>. | |
| 46 for (; i < dns_names.size(); ++i) { | |
| 47 if (dns_names[i] == cert->subject().common_name) | |
| 48 break; | |
| 49 } | |
| 50 if (i == dns_names.size()) | |
| 51 i = 0; | |
| 52 } else { | |
| 53 // The certificate had no DNS names, use an empty string for display. | |
| 54 dns_names.push_back("\"missing_subjectAltName\""); | |
|
Ryan Sleevi
2017/03/31 14:51:34
readability suggestion: It's usually easier to put
elawrence
2017/03/31 16:09:41
Swapped. (Heh. That's how I had it originally, the
| |
| 48 } | 55 } |
| 49 if (i == dns_names.size()) | 56 |
| 50 i = 0; | |
| 51 details = l10n_util::GetStringFUTF16( | 57 details = l10n_util::GetStringFUTF16( |
| 52 IDS_CERT_ERROR_COMMON_NAME_INVALID_DETAILS, | 58 IDS_CERT_ERROR_COMMON_NAME_INVALID_DETAILS, |
| 53 UTF8ToUTF16(request_url.host()), | 59 UTF8ToUTF16(request_url.host()), |
| 54 net::EscapeForHTML(UTF8ToUTF16(dns_names[i]))); | 60 net::EscapeForHTML(UTF8ToUTF16(dns_names[i]))); |
| 55 short_description = l10n_util::GetStringUTF16( | 61 short_description = l10n_util::GetStringUTF16( |
| 56 IDS_CERT_ERROR_COMMON_NAME_INVALID_DESCRIPTION); | 62 IDS_CERT_ERROR_COMMON_NAME_INVALID_DESCRIPTION); |
| 57 break; | 63 break; |
| 58 } | 64 } |
| 59 case CERT_DATE_INVALID: | 65 case CERT_DATE_INVALID: |
| 60 if (cert->HasExpired()) { | 66 if (cert->HasExpired()) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 258 |
| 253 for (size_t i = 0; i < arraysize(kErrorFlags); ++i) { | 259 for (size_t i = 0; i < arraysize(kErrorFlags); ++i) { |
| 254 if ((cert_status & kErrorFlags[i]) && errors) { | 260 if ((cert_status & kErrorFlags[i]) && errors) { |
| 255 errors->push_back( | 261 errors->push_back( |
| 256 ErrorInfo::CreateError(kErrorTypes[i], cert.get(), url)); | 262 ErrorInfo::CreateError(kErrorTypes[i], cert.get(), url)); |
| 257 } | 263 } |
| 258 } | 264 } |
| 259 } | 265 } |
| 260 | 266 |
| 261 } // namespace ssl_errors | 267 } // namespace ssl_errors |
| OLD | NEW |