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 "chrome/browser/tab_contents/tab_contents_ssl_helper.h" | 5 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
6 | 6 |
7 #include <string> | |
8 | |
7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | |
8 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/certificate_viewer.h" | 13 #include "chrome/browser/certificate_viewer.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
15 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ssl/ssl_add_cert_handler.h" | 16 #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
12 #include "chrome/browser/ssl_client_certificate_selector.h" | 17 #include "chrome/browser/ssl_client_certificate_selector.h" |
13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
14 #include "chrome/browser/tab_contents/infobar.h" | 19 #include "chrome/browser/tab_contents/infobar.h" |
15 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 20 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_switches.h" | |
24 #include "chrome/common/content_settings.h" | |
18 #include "content/browser/ssl/ssl_client_auth_handler.h" | 25 #include "content/browser/ssl/ssl_client_auth_handler.h" |
19 #include "content/common/notification_details.h" | 26 #include "content/common/notification_details.h" |
20 #include "content/common/notification_source.h" | 27 #include "content/common/notification_source.h" |
21 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources_standard.h" | 29 #include "grit/theme_resources_standard.h" |
23 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
24 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
26 | 33 |
27 namespace { | 34 namespace { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 178 |
172 // TabContentsSSLHelper ------------------------------------------------------- | 179 // TabContentsSSLHelper ------------------------------------------------------- |
173 | 180 |
174 TabContentsSSLHelper::TabContentsSSLHelper(TabContentsWrapper* tab_contents) | 181 TabContentsSSLHelper::TabContentsSSLHelper(TabContentsWrapper* tab_contents) |
175 : tab_contents_(tab_contents) { | 182 : tab_contents_(tab_contents) { |
176 } | 183 } |
177 | 184 |
178 TabContentsSSLHelper::~TabContentsSSLHelper() { | 185 TabContentsSSLHelper::~TabContentsSSLHelper() { |
179 } | 186 } |
180 | 187 |
188 void TabContentsSSLHelper::SelectClientCertificate( | |
189 scoped_refptr<SSLClientAuthHandler> handler) { | |
190 // Hide the auto submit certificate feature behind a cmd line flag. | |
wtc
2011/08/11 18:33:55
Nit: cmd => command
markusheintz_
2011/08/15 19:09:04
Done.
| |
191 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
192 switches::kEnableAutoSubmitCertificate)) { | |
193 ShowClientCertificateRequestDialog(handler); | |
194 return; | |
195 } | |
196 | |
197 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info(); | |
198 // TODO(markusheintz): What would be a proper scheme? I need a URL in order to | |
199 // query the HostContentSettingsMap. | |
Mattias Nissler (ping if slow)
2011/08/09 15:37:25
Maybe https:// ?
markusheintz_
2011/08/15 19:09:04
Done.
| |
200 GURL requesting_url("ssl://" + cert_request_info->host_and_port); | |
201 DCHECK(requesting_url.is_valid()) << " Invalid URL string: ssl://" | |
202 << cert_request_info->host_and_port; | |
wtc
2011/08/11 18:33:55
Use https:// instead of ssl:// on lines 200 and 20
markusheintz_
2011/08/15 19:09:04
Done.
| |
203 HostContentSettingsMap* map = | |
204 tab_contents_->profile()->GetHostContentSettingsMap(); | |
205 ContentSetting setting = map->GetContentSetting( | |
206 requesting_url, | |
207 requesting_url, | |
208 CONTENT_SETTINGS_TYPE_AUTO_SUBMIT_CERTIFICATE, | |
209 std::string()); | |
210 DCHECK(setting != CONTENT_SETTING_DEFAULT); | |
211 | |
212 // TODO(markusheintz): Implement filter for matchig specific certificate | |
213 // criterias. | |
wtc
2011/08/11 18:33:55
Nit: criterias => criteria
"criteria" is the plur
markusheintz_
2011/08/15 19:09:04
Done.
| |
214 bool cert_matches_filter = true; | |
215 | |
216 if (setting == CONTENT_SETTING_ALLOW && | |
217 cert_request_info->client_certs.size() == 1 && | |
218 cert_matches_filter) { | |
219 net::X509Certificate* cert = cert_request_info->client_certs[0].get(); | |
220 handler->CertificateSelected(cert); | |
221 } else { | |
222 ShowClientCertificateRequestDialog(handler); | |
223 } | |
wtc
2011/08/11 18:33:55
If the possible values of 'setting' are ALLOW and
markusheintz_
2011/08/15 19:09:04
Only two values are possible in version #4 of this
| |
224 } | |
225 | |
181 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( | 226 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( |
182 scoped_refptr<SSLClientAuthHandler> handler) { | 227 scoped_refptr<SSLClientAuthHandler> handler) { |
183 browser::ShowSSLClientCertificateSelector( | 228 browser::ShowSSLClientCertificateSelector( |
184 tab_contents_->tab_contents(), handler->cert_request_info(), handler); | 229 tab_contents_->tab_contents(), handler->cert_request_info(), handler); |
185 } | 230 } |
186 | 231 |
187 void TabContentsSSLHelper::OnVerifyClientCertificateError( | 232 void TabContentsSSLHelper::OnVerifyClientCertificateError( |
188 scoped_refptr<SSLAddCertHandler> handler, int error_code) { | 233 scoped_refptr<SSLAddCertHandler> handler, int error_code) { |
189 SSLAddCertData* add_cert_data = GetAddCertData(handler); | 234 SSLAddCertData* add_cert_data = GetAddCertData(handler); |
190 // Display an infobar with the error message. | 235 // Display an infobar with the error message. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData( | 273 TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData( |
229 SSLAddCertHandler* handler) { | 274 SSLAddCertHandler* handler) { |
230 // Find/create the slot. | 275 // Find/create the slot. |
231 linked_ptr<SSLAddCertData>& ptr_ref = | 276 linked_ptr<SSLAddCertData>& ptr_ref = |
232 request_id_to_add_cert_data_[handler->network_request_id()]; | 277 request_id_to_add_cert_data_[handler->network_request_id()]; |
233 // Fill it if necessary. | 278 // Fill it if necessary. |
234 if (!ptr_ref.get()) | 279 if (!ptr_ref.get()) |
235 ptr_ref.reset(new SSLAddCertData(tab_contents_)); | 280 ptr_ref.reset(new SSLAddCertData(tab_contents_)); |
236 return ptr_ref.get(); | 281 return ptr_ref.get(); |
237 } | 282 } |
OLD | NEW |