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 "chrome/browser/ssl/chrome_security_state_model_client.h" | 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 14 #include "build/build_config.h" |
12 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 15 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
13 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 16 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
16 #include "content/public/browser/cert_store.h" | 19 #include "content/public/browser/cert_store.h" |
17 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/security_style_explanation.h" | 21 #include "content/public/browser/security_style_explanation.h" |
19 #include "content/public/browser/security_style_explanations.h" | 22 #include "content/public/browser/security_style_explanations.h" |
20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/origin_util.h" | 24 #include "content/public/common/origin_util.h" |
22 #include "content/public/common/ssl_status.h" | 25 #include "content/public/common/ssl_status.h" |
23 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
24 #include "net/cert/x509_certificate.h" | 27 #include "net/cert/x509_certificate.h" |
| 28 #include "net/ssl/ssl_cipher_suite_names.h" |
| 29 #include "net/ssl/ssl_connection_status_flags.h" |
25 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
26 | 31 |
27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModelClient); | 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModelClient); |
28 | 33 |
29 using security_state::SecurityStateModel; | 34 using security_state::SecurityStateModel; |
30 | 35 |
31 namespace { | 36 namespace { |
32 | 37 |
33 // Converts a content::SecurityStyle (an indicator of a request's | 38 // Converts a content::SecurityStyle (an indicator of a request's |
34 // overall security level computed by //content) into a | 39 // overall security level computed by //content) into a |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 case SecurityStateModel::SECURE: | 75 case SecurityStateModel::SECURE: |
71 return content::SECURITY_STYLE_AUTHENTICATED; | 76 return content::SECURITY_STYLE_AUTHENTICATED; |
72 case SecurityStateModel::SECURITY_ERROR: | 77 case SecurityStateModel::SECURITY_ERROR: |
73 return content::SECURITY_STYLE_AUTHENTICATION_BROKEN; | 78 return content::SECURITY_STYLE_AUTHENTICATION_BROKEN; |
74 } | 79 } |
75 | 80 |
76 NOTREACHED(); | 81 NOTREACHED(); |
77 return content::SECURITY_STYLE_UNKNOWN; | 82 return content::SECURITY_STYLE_UNKNOWN; |
78 } | 83 } |
79 | 84 |
| 85 void AddConnectionExplanation( |
| 86 const security_state::SecurityStateModel::SecurityInfo& security_info, |
| 87 content::SecurityStyleExplanations* security_style_explanations) { |
| 88 int ssl_version = |
| 89 net::SSLConnectionStatusToVersion(security_info.connection_status); |
| 90 const char* protocol; |
| 91 net::SSLVersionToString(&protocol, ssl_version); |
| 92 const char* key_exchange; |
| 93 const char* cipher; |
| 94 const char* mac; |
| 95 bool is_aead; |
| 96 uint16_t cipher_suite = |
| 97 net::SSLConnectionStatusToCipherSuite(security_info.connection_status); |
| 98 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, |
| 99 cipher_suite); |
| 100 base::string16 protocol_name = base::ASCIIToUTF16(protocol); |
| 101 base::string16 key_exchange_name = base::ASCIIToUTF16(key_exchange); |
| 102 const base::string16 cipher_name = |
| 103 (mac == NULL) ? base::ASCIIToUTF16(cipher) |
| 104 : l10n_util::GetStringFUTF16(IDS_CIPHER_WITH_MAC, |
| 105 base::ASCIIToUTF16(cipher), |
| 106 base::ASCIIToUTF16(mac)); |
| 107 if (security_info.obsolete_ssl_status == net::OBSOLETE_SSL_NONE) { |
| 108 security_style_explanations->secure_explanations.push_back( |
| 109 content::SecurityStyleExplanation( |
| 110 l10n_util::GetStringUTF8(IDS_STRONG_SSL_SUMMARY), |
| 111 l10n_util::GetStringFUTF8(IDS_STRONG_SSL_DESCRIPTION, protocol_name, |
| 112 key_exchange_name, cipher_name))); |
| 113 return; |
| 114 } |
| 115 |
| 116 // Avoid showing TLS details when we couldn't even establish a TLS connection |
| 117 // (e.g. for net errors). We check the |cert_id| to see if there was a |
| 118 // connection. |
| 119 if (security_info.cert_id == 0) { |
| 120 return; |
| 121 } |
| 122 |
| 123 std::vector<base::string16> description_replacements; |
| 124 int status = security_info.obsolete_ssl_status; |
| 125 int str_id; |
| 126 |
| 127 str_id = (status & net::OBSOLETE_SSL_MASK_PROTOCOL) |
| 128 ? IDS_SSL_AN_OBSOLETE_PROTOCOL |
| 129 : IDS_SSL_A_STRONG_PROTOCOL; |
| 130 description_replacements.push_back(l10n_util::GetStringUTF16(str_id)); |
| 131 description_replacements.push_back(protocol_name); |
| 132 |
| 133 str_id = (status & net::OBSOLETE_SSL_MASK_KEY_EXCHANGE) |
| 134 ? IDS_SSL_AN_OBSOLETE_KEY_EXCHANGE |
| 135 : IDS_SSL_A_STRONG_KEY_EXCHANGE; |
| 136 description_replacements.push_back(l10n_util::GetStringUTF16(str_id)); |
| 137 description_replacements.push_back(key_exchange_name); |
| 138 |
| 139 str_id = (status & net::OBSOLETE_SSL_MASK_CIPHER) ? IDS_SSL_AN_OBSOLETE_CIPHER |
| 140 : IDS_SSL_A_STRONG_CIPHER; |
| 141 description_replacements.push_back(l10n_util::GetStringUTF16(str_id)); |
| 142 description_replacements.push_back(cipher_name); |
| 143 |
| 144 security_style_explanations->info_explanations.push_back( |
| 145 content::SecurityStyleExplanation( |
| 146 l10n_util::GetStringUTF8(IDS_OBSOLETE_SSL_SUMMARY), |
| 147 base::UTF16ToUTF8( |
| 148 l10n_util::GetStringFUTF16(IDS_OBSOLETE_SSL_DESCRIPTION, |
| 149 description_replacements, nullptr)))); |
| 150 } |
| 151 |
80 } // namespace | 152 } // namespace |
81 | 153 |
82 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( | 154 ChromeSecurityStateModelClient::ChromeSecurityStateModelClient( |
83 content::WebContents* web_contents) | 155 content::WebContents* web_contents) |
84 : web_contents_(web_contents), | 156 : web_contents_(web_contents), |
85 security_state_model_(new SecurityStateModel()) { | 157 security_state_model_(new SecurityStateModel()) { |
86 security_state_model_->SetClient(this); | 158 security_state_model_->SetClient(this); |
87 } | 159 } |
88 | 160 |
89 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} | 161 ChromeSecurityStateModelClient::~ChromeSecurityStateModelClient() {} |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 SecurityStateModel::NO_DEPRECATED_SHA1) { | 237 SecurityStateModel::NO_DEPRECATED_SHA1) { |
166 security_style_explanations->secure_explanations.push_back( | 238 security_style_explanations->secure_explanations.push_back( |
167 content::SecurityStyleExplanation( | 239 content::SecurityStyleExplanation( |
168 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), | 240 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), |
169 l10n_util::GetStringUTF8( | 241 l10n_util::GetStringUTF8( |
170 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION), | 242 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION), |
171 security_info.cert_id)); | 243 security_info.cert_id)); |
172 } | 244 } |
173 } | 245 } |
174 | 246 |
175 if (security_info.is_secure_protocol_and_ciphersuite) { | 247 AddConnectionExplanation(security_info, security_style_explanations); |
176 security_style_explanations->secure_explanations.push_back( | |
177 content::SecurityStyleExplanation( | |
178 l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE), | |
179 l10n_util::GetStringUTF8( | |
180 IDS_SECURE_PROTOCOL_AND_CIPHERSUITE_DESCRIPTION))); | |
181 } | |
182 | 248 |
183 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed; | 249 security_style_explanations->pkp_bypassed = security_info.pkp_bypassed; |
184 if (security_info.pkp_bypassed) { | 250 if (security_info.pkp_bypassed) { |
185 security_style_explanations->info_explanations.push_back( | 251 security_style_explanations->info_explanations.push_back( |
186 content::SecurityStyleExplanation( | 252 content::SecurityStyleExplanation( |
187 "Public-Key Pinning Bypassed", | 253 "Public-Key Pinning Bypassed", |
188 "Public-key pinning was bypassed by a local root certificate.")); | 254 "Public-key pinning was bypassed by a local root certificate.")); |
189 } | 255 } |
190 | 256 |
191 return security_style; | 257 return security_style; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 ssl.sct_statuses.begin(), | 312 ssl.sct_statuses.begin(), |
247 ssl.sct_statuses.end()); | 313 ssl.sct_statuses.end()); |
248 state->displayed_mixed_content = | 314 state->displayed_mixed_content = |
249 (ssl.content_status & content::SSLStatus::DISPLAYED_INSECURE_CONTENT) | 315 (ssl.content_status & content::SSLStatus::DISPLAYED_INSECURE_CONTENT) |
250 ? true | 316 ? true |
251 : false; | 317 : false; |
252 state->ran_mixed_content = | 318 state->ran_mixed_content = |
253 (ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT) ? true | 319 (ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT) ? true |
254 : false; | 320 : false; |
255 } | 321 } |
OLD | NEW |