2010-07-23 20:38:25 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 21:13:17 +01:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2010-07-23 20:38:25 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file onion.h
|
|
|
|
* \brief Header file for onion.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_ONION_H
|
|
|
|
#define TOR_ONION_H
|
2010-07-23 20:38:25 +02:00
|
|
|
|
2012-12-06 04:34:49 +01:00
|
|
|
struct create_cell_t;
|
|
|
|
int onion_pending_add(or_circuit_t *circ, struct create_cell_t *onionskin);
|
|
|
|
or_circuit_t *onion_next_task(struct create_cell_t **onionskin_out);
|
2013-09-01 10:40:05 +02:00
|
|
|
int onion_num_pending(uint16_t handshake_type);
|
2010-07-23 20:38:25 +02:00
|
|
|
void onion_pending_remove(or_circuit_t *circ);
|
|
|
|
void clear_pending_onions(void);
|
|
|
|
|
2012-12-05 03:27:07 +01:00
|
|
|
typedef struct server_onion_keys_t {
|
|
|
|
uint8_t my_identity[DIGEST_LEN];
|
|
|
|
crypto_pk_t *onion_key;
|
|
|
|
crypto_pk_t *last_onion_key;
|
|
|
|
di_digest256_map_t *curve25519_key_map;
|
2012-12-07 19:40:21 +01:00
|
|
|
curve25519_keypair_t *junk_keypair;
|
2012-12-05 03:27:07 +01:00
|
|
|
} server_onion_keys_t;
|
|
|
|
|
|
|
|
#define MAX_ONIONSKIN_CHALLENGE_LEN 255
|
|
|
|
#define MAX_ONIONSKIN_REPLY_LEN 255
|
|
|
|
|
2013-10-02 18:32:09 +02:00
|
|
|
server_onion_keys_t *server_onion_keys_new(void);
|
2017-11-21 15:37:47 +01:00
|
|
|
void server_onion_keys_free_(server_onion_keys_t *keys);
|
2017-12-07 16:52:55 +01:00
|
|
|
#define server_onion_keys_free(keys) \
|
|
|
|
FREE_AND_NULL(server_onion_keys_t, server_onion_keys_free_, (keys))
|
2012-12-05 03:27:07 +01:00
|
|
|
|
|
|
|
void onion_handshake_state_release(onion_handshake_state_t *state);
|
|
|
|
|
|
|
|
int onion_skin_create(int type,
|
|
|
|
const extend_info_t *node,
|
|
|
|
onion_handshake_state_t *state_out,
|
|
|
|
uint8_t *onion_skin_out);
|
|
|
|
int onion_skin_server_handshake(int type,
|
2012-12-06 04:34:49 +01:00
|
|
|
const uint8_t *onion_skin, size_t onionskin_len,
|
2012-12-05 03:27:07 +01:00
|
|
|
const server_onion_keys_t *keys,
|
|
|
|
uint8_t *reply_out,
|
2012-12-06 04:34:49 +01:00
|
|
|
uint8_t *keys_out, size_t key_out_len,
|
|
|
|
uint8_t *rend_nonce_out);
|
2012-12-05 03:27:07 +01:00
|
|
|
int onion_skin_client_handshake(int type,
|
|
|
|
const onion_handshake_state_t *handshake_state,
|
2012-12-06 04:34:49 +01:00
|
|
|
const uint8_t *reply, size_t reply_len,
|
2012-12-05 03:27:07 +01:00
|
|
|
uint8_t *keys_out, size_t key_out_len,
|
2014-10-16 19:26:42 +02:00
|
|
|
uint8_t *rend_authenticator_out,
|
|
|
|
const char **msg_out);
|
2012-12-05 03:27:07 +01:00
|
|
|
|
2012-12-05 22:47:22 +01:00
|
|
|
/** A parsed CREATE, CREATE_FAST, or CREATE2 cell. */
|
|
|
|
typedef struct create_cell_t {
|
|
|
|
/** The cell command. One of CREATE{,_FAST,2} */
|
|
|
|
uint8_t cell_type;
|
|
|
|
/** One of the ONION_HANDSHAKE_TYPE_* values */
|
|
|
|
uint16_t handshake_type;
|
|
|
|
/** The number of bytes used in <b>onionskin</b>. */
|
|
|
|
uint16_t handshake_len;
|
|
|
|
/** The client-side message for the circuit creation handshake. */
|
|
|
|
uint8_t onionskin[CELL_PAYLOAD_SIZE - 4];
|
|
|
|
} create_cell_t;
|
|
|
|
|
|
|
|
/** A parsed CREATED, CREATED_FAST, or CREATED2 cell. */
|
|
|
|
typedef struct created_cell_t {
|
|
|
|
/** The cell command. One of CREATED{,_FAST,2} */
|
|
|
|
uint8_t cell_type;
|
|
|
|
/** The number of bytes used in <b>reply</b>. */
|
|
|
|
uint16_t handshake_len;
|
|
|
|
/** The server-side message for the circuit creation handshake. */
|
|
|
|
uint8_t reply[CELL_PAYLOAD_SIZE - 2];
|
|
|
|
} created_cell_t;
|
|
|
|
|
|
|
|
/** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
|
|
|
|
typedef struct extend_cell_t {
|
|
|
|
/** One of RELAY_EXTEND or RELAY_EXTEND2 */
|
|
|
|
uint8_t cell_type;
|
|
|
|
/** An IPv4 address and port for the node we're connecting to. */
|
|
|
|
tor_addr_port_t orport_ipv4;
|
|
|
|
/** An IPv6 address and port for the node we're connecting to. Not currently
|
|
|
|
* used. */
|
|
|
|
tor_addr_port_t orport_ipv6;
|
|
|
|
/** Identity fingerprint of the node we're conecting to.*/
|
|
|
|
uint8_t node_id[DIGEST_LEN];
|
2016-09-14 22:00:23 +02:00
|
|
|
/** Ed25519 public identity key. Zero if not set. */
|
|
|
|
ed25519_public_key_t ed_pubkey;
|
2012-12-05 22:47:22 +01:00
|
|
|
/** The "create cell" embedded in this extend cell. Note that unlike the
|
|
|
|
* create cells we generate ourself, this once can have a handshake type we
|
|
|
|
* don't recognize. */
|
|
|
|
create_cell_t create_cell;
|
|
|
|
} extend_cell_t;
|
|
|
|
|
|
|
|
/** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
|
|
|
|
typedef struct extended_cell_t {
|
|
|
|
/** One of RELAY_EXTENDED or RELAY_EXTENDED2. */
|
|
|
|
uint8_t cell_type;
|
|
|
|
/** The "created cell" embedded in this extended cell. */
|
|
|
|
created_cell_t created_cell;
|
|
|
|
} extended_cell_t;
|
|
|
|
|
2013-09-01 10:40:05 +02:00
|
|
|
void create_cell_init(create_cell_t *cell_out, uint8_t cell_type,
|
|
|
|
uint16_t handshake_type, uint16_t handshake_len,
|
|
|
|
const uint8_t *onionskin);
|
2012-12-05 22:47:22 +01:00
|
|
|
int create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in);
|
|
|
|
int created_cell_parse(created_cell_t *cell_out, const cell_t *cell_in);
|
2013-01-17 20:38:15 +01:00
|
|
|
int extend_cell_parse(extend_cell_t *cell_out, const uint8_t command,
|
2012-12-05 22:47:22 +01:00
|
|
|
const uint8_t *payload_in, size_t payload_len);
|
2013-01-17 20:38:15 +01:00
|
|
|
int extended_cell_parse(extended_cell_t *cell_out, const uint8_t command,
|
2012-12-05 22:47:22 +01:00
|
|
|
const uint8_t *payload_in, size_t payload_len);
|
|
|
|
|
|
|
|
int create_cell_format(cell_t *cell_out, const create_cell_t *cell_in);
|
2012-12-06 06:21:24 +01:00
|
|
|
int create_cell_format_relayed(cell_t *cell_out, const create_cell_t *cell_in);
|
2012-12-05 22:47:22 +01:00
|
|
|
int created_cell_format(cell_t *cell_out, const created_cell_t *cell_in);
|
|
|
|
int extend_cell_format(uint8_t *command_out, uint16_t *len_out,
|
|
|
|
uint8_t *payload_out, const extend_cell_t *cell_in);
|
|
|
|
int extended_cell_format(uint8_t *command_out, uint16_t *len_out,
|
|
|
|
uint8_t *payload_out, const extended_cell_t *cell_in);
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_ONION_H) */
|
2010-07-23 20:38:25 +02:00
|
|
|
|