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