summaryrefslogtreecommitdiffstats
path: root/net/quic/quic_crypto_stream.h
blob: fb2f6c06d7fc1c5fc1ff737b380c685362abc0d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_QUIC_QUIC_CRYPTO_STREAM_H_
#define NET_QUIC_QUIC_CRYPTO_STREAM_H_

#include "net/quic/crypto/crypto_framer.h"
#include "net/quic/crypto/crypto_utils.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/reliable_quic_stream.h"

namespace net {

class QuicSession;
struct CryptoHandshakeMessage;

// Crypto handshake messages in QUIC take place over a reserved
// reliable stream with the id 1.  Each endpoint (client and server)
// will allocate an instance of a subclass of QuicCryptoStream
// to send and receive handshake messages.  (In the normal 1-RTT
// handshake, the client will send a client hello, CHLO, message.
// The server will receive this message and respond with a server
// hello message, SHLO.  At this point both sides will have established
// a crypto context they can use to send encrypted messages.
//
// For more details: http://goto.google.com/quic-crypto
class NET_EXPORT_PRIVATE QuicCryptoStream
    : public ReliableQuicStream,
      public CryptoFramerVisitorInterface {
 public:
  explicit QuicCryptoStream(QuicSession* session);

  // CryptoFramerVisitorInterface implementation
  virtual void OnError(CryptoFramer* framer) OVERRIDE;
  virtual void OnHandshakeMessage(const CryptoHandshakeMessage& message) = 0;

  // ReliableQuicStream implementation
  virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE;

  // Sends |message| to the peer.
  // TODO(wtc): return a success/failure status.
  void SendHandshakeMessage(const CryptoHandshakeMessage& message);

  bool handshake_complete() { return handshake_complete_; }

 protected:
  // Closes the connection
  void CloseConnection(QuicErrorCode error);
  void CloseConnectionWithDetails(QuicErrorCode error, const string& details);

  void SetHandshakeComplete(QuicErrorCode error);

 private:
  CryptoFramer crypto_framer_;
  bool handshake_complete_;

  DISALLOW_COPY_AND_ASSIGN(QuicCryptoStream);
};

// QuicNegotiatedParameters contains non-crypto parameters that are agreed upon
// during the crypto handshake.
class NET_EXPORT_PRIVATE QuicNegotiatedParameters {
 public:
  QuicNegotiatedParameters();

  CryptoTag congestion_control;
  QuicTime::Delta idle_connection_state_lifetime;
  QuicTime::Delta keepalive_timeout;
};

// QuicConfig contains non-crypto configuration options that are negotiated in
// the crypto handshake.
class NET_EXPORT_PRIVATE QuicConfig {
 public:
  QuicConfig();
  ~QuicConfig();

  // SetDefaults sets the members to sensible, default values.
  void SetDefaults();

  // ToHandshakeMessage serializes the settings in this object as a series of
  // tags /value pairs and adds them to |out|.
  void ToHandshakeMessage(CryptoHandshakeMessage* out) const;

  QuicErrorCode ProcessPeerHandshake(
      const CryptoHandshakeMessage& peer_handshake,
      CryptoUtils::Priority priority,
      QuicNegotiatedParameters* out_params,
      string* error_details) const;

  // Congestion control feedback type.
  CryptoTagVector congestion_control;
  // Idle connection state lifetime
  QuicTime::Delta idle_connection_state_lifetime;
  // Keepalive timeout, or 0 to turn off keepalive probes
  QuicTime::Delta keepalive_timeout;
};

}  // namespace net

#endif  // NET_QUIC_QUIC_CRYPTO_STREAM_H_