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