Home | History | Annotate | Download | only in quic
      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_STREAM_H_
      6 #define NET_QUIC_QUIC_CRYPTO_STREAM_H_
      7 
      8 #include "net/quic/crypto/crypto_framer.h"
      9 #include "net/quic/crypto/crypto_utils.h"
     10 #include "net/quic/quic_config.h"
     11 #include "net/quic/quic_protocol.h"
     12 #include "net/quic/reliable_quic_stream.h"
     13 
     14 namespace net {
     15 
     16 class CryptoHandshakeMessage;
     17 class QuicSession;
     18 
     19 // Crypto handshake messages in QUIC take place over a reserved
     20 // reliable stream with the id 1.  Each endpoint (client and server)
     21 // will allocate an instance of a subclass of QuicCryptoStream
     22 // to send and receive handshake messages.  (In the normal 1-RTT
     23 // handshake, the client will send a client hello, CHLO, message.
     24 // The server will receive this message and respond with a server
     25 // hello message, SHLO.  At this point both sides will have established
     26 // a crypto context they can use to send encrypted messages.
     27 //
     28 // For more details: http://goto.google.com/quic-crypto
     29 class NET_EXPORT_PRIVATE QuicCryptoStream
     30     : public ReliableQuicStream,
     31       public CryptoFramerVisitorInterface {
     32  public:
     33   explicit QuicCryptoStream(QuicSession* session);
     34 
     35   // CryptoFramerVisitorInterface implementation
     36   virtual void OnError(CryptoFramer* framer) OVERRIDE;
     37   virtual void OnHandshakeMessage(const CryptoHandshakeMessage& message) = 0;
     38 
     39   // ReliableQuicStream implementation
     40   virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE;
     41 
     42   // Sends |message| to the peer.
     43   // TODO(wtc): return a success/failure status.
     44   void SendHandshakeMessage(const CryptoHandshakeMessage& message);
     45 
     46   bool encryption_established() { return encryption_established_; }
     47   bool handshake_confirmed() { return handshake_confirmed_; }
     48 
     49   const QuicCryptoNegotiatedParameters& crypto_negotiated_params() const;
     50 
     51  protected:
     52   // Closes the connection
     53   void CloseConnection(QuicErrorCode error);
     54   void CloseConnectionWithDetails(QuicErrorCode error, const string& details);
     55 
     56   bool encryption_established_;
     57   bool handshake_confirmed_;
     58 
     59   QuicCryptoNegotiatedParameters crypto_negotiated_params_;
     60 
     61  private:
     62   CryptoFramer crypto_framer_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(QuicCryptoStream);
     65 };
     66 
     67 }  // namespace net
     68 
     69 #endif  // NET_QUIC_QUIC_CRYPTO_STREAM_H_
     70