| 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 NET_EXPORT_PRIVATE QuicCryptoServerStream | 
 |   90     : public QuicCryptoServerStreamBase { | 
|   50  public: |   91  public: | 
|   51   // |crypto_config| must outlive the stream. |   92   // |crypto_config| must outlive the stream. | 
|   52   QuicCryptoServerStream(const QuicCryptoServerConfig* crypto_config, |   93   QuicCryptoServerStream(const QuicCryptoServerConfig* crypto_config, | 
|   53                          QuicSession* session); |   94                          QuicSession* session); | 
|   54   ~QuicCryptoServerStream() override; |   95   ~QuicCryptoServerStream() override; | 
|   55  |   96  | 
|   56   // Cancel any outstanding callbacks, such as asynchronous validation of client |   97   // From QuicCryptoServerStreamBase | 
|   57   // hello. |   98   void CancelOutstandingCallbacks() override; | 
|   58   void CancelOutstandingCallbacks(); |  | 
|   59  |  | 
|   60   // CryptoFramerVisitorInterface implementation |  | 
|   61   void OnHandshakeMessage(const CryptoHandshakeMessage& message) override; |   99   void OnHandshakeMessage(const CryptoHandshakeMessage& message) override; | 
|   62  |  100   bool GetBase64SHA256ClientChannelID(std::string* output) const override; | 
|   63   // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded, |  101   void SendServerConfigUpdate( | 
|   64   // SHA-256 hash of the client's ChannelID key and returns true, if the client |  102       const CachedNetworkParameters* cached_network_params) override; | 
|   65   // presented a ChannelID. Otherwise it returns false. |  103   void OnServerHelloAcked() override; | 
|   66   bool GetBase64SHA256ClientChannelID(std::string* output) const; |  104   uint8 NumHandshakeMessages() const override; | 
|   67  |  105   uint8 NumHandshakeMessagesWithServerNonces() const override; | 
|   68   uint8 num_handshake_messages() const { return num_handshake_messages_; } |  106   int NumServerConfigUpdateMessagesSent() const override; | 
|   69  |  107   const CachedNetworkParameters* PreviousCachedNetworkParams() const override; | 
|   70   uint8 num_handshake_messages_with_server_nonces() const { |  108   bool UseStatelessRejectsIfPeerSupported() const override; | 
|   71     return num_handshake_messages_with_server_nonces_; |  109   bool PeerSupportsStatelessRejects() const override; | 
|   72   } |  110   void SetPeerSupportsStatelessRejects( | 
|   73  |  111       bool peer_supports_stateless_rejects) override; | 
|   74   int num_server_config_update_messages_sent() const { |  112   void SetPreviousCachedNetworkParams( | 
|   75     return num_server_config_update_messages_sent_; |  113       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  |  114  | 
|  104  protected: |  115  protected: | 
|  105   virtual QuicErrorCode ProcessClientHello( |  116   virtual QuicErrorCode ProcessClientHello( | 
|  106       const CryptoHandshakeMessage& message, |  117       const CryptoHandshakeMessage& message, | 
|  107       const ValidateClientHelloResultCallback::Result& result, |  118       const ValidateClientHelloResultCallback::Result& result, | 
|  108       CryptoHandshakeMessage* reply, |  119       CryptoHandshakeMessage* reply, | 
|  109       std::string* error_details); |  120       std::string* error_details); | 
|  110  |  121  | 
|  111   // Hook that allows the server to set QuicConfig defaults just |  122   // Hook that allows the server to set QuicConfig defaults just | 
|  112   // before going through the parameter negotiation step. |  123   // 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 |  202   //  TODO(jokulik): Remove once client stateless reject support | 
|  192   // becomes the default. |  203   // becomes the default. | 
|  193   bool peer_supports_stateless_rejects_; |  204   bool peer_supports_stateless_rejects_; | 
|  194  |  205  | 
|  195   DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream); |  206   DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream); | 
|  196 }; |  207 }; | 
|  197  |  208  | 
|  198 }  // namespace net |  209 }  // namespace net | 
|  199  |  210  | 
|  200 #endif  // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ |  211 #endif  // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ | 
| OLD | NEW |