2004-04-03 00:23:15 +02:00
|
|
|
/* Copyright 2004 Roger Dingledine */
|
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
/* $Id$ */
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/**
|
|
|
|
* \file rendclient.c
|
|
|
|
* \brief Client code to access location-hiddenn services.
|
|
|
|
**/
|
2004-05-05 23:32:43 +02:00
|
|
|
|
2004-04-03 00:23:15 +02:00
|
|
|
#include "or.h"
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Called when we've established a circuit to an introduction point:
|
2004-05-05 23:32:43 +02:00
|
|
|
* send the introduction request. */
|
2004-04-03 00:23:15 +02:00
|
|
|
void
|
2004-05-13 09:24:49 +02:00
|
|
|
rend_client_introcirc_has_opened(circuit_t *circ)
|
2004-04-03 00:23:15 +02:00
|
|
|
{
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
|
|
|
|
tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath);
|
2004-04-03 00:23:15 +02:00
|
|
|
|
2004-04-05 02:47:48 +02:00
|
|
|
log_fn(LOG_INFO,"introcirc is open");
|
|
|
|
connection_ap_attach_pending();
|
2004-04-03 00:23:15 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Send the establish-rendezvous cell along a rendezvous circuit. if
|
2004-05-05 23:32:43 +02:00
|
|
|
* it fails, mark the circ for close and return -1. else return 0.
|
2004-04-05 09:41:31 +02:00
|
|
|
*/
|
2004-05-12 22:58:27 +02:00
|
|
|
static int
|
2004-04-03 06:22:22 +02:00
|
|
|
rend_client_send_establish_rendezvous(circuit_t *circ)
|
|
|
|
{
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
|
2004-04-03 06:22:22 +02:00
|
|
|
log_fn(LOG_INFO, "Sending an ESTABLISH_RENDEZVOUS cell");
|
|
|
|
|
|
|
|
if (crypto_rand(REND_COOKIE_LEN, circ->rend_cookie)<0) {
|
|
|
|
log_fn(LOG_WARN, "Couldn't get random cookie");
|
2004-04-05 09:41:31 +02:00
|
|
|
circuit_mark_for_close(circ);
|
2004-04-03 06:22:22 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (connection_edge_send_command(NULL,circ,
|
|
|
|
RELAY_COMMAND_ESTABLISH_RENDEZVOUS,
|
|
|
|
circ->rend_cookie, REND_COOKIE_LEN,
|
|
|
|
circ->cpath->prev)<0) {
|
2004-04-05 09:41:31 +02:00
|
|
|
/* circ is already marked for close */
|
2004-04-03 06:22:22 +02:00
|
|
|
log_fn(LOG_WARN, "Couldn't send ESTABLISH_RENDEZVOUS cell");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Called when we're trying to connect an ap conn; sends an INTRODUCE1 cell
|
2004-04-06 05:44:36 +02:00
|
|
|
* down introcirc if possible.
|
|
|
|
*/
|
2004-04-05 09:41:31 +02:00
|
|
|
int
|
|
|
|
rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) {
|
2004-04-08 00:41:00 +02:00
|
|
|
int payload_len, r;
|
2004-04-05 23:15:14 +02:00
|
|
|
char payload[RELAY_PAYLOAD_SIZE];
|
2004-04-06 05:44:36 +02:00
|
|
|
char tmp[(MAX_NICKNAME_LEN+1)+REND_COOKIE_LEN+DH_KEY_LEN];
|
2004-04-08 00:41:00 +02:00
|
|
|
rend_cache_entry_t *entry;
|
2004-04-05 22:30:53 +02:00
|
|
|
crypt_path_t *cpath;
|
2004-04-05 09:41:31 +02:00
|
|
|
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
|
|
|
|
tor_assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY);
|
|
|
|
tor_assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query));
|
2004-04-05 09:41:31 +02:00
|
|
|
|
2004-04-08 00:41:00 +02:00
|
|
|
if(rend_cache_lookup_entry(introcirc->rend_query, &entry) < 1) {
|
2004-04-05 09:41:31 +02:00
|
|
|
log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.",
|
|
|
|
introcirc->rend_query);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first 20 bytes of payload are the hash of bob's pk */
|
2004-04-08 00:41:00 +02:00
|
|
|
if (crypto_pk_get_digest(entry->parsed->pk, payload)<0) {
|
2004-04-05 09:41:31 +02:00
|
|
|
log_fn(LOG_WARN, "Couldn't hash public key.");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-04-05 22:30:53 +02:00
|
|
|
/* Initialize the pending_final_cpath and start the DH handshake. */
|
2004-04-13 05:19:58 +02:00
|
|
|
cpath = rendcirc->build_state->pending_final_cpath;
|
|
|
|
if (!cpath) {
|
|
|
|
cpath = rendcirc->build_state->pending_final_cpath =
|
|
|
|
tor_malloc_zero(sizeof(crypt_path_t));
|
|
|
|
if (!(cpath->handshake_state = crypto_dh_new())) {
|
|
|
|
log_fn(LOG_WARN, "Couldn't allocate DH");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (crypto_dh_generate_public(cpath->handshake_state)<0) {
|
|
|
|
log_fn(LOG_WARN, "Couldn't generate g^x");
|
|
|
|
goto err;
|
|
|
|
}
|
2004-04-05 22:30:53 +02:00
|
|
|
}
|
|
|
|
|
2004-04-05 09:41:31 +02:00
|
|
|
/* write the remaining items into tmp */
|
2004-04-06 05:44:36 +02:00
|
|
|
strncpy(tmp, rendcirc->build_state->chosen_exit, (MAX_NICKNAME_LEN+1)); /* nul pads */
|
|
|
|
memcpy(tmp+MAX_NICKNAME_LEN+1, rendcirc->rend_cookie, REND_COOKIE_LEN);
|
|
|
|
if (crypto_dh_get_public(cpath->handshake_state,
|
|
|
|
tmp+MAX_NICKNAME_LEN+1+REND_COOKIE_LEN,
|
|
|
|
DH_KEY_LEN)<0) {
|
2004-04-05 22:30:53 +02:00
|
|
|
log_fn(LOG_WARN, "Couldn't extract g^x");
|
|
|
|
goto err;
|
|
|
|
}
|
2004-04-05 09:41:31 +02:00
|
|
|
|
2004-04-08 00:41:00 +02:00
|
|
|
r = crypto_pk_public_hybrid_encrypt(entry->parsed->pk, tmp,
|
2004-04-06 05:44:36 +02:00
|
|
|
MAX_NICKNAME_LEN+1+REND_COOKIE_LEN+DH_KEY_LEN,
|
|
|
|
payload+DIGEST_LEN,
|
2004-04-06 22:55:46 +02:00
|
|
|
PK_PKCS1_OAEP_PADDING, 0);
|
2004-04-05 23:15:14 +02:00
|
|
|
if (r<0) {
|
2004-04-05 09:41:31 +02:00
|
|
|
log_fn(LOG_WARN,"hybrid pk encrypt failed.");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(DIGEST_LEN + r <= RELAY_PAYLOAD_SIZE); /* we overran something */
|
2004-04-06 05:44:36 +02:00
|
|
|
payload_len = DIGEST_LEN + r;
|
2004-04-05 23:15:14 +02:00
|
|
|
|
2004-04-05 09:41:31 +02:00
|
|
|
if (connection_edge_send_command(NULL, introcirc,
|
|
|
|
RELAY_COMMAND_INTRODUCE1,
|
2004-04-05 23:15:14 +02:00
|
|
|
payload, payload_len,
|
2004-04-05 09:41:31 +02:00
|
|
|
introcirc->cpath->prev)<0) {
|
|
|
|
/* introcirc is already marked for close. leave rendcirc alone. */
|
|
|
|
log_fn(LOG_WARN, "Couldn't send INTRODUCE1 cell");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-04-13 03:41:39 +02:00
|
|
|
/* Now, we wait for an ACK or NAK on this circuit. */
|
|
|
|
introcirc->purpose = CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT;
|
2004-04-05 17:17:34 +02:00
|
|
|
|
2004-04-05 09:41:31 +02:00
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
circuit_mark_for_close(introcirc);
|
|
|
|
circuit_mark_for_close(rendcirc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Called when a rendezvous circuit is open; sends a establish
|
2004-05-05 23:32:43 +02:00
|
|
|
* rendezvous circuit as appropriate. */
|
2004-04-03 00:23:15 +02:00
|
|
|
void
|
2004-05-13 09:24:49 +02:00
|
|
|
rend_client_rendcirc_has_opened(circuit_t *circ)
|
2004-04-03 00:23:15 +02:00
|
|
|
{
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
|
|
|
|
tor_assert(CIRCUIT_IS_ORIGIN(circ));
|
2004-04-03 00:23:15 +02:00
|
|
|
|
2004-04-05 02:47:48 +02:00
|
|
|
log_fn(LOG_INFO,"rendcirc is open");
|
2004-04-03 05:06:06 +02:00
|
|
|
|
2004-04-05 02:47:48 +02:00
|
|
|
/* generate a rendezvous cookie, store it in circ */
|
|
|
|
if (rend_client_send_establish_rendezvous(circ) < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
connection_ap_attach_pending();
|
|
|
|
}
|
2004-04-03 05:06:06 +02:00
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Called when get an ACK or a NAK for a REND_INTRODUCE1 cell.
|
2004-04-13 01:33:47 +02:00
|
|
|
*/
|
|
|
|
int
|
2004-04-13 03:41:39 +02:00
|
|
|
rend_client_introduction_acked(circuit_t *circ,
|
2004-04-13 01:33:47 +02:00
|
|
|
const char *request, int request_len)
|
|
|
|
{
|
2004-04-13 04:31:52 +02:00
|
|
|
char *nickname;
|
2004-04-14 00:56:24 +02:00
|
|
|
circuit_t *rendcirc;
|
2004-04-13 04:31:52 +02:00
|
|
|
|
2004-04-13 03:41:39 +02:00
|
|
|
if (circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
|
2004-04-13 07:20:52 +02:00
|
|
|
log_fn(LOG_WARN, "Received REND_INTRODUCE_ACK on unexpected circuit %d",
|
2004-04-13 03:41:39 +02:00
|
|
|
circ->n_circ_id);
|
|
|
|
circuit_mark_for_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(circ->build_state->chosen_exit);
|
2004-04-13 04:31:52 +02:00
|
|
|
|
2004-04-13 01:33:47 +02:00
|
|
|
if (request_len == 0) {
|
|
|
|
/* It's an ACK; the introduction point relayed our introduction request. */
|
2004-04-14 00:56:24 +02:00
|
|
|
/* Locate the rend circ which is waiting to hear about this ack,
|
|
|
|
* and tell it.
|
|
|
|
*/
|
2004-04-16 10:21:35 +02:00
|
|
|
log_fn(LOG_INFO,"Received ack. Telling rend circ.");
|
2004-04-14 00:56:24 +02:00
|
|
|
rendcirc = circuit_get_by_rend_query_and_purpose(
|
|
|
|
circ->rend_query, CIRCUIT_PURPOSE_C_REND_READY);
|
|
|
|
if(rendcirc) { /* remember the ack */
|
|
|
|
rendcirc->purpose = CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED;
|
|
|
|
}
|
|
|
|
/* close the circuit: we won't need it anymore. */
|
2004-04-18 10:38:40 +02:00
|
|
|
circ->purpose = CIRCUIT_PURPOSE_C_INTRODUCE_ACKED;
|
2004-04-13 03:41:39 +02:00
|
|
|
circuit_mark_for_close(circ);
|
2004-04-13 01:33:47 +02:00
|
|
|
} else {
|
|
|
|
/* It's a NAK; the introduction point didn't relay our request. */
|
2004-04-13 03:41:39 +02:00
|
|
|
circ->purpose = CIRCUIT_PURPOSE_C_INTRODUCING;
|
2004-04-18 09:37:16 +02:00
|
|
|
/* Remove this intro point from the set of viable introduction
|
|
|
|
* points. If any remain, extend to a new one and try again.
|
|
|
|
* If none remain, refetch the service descriptor.
|
2004-04-13 03:41:39 +02:00
|
|
|
*/
|
2004-04-18 09:37:16 +02:00
|
|
|
if(rend_client_remove_intro_point(circ->build_state->chosen_exit,
|
|
|
|
circ->rend_query) > 0) {
|
|
|
|
/* There are introduction points left. re-extend the circuit to
|
2004-04-13 04:31:52 +02:00
|
|
|
* another intro point and try again. */
|
2004-04-18 09:37:16 +02:00
|
|
|
nickname = rend_client_get_random_intro(circ->rend_query);
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(nickname);
|
2004-04-18 09:37:16 +02:00
|
|
|
log_fn(LOG_INFO,"Got nack for %s from %s, extending to %s.", circ->rend_query, circ->build_state->chosen_exit, nickname);
|
|
|
|
if (!router_get_by_nickname(nickname)) {
|
|
|
|
log_fn(LOG_WARN, "Advertised intro point '%s' for %s is not known. Closing.",
|
|
|
|
nickname, circ->rend_query);
|
|
|
|
circuit_mark_for_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
log_fn(LOG_INFO, "Chose new intro point %s for %s (circ %d)",
|
|
|
|
nickname, circ->rend_query, circ->n_circ_id);
|
|
|
|
circ->state = CIRCUIT_STATE_BUILDING;
|
|
|
|
tor_free(circ->build_state->chosen_exit);
|
|
|
|
circ->build_state->chosen_exit = tor_strdup(nickname);
|
|
|
|
++circ->build_state->desired_path_len;
|
|
|
|
if (circuit_send_next_onion_skin(circ)<0) {
|
|
|
|
log_fn(LOG_WARN, "Couldn't extend circuit to new intro point.");
|
|
|
|
circuit_mark_for_close(circ);
|
|
|
|
return -1;
|
2004-04-13 04:31:52 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-13 01:33:47 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-05 23:32:43 +02:00
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** If we are not currently fetching a rendezvous service descriptor
|
2004-05-10 06:34:48 +02:00
|
|
|
* for the service ID <b>query</b>, start a directory connection to fetch a
|
2004-05-05 23:32:43 +02:00
|
|
|
* new one.
|
|
|
|
*/
|
2004-04-18 09:37:16 +02:00
|
|
|
void
|
2004-05-05 23:32:43 +02:00
|
|
|
rend_client_refetch_renddesc(const char *query)
|
2004-04-18 09:37:16 +02:00
|
|
|
{
|
|
|
|
if(connection_get_by_type_rendquery(CONN_TYPE_DIR, query)) {
|
|
|
|
log_fn(LOG_INFO,"Would fetch a new renddesc here (for %s), but one is already in progress.", query);
|
|
|
|
} else {
|
|
|
|
/* not one already; initiate a dir rend desc lookup */
|
2004-05-13 01:48:57 +02:00
|
|
|
directory_get_from_dirserver(DIR_PURPOSE_FETCH_RENDDESC,
|
|
|
|
query, strlen(query));
|
2004-04-18 09:37:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** remove failed_intro from ent. if ent now has no intro points, or
|
2004-04-18 09:37:16 +02:00
|
|
|
* service is unrecognized, then launch a new renddesc fetch.
|
|
|
|
*
|
|
|
|
* Return -1 if error, 0 if no intro points remain or service
|
|
|
|
* unrecognized, 1 if recognized and some intro points remain.
|
|
|
|
*/
|
|
|
|
int
|
2004-05-05 23:32:43 +02:00
|
|
|
rend_client_remove_intro_point(char *failed_intro, const char *query)
|
2004-04-18 09:37:16 +02:00
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
rend_cache_entry_t *ent;
|
|
|
|
|
|
|
|
r = rend_cache_lookup_entry(query, &ent);
|
|
|
|
if (r<0) {
|
|
|
|
log_fn(LOG_WARN, "Malformed service ID '%s'", query);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (r==0) {
|
|
|
|
log_fn(LOG_INFO, "Unknown service %s. Re-fetching descriptor.", query);
|
|
|
|
rend_client_refetch_renddesc(query);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i < ent->parsed->n_intro_points; ++i) {
|
|
|
|
if (!strcasecmp(ent->parsed->intro_points[i], failed_intro)) {
|
|
|
|
tor_free(ent->parsed->intro_points[i]);
|
|
|
|
ent->parsed->intro_points[i] =
|
|
|
|
ent->parsed->intro_points[--ent->parsed->n_intro_points];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ent->parsed->n_intro_points) {
|
|
|
|
log_fn(LOG_INFO,"No more intro points remain for %s. Re-fetching descriptor.", query);
|
|
|
|
rend_client_refetch_renddesc(query);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
log_fn(LOG_INFO,"%d options left for %s.", ent->parsed->n_intro_points, query);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Called when we receive a RENDEZVOUS_ESTABLISHED cell; changes the state of
|
2004-04-06 05:44:36 +02:00
|
|
|
* the circuit to C_REND_READY.
|
|
|
|
*/
|
2004-04-05 02:47:48 +02:00
|
|
|
int
|
|
|
|
rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_len)
|
|
|
|
{
|
|
|
|
/* we just got an ack for our establish-rendezvous. switch purposes. */
|
|
|
|
if(circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
|
|
|
|
log_fn(LOG_WARN,"Got a rendezvous ack when we weren't expecting one. Closing circ.");
|
|
|
|
circuit_mark_for_close(circ);
|
|
|
|
return -1;
|
2004-04-03 05:06:06 +02:00
|
|
|
}
|
2004-04-05 09:41:31 +02:00
|
|
|
log_fn(LOG_INFO,"Got rendezvous ack. This circuit is now ready for rendezvous.");
|
2004-04-05 02:47:48 +02:00
|
|
|
circ->purpose = CIRCUIT_PURPOSE_C_REND_READY;
|
|
|
|
return 0;
|
2004-04-03 00:23:15 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Bob sent us a rendezvous cell; join the circuits. */
|
2004-04-05 09:41:31 +02:00
|
|
|
int
|
|
|
|
rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request_len)
|
2004-04-03 00:23:15 +02:00
|
|
|
{
|
2004-04-05 22:53:50 +02:00
|
|
|
crypt_path_t *hop;
|
|
|
|
char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN];
|
2004-04-03 00:23:15 +02:00
|
|
|
|
2004-04-14 07:18:21 +02:00
|
|
|
if( (circ->purpose != CIRCUIT_PURPOSE_C_REND_READY &&
|
|
|
|
circ->purpose != CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED)
|
|
|
|
|| !circ->build_state->pending_final_cpath) {
|
2004-04-05 09:41:31 +02:00
|
|
|
log_fn(LOG_WARN,"Got rendezvous2 cell from Bob, but not expecting it. Closing.");
|
|
|
|
circuit_mark_for_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-04-03 00:23:15 +02:00
|
|
|
|
2004-04-05 22:53:50 +02:00
|
|
|
if (request_len != DH_KEY_LEN+DIGEST_LEN) {
|
|
|
|
log_fn(LOG_WARN,"Incorrect length (%d) on RENDEZVOUS2 cell.",request_len);
|
|
|
|
goto err;
|
|
|
|
}
|
2004-04-03 00:23:15 +02:00
|
|
|
|
2004-04-05 22:53:50 +02:00
|
|
|
/* first DH_KEY_LEN bytes are g^y from bob. Finish the dh handshake...*/
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(circ->build_state && circ->build_state->pending_final_cpath);
|
2004-04-05 22:53:50 +02:00
|
|
|
hop = circ->build_state->pending_final_cpath;
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(hop->handshake_state);
|
2004-04-05 22:53:50 +02:00
|
|
|
if (crypto_dh_compute_secret(hop->handshake_state, request, DH_KEY_LEN,
|
|
|
|
keys, DIGEST_LEN+CPATH_KEY_MATERIAL_LEN)<0) {
|
|
|
|
log_fn(LOG_WARN, "Couldn't complete DH handshake");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* ... and set up cpath. */
|
|
|
|
if (circuit_init_cpath_crypto(hop, keys+DIGEST_LEN, 0)<0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Check whether the digest is right... */
|
2004-04-05 23:39:18 +02:00
|
|
|
if (memcmp(keys, request+DH_KEY_LEN, DIGEST_LEN)) {
|
2004-04-05 22:53:50 +02:00
|
|
|
log_fn(LOG_WARN, "Incorrect digest of key material");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-04-06 22:23:58 +02:00
|
|
|
crypto_dh_free(hop->handshake_state);
|
|
|
|
hop->handshake_state = NULL;
|
|
|
|
|
2004-04-05 22:53:50 +02:00
|
|
|
/* All is well. Extend the circuit. */
|
2004-04-05 09:41:31 +02:00
|
|
|
circ->purpose = CIRCUIT_PURPOSE_C_REND_JOINED;
|
2004-04-06 01:40:59 +02:00
|
|
|
hop->state = CPATH_STATE_OPEN;
|
2004-04-06 23:25:11 +02:00
|
|
|
/* set the windows to default. these are the windows
|
|
|
|
* that alice thinks bob has.
|
|
|
|
*/
|
|
|
|
hop->package_window = CIRCWINDOW_START;
|
|
|
|
hop->deliver_window = CIRCWINDOW_START;
|
|
|
|
|
2004-04-05 22:53:50 +02:00
|
|
|
onion_append_to_cpath(&circ->cpath, hop);
|
|
|
|
circ->build_state->pending_final_cpath = NULL; /* prevent double-free */
|
2004-04-05 09:41:31 +02:00
|
|
|
return 0;
|
2004-04-05 22:53:50 +02:00
|
|
|
err:
|
|
|
|
circuit_mark_for_close(circ);
|
|
|
|
return -1;
|
2004-04-05 09:41:31 +02:00
|
|
|
}
|
2004-04-03 00:23:15 +02:00
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Find all the apconns in state AP_CONN_STATE_RENDDESC_WAIT that
|
2004-04-03 01:38:26 +02:00
|
|
|
* are waiting on query. If success==1, move them to the next state.
|
|
|
|
* If success==0, fail them.
|
|
|
|
*/
|
|
|
|
void rend_client_desc_fetched(char *query, int success) {
|
|
|
|
connection_t **carray;
|
|
|
|
connection_t *conn;
|
|
|
|
int n, i;
|
2004-04-08 00:41:00 +02:00
|
|
|
rend_cache_entry_t *entry;
|
2004-04-03 01:38:26 +02:00
|
|
|
|
|
|
|
get_connection_array(&carray, &n);
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
conn = carray[i];
|
|
|
|
if (conn->type != CONN_TYPE_AP ||
|
2004-04-05 02:47:48 +02:00
|
|
|
conn->state != AP_CONN_STATE_RENDDESC_WAIT)
|
2004-04-03 01:38:26 +02:00
|
|
|
continue;
|
2004-04-03 01:54:48 +02:00
|
|
|
if (rend_cmp_service_ids(conn->rend_query, query))
|
2004-04-03 01:38:26 +02:00
|
|
|
continue;
|
|
|
|
/* great, this guy was waiting */
|
2004-04-08 00:41:00 +02:00
|
|
|
if(success ||
|
|
|
|
rend_cache_lookup_entry(conn->rend_query, &entry) == 1) {
|
|
|
|
/* either this fetch worked, or it failed but there was a
|
|
|
|
* valid entry from before which we should reuse */
|
2004-04-05 02:47:48 +02:00
|
|
|
log_fn(LOG_INFO,"Rend desc retrieved. Launching circuits.");
|
|
|
|
conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
|
2004-04-03 01:38:26 +02:00
|
|
|
if (connection_ap_handshake_attach_circuit(conn) < 0) {
|
|
|
|
/* it will never work */
|
|
|
|
log_fn(LOG_WARN,"attaching to a rend circ failed. Closing conn.");
|
2004-05-12 23:12:33 +02:00
|
|
|
conn->has_sent_end = 1;
|
|
|
|
connection_mark_for_close(conn);
|
2004-04-03 01:38:26 +02:00
|
|
|
}
|
2004-04-08 00:41:00 +02:00
|
|
|
} else { /* 404, or fetch didn't get that far */
|
|
|
|
log_fn(LOG_WARN,"service id '%s' fetched failed, and not in cache. Closing conn.", query);
|
2004-05-12 23:12:33 +02:00
|
|
|
conn->has_sent_end = 1;
|
|
|
|
connection_mark_for_close(conn);
|
2004-04-03 01:38:26 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-03 00:23:15 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** strdup a nickname for a random introduction
|
2004-04-05 02:47:48 +02:00
|
|
|
* point of query. return NULL if error.
|
|
|
|
*/
|
2004-04-05 19:51:00 +02:00
|
|
|
char *rend_client_get_random_intro(char *query) {
|
2004-04-05 02:47:48 +02:00
|
|
|
int i;
|
|
|
|
smartlist_t *sl;
|
|
|
|
char *choice;
|
2004-04-05 19:56:34 +02:00
|
|
|
char *nickname;
|
2004-04-08 04:11:49 +02:00
|
|
|
rend_cache_entry_t *entry;
|
2004-04-05 02:47:48 +02:00
|
|
|
|
2004-04-08 04:11:49 +02:00
|
|
|
if(rend_cache_lookup_entry(query, &entry) < 1) {
|
2004-04-05 02:47:48 +02:00
|
|
|
log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.", query);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sl = smartlist_create();
|
|
|
|
|
|
|
|
/* add the intro point nicknames */
|
2004-04-08 04:11:49 +02:00
|
|
|
for(i=0;i<entry->parsed->n_intro_points;i++)
|
|
|
|
smartlist_add(sl,entry->parsed->intro_points[i]);
|
2004-04-05 02:47:48 +02:00
|
|
|
|
|
|
|
choice = smartlist_choose(sl);
|
2004-04-08 05:18:03 +02:00
|
|
|
if(!choice) {
|
|
|
|
smartlist_free(sl);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-04-05 19:56:34 +02:00
|
|
|
nickname = tor_strdup(choice);
|
2004-04-05 02:47:48 +02:00
|
|
|
smartlist_free(sl);
|
2004-04-05 19:56:34 +02:00
|
|
|
return nickname;
|
2004-04-05 02:47:48 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** If address is of the form "y.onion" with a well-formed handle y,
|
2004-04-03 03:59:53 +02:00
|
|
|
* then put a '\0' after y, lower-case it, and return 0.
|
|
|
|
* Else return -1 and change nothing.
|
|
|
|
*/
|
|
|
|
int rend_parse_rendezvous_address(char *address) {
|
|
|
|
char *s;
|
|
|
|
char query[REND_SERVICE_ID_LEN+1];
|
|
|
|
|
|
|
|
s = strrchr(address,'.');
|
|
|
|
if(!s) return -1; /* no dot */
|
|
|
|
if (strcasecmp(s+1,"onion"))
|
|
|
|
return -1; /* not .onion */
|
|
|
|
|
|
|
|
*s = 0; /* null terminate it */
|
|
|
|
if(strlcpy(query, address, REND_SERVICE_ID_LEN+1) >= REND_SERVICE_ID_LEN+1)
|
|
|
|
goto failed;
|
|
|
|
tor_strlower(query);
|
|
|
|
if(rend_valid_service_id(query)) {
|
|
|
|
tor_strlower(address);
|
|
|
|
return 0; /* success */
|
|
|
|
}
|
|
|
|
failed:
|
|
|
|
/* otherwise, return to previous state and return -1 */
|
|
|
|
*s = '.';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-04-03 00:23:15 +02:00
|
|
|
/*
|
|
|
|
Local Variables:
|
|
|
|
mode:c
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
c-basic-offset:2
|
|
|
|
End:
|
|
|
|
*/
|