quic_crypto_server_stream.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/crypto/crypto_handshake.h"
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/crypto/quic_crypto_server_config.h"
12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/quic/quic_config.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/quic_crypto_stream.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace net {
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class CryptoHandshakeMessage;
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class QuicCryptoServerConfig;
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class QuicSession;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test {
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CryptoTestUtils;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace test
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NET_EXPORT_PRIVATE QuicCryptoServerStream : public QuicCryptoStream {
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  QuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                         QuicSession* session);
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit QuicCryptoServerStream(QuicSession* session);
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~QuicCryptoServerStream();
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Cancel any outstanding callbacks, such as asynchronous validation of client
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // hello.
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void CancelOutstandingCallbacks();
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // CryptoFramerVisitorInterface implementation
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnHandshakeMessage(
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const CryptoHandshakeMessage& message) OVERRIDE;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
409ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded,
419ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // SHA-256 hash of the client's ChannelID key and returns true, if the client
429ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch  // presented a ChannelID. Otherwise it returns false.
43a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  bool GetBase64SHA256ClientChannelID(std::string* output) const;
449ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) protected:
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual QuicErrorCode ProcessClientHello(
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      const CryptoHandshakeMessage& message,
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const ValidateClientHelloResultCallback::Result& result,
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      CryptoHandshakeMessage* reply,
50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      std::string* error_details);
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class test::CryptoTestUtils;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  class ValidateCallback : public ValidateClientHelloResultCallback {
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)   public:
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    explicit ValidateCallback(QuicCryptoServerStream* parent);
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // To allow the parent to detach itself from the callback before deletion.
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    void Cancel();
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // From ValidateClientHelloResultCallback
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    virtual void RunImpl(const CryptoHandshakeMessage& client_hello,
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                         const Result& result) OVERRIDE;
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)   private:
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    QuicCryptoServerStream* parent_;
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(ValidateCallback);
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  };
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Invoked by ValidateCallback::RunImpl once initial validation of
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the client hello is complete.  Finishes processing of the client
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // hello message and handles handshake success/failure.
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void FinishProcessingHandshakeMessage(
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const CryptoHandshakeMessage& message,
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const ValidateClientHelloResultCallback::Result& result);
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // crypto_config_ contains crypto parameters for the handshake.
79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const QuicCryptoServerConfig& crypto_config_;
80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Pointer to the active callback that will receive the result of
82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the client hello validation request and forward it to
83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // FinishProcessingHandshakeMessage for processing.  NULL if no
84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // handshake message is being validated.
85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ValidateCallback* validate_client_hello_cb_;
860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream);
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace net
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
93