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 "net/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
6 | 6 |
| 7 #include "base/base64.h" |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "base/profiler/scoped_tracker.h" | 12 #include "base/profiler/scoped_tracker.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
15 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
16 #include "net/base/upload_data_stream.h" | 17 #include "net/base/upload_data_stream.h" |
17 #include "net/http/http_chunked_decoder.h" | 18 #include "net/http/http_chunked_decoder.h" |
18 #include "net/http/http_request_headers.h" | 19 #include "net/http/http_request_headers.h" |
19 #include "net/http/http_request_info.h" | 20 #include "net/http/http_request_info.h" |
20 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
21 #include "net/http/http_status_line_validator.h" | 22 #include "net/http/http_status_line_validator.h" |
22 #include "net/http/http_util.h" | 23 #include "net/http/http_util.h" |
23 #include "net/socket/client_socket_handle.h" | 24 #include "net/socket/client_socket_handle.h" |
24 #include "net/socket/ssl_client_socket.h" | 25 #include "net/socket/ssl_client_socket.h" |
| 26 #include "net/ssl/token_binding.h" |
25 | 27 |
26 namespace net { | 28 namespace net { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 enum HttpHeaderParserEvent { | 32 enum HttpHeaderParserEvent { |
31 HEADER_PARSER_INVOKED = 0, | 33 HEADER_PARSER_INVOKED = 0, |
32 // Obsolete: HEADER_HTTP_09_RESPONSE = 1, | 34 // Obsolete: HEADER_HTTP_09_RESPONSE = 1, |
33 HEADER_ALLOWED_TRUNCATED_HEADERS = 2, | 35 HEADER_ALLOWED_TRUNCATED_HEADERS = 2, |
34 HEADER_SKIPPED_WS_PREFIX = 3, | 36 HEADER_SKIPPED_WS_PREFIX = 3, |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 | 1093 |
1092 void HttpStreamParser::GetSSLCertRequestInfo( | 1094 void HttpStreamParser::GetSSLCertRequestInfo( |
1093 SSLCertRequestInfo* cert_request_info) { | 1095 SSLCertRequestInfo* cert_request_info) { |
1094 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { | 1096 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { |
1095 SSLClientSocket* ssl_socket = | 1097 SSLClientSocket* ssl_socket = |
1096 static_cast<SSLClientSocket*>(connection_->socket()); | 1098 static_cast<SSLClientSocket*>(connection_->socket()); |
1097 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 1099 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
1098 } | 1100 } |
1099 } | 1101 } |
1100 | 1102 |
| 1103 int HttpStreamParser::GetTokenBindingMessageHeader(std::string* out) { |
| 1104 if (!request_->url.SchemeIsCryptographic() || !connection_->socket()) { |
| 1105 *out = ""; |
| 1106 return OK; |
| 1107 } |
| 1108 SSLClientSocket* ssl_socket = |
| 1109 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1110 SSLInfo ssl_info; |
| 1111 if (!ssl_socket->GetSSLInfo(&ssl_info) || |
| 1112 !ssl_info.token_binding_negotiated) { |
| 1113 *out = ""; |
| 1114 return OK; |
| 1115 } |
| 1116 std::string provided_token_binding = ssl_socket->GetProvidedTokenBinding(); |
| 1117 if (provided_token_binding == "") { |
| 1118 *out = ""; |
| 1119 return OK; |
| 1120 } |
| 1121 std::string token_binding_message; |
| 1122 std::vector<std::string> token_bindings; |
| 1123 token_bindings.push_back(provided_token_binding); |
| 1124 int rv; |
| 1125 if ((rv = BuildTokenBindingMessageFromTokenBindings( |
| 1126 token_bindings, &token_binding_message)) != OK) { |
| 1127 return rv; |
| 1128 } |
| 1129 base::Base64Encode(token_binding_message, out); |
| 1130 base::ReplaceChars(*out, "+", "-", out); |
| 1131 base::ReplaceChars(*out, "/", "_", out); |
| 1132 return OK; |
| 1133 } |
| 1134 |
1101 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, | 1135 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, |
1102 char* output, | 1136 char* output, |
1103 size_t output_size) { | 1137 size_t output_size) { |
1104 if (output_size < payload.size() + kChunkHeaderFooterSize) | 1138 if (output_size < payload.size() + kChunkHeaderFooterSize) |
1105 return ERR_INVALID_ARGUMENT; | 1139 return ERR_INVALID_ARGUMENT; |
1106 | 1140 |
1107 char* cursor = output; | 1141 char* cursor = output; |
1108 // Add the header. | 1142 // Add the header. |
1109 const int num_chars = base::snprintf(output, output_size, | 1143 const int num_chars = base::snprintf(output, output_size, |
1110 "%X\r\n", | 1144 "%X\r\n", |
(...skipping 27 matching lines...) Expand all Loading... |
1138 } | 1172 } |
1139 | 1173 |
1140 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { | 1174 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { |
1141 HttpStatusLineValidator::StatusLineStatus status = | 1175 HttpStatusLineValidator::StatusLineStatus status = |
1142 HttpStatusLineValidator::ValidateStatusLine(status_line); | 1176 HttpStatusLineValidator::ValidateStatusLine(status_line); |
1143 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, | 1177 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, |
1144 HttpStatusLineValidator::STATUS_LINE_MAX); | 1178 HttpStatusLineValidator::STATUS_LINE_MAX); |
1145 } | 1179 } |
1146 | 1180 |
1147 } // namespace net | 1181 } // namespace net |
OLD | NEW |