| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/ssl/ssl_policy.h" | 5 #include "content/browser/ssl/ssl_policy.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "content/browser/frame_host/navigation_entry_impl.h" | 14 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 15 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/site_instance_impl.h" | 17 #include "content/browser/site_instance_impl.h" |
| 18 #include "content/browser/ssl/ssl_cert_error_handler.h" | 18 #include "content/browser/ssl/ssl_cert_error_handler.h" |
| 19 #include "content/browser/ssl/ssl_request_info.h" | 19 #include "content/browser/ssl/ssl_request_info.h" |
| 20 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
| 21 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 22 #include "content/public/browser/web_contents.h" | |
| 23 #include "content/public/common/resource_type.h" | 22 #include "content/public/common/resource_type.h" |
| 24 #include "content/public/common/ssl_status.h" | 23 #include "content/public/common/ssl_status.h" |
| 25 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 26 #include "net/ssl/ssl_info.h" | 25 #include "net/ssl/ssl_info.h" |
| 27 #include "url/gurl.h" | 26 |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 // Events for UMA. Do not reorder or change! | 32 // Events for UMA. Do not reorder or change! |
| 34 enum SSLGoodCertSeenEvent { | 33 enum SSLGoodCertSeenEvent { |
| 35 NO_PREVIOUS_EXCEPTION = 0, | 34 NO_PREVIOUS_EXCEPTION = 0, |
| 36 HAD_PREVIOUS_EXCEPTION = 1, | 35 HAD_PREVIOUS_EXCEPTION = 1, |
| 37 SSL_GOOD_CERT_SEEN_EVENT_MAX = 2 | 36 SSL_GOOD_CERT_SEEN_EVENT_MAX = 2 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // certificates. | 131 // certificates. |
| 133 backend_->RevokeUserAllowExceptions(info->url().host()); | 132 backend_->RevokeUserAllowExceptions(info->url().host()); |
| 134 event = HAD_PREVIOUS_EXCEPTION; | 133 event = HAD_PREVIOUS_EXCEPTION; |
| 135 } | 134 } |
| 136 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.good_cert_seen", event, | 135 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.good_cert_seen", event, |
| 137 SSL_GOOD_CERT_SEEN_EVENT_MAX); | 136 SSL_GOOD_CERT_SEEN_EVENT_MAX); |
| 138 } | 137 } |
| 139 } | 138 } |
| 140 | 139 |
| 141 void SSLPolicy::UpdateEntry(NavigationEntryImpl* entry, | 140 void SSLPolicy::UpdateEntry(NavigationEntryImpl* entry, |
| 142 WebContents* web_contents) { | 141 WebContentsImpl* web_contents) { |
| 143 DCHECK(entry); | 142 DCHECK(entry); |
| 144 | 143 |
| 145 InitializeEntryIfNeeded(entry); | 144 InitializeEntryIfNeeded(entry); |
| 146 | 145 |
| 147 if (entry->GetSSL().security_style == SECURITY_STYLE_UNAUTHENTICATED) | 146 if (!entry->GetURL().SchemeIsCryptographic()) |
| 148 return; | 147 return; |
| 149 | 148 |
| 150 if (!web_contents->DisplayedInsecureContent()) | 149 if (!web_contents->DisplayedInsecureContent()) |
| 151 entry->GetSSL().content_status &= ~SSLStatus::DISPLAYED_INSECURE_CONTENT; | 150 entry->GetSSL().content_status &= ~SSLStatus::DISPLAYED_INSECURE_CONTENT; |
| 152 | 151 |
| 152 // An HTTPS response may not have a certificate for some reason. When that |
| 153 // happens, use the unauthenticated (HTTP) rather than the authentication |
| 154 // broken security style so that we can detect this error condition. |
| 155 if (!entry->GetSSL().cert_id) { |
| 156 entry->GetSSL().security_style = SECURITY_STYLE_UNAUTHENTICATED; |
| 157 return; |
| 158 } |
| 159 |
| 153 if (web_contents->DisplayedInsecureContent()) | 160 if (web_contents->DisplayedInsecureContent()) |
| 154 entry->GetSSL().content_status |= SSLStatus::DISPLAYED_INSECURE_CONTENT; | 161 entry->GetSSL().content_status |= SSLStatus::DISPLAYED_INSECURE_CONTENT; |
| 155 | 162 |
| 156 if (entry->GetSSL().security_style == SECURITY_STYLE_AUTHENTICATION_BROKEN) | 163 if (net::IsCertStatusError(entry->GetSSL().cert_status)) { |
| 164 // Minor errors don't lower the security style to |
| 165 // SECURITY_STYLE_AUTHENTICATION_BROKEN. |
| 166 if (!net::IsCertStatusMinorError(entry->GetSSL().cert_status)) { |
| 167 entry->GetSSL().security_style = |
| 168 SECURITY_STYLE_AUTHENTICATION_BROKEN; |
| 169 } |
| 157 return; | 170 return; |
| 171 } |
| 158 | 172 |
| 159 SiteInstance* site_instance = entry->site_instance(); | 173 SiteInstance* site_instance = entry->site_instance(); |
| 160 // Note that |site_instance| can be NULL here because NavigationEntries don't | 174 // Note that |site_instance| can be NULL here because NavigationEntries don't |
| 161 // necessarily have site instances. Without a process, the entry can't | 175 // necessarily have site instances. Without a process, the entry can't |
| 162 // possibly have insecure content. See bug http://crbug.com/12423. | 176 // possibly have insecure content. See bug http://crbug.com/12423. |
| 163 if (site_instance && | 177 if (site_instance && |
| 164 backend_->DidHostRunInsecureContent( | 178 backend_->DidHostRunInsecureContent( |
| 165 entry->GetURL().host(), site_instance->GetProcess()->GetID())) { | 179 entry->GetURL().host(), site_instance->GetProcess()->GetID())) { |
| 166 entry->GetSSL().security_style = | 180 entry->GetSSL().security_style = |
| 167 SECURITY_STYLE_AUTHENTICATION_BROKEN; | 181 SECURITY_STYLE_AUTHENTICATION_BROKEN; |
| 168 entry->GetSSL().content_status |= SSLStatus::RAN_INSECURE_CONTENT; | 182 entry->GetSSL().content_status |= SSLStatus::RAN_INSECURE_CONTENT; |
| 169 return; | 183 return; |
| 170 } | 184 } |
| 171 } | 185 } |
| 172 | 186 |
| 173 // Static | |
| 174 SecurityStyle SSLPolicy::GetSecurityStyleForResource(const GURL& url, | |
| 175 const SSLStatus& ssl) { | |
| 176 // An HTTPS response may not have a certificate for some reason. When that | |
| 177 // happens, use the unauthenticated (HTTP) rather than the authentication | |
| 178 // broken security style so that we can detect this error condition. | |
| 179 if (!url.SchemeIsCryptographic() || !ssl.cert_id) | |
| 180 return SECURITY_STYLE_UNAUTHENTICATED; | |
| 181 | |
| 182 // Minor errors don't lower the security style to | |
| 183 // SECURITY_STYLE_AUTHENTICATION_BROKEN. | |
| 184 if (net::IsCertStatusError(ssl.cert_status) && | |
| 185 !net::IsCertStatusMinorError(ssl.cert_status)) { | |
| 186 return SECURITY_STYLE_AUTHENTICATION_BROKEN; | |
| 187 } | |
| 188 | |
| 189 return SECURITY_STYLE_AUTHENTICATED; | |
| 190 } | |
| 191 | |
| 192 void SSLPolicy::OnAllowCertificate(scoped_refptr<SSLCertErrorHandler> handler, | 187 void SSLPolicy::OnAllowCertificate(scoped_refptr<SSLCertErrorHandler> handler, |
| 193 bool allow) { | 188 bool allow) { |
| 194 DCHECK(handler->ssl_info().is_valid()); | 189 DCHECK(handler->ssl_info().is_valid()); |
| 195 if (allow) { | 190 if (allow) { |
| 196 // Default behavior for accepting a certificate. | 191 // Default behavior for accepting a certificate. |
| 197 // Note that we should not call SetMaxSecurityStyle here, because the active | 192 // Note that we should not call SetMaxSecurityStyle here, because the active |
| 198 // NavigationEntry has just been deleted (in HideInterstitialPage) and the | 193 // NavigationEntry has just been deleted (in HideInterstitialPage) and the |
| 199 // new NavigationEntry will not be set until DidNavigate. This is ok, | 194 // new NavigationEntry will not be set until DidNavigate. This is ok, |
| 200 // because the new NavigationEntry will have its max security style set | 195 // because the new NavigationEntry will have its max security style set |
| 201 // within DidNavigate. | 196 // within DidNavigate. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 break; | 244 break; |
| 250 default: | 245 default: |
| 251 NOTREACHED(); | 246 NOTREACHED(); |
| 252 } | 247 } |
| 253 } | 248 } |
| 254 | 249 |
| 255 void SSLPolicy::InitializeEntryIfNeeded(NavigationEntryImpl* entry) { | 250 void SSLPolicy::InitializeEntryIfNeeded(NavigationEntryImpl* entry) { |
| 256 if (entry->GetSSL().security_style != SECURITY_STYLE_UNKNOWN) | 251 if (entry->GetSSL().security_style != SECURITY_STYLE_UNKNOWN) |
| 257 return; | 252 return; |
| 258 | 253 |
| 259 entry->GetSSL().security_style = | 254 entry->GetSSL().security_style = entry->GetURL().SchemeIsCryptographic() |
| 260 GetSecurityStyleForResource(entry->GetURL(), entry->GetSSL()); | 255 ? SECURITY_STYLE_AUTHENTICATED |
| 256 : SECURITY_STYLE_UNAUTHENTICATED; |
| 261 } | 257 } |
| 262 | 258 |
| 263 void SSLPolicy::OriginRanInsecureContent(const std::string& origin, int pid) { | 259 void SSLPolicy::OriginRanInsecureContent(const std::string& origin, int pid) { |
| 264 GURL parsed_origin(origin); | 260 GURL parsed_origin(origin); |
| 265 if (parsed_origin.SchemeIsCryptographic()) | 261 if (parsed_origin.SchemeIsCryptographic()) |
| 266 backend_->HostRanInsecureContent(parsed_origin.host(), pid); | 262 backend_->HostRanInsecureContent(parsed_origin.host(), pid); |
| 267 } | 263 } |
| 268 | 264 |
| 269 } // namespace content | 265 } // namespace content |
| OLD | NEW |