Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_number_conversions.h" | |
| 18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "components/mime_util/mime_util.h" | 22 #include "components/mime_util/mime_util.h" |
| 22 #include "components/scheduler/child/web_task_runner_impl.h" | 23 #include "components/scheduler/child/web_task_runner_impl.h" |
| 23 #include "content/child/child_thread_impl.h" | 24 #include "content/child/child_thread_impl.h" |
| 24 #include "content/child/ftp_directory_listing_response_delegate.h" | 25 #include "content/child/ftp_directory_listing_response_delegate.h" |
| 25 #include "content/child/request_extra_data.h" | 26 #include "content/child/request_extra_data.h" |
| 26 #include "content/child/request_info.h" | 27 #include "content/child/request_info.h" |
| 27 #include "content/child/resource_dispatcher.h" | 28 #include "content/child/resource_dispatcher.h" |
| 28 #include "content/child/shared_memory_data_consumer_handle.h" | 29 #include "content/child/shared_memory_data_consumer_handle.h" |
| 29 #include "content/child/sync_load_response.h" | 30 #include "content/child/sync_load_response.h" |
| 30 #include "content/child/web_url_request_util.h" | 31 #include "content/child/web_url_request_util.h" |
| 31 #include "content/child/weburlresponse_extradata_impl.h" | 32 #include "content/child/weburlresponse_extradata_impl.h" |
| 32 #include "content/common/resource_messages.h" | 33 #include "content/common/resource_messages.h" |
| 33 #include "content/common/resource_request_body.h" | 34 #include "content/common/resource_request_body.h" |
| 34 #include "content/common/service_worker/service_worker_types.h" | 35 #include "content/common/service_worker/service_worker_types.h" |
| 35 #include "content/common/ssl_status_serialization.h" | 36 #include "content/common/ssl_status_serialization.h" |
| 36 #include "content/public/child/fixed_received_data.h" | 37 #include "content/public/child/fixed_received_data.h" |
| 37 #include "content/public/child/request_peer.h" | 38 #include "content/public/child/request_peer.h" |
| 38 #include "content/public/common/browser_side_navigation_policy.h" | 39 #include "content/public/common/browser_side_navigation_policy.h" |
| 39 #include "content/public/common/signed_certificate_timestamp_id_and_status.h" | |
| 40 #include "content/public/common/ssl_status.h" | 40 #include "content/public/common/ssl_status.h" |
| 41 #include "net/base/data_url.h" | 41 #include "net/base/data_url.h" |
| 42 #include "net/base/filename_util.h" | 42 #include "net/base/filename_util.h" |
| 43 #include "net/base/net_errors.h" | 43 #include "net/base/net_errors.h" |
| 44 #include "net/cert/cert_status_flags.h" | 44 #include "net/cert/cert_status_flags.h" |
| 45 #include "net/cert/ct_sct_to_string.h" | |
| 45 #include "net/cert/sct_status_flags.h" | 46 #include "net/cert/sct_status_flags.h" |
| 46 #include "net/http/http_response_headers.h" | 47 #include "net/http/http_response_headers.h" |
| 47 #include "net/http/http_util.h" | 48 #include "net/http/http_util.h" |
| 48 #include "net/ssl/ssl_cipher_suite_names.h" | 49 #include "net/ssl/ssl_cipher_suite_names.h" |
| 49 #include "net/ssl/ssl_connection_status_flags.h" | 50 #include "net/ssl/ssl_connection_status_flags.h" |
| 50 #include "net/url_request/url_request_data_job.h" | 51 #include "net/url_request/url_request_data_job.h" |
| 51 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" | 52 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" |
| 52 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 53 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 53 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | 54 #include "third_party/WebKit/public/platform/WebTraceLocation.h" |
| 54 #include "third_party/WebKit/public/platform/WebURL.h" | 55 #include "third_party/WebKit/public/platform/WebURL.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 info->mime_type.swap(mime_type); | 179 info->mime_type.swap(mime_type); |
| 179 info->charset.swap(charset); | 180 info->charset.swap(charset); |
| 180 info->security_info.clear(); | 181 info->security_info.clear(); |
| 181 info->content_length = data->length(); | 182 info->content_length = data->length(); |
| 182 info->encoded_data_length = 0; | 183 info->encoded_data_length = 0; |
| 183 | 184 |
| 184 return net::OK; | 185 return net::OK; |
| 185 } | 186 } |
| 186 | 187 |
| 187 void SetSecurityStyleAndDetails(const GURL& url, | 188 void SetSecurityStyleAndDetails(const GURL& url, |
| 188 const std::string& security_info, | 189 const ResourceResponseInfo& info, |
| 189 WebURLResponse* response, | 190 WebURLResponse* response, |
| 190 bool report_security_info) { | 191 bool report_security_info) { |
| 191 if (!report_security_info) { | 192 if (!report_security_info) { |
| 192 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); | 193 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); |
| 193 return; | 194 return; |
| 194 } | 195 } |
| 195 if (!url.SchemeIsCryptographic()) { | 196 if (!url.SchemeIsCryptographic()) { |
| 196 response->setSecurityStyle(WebURLResponse::SecurityStyleUnauthenticated); | 197 response->setSecurityStyle(WebURLResponse::SecurityStyleUnauthenticated); |
| 197 return; | 198 return; |
| 198 } | 199 } |
| 199 | 200 |
| 200 // There are cases where an HTTPS request can come in without security | 201 // There are cases where an HTTPS request can come in without security |
| 201 // info attached (such as a redirect response). | 202 // info attached (such as a redirect response). |
| 203 const std::string& security_info = info.security_info; | |
| 202 if (security_info.empty()) { | 204 if (security_info.empty()) { |
| 203 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); | 205 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); |
| 204 return; | 206 return; |
| 205 } | 207 } |
| 206 | 208 |
| 207 SSLStatus ssl_status; | 209 SSLStatus ssl_status; |
| 208 if (!DeserializeSecurityInfo(security_info, &ssl_status)) { | 210 if (!DeserializeSecurityInfo(security_info, &ssl_status)) { |
| 209 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); | 211 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); |
| 210 DLOG(ERROR) | 212 DLOG(ERROR) |
| 211 << "DeserializeSecurityInfo() failed for an authenticated request."; | 213 << "DeserializeSecurityInfo() failed for an authenticated request."; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 case SECURITY_STYLE_WARNING: | 247 case SECURITY_STYLE_WARNING: |
| 246 securityStyle = WebURLResponse::SecurityStyleWarning; | 248 securityStyle = WebURLResponse::SecurityStyleWarning; |
| 247 break; | 249 break; |
| 248 case SECURITY_STYLE_AUTHENTICATED: | 250 case SECURITY_STYLE_AUTHENTICATED: |
| 249 securityStyle = WebURLResponse::SecurityStyleAuthenticated; | 251 securityStyle = WebURLResponse::SecurityStyleAuthenticated; |
| 250 break; | 252 break; |
| 251 } | 253 } |
| 252 | 254 |
| 253 response->setSecurityStyle(securityStyle); | 255 response->setSecurityStyle(securityStyle); |
| 254 | 256 |
| 255 SignedCertificateTimestampIDStatusList sct_list = | 257 size_t num_unknown_scts = ssl_status.num_unknown_scts; |
| 256 ssl_status.signed_certificate_timestamp_ids; | 258 size_t num_invalid_scts = ssl_status.num_invalid_scts; |
| 259 size_t num_valid_scts = ssl_status.num_valid_scts; | |
| 257 | 260 |
| 258 size_t num_unknown_scts = 0; | 261 blink::WebURLResponse::SignedCertificateTimestampList sctList; |
| 259 size_t num_invalid_scts = 0; | |
| 260 size_t num_valid_scts = 0; | |
| 261 | 262 |
| 262 SignedCertificateTimestampIDStatusList::iterator iter; | 263 // TODO: info.signed_certificate_timestamps is empty |
|
dwaxweiler
2016/03/21 23:03:44
info.signed_certificate_timestamps is empty althou
| |
| 263 for (iter = sct_list.begin(); iter < sct_list.end(); ++iter) { | 264 for (const auto& sct_and_status : info.signed_certificate_timestamps) { |
| 264 switch (iter->status) { | 265 // Extract SCT's details. |
| 265 case net::ct::SCT_STATUS_LOG_UNKNOWN: | 266 blink::WebURLResponse::SignedCertificateTimestamp sct( |
| 266 num_unknown_scts++; | 267 WebString::fromUTF8(net::ct::StatusToString(sct_and_status.status)), |
| 267 break; | 268 WebString::fromUTF8(net::ct::OriginToString(sct_and_status.sct->origin)), |
| 268 case net::ct::SCT_STATUS_INVALID: | 269 WebString::fromUTF8( |
| 269 num_invalid_scts++; | 270 net::ct::VersionToString(sct_and_status.sct->version)), |
| 270 break; | 271 WebString::fromUTF8(sct_and_status.sct->log_description), |
| 271 case net::ct::SCT_STATUS_OK: | 272 WebString::fromUTF8( |
| 272 num_valid_scts++; | 273 base::HexEncode( |
| 273 break; | 274 reinterpret_cast<const unsigned char*>( |
| 274 case net::ct::SCT_STATUS_NONE: | 275 sct_and_status.sct->log_id.data()), |
| 275 case net::ct::SCT_STATUS_MAX: | 276 sct_and_status.sct->log_id.length())), |
| 276 // These enum values do not represent SCTs that are taken into account | 277 sct_and_status.sct->timestamp.ToJavaTime(), |
| 277 // for CT compliance calculations, so we ignore them. | 278 WebString::fromUTF8( |
| 278 break; | 279 net::ct::HashAlgorithmToString( |
| 279 } | 280 sct_and_status.sct->signature.hash_algorithm)), |
| 281 WebString::fromUTF8( | |
| 282 net::ct::SignatureAlgorithmToString( | |
| 283 sct_and_status.sct->signature.signature_algorithm)), | |
| 284 WebString::fromUTF8( | |
| 285 base::HexEncode( | |
| 286 reinterpret_cast<const unsigned char*>( | |
| 287 sct_and_status.sct->signature.signature_data.data()), | |
| 288 sct_and_status.sct->signature.signature_data.length()))); | |
| 289 sctList.push_back(sct); | |
| 280 } | 290 } |
| 281 | 291 |
| 282 blink::WebURLResponse::WebSecurityDetails webSecurityDetails( | 292 blink::WebURLResponse::WebSecurityDetails webSecurityDetails( |
| 283 WebString::fromUTF8(protocol), WebString::fromUTF8(key_exchange), | 293 WebString::fromUTF8(protocol), WebString::fromUTF8(key_exchange), |
| 284 WebString::fromUTF8(cipher), WebString::fromUTF8(mac), | 294 WebString::fromUTF8(cipher), WebString::fromUTF8(mac), |
| 285 ssl_status.cert_id, num_unknown_scts, num_invalid_scts, num_valid_scts); | 295 ssl_status.cert_id, num_unknown_scts, num_invalid_scts, num_valid_scts, |
| 296 sctList); | |
| 286 | 297 |
| 287 response->setSecurityDetails(webSecurityDetails); | 298 response->setSecurityDetails(webSecurityDetails); |
| 288 } | 299 } |
| 289 | 300 |
| 290 } // namespace | 301 } // namespace |
| 291 | 302 |
| 292 // This inner class exists since the WebURLLoader may be deleted while inside a | 303 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 293 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 304 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
| 294 // deleted if it may have work to do after calling into the client. | 305 // deleted if it may have work to do after calling into the client. |
| 295 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 306 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 response->setConnectionReused(info.load_timing.socket_reused); | 947 response->setConnectionReused(info.load_timing.socket_reused); |
| 937 response->setDownloadFilePath(info.download_file_path.AsUTF16Unsafe()); | 948 response->setDownloadFilePath(info.download_file_path.AsUTF16Unsafe()); |
| 938 response->setWasFetchedViaSPDY(info.was_fetched_via_spdy); | 949 response->setWasFetchedViaSPDY(info.was_fetched_via_spdy); |
| 939 response->setWasFetchedViaServiceWorker(info.was_fetched_via_service_worker); | 950 response->setWasFetchedViaServiceWorker(info.was_fetched_via_service_worker); |
| 940 response->setWasFallbackRequiredByServiceWorker( | 951 response->setWasFallbackRequiredByServiceWorker( |
| 941 info.was_fallback_required_by_service_worker); | 952 info.was_fallback_required_by_service_worker); |
| 942 response->setServiceWorkerResponseType(info.response_type_via_service_worker); | 953 response->setServiceWorkerResponseType(info.response_type_via_service_worker); |
| 943 response->setOriginalURLViaServiceWorker( | 954 response->setOriginalURLViaServiceWorker( |
| 944 info.original_url_via_service_worker); | 955 info.original_url_via_service_worker); |
| 945 | 956 |
| 946 SetSecurityStyleAndDetails(url, info.security_info, response, | 957 SetSecurityStyleAndDetails(url, info, response, report_security_info); |
| 947 report_security_info); | |
| 948 | 958 |
| 949 WebURLResponseExtraDataImpl* extra_data = | 959 WebURLResponseExtraDataImpl* extra_data = |
| 950 new WebURLResponseExtraDataImpl(info.npn_negotiated_protocol); | 960 new WebURLResponseExtraDataImpl(info.npn_negotiated_protocol); |
| 951 response->setExtraData(extra_data); | 961 response->setExtraData(extra_data); |
| 952 extra_data->set_was_fetched_via_spdy(info.was_fetched_via_spdy); | 962 extra_data->set_was_fetched_via_spdy(info.was_fetched_via_spdy); |
| 953 extra_data->set_was_npn_negotiated(info.was_npn_negotiated); | 963 extra_data->set_was_npn_negotiated(info.was_npn_negotiated); |
| 954 extra_data->set_was_alternate_protocol_available( | 964 extra_data->set_was_alternate_protocol_available( |
| 955 info.was_alternate_protocol_available); | 965 info.was_alternate_protocol_available); |
| 956 extra_data->set_connection_info(info.connection_info); | 966 extra_data->set_connection_info(info.connection_info); |
| 957 extra_data->set_was_fetched_via_proxy(info.was_fetched_via_proxy); | 967 extra_data->set_was_fetched_via_proxy(info.was_fetched_via_proxy); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 response->clearHTTPHeaderField(webStringName); | 1182 response->clearHTTPHeaderField(webStringName); |
| 1173 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1183 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1174 response->addHTTPHeaderField(webStringName, | 1184 response->addHTTPHeaderField(webStringName, |
| 1175 WebString::fromLatin1(value)); | 1185 WebString::fromLatin1(value)); |
| 1176 } | 1186 } |
| 1177 } | 1187 } |
| 1178 return true; | 1188 return true; |
| 1179 } | 1189 } |
| 1180 | 1190 |
| 1181 } // namespace content | 1191 } // namespace content |
| OLD | NEW |