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