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 CryptoHandshakeMessage; 18 class QuicCryptoServerConfig; 19 class QuicSession; 20 21 namespace test { 22 class CryptoTestUtils; 23 } // namespace test 24 25 class NET_EXPORT_PRIVATE QuicCryptoServerStream : public QuicCryptoStream { 26 public: 27 QuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, 28 QuicSession* session); 29 explicit QuicCryptoServerStream(QuicSession* session); 30 virtual ~QuicCryptoServerStream(); 31 32 // Cancel any outstanding callbacks, such as asynchronous validation of client 33 // hello. 34 void CancelOutstandingCallbacks(); 35 36 // CryptoFramerVisitorInterface implementation 37 virtual void OnHandshakeMessage( 38 const CryptoHandshakeMessage& message) OVERRIDE; 39 40 // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded, 41 // SHA-256 hash of the client's ChannelID key and returns true, if the client 42 // presented a ChannelID. Otherwise it returns false. 43 bool GetBase64SHA256ClientChannelID(std::string* output) const; 44 num_handshake_messages()45 uint8 num_handshake_messages() const { return num_handshake_messages_; } 46 47 protected: 48 virtual QuicErrorCode ProcessClientHello( 49 const CryptoHandshakeMessage& message, 50 const ValidateClientHelloResultCallback::Result& result, 51 CryptoHandshakeMessage* reply, 52 std::string* error_details); 53 54 // Hook that allows the server to set QuicConfig defaults just 55 // before going through the parameter negotiation step. 56 virtual void OverrideQuicConfigDefaults(QuicConfig* config); 57 58 private: 59 friend class test::CryptoTestUtils; 60 61 class ValidateCallback : public ValidateClientHelloResultCallback { 62 public: 63 explicit ValidateCallback(QuicCryptoServerStream* parent); 64 // To allow the parent to detach itself from the callback before deletion. 65 void Cancel(); 66 67 // From ValidateClientHelloResultCallback 68 virtual void RunImpl(const CryptoHandshakeMessage& client_hello, 69 const Result& result) OVERRIDE; 70 71 private: 72 QuicCryptoServerStream* parent_; 73 74 DISALLOW_COPY_AND_ASSIGN(ValidateCallback); 75 }; 76 77 // Invoked by ValidateCallback::RunImpl once initial validation of 78 // the client hello is complete. Finishes processing of the client 79 // hello message and handles handshake success/failure. 80 void FinishProcessingHandshakeMessage( 81 const CryptoHandshakeMessage& message, 82 const ValidateClientHelloResultCallback::Result& result); 83 84 // crypto_config_ contains crypto parameters for the handshake. 85 const QuicCryptoServerConfig& crypto_config_; 86 87 // Pointer to the active callback that will receive the result of 88 // the client hello validation request and forward it to 89 // FinishProcessingHandshakeMessage for processing. NULL if no 90 // handshake message is being validated. 91 ValidateCallback* validate_client_hello_cb_; 92 93 uint8 num_handshake_messages_; 94 95 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream); 96 }; 97 98 } // namespace net 99 100 #endif // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_ 101