tor  master
Data Structures | Macros | Typedefs | Functions
onion.h File Reference

Header file for onion.c. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  server_onion_keys_t
 
struct  create_cell_t
 
struct  created_cell_t
 
struct  extend_cell_t
 
struct  extended_cell_t
 

Macros

#define MAX_ONIONSKIN_CHALLENGE_LEN   255
 
#define MAX_ONIONSKIN_REPLY_LEN   255
 
#define server_onion_keys_free(keys)   FREE_AND_NULL(server_onion_keys_t, server_onion_keys_free_, (keys))
 

Typedefs

typedef struct server_onion_keys_t server_onion_keys_t
 
typedef struct create_cell_t create_cell_t
 
typedef struct created_cell_t created_cell_t
 
typedef struct extend_cell_t extend_cell_t
 
typedef struct extended_cell_t extended_cell_t
 

Functions

int onion_pending_add (or_circuit_t *circ, struct create_cell_t *onionskin)
 
or_circuit_tonion_next_task (struct create_cell_t **onionskin_out)
 
int onion_num_pending (uint16_t handshake_type)
 
void onion_pending_remove (or_circuit_t *circ)
 
void clear_pending_onions (void)
 
server_onion_keys_tserver_onion_keys_new (void)
 
void server_onion_keys_free_ (server_onion_keys_t *keys)
 
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, const uint8_t *onion_skin, size_t onionskin_len, const server_onion_keys_t *keys, uint8_t *reply_out, uint8_t *keys_out, size_t key_out_len, uint8_t *rend_nonce_out)
 
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 key_out_len, uint8_t *rend_authenticator_out, const char **msg_out)
 
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)
 
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)
 
int extend_cell_parse (extend_cell_t *cell_out, const uint8_t command, const uint8_t *payload_in, size_t payload_len)
 
int extended_cell_parse (extended_cell_t *cell_out, const uint8_t command, const uint8_t *payload_in, size_t payload_len)
 
int create_cell_format (cell_t *cell_out, const create_cell_t *cell_in)
 
int create_cell_format_relayed (cell_t *cell_out, const create_cell_t *cell_in)
 
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)
 

Detailed Description

Header file for onion.c.

Typedef Documentation

◆ create_cell_t

typedef struct create_cell_t create_cell_t

A parsed CREATE, CREATE_FAST, or CREATE2 cell.

◆ created_cell_t

A parsed CREATED, CREATED_FAST, or CREATED2 cell.

◆ extend_cell_t

typedef struct extend_cell_t extend_cell_t

A parsed RELAY_EXTEND or RELAY_EXTEND2 cell

◆ extended_cell_t

A parsed RELAY_EXTEND or RELAY_EXTEND2 cell

Function Documentation

◆ clear_pending_onions()

void clear_pending_onions ( void  )

Remove all circuits from the pending list. Called from tor_free_all.

◆ create_cell_init()

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 
)

Write the various parameters into the create cell. Separate from create_cell_parse() to make unit testing easier.

◆ create_cell_parse()

int create_cell_parse ( create_cell_t cell_out,
const cell_t cell_in 
)

