Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_crypto_server_stream.h
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
6 #define NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
7
8 #include <string>
9
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/crypto/quic_crypto_server_config.h"
12 #include "net/quic/quic_config.h"
13 #include "net/quic/quic_crypto_stream.h"
14
15 namespace net {
16
17 class CachedNetworkParameters;
18 class CryptoHandshakeMessage;
19 class QuicCryptoServerConfig;
20 class QuicCryptoServerStream;
21 class QuicSession;
22
23 namespace test {
24 class CryptoTestUtils;
25 }  // namespace test
26
27 // Receives a notification when the server hello (SHLO) has been ACKed by the
28 // peer. At this point we disable HANDSHAKE_MODE in the sent packet manager.
29 class NET_EXPORT_PRIVATE ServerHelloNotifier : public
30     QuicAckNotifier::DelegateInterface {
31  public:
32   explicit ServerHelloNotifier(QuicCryptoServerStream* stream)
33       : server_stream_(stream) {}
34
35   // QuicAckNotifier::DelegateInterface implementation
36   void OnAckNotification(int num_original_packets,
37                          int num_original_bytes,
38                          int num_retransmitted_packets,
39                          int num_retransmitted_bytes,
40                          QuicTime::Delta delta_largest_observed) override;
41
42  private:
43   ~ServerHelloNotifier() override {}
44
45   QuicCryptoServerStream* server_stream_;
46
47   DISALLOW_COPY_AND_ASSIGN(ServerHelloNotifier);
48 };
49
50 class NET_EXPORT_PRIVATE QuicCryptoServerStream : public QuicCryptoStream {
51  public:
52   QuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
53                          QuicSession* session);
54   ~QuicCryptoServerStream() override;
55
56   // Cancel any outstanding callbacks, such as asynchronous validation of client
57   // hello.
58   void CancelOutstandingCallbacks();
59
60   // CryptoFramerVisitorInterface implementation
61   void OnHandshakeMessage(const CryptoHandshakeMessage& message) override;
62
63   // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded,
64   // SHA-256 hash of the client's ChannelID key and returns true, if the client
65   // presented a ChannelID. Otherwise it returns false.
66   bool GetBase64SHA256ClientChannelID(std::string* output) const;
67
68   uint8 num_handshake_messages() const { return num_handshake_messages_; }
69
70   int num_server_config_update_messages_sent() const {
71     return num_server_config_update_messages_sent_;
72   }
73
74   // Sends the latest server config and source-address token to the client.
75   virtual void SendServerConfigUpdate(
76       const CachedNetworkParameters* cached_network_params);
77
78   // Called by the ServerHello AckNotifier once the SHLO has been ACKed by the
79   // client.
80   void OnServerHelloAcked();
81
82   void set_previous_cached_network_params(
83       CachedNetworkParameters cached_network_params);
84
85  protected:
86   virtual QuicErrorCode ProcessClientHello(
87       const CryptoHandshakeMessage& message,
88       const ValidateClientHelloResultCallback::Result& result,
89       CryptoHandshakeMessage* reply,
90       std::string* error_details);
91
92   // Hook that allows the server to set QuicConfig defaults just
93   // before going through the parameter negotiation step.
94   virtual void OverrideQuicConfigDefaults(QuicConfig* config);
95
96   CachedNetworkParameters* get_previous_cached_network_params();
97
98  private:
99   friend class test::CryptoTestUtils;
100
101   class ValidateCallback : public ValidateClientHelloResultCallback {
102    public:
103     explicit ValidateCallback(QuicCryptoServerStream* parent);
104     // To allow the parent to detach itself from the callback before deletion.
105     void Cancel();
106
107     // From ValidateClientHelloResultCallback
108     void RunImpl(const CryptoHandshakeMessage& client_hello,
109                  const Result& result) override;
110
111    private:
112     QuicCryptoServerStream* parent_;
113
114     DISALLOW_COPY_AND_ASSIGN(ValidateCallback);
115   };
116
117   // Invoked by ValidateCallback::RunImpl once initial validation of
118   // the client hello is complete.  Finishes processing of the client
119   // hello message and handles handshake success/failure.
120   void FinishProcessingHandshakeMessage(
121       const CryptoHandshakeMessage& message,
122       const ValidateClientHelloResultCallback::Result& result);
123
124   // crypto_config_ contains crypto parameters for the handshake.
125   const QuicCryptoServerConfig& crypto_config_;
126
127   // Pointer to the active callback that will receive the result of
128   // the client hello validation request and forward it to
129   // FinishProcessingHandshakeMessage for processing.  nullptr if no
130   // handshake message is being validated.
131   ValidateCallback* validate_client_hello_cb_;
132
133   // Number of handshake messages received by this stream.
134   uint8 num_handshake_messages_;
135
136   // Number of server config update (SCUP) messages sent by this stream.
137   int num_server_config_update_messages_sent_;
138
139   // If the client provides CachedNetworkParameters in the STK in the CHLO, then
140   // store here, and send back in future STKs if we have no better bandwidth
141   // estimate to send.
142   scoped_ptr<CachedNetworkParameters> previous_cached_network_params_;
143
144   DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream);
145 };
146
147 }  // namespace net
148
149 #endif  // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_