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

Side by Side Diff: net/quic/test_tools/crypto_test_utils.cc

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 years, 6 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 | Annotate | Revision Log
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/quic/test_tools/crypto_test_utils.h" 5 #include "net/quic/test_tools/crypto_test_utils.h"
6 6
7 #include "net/quic/crypto/common_cert_set.h" 7 #include "net/quic/crypto/common_cert_set.h"
8 #include "net/quic/crypto/crypto_handshake.h" 8 #include "net/quic/crypto/crypto_handshake.h"
9 #include "net/quic/crypto/crypto_server_config.h" 9 #include "net/quic/crypto/crypto_server_config.h"
10 #include "net/quic/crypto/quic_decrypter.h" 10 #include "net/quic/crypto/quic_decrypter.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 102
103 // HexChar parses |c| as a hex character. If valid, it sets |*value| to the 103 // HexChar parses |c| as a hex character. If valid, it sets |*value| to the
104 // value of the hex character and returns true. Otherwise it returns false. 104 // value of the hex character and returns true. Otherwise it returns false.
105 bool HexChar(char c, uint8* value) { 105 bool HexChar(char c, uint8* value) {
106 if (c >= '0' && c <= '9') { 106 if (c >= '0' && c <= '9') {
107 *value = c - '0'; 107 *value = c - '0';
108 return true; 108 return true;
109 } 109 }
110 if (c >= 'a' && c <= 'f') { 110 if (c >= 'a' && c <= 'f') {
111 *value = c - 'a'; 111 *value = c - 'a' + 10;
112 return true; 112 return true;
113 } 113 }
114 if (c >= 'A' && c <= 'F') { 114 if (c >= 'A' && c <= 'F') {
115 *value = c - 'A'; 115 *value = c - 'A' + 10;
116 return true; 116 return true;
117 } 117 }
118 return false; 118 return false;
119 } 119 }
120 120
121 } // anonymous namespace 121 } // anonymous namespace
122 122
123 CryptoTestUtils::FakeClientOptions::FakeClientOptions() 123 CryptoTestUtils::FakeClientOptions::FakeClientOptions()
124 : dont_verify_certs(false) { 124 : dont_verify_certs(false),
125 channel_id_enabled(false) {
125 } 126 }
126 127
127 // static 128 // static
128 int CryptoTestUtils::HandshakeWithFakeServer( 129 int CryptoTestUtils::HandshakeWithFakeServer(
129 PacketSavingConnection* client_conn, 130 PacketSavingConnection* client_conn,
130 QuicCryptoClientStream* client) { 131 QuicCryptoClientStream* client) {
131 QuicGuid guid(1); 132 QuicGuid guid(1);
132 IPAddressNumber ip; 133 IPAddressNumber ip;
133 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); 134 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
134 IPEndPoint addr = IPEndPoint(ip, 1); 135 IPEndPoint addr = IPEndPoint(ip, 1);
135 PacketSavingConnection* server_conn = 136 PacketSavingConnection* server_conn =
136 new PacketSavingConnection(guid, addr, true); 137 new PacketSavingConnection(guid, addr, true);
137 TestSession server_session(server_conn, QuicConfig(), true); 138 TestSession server_session(server_conn, QuicConfig(), true);
138 139
139 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING); 140 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING,
141 QuicRandom::GetInstance());
140 SetupCryptoServerConfigForTest( 142 SetupCryptoServerConfigForTest(
141 server_session.connection()->clock(), 143 server_session.connection()->clock(),
142 server_session.connection()->random_generator(), 144 server_session.connection()->random_generator(),
143 server_session.config(), &crypto_config); 145 server_session.config(), &crypto_config);
144 146
145 QuicCryptoServerStream server(crypto_config, &server_session); 147 QuicCryptoServerStream server(crypto_config, &server_session);
146 server_session.SetCryptoStream(&server); 148 server_session.SetCryptoStream(&server);
147 149
148 // The client's handshake must have been started already. 150 // The client's handshake must have been started already.
149 CHECK_NE(0u, client_conn->packets_.size()); 151 CHECK_NE(0u, client_conn->packets_.size());
(...skipping 16 matching lines...) Expand all
166 IPEndPoint addr = IPEndPoint(ip, 1); 168 IPEndPoint addr = IPEndPoint(ip, 1);
167 PacketSavingConnection* client_conn = 169 PacketSavingConnection* client_conn =
168 new PacketSavingConnection(guid, addr, false); 170 new PacketSavingConnection(guid, addr, false);
169 TestSession client_session(client_conn, QuicConfig(), false); 171 TestSession client_session(client_conn, QuicConfig(), false);
170 QuicCryptoClientConfig crypto_config; 172 QuicCryptoClientConfig crypto_config;
171 173
172 client_session.config()->SetDefaults(); 174 client_session.config()->SetDefaults();
173 crypto_config.SetDefaults(); 175 crypto_config.SetDefaults();
174 // TODO(rtenneti): Enable testing of ProofVerifier. 176 // TODO(rtenneti): Enable testing of ProofVerifier.
175 // if (!options.dont_verify_certs) { 177 // if (!options.dont_verify_certs) {
176 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); 178 // crypto_config.SetProofVerifier(ProofVerifierForTesting());
177 // } 179 // }
180 if (options.channel_id_enabled) {
181 crypto_config.SetChannelIDSigner(ChannelIDSignerForTesting());
182 }
178 QuicCryptoClientStream client("test.example.com", &client_session, 183 QuicCryptoClientStream client("test.example.com", &client_session,
179 &crypto_config); 184 &crypto_config);
180 client_session.SetCryptoStream(&client); 185 client_session.SetCryptoStream(&client);
181 186
182 CHECK(client.CryptoConnect()); 187 CHECK(client.CryptoConnect());
183 CHECK_EQ(1u, client_conn->packets_.size()); 188 CHECK_EQ(1u, client_conn->packets_.size());
184 189
185 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); 190 CommunicateHandshakeMessages(client_conn, &client, server_conn, server);
186 191
187 CompareClientAndServerKeys(&client, server); 192 CompareClientAndServerKeys(&client, server);
188 193
189 return client.num_sent_client_hellos(); 194 return client.num_sent_client_hellos();
190 } 195 }
191 196
192 // static 197 // static
193 void CryptoTestUtils::SetupCryptoServerConfigForTest( 198 void CryptoTestUtils::SetupCryptoServerConfigForTest(
194 const QuicClock* clock, 199 const QuicClock* clock,
195 QuicRandom* rand, 200 QuicRandom* rand,
196 QuicConfig* config, 201 QuicConfig* config,
197 QuicCryptoServerConfig* crypto_config) { 202 QuicCryptoServerConfig* crypto_config) {
198 config->SetDefaults(); 203 config->SetDefaults();
204 QuicCryptoServerConfig::ConfigOptions options;
205 options.channel_id_enabled = true;
199 scoped_ptr<CryptoHandshakeMessage> scfg( 206 scoped_ptr<CryptoHandshakeMessage> scfg(
200 crypto_config->AddDefaultConfig( 207 crypto_config->AddDefaultConfig(rand, clock, options));
201 rand, clock, QuicCryptoServerConfig::kDefaultExpiry));
202 } 208 }
203 209
204 // static 210 // static
205 void CryptoTestUtils::CommunicateHandshakeMessages( 211 void CryptoTestUtils::CommunicateHandshakeMessages(
206 PacketSavingConnection* a_conn, 212 PacketSavingConnection* a_conn,
207 QuicCryptoStream* a, 213 QuicCryptoStream* a,
208 PacketSavingConnection* b_conn, 214 PacketSavingConnection* b_conn,
209 QuicCryptoStream* b) { 215 QuicCryptoStream* b) {
210 size_t a_i = 0, b_i = 0; 216 size_t a_i = 0, b_i = 0;
211 while (!a->handshake_confirmed()) { 217 while (!a->handshake_confirmed()) {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 469 }
464 470
465 msg.SetStringPiece(tag, valuestr); 471 msg.SetStringPiece(tag, valuestr);
466 } 472 }
467 473
468 return msg; 474 return msg;
469 } 475 }
470 476
471 } // namespace test 477 } // namespace test
472 } // namespace net 478 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698