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/core/quic_crypto_server_stream.h" | 5 #include "net/quic/core/quic_crypto_server_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "crypto/secure_hash.h" | 10 #include "crypto/secure_hash.h" |
11 #include "net/quic/core/crypto/crypto_protocol.h" | 11 #include "net/quic/core/crypto/crypto_protocol.h" |
12 #include "net/quic/core/crypto/crypto_utils.h" | 12 #include "net/quic/core/crypto/crypto_utils.h" |
13 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 13 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
14 #include "net/quic/core/crypto/quic_random.h" | 14 #include "net/quic/core/crypto/quic_random.h" |
15 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 15 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
16 #include "net/quic/core/quic_config.h" | 16 #include "net/quic/core/quic_config.h" |
17 #include "net/quic/core/quic_flags.h" | 17 #include "net/quic/core/quic_flags.h" |
18 #include "net/quic/core/quic_protocol.h" | 18 #include "net/quic/core/quic_protocol.h" |
19 #include "net/quic/core/quic_server_session_base.h" | 19 #include "net/quic/core/quic_server_session_base.h" |
20 | 20 |
21 using base::StringPiece; | 21 using base::StringPiece; |
22 using std::string; | 22 using std::string; |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 QuicCryptoServerStreamBase::QuicCryptoServerStreamBase( | 26 QuicCryptoServerStreamBase::QuicCryptoServerStreamBase(QuicSession* session) |
27 QuicServerSessionBase* session) | |
28 : QuicCryptoStream(session) {} | 27 : QuicCryptoStream(session) {} |
29 | 28 |
30 // TODO(jokulik): Once stateless rejects support is inherent in the version | 29 // TODO(jokulik): Once stateless rejects support is inherent in the version |
31 // number, this function will likely go away entirely. | 30 // number, this function will likely go away entirely. |
32 // static | 31 // static |
33 bool QuicCryptoServerStreamBase::DoesPeerSupportStatelessRejects( | 32 bool QuicCryptoServerStreamBase::DoesPeerSupportStatelessRejects( |
34 const CryptoHandshakeMessage& message) { | 33 const CryptoHandshakeMessage& message) { |
35 const QuicTag* received_tags; | 34 const QuicTag* received_tags; |
36 size_t received_tags_length; | 35 size_t received_tags_length; |
37 QuicErrorCode error = | 36 QuicErrorCode error = |
38 message.GetTaglist(kCOPT, &received_tags, &received_tags_length); | 37 message.GetTaglist(kCOPT, &received_tags, &received_tags_length); |
39 if (error != QUIC_NO_ERROR) { | 38 if (error != QUIC_NO_ERROR) { |
40 return false; | 39 return false; |
41 } | 40 } |
42 for (size_t i = 0; i < received_tags_length; ++i) { | 41 for (size_t i = 0; i < received_tags_length; ++i) { |
43 if (received_tags[i] == kSREJ) { | 42 if (received_tags[i] == kSREJ) { |
44 return true; | 43 return true; |
45 } | 44 } |
46 } | 45 } |
47 return false; | 46 return false; |
48 } | 47 } |
49 | 48 |
50 QuicCryptoServerStream::QuicCryptoServerStream( | 49 QuicCryptoServerStream::QuicCryptoServerStream( |
51 const QuicCryptoServerConfig* crypto_config, | 50 const QuicCryptoServerConfig* crypto_config, |
52 QuicCompressedCertsCache* compressed_certs_cache, | 51 QuicCompressedCertsCache* compressed_certs_cache, |
53 bool use_stateless_rejects_if_peer_supported, | 52 bool use_stateless_rejects_if_peer_supported, |
54 QuicServerSessionBase* session) | 53 QuicSession* session, |
| 54 Helper* helper) |
55 : QuicCryptoServerStreamBase(session), | 55 : QuicCryptoServerStreamBase(session), |
56 crypto_config_(crypto_config), | 56 crypto_config_(crypto_config), |
57 compressed_certs_cache_(compressed_certs_cache), | 57 compressed_certs_cache_(compressed_certs_cache), |
58 validate_client_hello_cb_(nullptr), | 58 validate_client_hello_cb_(nullptr), |
| 59 helper_(helper), |
59 num_handshake_messages_(0), | 60 num_handshake_messages_(0), |
60 num_handshake_messages_with_server_nonces_(0), | 61 num_handshake_messages_with_server_nonces_(0), |
61 send_server_config_update_cb_(nullptr), | 62 send_server_config_update_cb_(nullptr), |
62 num_server_config_update_messages_sent_(0), | 63 num_server_config_update_messages_sent_(0), |
63 use_stateless_rejects_if_peer_supported_( | 64 use_stateless_rejects_if_peer_supported_( |
64 use_stateless_rejects_if_peer_supported), | 65 use_stateless_rejects_if_peer_supported), |
65 peer_supports_stateless_rejects_(false), | 66 peer_supports_stateless_rejects_(false), |
66 chlo_packet_size_(0) { | 67 chlo_packet_size_(0) { |
67 DCHECK_EQ(Perspective::IS_SERVER, session->connection()->perspective()); | 68 DCHECK_EQ(Perspective::IS_SERVER, session->connection()->perspective()); |
68 } | 69 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return true; | 378 return true; |
378 } | 379 } |
379 | 380 |
380 QuicErrorCode QuicCryptoServerStream::ProcessClientHello( | 381 QuicErrorCode QuicCryptoServerStream::ProcessClientHello( |
381 const CryptoHandshakeMessage& message, | 382 const CryptoHandshakeMessage& message, |
382 const ValidateClientHelloResultCallback::Result& result, | 383 const ValidateClientHelloResultCallback::Result& result, |
383 std::unique_ptr<ProofSource::Details> proof_source_details, | 384 std::unique_ptr<ProofSource::Details> proof_source_details, |
384 CryptoHandshakeMessage* reply, | 385 CryptoHandshakeMessage* reply, |
385 DiversificationNonce* out_diversification_nonce, | 386 DiversificationNonce* out_diversification_nonce, |
386 string* error_details) { | 387 string* error_details) { |
387 QuicServerSessionBase* session_base = | 388 if (!helper_->CanAcceptClientHello( |
388 static_cast<QuicServerSessionBase*>(session()); | 389 message, session()->connection()->self_address(), error_details)) { |
389 if (!session_base->CanAcceptClientHello(message, error_details)) { | |
390 return QUIC_HANDSHAKE_FAILED; | 390 return QUIC_HANDSHAKE_FAILED; |
391 } | 391 } |
392 | 392 |
393 if (!result.info.server_nonce.empty()) { | 393 if (!result.info.server_nonce.empty()) { |
394 ++num_handshake_messages_with_server_nonces_; | 394 ++num_handshake_messages_with_server_nonces_; |
395 } | 395 } |
396 // Store the bandwidth estimate from the client. | 396 // Store the bandwidth estimate from the client. |
397 if (result.cached_network_params.bandwidth_estimate_bytes_per_second() > 0) { | 397 if (result.cached_network_params.bandwidth_estimate_bytes_per_second() > 0) { |
398 previous_cached_network_params_.reset( | 398 previous_cached_network_params_.reset( |
399 new CachedNetworkParameters(result.cached_network_params)); | 399 new CachedNetworkParameters(result.cached_network_params)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 parent_->FinishProcessingHandshakeMessage(client_hello, result, | 435 parent_->FinishProcessingHandshakeMessage(client_hello, result, |
436 std::move(details)); | 436 std::move(details)); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( | 440 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( |
441 bool use_stateless_rejects) { | 441 bool use_stateless_rejects) { |
442 if (!use_stateless_rejects) { | 442 if (!use_stateless_rejects) { |
443 return 0; | 443 return 0; |
444 } | 444 } |
445 QuicServerSessionBase* session_base = | 445 return helper_->GenerateConnectionIdForReject( |
446 static_cast<QuicServerSessionBase*>(session()); | |
447 return session_base->GenerateConnectionIdForReject( | |
448 session()->connection()->connection_id()); | 446 session()->connection()->connection_id()); |
449 } | 447 } |
450 | 448 |
451 } // namespace net | 449 } // namespace net |
OLD | NEW |