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 "net/base/completion_callback.h" | 7 #include "net/base/completion_callback.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
10 #include "net/quic/crypto/crypto_utils.h" | 10 #include "net/quic/crypto/crypto_utils.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 void QuicCryptoClientStream::DoHandshakeLoop( | 146 void QuicCryptoClientStream::DoHandshakeLoop( |
147 const CryptoHandshakeMessage* in) { | 147 const CryptoHandshakeMessage* in) { |
148 CryptoHandshakeMessage out; | 148 CryptoHandshakeMessage out; |
149 QuicErrorCode error; | 149 QuicErrorCode error; |
150 string error_details; | 150 string error_details; |
151 QuicCryptoClientConfig::CachedState* cached = | 151 QuicCryptoClientConfig::CachedState* cached = |
152 crypto_config_->LookupOrCreate(server_hostname_); | 152 crypto_config_->LookupOrCreate(server_hostname_); |
153 | 153 |
154 if (in != NULL) { | 154 if (in != NULL) { |
155 DVLOG(1) << "Client received: " << in->DebugString(); | 155 DVLOG(1) << "Client: Received " << in->DebugString(); |
156 } | 156 } |
157 | 157 |
158 for (;;) { | 158 for (;;) { |
159 const State state = next_state_; | 159 const State state = next_state_; |
160 next_state_ = STATE_IDLE; | 160 next_state_ = STATE_IDLE; |
161 switch (state) { | 161 switch (state) { |
162 case STATE_SEND_CHLO: { | 162 case STATE_SEND_CHLO: { |
163 // Send the client hello in plaintext. | 163 // Send the client hello in plaintext. |
164 session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_NONE); | 164 session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_NONE); |
165 if (num_client_hellos_ > kMaxClientHellos) { | 165 if (num_client_hellos_ > kMaxClientHellos) { |
166 CloseConnection(QUIC_CRYPTO_TOO_MANY_REJECTS); | 166 CloseConnection(QUIC_CRYPTO_TOO_MANY_REJECTS); |
167 return; | 167 return; |
168 } | 168 } |
169 num_client_hellos_++; | 169 num_client_hellos_++; |
170 | 170 |
171 if (!cached->IsComplete(session()->connection()->clock()->WallNow())) { | 171 if (!cached->IsComplete(session()->connection()->clock()->WallNow())) { |
172 crypto_config_->FillInchoateClientHello( | 172 crypto_config_->FillInchoateClientHello( |
173 server_hostname_, cached, &crypto_negotiated_params_, &out); | 173 server_hostname_, cached, &crypto_negotiated_params_, &out); |
174 next_state_ = STATE_RECV_REJ; | 174 next_state_ = STATE_RECV_REJ; |
175 DVLOG(1) << "Client Sending: " << out.DebugString(); | 175 DVLOG(1) << "Client: Sending " << out.DebugString(); |
176 SendHandshakeMessage(out); | 176 SendHandshakeMessage(out); |
177 return; | 177 return; |
178 } | 178 } |
179 session()->config()->ToHandshakeMessage(&out); | 179 session()->config()->ToHandshakeMessage(&out); |
180 error = crypto_config_->FillClientHello( | 180 error = crypto_config_->FillClientHello( |
181 server_hostname_, | 181 server_hostname_, |
182 session()->connection()->guid(), | 182 session()->connection()->guid(), |
183 cached, | 183 cached, |
184 session()->connection()->clock()->WallNow(), | 184 session()->connection()->clock()->WallNow(), |
185 session()->connection()->random_generator(), | 185 session()->connection()->random_generator(), |
186 &crypto_negotiated_params_, | 186 &crypto_negotiated_params_, |
187 &out, | 187 &out, |
188 &error_details); | 188 &error_details); |
189 if (error != QUIC_NO_ERROR) { | 189 if (error != QUIC_NO_ERROR) { |
190 // Flush the cached config so that, if it's bad, the server has a | 190 // Flush the cached config so that, if it's bad, the server has a |
191 // chance to send us another in the future. | 191 // chance to send us another in the future. |
192 cached->InvalidateServerConfig(); | 192 cached->InvalidateServerConfig(); |
193 CloseConnectionWithDetails(error, error_details); | 193 CloseConnectionWithDetails(error, error_details); |
194 return; | 194 return; |
195 } | 195 } |
196 if (cached->proof_verify_details()) { | 196 if (cached->proof_verify_details()) { |
197 CopyCertVerifyResult(cached->proof_verify_details(), | 197 CopyCertVerifyResult(cached->proof_verify_details(), |
198 &cert_verify_result_); | 198 &cert_verify_result_); |
199 } else { | 199 } else { |
200 cert_verify_result_.reset(); | 200 cert_verify_result_.reset(); |
201 } | 201 } |
202 next_state_ = STATE_RECV_SHLO; | 202 next_state_ = STATE_RECV_SHLO; |
203 DVLOG(1) << "Client Sending: " << out.DebugString(); | 203 DVLOG(1) << "Client: Sending " << out.DebugString(); |
204 SendHandshakeMessage(out); | 204 SendHandshakeMessage(out); |
205 // Be prepared to decrypt with the new server write key. | 205 // Be prepared to decrypt with the new server write key. |
206 session()->connection()->SetAlternativeDecrypter( | 206 session()->connection()->SetAlternativeDecrypter( |
207 crypto_negotiated_params_.initial_crypters.decrypter.release(), | 207 crypto_negotiated_params_.initial_crypters.decrypter.release(), |
208 true /* latch once used */); | 208 true /* latch once used */); |
209 // Send subsequent packets under encryption on the assumption that the | 209 // Send subsequent packets under encryption on the assumption that the |
210 // server will accept the handshake. | 210 // server will accept the handshake. |
211 session()->connection()->SetEncrypter( | 211 session()->connection()->SetEncrypter( |
212 ENCRYPTION_INITIAL, | 212 ENCRYPTION_INITIAL, |
213 crypto_negotiated_params_.initial_crypters.encrypter.release()); | 213 crypto_negotiated_params_.initial_crypters.encrypter.release()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 366 } |
367 case STATE_IDLE: | 367 case STATE_IDLE: |
368 // This means that the peer sent us a message that we weren't expecting. | 368 // This means that the peer sent us a message that we weren't expecting. |
369 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); | 369 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); |
370 return; | 370 return; |
371 } | 371 } |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 } // namespace net | 375 } // namespace net |
OLD | NEW |