| 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/quic/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/channel_id.h" | 7 #include "net/quic/crypto/channel_id.h" |
| 8 #include "net/quic/crypto/common_cert_set.h" | 8 #include "net/quic/crypto/common_cert_set.h" |
| 9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
| 10 #include "net/quic/crypto/quic_crypto_server_config.h" | 10 #include "net/quic/crypto/quic_crypto_server_config.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 scoped_ptr<ChannelIDSource> sync_source_; | 162 scoped_ptr<ChannelIDSource> sync_source_; |
| 163 scoped_ptr<ChannelIDSourceCallback> callback_; | 163 scoped_ptr<ChannelIDSourceCallback> callback_; |
| 164 scoped_ptr<ChannelIDKey> channel_id_key_; | 164 scoped_ptr<ChannelIDKey> channel_id_key_; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 } // anonymous namespace | 167 } // anonymous namespace |
| 168 | 168 |
| 169 CryptoTestUtils::FakeClientOptions::FakeClientOptions() | 169 CryptoTestUtils::FakeClientOptions::FakeClientOptions() |
| 170 : dont_verify_certs(false), | 170 : channel_id_enabled(false), channel_id_source_async(false) {} |
| 171 channel_id_enabled(false), | |
| 172 channel_id_source_async(false) { | |
| 173 } | |
| 174 | 171 |
| 175 // static | 172 // static |
| 176 int CryptoTestUtils::HandshakeWithFakeServer( | 173 int CryptoTestUtils::HandshakeWithFakeServer( |
| 177 PacketSavingConnection* client_conn, | 174 PacketSavingConnection* client_conn, |
| 178 QuicCryptoClientStream* client) { | 175 QuicCryptoClientStream* client) { |
| 179 PacketSavingConnection* server_conn = new PacketSavingConnection( | 176 PacketSavingConnection* server_conn = new PacketSavingConnection( |
| 180 Perspective::IS_SERVER, client_conn->supported_versions()); | 177 Perspective::IS_SERVER, client_conn->supported_versions()); |
| 181 | 178 |
| 182 QuicConfig config = DefaultQuicConfig(); | 179 QuicConfig config = DefaultQuicConfig(); |
| 183 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING, | 180 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING, |
| 184 QuicRandom::GetInstance()); | 181 QuicRandom::GetInstance(), |
| 182 ProofSourceForTesting()); |
| 185 SetupCryptoServerConfigForTest(server_conn->clock(), | 183 SetupCryptoServerConfigForTest(server_conn->clock(), |
| 186 server_conn->random_generator(), &config, | 184 server_conn->random_generator(), &config, |
| 187 &crypto_config); | 185 &crypto_config); |
| 188 | 186 |
| 189 TestQuicSpdyServerSession server_session(server_conn, config, &crypto_config); | 187 TestQuicSpdyServerSession server_session(server_conn, config, &crypto_config); |
| 190 | 188 |
| 191 // The client's handshake must have been started already. | 189 // The client's handshake must have been started already. |
| 192 CHECK_NE(0u, client_conn->encrypted_packets_.size()); | 190 CHECK_NE(0u, client_conn->encrypted_packets_.size()); |
| 193 | 191 |
| 194 CommunicateHandshakeMessages(client_conn, client, server_conn, | 192 CommunicateHandshakeMessages(client_conn, client, server_conn, |
| 195 server_session.GetCryptoStream()); | 193 server_session.GetCryptoStream()); |
| 196 | |
| 197 CompareClientAndServerKeys(client, server_session.GetCryptoStream()); | 194 CompareClientAndServerKeys(client, server_session.GetCryptoStream()); |
| 198 | 195 |
| 199 return client->num_sent_client_hellos(); | 196 return client->num_sent_client_hellos(); |
| 200 } | 197 } |
| 201 | 198 |
| 202 // static | 199 // static |
| 203 int CryptoTestUtils::HandshakeWithFakeClient( | 200 int CryptoTestUtils::HandshakeWithFakeClient( |
| 204 PacketSavingConnection* server_conn, | 201 PacketSavingConnection* server_conn, |
| 205 QuicCryptoServerStream* server, | 202 QuicCryptoServerStream* server, |
| 206 const QuicServerId& server_id, | 203 const QuicServerId& server_id, |
| 207 const FakeClientOptions& options) { | 204 const FakeClientOptions& options) { |
| 208 PacketSavingConnection* client_conn = | 205 PacketSavingConnection* client_conn = |
| 209 new PacketSavingConnection(Perspective::IS_CLIENT); | 206 new PacketSavingConnection(Perspective::IS_CLIENT); |
| 210 // Advance the time, because timers do not like uninitialized times. | 207 // Advance the time, because timers do not like uninitialized times. |
| 211 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 208 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 212 | 209 |
| 213 QuicCryptoClientConfig crypto_config; | 210 QuicCryptoClientConfig crypto_config(ProofVerifierForTesting()); |
| 214 AsyncTestChannelIDSource* async_channel_id_source = nullptr; | 211 AsyncTestChannelIDSource* async_channel_id_source = nullptr; |
| 215 if (options.channel_id_enabled) { | 212 if (options.channel_id_enabled) { |
| 216 | 213 |
| 217 ChannelIDSource* source = ChannelIDSourceForTesting(); | 214 ChannelIDSource* source = ChannelIDSourceForTesting(); |
| 218 if (options.channel_id_source_async) { | 215 if (options.channel_id_source_async) { |
| 219 async_channel_id_source = new AsyncTestChannelIDSource(source); | 216 async_channel_id_source = new AsyncTestChannelIDSource(source); |
| 220 source = async_channel_id_source; | 217 source = async_channel_id_source; |
| 221 } | 218 } |
| 222 crypto_config.SetChannelIDSource(source); | 219 crypto_config.SetChannelIDSource(source); |
| 223 } | 220 } |
| 224 if (!options.dont_verify_certs && server_id.is_https()) { | |
| 225 #if defined(USE_OPENSSL) | |
| 226 crypto_config.SetProofVerifier(ProofVerifierForTesting()); | |
| 227 #else | |
| 228 // TODO(rch): Implement a NSS proof source. | |
| 229 crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); | |
| 230 #endif | |
| 231 } | |
| 232 TestQuicSpdyClientSession client_session(client_conn, DefaultQuicConfig(), | 221 TestQuicSpdyClientSession client_session(client_conn, DefaultQuicConfig(), |
| 233 server_id, &crypto_config); | 222 server_id, &crypto_config); |
| 234 | 223 |
| 235 client_session.GetCryptoStream()->CryptoConnect(); | 224 client_session.GetCryptoStream()->CryptoConnect(); |
| 236 CHECK_EQ(1u, client_conn->encrypted_packets_.size()); | 225 CHECK_EQ(1u, client_conn->encrypted_packets_.size()); |
| 237 | 226 |
| 238 CommunicateHandshakeMessagesAndRunCallbacks( | 227 CommunicateHandshakeMessagesAndRunCallbacks( |
| 239 client_conn, client_session.GetCryptoStream(), server_conn, server, | 228 client_conn, client_session.GetCryptoStream(), server_conn, server, |
| 240 async_channel_id_source); | 229 async_channel_id_source); |
| 241 | 230 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 scoped_ptr<CryptoHandshakeMessage> parsed( | 601 scoped_ptr<CryptoHandshakeMessage> parsed( |
| 613 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 602 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
| 614 CHECK(parsed.get()); | 603 CHECK(parsed.get()); |
| 615 | 604 |
| 616 va_end(ap); | 605 va_end(ap); |
| 617 return *parsed; | 606 return *parsed; |
| 618 } | 607 } |
| 619 | 608 |
| 620 } // namespace test | 609 } // namespace test |
| 621 } // namespace net | 610 } // namespace net |
| OLD | NEW |