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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 session_(new TestClientSession(connection_, DefaultQuicConfig())), | 34 session_(new TestClientSession(connection_, DefaultQuicConfig())), |
35 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), | 35 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), |
36 stream_(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, | 36 stream_(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, |
37 &crypto_config_)) { | 37 &crypto_config_)) { |
38 session_->SetCryptoStream(stream_.get()); | 38 session_->SetCryptoStream(stream_.get()); |
39 // Advance the time, because timers do not like uninitialized times. | 39 // Advance the time, because timers do not like uninitialized times. |
40 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 40 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
41 } | 41 } |
42 | 42 |
43 void CompleteCryptoHandshake() { | 43 void CompleteCryptoHandshake() { |
44 EXPECT_TRUE(stream_->CryptoConnect()); | 44 stream_->CryptoConnect(); |
45 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); | 45 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); |
46 } | 46 } |
47 | 47 |
48 void ConstructHandshakeMessage() { | 48 void ConstructHandshakeMessage() { |
49 CryptoFramer framer; | 49 CryptoFramer framer; |
50 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | 50 message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
51 } | 51 } |
52 | 52 |
53 PacketSavingConnection* connection_; | 53 PacketSavingConnection* connection_; |
54 scoped_ptr<TestClientSession> session_; | 54 scoped_ptr<TestClientSession> session_; |
(...skipping 19 matching lines...) Expand all Loading... |
74 CompleteCryptoHandshake(); | 74 CompleteCryptoHandshake(); |
75 | 75 |
76 EXPECT_CALL(*connection_, SendConnectionClose( | 76 EXPECT_CALL(*connection_, SendConnectionClose( |
77 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE)); | 77 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE)); |
78 message_.set_tag(kCHLO); | 78 message_.set_tag(kCHLO); |
79 ConstructHandshakeMessage(); | 79 ConstructHandshakeMessage(); |
80 stream_->ProcessRawData(message_data_->data(), message_data_->length()); | 80 stream_->ProcessRawData(message_data_->data(), message_data_->length()); |
81 } | 81 } |
82 | 82 |
83 TEST_F(QuicCryptoClientStreamTest, BadMessageType) { | 83 TEST_F(QuicCryptoClientStreamTest, BadMessageType) { |
84 EXPECT_TRUE(stream_->CryptoConnect()); | 84 stream_->CryptoConnect(); |
85 | 85 |
86 message_.set_tag(kCHLO); | 86 message_.set_tag(kCHLO); |
87 ConstructHandshakeMessage(); | 87 ConstructHandshakeMessage(); |
88 | 88 |
89 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( | 89 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
90 QUIC_INVALID_CRYPTO_MESSAGE_TYPE, "Expected REJ")); | 90 QUIC_INVALID_CRYPTO_MESSAGE_TYPE, "Expected REJ")); |
91 stream_->ProcessRawData(message_data_->data(), message_data_->length()); | 91 stream_->ProcessRawData(message_data_->data(), message_data_->length()); |
92 } | 92 } |
93 | 93 |
94 TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { | 94 TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, | 127 stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, |
128 &crypto_config_)); | 128 &crypto_config_)); |
129 | 129 |
130 session_->SetCryptoStream(stream_.get()); | 130 session_->SetCryptoStream(stream_.get()); |
131 | 131 |
132 // Advance time 5 years to ensure that we pass the expiry time of the cached | 132 // Advance time 5 years to ensure that we pass the expiry time of the cached |
133 // server config. | 133 // server config. |
134 connection_->AdvanceTime( | 134 connection_->AdvanceTime( |
135 QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 135 QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
136 | 136 |
137 // Check that a client hello was sent and that CryptoConnect doesn't fail | 137 stream_->CryptoConnect(); |
138 // with an error. | 138 // Check that a client hello was sent. |
139 EXPECT_TRUE(stream_->CryptoConnect()); | |
140 ASSERT_EQ(1u, connection_->packets_.size()); | 139 ASSERT_EQ(1u, connection_->packets_.size()); |
141 } | 140 } |
142 | 141 |
143 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdate) { | 142 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdate) { |
144 // Test that the crypto client stream can receive server config updates after | 143 // Test that the crypto client stream can receive server config updates after |
145 // the connection has been established. | 144 // the connection has been established. |
146 CompleteCryptoHandshake(); | 145 CompleteCryptoHandshake(); |
147 | 146 |
148 QuicCryptoClientConfig::CachedState* state = | 147 QuicCryptoClientConfig::CachedState* state = |
149 crypto_config_.LookupOrCreate(server_id_); | 148 crypto_config_.LookupOrCreate(server_id_); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 CryptoHandshakeMessage server_config_update; | 195 CryptoHandshakeMessage server_config_update; |
197 server_config_update.set_tag(kSCUP); | 196 server_config_update.set_tag(kSCUP); |
198 scoped_ptr<QuicData> data( | 197 scoped_ptr<QuicData> data( |
199 CryptoFramer::ConstructHandshakeMessage(server_config_update)); | 198 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
200 stream_->ProcessRawData(data->data(), data->length()); | 199 stream_->ProcessRawData(data->data(), data->length()); |
201 } | 200 } |
202 | 201 |
203 } // namespace | 202 } // namespace |
204 } // namespace test | 203 } // namespace test |
205 } // namespace net | 204 } // namespace net |
OLD | NEW |