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

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

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 years, 6 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
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"
(...skipping 20 matching lines...) Expand all
31 class QuicCryptoServerConfigPeer; 31 class QuicCryptoServerConfigPeer;
32 } // namespace test 32 } // namespace test
33 33
34 // QuicCryptoServerConfig contains the crypto configuration of a QUIC server. 34 // QuicCryptoServerConfig contains the crypto configuration of a QUIC server.
35 // Unlike a client, a QUIC server can have multiple configurations active in 35 // Unlike a client, a QUIC server can have multiple configurations active in
36 // order to support clients resuming with a previous configuration. 36 // order to support clients resuming with a previous configuration.
37 // TODO(agl): when adding configurations at runtime is added, this object will 37 // TODO(agl): when adding configurations at runtime is added, this object will
38 // need to consider locking. 38 // need to consider locking.
39 class NET_EXPORT_PRIVATE QuicCryptoServerConfig { 39 class NET_EXPORT_PRIVATE QuicCryptoServerConfig {
40 public: 40 public:
41 enum { 41 // ConfigOptions contains options for generating server configs.
42 // kDefaultExpiry can be passed to DefaultConfig to select the default 42 struct NET_EXPORT_PRIVATE ConfigOptions {
43 // expiry time. 43 ConfigOptions();
44 kDefaultExpiry = 0, 44
45 // expiry_time is the time, in UNIX seconds, when the server config will
46 // expire. If unset, it defaults to the current time plus six months.
47 QuicWallTime expiry_time;
48 // channel_id_enabled controls whether the server config will indicate
49 // support for ChannelIDs.
50 bool channel_id_enabled;
45 }; 51 };
46 52
47 // |source_address_token_secret|: secret key material used for encrypting and 53 // |source_address_token_secret|: secret key material used for encrypting and
48 // decrypting source address tokens. It can be of any length as it is fed 54 // decrypting source address tokens. It can be of any length as it is fed
49 // into a KDF before use. In tests, use TESTING. 55 // into a KDF before use. In tests, use TESTING.
50 explicit QuicCryptoServerConfig( 56 // |server_nonce_entropy|: an entropy source used to generate the orbit and
51 base::StringPiece source_address_token_secret); 57 // key for server nonces, which are always local to a given instance of a
58 // server.
59 QuicCryptoServerConfig(base::StringPiece source_address_token_secret,
60 QuicRandom* server_nonce_entropy);
52 ~QuicCryptoServerConfig(); 61 ~QuicCryptoServerConfig();
53 62
54 // TESTING is a magic parameter for passing to the constructor in tests. 63 // TESTING is a magic parameter for passing to the constructor in tests.
55 static const char TESTING[]; 64 static const char TESTING[];
56 65
57 // DefaultConfig generates a QuicServerConfigProtobuf protobuf suitable for 66 // DefaultConfig generates a QuicServerConfigProtobuf protobuf suitable for
58 // using in tests. If |expiry_time| is non-zero then it's used as the expiry 67 // using in tests.
59 // for the server config in UNIX epoch seconds. Otherwise the default expiry
60 // time is six months from now.
61 static QuicServerConfigProtobuf* DefaultConfig( 68 static QuicServerConfigProtobuf* DefaultConfig(
62 QuicRandom* rand, 69 QuicRandom* rand,
63 const QuicClock* clock, 70 const QuicClock* clock,
64 uint64 expiry_time); 71 const ConfigOptions& options);
65 72
66 // AddConfig adds a QuicServerConfigProtobuf to the availible configurations. 73 // AddConfig adds a QuicServerConfigProtobuf to the availible configurations.
67 // It returns the SCFG message from the config if successful. The caller 74 // It returns the SCFG message from the config if successful. The caller
68 // takes ownership of the CryptoHandshakeMessage. 75 // takes ownership of the CryptoHandshakeMessage.
69 CryptoHandshakeMessage* AddConfig(QuicServerConfigProtobuf* protobuf); 76 CryptoHandshakeMessage* AddConfig(QuicServerConfigProtobuf* protobuf);
70 77
71 // AddDefaultConfig calls DefaultConfig to create a config and then calls 78 // AddDefaultConfig calls DefaultConfig to create a config and then calls
72 // AddConfig to add it. See the comment for |DefaultConfig| for details of 79 // AddConfig to add it. See the comment for |DefaultConfig| for details of
73 // the arguments. 80 // the arguments.
74 CryptoHandshakeMessage* AddDefaultConfig( 81 CryptoHandshakeMessage* AddDefaultConfig(
75 QuicRandom* rand, 82 QuicRandom* rand,
76 const QuicClock* clock, 83 const QuicClock* clock,
77 uint64 expiry_time); 84 const ConfigOptions& options);
78 85
79 // ProcessClientHello processes |client_hello| and decides whether to accept 86 // ProcessClientHello processes |client_hello| and decides whether to accept
80 // or reject the connection. If the connection is to be accepted, |out| is 87 // or reject the connection. If the connection is to be accepted, |out| is
81 // set to the contents of the ServerHello, |out_params| is completed and 88 // set to the contents of the ServerHello, |out_params| is completed and
82 // QUIC_NO_ERROR is returned. Otherwise |out| is set to be a REJ message and 89 // QUIC_NO_ERROR is returned. Otherwise |out| is set to be a REJ message and
83 // an error code is returned. 90 // an error code is returned.
84 // 91 //
85 // client_hello: the incoming client hello message. 92 // client_hello: the incoming client hello message.
86 // guid: the GUID for the connection, which is used in key derivation. 93 // guid: the GUID for the connection, which is used in key derivation.
87 // client_ip: the IP address of the client, which is used to generate and 94 // client_ip: the IP address of the client, which is used to generate and
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 unsigned char orbit[kOrbitSize]; 159 unsigned char orbit[kOrbitSize];
153 160
154 // key_exchanges contains key exchange objects with the private keys 161 // key_exchanges contains key exchange objects with the private keys
155 // already loaded. The values correspond, one-to-one, with the tags in 162 // already loaded. The values correspond, one-to-one, with the tags in
156 // |kexs| from the parent class. 163 // |kexs| from the parent class.
157 std::vector<KeyExchange*> key_exchanges; 164 std::vector<KeyExchange*> key_exchanges;
158 165
159 // tag_value_map contains the raw key/value pairs for the config. 166 // tag_value_map contains the raw key/value pairs for the config.
160 QuicTagValueMap tag_value_map; 167 QuicTagValueMap tag_value_map;
161 168
169 // channel_id_enabled is true if the config in |serialized| specifies that
170 // ChannelIDs are supported.
171 bool channel_id_enabled;
172
162 private: 173 private:
163 DISALLOW_COPY_AND_ASSIGN(Config); 174 DISALLOW_COPY_AND_ASSIGN(Config);
164 }; 175 };
165 176
166 // NewSourceAddressToken returns a fresh source address token for the given 177 // NewSourceAddressToken returns a fresh source address token for the given
167 // IP address. 178 // IP address.
168 std::string NewSourceAddressToken(const IPEndPoint& ip, 179 std::string NewSourceAddressToken(const IPEndPoint& ip,
169 QuicRandom* rand, 180 QuicRandom* rand,
170 QuicWallTime now) const; 181 QuicWallTime now) const;
171 182
172 // ValidateSourceAddressToken returns true if the source address token in 183 // ValidateSourceAddressToken returns true if the source address token in
173 // |token| is a valid and timely token for the IP address |ip| given that the 184 // |token| is a valid and timely token for the IP address |ip| given that the
174 // current time is |now|. 185 // current time is |now|.
175 bool ValidateSourceAddressToken(base::StringPiece token, 186 bool ValidateSourceAddressToken(base::StringPiece token,
176 const IPEndPoint& ip, 187 const IPEndPoint& ip,
177 QuicWallTime now) const; 188 QuicWallTime now) const;
178 189
190 // NewServerNonce generates and encrypts a random nonce.
191 std::string NewServerNonce(QuicRandom* rand, QuicWallTime now) const;
192
193 // ValidateServerNonce decrypts |token| and verifies that it hasn't been
194 // previously used and is recent enough that it is plausible that it was part
195 // of a very recently provided rejection ("recent" will be on the order of
196 // 10-30 seconds). If so, it records that it has been used and returns true.
197 // Otherwise it returns false.
198 bool ValidateServerNonce(base::StringPiece echoed_server_nonce,
199 QuicWallTime now) const;
200
179 std::map<ServerConfigID, Config*> configs_; 201 std::map<ServerConfigID, Config*> configs_;
180 202
181 ServerConfigID active_config_; 203 ServerConfigID active_config_;
182 204
183 mutable base::Lock strike_register_lock_; 205 mutable base::Lock strike_register_lock_;
184 // strike_register_ contains a data structure that keeps track of previously 206 // strike_register_ contains a data structure that keeps track of previously
185 // observed client nonces in order to prevent replay attacks. 207 // observed client nonces in order to prevent replay attacks.
186 mutable scoped_ptr<StrikeRegister> strike_register_; 208 mutable scoped_ptr<StrikeRegister> strike_register_;
187 209
188 // source_address_token_boxer_ is used to protect the source-address tokens 210 // source_address_token_boxer_ is used to protect the source-address tokens
189 // that are given to clients. 211 // that are given to clients.
190 CryptoSecretBoxer source_address_token_boxer_; 212 CryptoSecretBoxer source_address_token_boxer_;
191 213
214 // server_nonce_boxer_ is used to encrypt and validate suggested server
215 // nonces.
216 CryptoSecretBoxer server_nonce_boxer_;
217
218 // server_nonce_orbit_ contains the random, per-server orbit values that this
219 // server will use to generate server nonces (the moral equivalent of a SYN
220 // cookies).
221 uint8 server_nonce_orbit_[8];
222
223 mutable base::Lock server_nonce_strike_register_lock_;
224 // server_nonce_strike_register_ contains a data structure that keeps track of
225 // previously observed server nonces from this server, in order to prevent
226 // replay attacks.
227 mutable scoped_ptr<StrikeRegister> server_nonce_strike_register_;
228
192 // proof_source_ contains an object that can provide certificate chains and 229 // proof_source_ contains an object that can provide certificate chains and
193 // signatures. 230 // signatures.
194 scoped_ptr<ProofSource> proof_source_; 231 scoped_ptr<ProofSource> proof_source_;
195 232
196 // ephemeral_key_source_ contains an object that caches ephemeral keys for a 233 // ephemeral_key_source_ contains an object that caches ephemeral keys for a
197 // short period of time. 234 // short period of time.
198 scoped_ptr<EphemeralKeySource> ephemeral_key_source_; 235 scoped_ptr<EphemeralKeySource> ephemeral_key_source_;
199 236
200 // These fields store configuration values. See the comments for their 237 // These fields store configuration values. See the comments for their
201 // respective setter functions. 238 // respective setter functions.
202 uint32 strike_register_max_entries_; 239 uint32 strike_register_max_entries_;
203 uint32 strike_register_window_secs_; 240 uint32 strike_register_window_secs_;
204 uint32 source_address_token_future_secs_; 241 uint32 source_address_token_future_secs_;
205 uint32 source_address_token_lifetime_secs_; 242 uint32 source_address_token_lifetime_secs_;
243 uint32 server_nonce_strike_register_max_entries_;
244 uint32 server_nonce_strike_register_window_secs_;
206 }; 245 };
207 246
208 } // namespace net 247 } // namespace net
209 248
210 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_ 249 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698