| 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_manager.h" | 5 #include "content/browser/ssl/ssl_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/browser/load_from_memory_cache_details.h" | 9 #include "content/browser/load_from_memory_cache_details.h" |
| 10 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 10 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 11 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 11 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 12 #include "content/browser/renderer_host/resource_request_details.h" | 12 #include "content/browser/renderer_host/resource_request_details.h" |
| 13 #include "content/browser/ssl/ssl_cert_error_handler.h" | 13 #include "content/browser/ssl/ssl_cert_error_handler.h" |
| 14 #include "content/browser/ssl/ssl_policy.h" | 14 #include "content/browser/ssl/ssl_policy.h" |
| 15 #include "content/browser/ssl/ssl_request_info.h" | 15 #include "content/browser/ssl/ssl_request_info.h" |
| 16 #include "content/browser/tab_contents/navigation_entry_impl.h" | 16 #include "content/browser/tab_contents/navigation_entry_impl.h" |
| 17 #include "content/browser/tab_contents/provisional_load_details.h" | 17 #include "content/browser/tab_contents/provisional_load_details.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/common/ssl_status_serialization.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
| 21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/ssl_status.h" | 24 #include "content/public/common/ssl_status.h" |
| 24 #include "net/base/cert_status_flags.h" | |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using content::NavigationController; | 27 using content::NavigationController; |
| 28 using content::NavigationEntry; | 28 using content::NavigationEntry; |
| 29 using content::NavigationEntryImpl; | 29 using content::NavigationEntryImpl; |
| 30 using content::SSLStatus; | 30 using content::SSLStatus; |
| 31 using content::WebContents; | 31 using content::WebContents; |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, | 34 void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 void SSLManager::NotifySSLInternalStateChanged( | 59 void SSLManager::NotifySSLInternalStateChanged( |
| 60 NavigationControllerImpl* controller) { | 60 NavigationControllerImpl* controller) { |
| 61 content::NotificationService::current()->Notify( | 61 content::NotificationService::current()->Notify( |
| 62 content::NOTIFICATION_SSL_INTERNAL_STATE_CHANGED, | 62 content::NOTIFICATION_SSL_INTERNAL_STATE_CHANGED, |
| 63 content::Source<content::BrowserContext>(controller->GetBrowserContext()), | 63 content::Source<content::BrowserContext>(controller->GetBrowserContext()), |
| 64 content::NotificationService::NoDetails()); | 64 content::NotificationService::NoDetails()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // static | |
| 68 std::string SSLManager::SerializeSecurityInfo(int cert_id, | |
| 69 net::CertStatus cert_status, | |
| 70 int security_bits, | |
| 71 int ssl_connection_status) { | |
| 72 Pickle pickle; | |
| 73 pickle.WriteInt(cert_id); | |
| 74 pickle.WriteUInt32(cert_status); | |
| 75 pickle.WriteInt(security_bits); | |
| 76 pickle.WriteInt(ssl_connection_status); | |
| 77 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); | |
| 78 } | |
| 79 | |
| 80 // static | |
| 81 bool SSLManager::DeserializeSecurityInfo(const std::string& state, | |
| 82 int* cert_id, | |
| 83 net::CertStatus* cert_status, | |
| 84 int* security_bits, | |
| 85 int* ssl_connection_status) { | |
| 86 DCHECK(cert_id && cert_status && security_bits && ssl_connection_status); | |
| 87 if (state.empty()) { | |
| 88 // No SSL used. | |
| 89 *cert_id = 0; | |
| 90 // The following are not applicable and are set to the default values. | |
| 91 *cert_status = 0; | |
| 92 *security_bits = -1; | |
| 93 *ssl_connection_status = 0; | |
| 94 return false; | |
| 95 } | |
| 96 | |
| 97 Pickle pickle(state.data(), static_cast<int>(state.size())); | |
| 98 void * iter = NULL; | |
| 99 return pickle.ReadInt(&iter, cert_id) && | |
| 100 pickle.ReadUInt32(&iter, cert_status) && | |
| 101 pickle.ReadInt(&iter, security_bits) && | |
| 102 pickle.ReadInt(&iter, ssl_connection_status); | |
| 103 } | |
| 104 | |
| 105 SSLManager::SSLManager(NavigationControllerImpl* controller) | 67 SSLManager::SSLManager(NavigationControllerImpl* controller) |
| 106 : backend_(controller), | 68 : backend_(controller), |
| 107 policy_(new SSLPolicy(&backend_)), | 69 policy_(new SSLPolicy(&backend_)), |
| 108 controller_(controller) { | 70 controller_(controller) { |
| 109 DCHECK(controller_); | 71 DCHECK(controller_); |
| 110 | 72 |
| 111 // Subscribe to various notifications. | 73 // Subscribe to various notifications. |
| 112 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 74 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 113 content::Source<NavigationController>(controller_)); | 75 content::Source<NavigationController>(controller_)); |
| 114 registrar_.Add( | 76 registrar_.Add( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 137 NavigationEntryImpl* entry = | 99 NavigationEntryImpl* entry = |
| 138 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()); | 100 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()); |
| 139 | 101 |
| 140 if (details->is_main_frame) { | 102 if (details->is_main_frame) { |
| 141 if (entry) { | 103 if (entry) { |
| 142 // Decode the security details. | 104 // Decode the security details. |
| 143 int ssl_cert_id; | 105 int ssl_cert_id; |
| 144 net::CertStatus ssl_cert_status; | 106 net::CertStatus ssl_cert_status; |
| 145 int ssl_security_bits; | 107 int ssl_security_bits; |
| 146 int ssl_connection_status; | 108 int ssl_connection_status; |
| 147 DeserializeSecurityInfo(details->serialized_security_info, | 109 content::DeserializeSecurityInfo(details->serialized_security_info, |
| 148 &ssl_cert_id, | 110 &ssl_cert_id, |
| 149 &ssl_cert_status, | 111 &ssl_cert_status, |
| 150 &ssl_security_bits, | 112 &ssl_security_bits, |
| 151 &ssl_connection_status); | 113 &ssl_connection_status); |
| 152 | 114 |
| 153 // We may not have an entry if this is a navigation to an initial blank | 115 // We may not have an entry if this is a navigation to an initial blank |
| 154 // page. Reset the SSL information and add the new data we have. | 116 // page. Reset the SSL information and add the new data we have. |
| 155 entry->GetSSL() = SSLStatus(); | 117 entry->GetSSL() = SSLStatus(); |
| 156 entry->GetSSL().cert_id = ssl_cert_id; | 118 entry->GetSSL().cert_id = ssl_cert_id; |
| 157 entry->GetSSL().cert_status = ssl_cert_status; | 119 entry->GetSSL().cert_status = ssl_cert_status; |
| 158 entry->GetSSL().security_bits = ssl_security_bits; | 120 entry->GetSSL().security_bits = ssl_security_bits; |
| 159 entry->GetSSL().connection_status = ssl_connection_status; | 121 entry->GetSSL().connection_status = ssl_connection_status; |
| 160 } | 122 } |
| 161 } | 123 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 223 |
| 262 policy()->UpdateEntry(entry, controller_->tab_contents()); | 224 policy()->UpdateEntry(entry, controller_->tab_contents()); |
| 263 | 225 |
| 264 if (!entry->GetSSL().Equals(original_ssl_status)) { | 226 if (!entry->GetSSL().Equals(original_ssl_status)) { |
| 265 content::NotificationService::current()->Notify( | 227 content::NotificationService::current()->Notify( |
| 266 content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | 228 content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
| 267 content::Source<NavigationController>(controller_), | 229 content::Source<NavigationController>(controller_), |
| 268 content::NotificationService::NoDetails()); | 230 content::NotificationService::NoDetails()); |
| 269 } | 231 } |
| 270 } | 232 } |
| OLD | NEW |