50#include "trunnel/congestion_control.h"
51#include "trunnel/extension.h"
53static const uint8_t NTOR3_CIRC_VERIFICATION[] =
"circuit extend";
54static const size_t NTOR3_CIRC_VERIFICATION_LEN = 14;
56#define NTOR3_VERIFICATION_ARGS \
57 NTOR3_CIRC_VERIFICATION, NTOR3_CIRC_VERIFICATION_LEN
66 if (!get_master_identity_key())
85 crypto_pk_free(keys->onion_key);
86 crypto_pk_free(keys->last_onion_key);
87 ntor_key_map_free(keys->curve25519_key_map);
99 case ONION_HANDSHAKE_TYPE_TAP:
101 case ONION_HANDSHAKE_TYPE_FAST:
102 fast_handshake_state_free(state->u.fast);
103 state->u.fast = NULL;
105 case ONION_HANDSHAKE_TYPE_NTOR:
106 ntor_handshake_state_free(state->u.ntor);
107 state->u.ntor = NULL;
109 case ONION_HANDSHAKE_TYPE_NTOR_V3:
110 ntor3_handshake_state_free(state->u.ntor3);
115 log_warn(
LD_BUG,
"called with unknown handshake state type %d",
132 uint8_t *onion_skin_out,
133 size_t onion_skin_out_maxlen)
138 case ONION_HANDSHAKE_TYPE_TAP:
140 case ONION_HANDSHAKE_TYPE_FAST:
146 case ONION_HANDSHAKE_TYPE_NTOR:
149 if (!extend_info_supports_ntor(node))
159 case ONION_HANDSHAKE_TYPE_NTOR_V3:
168 uint8_t *onion_skin = NULL;
169 size_t onion_skin_len = 0;
173 NTOR3_VERIFICATION_ARGS,
176 &onion_skin, &onion_skin_len);
181 if (onion_skin_len > onion_skin_out_maxlen) {
185 memcpy(onion_skin_out, onion_skin, onion_skin_len);
187 r = (int) onion_skin_len;
193 log_warn(
LD_BUG,
"called with unknown handshake state type %d", type);
200 state_out->
tag = (uint16_t) type;
218 size_t param_request_len,
221 uint8_t **resp_msg_out,
222 size_t *resp_msg_len_out)
236 resp_msg_out, resp_msg_len_out);
252#define MAX_KEYS_TMP_LEN 128
263 const uint8_t *onion_skin,
size_t onionskin_len,
267 size_t reply_out_maxlen,
268 uint8_t *keys_out,
size_t keys_out_len,
269 uint8_t *rend_nonce_out,
273 memset(params_out, 0,
sizeof(*params_out));
276 case ONION_HANDSHAKE_TYPE_TAP:
278 case ONION_HANDSHAKE_TYPE_FAST:
279 if (reply_out_maxlen < CREATED_FAST_LEN)
281 if (onionskin_len != CREATE_FAST_LEN)
285 r = CREATED_FAST_LEN;
288 case ONION_HANDSHAKE_TYPE_NTOR:
294 size_t keys_tmp_len = keys_out_len +
DIGEST_LEN;
296 uint8_t keys_tmp[MAX_KEYS_TMP_LEN];
299 onion_skin, keys->curve25519_key_map,
302 reply_out, keys_tmp, keys_tmp_len)<0) {
307 memcpy(keys_out, keys_tmp, keys_out_len);
308 memcpy(rend_nonce_out, keys_tmp+keys_out_len,
DIGEST_LEN);
309 memwipe(keys_tmp, 0,
sizeof(keys_tmp));
313 case ONION_HANDSHAKE_TYPE_NTOR_V3: {
314 size_t keys_tmp_len = keys_out_len +
DIGEST_LEN;
316 uint8_t keys_tmp[MAX_KEYS_TMP_LEN];
317 uint8_t *client_msg = NULL;
318 size_t client_msg_len = 0;
319 uint8_t *reply_msg = NULL;
320 size_t reply_msg_len = 0;
325 keys->curve25519_key_map,
327 &keys->my_ed_identity,
328 onion_skin, onionskin_len,
329 NTOR3_VERIFICATION_ARGS,
330 &client_msg, &client_msg_len,
340 &reply_msg_len) < 0) {
341 ntor3_server_handshake_state_free(state);
347 uint8_t *server_handshake = NULL;
348 size_t server_handshake_len = 0;
351 NTOR3_VERIFICATION_ARGS,
352 reply_msg, reply_msg_len,
353 &server_handshake, &server_handshake_len,
354 keys_tmp, keys_tmp_len) < 0) {
356 ntor3_server_handshake_state_free(state);
361 if (server_handshake_len > reply_out_maxlen) {
363 ntor3_server_handshake_state_free(state);
367 memcpy(keys_out, keys_tmp, keys_out_len);
368 memcpy(rend_nonce_out, keys_tmp+keys_out_len,
DIGEST_LEN);
369 memcpy(reply_out, server_handshake, server_handshake_len);
370 memwipe(keys_tmp, 0, keys_tmp_len);
371 memwipe(server_handshake, 0, server_handshake_len);
373 ntor3_server_handshake_state_free(state);
375 r = (int) server_handshake_len;
381 log_warn(
LD_BUG,
"called with unknown handshake state type %d", type);
399 size_t param_response_len,
439 const uint8_t *reply,
size_t reply_len,
440 uint8_t *keys_out,
size_t keys_out_len,
441 uint8_t *rend_authenticator_out,
443 const char **msg_out)
445 if (handshake_state->
tag != type)
448 memset(params_out, 0,
sizeof(*params_out));
451 case ONION_HANDSHAKE_TYPE_TAP:
453 case ONION_HANDSHAKE_TYPE_FAST:
454 if (reply_len != CREATED_FAST_LEN) {
456 *msg_out =
"TAP reply was not of the correct length.";
460 keys_out, keys_out_len, msg_out) < 0)
465 case ONION_HANDSHAKE_TYPE_NTOR:
468 *msg_out =
"ntor reply was not of the correct length.";
472 size_t keys_tmp_len = keys_out_len +
DIGEST_LEN;
473 uint8_t *keys_tmp = tor_malloc(keys_tmp_len);
476 keys_tmp, keys_tmp_len, msg_out) < 0) {
480 memcpy(keys_out, keys_tmp, keys_out_len);
481 memcpy(rend_authenticator_out, keys_tmp + keys_out_len,
DIGEST_LEN);
482 memwipe(keys_tmp, 0, keys_tmp_len);
486 case ONION_HANDSHAKE_TYPE_NTOR_V3: {
487 size_t keys_tmp_len = keys_out_len +
DIGEST_LEN;
488 uint8_t *keys_tmp = tor_malloc(keys_tmp_len);
489 uint8_t *server_msg = NULL;
490 size_t server_msg_len = 0;
492 handshake_state->u.ntor3,
494 NTOR3_VERIFICATION_ARGS,
495 keys_tmp, keys_tmp_len,
496 &server_msg, &server_msg_len);
512 memcpy(keys_out, keys_tmp, keys_out_len);
513 memcpy(rend_authenticator_out, keys_tmp + keys_out_len,
DIGEST_LEN);
514 memwipe(keys_tmp, 0, keys_tmp_len);
520 log_warn(
LD_BUG,
"called with unknown handshake state type %d", type);
int client_circ_negotiation_message(const extend_info_t *ei, uint8_t **msg_out, size_t *msg_len_out)
Header file for circuitbuild.c.
int congestion_control_build_ext_response(const circuit_params_t *our_params, const circuit_params_t *circ_params, uint8_t **msg_out, size_t *msg_len_out)
int congestion_control_parse_ext_request(const uint8_t *msg, const size_t msg_len)
int congestion_control_parse_ext_response(const uint8_t *msg, const size_t msg_len, circuit_params_t *params_out)
bool congestion_control_enabled(void)
Public APIs for congestion control.
Path structures for origin circuits.
int curve25519_keypair_generate(curve25519_keypair_t *keypair_out, int extra_strong)
void ed25519_pubkey_copy(ed25519_public_key_t *dest, const ed25519_public_key_t *src)
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
int extend_info_supports_ntor_v3(const extend_info_t *ei)
Header for core/or/extendinfo.c.
int onion_skin_client_handshake(int type, const onion_handshake_state_t *handshake_state, const uint8_t *reply, size_t reply_len, uint8_t *keys_out, size_t keys_out_len, uint8_t *rend_authenticator_out, circuit_params_t *params_out, const char **msg_out)
static int negotiate_v3_ntor_client_circ_params(const uint8_t *param_response_msg, size_t param_response_len, circuit_params_t *params_out)
int onion_skin_create(int type, const extend_info_t *node, onion_handshake_state_t *state_out, uint8_t *onion_skin_out, size_t onion_skin_out_maxlen)
int onion_skin_server_handshake(int type, const uint8_t *onion_skin, size_t onionskin_len, const server_onion_keys_t *keys, const circuit_params_t *our_ns_params, uint8_t *reply_out, size_t reply_out_maxlen, uint8_t *keys_out, size_t keys_out_len, uint8_t *rend_nonce_out, circuit_params_t *params_out)
void server_onion_keys_free_(server_onion_keys_t *keys)
void onion_handshake_state_release(onion_handshake_state_t *state)
static int negotiate_v3_ntor_server_circ_params(const uint8_t *param_request_msg, size_t param_request_len, const circuit_params_t *our_ns_params, circuit_params_t *params_out, uint8_t **resp_msg_out, size_t *resp_msg_len_out)
server_onion_keys_t * server_onion_keys_new(void)
Header file for onion_crypto.c.
int fast_client_handshake(const fast_handshake_state_t *handshake_state, const uint8_t *handshake_reply_out, uint8_t *key_out, size_t key_out_len, const char **msg_out)
int fast_server_handshake(const uint8_t *key_in, uint8_t *handshake_reply_out, uint8_t *key_out, size_t key_out_len)
int fast_onionskin_create(fast_handshake_state_t **handshake_state_out, uint8_t *handshake_out)
Header file for onion_fast.c.
int onion_skin_ntor_client_handshake(const ntor_handshake_state_t *handshake_state, const uint8_t *handshake_reply, uint8_t *key_out, size_t key_out_len, const char **msg_out)
int onion_skin_ntor_server_handshake(const uint8_t *onion_skin, const di_digest256_map_t *private_keys, const curve25519_keypair_t *junk_keys, const uint8_t *my_node_id, uint8_t *handshake_reply_out, uint8_t *key_out, size_t key_out_len)
int onion_skin_ntor_create(const uint8_t *router_id, const curve25519_public_key_t *router_key, ntor_handshake_state_t **handshake_state_out, uint8_t *onion_skin_out)
#define NTOR_ONIONSKIN_LEN
int onion_ntor3_client_handshake(const ntor3_handshake_state_t *handshake_state, const uint8_t *handshake_reply, size_t reply_len, const uint8_t *verification, size_t verification_len, uint8_t *keys_out, size_t keys_out_len, uint8_t **message_out, size_t *message_len_out)
int onion_skin_ntor3_server_handshake_part1(const di_digest256_map_t *private_keys, const curve25519_keypair_t *junk_key, const ed25519_public_key_t *my_id, const uint8_t *client_handshake, size_t client_handshake_len, const uint8_t *verification, size_t verification_len, uint8_t **client_message_out, size_t *client_message_len_out, ntor3_server_handshake_state_t **state_out)
int onion_skin_ntor3_create(const ed25519_public_key_t *relay_id, const curve25519_public_key_t *relay_key, const uint8_t *verification, const size_t verification_len, const uint8_t *message, const size_t message_len, ntor3_handshake_state_t **handshake_state_out, uint8_t **onion_skin_out, size_t *onion_skin_len_out)
int onion_skin_ntor3_server_handshake_part2(const ntor3_server_handshake_state_t *state, const uint8_t *verification, size_t verification_len, const uint8_t *server_message, size_t server_message_len, uint8_t **handshake_out, size_t *handshake_len_out, uint8_t *keys_out, size_t keys_out_len)
Header for core/crypto/onion_ntor_v3.c.
struct ntor3_server_handshake_state_t ntor3_server_handshake_state_t
Master header file for Tor-specific functionality.
const uint8_t * router_get_my_id_digest(void)
void dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last)
di_digest256_map_t * construct_ntor_key_map(void)
Header file for router.c.
ed25519_public_key_t ed_identity
char identity_digest[DIGEST_LEN]
curve25519_public_key_t curve25519_onion_key
#define tor_fragile_assert()