Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / quic / crypto / crypto_handshake.h
blobc5c90320a4c5b39f6d85654da1d715a2bd7b0a4b
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.
5 #ifndef NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_
6 #define NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "net/base/net_export.h"
13 #include "net/quic/quic_protocol.h"
15 namespace net {
17 class CommonCertSets;
18 class KeyExchange;
19 class QuicDecrypter;
20 class QuicEncrypter;
22 // HandshakeFailureReason enum values are uploaded to UMA, they cannot be
23 // changed.
24 enum HandshakeFailureReason {
25 HANDSHAKE_OK = 0,
27 // Failure reasons for an invalid client nonce in CHLO.
29 // Client nonce had incorrect length.
30 CLIENT_NONCE_INVALID_FAILURE = 1,
31 // Client nonce is not unique.
32 CLIENT_NONCE_NOT_UNIQUE_FAILURE = 2,
33 // Client orbit is invalid or incorrect.
34 CLIENT_NONCE_INVALID_ORBIT_FAILURE = 3,
35 // Client nonce's timestamp is not in the strike register's valid time range.
36 CLIENT_NONCE_INVALID_TIME_FAILURE = 4,
37 // Client nonce verification has failed because strike register is down.
38 CLIENT_NONCE_NO_STRIKE_REGISTER_FAILURE = 5,
40 // Failure reasons for an invalid server nonce in CHLO.
42 // Unbox of server nonce failed.
43 SERVER_NONCE_DECRYPTION_FAILURE = 6,
44 // Decrypted server nonce had incorrect length.
45 SERVER_NONCE_INVALID_FAILURE = 7,
46 // Server nonce is not unique.
47 SERVER_NONCE_NOT_UNIQUE_FAILURE = 8,
48 // Server nonce's timestamp is not in the strike register's valid time range.
49 SERVER_NONCE_INVALID_TIME_FAILURE = 9,
51 // Failure reasons for an invalid server config in CHLO.
53 // Missing Server config id (kSCID) tag.
54 SERVER_CONFIG_INCHOATE_HELLO_FAILURE = 10,
55 // Couldn't find the Server config id (kSCID).
56 SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE = 11,
58 // Failure reasons for an invalid source-address token.
60 // Missing Source-address token (kSourceAddressTokenTag) tag.
61 SOURCE_ADDRESS_TOKEN_INVALID_FAILURE = 12,
62 // Unbox of Source-address token failed.
63 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE = 13,
64 // Couldn't parse the unbox'ed Source-address token.
65 SOURCE_ADDRESS_TOKEN_PARSE_FAILURE = 14,
66 // Source-address token is for a different IP address.
67 SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE = 15,
68 // The source-address token has a timestamp in the future.
69 SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE = 16,
70 // The source-address token has expired.
71 SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE = 17,
73 MAX_FAILURE_REASON,
76 // These errors will be packed into an uint32 and we don't want to set the most
77 // significant bit, which may be misinterpreted as the sign bit.
78 COMPILE_ASSERT(MAX_FAILURE_REASON <= 32, failure_reason_out_of_sync);
80 // A CrypterPair contains the encrypter and decrypter for an encryption level.
81 struct NET_EXPORT_PRIVATE CrypterPair {
82 CrypterPair();
83 ~CrypterPair();
84 scoped_ptr<QuicEncrypter> encrypter;
85 scoped_ptr<QuicDecrypter> decrypter;
88 // Parameters negotiated by the crypto handshake.
89 struct NET_EXPORT_PRIVATE QuicCryptoNegotiatedParameters {
90 // Initializes the members to 0 or empty values.
91 QuicCryptoNegotiatedParameters();
92 ~QuicCryptoNegotiatedParameters();
94 QuicTag key_exchange;
95 QuicTag aead;
96 std::string initial_premaster_secret;
97 std::string forward_secure_premaster_secret;
98 CrypterPair initial_crypters;
99 CrypterPair forward_secure_crypters;
100 // Normalized SNI: converted to lower case and trailing '.' removed.
101 std::string sni;
102 std::string client_nonce;
103 std::string server_nonce;
104 // hkdf_input_suffix contains the HKDF input following the label: the
105 // ConnectionId, client hello and server config. This is only populated in the
106 // client because only the client needs to derive the forward secure keys at a
107 // later time from the initial keys.
108 std::string hkdf_input_suffix;
109 // cached_certs contains the cached certificates that a client used when
110 // sending a client hello.
111 std::vector<std::string> cached_certs;
112 // client_key_exchange is used by clients to store the ephemeral KeyExchange
113 // for the connection.
114 scoped_ptr<KeyExchange> client_key_exchange;
115 // channel_id is set by servers to a ChannelID key when the client correctly
116 // proves possession of the corresponding private key. It consists of 32
117 // bytes of x coordinate, followed by 32 bytes of y coordinate. Both values
118 // are big-endian and the pair is a P-256 public key.
119 std::string channel_id;
122 // QuicCryptoConfig contains common configuration between clients and servers.
123 class NET_EXPORT_PRIVATE QuicCryptoConfig {
124 public:
125 // kInitialLabel is a constant that is used when deriving the initial
126 // (non-forward secure) keys for the connection in order to tie the resulting
127 // key to this protocol.
128 static const char kInitialLabel[];
130 // kCETVLabel is a constant that is used when deriving the keys for the
131 // encrypted tag/value block in the client hello.
132 static const char kCETVLabel[];
134 // kForwardSecureLabel is a constant that is used when deriving the forward
135 // secure keys for the connection in order to tie the resulting key to this
136 // protocol.
137 static const char kForwardSecureLabel[];
139 QuicCryptoConfig();
140 ~QuicCryptoConfig();
142 // Key exchange methods. The following two members' values correspond by
143 // index.
144 QuicTagVector kexs;
145 // Authenticated encryption with associated data (AEAD) algorithms.
146 QuicTagVector aead;
148 const CommonCertSets* common_cert_sets;
150 private:
151 DISALLOW_COPY_AND_ASSIGN(QuicCryptoConfig);
154 } // namespace net
156 #endif // NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_