| 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 #ifndef NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ | 5 #ifndef NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ |
| 6 #define NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ | 6 #define NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
| 11 #include "net/quic/crypto/quic_crypto_server_config.h" | 11 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 12 #include "net/quic/proto/source_address_token.pb.h" | 12 #include "net/quic/proto/source_address_token.pb.h" |
| 13 #include "net/quic/quic_config.h" | 13 #include "net/quic/quic_config.h" |
| 14 #include "net/quic/quic_crypto_stream.h" | 14 #include "net/quic/quic_crypto_stream.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 class CachedNetworkParameters; | 18 class CachedNetworkParameters; |
| 19 class CryptoHandshakeMessage; | 19 class CryptoHandshakeMessage; |
| 20 class QuicCryptoServerConfig; | 20 class QuicCryptoServerConfig; |
| 21 class QuicCryptoServerStream; | 21 class QuicCryptoServerStreamBase; |
| 22 class QuicSession; | 22 class QuicSession; |
| 23 | 23 |
| 24 namespace test { | 24 namespace test { |
| 25 class CryptoTestUtils; | 25 class CryptoTestUtils; |
| 26 class QuicCryptoServerStreamPeer; | 26 class QuicCryptoServerStreamPeer; |
| 27 } // namespace test | 27 } // namespace test |
| 28 | 28 |
| 29 // Receives a notification when the server hello (SHLO) has been ACKed by the | 29 // Receives a notification when the server hello (SHLO) has been ACKed by the |
| 30 // peer. At this point we disable HANDSHAKE_MODE in the sent packet manager. | 30 // peer. At this point we disable HANDSHAKE_MODE in the sent packet manager. |
| 31 class NET_EXPORT_PRIVATE ServerHelloNotifier : public QuicAckListenerInterface { | 31 class NET_EXPORT_PRIVATE ServerHelloNotifier : public QuicAckListenerInterface { |
| 32 public: | 32 public: |
| 33 explicit ServerHelloNotifier(QuicCryptoServerStream* stream) | 33 explicit ServerHelloNotifier(QuicCryptoServerStreamBase* stream) |
| 34 : server_stream_(stream) {} | 34 : server_stream_(stream) {} |
| 35 | 35 |
| 36 void OnPacketAcked(int acked_bytes, | 36 void OnPacketAcked(int acked_bytes, |
| 37 QuicTime::Delta delta_largest_observed) override; | 37 QuicTime::Delta delta_largest_observed) override; |
| 38 | 38 |
| 39 void OnPacketRetransmitted(int retransmitted_bytes) override; | 39 void OnPacketRetransmitted(int retransmitted_bytes) override; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 ~ServerHelloNotifier() override {} | 42 ~ServerHelloNotifier() override {} |
| 43 | 43 |
| 44 QuicCryptoServerStream* server_stream_; | 44 QuicCryptoServerStreamBase* server_stream_; |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(ServerHelloNotifier); | 46 DISALLOW_COPY_AND_ASSIGN(ServerHelloNotifier); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class NET_EXPORT_PRIVATE QuicCryptoServerStream : public QuicCryptoStream { | 49 // TODO(alyssar) see what can be moved out of QuicCryptoServerStream with |
| 50 // various code and test refactoring. |
| 51 class NET_EXPORT_PRIVATE QuicCryptoServerStreamBase : public QuicCryptoStream { |
| 52 public: |
| 53 // |crypto_config| must outlive the stream. |
| 54 explicit QuicCryptoServerStreamBase(QuicSession* session) |
| 55 : QuicCryptoStream(session) {} |
| 56 ~QuicCryptoServerStreamBase() override {} |
| 57 |
| 58 // Cancel any outstanding callbacks, such as asynchronous validation of client |
| 59 // hello. |
| 60 virtual void CancelOutstandingCallbacks() = 0; |
| 61 |
| 62 // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded, |
| 63 // SHA-256 hash of the client's ChannelID key and returns true, if the client |
| 64 // presented a ChannelID. Otherwise it returns false. |
| 65 virtual bool GetBase64SHA256ClientChannelID(std::string* output) const = 0; |
| 66 |
| 67 virtual int NumServerConfigUpdateMessagesSent() const = 0; |
| 68 |
| 69 // Sends the latest server config and source-address token to the client. |
| 70 virtual void SendServerConfigUpdate( |
| 71 const CachedNetworkParameters* cached_network_params) = 0; |
| 72 |
| 73 // Called by the ServerHello AckNotifier once the SHLO has been ACKed by the |
| 74 // client. |
| 75 virtual void OnServerHelloAcked() = 0; |
| 76 |
| 77 // These are all accessors and setters to their respective counters. |
| 78 virtual uint8 NumHandshakeMessages() const = 0; |
| 79 virtual uint8 NumHandshakeMessagesWithServerNonces() const = 0; |
| 80 virtual bool UseStatelessRejectsIfPeerSupported() const = 0; |
| 81 virtual bool PeerSupportsStatelessRejects() const = 0; |
| 82 virtual void SetPeerSupportsStatelessRejects(bool set) = 0; |
| 83 virtual const CachedNetworkParameters* PreviousCachedNetworkParams() |
| 84 const = 0; |
| 85 virtual void SetPreviousCachedNetworkParams( |
| 86 CachedNetworkParameters cached_network_params) = 0; |
| 87 }; |
| 88 |
| 89 class QuicCryptoServerStream : public QuicCryptoServerStreamBase { |
| 50 public: | 90 public: |
| 51 // |crypto_config| must outlive the stream. | 91 // |crypto_config| must outlive the stream. |
| 52 QuicCryptoServerStream(const QuicCryptoServerConfig* crypto_config, | 92 QuicCryptoServerStream(const QuicCryptoServerConfig* crypto_config, |
| 53 QuicSession* session); | 93 QuicSession* session); |
| 54 ~QuicCryptoServerStream() override; | 94 ~QuicCryptoServerStream() override; |
| 55 | 95 |
| 56 // Cancel any outstanding callbacks, such as asynchronous validation of client | 96 // From QuicCryptoServerStreamBase |
| 57 // hello. | 97 void CancelOutstandingCallbacks() override; |
| 58 void CancelOutstandingCallbacks(); | |
| 59 | |
| 60 // CryptoFramerVisitorInterface implementation | |
| 61 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override; | 98 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override; |
| 62 | 99 bool GetBase64SHA256ClientChannelID(std::string* output) const override; |
| 63 // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded, | 100 void SendServerConfigUpdate( |
| 64 // SHA-256 hash of the client's ChannelID key and returns true, if the client | 101 const CachedNetworkParameters* cached_network_params) override; |
| 65 // presented a ChannelID. Otherwise it returns false. | 102 void OnServerHelloAcked() override; |
| 66 bool GetBase64SHA256ClientChannelID(std::string* output) const; | 103 uint8 NumHandshakeMessages() const override; |
| 67 | 104 uint8 NumHandshakeMessagesWithServerNonces() const override; |
| 68 uint8 num_handshake_messages() const { return num_handshake_messages_; } | 105 int NumServerConfigUpdateMessagesSent() const override; |
| 69 | 106 const CachedNetworkParameters* PreviousCachedNetworkParams() const override; |
| 70 uint8 num_handshake_messages_with_server_nonces() const { | 107 bool UseStatelessRejectsIfPeerSupported() const override; |
| 71 return num_handshake_messages_with_server_nonces_; | 108 bool PeerSupportsStatelessRejects() const override; |
| 72 } | 109 void SetPeerSupportsStatelessRejects( |
| 73 | 110 bool peer_supports_stateless_rejects) override; |
| 74 int num_server_config_update_messages_sent() const { | 111 void SetPreviousCachedNetworkParams( |
| 75 return num_server_config_update_messages_sent_; | 112 CachedNetworkParameters cached_network_params) override; |
| 76 } | |
| 77 | |
| 78 // Sends the latest server config and source-address token to the client. | |
| 79 virtual void SendServerConfigUpdate( | |
| 80 const CachedNetworkParameters* cached_network_params); | |
| 81 | |
| 82 // Called by the ServerHello AckNotifier once the SHLO has been ACKed by the | |
| 83 // client. | |
| 84 void OnServerHelloAcked(); | |
| 85 | |
| 86 void set_previous_cached_network_params( | |
| 87 CachedNetworkParameters cached_network_params); | |
| 88 | |
| 89 const CachedNetworkParameters* previous_cached_network_params() const; | |
| 90 | |
| 91 bool use_stateless_rejects_if_peer_supported() const { | |
| 92 return use_stateless_rejects_if_peer_supported_; | |
| 93 } | |
| 94 | |
| 95 bool peer_supports_stateless_rejects() const { | |
| 96 return peer_supports_stateless_rejects_; | |
| 97 } | |
| 98 | |
| 99 void set_peer_supports_stateless_rejects( | |
| 100 bool peer_supports_stateless_rejects) { | |
| 101 peer_supports_stateless_rejects_ = peer_supports_stateless_rejects; | |
| 102 } | |
| 103 | 113 |
| 104 protected: | 114 protected: |
| 105 virtual QuicErrorCode ProcessClientHello( | 115 virtual QuicErrorCode ProcessClientHello( |
| 106 const CryptoHandshakeMessage& message, | 116 const CryptoHandshakeMessage& message, |
| 107 const ValidateClientHelloResultCallback::Result& result, | 117 const ValidateClientHelloResultCallback::Result& result, |
| 108 CryptoHandshakeMessage* reply, | 118 CryptoHandshakeMessage* reply, |
| 109 std::string* error_details); | 119 std::string* error_details); |
| 110 | 120 |
| 111 // Hook that allows the server to set QuicConfig defaults just | 121 // Hook that allows the server to set QuicConfig defaults just |
| 112 // before going through the parameter negotiation step. | 122 // before going through the parameter negotiation step. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // TODO(jokulik): Remove once client stateless reject support | 201 // TODO(jokulik): Remove once client stateless reject support |
| 192 // becomes the default. | 202 // becomes the default. |
| 193 bool peer_supports_stateless_rejects_; | 203 bool peer_supports_stateless_rejects_; |
| 194 | 204 |
| 195 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream); | 205 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream); |
| 196 }; | 206 }; |
| 197 | 207 |
| 198 } // namespace net | 208 } // namespace net |
| 199 | 209 |
| 200 #endif // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ | 210 #endif // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ |
| OLD | NEW |