onion.c File Reference

Functions to queue create cells, and handle onionskin parsing and creation. More...

#include "or.h"

Data Structures

struct  onion_queue_t

Defines

#define ONIONQUEUE_WAIT_CUTOFF   5
#define WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL   (60)

Functions

int onion_pending_add (or_circuit_t *circ, char *onionskin)
or_circuit_tonion_next_task (char **onionskin_out)
void onion_pending_remove (or_circuit_t *circ)
int onion_skin_create (crypto_pk_env_t *dest_router_key, crypto_dh_env_t **handshake_state_out, char *onion_skin_out)
int onion_skin_server_handshake (const char *onion_skin, crypto_pk_env_t *private_key, crypto_pk_env_t *prev_private_key, char *handshake_reply_out, char *key_out, size_t key_out_len)
int onion_skin_client_handshake (crypto_dh_env_t *handshake_state, const char *handshake_reply, char *key_out, size_t key_out_len)
int fast_server_handshake (const char *key_in, char *handshake_reply_out, char *key_out, size_t key_out_len)
int fast_client_handshake (const char *handshake_state, const char *handshake_reply_out, char *key_out, size_t key_out_len)
void clear_pending_onions (void)

Variables

static onion_queue_tol_list = NULL
static onion_queue_tol_tail = NULL
static int ol_length = 0


Detailed Description

Functions to queue create cells, and handle onionskin parsing and creation.


Define Documentation

#define ONIONQUEUE_WAIT_CUTOFF   5

5 seconds on the onion queue til we just send back a destroy

Referenced by onion_pending_add().


Function Documentation

void clear_pending_onions ( void   ) 

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

References onion_queue_t::next, ol_length, onion_queue_t::onionskin, and tor_free.

Referenced by tor_free_all().

int fast_client_handshake ( const char *  handshake_state,
const char *  handshake_reply_out,
char *  key_out,
size_t  key_out_len 
)

Implement the second half of the client side of the CREATE_FAST handshake. We sent the server handshake_state ("x") already, and the server told us handshake_reply_out (y|H(x|y)). Make sure that the hash is correct, and generate key material in key_out. Return 0 on success, true on failure.

NOTE: The "CREATE_FAST" handshake path is distinguishable from regular "onionskin" handshakes, and is not secure if an adversary can see or modify the messages. Therefore, it should only be used by clients, and only as the first hop of a circuit (since the first hop is already authenticated and protected by TLS).

References crypto_expand_key_material(), DIGEST_LEN, LD_PROTOCOL, and tor_free.

Referenced by circuit_finish_handshake().

int fast_server_handshake ( const char *  key_in,
char *  handshake_reply_out,
char *  key_out,
size_t  key_out_len 
)

Implement the server side of the CREATE_FAST abbreviated handshake. The client has provided DIGEST_LEN key bytes in key_in ("x"). We generate a reply of DIGEST_LEN*2 bytes in key_out, consisting of a new random "y", followed by H(x|y) to check for correctness. We set key_out_len bytes of key material in key_out. Return 0 on success, <0 on failure.

References crypto_expand_key_material(), crypto_rand(), DIGEST_LEN, and tor_free.

Referenced by command_process_create_cell().

or_circuit_t* onion_next_task ( char **  onionskin_out  ) 

Remove the first item from ol_list and return it, or return NULL if the list is empty.

References onion_queue_t::circ, ol_length, onion_pending_remove(), onion_queue_t::onionskin, or_circuit_t::p_conn, and tor_assert.

Referenced by process_pending_task().

int onion_pending_add ( or_circuit_t circ,
char *  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.

References onion_queue_t::circ, get_options(), LD_CIRC, LD_GENERAL, onion_queue_t::next, ol_length, onion_pending_remove(), ONIONQUEUE_WAIT_CUTOFF, onion_queue_t::onionskin, TO_CIRCUIT, tor_assert, tor_free, and onion_queue_t::when_added.

Referenced by assign_onionskin_to_cpuworker().

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.

References onion_queue_t::circ, LD_GENERAL, onion_queue_t::next, ol_length, onion_queue_t::onionskin, or_circuit_t::p_circ_id, and tor_free.

Referenced by _circuit_mark_for_close(), onion_next_task(), and onion_pending_add().

int onion_skin_client_handshake ( crypto_dh_env_t handshake_state,
const char *  handshake_reply,
char *  key_out,
size_t  key_out_len 
)

Finish the client side of the DH handshake. Given the 128 byte DH reply + 20 byte hash as generated by onion_skin_server_handshake and the handshake state generated by onion_skin_create, verify H(K) with the first 20 bytes of shared key material, then generate key_out_len more bytes of shared key material and store them in key_out.

After the invocation, call crypto_dh_free on handshake_state.

References crypto_dh_compute_secret(), crypto_dh_get_bytes(), DIGEST_LEN, LD_PROTOCOL, tor_assert, and tor_free.

Referenced by circuit_finish_handshake().

int onion_skin_create ( crypto_pk_env_t dest_router_key,
crypto_dh_env_t **  handshake_state_out,
char *  onion_skin_out 
)

Given a router's 128 byte public key, stores the following in onion_skin_out:

  • [42 bytes] OAEP padding
  • [16 bytes] Symmetric key for encrypting blob past RSA
  • [70 bytes] g^x part 1 (inside the RSA)
  • [58 bytes] g^x part 2 (symmetrically encrypted)

Stores the DH private key into handshake_state_out for later completion of the handshake.

The meeting point/cookies and auth are zeroed out for now.

References crypto_dh_free(), crypto_dh_get_bytes(), crypto_dh_get_public(), crypto_dh_new(), crypto_pk_keysize(), crypto_pk_public_hybrid_encrypt(), note_crypto_pk_op(), PK_PKCS1_OAEP_PADDING, and tor_assert.

Referenced by circuit_send_next_onion_skin().

int onion_skin_server_handshake ( const char *  onion_skin,
crypto_pk_env_t private_key,
crypto_pk_env_t prev_private_key,
char *  handshake_reply_out,
char *  key_out,
size_t  key_out_len 
)

Given an encrypted DH public key as generated by onion_skin_create, and the private key for this onion router, generate the reply (128-byte DH plus the first 20 bytes of shared key material), and store the next key_out_len bytes of key material in key_out.

References crypto_dh_compute_secret(), crypto_dh_free(), crypto_dh_get_public(), crypto_dh_new(), crypto_pk_private_hybrid_decrypt(), DIGEST_LEN, LD_GENERAL, LD_PROTOCOL, note_crypto_pk_op(), PK_PKCS1_OAEP_PADDING, and tor_free.

Referenced by cpuworker_main().


Variable Documentation

int ol_length = 0 [static]

onion_queue_t* ol_list = NULL [static]

First and last elements in the linked list of circuits waiting for CPU workers, or NULL if the list is empty.


Generated on Tue May 25 00:30:45 2010 for tor by  doxygen 1.5.6