Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: net/quic/quic_crypto_client_stream.cc

Issue 14083012: QUIC: retransmit packets with the correct encryption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved HandshakeMode enum to MockCryptoClientStream Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/proof_verifier.h" 10 #include "net/quic/crypto/proof_verifier.h"
10 #include "net/quic/quic_protocol.h" 11 #include "net/quic/quic_protocol.h"
11 #include "net/quic/quic_session.h" 12 #include "net/quic/quic_session.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 QuicCryptoClientStream::QuicCryptoClientStream( 16 QuicCryptoClientStream::QuicCryptoClientStream(
16 const string& server_hostname, 17 const string& server_hostname,
17 const QuicConfig& config, 18 const QuicConfig& config,
18 QuicSession* session, 19 QuicSession* session,
19 QuicCryptoClientConfig* crypto_config) 20 QuicCryptoClientConfig* crypto_config)
20 : QuicCryptoStream(session), 21 : QuicCryptoStream(session),
21 next_state_(STATE_IDLE), 22 next_state_(STATE_IDLE),
22 num_client_hellos_(0), 23 num_client_hellos_(0),
23 config_(config), 24 config_(config),
24 crypto_config_(crypto_config), 25 crypto_config_(crypto_config),
25 decrypter_pushed_(false),
26 server_hostname_(server_hostname) { 26 server_hostname_(server_hostname) {
27 } 27 }
28 28
29 QuicCryptoClientStream::~QuicCryptoClientStream() { 29 QuicCryptoClientStream::~QuicCryptoClientStream() {
30 } 30 }
31 31
32 void QuicCryptoClientStream::OnHandshakeMessage( 32 void QuicCryptoClientStream::OnHandshakeMessage(
33 const CryptoHandshakeMessage& message) { 33 const CryptoHandshakeMessage& message) {
34 DoHandshakeLoop(&message); 34 DoHandshakeLoop(&message);
35 } 35 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 *scfg, CryptoUtils::PEER_PRIORITY, &negotiated_params_, 111 *scfg, CryptoUtils::PEER_PRIORITY, &negotiated_params_,
112 &error_details); 112 &error_details);
113 if (error != QUIC_NO_ERROR) { 113 if (error != QUIC_NO_ERROR) {
114 CloseConnectionWithDetails(error, error_details); 114 CloseConnectionWithDetails(error, error_details);
115 return; 115 return;
116 } 116 }
117 next_state_ = STATE_RECV_SHLO; 117 next_state_ = STATE_RECV_SHLO;
118 DLOG(INFO) << "Client Sending: " << out.DebugString(); 118 DLOG(INFO) << "Client Sending: " << out.DebugString();
119 SendHandshakeMessage(out); 119 SendHandshakeMessage(out);
120 // Be prepared to decrypt with the new server write key. 120 // Be prepared to decrypt with the new server write key.
121 session()->connection()->PushDecrypter( 121 session()->connection()->SetAlternativeDecrypter(
122 crypto_negotiated_params_.decrypter.release()); 122 crypto_negotiated_params_.decrypter.release(),
123 decrypter_pushed_ = true; 123 true /* latch once used */);
124 // Send subsequent packets under encryption on the assumption that the
125 // server will accept the handshake.
126 session()->connection()->SetEncrypter(
127 ENCRYPTION_INITIAL,
128 crypto_negotiated_params_.encrypter.release());
129 session()->connection()->SetDefaultEncryptionLevel(
130 ENCRYPTION_INITIAL);
131 if (!encryption_established_) {
132 session()->OnCryptoHandshakeEvent(
133 QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
134 encryption_established_ = true;
135 } else {
136 session()->OnCryptoHandshakeEvent(
137 QuicSession::ENCRYPTION_REESTABLISHED);
138 }
124 return; 139 return;
125 } 140 }
126 case STATE_RECV_REJ: 141 case STATE_RECV_REJ:
127 // We sent a dummy CHLO because we didn't have enough information to 142 // We sent a dummy CHLO because we didn't have enough information to
128 // perform a handshake, or we sent a full hello that the server 143 // perform a handshake, or we sent a full hello that the server
129 // rejected. Here we hope to have a REJ that contains the information 144 // rejected. Here we hope to have a REJ that contains the information
130 // that we need. 145 // that we need.
131 if (in->tag() != kREJ) { 146 if (in->tag() != kREJ) {
132 CloseConnectionWithDetails(QUIC_INVALID_CRYPTO_MESSAGE_TYPE, 147 CloseConnectionWithDetails(QUIC_INVALID_CRYPTO_MESSAGE_TYPE,
133 "Expected REJ"); 148 "Expected REJ");
(...skipping 19 matching lines...) Expand all
153 cached->certs(), 168 cached->certs(),
154 cached->signature(), 169 cached->signature(),
155 &error_details)) { 170 &error_details)) {
156 CloseConnectionWithDetails(QUIC_PROOF_INVALID, 171 CloseConnectionWithDetails(QUIC_PROOF_INVALID,
157 "Proof invalid: " + error_details); 172 "Proof invalid: " + error_details);
158 return; 173 return;
159 } 174 }
160 cached->SetProofValid(); 175 cached->SetProofValid();
161 } 176 }
162 } 177 }
163 // Clear any new server write key that we may have set before. 178 // Send the subsequent client hello in plaintext.
164 if (decrypter_pushed_) { 179 session()->connection()->SetDefaultEncryptionLevel(
165 session()->connection()->PopDecrypter(); 180 ENCRYPTION_NONE);
166 decrypter_pushed_ = false;
167 }
168 next_state_ = STATE_SEND_CHLO; 181 next_state_ = STATE_SEND_CHLO;
169 break; 182 break;
170 case STATE_RECV_SHLO: 183 case STATE_RECV_SHLO:
171 // We sent a CHLO that we expected to be accepted and now we're hoping 184 // We sent a CHLO that we expected to be accepted and now we're hoping
172 // for a SHLO from the server to confirm that. 185 // for a SHLO from the server to confirm that.
173 if (in->tag() == kREJ) { 186 if (in->tag() == kREJ) {
174 next_state_ = STATE_RECV_REJ; 187 next_state_ = STATE_RECV_REJ;
175 break; 188 break;
176 } 189 }
177 if (in->tag() != kSHLO) { 190 if (in->tag() != kSHLO) {
178 CloseConnectionWithDetails(QUIC_INVALID_CRYPTO_MESSAGE_TYPE, 191 CloseConnectionWithDetails(QUIC_INVALID_CRYPTO_MESSAGE_TYPE,
179 "Expected SHLO or REJ"); 192 "Expected SHLO or REJ");
180 return; 193 return;
181 } 194 }
182 // Receiving SHLO implies the server must have processed our full 195 // TODO(agl): enable this once the tests are corrected to permit it.
183 // CHLO and is ready to decrypt with the new client write key. We 196 // DCHECK(session()->connection()->alternative_decrypter() == NULL);
184 // can start to encrypt with the new client write key. 197 handshake_confirmed_ = true;
185 // TODO(wtc): when we support 0-RTT, we will need to change the 198 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
186 // encrypter when we send a full CHLO because we will be sending
187 // application data immediately after.
188 session()->connection()->ChangeEncrypter(
189 crypto_negotiated_params_.encrypter.release());
190 SetHandshakeComplete(QUIC_NO_ERROR);
191 return; 199 return;
192 case STATE_IDLE: 200 case STATE_IDLE:
193 // This means that the peer sent us a message that we weren't expecting. 201 // This means that the peer sent us a message that we weren't expecting.
194 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); 202 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE);
195 return; 203 return;
196 } 204 }
197 } 205 }
198 } 206 }
199 207
200 } // namespace net 208 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698