| 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 "content/browser/ssl/ssl_policy.h" | 5 #include "content/browser/ssl/ssl_policy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.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/string_piece.h" | 11 #include "base/string_piece.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "content/browser/renderer_host/render_process_host_impl.h" | 13 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 14 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
| 15 #include "content/browser/site_instance.h" | 15 #include "content/browser/site_instance.h" |
| 16 #include "content/browser/ssl/ssl_cert_error_handler.h" | 16 #include "content/browser/ssl/ssl_cert_error_handler.h" |
| 17 #include "content/browser/ssl/ssl_request_info.h" | 17 #include "content/browser/ssl/ssl_request_info.h" |
| 18 #include "content/browser/tab_contents/navigation_entry.h" | 18 #include "content/browser/tab_contents/navigation_entry_impl.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/ssl_status.h" | 21 #include "content/public/browser/ssl_status.h" |
| 22 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 23 #include "net/base/cert_status_flags.h" | 23 #include "net/base/cert_status_flags.h" |
| 24 #include "net/base/ssl_info.h" | 24 #include "net/base/ssl_info.h" |
| 25 #include "webkit/glue/resource_type.h" | 25 #include "webkit/glue/resource_type.h" |
| 26 | 26 |
| 27 using content::NavigationEntryImpl; |
| 27 using content::SSLStatus; | 28 using content::SSLStatus; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 static const char kDot = '.'; | 32 static const char kDot = '.'; |
| 32 | 33 |
| 33 static bool IsIntranetHost(const std::string& host) { | 34 static bool IsIntranetHost(const std::string& host) { |
| 34 const size_t dot = host.find(kDot); | 35 const size_t dot = host.find(kDot); |
| 35 return dot == std::string::npos || dot == host.length() - 1; | 36 return dot == std::string::npos || dot == host.length() - 1; |
| 36 } | 37 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 case net::ERR_CERT_NOT_IN_DNS: | 80 case net::ERR_CERT_NOT_IN_DNS: |
| 80 OnCertErrorInternal(handler, false); | 81 OnCertErrorInternal(handler, false); |
| 81 break; | 82 break; |
| 82 default: | 83 default: |
| 83 NOTREACHED(); | 84 NOTREACHED(); |
| 84 handler->CancelRequest(); | 85 handler->CancelRequest(); |
| 85 break; | 86 break; |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 void SSLPolicy::DidRunInsecureContent(NavigationEntry* entry, | 90 void SSLPolicy::DidRunInsecureContent(NavigationEntryImpl* entry, |
| 90 const std::string& security_origin) { | 91 const std::string& security_origin) { |
| 91 if (!entry) | 92 if (!entry) |
| 92 return; | 93 return; |
| 93 | 94 |
| 94 SiteInstance* site_instance = entry->site_instance(); | 95 SiteInstance* site_instance = entry->site_instance(); |
| 95 if (!site_instance) | 96 if (!site_instance) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 backend_->HostRanInsecureContent(GURL(security_origin).host(), | 99 backend_->HostRanInsecureContent(GURL(security_origin).host(), |
| 99 site_instance->GetProcess()->GetID()); | 100 site_instance->GetProcess()->GetID()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void SSLPolicy::OnRequestStarted(SSLRequestInfo* info) { | 103 void SSLPolicy::OnRequestStarted(SSLRequestInfo* info) { |
| 103 // TODO(abarth): This mechanism is wrong. What we should be doing is sending | 104 // TODO(abarth): This mechanism is wrong. What we should be doing is sending |
| 104 // this information back through WebKit and out some FrameLoaderClient | 105 // this information back through WebKit and out some FrameLoaderClient |
| 105 // methods. | 106 // methods. |
| 106 | 107 |
| 107 if (net::IsCertStatusError(info->ssl_cert_status())) | 108 if (net::IsCertStatusError(info->ssl_cert_status())) |
| 108 backend_->HostRanInsecureContent(info->url().host(), info->child_id()); | 109 backend_->HostRanInsecureContent(info->url().host(), info->child_id()); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void SSLPolicy::UpdateEntry(NavigationEntry* entry, TabContents* tab_contents) { | 112 void SSLPolicy::UpdateEntry(NavigationEntryImpl* entry, |
| 113 TabContents* tab_contents) { |
| 112 DCHECK(entry); | 114 DCHECK(entry); |
| 113 | 115 |
| 114 InitializeEntryIfNeeded(entry); | 116 InitializeEntryIfNeeded(entry); |
| 115 | 117 |
| 116 if (!entry->GetURL().SchemeIsSecure()) | 118 if (!entry->GetURL().SchemeIsSecure()) |
| 117 return; | 119 return; |
| 118 | 120 |
| 119 // An HTTPS response may not have a certificate for some reason. When that | 121 // An HTTPS response may not have a certificate for some reason. When that |
| 120 // happens, use the unauthenticated (HTTP) rather than the authentication | 122 // happens, use the unauthenticated (HTTP) rather than the authentication |
| 121 // broken security style so that we can detect this error condition. | 123 // broken security style so that we can detect this error condition. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 handler->DenyRequest(); | 201 handler->DenyRequest(); |
| 200 return; | 202 return; |
| 201 } | 203 } |
| 202 | 204 |
| 203 content::GetContentClient()->browser()->AllowCertificateError( | 205 content::GetContentClient()->browser()->AllowCertificateError( |
| 204 handler, | 206 handler, |
| 205 overridable, | 207 overridable, |
| 206 base::Bind(&SSLPolicy::OnAllowCertificate, base::Unretained(this))); | 208 base::Bind(&SSLPolicy::OnAllowCertificate, base::Unretained(this))); |
| 207 } | 209 } |
| 208 | 210 |
| 209 void SSLPolicy::InitializeEntryIfNeeded(NavigationEntry* entry) { | 211 void SSLPolicy::InitializeEntryIfNeeded(NavigationEntryImpl* entry) { |
| 210 if (entry->GetSSL().security_style != content::SECURITY_STYLE_UNKNOWN) | 212 if (entry->GetSSL().security_style != content::SECURITY_STYLE_UNKNOWN) |
| 211 return; | 213 return; |
| 212 | 214 |
| 213 entry->GetSSL().security_style = entry->GetURL().SchemeIsSecure() ? | 215 entry->GetSSL().security_style = entry->GetURL().SchemeIsSecure() ? |
| 214 content::SECURITY_STYLE_AUTHENTICATED : | 216 content::SECURITY_STYLE_AUTHENTICATED : |
| 215 content::SECURITY_STYLE_UNAUTHENTICATED; | 217 content::SECURITY_STYLE_UNAUTHENTICATED; |
| 216 } | 218 } |
| 217 | 219 |
| 218 void SSLPolicy::OriginRanInsecureContent(const std::string& origin, int pid) { | 220 void SSLPolicy::OriginRanInsecureContent(const std::string& origin, int pid) { |
| 219 GURL parsed_origin(origin); | 221 GURL parsed_origin(origin); |
| 220 if (parsed_origin.SchemeIsSecure()) | 222 if (parsed_origin.SchemeIsSecure()) |
| 221 backend_->HostRanInsecureContent(parsed_origin.host(), pid); | 223 backend_->HostRanInsecureContent(parsed_origin.host(), pid); |
| 222 } | 224 } |
| OLD | NEW |