Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: net/quic/crypto/crypto_server_config.h

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_protocol.h ('k') | net/quic/crypto/crypto_server_config.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_ 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
6 #define NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_ 6 #define NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "net/base/ip_endpoint.h" 11 #include "net/base/ip_endpoint.h"
12 #include "net/base/net_export.h" 12 #include "net/base/net_export.h"
13 #include "net/quic/crypto/crypto_handshake.h" 13 #include "net/quic/crypto/crypto_handshake.h"
14 #include "net/quic/crypto/crypto_protocol.h" 14 #include "net/quic/crypto/crypto_protocol.h"
15 #include "net/quic/quic_time.h" 15 #include "net/quic/quic_time.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 class EphemeralKeySource;
19 class KeyExchange; 20 class KeyExchange;
20 class ProofSource; 21 class ProofSource;
21 class QuicClock; 22 class QuicClock;
22 class QuicDecrypter; 23 class QuicDecrypter;
23 class QuicEncrypter; 24 class QuicEncrypter;
24 class QuicRandom; 25 class QuicRandom;
25 class QuicServerConfigProtobuf; 26 class QuicServerConfigProtobuf;
26 class StrikeRegister; 27 class StrikeRegister;
27 28
28 namespace test { 29 namespace test {
29 class QuicCryptoServerConfigPeer; 30 class QuicCryptoServerConfigPeer;
30 } // namespace test 31 } // namespace test
31 32
32 // QuicCryptoServerConfig contains the crypto configuration of a QUIC server. 33 // QuicCryptoServerConfig contains the crypto configuration of a QUIC server.
33 // Unlike a client, a QUIC server can have multiple configurations active in 34 // Unlike a client, a QUIC server can have multiple configurations active in
34 // order to support clients resuming with a previous configuration. 35 // order to support clients resuming with a previous configuration.
35 // TODO(agl): when adding configurations at runtime is added, this object will 36 // TODO(agl): when adding configurations at runtime is added, this object will
36 // need to consider locking. 37 // need to consider locking.
37 class NET_EXPORT_PRIVATE QuicCryptoServerConfig { 38 class NET_EXPORT_PRIVATE QuicCryptoServerConfig {
38 public: 39 public:
40 enum {
41 // kDefaultExpiry can be passed to DefaultConfig to select the default
42 // expiry time.
43 kDefaultExpiry = 0,
44 };
45
39 // |source_address_token_secret|: secret key material used for encrypting and 46 // |source_address_token_secret|: secret key material used for encrypting and
40 // decrypting source address tokens. It can be of any length as it is fed 47 // decrypting source address tokens. It can be of any length as it is fed
41 // into a KDF before use. In tests, use TESTING. 48 // into a KDF before use. In tests, use TESTING.
42 explicit QuicCryptoServerConfig( 49 explicit QuicCryptoServerConfig(
43 base::StringPiece source_address_token_secret); 50 base::StringPiece source_address_token_secret);
44 ~QuicCryptoServerConfig(); 51 ~QuicCryptoServerConfig();
45 52
46 // TESTING is a magic parameter for passing to the constructor in tests. 53 // TESTING is a magic parameter for passing to the constructor in tests.
47 static const char TESTING[]; 54 static const char TESTING[];
48 55
49 // DefaultConfig generates a QuicServerConfigProtobuf protobuf suitable 56 // DefaultConfig generates a QuicServerConfigProtobuf protobuf suitable for
50 // for using in tests. |extra_tags| contains additional key/value pairs that 57 // using in tests. |extra_tags| contains additional key/value pairs that will
51 // will be inserted into the config. 58 // be inserted into the config. If |expiry_time| is non-zero then it's used
59 // as the expiry for the server config in UNIX epoch seconds. Otherwise the
60 // default expiry time is six months from now.
52 static QuicServerConfigProtobuf* DefaultConfig( 61 static QuicServerConfigProtobuf* DefaultConfig(
53 QuicRandom* rand, 62 QuicRandom* rand,
54 const QuicClock* clock, 63 const QuicClock* clock,
55 const CryptoHandshakeMessage& extra_tags); 64 const CryptoHandshakeMessage& extra_tags,
65 uint64 expiry_time);
56 66
57 // AddConfig adds a QuicServerConfigProtobuf to the availible configurations. 67 // AddConfig adds a QuicServerConfigProtobuf to the availible configurations.
58 // It returns the SCFG message from the config if successful. The caller 68 // It returns the SCFG message from the config if successful. The caller
59 // takes ownership of the CryptoHandshakeMessage. 69 // takes ownership of the CryptoHandshakeMessage.
60 CryptoHandshakeMessage* AddConfig(QuicServerConfigProtobuf* protobuf); 70 CryptoHandshakeMessage* AddConfig(QuicServerConfigProtobuf* protobuf);
61 71
62 // AddDefaultConfig creates a config and then calls AddConfig to 72 // AddDefaultConfig creates a config and then calls AddConfig to add it. See
63 // add it. Any tags in |extra_tags| will be copied into the config. 73 // the comment for |DefaultConfig| for details of the arguments.
64 CryptoHandshakeMessage* AddDefaultConfig( 74 CryptoHandshakeMessage* AddDefaultConfig(
65 QuicRandom* rand, 75 QuicRandom* rand,
66 const QuicClock* clock, 76 const QuicClock* clock,
67 const CryptoHandshakeMessage& extra_tags); 77 const CryptoHandshakeMessage& extra_tags,
78 uint64 expiry_time);
68 79
69 // ProcessClientHello processes |client_hello| and decides whether to accept 80 // ProcessClientHello processes |client_hello| and decides whether to accept
70 // or reject the connection. If the connection is to be accepted, |out| is 81 // or reject the connection. If the connection is to be accepted, |out| is
71 // set to the contents of the ServerHello, |out_params| is completed and 82 // set to the contents of the ServerHello, |out_params| is completed and
72 // QUIC_NO_ERROR is returned. Otherwise |out| is set to be a REJ message and 83 // QUIC_NO_ERROR is returned. Otherwise |out| is set to be a REJ message and
73 // an error code is returned. 84 // an error code is returned.
74 // 85 //
75 // client_hello: the incoming client hello message. 86 // client_hello: the incoming client hello message.
76 // guid: the GUID for the connection, which is used in key derivation. 87 // guid: the GUID for the connection, which is used in key derivation.
77 // client_ip: the IP address of the client, which is used to generate and 88 // client_ip: the IP address of the client, which is used to generate and
78 // validate source-address tokens. 89 // validate source-address tokens.
79 // now_since_epoch: the current time, as a delta since the unix epoch, 90 // clock: used to validate client nonces and ephemeral keys.
80 // which is used to validate client nonces.
81 // rand: an entropy source 91 // rand: an entropy source
82 // params: the state of the handshake. This may be updated with a server 92 // params: the state of the handshake. This may be updated with a server
83 // nonce when we send a rejection. After a successful handshake, this will 93 // nonce when we send a rejection. After a successful handshake, this will
84 // contain the state of the connection. 94 // contain the state of the connection.
85 // out: the resulting handshake message (either REJ or SHLO) 95 // out: the resulting handshake message (either REJ or SHLO)
86 // error_details: used to store a string describing any error. 96 // error_details: used to store a string describing any error.
87 QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello, 97 QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
88 QuicGuid guid, 98 QuicGuid guid,
89 const IPEndPoint& client_ip, 99 const IPEndPoint& client_ip,
90 QuicTime::Delta now_since_epoch, 100 const QuicClock* now,
91 QuicRandom* rand, 101 QuicRandom* rand,
92 QuicCryptoNegotiatedParameters* params, 102 QuicCryptoNegotiatedParameters* params,
93 CryptoHandshakeMessage* out, 103 CryptoHandshakeMessage* out,
94 std::string* error_details) const; 104 std::string* error_details) const;
95 105
96 // SetProofSource installs |proof_source| as the ProofSource for handshakes. 106 // SetProofSource installs |proof_source| as the ProofSource for handshakes.
97 // This object takes ownership of |proof_source|. 107 // This object takes ownership of |proof_source|.
98 void SetProofSource(ProofSource* proof_source); 108 void SetProofSource(ProofSource* proof_source);
99 109
110 // SetEphemeralKeySource installs an object that can cache ephemeral keys for
111 // a short period of time. This object takes ownership of
112 // |ephemeral_key_source|. If not set then ephemeral keys will be generated
113 // per-connection.
114 void SetEphemeralKeySource(EphemeralKeySource* ephemeral_key_source);
115
100 private: 116 private:
101 friend class test::QuicCryptoServerConfigPeer; 117 friend class test::QuicCryptoServerConfigPeer;
102 118
103 // Config represents a server config: a collection of preferences and 119 // Config represents a server config: a collection of preferences and
104 // Diffie-Hellman public values. 120 // Diffie-Hellman public values.
105 struct Config : public QuicCryptoConfig { 121 struct Config : public QuicCryptoConfig {
106 Config(); 122 Config();
107 ~Config(); 123 ~Config();
108 124
109 // serialized contains the bytes of this server config, suitable for sending 125 // serialized contains the bytes of this server config, suitable for sending
110 // on the wire. 126 // on the wire.
111 std::string serialized; 127 std::string serialized;
112 // id contains the SCID of this server config. 128 // id contains the SCID of this server config.
113 std::string id; 129 std::string id;
114 // orbit contains the orbit value for this config: an opaque identifier 130 // orbit contains the orbit value for this config: an opaque identifier
115 // used to identify clusters of server frontends. 131 // used to identify clusters of server frontends.
116 unsigned char orbit[kOrbitSize]; 132 unsigned char orbit[kOrbitSize];
117 133
118 // key_exchanges contains key exchange objects with the private keys 134 // key_exchanges contains key exchange objects with the private keys
119 // already loaded. The values correspond, one-to-one, with the tags in 135 // already loaded. The values correspond, one-to-one, with the tags in
120 // |kexs| from the parent class. 136 // |kexs| from the parent class.
121 std::vector<KeyExchange*> key_exchanges; 137 std::vector<KeyExchange*> key_exchanges;
122 138
123 // tag_value_map contains the raw key/value pairs for the config. 139 // tag_value_map contains the raw key/value pairs for the config.
124 CryptoTagValueMap tag_value_map; 140 QuicTagValueMap tag_value_map;
125 141
126 private: 142 private:
127 DISALLOW_COPY_AND_ASSIGN(Config); 143 DISALLOW_COPY_AND_ASSIGN(Config);
128 }; 144 };
129 145
130 // NewSourceAddressToken returns a fresh source address token for the given 146 // NewSourceAddressToken returns a fresh source address token for the given
131 // IP address. 147 // IP address.
132 std::string NewSourceAddressToken(const IPEndPoint& ip, 148 std::string NewSourceAddressToken(const IPEndPoint& ip,
133 QuicRandom* rand, 149 QuicRandom* rand,
134 QuicTime::Delta now_since_epoch) const; 150 QuicWallTime now) const;
135 151
136 // ValidateSourceAddressToken returns true if the source address token in 152 // ValidateSourceAddressToken returns true if the source address token in
137 // |token| is a valid and timely token for the IP address |ip| given that the 153 // |token| is a valid and timely token for the IP address |ip| given that the
138 // current time is |now|. 154 // current time is |now|.
139 bool ValidateSourceAddressToken(base::StringPiece token, 155 bool ValidateSourceAddressToken(base::StringPiece token,
140 const IPEndPoint& ip, 156 const IPEndPoint& ip,
141 QuicTime::Delta now_since_epoch) const; 157 QuicWallTime now) const;
142 158
143 std::map<ServerConfigID, Config*> configs_; 159 std::map<ServerConfigID, Config*> configs_;
144 160
145 ServerConfigID active_config_; 161 ServerConfigID active_config_;
146 162
147 mutable base::Lock strike_register_lock_; 163 mutable base::Lock strike_register_lock_;
148 // strike_register_ contains a data structure that keeps track of previously 164 // strike_register_ contains a data structure that keeps track of previously
149 // observed client nonces in order to prevent replay attacks. 165 // observed client nonces in order to prevent replay attacks.
150 mutable scoped_ptr<StrikeRegister> strike_register_; 166 mutable scoped_ptr<StrikeRegister> strike_register_;
151 167
152 // These members are used to encrypt and decrypt the source address tokens 168 // These members are used to encrypt and decrypt the source address tokens
153 // that we receive from and send to clients. 169 // that we receive from and send to clients.
154 scoped_ptr<QuicEncrypter> source_address_token_encrypter_; 170 scoped_ptr<QuicEncrypter> source_address_token_encrypter_;
155 scoped_ptr<QuicDecrypter> source_address_token_decrypter_; 171 scoped_ptr<QuicDecrypter> source_address_token_decrypter_;
156 172
157 // proof_source_ contains an object that can provide certificate chains and 173 // proof_source_ contains an object that can provide certificate chains and
158 // signatures. 174 // signatures.
159 scoped_ptr<ProofSource> proof_source_; 175 scoped_ptr<ProofSource> proof_source_;
176
177 // ephemeral_key_source_ contains an object that caches ephemeral keys for a
178 // short period of time.
179 scoped_ptr<EphemeralKeySource> ephemeral_key_source_;
160 }; 180 };
161 181
162 } // namespace net 182 } // namespace net
163 183
164 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_ 184 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_protocol.h ('k') | net/quic/crypto/crypto_server_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698