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.
5 #ifndef NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
6 #define NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
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"
17 class CryptoHandshakeMessage;
18 class QuicCryptoServerConfig;
19 class QuicCryptoServerStream;
23 class CryptoTestUtils;
26 // Receives a notification when the server hello (SHLO) has been ACKed by the
27 // peer. At this point we disable HANDSHAKE_MODE in the sent packet manager.
28 class NET_EXPORT_PRIVATE ServerHelloNotifier : public
29 QuicAckNotifier::DelegateInterface {
31 explicit ServerHelloNotifier(QuicCryptoServerStream* stream)
32 : server_stream_(stream) {}
34 // QuicAckNotifier::DelegateInterface implementation
35 virtual void OnAckNotification(
36 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;
43 virtual ~ServerHelloNotifier() {}
45 QuicCryptoServerStream* server_stream_;
47 DISALLOW_COPY_AND_ASSIGN(ServerHelloNotifier);
50 class NET_EXPORT_PRIVATE QuicCryptoServerStream : public QuicCryptoStream {
52 QuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
53 QuicSession* session);
54 explicit QuicCryptoServerStream(QuicSession* session);
55 virtual ~QuicCryptoServerStream();
57 // Cancel any outstanding callbacks, such as asynchronous validation of client
59 void CancelOutstandingCallbacks();
61 // CryptoFramerVisitorInterface implementation
62 virtual void OnHandshakeMessage(
63 const CryptoHandshakeMessage& message) OVERRIDE;
65 // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded,
66 // SHA-256 hash of the client's ChannelID key and returns true, if the client
67 // presented a ChannelID. Otherwise it returns false.
68 bool GetBase64SHA256ClientChannelID(std::string* output) const;
70 uint8 num_handshake_messages() const { return num_handshake_messages_; }
72 int num_server_config_update_messages_sent() const {
73 return num_server_config_update_messages_sent_;
76 // Sends the latest server config and source-address token to the client.
77 void SendServerConfigUpdate();
79 // Called by the ServerHello AckNotifier once the SHLO has been ACKed by the
81 void OnServerHelloAcked();
84 virtual QuicErrorCode ProcessClientHello(
85 const CryptoHandshakeMessage& message,
86 const ValidateClientHelloResultCallback::Result& result,
87 CryptoHandshakeMessage* reply,
88 std::string* error_details);
90 // Hook that allows the server to set QuicConfig defaults just
91 // before going through the parameter negotiation step.
92 virtual void OverrideQuicConfigDefaults(QuicConfig* config);
95 friend class test::CryptoTestUtils;
97 class ValidateCallback : public ValidateClientHelloResultCallback {
99 explicit ValidateCallback(QuicCryptoServerStream* parent);
100 // To allow the parent to detach itself from the callback before deletion.
103 // From ValidateClientHelloResultCallback
104 virtual void RunImpl(const CryptoHandshakeMessage& client_hello,
105 const Result& result) OVERRIDE;
108 QuicCryptoServerStream* parent_;
110 DISALLOW_COPY_AND_ASSIGN(ValidateCallback);
113 // Invoked by ValidateCallback::RunImpl once initial validation of
114 // the client hello is complete. Finishes processing of the client
115 // hello message and handles handshake success/failure.
116 void FinishProcessingHandshakeMessage(
117 const CryptoHandshakeMessage& message,
118 const ValidateClientHelloResultCallback::Result& result);
120 // crypto_config_ contains crypto parameters for the handshake.
121 const QuicCryptoServerConfig& crypto_config_;
123 // Pointer to the active callback that will receive the result of
124 // the client hello validation request and forward it to
125 // FinishProcessingHandshakeMessage for processing. NULL if no
126 // handshake message is being validated.
127 ValidateCallback* validate_client_hello_cb_;
129 // Number of handshake messages received by this stream.
130 uint8 num_handshake_messages_;
132 // Number of server config update (SCUP) messages sent by this stream.
133 int num_server_config_update_messages_sent_;
135 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream);
140 #endif // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_