Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: net/tools/quic/test_tools/quic_test_client.cc

Issue 1397983007: relnote: remove insecure QUIC support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rch_insecure_quic
Patch Set: Compile fix Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/test_tools/quic_test_client.h ('k') | net/tools/quic/test_tools/server_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tools/quic/test_tools/quic_test_client.h" 5 #include "net/tools/quic/test_tools/quic_test_client.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/cert/cert_verify_result.h" 10 #include "net/cert/cert_verify_result.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 const string& common_name() const { return common_name_; } 77 const string& common_name() const { return common_name_; }
78 78
79 private: 79 private:
80 string common_name_; 80 string common_name_;
81 }; 81 };
82 82
83 } // anonymous namespace 83 } // anonymous namespace
84 84
85 BalsaHeaders* MungeHeaders(const BalsaHeaders* const_headers, 85 BalsaHeaders* MungeHeaders(const BalsaHeaders* const_headers) {
86 bool secure) {
87 StringPiece uri = const_headers->request_uri(); 86 StringPiece uri = const_headers->request_uri();
88 if (uri.empty()) { 87 if (uri.empty()) {
89 return nullptr; 88 return nullptr;
90 } 89 }
91 if (const_headers->request_method() == "CONNECT") { 90 if (const_headers->request_method() == "CONNECT") {
92 return nullptr; 91 return nullptr;
93 } 92 }
94 BalsaHeaders* headers = new BalsaHeaders; 93 BalsaHeaders* headers = new BalsaHeaders;
95 headers->CopyFrom(*const_headers); 94 headers->CopyFrom(*const_headers);
96 if (!uri.starts_with("https://") && 95 if (!uri.starts_with("https://") &&
97 !uri.starts_with("http://")) { 96 !uri.starts_with("http://")) {
98 // If we have a relative URL, set some defaults. 97 // If we have a relative URL, set some defaults.
99 string full_uri = secure ? "https://www.google.com" : 98 string full_uri = "https://www.google.com";
100 "http://www.google.com";
101 full_uri.append(uri.as_string()); 99 full_uri.append(uri.as_string());
102 headers->SetRequestUri(full_uri); 100 headers->SetRequestUri(full_uri);
103 } 101 }
104 return headers; 102 return headers;
105 } 103 }
106 104
107 MockableQuicClient::MockableQuicClient( 105 MockableQuicClient::MockableQuicClient(
108 IPEndPoint server_address, 106 IPEndPoint server_address,
109 const QuicServerId& server_id, 107 const QuicServerId& server_id,
110 const QuicVersionVector& supported_versions, 108 const QuicVersionVector& supported_versions,
111 EpollServer* epoll_server) 109 EpollServer* epoll_server)
112 : QuicClient(server_address, 110 : QuicClient(server_address,
113 server_id, 111 server_id,
114 supported_versions, 112 supported_versions,
115 epoll_server), 113 epoll_server,
114 new RecordingProofVerifier()),
116 override_connection_id_(0), 115 override_connection_id_(0),
117 test_writer_(nullptr) {} 116 test_writer_(nullptr) {}
118 117
119 MockableQuicClient::MockableQuicClient( 118 MockableQuicClient::MockableQuicClient(
120 IPEndPoint server_address, 119 IPEndPoint server_address,
121 const QuicServerId& server_id, 120 const QuicServerId& server_id,
122 const QuicConfig& config, 121 const QuicConfig& config,
123 const QuicVersionVector& supported_versions, 122 const QuicVersionVector& supported_versions,
124 EpollServer* epoll_server) 123 EpollServer* epoll_server)
125 : QuicClient(server_address, 124 : QuicClient(server_address,
126 server_id, 125 server_id,
127 supported_versions, 126 supported_versions,
128 config, 127 config,
129 epoll_server), 128 epoll_server,
129 new RecordingProofVerifier()),
130 override_connection_id_(0), 130 override_connection_id_(0),
131 test_writer_(nullptr) {} 131 test_writer_(nullptr) {}
132 132
133 MockableQuicClient::~MockableQuicClient() { 133 MockableQuicClient::~MockableQuicClient() {
134 if (connected()) { 134 if (connected()) {
135 Disconnect(); 135 Disconnect();
136 } 136 }
137 } 137 }
138 138
139 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() { 139 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() {
(...skipping 15 matching lines...) Expand all
155 CHECK(test_writer_ == nullptr); 155 CHECK(test_writer_ == nullptr);
156 test_writer_ = writer; 156 test_writer_ = writer;
157 } 157 }
158 158
159 void MockableQuicClient::UseConnectionId(QuicConnectionId connection_id) { 159 void MockableQuicClient::UseConnectionId(QuicConnectionId connection_id) {
160 override_connection_id_ = connection_id; 160 override_connection_id_ = connection_id;
161 } 161 }
162 162
163 QuicTestClient::QuicTestClient(IPEndPoint server_address, 163 QuicTestClient::QuicTestClient(IPEndPoint server_address,
164 const string& server_hostname, 164 const string& server_hostname,
165 bool secure,
166 const QuicVersionVector& supported_versions) 165 const QuicVersionVector& supported_versions)
167 : client_(new MockableQuicClient(server_address, 166 : client_(new MockableQuicClient(server_address,
168 QuicServerId(server_hostname, 167 QuicServerId(server_hostname,
169 server_address.port(), 168 server_address.port(),
170 secure,
171 PRIVACY_MODE_DISABLED), 169 PRIVACY_MODE_DISABLED),
172 supported_versions, 170 supported_versions,
173 &epoll_server_)) { 171 &epoll_server_)) {
174 Initialize(secure); 172 Initialize();
175 } 173 }
176 174
177 QuicTestClient::QuicTestClient( 175 QuicTestClient::QuicTestClient(
178 IPEndPoint server_address, 176 IPEndPoint server_address,
179 const string& server_hostname, 177 const string& server_hostname,
180 bool secure,
181 const QuicConfig& config, 178 const QuicConfig& config,
182 const QuicVersionVector& supported_versions) 179 const QuicVersionVector& supported_versions)
183 : client_( 180 : client_(
184 new MockableQuicClient(server_address, 181 new MockableQuicClient(server_address,
185 QuicServerId(server_hostname, 182 QuicServerId(server_hostname,
186 server_address.port(), 183 server_address.port(),
187 secure,
188 PRIVACY_MODE_DISABLED), 184 PRIVACY_MODE_DISABLED),
189 config, 185 config,
190 supported_versions, 186 supported_versions,
191 &epoll_server_)) { 187 &epoll_server_)) {
192 Initialize(secure); 188 Initialize();
193 } 189 }
194 190
195 QuicTestClient::QuicTestClient() { 191 QuicTestClient::QuicTestClient() {
196 } 192 }
197 193
198 QuicTestClient::~QuicTestClient() { 194 QuicTestClient::~QuicTestClient() {
199 if (stream_) { 195 if (stream_) {
200 stream_->set_visitor(nullptr); 196 stream_->set_visitor(nullptr);
201 } 197 }
202 } 198 }
203 199
204 void QuicTestClient::Initialize(bool secure) { 200 void QuicTestClient::Initialize() {
205 priority_ = 3; 201 priority_ = 3;
206 connect_attempted_ = false; 202 connect_attempted_ = false;
207 secure_ = secure;
208 auto_reconnect_ = false; 203 auto_reconnect_ = false;
209 buffer_body_ = true; 204 buffer_body_ = true;
210 fec_policy_ = FEC_PROTECT_OPTIONAL; 205 fec_policy_ = FEC_PROTECT_OPTIONAL;
211 proof_verifier_ = nullptr;
212 ClearPerRequestState(); 206 ClearPerRequestState();
213 ExpectCertificates(secure_);
214 // As chrome will generally do this, we want it to be the default when it's 207 // As chrome will generally do this, we want it to be the default when it's
215 // not overridden. 208 // not overridden.
216 if (!client_->config()->HasSetBytesForConnectionIdToSend()) { 209 if (!client_->config()->HasSetBytesForConnectionIdToSend()) {
217 client_->config()->SetBytesForConnectionIdToSend(0); 210 client_->config()->SetBytesForConnectionIdToSend(0);
218 } 211 }
219 } 212 }
220 213
221 void QuicTestClient::ExpectCertificates(bool on) {
222 if (on) {
223 proof_verifier_ = new RecordingProofVerifier;
224 client_->SetProofVerifier(proof_verifier_);
225 } else {
226 proof_verifier_ = nullptr;
227 client_->SetProofVerifier(nullptr);
228 }
229 }
230
231 void QuicTestClient::SetUserAgentID(const string& user_agent_id) { 214 void QuicTestClient::SetUserAgentID(const string& user_agent_id) {
232 client_->SetUserAgentID(user_agent_id); 215 client_->SetUserAgentID(user_agent_id);
233 } 216 }
234 217
235 ssize_t QuicTestClient::SendRequest(const string& uri) { 218 ssize_t QuicTestClient::SendRequest(const string& uri) {
236 HTTPMessage message; 219 HTTPMessage message;
237 FillInRequest(uri, &message); 220 FillInRequest(uri, &message);
238 return SendMessage(message); 221 return SendMessage(message);
239 } 222 }
240 223
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return ret; 273 return ret;
291 } 274 }
292 275
293 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { 276 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) {
294 stream_ = nullptr; // Always force creation of a stream for SendMessage. 277 stream_ = nullptr; // Always force creation of a stream for SendMessage.
295 278
296 // If we're not connected, try to find an sni hostname. 279 // If we're not connected, try to find an sni hostname.
297 if (!connected()) { 280 if (!connected()) {
298 GURL url(message.headers()->request_uri().as_string()); 281 GURL url(message.headers()->request_uri().as_string());
299 if (!url.host().empty()) { 282 if (!url.host().empty()) {
300 client_->set_server_id( 283 client_->set_server_id(QuicServerId(url.host(), url.EffectiveIntPort(),
301 QuicServerId(url.host(), 284 PRIVACY_MODE_DISABLED));
302 url.EffectiveIntPort(),
303 url.SchemeIs("https"),
304 PRIVACY_MODE_DISABLED));
305 } 285 }
306 } 286 }
307 287
308 // TODO(rtenneti): Add support for HTTPMessage::body_chunks(). 288 // TODO(rtenneti): Add support for HTTPMessage::body_chunks().
309 // CHECK(message.body_chunks().empty()) 289 // CHECK(message.body_chunks().empty())
310 // << "HTTPMessage::body_chunks not supported"; 290 // << "HTTPMessage::body_chunks not supported";
311 291
312 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), 292 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers()));
313 secure_));
314 ssize_t ret = GetOrCreateStreamAndSendRequest( 293 ssize_t ret = GetOrCreateStreamAndSendRequest(
315 (munged_headers.get() ? munged_headers.get() : message.headers()), 294 (munged_headers.get() ? munged_headers.get() : message.headers()),
316 message.body(), message.has_complete_message(), nullptr); 295 message.body(), message.has_complete_message(), nullptr);
317 WaitForWriteToFlush(); 296 WaitForWriteToFlush();
318 return ret; 297 return ret;
319 } 298 }
320 299
321 ssize_t QuicTestClient::SendData(const string& data, bool last_data) { 300 ssize_t QuicTestClient::SendData(const string& data, bool last_data) {
322 return SendData(data, last_data, nullptr); 301 return SendData(data, last_data, nullptr);
323 } 302 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 return stream_; 379 return stream_;
401 } 380 }
402 381
403 QuicErrorCode QuicTestClient::connection_error() { 382 QuicErrorCode QuicTestClient::connection_error() {
404 return client()->connection_error(); 383 return client()->connection_error();
405 } 384 }
406 385
407 MockableQuicClient* QuicTestClient::client() { return client_.get(); } 386 MockableQuicClient* QuicTestClient::client() { return client_.get(); }
408 387
409 const string& QuicTestClient::cert_common_name() const { 388 const string& QuicTestClient::cert_common_name() const {
410 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_) 389 return reinterpret_cast<RecordingProofVerifier*>(client_->proof_verifier())
411 ->common_name(); 390 ->common_name();
412 } 391 }
413 392
414 QuicTagValueMap QuicTestClient::GetServerConfig() const { 393 QuicTagValueMap QuicTestClient::GetServerConfig() const {
415 QuicCryptoClientConfig* config = client_->crypto_config(); 394 QuicCryptoClientConfig* config = client_->crypto_config();
416 QuicCryptoClientConfig::CachedState* state = 395 QuicCryptoClientConfig::CachedState* state =
417 config->LookupOrCreate(client_->server_id()); 396 config->LookupOrCreate(client_->server_id());
418 const CryptoHandshakeMessage* handshake_msg = state->GetServerConfig(); 397 const CryptoHandshakeMessage* handshake_msg = state->GetServerConfig();
419 if (handshake_msg != nullptr) { 398 if (handshake_msg != nullptr) {
420 return handshake_msg->tag_value_map(); 399 return handshake_msg->tag_value_map();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 message->headers()->SetRequestVersion( 620 message->headers()->SetRequestVersion(
642 HTTPMessage::VersionToString(HttpConstants::HTTP_1_1)); 621 HTTPMessage::VersionToString(HttpConstants::HTTP_1_1));
643 message->headers()->SetRequestMethod( 622 message->headers()->SetRequestMethod(
644 HTTPMessage::MethodToString(HttpConstants::GET)); 623 HTTPMessage::MethodToString(HttpConstants::GET));
645 message->headers()->SetRequestUri(uri); 624 message->headers()->SetRequestUri(uri);
646 } 625 }
647 626
648 } // namespace test 627 } // namespace test
649 } // namespace tools 628 } // namespace tools
650 } // namespace net 629 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_client.h ('k') | net/tools/quic/test_tools/server_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698