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

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

Issue 14411004: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use CONFIG_VERSION insteaf of VERSION Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
6 #define NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_piece.h"
10 #include "base/synchronization/lock.h"
11 #include "net/base/ip_endpoint.h"
12 #include "net/base/net_export.h"
13 #include "net/quic/crypto/crypto_handshake.h"
14 #include "net/quic/crypto/crypto_protocol.h"
15 #include "net/quic/quic_time.h"
16
17 namespace net {
18
19 class KeyExchange;
20 class ProofSource;
21 class QuicClock;
22 class QuicDecrypter;
23 class QuicEncrypter;
24 class QuicRandom;
25 class QuicServerConfigProtobuf;
26 class StrikeRegister;
27
28 namespace test {
29 class QuicCryptoServerConfigPeer;
30 } // namespace test
31
32 // QuicCryptoServerConfig contains the crypto configuration of a QUIC server.
33 // Unlike a client, a QUIC server can have multiple configurations active in
34 // order to support clients resuming with a previous configuration.
35 // TODO(agl): when adding configurations at runtime is added, this object will
36 // need to consider locking.
37 class NET_EXPORT_PRIVATE QuicCryptoServerConfig {
38 public:
39 // |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
41 // into a KDF before use. In tests, use TESTING.
42 explicit QuicCryptoServerConfig(
43 base::StringPiece source_address_token_secret);
44 ~QuicCryptoServerConfig();
45
46 // TESTING is a magic parameter for passing to the constructor in tests.
47 static const char TESTING[];
48
49 // DefaultConfig generates a QuicServerConfigProtobuf protobuf suitable
50 // for using in tests. |extra_tags| contains additional key/value pairs that
51 // will be inserted into the config.
52 static QuicServerConfigProtobuf* DefaultConfig(
53 QuicRandom* rand,
54 const QuicClock* clock,
55 const CryptoHandshakeMessage& extra_tags);
56
57 // AddConfig adds a QuicServerConfigProtobuf to the availible configurations.
58 // It returns the SCFG message from the config if successful. The caller
59 // takes ownership of the CryptoHandshakeMessage.
60 CryptoHandshakeMessage* AddConfig(QuicServerConfigProtobuf* protobuf);
61
62 // AddDefaultConfig creates a config and then calls AddConfig to
63 // add it. Any tags in |extra_tags| will be copied into the config.
64 CryptoHandshakeMessage* AddDefaultConfig(
65 QuicRandom* rand,
66 const QuicClock* clock,
67 const CryptoHandshakeMessage& extra_tags);
68
69 // ProcessClientHello processes |client_hello| and decides whether to accept
70 // 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
72 // QUIC_NO_ERROR is returned. Otherwise |out| is set to be a REJ message and
73 // an error code is returned.
74 //
75 // client_hello: the incoming client hello message.
76 // 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
78 // validate source-address tokens.
79 // now_since_epoch: the current time, as a delta since the unix epoch,
80 // which is used to validate client nonces.
81 // rand: an entropy source
82 // 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
84 // contain the state of the connection.
85 // out: the resulting handshake message (either REJ or SHLO)
86 // error_details: used to store a string describing any error.
87 QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
88 QuicGuid guid,
89 const IPEndPoint& client_ip,
90 QuicTime::Delta now_since_epoch,
91 QuicRandom* rand,
92 QuicCryptoNegotiatedParameters* params,
93 CryptoHandshakeMessage* out,
94 std::string* error_details) const;
95
96 // SetProofSource installs |proof_source| as the ProofSource for handshakes.
97 // This object takes ownership of |proof_source|.
98 void SetProofSource(ProofSource* proof_source);
99
100 private:
101 friend class test::QuicCryptoServerConfigPeer;
102
103 // Config represents a server config: a collection of preferences and
104 // Diffie-Hellman public values.
105 struct Config : public QuicCryptoConfig {
106 Config();
107 ~Config();
108
109 // serialized contains the bytes of this server config, suitable for sending
110 // on the wire.
111 std::string serialized;
112 // id contains the SCID of this server config.
113 std::string id;
114 // orbit contains the orbit value for this config: an opaque identifier
115 // used to identify clusters of server frontends.
116 unsigned char orbit[kOrbitSize];
117
118 // key_exchanges contains key exchange objects with the private keys
119 // already loaded. The values correspond, one-to-one, with the tags in
120 // |kexs| from the parent class.
121 std::vector<KeyExchange*> key_exchanges;
122
123 // tag_value_map contains the raw key/value pairs for the config.
124 CryptoTagValueMap tag_value_map;
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(Config);
128 };
129
130 // NewSourceAddressToken returns a fresh source address token for the given
131 // IP address.
132 std::string NewSourceAddressToken(const IPEndPoint& ip,
133 QuicRandom* rand,
134 QuicTime::Delta now_since_epoch) const;
135
136 // 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
138 // current time is |now|.
139 bool ValidateSourceAddressToken(base::StringPiece token,
140 const IPEndPoint& ip,
141 QuicTime::Delta now_since_epoch) const;
142
143 std::map<ServerConfigID, Config*> configs_;
144
145 ServerConfigID active_config_;
146
147 mutable base::Lock strike_register_lock_;
148 // strike_register_ contains a data structure that keeps track of previously
149 // observed client nonces in order to prevent replay attacks.
150 mutable scoped_ptr<StrikeRegister> strike_register_;
151
152 // These members are used to encrypt and decrypt the source address tokens
153 // that we receive from and send to clients.
154 scoped_ptr<QuicEncrypter> source_address_token_encrypter_;
155 scoped_ptr<QuicDecrypter> source_address_token_decrypter_;
156
157 // proof_source_ contains an object that can provide certificate chains and
158 // signatures.
159 scoped_ptr<ProofSource> proof_source_;
160 };
161
162 } // namespace net
163
164 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698