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 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "content/child/ftp_directory_listing_response_delegate.h" | 26 #include "content/child/ftp_directory_listing_response_delegate.h" |
| 27 #include "content/child/request_extra_data.h" | 27 #include "content/child/request_extra_data.h" |
| 28 #include "content/child/request_info.h" | 28 #include "content/child/request_info.h" |
| 29 #include "content/child/resource_dispatcher.h" | 29 #include "content/child/resource_dispatcher.h" |
| 30 #include "content/child/shared_memory_data_consumer_handle.h" | 30 #include "content/child/shared_memory_data_consumer_handle.h" |
| 31 #include "content/child/sync_load_response.h" | 31 #include "content/child/sync_load_response.h" |
| 32 #include "content/child/web_url_request_util.h" | 32 #include "content/child/web_url_request_util.h" |
| 33 #include "content/child/weburlresponse_extradata_impl.h" | 33 #include "content/child/weburlresponse_extradata_impl.h" |
| 34 #include "content/common/resource_messages.h" | 34 #include "content/common/resource_messages.h" |
| 35 #include "content/common/resource_request_body_impl.h" | 35 #include "content/common/resource_request_body_impl.h" |
| 36 #include "content/common/security_style_util.h" | |
| 36 #include "content/common/service_worker/service_worker_types.h" | 37 #include "content/common/service_worker/service_worker_types.h" |
| 37 #include "content/common/ssl_status_serialization.h" | |
| 38 #include "content/common/url_loader.mojom.h" | 38 #include "content/common/url_loader.mojom.h" |
| 39 #include "content/public/child/fixed_received_data.h" | 39 #include "content/public/child/fixed_received_data.h" |
| 40 #include "content/public/child/request_peer.h" | 40 #include "content/public/child/request_peer.h" |
| 41 #include "content/public/common/browser_side_navigation_policy.h" | 41 #include "content/public/common/browser_side_navigation_policy.h" |
| 42 #include "content/public/common/ssl_status.h" | 42 #include "content/public/common/ssl_status.h" |
| 43 #include "net/base/data_url.h" | 43 #include "net/base/data_url.h" |
| 44 #include "net/base/filename_util.h" | 44 #include "net/base/filename_util.h" |
| 45 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 46 #include "net/cert/cert_status_flags.h" | 46 #include "net/cert/cert_status_flags.h" |
| 47 #include "net/cert/ct_sct_to_string.h" | 47 #include "net/cert/ct_sct_to_string.h" |
| 48 #include "net/cert/internal/name_constraints.h" | |
| 49 #include "net/cert/internal/parse_certificate.h" | |
| 50 #include "net/cert/internal/parse_name.h" | |
| 48 #include "net/http/http_response_headers.h" | 51 #include "net/http/http_response_headers.h" |
| 49 #include "net/http/http_util.h" | 52 #include "net/http/http_util.h" |
| 50 #include "net/ssl/ssl_cipher_suite_names.h" | 53 #include "net/ssl/ssl_cipher_suite_names.h" |
| 51 #include "net/ssl/ssl_connection_status_flags.h" | 54 #include "net/ssl/ssl_connection_status_flags.h" |
| 52 #include "net/url_request/url_request_data_job.h" | 55 #include "net/url_request/url_request_data_job.h" |
| 53 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" | 56 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" |
| 54 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 57 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 55 #include "third_party/WebKit/public/platform/WebTaskRunner.h" | 58 #include "third_party/WebKit/public/platform/WebTaskRunner.h" |
| 56 #include "third_party/WebKit/public/platform/WebURL.h" | 59 #include "third_party/WebKit/public/platform/WebURL.h" |
| 57 #include "third_party/WebKit/public/platform/WebURLError.h" | 60 #include "third_party/WebKit/public/platform/WebURLError.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 sct_and_status.sct->timestamp.ToJavaTime(), | 205 sct_and_status.sct->timestamp.ToJavaTime(), |
| 203 WebString::fromUTF8(net::ct::HashAlgorithmToString( | 206 WebString::fromUTF8(net::ct::HashAlgorithmToString( |
| 204 sct_and_status.sct->signature.hash_algorithm)), | 207 sct_and_status.sct->signature.hash_algorithm)), |
| 205 WebString::fromUTF8(net::ct::SignatureAlgorithmToString( | 208 WebString::fromUTF8(net::ct::SignatureAlgorithmToString( |
| 206 sct_and_status.sct->signature.signature_algorithm)), | 209 sct_and_status.sct->signature.signature_algorithm)), |
| 207 WebString::fromUTF8( | 210 WebString::fromUTF8( |
| 208 base::HexEncode(sct_and_status.sct->signature.signature_data.c_str(), | 211 base::HexEncode(sct_and_status.sct->signature.signature_data.c_str(), |
| 209 sct_and_status.sct->signature.signature_data.length()))); | 212 sct_and_status.sct->signature.signature_data.length()))); |
| 210 } | 213 } |
| 211 | 214 |
| 215 bool GetCommonName(const net::der::Input& tlv, std::string* common_name) { | |
| 216 net::RDNSequence rdn_sequence; | |
| 217 if (!net::ParseName(tlv, &rdn_sequence)) | |
| 218 return false; | |
| 219 | |
| 220 for (const net::RelativeDistinguishedName& rdn : rdn_sequence) { | |
| 221 for (const auto& atv : rdn) { | |
| 222 if (atv.type == net::TypeCommonNameOid()) { | |
| 223 return atv.ValueAsStringUnsafe(common_name); | |
| 224 } | |
| 225 } | |
| 226 } | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 230 bool DecodeTime(const net::der::GeneralizedTime& generalized_time, | |
| 231 base::Time* time) { | |
| 232 base::Time::Exploded exploded = {0}; | |
| 233 exploded.year = generalized_time.year; | |
| 234 exploded.month = generalized_time.month; | |
| 235 exploded.day_of_month = generalized_time.day; | |
| 236 exploded.hour = generalized_time.hours; | |
| 237 exploded.minute = generalized_time.minutes; | |
| 238 exploded.second = generalized_time.seconds; | |
| 239 return base::Time::FromUTCExploded(exploded, time); | |
| 240 } | |
| 241 | |
| 212 void SetSecurityStyleAndDetails(const GURL& url, | 242 void SetSecurityStyleAndDetails(const GURL& url, |
| 213 const ResourceResponseInfo& info, | 243 const ResourceResponseInfo& info, |
| 214 WebURLResponse* response, | 244 WebURLResponse* response, |
| 215 bool report_security_info) { | 245 bool report_security_info) { |
| 216 if (!report_security_info) { | 246 if (!report_security_info) { |
| 217 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); | 247 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); |
| 218 return; | 248 return; |
| 219 } | 249 } |
| 220 if (!url.SchemeIsCryptographic()) { | 250 if (!url.SchemeIsCryptographic()) { |
| 221 response->setSecurityStyle(WebURLResponse::SecurityStyleUnauthenticated); | 251 response->setSecurityStyle(WebURLResponse::SecurityStyleUnauthenticated); |
| 222 return; | 252 return; |
| 223 } | 253 } |
| 224 | 254 |
| 225 // There are cases where an HTTPS request can come in without security | 255 // There are cases where an HTTPS request can come in without security |
| 226 // info attached (such as a redirect response). | 256 // info attached (such as a redirect response). |
| 227 const std::string& security_info = info.security_info; | 257 if (info.certificate.empty()) { |
| 228 if (security_info.empty()) { | |
| 229 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); | 258 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); |
| 230 return; | 259 return; |
| 231 } | 260 } |
| 232 | 261 |
| 233 SSLStatus ssl_status; | |
| 234 if (!DeserializeSecurityInfo(security_info, &ssl_status)) { | |
| 235 response->setSecurityStyle(WebURLResponse::SecurityStyleUnknown); | |
| 236 DLOG(ERROR) | |
| 237 << "DeserializeSecurityInfo() failed for an authenticated request."; | |
| 238 return; | |
| 239 } | |
| 240 | |
| 241 int ssl_version = | 262 int ssl_version = |
| 242 net::SSLConnectionStatusToVersion(ssl_status.connection_status); | 263 net::SSLConnectionStatusToVersion(info.ssl_connection_status); |
| 243 const char* protocol; | 264 const char* protocol; |
| 244 net::SSLVersionToString(&protocol, ssl_version); | 265 net::SSLVersionToString(&protocol, ssl_version); |
| 245 | 266 |
| 246 const char* key_exchange; | 267 const char* key_exchange; |
| 247 const char* cipher; | 268 const char* cipher; |
| 248 const char* mac; | 269 const char* mac; |
| 249 bool is_aead; | 270 bool is_aead; |
| 250 uint16_t cipher_suite = | 271 uint16_t cipher_suite = |
| 251 net::SSLConnectionStatusToCipherSuite(ssl_status.connection_status); | 272 net::SSLConnectionStatusToCipherSuite(info.ssl_connection_status); |
| 252 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, | 273 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, |
| 253 cipher_suite); | 274 cipher_suite); |
| 254 if (mac == NULL) { | 275 if (mac == NULL) { |
| 255 DCHECK(is_aead); | 276 DCHECK(is_aead); |
| 256 mac = ""; | 277 mac = ""; |
| 257 } | 278 } |
| 258 | 279 |
| 259 blink::WebURLResponse::SecurityStyle securityStyle = | 280 SecurityStyle security_style = GetSecurityStyleForResource( |
| 281 url, true, info.cert_status); | |
| 282 | |
| 283 blink::WebURLResponse::SecurityStyle security_style_blink = | |
| 260 WebURLResponse::SecurityStyleUnknown; | 284 WebURLResponse::SecurityStyleUnknown; |
| 261 switch (ssl_status.security_style) { | 285 switch (security_style) { |
| 262 case SECURITY_STYLE_UNKNOWN: | 286 case SECURITY_STYLE_UNKNOWN: |
| 263 securityStyle = WebURLResponse::SecurityStyleUnknown; | 287 security_style_blink = WebURLResponse::SecurityStyleUnknown; |
| 264 break; | 288 break; |
| 265 case SECURITY_STYLE_UNAUTHENTICATED: | 289 case SECURITY_STYLE_UNAUTHENTICATED: |
| 266 securityStyle = WebURLResponse::SecurityStyleUnauthenticated; | 290 security_style_blink = WebURLResponse::SecurityStyleUnauthenticated; |
| 267 break; | 291 break; |
| 268 case SECURITY_STYLE_AUTHENTICATION_BROKEN: | 292 case SECURITY_STYLE_AUTHENTICATION_BROKEN: |
| 269 securityStyle = WebURLResponse::SecurityStyleAuthenticationBroken; | 293 security_style_blink = WebURLResponse::SecurityStyleAuthenticationBroken; |
| 270 break; | 294 break; |
| 271 case SECURITY_STYLE_WARNING: | 295 case SECURITY_STYLE_WARNING: |
| 272 securityStyle = WebURLResponse::SecurityStyleWarning; | 296 security_style_blink = WebURLResponse::SecurityStyleWarning; |
| 273 break; | 297 break; |
| 274 case SECURITY_STYLE_AUTHENTICATED: | 298 case SECURITY_STYLE_AUTHENTICATED: |
| 275 securityStyle = WebURLResponse::SecurityStyleAuthenticated; | 299 security_style_blink = WebURLResponse::SecurityStyleAuthenticated; |
| 276 break; | 300 break; |
| 277 } | 301 } |
| 278 | 302 |
| 279 response->setSecurityStyle(securityStyle); | 303 response->setSecurityStyle(security_style_blink); |
| 280 | 304 |
| 281 blink::WebURLResponse::SignedCertificateTimestampList sct_list( | 305 blink::WebURLResponse::SignedCertificateTimestampList sct_list( |
| 282 info.signed_certificate_timestamps.size()); | 306 info.signed_certificate_timestamps.size()); |
| 283 | 307 |
| 284 for (size_t i = 0; i < sct_list.size(); ++i) | 308 for (size_t i = 0; i < sct_list.size(); ++i) |
| 285 sct_list[i] = NetSCTToBlinkSCT(info.signed_certificate_timestamps[i]); | 309 sct_list[i] = NetSCTToBlinkSCT(info.signed_certificate_timestamps[i]); |
| 286 | 310 |
| 311 net::der::Input cert_data(&info.certificate[0]); | |
| 312 net::der::Input tbs_cert, signature_alg; | |
| 313 net::der::BitString signature_value; | |
| 314 bool rv = net::ParseCertificate(cert_data, &tbs_cert, &signature_alg, | |
| 315 &signature_value); | |
| 316 DCHECK(rv); | |
|
Ryan Sleevi
2016/09/03 00:02:51
DESIGN: You've removed the code that sanity checke
jam
2016/09/03 01:42:39
This wasn't sanity check as much as deserializatio
| |
| 317 net::ParsedTbsCertificate parsed_tbs_cert; | |
| 318 rv = net::ParseTbsCertificate(tbs_cert, net::ParseCertificateOptions(), | |
| 319 &parsed_tbs_cert); | |
| 320 DCHECK(rv); | |
| 321 std::string subject, issuer; | |
| 322 | |
| 323 GetCommonName(parsed_tbs_cert.subject_tlv, &subject); | |
| 324 GetCommonName(parsed_tbs_cert.issuer_tlv, &issuer); | |
| 325 base::Time valid_start, valid_expiry; | |
| 326 DecodeTime(parsed_tbs_cert.validity_not_before, &valid_start); | |
| 327 DecodeTime(parsed_tbs_cert.validity_not_after, &valid_expiry); | |
| 328 | |
| 329 std::map<net::der::Input, net::ParsedExtension> extensions; | |
| 330 rv = net::ParseExtensions(parsed_tbs_cert.extensions_tlv, &extensions); | |
| 331 | |
| 332 std::vector<std::string> san; | |
| 333 if (extensions.find(net::SubjectAltNameOid()) != extensions.end()) { | |
| 334 std::unique_ptr<net::GeneralNames> subject_alt_names = | |
| 335 net::GeneralNames::CreateFromDer( | |
| 336 extensions[net::SubjectAltNameOid()].value); | |
| 337 if (subject_alt_names) { | |
| 338 san = subject_alt_names->dns_names; | |
| 339 for (const net::IPAddress& ip : subject_alt_names->ip_addresses) | |
| 340 san.push_back(ip.ToString()); | |
| 341 } | |
| 342 } | |
| 343 | |
| 344 blink::WebVector<blink::WebString> web_san(san.size()); | |
| 345 std::transform( | |
| 346 san.begin(), | |
| 347 san.end(), web_san.begin(), | |
| 348 [](const std::string& h) { return blink::WebString::fromLatin1(h); }); | |
| 349 | |
| 350 blink::WebVector<blink::WebString> web_cert(info.certificate.size()); | |
| 351 std::transform( | |
| 352 info.certificate.begin(), | |
| 353 info.certificate.end(), web_cert.begin(), | |
| 354 [](const std::string& h) { return blink::WebString::fromLatin1(h); }); | |
| 355 | |
| 287 blink::WebURLResponse::WebSecurityDetails webSecurityDetails( | 356 blink::WebURLResponse::WebSecurityDetails webSecurityDetails( |
| 288 WebString::fromUTF8(protocol), WebString::fromUTF8(key_exchange), | 357 WebString::fromUTF8(protocol), WebString::fromUTF8(key_exchange), |
| 289 WebString::fromUTF8(cipher), WebString::fromUTF8(mac), ssl_status.cert_id, | 358 WebString::fromUTF8(cipher), WebString::fromUTF8(mac), |
| 359 WebString::fromUTF8(subject), | |
| 360 web_san, | |
| 361 WebString::fromUTF8(issuer), | |
| 362 valid_start.ToDoubleT(), | |
| 363 valid_expiry.ToDoubleT(), | |
| 364 web_cert, | |
| 290 sct_list); | 365 sct_list); |
| 291 | 366 |
| 292 response->setSecurityDetails(webSecurityDetails); | 367 response->setSecurityDetails(webSecurityDetails); |
| 293 } | 368 } |
| 294 | 369 |
| 295 } // namespace | 370 } // namespace |
| 296 | 371 |
| 297 // This inner class exists since the WebURLLoader may be deleted while inside a | 372 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 298 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 373 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
| 299 // deleted if it may have work to do after calling into the client. | 374 // deleted if it may have work to do after calling into the client. |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 response->clearHTTPHeaderField(webStringName); | 1288 response->clearHTTPHeaderField(webStringName); |
| 1214 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1289 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1215 response->addHTTPHeaderField(webStringName, | 1290 response->addHTTPHeaderField(webStringName, |
| 1216 WebString::fromLatin1(value)); | 1291 WebString::fromLatin1(value)); |
| 1217 } | 1292 } |
| 1218 } | 1293 } |
| 1219 return true; | 1294 return true; |
| 1220 } | 1295 } |
| 1221 | 1296 |
| 1222 } // namespace content | 1297 } // namespace content |
| OLD | NEW |