Parse a CREATE, CREATE_FAST, or CREATE2 cell from cell_in into cell_out. Return 0 on success, -1 on failure. (We reject some syntactically valid CREATE2 cells that we can't generate or react to.)

◆ created_cell_format()

int created_cell_format ( cell_t cell_out,
const created_cell_t cell_in 
)

Fill cell_out with a correctly formatted version of the CREATED{,_FAST,2} cell in cell_in. Return 0 on success, -1 on failure.

◆ created_cell_parse()

int created_cell_parse ( created_cell_t cell_out,
const cell_t cell_in 
)

Parse a CREATED, CREATED_FAST, or CREATED2 cell from cell_in into cell_out. Return 0 on success, -1 on failure.

◆ extend_cell_format()

int extend_cell_format ( uint8_t *  command_out,
uint16_t *  len_out,
uint8_t *  payload_out,
const extend_cell_t cell_in 
)

Format the EXTEND{,2} cell in cell_in, storing its relay payload in payload_out, the number of bytes used in *len_out, and the relay command in *command_out. The payload_out must have RELAY_PAYLOAD_SIZE bytes available. Return 0 on success, -1 on failure.

◆ extend_cell_parse()

int extend_cell_parse ( extend_cell_t cell_out,
const uint8_t  command,
const uint8_t *  payload,
size_t  payload_length 
)

Parse an EXTEND or EXTEND2 cell (according to command) from the payload_length bytes of payload into cell_out. Return 0 on success, -1 on failure.

◆ extended_cell_format()

int extended_cell_format ( uint8_t *  command_out,
uint16_t *  len_out,
uint8_t *  payload_out,
const extended_cell_t cell_in 
)

Format the EXTENDED{,2} cell in cell_in, storing its relay payload in payload_out, the number of bytes used in *len_out, and the relay command in *command_out. The payload_out must have RELAY_PAYLOAD_SIZE bytes available. Return 0 on success, -1 on failure.

◆ extended_cell_parse()

int extended_cell_parse ( extended_cell_t cell_out,
const uint8_t  command,
const uint8_t *  payload,
size_t  payload_len 
)

Parse an EXTENDED or EXTENDED2 cell (according to command) from the payload_length bytes of payload into cell_out. Return 0 on success, -1 on failure.

◆ onion_handshake_state_release()

void onion_handshake_state_release ( onion_handshake_state_t state)

Release whatever storage is held in state, depending on its type, and clear its pointer.

◆ onion_next_task()

or_circuit_t* onion_next_task ( create_cell_t **  onionskin_out)

Remove the highest priority item from ol_list[] and return it, or return NULL if the lists are empty.

◆ onion_num_pending()

int onion_num_pending ( uint16_t  handshake_type)

Return the number of handshake_type-style create requests pending.

◆ onion_pending_add()

int onion_pending_add ( or_circuit_t circ,
create_cell_t onionskin 
)

Add circ to the end of ol_list and return 0, except if ol_list is too long, in which case do nothing and return -1.

◆ onion_pending_remove()

void onion_pending_remove ( or_circuit_t circ)

Go through ol_list, find the onion_queue_t element which points to circ, remove and free that element. Leave circ itself alone.

◆ onion_skin_client_handshake()

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,
const char **  msg_out 
)

Perform the final (client-side) step of a circuit-creation handshake of type type, using our state in handshake_state and the server's response in reply. On success, generate keys_out_len bytes worth of key material in keys_out_len, set rend_authenticator_out to the "KH" field that can be used to establish introduction points at this hop, and return 0. On failure, return -1, and set *msg_out to an error message if this is worth complaining to the user about.

◆ onion_skin_create()

int onion_skin_create ( int  type,
const extend_info_t node,
onion_handshake_state_t state_out,
uint8_t *  onion_skin_out 
)

Perform the first step of a circuit-creation handshake of type type (one of ONION_HANDSHAKE_TYPE_*): generate the initial "onion skin" in onion_skin_out, and store any state information in state_out. Return -1 on failure, and the length of the onionskin on acceptance.

◆ onion_skin_server_handshake()

int onion_skin_server_handshake ( int  type,
const uint8_t *  onion_skin,
size_t  onionskin_len,
const server_onion_keys_t keys,
uint8_t *  reply_out,
uint8_t *  keys_out,
size_t  keys_out_len,
uint8_t *  rend_nonce_out 
)

Perform the second (server-side) step of a circuit-creation handshake of type type, responding to the client request in onion_skin using the keys in keys. On success, write our response into reply_out, generate keys_out_len bytes worth of key material in keys_out_len, a hidden service nonce to rend_nonce_out, and return the length of the reply. On failure, return -1.

◆ server_onion_keys_free_()

void server_onion_keys_free_ ( server_onion_keys_t keys)

Release all storage held in keys.

◆ server_onion_keys_new()

server_onion_keys_t* server_onion_keys_new ( void  )

Return a new server_onion_keys_t object with all of the keys and other info we might need to do onion handshakes. (We make a copy of our keys for each cpuworker to avoid race conditions with the main thread, and to avoid locking)