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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "net/quic/crypto/channel_id.h" | 10 #include "net/quic/crypto/channel_id.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 : token_binding_enabled(false) {} | 123 : token_binding_enabled(false) {} |
124 | 124 |
125 CryptoTestUtils::FakeClientOptions::FakeClientOptions() | 125 CryptoTestUtils::FakeClientOptions::FakeClientOptions() |
126 : channel_id_enabled(false), | 126 : channel_id_enabled(false), |
127 channel_id_source_async(false), | 127 channel_id_source_async(false), |
128 token_binding_enabled(false) {} | 128 token_binding_enabled(false) {} |
129 | 129 |
130 // static | 130 // static |
131 int CryptoTestUtils::HandshakeWithFakeServer( | 131 int CryptoTestUtils::HandshakeWithFakeServer( |
132 MockConnectionHelper* helper, | 132 MockConnectionHelper* helper, |
| 133 MockAlarmFactory* alarm_factory, |
133 PacketSavingConnection* client_conn, | 134 PacketSavingConnection* client_conn, |
134 QuicCryptoClientStream* client, | 135 QuicCryptoClientStream* client, |
135 const FakeServerOptions& options) { | 136 const FakeServerOptions& options) { |
136 PacketSavingConnection* server_conn = new PacketSavingConnection( | 137 PacketSavingConnection* server_conn = |
137 helper, Perspective::IS_SERVER, client_conn->supported_versions()); | 138 new PacketSavingConnection(helper, alarm_factory, Perspective::IS_SERVER, |
| 139 client_conn->supported_versions()); |
138 | 140 |
139 QuicConfig config = DefaultQuicConfig(); | 141 QuicConfig config = DefaultQuicConfig(); |
140 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING, | 142 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING, |
141 QuicRandom::GetInstance(), | 143 QuicRandom::GetInstance(), |
142 ProofSourceForTesting()); | 144 ProofSourceForTesting()); |
143 QuicCompressedCertsCache compressed_certs_cache( | 145 QuicCompressedCertsCache compressed_certs_cache( |
144 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); | 146 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); |
145 SetupCryptoServerConfigForTest(server_conn->clock(), | 147 SetupCryptoServerConfigForTest(server_conn->clock(), |
146 server_conn->random_generator(), &config, | 148 server_conn->random_generator(), &config, |
147 &crypto_config, options); | 149 &crypto_config, options); |
148 | 150 |
149 TestQuicSpdyServerSession server_session(server_conn, config, &crypto_config, | 151 TestQuicSpdyServerSession server_session(server_conn, config, &crypto_config, |
150 &compressed_certs_cache); | 152 &compressed_certs_cache); |
151 | 153 |
152 // The client's handshake must have been started already. | 154 // The client's handshake must have been started already. |
153 CHECK_NE(0u, client_conn->encrypted_packets_.size()); | 155 CHECK_NE(0u, client_conn->encrypted_packets_.size()); |
154 | 156 |
155 CommunicateHandshakeMessages(client_conn, client, server_conn, | 157 CommunicateHandshakeMessages(client_conn, client, server_conn, |
156 server_session.GetCryptoStream()); | 158 server_session.GetCryptoStream()); |
157 CompareClientAndServerKeys(client, server_session.GetCryptoStream()); | 159 CompareClientAndServerKeys(client, server_session.GetCryptoStream()); |
158 | 160 |
159 return client->num_sent_client_hellos(); | 161 return client->num_sent_client_hellos(); |
160 } | 162 } |
161 | 163 |
162 // static | 164 // static |
163 int CryptoTestUtils::HandshakeWithFakeClient( | 165 int CryptoTestUtils::HandshakeWithFakeClient( |
164 MockConnectionHelper* helper, | 166 MockConnectionHelper* helper, |
| 167 MockAlarmFactory* alarm_factory, |
165 PacketSavingConnection* server_conn, | 168 PacketSavingConnection* server_conn, |
166 QuicCryptoServerStream* server, | 169 QuicCryptoServerStream* server, |
167 const QuicServerId& server_id, | 170 const QuicServerId& server_id, |
168 const FakeClientOptions& options) { | 171 const FakeClientOptions& options) { |
169 PacketSavingConnection* client_conn = | 172 PacketSavingConnection* client_conn = |
170 new PacketSavingConnection(helper, Perspective::IS_CLIENT); | 173 new PacketSavingConnection(helper, alarm_factory, Perspective::IS_CLIENT); |
171 // Advance the time, because timers do not like uninitialized times. | 174 // Advance the time, because timers do not like uninitialized times. |
172 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 175 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
173 | 176 |
174 QuicCryptoClientConfig crypto_config(ProofVerifierForTesting()); | 177 QuicCryptoClientConfig crypto_config(ProofVerifierForTesting()); |
175 AsyncTestChannelIDSource* async_channel_id_source = nullptr; | 178 AsyncTestChannelIDSource* async_channel_id_source = nullptr; |
176 if (options.channel_id_enabled) { | 179 if (options.channel_id_enabled) { |
177 ChannelIDSource* source = ChannelIDSourceForTesting(); | 180 ChannelIDSource* source = ChannelIDSourceForTesting(); |
178 if (options.channel_id_source_async) { | 181 if (options.channel_id_source_async) { |
179 async_channel_id_source = new AsyncTestChannelIDSource(source); | 182 async_channel_id_source = new AsyncTestChannelIDSource(source); |
180 source = async_channel_id_source; | 183 source = async_channel_id_source; |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 647 |
645 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining()); | 648 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining()); |
646 | 649 |
647 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) { | 650 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) { |
648 dest_stream->OnHandshakeMessage(message); | 651 dest_stream->OnHandshakeMessage(message); |
649 } | 652 } |
650 } | 653 } |
651 | 654 |
652 } // namespace test | 655 } // namespace test |
653 } // namespace net | 656 } // namespace net |
OLD | NEW |