42 const std::string& hostname,
49 std::string identity_hint =
"";
54 identity_hint = reader.
get_string(2, 0, 65535);
57 const std::string psk_identity =
58 creds.
psk_identity(
"tls-client", hostname, identity_hint);
64 std::vector<uint8_t> zeros(psk.
length());
78 std::string identity_hint = reader.
get_string(2, 0, 65535);
80 const std::string psk_identity =
81 creds.
psk_identity(
"tls-client", hostname, identity_hint);
85 psk = creds.
psk(
"tls-client", hostname, psk_identity);
91 const std::vector<uint8_t> modulus = reader.
get_range<uint8_t>(2, 1, 65535);
92 const std::vector<uint8_t> generator = reader.
get_range<uint8_t>(2, 1, 65535);
93 const std::vector<uint8_t> peer_public_value = reader.
get_range<uint8_t>(2, 1, 65535);
98 const std::pair<secure_vector<uint8_t>, std::vector<uint8_t>> dh_result =
102 m_pre_master = dh_result.first;
114 const uint8_t curve_type = reader.
get_byte();
119 const std::vector<uint8_t> peer_public_value = reader.
get_range<uint8_t>(1, 1, 255);
124 "Server sent ECC curve prohibited by policy");
131 std::to_string(
static_cast<uint16_t
>(curve_id)));
133 const std::pair<secure_vector<uint8_t>, std::vector<uint8_t>> ecdh_result =
139 m_pre_master = ecdh_result.first;
149#if defined(BOTAN_HAS_SRP6)
154 std::vector<uint8_t> salt = reader.get_range<uint8_t>(1, 1, 255);
159 const std::string srp_identifier =
162 const std::string srp_password =
163 creds.
srp_password(
"tls-client", hostname, srp_identifier);
165 std::pair<BigInt, SymmetricKey> srp_vals =
175 m_pre_master = srp_vals.second.bits_of();
179#if defined(BOTAN_HAS_CECPQ1)
182 const std::vector<uint8_t> cecpq1_offer = reader.get_range<uint8_t>(2, 1, 65535);
189 CECPQ1_accept(shared_secret.data(), newhope_accept.data(), cecpq1_offer.data(), rng);
191 m_pre_master = shared_secret;
196 throw Internal_Error(
"Client_Key_Exchange: Unknown key exchange method was negotiated");
199 reader.assert_done();
206 throw Unexpected_Message(
"No server kex message, but negotiated a key exchange that required it");
215 rng.random_vec(m_pre_master, 48);
221 const std::vector<uint8_t> encrypted_key = encryptor.encrypt(m_pre_master, rng);
227 "Expected a RSA key in server cert but got " +
231 state.hash().update(io.send(*
this));
237Client_Key_Exchange::Client_Key_Exchange(
const std::vector<uint8_t>& contents,
246 if(kex_algo == Kex_Algo::STATIC_RSA)
249 "RSA key exchange negotiated so server sent a certificate");
251 if(!server_rsa_kex_key)
252 throw Internal_Error(
"Expected RSA kex but no server kex key set");
258 const std::vector<uint8_t> encrypted_pre_master = reader.
get_range<uint8_t>(2, 0, 65535);
263 const uint8_t client_major = state.
client_hello()->version().major_version();
264 const uint8_t client_minor = state.
client_hello()->version().minor_version();
272 const size_t expected_plaintext_size = 48;
273 const size_t expected_content_size = 2;
274 const uint8_t expected_content_bytes[expected_content_size] = { client_major, client_minor };
275 const uint8_t expected_content_pos[expected_content_size] = { 0, 1 };
279 encrypted_pre_master.size(),
280 expected_plaintext_size,
282 expected_content_bytes,
283 expected_content_pos,
284 expected_content_size);
294 const std::string psk_identity = reader.
get_string(2, 0, 65535);
296 psk = creds.
psk(
"tls-server",
306 "No PSK for identifier " + psk_identity);
310 if(kex_algo == Kex_Algo::PSK)
312 std::vector<uint8_t> zeros(psk.
length());
316#if defined(BOTAN_HAS_SRP6)
317 else if(kex_algo == Kex_Algo::SRP_SHA)
324#if defined(BOTAN_HAS_CECPQ1)
325 else if(kex_algo == Kex_Algo::CECPQ1)
329 const std::vector<uint8_t> cecpq1_accept = reader.
get_range<uint8_t>(2, 0, 65535);
334 CECPQ1_finish(m_pre_master.data(), cecpq1_offer, cecpq1_accept.data());
337 else if(kex_algo == Kex_Algo::DH ||
338 kex_algo == Kex_Algo::DHE_PSK ||
339 kex_algo == Kex_Algo::ECDH ||
340 kex_algo == Kex_Algo::ECDHE_PSK)
351 std::vector<uint8_t> client_pubkey;
355 client_pubkey = reader.
get_range<uint8_t>(2, 0, 65535);
359 client_pubkey = reader.
get_range<uint8_t>(1, 1, 255);
371 if(kex_algo == Kex_Algo::DHE_PSK ||
372 kex_algo == Kex_Algo::ECDHE_PSK)
378 m_pre_master = shared_secret;
384 catch(std::exception&)
398 throw Internal_Error(
"Client_Key_Exchange: Unknown key exchange negotiated");
std::pair< BigInt, SymmetricKey > srp6_client_agree(const std::string &identifier, const std::string &password, const std::string &group_id, const std::string &hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)