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