OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_config.h" | 5 #include "net/quic/quic_config.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/quic/crypto/crypto_handshake_message.h" | 10 #include "net/quic/crypto/crypto_handshake_message.h" |
11 #include "net/quic/crypto/crypto_protocol.h" | 11 #include "net/quic/crypto/crypto_protocol.h" |
12 #include "net/quic/quic_flags.h" | 12 #include "net/quic/quic_flags.h" |
13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
14 | 14 |
15 using std::min; | 15 using std::min; |
16 using std::string; | 16 using std::string; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 // Reads the value corresponding to |name_| from |msg| into |out|. If the | 20 // Reads the value corresponding to |name_| from |msg| into |out|. If the |
21 // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set | 21 // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set |
22 // to |default_value|. | 22 // to |default_value|. |
23 QuicErrorCode ReadUint32(const CryptoHandshakeMessage& msg, | 23 QuicErrorCode ReadUint32(const CryptoHandshakeMessage& msg, |
24 QuicTag tag, | 24 QuicTag tag, |
25 QuicConfigPresence presence, | 25 QuicConfigPresence presence, |
26 uint32 default_value, | 26 uint32 default_value, |
27 uint32* out, | 27 uint32* out, |
28 string* error_details) { | 28 string* error_details) { |
29 DCHECK(error_details != NULL); | 29 DCHECK(error_details != nullptr); |
30 QuicErrorCode error = msg.GetUint32(tag, out); | 30 QuicErrorCode error = msg.GetUint32(tag, out); |
31 switch (error) { | 31 switch (error) { |
32 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 32 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
33 if (presence == PRESENCE_REQUIRED) { | 33 if (presence == PRESENCE_REQUIRED) { |
34 *error_details = "Missing " + QuicUtils::TagToString(tag); | 34 *error_details = "Missing " + QuicUtils::TagToString(tag); |
35 break; | 35 break; |
36 } | 36 } |
37 error = QUIC_NO_ERROR; | 37 error = QUIC_NO_ERROR; |
38 *out = default_value; | 38 *out = default_value; |
39 break; | 39 break; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } else { | 89 } else { |
90 out->SetValue(tag_, max_value_); | 90 out->SetValue(tag_, max_value_); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 QuicErrorCode QuicNegotiableUint32::ProcessPeerHello( | 94 QuicErrorCode QuicNegotiableUint32::ProcessPeerHello( |
95 const CryptoHandshakeMessage& peer_hello, | 95 const CryptoHandshakeMessage& peer_hello, |
96 HelloType hello_type, | 96 HelloType hello_type, |
97 string* error_details) { | 97 string* error_details) { |
98 DCHECK(!negotiated_); | 98 DCHECK(!negotiated_); |
99 DCHECK(error_details != NULL); | 99 DCHECK(error_details != nullptr); |
100 uint32 value; | 100 uint32 value; |
101 QuicErrorCode error = ReadUint32(peer_hello, | 101 QuicErrorCode error = ReadUint32(peer_hello, |
102 tag_, | 102 tag_, |
103 presence_, | 103 presence_, |
104 default_value_, | 104 default_value_, |
105 &value, | 105 &value, |
106 error_details); | 106 error_details); |
107 if (error != QUIC_NO_ERROR) { | 107 if (error != QUIC_NO_ERROR) { |
108 return error; | 108 return error; |
109 } | 109 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } else { | 148 } else { |
149 out->SetVector(tag_, possible_values_); | 149 out->SetVector(tag_, possible_values_); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 QuicErrorCode QuicNegotiableTag::ReadVector( | 153 QuicErrorCode QuicNegotiableTag::ReadVector( |
154 const CryptoHandshakeMessage& msg, | 154 const CryptoHandshakeMessage& msg, |
155 const QuicTag** out, | 155 const QuicTag** out, |
156 size_t* out_length, | 156 size_t* out_length, |
157 string* error_details) const { | 157 string* error_details) const { |
158 DCHECK(error_details != NULL); | 158 DCHECK(error_details != nullptr); |
159 QuicErrorCode error = msg.GetTaglist(tag_, out, out_length); | 159 QuicErrorCode error = msg.GetTaglist(tag_, out, out_length); |
160 switch (error) { | 160 switch (error) { |
161 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 161 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
162 if (presence_ == PRESENCE_REQUIRED) { | 162 if (presence_ == PRESENCE_REQUIRED) { |
163 *error_details = "Missing " + QuicUtils::TagToString(tag_); | 163 *error_details = "Missing " + QuicUtils::TagToString(tag_); |
164 break; | 164 break; |
165 } | 165 } |
166 error = QUIC_NO_ERROR; | 166 error = QUIC_NO_ERROR; |
167 *out_length = 1; | 167 *out_length = 1; |
168 *out = &default_value_; | 168 *out = &default_value_; |
169 | 169 |
170 case QUIC_NO_ERROR: | 170 case QUIC_NO_ERROR: |
171 break; | 171 break; |
172 default: | 172 default: |
173 *error_details = "Bad " + QuicUtils::TagToString(tag_); | 173 *error_details = "Bad " + QuicUtils::TagToString(tag_); |
174 break; | 174 break; |
175 } | 175 } |
176 return error; | 176 return error; |
177 } | 177 } |
178 | 178 |
179 QuicErrorCode QuicNegotiableTag::ProcessPeerHello( | 179 QuicErrorCode QuicNegotiableTag::ProcessPeerHello( |
180 const CryptoHandshakeMessage& peer_hello, | 180 const CryptoHandshakeMessage& peer_hello, |
181 HelloType hello_type, | 181 HelloType hello_type, |
182 string* error_details) { | 182 string* error_details) { |
183 DCHECK(!negotiated_); | 183 DCHECK(!negotiated_); |
184 DCHECK(error_details != NULL); | 184 DCHECK(error_details != nullptr); |
185 const QuicTag* received_tags; | 185 const QuicTag* received_tags; |
186 size_t received_tags_length; | 186 size_t received_tags_length; |
187 QuicErrorCode error = ReadVector(peer_hello, &received_tags, | 187 QuicErrorCode error = ReadVector(peer_hello, &received_tags, |
188 &received_tags_length, error_details); | 188 &received_tags_length, error_details); |
189 if (error != QUIC_NO_ERROR) { | 189 if (error != QUIC_NO_ERROR) { |
190 return error; | 190 return error; |
191 } | 191 } |
192 | 192 |
193 if (hello_type == SERVER) { | 193 if (hello_type == SERVER) { |
194 if (received_tags_length != 1 || | 194 if (received_tags_length != 1 || |
195 !ContainsQuicTag(possible_values_, *received_tags)) { | 195 !ContainsQuicTag(possible_values_, *received_tags)) { |
196 *error_details = "Invalid " + QuicUtils::TagToString(tag_); | 196 *error_details = "Invalid " + QuicUtils::TagToString(tag_); |
197 return QUIC_INVALID_NEGOTIATED_VALUE; | 197 return QUIC_INVALID_NEGOTIATED_VALUE; |
198 } | 198 } |
199 negotiated_tag_ = *received_tags; | 199 negotiated_tag_ = *received_tags; |
200 } else { | 200 } else { |
201 QuicTag negotiated_tag; | 201 QuicTag negotiated_tag; |
202 if (!QuicUtils::FindMutualTag(possible_values_, | 202 if (!QuicUtils::FindMutualTag(possible_values_, |
203 received_tags, | 203 received_tags, |
204 received_tags_length, | 204 received_tags_length, |
205 QuicUtils::LOCAL_PRIORITY, | 205 QuicUtils::LOCAL_PRIORITY, |
206 &negotiated_tag, | 206 &negotiated_tag, |
207 NULL)) { | 207 nullptr)) { |
208 *error_details = "Unsupported " + QuicUtils::TagToString(tag_); | 208 *error_details = "Unsupported " + QuicUtils::TagToString(tag_); |
209 return QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP; | 209 return QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP; |
210 } | 210 } |
211 negotiated_tag_ = negotiated_tag; | 211 negotiated_tag_ = negotiated_tag; |
212 } | 212 } |
213 | 213 |
214 negotiated_ = true; | 214 negotiated_ = true; |
215 return QUIC_NO_ERROR; | 215 return QUIC_NO_ERROR; |
216 } | 216 } |
217 | 217 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | 255 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
256 if (has_send_value_) { | 256 if (has_send_value_) { |
257 out->SetValue(tag_, send_value_); | 257 out->SetValue(tag_, send_value_); |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 QuicErrorCode QuicFixedUint32::ProcessPeerHello( | 261 QuicErrorCode QuicFixedUint32::ProcessPeerHello( |
262 const CryptoHandshakeMessage& peer_hello, | 262 const CryptoHandshakeMessage& peer_hello, |
263 HelloType hello_type, | 263 HelloType hello_type, |
264 string* error_details) { | 264 string* error_details) { |
265 DCHECK(error_details != NULL); | 265 DCHECK(error_details != nullptr); |
266 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); | 266 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); |
267 switch (error) { | 267 switch (error) { |
268 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 268 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
269 if (presence_ == PRESENCE_OPTIONAL) { | 269 if (presence_ == PRESENCE_OPTIONAL) { |
270 return QUIC_NO_ERROR; | 270 return QUIC_NO_ERROR; |
271 } | 271 } |
272 *error_details = "Missing " + QuicUtils::TagToString(tag_); | 272 *error_details = "Missing " + QuicUtils::TagToString(tag_); |
273 break; | 273 break; |
274 case QUIC_NO_ERROR: | 274 case QUIC_NO_ERROR: |
275 has_receive_value_ = true; | 275 has_receive_value_ = true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 void QuicFixedTag::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | 323 void QuicFixedTag::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
324 if (has_send_value_) { | 324 if (has_send_value_) { |
325 out->SetValue(tag_, send_value_); | 325 out->SetValue(tag_, send_value_); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 QuicErrorCode QuicFixedTag::ProcessPeerHello( | 329 QuicErrorCode QuicFixedTag::ProcessPeerHello( |
330 const CryptoHandshakeMessage& peer_hello, | 330 const CryptoHandshakeMessage& peer_hello, |
331 HelloType hello_type, | 331 HelloType hello_type, |
332 string* error_details) { | 332 string* error_details) { |
333 DCHECK(error_details != NULL); | 333 DCHECK(error_details != nullptr); |
334 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); | 334 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); |
335 switch (error) { | 335 switch (error) { |
336 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 336 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
337 if (presence_ == PRESENCE_OPTIONAL) { | 337 if (presence_ == PRESENCE_OPTIONAL) { |
338 return QUIC_NO_ERROR; | 338 return QUIC_NO_ERROR; |
339 } | 339 } |
340 *error_details = "Missing " + QuicUtils::TagToString(tag_); | 340 *error_details = "Missing " + QuicUtils::TagToString(tag_); |
341 break; | 341 break; |
342 case QUIC_NO_ERROR: | 342 case QUIC_NO_ERROR: |
343 has_receive_value_ = true; | 343 has_receive_value_ = true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | 391 void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
392 if (has_send_values_) { | 392 if (has_send_values_) { |
393 out->SetVector(tag_, send_values_); | 393 out->SetVector(tag_, send_values_); |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 QuicErrorCode QuicFixedTagVector::ProcessPeerHello( | 397 QuicErrorCode QuicFixedTagVector::ProcessPeerHello( |
398 const CryptoHandshakeMessage& peer_hello, | 398 const CryptoHandshakeMessage& peer_hello, |
399 HelloType hello_type, | 399 HelloType hello_type, |
400 string* error_details) { | 400 string* error_details) { |
401 DCHECK(error_details != NULL); | 401 DCHECK(error_details != nullptr); |
402 const QuicTag* received_tags; | 402 const QuicTag* received_tags; |
403 size_t received_tags_length; | 403 size_t received_tags_length; |
404 QuicErrorCode error = | 404 QuicErrorCode error = |
405 peer_hello.GetTaglist(tag_, &received_tags, &received_tags_length); | 405 peer_hello.GetTaglist(tag_, &received_tags, &received_tags_length); |
406 switch (error) { | 406 switch (error) { |
407 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 407 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
408 if (presence_ == PRESENCE_OPTIONAL) { | 408 if (presence_ == PRESENCE_OPTIONAL) { |
409 return QUIC_NO_ERROR; | 409 return QUIC_NO_ERROR; |
410 } | 410 } |
411 *error_details = "Missing " + QuicUtils::TagToString(tag_); | 411 *error_details = "Missing " + QuicUtils::TagToString(tag_); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out); | 660 initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out); |
661 initial_session_flow_control_window_bytes_.ToHandshakeMessage(out); | 661 initial_session_flow_control_window_bytes_.ToHandshakeMessage(out); |
662 socket_receive_buffer_.ToHandshakeMessage(out); | 662 socket_receive_buffer_.ToHandshakeMessage(out); |
663 connection_options_.ToHandshakeMessage(out); | 663 connection_options_.ToHandshakeMessage(out); |
664 } | 664 } |
665 | 665 |
666 QuicErrorCode QuicConfig::ProcessPeerHello( | 666 QuicErrorCode QuicConfig::ProcessPeerHello( |
667 const CryptoHandshakeMessage& peer_hello, | 667 const CryptoHandshakeMessage& peer_hello, |
668 HelloType hello_type, | 668 HelloType hello_type, |
669 string* error_details) { | 669 string* error_details) { |
670 DCHECK(error_details != NULL); | 670 DCHECK(error_details != nullptr); |
671 | 671 |
672 QuicErrorCode error = QUIC_NO_ERROR; | 672 QuicErrorCode error = QUIC_NO_ERROR; |
673 if (error == QUIC_NO_ERROR) { | 673 if (error == QUIC_NO_ERROR) { |
674 error = congestion_feedback_.ProcessPeerHello( | 674 error = congestion_feedback_.ProcessPeerHello( |
675 peer_hello, hello_type, error_details); | 675 peer_hello, hello_type, error_details); |
676 } | 676 } |
677 if (error == QUIC_NO_ERROR) { | 677 if (error == QUIC_NO_ERROR) { |
678 error = idle_connection_state_lifetime_seconds_.ProcessPeerHello( | 678 error = idle_connection_state_lifetime_seconds_.ProcessPeerHello( |
679 peer_hello, hello_type, error_details); | 679 peer_hello, hello_type, error_details); |
680 } | 680 } |
(...skipping 30 matching lines...) Expand all Loading... |
711 peer_hello, hello_type, error_details); | 711 peer_hello, hello_type, error_details); |
712 } | 712 } |
713 if (error == QUIC_NO_ERROR) { | 713 if (error == QUIC_NO_ERROR) { |
714 error = connection_options_.ProcessPeerHello( | 714 error = connection_options_.ProcessPeerHello( |
715 peer_hello, hello_type, error_details); | 715 peer_hello, hello_type, error_details); |
716 } | 716 } |
717 return error; | 717 return error; |
718 } | 718 } |
719 | 719 |
720 } // namespace net | 720 } // namespace net |
OLD | NEW |