| 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/quic/crypto/crypto_protocol.h" | 7 #include "net/quic/crypto/crypto_protocol.h" |
| 8 #include "net/quic/crypto/crypto_utils.h" | 8 #include "net/quic/crypto/crypto_utils.h" |
| 9 #include "net/quic/crypto/null_encrypter.h" | 9 #include "net/quic/crypto/null_encrypter.h" |
| 10 #include "net/quic/quic_client_session_base.h" | 10 #include "net/quic/quic_client_session_base.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (channel_id_source_callback_) { | 88 if (channel_id_source_callback_) { |
| 89 channel_id_source_callback_->Cancel(); | 89 channel_id_source_callback_->Cancel(); |
| 90 } | 90 } |
| 91 if (proof_verify_callback_) { | 91 if (proof_verify_callback_) { |
| 92 proof_verify_callback_->Cancel(); | 92 proof_verify_callback_->Cancel(); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 void QuicCryptoClientStream::OnHandshakeMessage( | 96 void QuicCryptoClientStream::OnHandshakeMessage( |
| 97 const CryptoHandshakeMessage& message) { | 97 const CryptoHandshakeMessage& message) { |
| 98 DVLOG(1) << "Client: Received " << message.DebugString(); |
| 99 |
| 98 QuicCryptoStream::OnHandshakeMessage(message); | 100 QuicCryptoStream::OnHandshakeMessage(message); |
| 99 | 101 |
| 102 if (message.tag() == kSCUP) { |
| 103 if (!handshake_confirmed()) { |
| 104 CloseConnection(QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE); |
| 105 return; |
| 106 } |
| 107 |
| 108 // |message| is an update from the server, so we treat it differently from a |
| 109 // handshake message. |
| 110 HandleServerConfigUpdateMessage(&message); |
| 111 return; |
| 112 } |
| 113 |
| 114 // Do not process handshake messages after the handshake is confirmed. |
| 115 if (handshake_confirmed()) { |
| 116 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); |
| 117 return; |
| 118 } |
| 119 |
| 100 DoHandshakeLoop(&message); | 120 DoHandshakeLoop(&message); |
| 101 } | 121 } |
| 102 | 122 |
| 103 bool QuicCryptoClientStream::CryptoConnect() { | 123 bool QuicCryptoClientStream::CryptoConnect() { |
| 104 next_state_ = STATE_INITIALIZE; | 124 next_state_ = STATE_INITIALIZE; |
| 105 DoHandshakeLoop(NULL); | 125 DoHandshakeLoop(NULL); |
| 106 return true; | 126 return true; |
| 107 } | 127 } |
| 108 | 128 |
| 109 int QuicCryptoClientStream::num_sent_client_hellos() const { | 129 int QuicCryptoClientStream::num_sent_client_hellos() const { |
| 110 return num_client_hellos_; | 130 return num_client_hellos_; |
| 111 } | 131 } |
| 112 | 132 |
| 113 bool QuicCryptoClientStream::WasChannelIDSent() const { | 133 bool QuicCryptoClientStream::WasChannelIDSent() const { |
| 114 return channel_id_sent_; | 134 return channel_id_sent_; |
| 115 } | 135 } |
| 116 | 136 |
| 137 void QuicCryptoClientStream::HandleServerConfigUpdateMessage( |
| 138 const CryptoHandshakeMessage* in) { |
| 139 DCHECK(in->tag() == kSCUP); |
| 140 string error_details; |
| 141 QuicCryptoClientConfig::CachedState* cached = |
| 142 crypto_config_->LookupOrCreate(server_id_); |
| 143 QuicErrorCode error = crypto_config_->ProcessServerConfigUpdate( |
| 144 *in, |
| 145 session()->connection()->clock()->WallNow(), |
| 146 cached, |
| 147 &crypto_negotiated_params_, |
| 148 &error_details); |
| 149 |
| 150 if (error != QUIC_NO_ERROR) { |
| 151 CloseConnectionWithDetails( |
| 152 error, "Server config update invalid: " + error_details); |
| 153 return; |
| 154 } |
| 155 } |
| 156 |
| 117 // kMaxClientHellos is the maximum number of times that we'll send a client | 157 // kMaxClientHellos is the maximum number of times that we'll send a client |
| 118 // hello. The value 3 accounts for: | 158 // hello. The value 3 accounts for: |
| 119 // * One failure due to an incorrect or missing source-address token. | 159 // * One failure due to an incorrect or missing source-address token. |
| 120 // * One failure due the server's certificate chain being unavailible and the | 160 // * One failure due the server's certificate chain being unavailible and the |
| 121 // server being unwilling to send it without a valid source-address token. | 161 // server being unwilling to send it without a valid source-address token. |
| 122 static const int kMaxClientHellos = 3; | 162 static const int kMaxClientHellos = 3; |
| 123 | 163 |
| 124 void QuicCryptoClientStream::DoHandshakeLoop( | 164 void QuicCryptoClientStream::DoHandshakeLoop( |
| 125 const CryptoHandshakeMessage* in) { | 165 const CryptoHandshakeMessage* in) { |
| 126 CryptoHandshakeMessage out; | 166 CryptoHandshakeMessage out; |
| 127 QuicErrorCode error; | 167 QuicErrorCode error; |
| 128 string error_details; | 168 string error_details; |
| 129 QuicCryptoClientConfig::CachedState* cached = | 169 QuicCryptoClientConfig::CachedState* cached = |
| 130 crypto_config_->LookupOrCreate(server_id_); | 170 crypto_config_->LookupOrCreate(server_id_); |
| 131 | 171 |
| 132 if (in != NULL) { | |
| 133 DVLOG(1) << "Client: Received " << in->DebugString(); | |
| 134 } | |
| 135 | |
| 136 for (;;) { | 172 for (;;) { |
| 137 const State state = next_state_; | 173 const State state = next_state_; |
| 138 next_state_ = STATE_IDLE; | 174 next_state_ = STATE_IDLE; |
| 139 switch (state) { | 175 switch (state) { |
| 140 case STATE_INITIALIZE: { | 176 case STATE_INITIALIZE: { |
| 141 if (!cached->IsEmpty() && !cached->proof_valid() && | 177 if (!cached->IsEmpty() && !cached->proof_valid() && |
| 142 !cached->signature().empty() && server_id_.is_https()) { | 178 !cached->signature().empty() && server_id_.is_https()) { |
| 143 DCHECK(crypto_config_->proof_verifier()); | 179 DCHECK(crypto_config_->proof_verifier()); |
| 144 // If the cached state needs to be verified, do it now. | 180 // If the cached state needs to be verified, do it now. |
| 145 next_state_ = STATE_VERIFY_PROOF; | 181 next_state_ = STATE_VERIFY_PROOF; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 492 } |
| 457 } | 493 } |
| 458 return false; | 494 return false; |
| 459 } | 495 } |
| 460 | 496 |
| 461 QuicClientSessionBase* QuicCryptoClientStream::client_session() { | 497 QuicClientSessionBase* QuicCryptoClientStream::client_session() { |
| 462 return reinterpret_cast<QuicClientSessionBase*>(session()); | 498 return reinterpret_cast<QuicClientSessionBase*>(session()); |
| 463 } | 499 } |
| 464 | 500 |
| 465 } // namespace net | 501 } // namespace net |
| OLD | NEW |