2007-12-12 22:09:01 +01:00
|
|
|
/* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2009-05-02 22:00:54 +02:00
|
|
|
* Copyright (c) 2007-2009, The Tor Project, Inc. */
|
2004-04-01 06:07:09 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/**
|
|
|
|
* \file rendmid.c
|
|
|
|
* \brief Implement introductions points and rendezvous points.
|
|
|
|
**/
|
2004-05-05 23:32:43 +02:00
|
|
|
|
2004-04-01 06:07:09 +02:00
|
|
|
#include "or.h"
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Respond to an ESTABLISH_INTRO cell by checking the signed data and
|
2004-05-05 23:32:43 +02:00
|
|
|
* setting the circuit's purpose and service pk digest.
|
2004-04-02 23:56:52 +02:00
|
|
|
*/
|
2004-04-01 06:07:09 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
rend_mid_establish_intro(or_circuit_t *circ, const char *request,
|
2005-12-14 21:40:40 +01:00
|
|
|
size_t request_len)
|
2004-04-01 06:07:09 +02:00
|
|
|
{
|
2004-04-02 23:56:52 +02:00
|
|
|
crypto_pk_env_t *pk = NULL;
|
2004-04-05 23:15:14 +02:00
|
|
|
char buf[DIGEST_LEN+9];
|
|
|
|
char expected_digest[DIGEST_LEN];
|
|
|
|
char pk_digest[DIGEST_LEN];
|
2004-10-14 04:47:09 +02:00
|
|
|
size_t asn1len;
|
2006-07-26 21:05:41 +02:00
|
|
|
or_circuit_t *c;
|
2007-11-29 16:25:04 +01:00
|
|
|
char serviceid[REND_SERVICE_ID_LEN_BASE32+1];
|
2006-01-05 22:23:03 +01:00
|
|
|
int reason = END_CIRC_REASON_INTERNAL;
|
2004-04-02 23:56:52 +02:00
|
|
|
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Received an ESTABLISH_INTRO request on circuit %d",
|
|
|
|
circ->p_circ_id);
|
2004-04-03 01:30:54 +02:00
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
if (circ->_base.purpose != CIRCUIT_PURPOSE_OR || circ->_base.n_conn) {
|
2006-01-23 10:26:22 +01:00
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
2005-12-14 21:40:40 +01:00
|
|
|
"Rejecting ESTABLISH_INTRO on non-OR or non-edge circuit.");
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2004-04-05 23:15:14 +02:00
|
|
|
if (request_len < 2+DIGEST_LEN)
|
2004-04-02 23:56:52 +02:00
|
|
|
goto truncated;
|
|
|
|
/* First 2 bytes: length of asn1-encoded key. */
|
2004-04-08 06:47:39 +02:00
|
|
|
asn1len = ntohs(get_uint16(request));
|
2004-04-02 23:56:52 +02:00
|
|
|
|
|
|
|
/* Next asn1len bytes: asn1-encoded key. */
|
2004-04-05 23:15:14 +02:00
|
|
|
if (request_len < 2+DIGEST_LEN+asn1len)
|
2004-04-02 23:56:52 +02:00
|
|
|
goto truncated;
|
|
|
|
pk = crypto_pk_asn1_decode(request+2, asn1len);
|
|
|
|
if (!pk) {
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL, "Couldn't decode public key.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next 20 bytes: Hash of handshake_digest | "INTRODUCE" */
|
2004-04-05 23:15:14 +02:00
|
|
|
memcpy(buf, circ->handshake_digest, DIGEST_LEN);
|
|
|
|
memcpy(buf+DIGEST_LEN, "INTRODUCE", 9);
|
2004-11-02 03:28:51 +01:00
|
|
|
if (crypto_digest(expected_digest, buf, DIGEST_LEN+9) < 0) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_BUG, "Internal error computing digest.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2004-04-05 23:15:14 +02:00
|
|
|
if (memcmp(expected_digest, request+2+asn1len, DIGEST_LEN)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL, "Hash of session info was not as expected.");
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* Rest of body: signature of previous data */
|
2006-10-31 20:17:07 +01:00
|
|
|
note_crypto_pk_op(REND_MID);
|
2004-04-05 23:15:14 +02:00
|
|
|
if (crypto_pk_public_checksig_digest(pk, request, 2+asn1len+DIGEST_LEN,
|
|
|
|
request+2+DIGEST_LEN+asn1len,
|
|
|
|
request_len-(2+DIGEST_LEN+asn1len))<0) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL,
|
|
|
|
"Incorrect signature on ESTABLISH_INTRO cell; rejecting.");
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The request is valid. First, compute the hash of Bob's PK.*/
|
|
|
|
if (crypto_pk_get_digest(pk, pk_digest)<0) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_BUG, "Internal error: couldn't hash public key.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2005-05-21 00:14:33 +02:00
|
|
|
crypto_free_pk_env(pk); /* don't need it anymore */
|
|
|
|
pk = NULL; /* so we don't free it again if err */
|
|
|
|
|
2007-11-29 16:25:04 +01:00
|
|
|
base32_encode(serviceid, REND_SERVICE_ID_LEN_BASE32+1,
|
|
|
|
pk_digest, REND_SERVICE_ID_LEN);
|
2004-04-03 01:30:54 +02:00
|
|
|
|
2004-04-02 23:56:52 +02:00
|
|
|
/* Close any other intro circuits with the same pk. */
|
|
|
|
c = NULL;
|
2006-07-26 21:05:41 +02:00
|
|
|
while ((c = circuit_get_intro_point(pk_digest))) {
|
2006-07-23 09:37:35 +02:00
|
|
|
log_info(LD_REND, "Replacing old circuit for service %s",
|
|
|
|
safe_str(serviceid));
|
2006-10-17 17:20:00 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(c), END_CIRC_REASON_FINISHED);
|
2006-07-26 21:05:41 +02:00
|
|
|
/* Now it's marked, and it won't be returned next time. */
|
2004-04-02 23:56:52 +02:00
|
|
|
}
|
|
|
|
|
2004-12-01 04:48:14 +01:00
|
|
|
/* Acknowledge the request. */
|
2007-03-24 16:58:11 +01:00
|
|
|
if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
|
2004-04-03 06:55:22 +02:00
|
|
|
RELAY_COMMAND_INTRO_ESTABLISHED,
|
2007-03-24 16:58:11 +01:00
|
|
|
"", 0, NULL)<0) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_GENERAL, "Couldn't send INTRO_ESTABLISHED cell.");
|
2004-04-03 06:55:22 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-04-02 23:56:52 +02:00
|
|
|
/* Now, set up this circuit. */
|
2006-07-23 09:37:35 +02:00
|
|
|
circ->_base.purpose = CIRCUIT_PURPOSE_INTRO_POINT;
|
2006-07-26 21:05:41 +02:00
|
|
|
memcpy(circ->rend_token, pk_digest, DIGEST_LEN);
|
2004-04-02 23:56:52 +02:00
|
|
|
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Established introduction point on circuit %d for service %s",
|
|
|
|
circ->p_circ_id, safe_str(serviceid));
|
2004-04-03 01:30:54 +02:00
|
|
|
|
2004-04-01 06:07:09 +02:00
|
|
|
return 0;
|
2004-04-02 23:56:52 +02:00
|
|
|
truncated:
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL, "Rejecting truncated ESTABLISH_INTRO cell.");
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
err:
|
|
|
|
if (pk) crypto_free_pk_env(pk);
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), reason);
|
2004-04-02 23:56:52 +02:00
|
|
|
return -1;
|
2004-04-01 06:07:09 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Process an INTRODUCE1 cell by finding the corresponding introduction
|
2004-04-02 23:56:52 +02:00
|
|
|
* circuit, and relaying the body of the INTRODUCE1 cell inside an
|
|
|
|
* INTRODUCE2 cell.
|
|
|
|
*/
|
2004-04-01 06:07:09 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
rend_mid_introduce(or_circuit_t *circ, const char *request, size_t request_len)
|
2004-04-01 06:07:09 +02:00
|
|
|
{
|
2006-07-26 21:05:41 +02:00
|
|
|
or_circuit_t *intro_circ;
|
2007-11-29 16:25:04 +01:00
|
|
|
char serviceid[REND_SERVICE_ID_LEN_BASE32+1];
|
2004-04-13 01:33:47 +02:00
|
|
|
char nak_body[1];
|
2004-04-03 02:58:54 +02:00
|
|
|
|
2007-08-11 16:13:25 +02:00
|
|
|
log_info(LD_REND, "Received an INTRODUCE1 request on circuit %d",
|
|
|
|
circ->p_circ_id);
|
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
if (circ->_base.purpose != CIRCUIT_PURPOSE_OR || circ->_base.n_conn) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL,
|
|
|
|
"Rejecting INTRODUCE1 on non-OR or non-edge circuit %d.",
|
|
|
|
circ->p_circ_id);
|
2004-04-03 02:58:54 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2004-04-02 23:56:52 +02:00
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
/* We could change this to MAX_HEX_NICKNAME_LEN now that 0.0.9.x is
|
|
|
|
* obsolete; however, there isn't much reason to do so, and we're going
|
|
|
|
* to revise this protocol anyway.
|
|
|
|
*/
|
2004-04-06 05:44:36 +02:00
|
|
|
if (request_len < (DIGEST_LEN+(MAX_NICKNAME_LEN+1)+REND_COOKIE_LEN+
|
|
|
|
DH_KEY_LEN+CIPHER_KEY_LEN+PKCS1_OAEP_PADDING_OVERHEAD)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL, "Impossibly short INTRODUCE1 cell on circuit %d; "
|
|
|
|
"responding with nack.",
|
|
|
|
circ->p_circ_id);
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2007-11-29 16:25:04 +01:00
|
|
|
base32_encode(serviceid, REND_SERVICE_ID_LEN_BASE32+1,
|
|
|
|
request, REND_SERVICE_ID_LEN);
|
2004-04-12 20:10:28 +02:00
|
|
|
|
2004-04-02 23:56:52 +02:00
|
|
|
/* The first 20 bytes are all we look at: they have a hash of Bob's PK. */
|
2006-07-26 21:05:41 +02:00
|
|
|
intro_circ = circuit_get_intro_point(request);
|
|
|
|
if (!intro_circ) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"No intro circ found for INTRODUCE1 cell (%s) from circuit %d; "
|
|
|
|
"responding with nack.",
|
|
|
|
safe_str(serviceid), circ->p_circ_id);
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Sending introduction request for service %s "
|
|
|
|
"from circ %d to circ %d",
|
2006-07-23 09:37:35 +02:00
|
|
|
safe_str(serviceid), circ->p_circ_id,
|
2006-07-26 21:05:41 +02:00
|
|
|
intro_circ->p_circ_id);
|
2004-04-03 02:58:54 +02:00
|
|
|
|
2004-04-02 23:56:52 +02:00
|
|
|
/* Great. Now we just relay the cell down the circuit. */
|
2007-03-24 16:58:11 +01:00
|
|
|
if (relay_send_command_from_edge(0, TO_CIRCUIT(intro_circ),
|
2004-04-02 23:56:52 +02:00
|
|
|
RELAY_COMMAND_INTRODUCE2,
|
2007-03-24 16:58:11 +01:00
|
|
|
request, request_len, NULL)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_GENERAL,
|
|
|
|
"Unable to send INTRODUCE2 cell to Tor client.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2004-10-24 21:08:07 +02:00
|
|
|
/* And sent an ack down Alice's circuit. Empty body means succeeded. */
|
2007-03-24 16:58:11 +01:00
|
|
|
if (relay_send_command_from_edge(0,TO_CIRCUIT(circ),
|
2006-07-23 09:37:35 +02:00
|
|
|
RELAY_COMMAND_INTRODUCE_ACK,
|
2007-03-24 16:58:11 +01:00
|
|
|
NULL,0,NULL)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_GENERAL, "Unable to send INTRODUCE_ACK cell to Tor client.");
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
|
2004-04-13 01:33:47 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2004-04-02 23:56:52 +02:00
|
|
|
|
2004-04-01 06:07:09 +02:00
|
|
|
return 0;
|
2004-04-02 23:56:52 +02:00
|
|
|
err:
|
2004-04-27 01:02:20 +02:00
|
|
|
/* Send the client an NACK */
|
2004-04-13 01:33:47 +02:00
|
|
|
nak_body[0] = 1;
|
2007-03-24 16:58:11 +01:00
|
|
|
if (relay_send_command_from_edge(0,TO_CIRCUIT(circ),
|
2006-07-23 09:37:35 +02:00
|
|
|
RELAY_COMMAND_INTRODUCE_ACK,
|
2007-03-24 16:58:11 +01:00
|
|
|
nak_body, 1, NULL)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_GENERAL, "Unable to send NAK to Tor client.");
|
2006-01-05 22:23:03 +01:00
|
|
|
/* Is this right? */
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
|
2004-04-13 01:33:47 +02:00
|
|
|
}
|
2004-04-02 23:56:52 +02:00
|
|
|
return -1;
|
2004-04-01 06:07:09 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Process an ESTABLISH_RENDEZVOUS cell by setting the circuit's purpose and
|
2004-04-02 23:56:52 +02:00
|
|
|
* rendezvous cookie.
|
|
|
|
*/
|
2004-04-01 06:07:09 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
rend_mid_establish_rendezvous(or_circuit_t *circ, const char *request,
|
2005-12-14 21:40:40 +01:00
|
|
|
size_t request_len)
|
2004-04-01 06:07:09 +02:00
|
|
|
{
|
2004-04-03 02:58:54 +02:00
|
|
|
char hexid[9];
|
2006-01-05 22:23:03 +01:00
|
|
|
int reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-03 02:58:54 +02:00
|
|
|
|
2007-08-11 16:13:25 +02:00
|
|
|
log_info(LD_REND, "Received an ESTABLISH_RENDEZVOUS request on circuit %d",
|
|
|
|
circ->p_circ_id);
|
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
if (circ->_base.purpose != CIRCUIT_PURPOSE_OR || circ->_base.n_conn) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL,
|
|
|
|
"Tried to establish rendezvous on non-OR or non-edge circuit.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_len != REND_COOKIE_LEN) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL, "Invalid length on ESTABLISH_RENDEZVOUS.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (circuit_get_rendezvous(request)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL,
|
|
|
|
"Duplicate rendezvous cookie in ESTABLISH_RENDEZVOUS.");
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-12-01 04:48:14 +01:00
|
|
|
/* Acknowledge the request. */
|
2007-03-24 16:58:11 +01:00
|
|
|
if (relay_send_command_from_edge(0,TO_CIRCUIT(circ),
|
2004-04-03 06:55:22 +02:00
|
|
|
RELAY_COMMAND_RENDEZVOUS_ESTABLISHED,
|
2007-03-24 16:58:11 +01:00
|
|
|
"", 0, NULL)<0) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_PROTOCOL, "Couldn't send RENDEZVOUS_ESTABLISHED cell.");
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_INTERNAL;
|
2004-04-03 06:55:22 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
circ->_base.purpose = CIRCUIT_PURPOSE_REND_POINT_WAITING;
|
2006-07-26 21:05:41 +02:00
|
|
|
memcpy(circ->rend_token, request, REND_COOKIE_LEN);
|
2004-04-02 23:56:52 +02:00
|
|
|
|
2004-08-07 03:03:33 +02:00
|
|
|
base16_encode(hexid,9,request,4);
|
2004-04-12 20:10:28 +02:00
|
|
|
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Established rendezvous point on circuit %d for cookie %s",
|
|
|
|
circ->p_circ_id, hexid);
|
2004-04-03 02:58:54 +02:00
|
|
|
|
2004-04-01 06:07:09 +02:00
|
|
|
return 0;
|
2004-04-02 23:56:52 +02:00
|
|
|
err:
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), reason);
|
2004-04-02 23:56:52 +02:00
|
|
|
return -1;
|
2004-04-01 06:07:09 +02:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Process a RENDEZVOUS1 cell by looking up the correct rendezvous
|
2004-05-05 23:32:43 +02:00
|
|
|
* circuit by its relaying the cell's body in a RENDEZVOUS2 cell, and
|
|
|
|
* connecting the two circuits.
|
2004-04-02 23:56:52 +02:00
|
|
|
*/
|
2004-04-01 06:07:09 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
rend_mid_rendezvous(or_circuit_t *circ, const char *request,
|
|
|
|
size_t request_len)
|
2004-04-01 06:07:09 +02:00
|
|
|
{
|
2006-07-23 09:37:35 +02:00
|
|
|
or_circuit_t *rend_circ;
|
2004-04-03 02:58:54 +02:00
|
|
|
char hexid[9];
|
2006-01-05 22:23:03 +01:00
|
|
|
int reason = END_CIRC_REASON_INTERNAL;
|
2004-08-07 03:12:04 +02:00
|
|
|
base16_encode(hexid,9,request,request_len<4?request_len:4);
|
|
|
|
|
2004-04-03 02:58:54 +02:00
|
|
|
if (request_len>=4) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Got request for rendezvous from circuit %d to cookie %s.",
|
|
|
|
circ->p_circ_id, hexid);
|
2004-04-03 02:58:54 +02:00
|
|
|
}
|
2004-04-02 23:56:52 +02:00
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
if (circ->_base.purpose != CIRCUIT_PURPOSE_OR || circ->_base.n_conn) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Tried to complete rendezvous on non-OR or non-edge circuit %d.",
|
|
|
|
circ->p_circ_id);
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2004-04-05 23:40:22 +02:00
|
|
|
if (request_len != REND_COOKIE_LEN+DH_KEY_LEN+DIGEST_LEN) {
|
2006-01-23 10:26:22 +01:00
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
2005-10-19 00:56:40 +02:00
|
|
|
"Rejecting RENDEZVOUS1 cell with bad length (%d) on circuit %d.",
|
|
|
|
(int)request_len, circ->p_circ_id);
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
rend_circ = circuit_get_rendezvous(request);
|
|
|
|
if (!rend_circ) {
|
2006-01-23 10:26:22 +01:00
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
2005-10-19 00:56:40 +02:00
|
|
|
"Rejecting RENDEZVOUS1 cell with unrecognized rendezvous cookie %s.",
|
|
|
|
hexid);
|
2006-01-05 22:23:03 +01:00
|
|
|
reason = END_CIRC_REASON_TORPROTOCOL;
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the RENDEZVOUS2 cell to Alice. */
|
2007-03-24 16:58:11 +01:00
|
|
|
if (relay_send_command_from_edge(0, TO_CIRCUIT(rend_circ),
|
2004-04-02 23:56:52 +02:00
|
|
|
RELAY_COMMAND_RENDEZVOUS2,
|
2004-04-06 05:44:36 +02:00
|
|
|
request+REND_COOKIE_LEN,
|
2007-03-24 16:58:11 +01:00
|
|
|
request_len-REND_COOKIE_LEN, NULL)) {
|
2006-02-13 11:33:00 +01:00
|
|
|
log_warn(LD_GENERAL,
|
2006-09-07 03:00:37 +02:00
|
|
|
"Unable to send RENDEZVOUS2 cell to client on circuit %d.",
|
2006-02-13 11:33:00 +01:00
|
|
|
rend_circ->p_circ_id);
|
2004-04-02 23:56:52 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Join the circuits. */
|
2006-02-13 11:33:00 +01:00
|
|
|
log_info(LD_REND,
|
|
|
|
"Completing rendezvous: circuit %d joins circuit %d (cookie %s)",
|
|
|
|
circ->p_circ_id, rend_circ->p_circ_id, hexid);
|
2004-04-03 02:58:54 +02:00
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
circ->_base.purpose = CIRCUIT_PURPOSE_REND_ESTABLISHED;
|
|
|
|
rend_circ->_base.purpose = CIRCUIT_PURPOSE_REND_ESTABLISHED;
|
2006-07-26 21:05:41 +02:00
|
|
|
memset(circ->rend_token, 0, REND_COOKIE_LEN);
|
2004-04-02 23:56:52 +02:00
|
|
|
|
|
|
|
rend_circ->rend_splice = circ;
|
|
|
|
circ->rend_splice = rend_circ;
|
|
|
|
|
2004-04-01 06:07:09 +02:00
|
|
|
return 0;
|
2004-04-02 23:56:52 +02:00
|
|
|
err:
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), reason);
|
2004-04-02 23:56:52 +02:00
|
|
|
return -1;
|
2004-04-01 06:07:09 +02:00
|
|
|
}
|
2005-06-09 21:03:31 +02:00
|
|
|
|