QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_crypto_client_stream.h" |
| 6 | |
| 7 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 9 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 11 | #include "net/third_party/quiche/src/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h" |
| 13 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/quic_server_id.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 18 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 19 | #include "net/third_party/quiche/src/quic/test_tools/crypto_test_utils.h" |
| 20 | #include "net/third_party/quiche/src/quic/test_tools/quic_stream_peer.h" |
| 21 | #include "net/third_party/quiche/src/quic/test_tools/quic_stream_sequencer_peer.h" |
| 22 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 23 | #include "net/third_party/quiche/src/quic/test_tools/simple_quic_framer.h" |
nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/test_tools/simple_session_cache.h" |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 25 | #include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h" |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 26 | #include "net/third_party/quiche/src/common/test_tools/quiche_test_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | |
| 28 | using testing::_; |
| 29 | |
| 30 | namespace quic { |
| 31 | namespace test { |
| 32 | namespace { |
| 33 | |
| 34 | const char kServerHostname[] = "test.example.com"; |
| 35 | const uint16_t kServerPort = 443; |
| 36 | |
nharper | c1873ae | 2020-04-15 11:24:25 -0700 | [diff] [blame] | 37 | // This test tests the client-side of the QUIC crypto handshake. It does not |
| 38 | // test the TLS handshake - that is in tls_client_handshaker_test.cc. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 39 | class QuicCryptoClientStreamTest : public QuicTest { |
| 40 | public: |
| 41 | QuicCryptoClientStreamTest() |
nharper | c1873ae | 2020-04-15 11:24:25 -0700 | [diff] [blame] | 42 | : supported_versions_(AllSupportedVersionsWithQuicCrypto()), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | server_id_(kServerHostname, kServerPort, false), |
nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 44 | crypto_config_(crypto_test_utils::ProofVerifierForTesting(), |
| 45 | std::make_unique<test::SimpleSessionCache>()), |
| 46 | server_crypto_config_( |
| 47 | crypto_test_utils::CryptoServerConfigForTesting()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | CreateConnection(); |
| 49 | } |
| 50 | |
dschinazi | dffd298 | 2020-03-02 10:25:11 -0800 | [diff] [blame] | 51 | void CreateSession() { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 52 | session_ = std::make_unique<TestQuicSpdyClientSession>( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 53 | connection_, DefaultQuicConfig(), supported_versions_, server_id_, |
| 54 | &crypto_config_); |
vasilvv | efc6af8 | 2019-10-11 12:46:56 -0700 | [diff] [blame] | 55 | EXPECT_CALL(*session_, GetAlpnsToOffer()) |
| 56 | .WillRepeatedly(testing::Return(std::vector<std::string>( |
| 57 | {AlpnForVersion(connection_->version())}))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 58 | } |
| 59 | |
dschinazi | dffd298 | 2020-03-02 10:25:11 -0800 | [diff] [blame] | 60 | void CreateConnection() { |
| 61 | connection_ = |
| 62 | new PacketSavingConnection(&client_helper_, &alarm_factory_, |
| 63 | Perspective::IS_CLIENT, supported_versions_); |
| 64 | // Advance the time, because timers do not like uninitialized times. |
| 65 | connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 66 | CreateSession(); |
| 67 | } |
| 68 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 69 | void CompleteCryptoHandshake() { |
nharper | 1473c09 | 2019-11-11 13:13:19 -0800 | [diff] [blame] | 70 | int proof_verify_details_calls = 1; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 71 | if (stream()->handshake_protocol() != PROTOCOL_TLS1_3) { |
| 72 | EXPECT_CALL(*session_, OnProofValid(testing::_)); |
nharper | 1473c09 | 2019-11-11 13:13:19 -0800 | [diff] [blame] | 73 | proof_verify_details_calls = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 74 | } |
| 75 | EXPECT_CALL(*session_, OnProofVerifyDetailsAvailable(testing::_)) |
nharper | 1473c09 | 2019-11-11 13:13:19 -0800 | [diff] [blame] | 76 | .Times(testing::AtLeast(proof_verify_details_calls)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 77 | stream()->CryptoConnect(); |
| 78 | QuicConfig config; |
nharper | ba5f32c | 2019-05-13 12:21:31 -0700 | [diff] [blame] | 79 | crypto_test_utils::HandshakeWithFakeServer( |
rch | 83f29bd | 2019-11-13 11:47:34 -0800 | [diff] [blame] | 80 | &config, server_crypto_config_.get(), &server_helper_, &alarm_factory_, |
nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 81 | connection_, stream(), AlpnForVersion(connection_->version())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | QuicCryptoClientStream* stream() { |
| 85 | return session_->GetMutableCryptoStream(); |
| 86 | } |
| 87 | |
| 88 | MockQuicConnectionHelper server_helper_; |
| 89 | MockQuicConnectionHelper client_helper_; |
| 90 | MockAlarmFactory alarm_factory_; |
| 91 | PacketSavingConnection* connection_; |
| 92 | ParsedQuicVersionVector supported_versions_; |
| 93 | std::unique_ptr<TestQuicSpdyClientSession> session_; |
| 94 | QuicServerId server_id_; |
| 95 | CryptoHandshakeMessage message_; |
| 96 | QuicCryptoClientConfig crypto_config_; |
rch | 83f29bd | 2019-11-13 11:47:34 -0800 | [diff] [blame] | 97 | std::unique_ptr<QuicCryptoServerConfig> server_crypto_config_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) { |
| 101 | EXPECT_FALSE(stream()->encryption_established()); |
fayang | 685367a | 2020-01-14 10:40:15 -0800 | [diff] [blame] | 102 | EXPECT_FALSE(stream()->one_rtt_keys_available()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) { |
| 106 | CompleteCryptoHandshake(); |
| 107 | EXPECT_TRUE(stream()->encryption_established()); |
fayang | 685367a | 2020-01-14 10:40:15 -0800 | [diff] [blame] | 108 | EXPECT_TRUE(stream()->one_rtt_keys_available()); |
nharper | 0270396 | 2019-11-07 12:23:13 -0800 | [diff] [blame] | 109 | EXPECT_FALSE(stream()->IsResumption()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 110 | } |
| 111 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 112 | TEST_F(QuicCryptoClientStreamTest, MessageAfterHandshake) { |
| 113 | CompleteCryptoHandshake(); |
| 114 | |
| 115 | EXPECT_CALL( |
| 116 | *connection_, |
| 117 | CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE, _, _)); |
| 118 | message_.set_tag(kCHLO); |
| 119 | crypto_test_utils::SendHandshakeMessageToStream(stream(), message_, |
| 120 | Perspective::IS_CLIENT); |
| 121 | } |
| 122 | |
| 123 | TEST_F(QuicCryptoClientStreamTest, BadMessageType) { |
| 124 | stream()->CryptoConnect(); |
| 125 | |
| 126 | message_.set_tag(kCHLO); |
| 127 | |
| 128 | EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE, |
| 129 | "Expected REJ", _)); |
| 130 | crypto_test_utils::SendHandshakeMessageToStream(stream(), message_, |
| 131 | Perspective::IS_CLIENT); |
| 132 | } |
| 133 | |
| 134 | TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { |
| 135 | CompleteCryptoHandshake(); |
| 136 | |
| 137 | const QuicConfig* config = session_->config(); |
| 138 | EXPECT_EQ(kMaximumIdleTimeoutSecs, config->IdleNetworkTimeout().ToSeconds()); |
| 139 | |
| 140 | const QuicCryptoNegotiatedParameters& crypto_params( |
| 141 | stream()->crypto_negotiated_params()); |
| 142 | EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); |
| 143 | EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); |
| 144 | } |
| 145 | |
| 146 | TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
| 147 | // Seed the config with a cached server config. |
| 148 | CompleteCryptoHandshake(); |
| 149 | |
| 150 | // Recreate connection with the new config. |
| 151 | CreateConnection(); |
| 152 | |
| 153 | // Advance time 5 years to ensure that we pass the expiry time of the cached |
| 154 | // server config. |
| 155 | connection_->AdvanceTime( |
| 156 | QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
| 157 | |
| 158 | EXPECT_CALL(*session_, OnProofValid(testing::_)); |
| 159 | stream()->CryptoConnect(); |
| 160 | // Check that a client hello was sent. |
| 161 | ASSERT_EQ(1u, connection_->encrypted_packets_.size()); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 162 | EXPECT_EQ(ENCRYPTION_INITIAL, connection_->encryption_level()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 163 | } |
| 164 | |
renjietang | 1b5d1e1 | 2020-06-23 17:45:20 -0700 | [diff] [blame^] | 165 | TEST_F(QuicCryptoClientStreamTest, ClientTurnedOffZeroRtt) { |
| 166 | // Seed the config with a cached server config. |
| 167 | CompleteCryptoHandshake(); |
| 168 | |
| 169 | // Recreate connection with the new config. |
| 170 | CreateConnection(); |
| 171 | |
| 172 | // Set connection option. |
| 173 | QuicTagVector options; |
| 174 | options.push_back(kQNZR); |
| 175 | session_->config()->SetClientConnectionOptions(options); |
| 176 | |
| 177 | EXPECT_CALL(*session_, OnProofValid(testing::_)); |
| 178 | stream()->CryptoConnect(); |
| 179 | // Check that a client hello was sent. |
| 180 | ASSERT_EQ(1u, connection_->encrypted_packets_.size()); |
| 181 | EXPECT_EQ(ENCRYPTION_INITIAL, connection_->encryption_level()); |
| 182 | } |
| 183 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 184 | TEST_F(QuicCryptoClientStreamTest, ClockSkew) { |
| 185 | // Test that if the client's clock is skewed with respect to the server, |
| 186 | // the handshake succeeds. In the past, the client would get the server |
| 187 | // config, notice that it had already expired and then close the connection. |
| 188 | |
| 189 | // Advance time 5 years to ensure that we pass the expiry time in the server |
| 190 | // config, but the TTL is used instead. |
| 191 | connection_->AdvanceTime( |
| 192 | QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
| 193 | |
| 194 | // The handshakes completes! |
| 195 | CompleteCryptoHandshake(); |
| 196 | } |
| 197 | |
| 198 | TEST_F(QuicCryptoClientStreamTest, InvalidCachedServerConfig) { |
| 199 | // Seed the config with a cached server config. |
| 200 | CompleteCryptoHandshake(); |
| 201 | |
| 202 | // Recreate connection with the new config. |
| 203 | CreateConnection(); |
| 204 | |
| 205 | QuicCryptoClientConfig::CachedState* state = |
| 206 | crypto_config_.LookupOrCreate(server_id_); |
| 207 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 208 | std::vector<std::string> certs = state->certs(); |
| 209 | std::string cert_sct = state->cert_sct(); |
| 210 | std::string signature = state->signature(); |
| 211 | std::string chlo_hash = state->chlo_hash(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 212 | state->SetProof(certs, cert_sct, chlo_hash, signature + signature); |
| 213 | |
| 214 | EXPECT_CALL(*session_, OnProofVerifyDetailsAvailable(testing::_)) |
| 215 | .Times(testing::AnyNumber()); |
| 216 | stream()->CryptoConnect(); |
| 217 | // Check that a client hello was sent. |
| 218 | ASSERT_EQ(1u, connection_->encrypted_packets_.size()); |
| 219 | } |
| 220 | |
| 221 | TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdate) { |
| 222 | // Test that the crypto client stream can receive server config updates after |
| 223 | // the connection has been established. |
| 224 | CompleteCryptoHandshake(); |
| 225 | |
| 226 | QuicCryptoClientConfig::CachedState* state = |
| 227 | crypto_config_.LookupOrCreate(server_id_); |
| 228 | |
| 229 | // Ensure cached STK is different to what we send in the handshake. |
| 230 | EXPECT_NE("xstk", state->source_address_token()); |
| 231 | |
| 232 | // Initialize using {...} syntax to avoid trailing \0 if converting from |
| 233 | // string. |
| 234 | unsigned char stk[] = {'x', 's', 't', 'k'}; |
| 235 | |
| 236 | // Minimum SCFG that passes config validation checks. |
| 237 | unsigned char scfg[] = {// SCFG |
| 238 | 0x53, 0x43, 0x46, 0x47, |
| 239 | // num entries |
| 240 | 0x01, 0x00, |
| 241 | // padding |
| 242 | 0x00, 0x00, |
| 243 | // EXPY |
| 244 | 0x45, 0x58, 0x50, 0x59, |
| 245 | // EXPY end offset |
| 246 | 0x08, 0x00, 0x00, 0x00, |
| 247 | // Value |
| 248 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 249 | |
| 250 | CryptoHandshakeMessage server_config_update; |
| 251 | server_config_update.set_tag(kSCUP); |
| 252 | server_config_update.SetValue(kSourceAddressTokenTag, stk); |
| 253 | server_config_update.SetValue(kSCFG, scfg); |
| 254 | const uint64_t expiry_seconds = 60 * 60 * 24 * 2; |
| 255 | server_config_update.SetValue(kSTTL, expiry_seconds); |
| 256 | |
| 257 | crypto_test_utils::SendHandshakeMessageToStream( |
| 258 | stream(), server_config_update, Perspective::IS_SERVER); |
| 259 | |
| 260 | // Make sure that the STK and SCFG are cached correctly. |
| 261 | EXPECT_EQ("xstk", state->source_address_token()); |
| 262 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 263 | const std::string& cached_scfg = state->server_config(); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 264 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 265 | "scfg", cached_scfg.data(), cached_scfg.length(), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 266 | reinterpret_cast<char*>(scfg), QUICHE_ARRAYSIZE(scfg)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 267 | |
| 268 | QuicStreamSequencer* sequencer = QuicStreamPeer::sequencer(stream()); |
| 269 | EXPECT_FALSE(QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); |
| 270 | } |
| 271 | |
| 272 | TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateWithCert) { |
| 273 | // Test that the crypto client stream can receive and use server config |
| 274 | // updates with certificates after the connection has been established. |
| 275 | CompleteCryptoHandshake(); |
| 276 | |
| 277 | // Build a server config update message with certificates |
| 278 | QuicCryptoServerConfig crypto_config( |
| 279 | QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(), |
nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 280 | crypto_test_utils::ProofSourceForTesting(), KeyExchangeSource::Default()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 281 | crypto_test_utils::SetupCryptoServerConfigForTest( |
nharper | ba5f32c | 2019-05-13 12:21:31 -0700 | [diff] [blame] | 282 | connection_->clock(), QuicRandom::GetInstance(), &crypto_config); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 283 | SourceAddressTokens tokens; |
| 284 | QuicCompressedCertsCache cache(1); |
| 285 | CachedNetworkParameters network_params; |
| 286 | CryptoHandshakeMessage server_config_update; |
| 287 | |
| 288 | class Callback : public BuildServerConfigUpdateMessageResultCallback { |
| 289 | public: |
| 290 | Callback(bool* ok, CryptoHandshakeMessage* message) |
| 291 | : ok_(ok), message_(message) {} |
| 292 | void Run(bool ok, const CryptoHandshakeMessage& message) override { |
| 293 | *ok_ = ok; |
| 294 | *message_ = message; |
| 295 | } |
| 296 | |
| 297 | private: |
| 298 | bool* ok_; |
| 299 | CryptoHandshakeMessage* message_; |
| 300 | }; |
| 301 | |
| 302 | // Note: relies on the callback being invoked synchronously |
| 303 | bool ok = false; |
| 304 | crypto_config.BuildServerConfigUpdateMessage( |
renjietang | d1d0085 | 2019-09-06 10:43:12 -0700 | [diff] [blame] | 305 | session_->transport_version(), stream()->chlo_hash(), tokens, |
| 306 | QuicSocketAddress(QuicIpAddress::Loopback6(), 1234), |
danzh | d1fc591 | 2020-05-01 15:29:04 -0700 | [diff] [blame] | 307 | QuicSocketAddress(QuicIpAddress::Loopback6(), 4321), connection_->clock(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 308 | QuicRandom::GetInstance(), &cache, stream()->crypto_negotiated_params(), |
| 309 | &network_params, |
| 310 | std::unique_ptr<BuildServerConfigUpdateMessageResultCallback>( |
| 311 | new Callback(&ok, &server_config_update))); |
| 312 | EXPECT_TRUE(ok); |
| 313 | |
| 314 | EXPECT_CALL(*session_, OnProofValid(testing::_)); |
| 315 | crypto_test_utils::SendHandshakeMessageToStream( |
| 316 | stream(), server_config_update, Perspective::IS_SERVER); |
| 317 | |
| 318 | // Recreate connection with the new config and verify a 0-RTT attempt. |
| 319 | CreateConnection(); |
| 320 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 321 | EXPECT_CALL(*session_, OnProofValid(testing::_)); |
| 322 | EXPECT_CALL(*session_, OnProofVerifyDetailsAvailable(testing::_)) |
| 323 | .Times(testing::AnyNumber()); |
| 324 | stream()->CryptoConnect(); |
| 325 | EXPECT_TRUE(session_->IsEncryptionEstablished()); |
| 326 | } |
| 327 | |
| 328 | TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateBeforeHandshake) { |
| 329 | EXPECT_CALL( |
| 330 | *connection_, |
| 331 | CloseConnection(QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE, _, _)); |
| 332 | CryptoHandshakeMessage server_config_update; |
| 333 | server_config_update.set_tag(kSCUP); |
| 334 | crypto_test_utils::SendHandshakeMessageToStream( |
| 335 | stream(), server_config_update, Perspective::IS_SERVER); |
| 336 | } |
| 337 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 338 | TEST_F(QuicCryptoClientStreamTest, PreferredVersion) { |
| 339 | // This mimics the case where client receives version negotiation packet, such |
| 340 | // that, the preferred version is different from the packets' version. |
| 341 | connection_ = new PacketSavingConnection( |
| 342 | &client_helper_, &alarm_factory_, Perspective::IS_CLIENT, |
| 343 | ParsedVersionOfIndex(supported_versions_, 1)); |
| 344 | connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 345 | |
dschinazi | dffd298 | 2020-03-02 10:25:11 -0800 | [diff] [blame] | 346 | CreateSession(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 347 | CompleteCryptoHandshake(); |
| 348 | // 2 CHLOs are sent. |
| 349 | ASSERT_EQ(2u, session_->sent_crypto_handshake_messages().size()); |
| 350 | // Verify preferred version is the highest version that session supports, and |
| 351 | // is different from connection's version. |
| 352 | QuicVersionLabel client_version_label; |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 353 | EXPECT_THAT(session_->sent_crypto_handshake_messages()[0].GetVersionLabel( |
| 354 | kVER, &client_version_label), |
| 355 | IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 356 | EXPECT_EQ(CreateQuicVersionLabel(supported_versions_[0]), |
| 357 | client_version_label); |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 358 | EXPECT_THAT(session_->sent_crypto_handshake_messages()[1].GetVersionLabel( |
| 359 | kVER, &client_version_label), |
| 360 | IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 361 | EXPECT_EQ(CreateQuicVersionLabel(supported_versions_[0]), |
| 362 | client_version_label); |
| 363 | EXPECT_NE(CreateQuicVersionLabel(connection_->version()), |
| 364 | client_version_label); |
| 365 | } |
| 366 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 367 | } // namespace |
| 368 | } // namespace test |
| 369 | } // namespace quic |