Tor 0.4.9.8
Loading...
Searching...
No Matches
onion.c File Reference

Functions to queue create cells, and parse and create the CREATE cell and its allies. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/crypto/onion_crypto.h"
#include "core/crypto/onion_fast.h"
#include "core/crypto/onion_ntor.h"
#include "core/or/onion.h"
#include "feature/nodelist/networkstatus.h"
#include "core/or/cell_st.h"
#include "trunnel/ed25519_cert.h"

Go to the source code of this file.

Macros

#define NTOR_CREATE_MAGIC   "ntorNTORntorNTOR"
 

Functions

static int check_create_cell (const create_cell_t *cell, int unknown_ok)
 
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)
 
static int parse_create2_payload (create_cell_t *cell_out, const uint8_t *p, size_t p_len)
 
int create_cell_parse (create_cell_t *cell_out, const cell_t *cell_in)
 
static int check_created_cell (const created_cell_t *cell)
 
int created_cell_parse (created_cell_t *cell_out, const cell_t *cell_in)
 
static int check_extend_cell (const extend_cell_t *cell)
 
static int create_cell_from_create2_cell_body (create_cell_t *cell_out, const create2_cell_body_t *cell)
 
static int extend_cell_from_extend2_cell_body (extend_cell_t *cell_out, const extend2_cell_body_t *cell)
 
int extend_cell_parse (extend_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_length)
 
static int check_extended_cell (const extended_cell_t *cell)
 
int extended_cell_parse (extended_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_len)
 
static int create_cell_format_impl (cell_t *cell_out, const create_cell_t *cell_in, int relayed)
 
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)
 
static int should_include_ed25519_id_extend_cells (const networkstatus_t *ns, const or_options_t *options)
 
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

Functions to queue create cells, and parse and create the CREATE cell and its allies.

This module has a few functions, all related to the CREATE/CREATED handshake that we use on links in order to create a circuit, and the related EXTEND/EXTENDED handshake that we use over circuits in order to extend them an additional hop.

Clients invoke these functions when creating or extending a circuit, from circuitbuild.c.

Relays invoke these functions when they receive a CREATE or EXTEND cell in command.c or relay.c, in order to queue the pending request. They also invoke them from cpuworker.c, which handles dispatching onionskin requests to different worker threads.


This module also handles:

  • Queueing incoming onionskins on the relay side before passing them to worker threads.
  • Expiring onionskins on the relay side if they have waited for too long.
  • Packaging private keys on the server side in order to pass them to worker threads.
  • Encoding and decoding CREATE, CREATED, CREATE2, and CREATED2 cells.
  • Encoding and decodign EXTEND, EXTENDED, EXTEND2, and EXTENDED2 relay cells.

Definition in file onion.c.

Macro Definition Documentation

◆ NTOR_CREATE_MAGIC

#define NTOR_CREATE_MAGIC   "ntorNTORntorNTOR"

Magic string which, in a CREATE or EXTEND cell, indicates that a seeming TAP payload is really an ntor payload. We'd do away with this if every relay supported EXTEND2, but we want to be able to extend from A to B with ntor even when A doesn't understand EXTEND2 and so can't generate a CREATE2 cell.

Definition at line 147 of file onion.c.

Referenced by create_cell_format_impl().

Function Documentation

◆ check_create_cell()

static int check_create_cell ( const create_cell_t * cell,
int unknown_ok )
static

Helper: return 0 if cell appears valid, -1 otherwise. If unknown_ok is true, allow cells with handshake types we don't recognize.

Definition at line 59 of file onion.c.

Referenced by check_extend_cell(), create_cell_format_impl(), and create_cell_parse().

◆ check_created_cell()

static int check_created_cell ( const created_cell_t * cell)
static

Helper: return 0 if cell appears valid, -1 otherwise.

Definition at line 176 of file onion.c.

Referenced by check_extended_cell(), created_cell_format(), and created_cell_parse().

◆ check_extend_cell()

static int check_extend_cell ( const extend_cell_t * cell)
static

Helper: return 0 if cell appears valid, -1 otherwise.

Definition at line 228 of file onion.c.

Referenced by extend_cell_format(), and extend_cell_parse().

◆ check_extended_cell()

static int check_extended_cell ( const extended_cell_t * cell)
static

Helper: return 0 if cell appears valid, -1 otherwise.

Definition at line 389 of file onion.c.

Referenced by extended_cell_format(), and extended_cell_parse().

◆ create_cell_format()

int create_cell_format ( cell_t * cell_out,
const create_cell_t * cell_in )

Definition at line 495 of file onion.c.

◆ create_cell_format_impl()

static int create_cell_format_impl ( cell_t * cell_out,
const create_cell_t * cell_in,
int relayed )
static

Fill cell_out with a correctly formatted version of the CREATE{,_FAST,2} cell in cell_in. Return 0 on success, -1 on failure. This is a cell we didn't originate if relayed is true.

Definition at line 450 of file onion.c.

◆ create_cell_format_relayed()

int create_cell_format_relayed ( cell_t * cell_out,
const create_cell_t * cell_in )

Definition at line 501 of file onion.c.

◆ create_cell_from_create2_cell_body()

static int create_cell_from_create2_cell_body ( create_cell_t * cell_out,
const create2_cell_body_t * cell )
static

Definition at line 262 of file onion.c.

◆ 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.

Definition at line 101 of file onion.c.

Referenced by create_cell_parse(), and parse_create2_payload().

◆ 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.)

Definition at line 153 of file onion.c.

Referenced by command_process_create_cell().

◆ 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.

Definition at line 510 of file onion.c.

Referenced by onionskin_answer().

◆ 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.

Definition at line 199 of file onion.c.

Referenced by command_process_created_cell().

◆ 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_MAX bytes available.

Return 0 on success, -1 on failure.

Definition at line 557 of file onion.c.

Referenced by circuit_send_intermediate_onion_skin().

◆ extend_cell_from_extend2_cell_body()

static int extend_cell_from_extend2_cell_body ( extend_cell_t * cell_out,
const extend2_cell_body_t * cell )
static

Definition at line 285 of file onion.c.

◆ 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.

Definition at line 352 of file onion.c.

Referenced by circuit_extend().

◆ 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_MAX bytes available.

Return 0 on success, -1 on failure.

Definition at line 651 of file onion.c.

Referenced by command_process_created_cell().

◆ 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_len bytes of payload into cell_out. Return 0 on success, -1 on failure.

Definition at line 409 of file onion.c.

Referenced by handle_relay_msg().

◆ parse_create2_payload()

static int parse_create2_payload ( create_cell_t * cell_out,
const uint8_t * p,
size_t p_len )
static

Helper: parse the CREATE2 payload at p, which could be up to p_len bytes long, and use it to fill the fields of cell_out. Return 0 on success and -1 on failure.

Note that part of the body of an EXTEND2 cell is a CREATE2 payload, so this function is also used for parsing those.

Definition at line 121 of file onion.c.

Referenced by create_cell_parse().

◆ should_include_ed25519_id_extend_cells()

static int should_include_ed25519_id_extend_cells ( const networkstatus_t * ns,
const or_options_t * options )
static

Return true iff we are configured (by torrc or by the networkstatus parameters) to use Ed25519 identities in our Extend2 cells.

Definition at line 538 of file onion.c.

Referenced by extend_cell_format().