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/quic_crypto_client_stream.h" | 5 #include "net/quic/quic_crypto_client_stream.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
9 #include "net/quic/crypto/quic_decrypter.h" | 9 #include "net/quic/crypto/quic_decrypter.h" |
10 #include "net/quic/crypto/quic_encrypter.h" | 10 #include "net/quic/crypto/quic_encrypter.h" |
11 #include "net/quic/quic_flags.h" | 11 #include "net/quic/quic_flags.h" |
12 #include "net/quic/quic_protocol.h" | 12 #include "net/quic/quic_protocol.h" |
13 #include "net/quic/quic_server_id.h" | 13 #include "net/quic/quic_server_id.h" |
| 14 #include "net/quic/quic_utils.h" |
14 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
15 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
16 #include "net/quic/test_tools/simple_quic_framer.h" | 17 #include "net/quic/test_tools/simple_quic_framer.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 namespace test { | 22 namespace test { |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // server config. | 134 // server config. |
134 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) | 135 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) |
135 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 136 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
136 | 137 |
137 // Check that a client hello was sent and that CryptoConnect doesn't fail | 138 // Check that a client hello was sent and that CryptoConnect doesn't fail |
138 // with an error. | 139 // with an error. |
139 EXPECT_TRUE(stream_->CryptoConnect()); | 140 EXPECT_TRUE(stream_->CryptoConnect()); |
140 ASSERT_EQ(1u, connection_->packets_.size()); | 141 ASSERT_EQ(1u, connection_->packets_.size()); |
141 } | 142 } |
142 | 143 |
| 144 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdate) { |
| 145 // Test that the crypto client stream can receive server config updates after |
| 146 // the connection has been established. |
| 147 CompleteCryptoHandshake(); |
| 148 |
| 149 QuicCryptoClientConfig::CachedState* state = |
| 150 crypto_config_.LookupOrCreate(server_id_); |
| 151 |
| 152 // Ensure cached STK is different to what we send in the handshake. |
| 153 EXPECT_NE("xstk", state->source_address_token()); |
| 154 |
| 155 // Initialize using {...} syntax to avoid trailing \0 if converting from |
| 156 // string. |
| 157 unsigned char stk[] = { 'x', 's', 't', 'k' }; |
| 158 |
| 159 // Minimum SCFG that passes config validation checks. |
| 160 unsigned char scfg[] = { |
| 161 // SCFG |
| 162 0x53, 0x43, 0x46, 0x47, |
| 163 // num entries |
| 164 0x01, 0x00, |
| 165 // padding |
| 166 0x00, 0x00, |
| 167 // EXPY |
| 168 0x45, 0x58, 0x50, 0x59, |
| 169 // EXPY end offset |
| 170 0x08, 0x00, 0x00, 0x00, |
| 171 // Value |
| 172 '1', '2', '3', '4', |
| 173 '5', '6', '7', '8' |
| 174 }; |
| 175 |
| 176 CryptoHandshakeMessage server_config_update; |
| 177 server_config_update.set_tag(kSCUP); |
| 178 server_config_update.SetValue(kSourceAddressTokenTag, stk); |
| 179 server_config_update.SetValue(kSCFG, scfg); |
| 180 |
| 181 scoped_ptr<QuicData> data( |
| 182 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
| 183 stream_->ProcessRawData(data->data(), data->length()); |
| 184 |
| 185 // Make sure that the STK and SCFG are cached correctly. |
| 186 EXPECT_EQ("xstk", state->source_address_token()); |
| 187 |
| 188 string cached_scfg = state->server_config(); |
| 189 test::CompareCharArraysWithHexError( |
| 190 "scfg", cached_scfg.data(), cached_scfg.length(), |
| 191 QuicUtils::AsChars(scfg), arraysize(scfg)); |
| 192 } |
| 193 |
| 194 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateBeforeHandshake) { |
| 195 EXPECT_CALL(*connection_, SendConnectionClose( |
| 196 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE)); |
| 197 CryptoHandshakeMessage server_config_update; |
| 198 server_config_update.set_tag(kSCUP); |
| 199 scoped_ptr<QuicData> data( |
| 200 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
| 201 stream_->ProcessRawData(data->data(), data->length()); |
| 202 } |
| 203 |
143 } // namespace | 204 } // namespace |
144 } // namespace test | 205 } // namespace test |
145 } // namespace net | 206 } // namespace net |
OLD | NEW |