blob: 1e3d66810b990842dc640d33eeb3857ff15fc61e [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 QUICHE_QUIC_CORE_CRYPTO_CRYPTO_HANDSHAKE_H_
6#define QUICHE_QUIC_CORE_CRYPTO_CRYPTO_HANDSHAKE_H_
7
8#include <memory>
9#include <vector>
10
11#include "base/macros.h"
12#include "net/third_party/quiche/src/quic/core/quic_packets.h"
13#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
14#include "net/third_party/quiche/src/quic/platform/api/quic_string.h"
15
16namespace quic {
17
18class CommonCertSets;
19class KeyExchange;
20class QuicDecrypter;
21class QuicEncrypter;
22
23// HandshakeFailureReason enum values are uploaded to UMA, they cannot be
24// changed.
25enum HandshakeFailureReason {
26 HANDSHAKE_OK = 0,
27
28 // Failure reasons for an invalid client nonce in CHLO.
29 //
30 // The default error value for nonce verification failures from strike
31 // register (covers old strike registers and unknown failures).
32 CLIENT_NONCE_UNKNOWN_FAILURE = 1,
33 // Client nonce had incorrect length.
34 CLIENT_NONCE_INVALID_FAILURE = 2,
35 // Client nonce is not unique.
36 CLIENT_NONCE_NOT_UNIQUE_FAILURE = 3,
37 // Client orbit is invalid or incorrect.
38 CLIENT_NONCE_INVALID_ORBIT_FAILURE = 4,
39 // Client nonce's timestamp is not in the strike register's valid time range.
40 CLIENT_NONCE_INVALID_TIME_FAILURE = 5,
41 // Strike register's RPC call timed out, client nonce couldn't be verified.
42 CLIENT_NONCE_STRIKE_REGISTER_TIMEOUT = 6,
43 // Strike register is down, client nonce couldn't be verified.
44 CLIENT_NONCE_STRIKE_REGISTER_FAILURE = 7,
45
46 // Failure reasons for an invalid server nonce in CHLO.
47 //
48 // Unbox of server nonce failed.
49 SERVER_NONCE_DECRYPTION_FAILURE = 8,
50 // Decrypted server nonce had incorrect length.
51 SERVER_NONCE_INVALID_FAILURE = 9,
52 // Server nonce is not unique.
53 SERVER_NONCE_NOT_UNIQUE_FAILURE = 10,
54 // Server nonce's timestamp is not in the strike register's valid time range.
55 SERVER_NONCE_INVALID_TIME_FAILURE = 11,
56 // The server requires handshake confirmation.
57 SERVER_NONCE_REQUIRED_FAILURE = 20,
58
59 // Failure reasons for an invalid server config in CHLO.
60 //
61 // Missing Server config id (kSCID) tag.
62 SERVER_CONFIG_INCHOATE_HELLO_FAILURE = 12,
63 // Couldn't find the Server config id (kSCID).
64 SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE = 13,
65
66 // Failure reasons for an invalid source-address token.
67 //
68 // Missing Source-address token (kSourceAddressTokenTag) tag.
69 SOURCE_ADDRESS_TOKEN_INVALID_FAILURE = 14,
70 // Unbox of Source-address token failed.
71 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE = 15,
72 // Couldn't parse the unbox'ed Source-address token.
73 SOURCE_ADDRESS_TOKEN_PARSE_FAILURE = 16,
74 // Source-address token is for a different IP address.
75 SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE = 17,
76 // The source-address token has a timestamp in the future.
77 SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE = 18,
78 // The source-address token has expired.
79 SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE = 19,
80
81 // The expected leaf certificate hash could not be validated.
82 INVALID_EXPECTED_LEAF_CERTIFICATE = 21,
83
84 MAX_FAILURE_REASON = 22,
85};
86
87// These errors will be packed into an uint32_t and we don't want to set the
88// most significant bit, which may be misinterpreted as the sign bit.
89static_assert(MAX_FAILURE_REASON <= 32, "failure reason out of sync");
90
91// A CrypterPair contains the encrypter and decrypter for an encryption level.
92struct QUIC_EXPORT_PRIVATE CrypterPair {
93 CrypterPair();
94 ~CrypterPair();
95 std::unique_ptr<QuicEncrypter> encrypter;
96 std::unique_ptr<QuicDecrypter> decrypter;
97};
98
99// Parameters negotiated by the crypto handshake.
100struct QUIC_EXPORT_PRIVATE QuicCryptoNegotiatedParameters
101 : public QuicReferenceCounted {
102 // Initializes the members to 0 or empty values.
103 QuicCryptoNegotiatedParameters();
104
105 QuicTag key_exchange;
106 QuicTag aead;
vasilvvc48c8712019-03-11 13:38:16 -0700107 std::string initial_premaster_secret;
108 std::string forward_secure_premaster_secret;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500109 // initial_subkey_secret is used as the PRK input to the HKDF used when
110 // performing key extraction that needs to happen before forward-secure keys
111 // are available.
vasilvvc48c8712019-03-11 13:38:16 -0700112 std::string initial_subkey_secret;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500113 // subkey_secret is used as the PRK input to the HKDF used for key extraction.
vasilvvc48c8712019-03-11 13:38:16 -0700114 std::string subkey_secret;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500115 CrypterPair initial_crypters;
116 CrypterPair forward_secure_crypters;
117 // Normalized SNI: converted to lower case and trailing '.' removed.
vasilvvc48c8712019-03-11 13:38:16 -0700118 std::string sni;
119 std::string client_nonce;
120 std::string server_nonce;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500121 // hkdf_input_suffix contains the HKDF input following the label: the
122 // ConnectionId, client hello and server config. This is only populated in the
123 // client because only the client needs to derive the forward secure keys at a
124 // later time from the initial keys.
vasilvvc48c8712019-03-11 13:38:16 -0700125 std::string hkdf_input_suffix;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500126 // cached_certs contains the cached certificates that a client used when
127 // sending a client hello.
vasilvvc48c8712019-03-11 13:38:16 -0700128 std::vector<std::string> cached_certs;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500129 // client_key_exchange is used by clients to store the ephemeral KeyExchange
130 // for the connection.
131 std::unique_ptr<KeyExchange> client_key_exchange;
132 // channel_id is set by servers to a ChannelID key when the client correctly
133 // proves possession of the corresponding private key. It consists of 32
134 // bytes of x coordinate, followed by 32 bytes of y coordinate. Both values
135 // are big-endian and the pair is a P-256 public key.
vasilvvc48c8712019-03-11 13:38:16 -0700136 std::string channel_id;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500137 QuicTag token_binding_key_param;
138
139 // Used when generating proof signature when sending server config updates.
140
141 // Used to generate cert chain when sending server config updates.
vasilvvc48c8712019-03-11 13:38:16 -0700142 std::string client_common_set_hashes;
143 std::string client_cached_cert_hashes;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500144
145 // Default to false; set to true if the client indicates that it supports sct
146 // by sending CSCT tag with an empty value in client hello.
147 bool sct_supported_by_client;
148
149 protected:
150 ~QuicCryptoNegotiatedParameters() override;
151};
152
153// QuicCryptoConfig contains common configuration between clients and servers.
154class QUIC_EXPORT_PRIVATE QuicCryptoConfig {
155 public:
156 // kInitialLabel is a constant that is used when deriving the initial
157 // (non-forward secure) keys for the connection in order to tie the resulting
158 // key to this protocol.
159 static const char kInitialLabel[];
160
161 // kCETVLabel is a constant that is used when deriving the keys for the
162 // encrypted tag/value block in the client hello.
163 static const char kCETVLabel[];
164
165 // kForwardSecureLabel is a constant that is used when deriving the forward
166 // secure keys for the connection in order to tie the resulting key to this
167 // protocol.
168 static const char kForwardSecureLabel[];
169
170 QuicCryptoConfig();
171 QuicCryptoConfig(const QuicCryptoConfig&) = delete;
172 QuicCryptoConfig& operator=(const QuicCryptoConfig&) = delete;
173 ~QuicCryptoConfig();
174
175 // Key exchange methods. The following two members' values correspond by
176 // index.
177 QuicTagVector kexs;
178 // Authenticated encryption with associated data (AEAD) algorithms.
179 QuicTagVector aead;
180
181 // Supported Token Binding key parameters that can be negotiated in the client
182 // hello.
183 QuicTagVector tb_key_params;
184
185 const CommonCertSets* common_cert_sets;
186};
187
188} // namespace quic
189
190#endif // QUICHE_QUIC_CORE_CRYPTO_CRYPTO_HANDSHAKE_H_