2007-12-12 22:09:01 +01:00
|
|
|
/* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 21:13:17 +01:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2004-03-31 04:07:38 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/**
|
|
|
|
* \file rendcommon.c
|
|
|
|
* \brief Rendezvous implementation: shared code between
|
2004-05-05 23:32:43 +02:00
|
|
|
* introducers, services, clients, and rendezvous points.
|
2004-05-09 18:47:25 +02:00
|
|
|
**/
|
2004-05-05 23:32:43 +02:00
|
|
|
|
2017-06-20 16:29:20 +02:00
|
|
|
#define RENDCOMMON_PRIVATE
|
|
|
|
|
2004-03-31 04:07:38 +02:00
|
|
|
#include "or.h"
|
2010-07-22 01:21:00 +02:00
|
|
|
#include "circuitbuild.h"
|
2018-04-23 22:06:34 +02:00
|
|
|
#include "circuituse.h"
|
2010-07-22 10:22:51 +02:00
|
|
|
#include "config.h"
|
2015-07-29 15:20:51 +02:00
|
|
|
#include "control.h"
|
2018-04-06 23:23:29 +02:00
|
|
|
#include "crypto_rand.h"
|
|
|
|
#include "crypto_util.h"
|
2018-04-06 23:42:15 +02:00
|
|
|
#include "hs_client.h"
|
2016-05-31 20:51:30 +02:00
|
|
|
#include "hs_common.h"
|
2018-04-06 23:42:15 +02:00
|
|
|
#include "hs_intropoint.h"
|
|
|
|
#include "networkstatus.h"
|
2010-07-22 00:13:51 +02:00
|
|
|
#include "rendclient.h"
|
2010-07-21 17:52:54 +02:00
|
|
|
#include "rendcommon.h"
|
2010-07-23 22:03:33 +02:00
|
|
|
#include "rendmid.h"
|
2010-07-22 00:30:17 +02:00
|
|
|
#include "rendservice.h"
|
2010-07-23 22:57:20 +02:00
|
|
|
#include "rephist.h"
|
2016-02-29 07:47:51 +01:00
|
|
|
#include "router.h"
|
2010-07-21 17:08:11 +02:00
|
|
|
#include "routerlist.h"
|
2010-07-23 23:23:43 +02:00
|
|
|
#include "routerparse.h"
|
2004-03-31 04:07:38 +02:00
|
|
|
|
2004-05-12 22:58:27 +02:00
|
|
|
/** Return 0 if one and two are the same service ids, else -1 or 1 */
|
2005-09-30 03:09:52 +02:00
|
|
|
int
|
|
|
|
rend_cmp_service_ids(const char *one, const char *two)
|
|
|
|
{
|
2004-05-12 22:58:27 +02:00
|
|
|
return strcasecmp(one,two);
|
|
|
|
}
|
|
|
|
|
2004-05-10 06:34:48 +02:00
|
|
|
/** Free the storage held by the service descriptor <b>desc</b>.
|
2004-04-06 05:44:36 +02:00
|
|
|
*/
|
2005-09-30 03:09:52 +02:00
|
|
|
void
|
2017-11-21 15:37:47 +01:00
|
|
|
rend_service_descriptor_free_(rend_service_descriptor_t *desc)
|
2004-03-31 04:07:38 +02:00
|
|
|
{
|
2009-09-28 16:37:01 +02:00
|
|
|
if (!desc)
|
|
|
|
return;
|
2004-03-31 04:07:38 +02:00
|
|
|
if (desc->pk)
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_free(desc->pk);
|
2007-12-21 10:28:22 +01:00
|
|
|
if (desc->intro_nodes) {
|
|
|
|
SMARTLIST_FOREACH(desc->intro_nodes, rend_intro_point_t *, intro,
|
|
|
|
rend_intro_point_free(intro););
|
|
|
|
smartlist_free(desc->intro_nodes);
|
2007-10-28 20:48:16 +01:00
|
|
|
}
|
2008-09-09 10:41:58 +02:00
|
|
|
if (desc->successful_uploads) {
|
|
|
|
SMARTLIST_FOREACH(desc->successful_uploads, char *, c, tor_free(c););
|
|
|
|
smartlist_free(desc->successful_uploads);
|
|
|
|
}
|
2004-03-31 04:07:38 +02:00
|
|
|
tor_free(desc);
|
|
|
|
}
|
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Length of the descriptor cookie that is used for versioned hidden
|
2007-10-28 20:48:14 +01:00
|
|
|
* service descriptors. */
|
2007-10-29 20:10:42 +01:00
|
|
|
#define REND_DESC_COOKIE_LEN 16
|
2007-10-28 20:48:14 +01:00
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Length of the replica number that is used to determine the secret ID
|
2007-10-28 20:48:14 +01:00
|
|
|
* part of versioned hidden service descriptors. */
|
2007-10-29 20:10:42 +01:00
|
|
|
#define REND_REPLICA_LEN 1
|
2007-10-28 20:48:14 +01:00
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Compute the descriptor ID for <b>service_id</b> of length
|
2007-11-29 16:25:04 +01:00
|
|
|
* <b>REND_SERVICE_ID_LEN</b> and <b>secret_id_part</b> of length
|
2007-10-28 20:48:14 +01:00
|
|
|
* <b>DIGEST_LEN</b>, and write it to <b>descriptor_id_out</b> of length
|
|
|
|
* <b>DIGEST_LEN</b>. */
|
|
|
|
void
|
|
|
|
rend_get_descriptor_id_bytes(char *descriptor_id_out,
|
|
|
|
const char *service_id,
|
|
|
|
const char *secret_id_part)
|
|
|
|
{
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_t *digest = crypto_digest_new();
|
2007-11-29 16:25:04 +01:00
|
|
|
crypto_digest_add_bytes(digest, service_id, REND_SERVICE_ID_LEN);
|
2007-10-28 20:48:14 +01:00
|
|
|
crypto_digest_add_bytes(digest, secret_id_part, DIGEST_LEN);
|
|
|
|
crypto_digest_get_digest(digest, descriptor_id_out, DIGEST_LEN);
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_free(digest);
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Compute the secret ID part for time_period,
|
|
|
|
* a <b>descriptor_cookie</b> of length
|
2007-10-29 20:10:42 +01:00
|
|
|
* <b>REND_DESC_COOKIE_LEN</b> which may also be <b>NULL</b> if no
|
2007-10-28 20:48:14 +01:00
|
|
|
* descriptor_cookie shall be used, and <b>replica</b>, and write it to
|
|
|
|
* <b>secret_id_part</b> of length DIGEST_LEN. */
|
|
|
|
static void
|
2007-10-28 20:48:16 +01:00
|
|
|
get_secret_id_part_bytes(char *secret_id_part, uint32_t time_period,
|
2007-10-28 20:48:14 +01:00
|
|
|
const char *descriptor_cookie, uint8_t replica)
|
|
|
|
{
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_t *digest = crypto_digest_new();
|
2007-10-28 20:48:16 +01:00
|
|
|
time_period = htonl(time_period);
|
|
|
|
crypto_digest_add_bytes(digest, (char*)&time_period, sizeof(uint32_t));
|
2007-10-28 20:48:14 +01:00
|
|
|
if (descriptor_cookie) {
|
|
|
|
crypto_digest_add_bytes(digest, descriptor_cookie,
|
2007-10-29 20:10:42 +01:00
|
|
|
REND_DESC_COOKIE_LEN);
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
2007-10-29 20:10:42 +01:00
|
|
|
crypto_digest_add_bytes(digest, (const char *)&replica, REND_REPLICA_LEN);
|
2007-10-28 20:48:14 +01:00
|
|
|
crypto_digest_get_digest(digest, secret_id_part, DIGEST_LEN);
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_free(digest);
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Return the time period for time <b>now</b> plus a potentially
|
|
|
|
* intended <b>deviation</b> of one or more periods, based on the first byte
|
|
|
|
* of <b>service_id</b>. */
|
|
|
|
static uint32_t
|
|
|
|
get_time_period(time_t now, uint8_t deviation, const char *service_id)
|
2007-10-28 20:48:14 +01:00
|
|
|
{
|
2007-10-28 20:48:16 +01:00
|
|
|
/* The time period is the number of REND_TIME_PERIOD_V2_DESC_VALIDITY
|
|
|
|
* intervals that have passed since the epoch, offset slightly so that
|
|
|
|
* each service's time periods start and end at a fraction of that
|
|
|
|
* period based on their first byte. */
|
|
|
|
return (uint32_t)
|
2007-10-28 20:48:14 +01:00
|
|
|
(now + ((uint8_t) *service_id) * REND_TIME_PERIOD_V2_DESC_VALIDITY / 256)
|
|
|
|
/ REND_TIME_PERIOD_V2_DESC_VALIDITY + deviation;
|
|
|
|
}
|
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Compute the time in seconds that a descriptor that is generated
|
2007-10-28 20:48:14 +01:00
|
|
|
* <b>now</b> for <b>service_id</b> will be valid. */
|
|
|
|
static uint32_t
|
|
|
|
get_seconds_valid(time_t now, const char *service_id)
|
|
|
|
{
|
|
|
|
uint32_t result = REND_TIME_PERIOD_V2_DESC_VALIDITY -
|
2007-10-28 20:48:16 +01:00
|
|
|
((uint32_t)
|
|
|
|
(now + ((uint8_t) *service_id) * REND_TIME_PERIOD_V2_DESC_VALIDITY / 256)
|
|
|
|
% REND_TIME_PERIOD_V2_DESC_VALIDITY);
|
2007-10-28 20:48:14 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-10-28 20:48:16 +01:00
|
|
|
/** Compute the binary <b>desc_id_out</b> (DIGEST_LEN bytes long) for a given
|
|
|
|
* base32-encoded <b>service_id</b> and optional unencoded
|
2007-10-29 20:10:42 +01:00
|
|
|
* <b>descriptor_cookie</b> of length REND_DESC_COOKIE_LEN,
|
2007-10-28 20:48:16 +01:00
|
|
|
* at time <b>now</b> for replica number
|
2007-10-28 20:48:14 +01:00
|
|
|
* <b>replica</b>. <b>desc_id</b> needs to have <b>DIGEST_LEN</b> bytes
|
|
|
|
* free. Return 0 for success, -1 otherwise. */
|
|
|
|
int
|
|
|
|
rend_compute_v2_desc_id(char *desc_id_out, const char *service_id,
|
|
|
|
const char *descriptor_cookie, time_t now,
|
|
|
|
uint8_t replica)
|
|
|
|
{
|
2007-11-29 16:25:04 +01:00
|
|
|
char service_id_binary[REND_SERVICE_ID_LEN];
|
2007-10-28 20:48:14 +01:00
|
|
|
char secret_id_part[DIGEST_LEN];
|
2007-10-28 20:48:16 +01:00
|
|
|
uint32_t time_period;
|
2007-10-28 20:48:14 +01:00
|
|
|
if (!service_id ||
|
2007-11-29 16:25:04 +01:00
|
|
|
strlen(service_id) != REND_SERVICE_ID_LEN_BASE32) {
|
2007-10-28 20:48:14 +01:00
|
|
|
log_warn(LD_REND, "Could not compute v2 descriptor ID: "
|
2009-09-28 15:08:32 +02:00
|
|
|
"Illegal service ID: %s",
|
2009-12-15 23:23:36 +01:00
|
|
|
safe_str(service_id));
|
2007-10-28 20:48:14 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (replica >= REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS) {
|
|
|
|
log_warn(LD_REND, "Could not compute v2 descriptor ID: "
|
|
|
|
"Replica number out of range: %d", replica);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Convert service ID to binary. */
|
2007-11-29 16:25:04 +01:00
|
|
|
if (base32_decode(service_id_binary, REND_SERVICE_ID_LEN,
|
|
|
|
service_id, REND_SERVICE_ID_LEN_BASE32) < 0) {
|
2007-10-28 20:48:14 +01:00
|
|
|
log_warn(LD_REND, "Could not compute v2 descriptor ID: "
|
|
|
|
"Illegal characters in service ID: %s",
|
2009-12-15 23:23:36 +01:00
|
|
|
safe_str_client(service_id));
|
2007-10-28 20:48:14 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Calculate current time-period. */
|
2007-10-28 20:48:16 +01:00
|
|
|
time_period = get_time_period(now, 0, service_id_binary);
|
2015-05-11 17:32:00 +02:00
|
|
|
/* Calculate secret-id-part = h(time-period | desc-cookie | replica). */
|
2007-10-28 20:48:14 +01:00
|
|
|
get_secret_id_part_bytes(secret_id_part, time_period, descriptor_cookie,
|
|
|
|
replica);
|
2015-05-11 17:32:00 +02:00
|
|
|
/* Calculate descriptor ID: H(permanent-id | secret-id-part) */
|
2007-10-28 20:48:14 +01:00
|
|
|
rend_get_descriptor_id_bytes(desc_id_out, service_id_binary, secret_id_part);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-19 17:41:28 +02:00
|
|
|
/** Encode the introduction points in <b>desc</b> and write the result to a
|
|
|
|
* newly allocated string pointed to by <b>encoded</b>. Return 0 for
|
|
|
|
* success, -1 otherwise. */
|
2007-10-28 20:48:14 +01:00
|
|
|
static int
|
2008-08-19 17:41:28 +02:00
|
|
|
rend_encode_v2_intro_points(char **encoded, rend_service_descriptor_t *desc)
|
2007-10-28 20:48:14 +01:00
|
|
|
{
|
|
|
|
size_t unenc_len;
|
2007-10-28 20:48:16 +01:00
|
|
|
char *unenc = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
size_t unenc_written = 0;
|
|
|
|
int i;
|
2007-10-28 20:48:16 +01:00
|
|
|
int r = -1;
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Assemble unencrypted list of introduction points. */
|
2007-12-21 10:28:22 +01:00
|
|
|
unenc_len = smartlist_len(desc->intro_nodes) * 1000; /* too long, but ok. */
|
2007-10-28 20:48:14 +01:00
|
|
|
unenc = tor_malloc_zero(unenc_len);
|
2007-12-21 10:28:22 +01:00
|
|
|
for (i = 0; i < smartlist_len(desc->intro_nodes); i++) {
|
2007-10-29 20:10:42 +01:00
|
|
|
char id_base32[REND_INTRO_POINT_ID_LEN_BASE32 + 1];
|
2007-10-28 20:48:16 +01:00
|
|
|
char *onion_key = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
size_t onion_key_len;
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_t *intro_key;
|
2007-10-28 20:48:16 +01:00
|
|
|
char *service_key = NULL;
|
2007-11-27 22:17:43 +01:00
|
|
|
char *address = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
size_t service_key_len;
|
|
|
|
int res;
|
2007-12-21 10:28:22 +01:00
|
|
|
rend_intro_point_t *intro = smartlist_get(desc->intro_nodes, i);
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Obtain extend info with introduction point details. */
|
2007-12-21 10:28:22 +01:00
|
|
|
extend_info_t *info = intro->extend_info;
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Encode introduction point ID. */
|
2007-10-28 20:48:16 +01:00
|
|
|
base32_encode(id_base32, sizeof(id_base32),
|
|
|
|
info->identity_digest, DIGEST_LEN);
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Encode onion key. */
|
|
|
|
if (crypto_pk_write_public_key_to_string(info->onion_key, &onion_key,
|
|
|
|
&onion_key_len) < 0) {
|
|
|
|
log_warn(LD_REND, "Could not write onion key.");
|
2007-10-28 20:48:16 +01:00
|
|
|
goto done;
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
/* Encode intro key. */
|
2007-12-21 10:28:22 +01:00
|
|
|
intro_key = intro->intro_key;
|
2007-10-28 20:48:14 +01:00
|
|
|
if (!intro_key ||
|
|
|
|
crypto_pk_write_public_key_to_string(intro_key, &service_key,
|
|
|
|
&service_key_len) < 0) {
|
|
|
|
log_warn(LD_REND, "Could not write intro key.");
|
|
|
|
tor_free(onion_key);
|
2007-10-28 20:48:16 +01:00
|
|
|
goto done;
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
/* Assemble everything for this introduction point. */
|
2016-03-28 22:36:51 +02:00
|
|
|
address = tor_addr_to_str_dup(&info->addr);
|
2007-10-28 20:48:14 +01:00
|
|
|
res = tor_snprintf(unenc + unenc_written, unenc_len - unenc_written,
|
|
|
|
"introduction-point %s\n"
|
|
|
|
"ip-address %s\n"
|
|
|
|
"onion-port %d\n"
|
|
|
|
"onion-key\n%s"
|
|
|
|
"service-key\n%s",
|
|
|
|
id_base32,
|
2007-11-27 22:17:43 +01:00
|
|
|
address,
|
2007-10-28 20:48:14 +01:00
|
|
|
info->port,
|
|
|
|
onion_key,
|
|
|
|
service_key);
|
2007-11-27 22:17:43 +01:00
|
|
|
tor_free(address);
|
2007-10-28 20:48:14 +01:00
|
|
|
tor_free(onion_key);
|
|
|
|
tor_free(service_key);
|
|
|
|
if (res < 0) {
|
|
|
|
log_warn(LD_REND, "Not enough space for writing introduction point "
|
|
|
|
"string.");
|
2007-10-28 20:48:16 +01:00
|
|
|
goto done;
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
/* Update total number of written bytes for unencrypted intro points. */
|
|
|
|
unenc_written += res;
|
|
|
|
}
|
|
|
|
/* Finalize unencrypted introduction points. */
|
|
|
|
if (unenc_len < unenc_written + 2) {
|
|
|
|
log_warn(LD_REND, "Not enough space for finalizing introduction point "
|
|
|
|
"string.");
|
2007-10-28 20:48:16 +01:00
|
|
|
goto done;
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
unenc[unenc_written++] = '\n';
|
|
|
|
unenc[unenc_written++] = 0;
|
2008-08-19 17:41:28 +02:00
|
|
|
*encoded = unenc;
|
|
|
|
r = 0;
|
|
|
|
done:
|
|
|
|
if (r<0)
|
|
|
|
tor_free(unenc);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Encrypt the encoded introduction points in <b>encoded</b> using
|
|
|
|
* authorization type 'basic' with <b>client_cookies</b> and write the
|
|
|
|
* result to a newly allocated string pointed to by <b>encrypted_out</b> of
|
2008-08-19 21:01:41 +02:00
|
|
|
* length <b>encrypted_len_out</b>. Return 0 for success, -1 otherwise. */
|
2008-08-19 17:41:28 +02:00
|
|
|
static int
|
|
|
|
rend_encrypt_v2_intro_points_basic(char **encrypted_out,
|
|
|
|
size_t *encrypted_len_out,
|
|
|
|
const char *encoded,
|
|
|
|
smartlist_t *client_cookies)
|
|
|
|
{
|
|
|
|
int r = -1, i, pos, enclen, client_blocks;
|
|
|
|
size_t len, client_entries_len;
|
|
|
|
char *enc = NULL, iv[CIPHER_IV_LEN], *client_part = NULL,
|
|
|
|
session_key[CIPHER_KEY_LEN];
|
|
|
|
smartlist_t *encrypted_session_keys = NULL;
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_t *digest;
|
|
|
|
crypto_cipher_t *cipher;
|
2008-08-19 17:41:28 +02:00
|
|
|
tor_assert(encoded);
|
|
|
|
tor_assert(client_cookies && smartlist_len(client_cookies) > 0);
|
|
|
|
|
|
|
|
/* Generate session key. */
|
2015-11-25 16:42:00 +01:00
|
|
|
crypto_rand(session_key, CIPHER_KEY_LEN);
|
2008-08-19 17:41:28 +02:00
|
|
|
|
|
|
|
/* Determine length of encrypted introduction points including session
|
|
|
|
* keys. */
|
|
|
|
client_blocks = 1 + ((smartlist_len(client_cookies) - 1) /
|
|
|
|
REND_BASIC_AUTH_CLIENT_MULTIPLE);
|
|
|
|
client_entries_len = client_blocks * REND_BASIC_AUTH_CLIENT_MULTIPLE *
|
|
|
|
REND_BASIC_AUTH_CLIENT_ENTRY_LEN;
|
|
|
|
len = 2 + client_entries_len + CIPHER_IV_LEN + strlen(encoded);
|
|
|
|
if (client_blocks >= 256) {
|
|
|
|
log_warn(LD_REND, "Too many clients in introduction point string.");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
enc = tor_malloc_zero(len);
|
|
|
|
enc[0] = 0x01; /* type of authorization. */
|
|
|
|
enc[1] = (uint8_t)client_blocks;
|
|
|
|
|
|
|
|
/* Encrypt with random session key. */
|
2012-03-20 20:35:43 +01:00
|
|
|
enclen = crypto_cipher_encrypt_with_iv(session_key,
|
2008-08-19 17:41:28 +02:00
|
|
|
enc + 2 + client_entries_len,
|
|
|
|
CIPHER_IV_LEN + strlen(encoded), encoded, strlen(encoded));
|
2012-03-20 20:35:43 +01:00
|
|
|
|
2008-08-19 17:41:28 +02:00
|
|
|
if (enclen < 0) {
|
|
|
|
log_warn(LD_REND, "Could not encrypt introduction point string.");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy(iv, enc + 2 + client_entries_len, CIPHER_IV_LEN);
|
|
|
|
|
|
|
|
/* Encrypt session key for cookies, determine client IDs, and put both
|
|
|
|
* in a smartlist. */
|
2012-01-18 21:53:30 +01:00
|
|
|
encrypted_session_keys = smartlist_new();
|
2008-08-19 17:41:28 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(client_cookies, const char *, cookie) {
|
|
|
|
client_part = tor_malloc_zero(REND_BASIC_AUTH_CLIENT_ENTRY_LEN);
|
|
|
|
/* Encrypt session key. */
|
2012-03-20 20:35:43 +01:00
|
|
|
cipher = crypto_cipher_new(cookie);
|
2008-08-19 17:41:28 +02:00
|
|
|
if (crypto_cipher_encrypt(cipher, client_part +
|
|
|
|
REND_BASIC_AUTH_CLIENT_ID_LEN,
|
|
|
|
session_key, CIPHER_KEY_LEN) < 0) {
|
|
|
|
log_warn(LD_REND, "Could not encrypt session key for client.");
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_cipher_free(cipher);
|
2008-08-19 17:41:28 +02:00
|
|
|
tor_free(client_part);
|
|
|
|
goto done;
|
|
|
|
}
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_cipher_free(cipher);
|
2008-08-19 17:41:28 +02:00
|
|
|
|
|
|
|
/* Determine client ID. */
|
2012-01-18 21:53:30 +01:00
|
|
|
digest = crypto_digest_new();
|
2008-08-19 17:41:28 +02:00
|
|
|
crypto_digest_add_bytes(digest, cookie, REND_DESC_COOKIE_LEN);
|
|
|
|
crypto_digest_add_bytes(digest, iv, CIPHER_IV_LEN);
|
|
|
|
crypto_digest_get_digest(digest, client_part,
|
|
|
|
REND_BASIC_AUTH_CLIENT_ID_LEN);
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_free(digest);
|
2008-08-19 17:41:28 +02:00
|
|
|
|
|
|
|
/* Put both together. */
|
|
|
|
smartlist_add(encrypted_session_keys, client_part);
|
|
|
|
} SMARTLIST_FOREACH_END(cookie);
|
|
|
|
|
|
|
|
/* Add some fake client IDs and encrypted session keys. */
|
|
|
|
for (i = (smartlist_len(client_cookies) - 1) %
|
|
|
|
REND_BASIC_AUTH_CLIENT_MULTIPLE;
|
|
|
|
i < REND_BASIC_AUTH_CLIENT_MULTIPLE - 1; i++) {
|
|
|
|
client_part = tor_malloc_zero(REND_BASIC_AUTH_CLIENT_ENTRY_LEN);
|
2015-11-25 16:42:00 +01:00
|
|
|
crypto_rand(client_part, REND_BASIC_AUTH_CLIENT_ENTRY_LEN);
|
2008-08-19 17:41:28 +02:00
|
|
|
smartlist_add(encrypted_session_keys, client_part);
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
2008-08-19 17:41:28 +02:00
|
|
|
/* Sort smartlist and put elements in result in order. */
|
|
|
|
smartlist_sort_digests(encrypted_session_keys);
|
|
|
|
pos = 2;
|
|
|
|
SMARTLIST_FOREACH(encrypted_session_keys, const char *, entry, {
|
|
|
|
memcpy(enc + pos, entry, REND_BASIC_AUTH_CLIENT_ENTRY_LEN);
|
|
|
|
pos += REND_BASIC_AUTH_CLIENT_ENTRY_LEN;
|
|
|
|
});
|
|
|
|
*encrypted_out = enc;
|
|
|
|
*encrypted_len_out = len;
|
|
|
|
enc = NULL; /* prevent free. */
|
|
|
|
r = 0;
|
|
|
|
done:
|
|
|
|
tor_free(enc);
|
|
|
|
if (encrypted_session_keys) {
|
|
|
|
SMARTLIST_FOREACH(encrypted_session_keys, char *, d, tor_free(d););
|
|
|
|
smartlist_free(encrypted_session_keys);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Encrypt the encoded introduction points in <b>encoded</b> using
|
|
|
|
* authorization type 'stealth' with <b>descriptor_cookie</b> of length
|
|
|
|
* REND_DESC_COOKIE_LEN and write the result to a newly allocated string
|
2008-08-19 21:01:41 +02:00
|
|
|
* pointed to by <b>encrypted_out</b> of length <b>encrypted_len_out</b>.
|
|
|
|
* Return 0 for success, -1 otherwise. */
|
2008-08-19 17:41:28 +02:00
|
|
|
static int
|
|
|
|
rend_encrypt_v2_intro_points_stealth(char **encrypted_out,
|
|
|
|
size_t *encrypted_len_out,
|
|
|
|
const char *encoded,
|
|
|
|
const char *descriptor_cookie)
|
|
|
|
{
|
|
|
|
int r = -1, enclen;
|
|
|
|
char *enc;
|
|
|
|
tor_assert(encoded);
|
|
|
|
tor_assert(descriptor_cookie);
|
|
|
|
|
|
|
|
enc = tor_malloc_zero(1 + CIPHER_IV_LEN + strlen(encoded));
|
|
|
|
enc[0] = 0x02; /* Auth type */
|
2012-03-20 20:35:43 +01:00
|
|
|
enclen = crypto_cipher_encrypt_with_iv(descriptor_cookie,
|
|
|
|
enc + 1,
|
2008-08-19 17:41:28 +02:00
|
|
|
CIPHER_IV_LEN+strlen(encoded),
|
|
|
|
encoded, strlen(encoded));
|
|
|
|
if (enclen < 0) {
|
|
|
|
log_warn(LD_REND, "Could not encrypt introduction point string.");
|
2007-10-28 20:48:16 +01:00
|
|
|
goto done;
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
2008-08-19 17:41:28 +02:00
|
|
|
*encrypted_out = enc;
|
|
|
|
*encrypted_len_out = enclen;
|
|
|
|
enc = NULL; /* prevent free */
|
2007-10-28 20:48:16 +01:00
|
|
|
r = 0;
|
|
|
|
done:
|
2008-08-19 17:41:28 +02:00
|
|
|
tor_free(enc);
|
2007-10-28 20:48:16 +01:00
|
|
|
return r;
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Attempt to parse the given <b>desc_str</b> and return true if this
|
|
|
|
* succeeds, false otherwise. */
|
2017-06-20 16:29:20 +02:00
|
|
|
STATIC int
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_desc_v2_is_parsable(rend_encoded_v2_service_descriptor_t *desc)
|
2007-10-28 20:48:14 +01:00
|
|
|
{
|
2007-10-28 20:48:16 +01:00
|
|
|
rend_service_descriptor_t *test_parsed = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
char test_desc_id[DIGEST_LEN];
|
2007-10-28 20:48:16 +01:00
|
|
|
char *test_intro_content = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
size_t test_intro_size;
|
|
|
|
size_t test_encoded_size;
|
|
|
|
const char *test_next;
|
|
|
|
int res = rend_parse_v2_service_descriptor(&test_parsed, test_desc_id,
|
|
|
|
&test_intro_content,
|
|
|
|
&test_intro_size,
|
|
|
|
&test_encoded_size,
|
2013-07-19 05:45:40 +02:00
|
|
|
&test_next, desc->desc_str, 1);
|
2009-12-12 08:07:59 +01:00
|
|
|
rend_service_descriptor_free(test_parsed);
|
2007-10-28 20:48:14 +01:00
|
|
|
tor_free(test_intro_content);
|
|
|
|
return (res >= 0);
|
|
|
|
}
|
|
|
|
|
2007-12-15 21:28:09 +01:00
|
|
|
/** Free the storage held by an encoded v2 service descriptor. */
|
|
|
|
void
|
2017-11-21 15:37:47 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free_(
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_t *desc)
|
|
|
|
{
|
2009-09-28 16:37:01 +02:00
|
|
|
if (!desc)
|
|
|
|
return;
|
2007-12-15 21:50:56 +01:00
|
|
|
tor_free(desc->desc_str);
|
2007-12-15 21:28:09 +01:00
|
|
|
tor_free(desc);
|
|
|
|
}
|
|
|
|
|
2007-12-21 10:28:22 +01:00
|
|
|
/** Free the storage held by an introduction point info. */
|
|
|
|
void
|
2017-11-21 15:37:47 +01:00
|
|
|
rend_intro_point_free_(rend_intro_point_t *intro)
|
2007-12-21 10:28:22 +01:00
|
|
|
{
|
2009-09-28 16:37:01 +02:00
|
|
|
if (!intro)
|
|
|
|
return;
|
2009-12-12 08:07:59 +01:00
|
|
|
|
|
|
|
extend_info_free(intro->extend_info);
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_free(intro->intro_key);
|
2011-10-30 02:02:53 +02:00
|
|
|
|
2011-11-27 18:26:48 +01:00
|
|
|
if (intro->accepted_intro_rsa_parts != NULL) {
|
2012-07-11 04:18:47 +02:00
|
|
|
replaycache_free(intro->accepted_intro_rsa_parts);
|
2011-10-30 02:02:53 +02:00
|
|
|
}
|
|
|
|
|
2007-12-21 10:28:22 +01:00
|
|
|
tor_free(intro);
|
|
|
|
}
|
|
|
|
|
2007-12-15 21:28:09 +01:00
|
|
|
/** Encode a set of rend_encoded_v2_service_descriptor_t's for <b>desc</b>
|
2008-08-19 17:41:28 +02:00
|
|
|
* at time <b>now</b> using <b>service_key</b>, depending on
|
|
|
|
* <b>auth_type</b> a <b>descriptor_cookie</b> and a list of
|
|
|
|
* <b>client_cookies</b> (which are both <b>NULL</b> if no client
|
|
|
|
* authorization is performed), and <b>period</b> (e.g. 0 for the current
|
|
|
|
* period, 1 for the next period, etc.) and add them to the existing list
|
|
|
|
* <b>descs_out</b>; return the number of seconds that the descriptors will
|
|
|
|
* be found by clients, or -1 if the encoding was not successful. */
|
2007-10-28 20:48:14 +01:00
|
|
|
int
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encode_v2_descriptors(smartlist_t *descs_out,
|
2007-10-28 20:48:14 +01:00
|
|
|
rend_service_descriptor_t *desc, time_t now,
|
2008-08-19 17:41:28 +02:00
|
|
|
uint8_t period, rend_auth_type_t auth_type,
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_t *client_key,
|
2008-08-19 17:41:28 +02:00
|
|
|
smartlist_t *client_cookies)
|
2007-10-28 20:48:14 +01:00
|
|
|
{
|
|
|
|
char service_id[DIGEST_LEN];
|
2015-07-29 15:20:51 +02:00
|
|
|
char service_id_base32[REND_SERVICE_ID_LEN_BASE32+1];
|
2007-10-28 20:48:16 +01:00
|
|
|
uint32_t time_period;
|
2008-08-19 17:41:28 +02:00
|
|
|
char *ipos_base64 = NULL, *ipos = NULL, *ipos_encrypted = NULL,
|
|
|
|
*descriptor_cookie = NULL;
|
|
|
|
size_t ipos_len = 0, ipos_encrypted_len = 0;
|
2007-10-28 20:48:14 +01:00
|
|
|
int k;
|
|
|
|
uint32_t seconds_valid;
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_t *service_key;
|
2010-02-23 17:09:02 +01:00
|
|
|
if (!desc) {
|
|
|
|
log_warn(LD_BUG, "Could not encode v2 descriptor: No desc given.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
service_key = (auth_type == REND_STEALTH_AUTH) ? client_key : desc->pk;
|
2008-08-19 17:41:28 +02:00
|
|
|
tor_assert(service_key);
|
|
|
|
if (auth_type == REND_STEALTH_AUTH) {
|
|
|
|
descriptor_cookie = smartlist_get(client_cookies, 0);
|
|
|
|
tor_assert(descriptor_cookie);
|
|
|
|
}
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Obtain service_id from public key. */
|
2017-08-09 15:24:16 +02:00
|
|
|
if (crypto_pk_get_digest(service_key, service_id) < 0) {
|
|
|
|
log_warn(LD_BUG, "Couldn't compute service key digest.");
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Calculate current time-period. */
|
2007-10-28 20:48:16 +01:00
|
|
|
time_period = get_time_period(now, period, service_id);
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Determine how many seconds the descriptor will be valid. */
|
|
|
|
seconds_valid = period * REND_TIME_PERIOD_V2_DESC_VALIDITY +
|
|
|
|
get_seconds_valid(now, service_id);
|
|
|
|
/* Assemble, possibly encrypt, and encode introduction points. */
|
2008-08-19 17:41:28 +02:00
|
|
|
if (smartlist_len(desc->intro_nodes) > 0) {
|
|
|
|
if (rend_encode_v2_intro_points(&ipos, desc) < 0) {
|
|
|
|
log_warn(LD_REND, "Encoding of introduction points did not succeed.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch (auth_type) {
|
|
|
|
case REND_NO_AUTH:
|
|
|
|
ipos_len = strlen(ipos);
|
|
|
|
break;
|
|
|
|
case REND_BASIC_AUTH:
|
|
|
|
if (rend_encrypt_v2_intro_points_basic(&ipos_encrypted,
|
|
|
|
&ipos_encrypted_len, ipos,
|
|
|
|
client_cookies) < 0) {
|
|
|
|
log_warn(LD_REND, "Encrypting of introduction points did not "
|
|
|
|
"succeed.");
|
|
|
|
tor_free(ipos);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
tor_free(ipos);
|
|
|
|
ipos = ipos_encrypted;
|
|
|
|
ipos_len = ipos_encrypted_len;
|
|
|
|
break;
|
|
|
|
case REND_STEALTH_AUTH:
|
|
|
|
if (rend_encrypt_v2_intro_points_stealth(&ipos_encrypted,
|
|
|
|
&ipos_encrypted_len, ipos,
|
|
|
|
descriptor_cookie) < 0) {
|
|
|
|
log_warn(LD_REND, "Encrypting of introduction points did not "
|
|
|
|
"succeed.");
|
|
|
|
tor_free(ipos);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
tor_free(ipos);
|
|
|
|
ipos = ipos_encrypted;
|
|
|
|
ipos_len = ipos_encrypted_len;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_warn(LD_REND|LD_BUG, "Unrecognized authorization type %d",
|
|
|
|
(int)auth_type);
|
|
|
|
tor_free(ipos);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Base64-encode introduction points. */
|
2014-08-13 16:36:06 +02:00
|
|
|
ipos_base64 = tor_calloc(ipos_len, 2);
|
2015-04-10 13:25:08 +02:00
|
|
|
if (base64_encode(ipos_base64, ipos_len * 2, ipos, ipos_len,
|
|
|
|
BASE64_ENCODE_MULTILINE)<0) {
|
2008-08-19 17:41:28 +02:00
|
|
|
log_warn(LD_REND, "Could not encode introduction point string to "
|
2008-08-20 07:15:08 +02:00
|
|
|
"base64. length=%d", (int)ipos_len);
|
2008-08-19 17:41:28 +02:00
|
|
|
tor_free(ipos_base64);
|
|
|
|
tor_free(ipos);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
tor_free(ipos);
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
/* Encode REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS descriptors. */
|
|
|
|
for (k = 0; k < REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS; k++) {
|
|
|
|
char secret_id_part[DIGEST_LEN];
|
2007-10-29 20:10:42 +01:00
|
|
|
char secret_id_part_base32[REND_SECRET_ID_PART_LEN_BASE32 + 1];
|
2007-10-31 21:48:06 +01:00
|
|
|
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
2007-10-28 20:48:16 +01:00
|
|
|
char *permanent_key = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
size_t permanent_key_len;
|
|
|
|
char published[ISO_TIME_LEN+1];
|
|
|
|
int i;
|
|
|
|
char protocol_versions_string[16]; /* max len: "0,1,2,3,4,5,6,7\0" */
|
|
|
|
size_t protocol_versions_written;
|
|
|
|
size_t desc_len;
|
2007-10-28 20:48:16 +01:00
|
|
|
char *desc_str = NULL;
|
2007-10-28 20:48:14 +01:00
|
|
|
int result = 0;
|
|
|
|
size_t written = 0;
|
|
|
|
char desc_digest[DIGEST_LEN];
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_t *enc =
|
|
|
|
tor_malloc_zero(sizeof(rend_encoded_v2_service_descriptor_t));
|
2014-09-23 02:09:03 +02:00
|
|
|
/* Calculate secret-id-part = h(time-period | cookie | replica). */
|
2007-10-28 20:48:14 +01:00
|
|
|
get_secret_id_part_bytes(secret_id_part, time_period, descriptor_cookie,
|
|
|
|
k);
|
2007-10-29 20:10:47 +01:00
|
|
|
base32_encode(secret_id_part_base32, sizeof(secret_id_part_base32),
|
2007-10-28 20:48:14 +01:00
|
|
|
secret_id_part, DIGEST_LEN);
|
|
|
|
/* Calculate descriptor ID. */
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_get_descriptor_id_bytes(enc->desc_id, service_id, secret_id_part);
|
2007-10-31 21:48:06 +01:00
|
|
|
base32_encode(desc_id_base32, sizeof(desc_id_base32),
|
2007-12-15 21:28:09 +01:00
|
|
|
enc->desc_id, DIGEST_LEN);
|
2007-10-28 20:48:14 +01:00
|
|
|
/* PEM-encode the public key */
|
2008-08-19 17:41:28 +02:00
|
|
|
if (crypto_pk_write_public_key_to_string(service_key, &permanent_key,
|
2007-10-28 20:48:14 +01:00
|
|
|
&permanent_key_len) < 0) {
|
|
|
|
log_warn(LD_BUG, "Could not write public key to string.");
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-10-28 20:48:14 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* Encode timestamp. */
|
|
|
|
format_iso_time(published, desc->timestamp);
|
|
|
|
/* Write protocol-versions bitmask to comma-separated value string. */
|
|
|
|
protocol_versions_written = 0;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (desc->protocols & 1 << i) {
|
|
|
|
tor_snprintf(protocol_versions_string + protocol_versions_written,
|
|
|
|
16 - protocol_versions_written, "%d,", i);
|
|
|
|
protocol_versions_written += 2;
|
|
|
|
}
|
|
|
|
}
|
2007-10-28 20:48:16 +01:00
|
|
|
if (protocol_versions_written)
|
|
|
|
protocol_versions_string[protocol_versions_written - 1] = '\0';
|
|
|
|
else
|
|
|
|
protocol_versions_string[0]= '\0';
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Assemble complete descriptor. */
|
2007-12-21 10:28:22 +01:00
|
|
|
desc_len = 2000 + smartlist_len(desc->intro_nodes) * 1000; /* far too long,
|
|
|
|
but okay.*/
|
2007-12-15 21:28:09 +01:00
|
|
|
enc->desc_str = desc_str = tor_malloc_zero(desc_len);
|
2007-10-28 20:48:14 +01:00
|
|
|
result = tor_snprintf(desc_str, desc_len,
|
|
|
|
"rendezvous-service-descriptor %s\n"
|
|
|
|
"version 2\n"
|
|
|
|
"permanent-key\n%s"
|
|
|
|
"secret-id-part %s\n"
|
|
|
|
"publication-time %s\n"
|
2007-11-27 22:06:34 +01:00
|
|
|
"protocol-versions %s\n",
|
2007-10-28 20:48:14 +01:00
|
|
|
desc_id_base32,
|
|
|
|
permanent_key,
|
|
|
|
secret_id_part_base32,
|
|
|
|
published,
|
2007-11-27 22:06:34 +01:00
|
|
|
protocol_versions_string);
|
2007-10-28 20:48:14 +01:00
|
|
|
tor_free(permanent_key);
|
|
|
|
if (result < 0) {
|
|
|
|
log_warn(LD_BUG, "Descriptor ran out of room.");
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-10-28 20:48:14 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
written = result;
|
2007-11-27 22:06:34 +01:00
|
|
|
/* Add introduction points. */
|
|
|
|
if (ipos_base64) {
|
|
|
|
result = tor_snprintf(desc_str + written, desc_len - written,
|
|
|
|
"introduction-points\n"
|
|
|
|
"-----BEGIN MESSAGE-----\n%s"
|
|
|
|
"-----END MESSAGE-----\n",
|
|
|
|
ipos_base64);
|
|
|
|
if (result < 0) {
|
|
|
|
log_warn(LD_BUG, "could not write introduction points.");
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-11-27 22:06:34 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
written += result;
|
|
|
|
}
|
2007-10-28 20:48:14 +01:00
|
|
|
/* Add signature. */
|
|
|
|
strlcpy(desc_str + written, "signature\n", desc_len - written);
|
|
|
|
written += strlen(desc_str + written);
|
|
|
|
if (crypto_digest(desc_digest, desc_str, written) < 0) {
|
|
|
|
log_warn(LD_BUG, "could not create digest.");
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-10-28 20:48:14 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (router_append_dirobj_signature(desc_str + written,
|
|
|
|
desc_len - written,
|
2009-09-14 17:57:19 +02:00
|
|
|
desc_digest, DIGEST_LEN,
|
|
|
|
service_key) < 0) {
|
2007-10-28 20:48:14 +01:00
|
|
|
log_warn(LD_BUG, "Couldn't sign desc.");
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-10-28 20:48:14 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
written += strlen(desc_str+written);
|
|
|
|
if (written+2 > desc_len) {
|
|
|
|
log_warn(LD_BUG, "Could not finish desc.");
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-10-28 20:48:14 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
desc_str[written++] = 0;
|
|
|
|
/* Check if we can parse our own descriptor. */
|
2007-12-15 21:28:09 +01:00
|
|
|
if (!rend_desc_v2_is_parsable(enc)) {
|
2007-10-28 20:48:14 +01:00
|
|
|
log_warn(LD_BUG, "Could not parse my own descriptor: %s", desc_str);
|
2007-12-15 21:28:09 +01:00
|
|
|
rend_encoded_v2_service_descriptor_free(enc);
|
2007-10-28 20:48:14 +01:00
|
|
|
goto err;
|
|
|
|
}
|
2007-12-15 21:28:09 +01:00
|
|
|
smartlist_add(descs_out, enc);
|
2015-07-29 15:20:51 +02:00
|
|
|
/* Add the uploaded descriptor to the local service's descriptor cache */
|
|
|
|
rend_cache_store_v2_desc_as_service(enc->desc_str);
|
|
|
|
base32_encode(service_id_base32, sizeof(service_id_base32),
|
|
|
|
service_id, REND_SERVICE_ID_LEN);
|
2015-08-04 14:47:51 +02:00
|
|
|
control_event_hs_descriptor_created(service_id_base32, desc_id_base32, k);
|
2007-10-28 20:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
log_info(LD_REND, "Successfully encoded a v2 descriptor and "
|
2007-11-27 22:17:43 +01:00
|
|
|
"confirmed that it is parsable.");
|
2007-10-28 20:48:14 +01:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
err:
|
2007-12-15 21:28:09 +01:00
|
|
|
SMARTLIST_FOREACH(descs_out, rend_encoded_v2_service_descriptor_t *, d,
|
|
|
|
rend_encoded_v2_service_descriptor_free(d););
|
|
|
|
smartlist_clear(descs_out);
|
2007-10-28 20:48:14 +01:00
|
|
|
seconds_valid = -1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
tor_free(ipos_base64);
|
|
|
|
return seconds_valid;
|
|
|
|
}
|
|
|
|
|
2004-05-10 06:34:48 +02:00
|
|
|
/** Sets <b>out</b> to the first 10 bytes of the digest of <b>pk</b>,
|
|
|
|
* base32 encoded. NUL-terminates out. (We use this string to
|
|
|
|
* identify services in directory requests and .onion URLs.)
|
2004-04-06 05:44:36 +02:00
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2012-01-18 21:53:30 +01:00
|
|
|
rend_get_service_id(crypto_pk_t *pk, char *out)
|
2004-03-31 05:42:56 +02:00
|
|
|
{
|
2004-04-03 04:40:30 +02:00
|
|
|
char buf[DIGEST_LEN];
|
2004-04-25 22:37:37 +02:00
|
|
|
tor_assert(pk);
|
2004-03-31 05:42:56 +02:00
|
|
|
if (crypto_pk_get_digest(pk, buf) < 0)
|
|
|
|
return -1;
|
2007-11-29 16:25:04 +01:00
|
|
|
base32_encode(out, REND_SERVICE_ID_LEN_BASE32+1, buf, REND_SERVICE_ID_LEN);
|
2004-03-31 05:42:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-10 06:34:48 +02:00
|
|
|
/** Return true iff <b>query</b> is a syntactically valid service ID (as
|
2004-05-05 23:32:43 +02:00
|
|
|
* generated by rend_get_service_id). */
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2017-06-01 12:21:03 +02:00
|
|
|
rend_valid_v2_service_id(const char *query)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2007-11-29 16:25:04 +01:00
|
|
|
if (strlen(query) != REND_SERVICE_ID_LEN_BASE32)
|
2004-04-01 21:39:11 +02:00
|
|
|
return 0;
|
|
|
|
|
2007-11-29 16:25:04 +01:00
|
|
|
if (strspn(query, BASE32_CHARS) != REND_SERVICE_ID_LEN_BASE32)
|
2004-04-03 01:30:54 +02:00
|
|
|
return 0;
|
|
|
|
|
2004-04-01 21:39:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-21 20:04:39 +02:00
|
|
|
/** Return true iff <b>query</b> is a syntactically valid descriptor ID.
|
|
|
|
* (as generated by rend_get_descriptor_id_bytes). */
|
|
|
|
int
|
|
|
|
rend_valid_descriptor_id(const char *query)
|
|
|
|
{
|
|
|
|
if (strlen(query) != REND_DESC_ID_V2_LEN_BASE32) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
if (strspn(query, BASE32_CHARS) != REND_DESC_ID_V2_LEN_BASE32) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2015-04-30 19:38:39 +02:00
|
|
|
invalid:
|
2015-04-21 20:04:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-20 00:32:25 +01:00
|
|
|
/** Return true iff <b>client_name</b> is a syntactically valid name
|
|
|
|
* for rendezvous client authentication. */
|
|
|
|
int
|
|
|
|
rend_valid_client_name(const char *client_name)
|
|
|
|
{
|
|
|
|
size_t len = strlen(client_name);
|
|
|
|
if (len < 1 || len > REND_CLIENTNAME_MAX_LEN) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (strspn(client_name, REND_LEGAL_CLIENTNAME_CHARACTERS) != len) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-05-09 18:47:25 +02:00
|
|
|
/** Called when we get a rendezvous-related relay cell on circuit
|
2004-05-10 06:34:48 +02:00
|
|
|
* <b>circ</b>. Dispatch on rendezvous relay command. */
|
2005-06-11 20:52:12 +02:00
|
|
|
void
|
2008-10-27 17:46:45 +01:00
|
|
|
rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint,
|
|
|
|
int command, size_t length,
|
2010-12-14 01:34:01 +01:00
|
|
|
const uint8_t *payload)
|
2004-04-03 05:37:11 +02:00
|
|
|
{
|
2006-07-23 09:37:35 +02:00
|
|
|
or_circuit_t *or_circ = NULL;
|
|
|
|
origin_circuit_t *origin_circ = NULL;
|
2007-08-31 16:20:44 +02:00
|
|
|
int r = -2;
|
2008-10-27 17:46:45 +01:00
|
|
|
if (CIRCUIT_IS_ORIGIN(circ)) {
|
2006-07-23 09:37:35 +02:00
|
|
|
origin_circ = TO_ORIGIN_CIRCUIT(circ);
|
2008-10-27 17:57:18 +01:00
|
|
|
if (!layer_hint || layer_hint != origin_circ->cpath->prev) {
|
2008-10-27 17:46:45 +01:00
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_APP,
|
|
|
|
"Relay cell (rend purpose %d) from wrong hop on origin circ",
|
|
|
|
command);
|
|
|
|
origin_circ = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2006-07-23 09:37:35 +02:00
|
|
|
or_circ = TO_OR_CIRCUIT(circ);
|
2008-10-27 17:46:45 +01:00
|
|
|
}
|
2006-07-23 09:37:35 +02:00
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
switch (command) {
|
2004-04-03 05:37:11 +02:00
|
|
|
case RELAY_COMMAND_ESTABLISH_INTRO:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (or_circ)
|
2016-11-02 16:37:50 +01:00
|
|
|
r = hs_intro_received_establish_intro(or_circ,payload,length);
|
2004-04-03 05:37:11 +02:00
|
|
|
break;
|
|
|
|
case RELAY_COMMAND_ESTABLISH_RENDEZVOUS:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (or_circ)
|
|
|
|
r = rend_mid_establish_rendezvous(or_circ,payload,length);
|
2004-04-03 05:37:11 +02:00
|
|
|
break;
|
|
|
|
case RELAY_COMMAND_INTRODUCE1:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (or_circ)
|
2016-11-10 22:04:23 +01:00
|
|
|
r = hs_intro_received_introduce1(or_circ,payload,length);
|
2004-04-03 05:37:11 +02:00
|
|
|
break;
|
|
|
|
case RELAY_COMMAND_INTRODUCE2:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (origin_circ)
|
2017-03-07 20:57:14 +01:00
|
|
|
r = hs_service_receive_introduce2(origin_circ,payload,length);
|
2004-04-03 05:37:11 +02:00
|
|
|
break;
|
2004-04-13 01:33:47 +02:00
|
|
|
case RELAY_COMMAND_INTRODUCE_ACK:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (origin_circ)
|
2017-07-21 23:48:18 +02:00
|
|
|
r = hs_client_receive_introduce_ack(origin_circ,payload,length);
|
2004-04-13 01:33:47 +02:00
|
|
|
break;
|
2004-04-03 05:37:11 +02:00
|
|
|
case RELAY_COMMAND_RENDEZVOUS1:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (or_circ)
|
|
|
|
r = rend_mid_rendezvous(or_circ,payload,length);
|
2004-04-03 05:37:11 +02:00
|
|
|
break;
|
|
|
|
case RELAY_COMMAND_RENDEZVOUS2:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (origin_circ)
|
2017-07-25 16:14:00 +02:00
|
|
|
r = hs_client_receive_rendezvous2(origin_circ,payload,length);
|
2004-04-03 05:37:11 +02:00
|
|
|
break;
|
2004-04-03 06:55:22 +02:00
|
|
|
case RELAY_COMMAND_INTRO_ESTABLISHED:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (origin_circ)
|
2017-03-07 20:33:03 +01:00
|
|
|
r = hs_service_receive_intro_established(origin_circ,payload,length);
|
2004-04-03 06:55:22 +02:00
|
|
|
break;
|
|
|
|
case RELAY_COMMAND_RENDEZVOUS_ESTABLISHED:
|
2007-08-31 16:20:44 +02:00
|
|
|
if (origin_circ)
|
2017-07-21 20:20:37 +02:00
|
|
|
r = hs_client_receive_rendezvous_acked(origin_circ,payload,length);
|
2004-04-03 06:55:22 +02:00
|
|
|
break;
|
2004-04-03 05:37:11 +02:00
|
|
|
default:
|
2007-08-31 16:20:44 +02:00
|
|
|
tor_fragile_assert();
|
2004-04-03 05:37:11 +02:00
|
|
|
}
|
2006-10-09 04:35:51 +02:00
|
|
|
|
2018-04-23 22:06:34 +02:00
|
|
|
if (r == 0 && origin_circ) {
|
|
|
|
/* This was a valid cell. Count it as delivered + overhead. */
|
|
|
|
circuit_read_valid_data(origin_circ, length);
|
|
|
|
}
|
|
|
|
|
2007-08-31 16:20:44 +02:00
|
|
|
if (r == -2)
|
|
|
|
log_info(LD_PROTOCOL, "Dropping cell (type %d) for wrong circuit type.",
|
|
|
|
command);
|
2004-04-03 05:37:11 +02:00
|
|
|
}
|
2005-06-09 21:03:31 +02:00
|
|
|
|
2016-02-29 07:47:51 +01:00
|
|
|
/** Determine the routers that are responsible for <b>id</b> (binary) and
|
|
|
|
* add pointers to those routers' routerstatus_t to <b>responsible_dirs</b>.
|
|
|
|
* Return -1 if we're returning an empty smartlist, else return 0.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
|
|
|
const char *id)
|
|
|
|
{
|
|
|
|
int start, found, n_added = 0, i;
|
|
|
|
networkstatus_t *c = networkstatus_get_latest_consensus();
|
|
|
|
if (!c || !smartlist_len(c->routerstatus_list)) {
|
|
|
|
log_warn(LD_REND, "We don't have a consensus, so we can't perform v2 "
|
|
|
|
"rendezvous operations.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
tor_assert(id);
|
|
|
|
start = networkstatus_vote_find_entry_idx(c, id, &found);
|
|
|
|
if (start == smartlist_len(c->routerstatus_list)) start = 0;
|
|
|
|
i = start;
|
|
|
|
do {
|
|
|
|
routerstatus_t *r = smartlist_get(c->routerstatus_list, i);
|
|
|
|
if (r->is_hs_dir) {
|
|
|
|
smartlist_add(responsible_dirs, r);
|
|
|
|
if (++n_added == REND_NUMBER_OF_CONSECUTIVE_REPLICAS)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (++i == smartlist_len(c->routerstatus_list))
|
|
|
|
i = 0;
|
|
|
|
} while (i != start);
|
|
|
|
|
|
|
|
/* Even though we don't have the desired number of hidden service
|
|
|
|
* directories, be happy if we got any. */
|
|
|
|
return smartlist_len(responsible_dirs) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2015-04-14 05:35:06 +02:00
|
|
|
/* Length of the 'extended' auth cookie used to encode auth type before
|
|
|
|
* base64 encoding. */
|
|
|
|
#define REND_DESC_COOKIE_LEN_EXT (REND_DESC_COOKIE_LEN + 1)
|
|
|
|
/* Length of the zero-padded auth cookie when base64 encoded. These two
|
|
|
|
* padding bytes always (A=) are stripped off of the returned cookie. */
|
|
|
|
#define REND_DESC_COOKIE_LEN_EXT_BASE64 (REND_DESC_COOKIE_LEN_BASE64 + 2)
|
|
|
|
|
|
|
|
/** Encode a client authorization descriptor cookie.
|
|
|
|
* The result of this function is suitable for use in the HidServAuth
|
|
|
|
* option. The trailing padding characters are removed, and the
|
|
|
|
* auth type is encoded into the cookie.
|
|
|
|
*
|
|
|
|
* Returns a new base64-encoded cookie. This function cannot fail.
|
|
|
|
* The caller is responsible for freeing the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
rend_auth_encode_cookie(const uint8_t *cookie_in, rend_auth_type_t auth_type)
|
|
|
|
{
|
|
|
|
uint8_t extended_cookie[REND_DESC_COOKIE_LEN_EXT];
|
|
|
|
char *cookie_out = tor_malloc_zero(REND_DESC_COOKIE_LEN_EXT_BASE64 + 1);
|
|
|
|
int re;
|
|
|
|
|
|
|
|
tor_assert(cookie_in);
|
|
|
|
|
|
|
|
memcpy(extended_cookie, cookie_in, REND_DESC_COOKIE_LEN);
|
|
|
|
extended_cookie[REND_DESC_COOKIE_LEN] = ((int)auth_type - 1) << 4;
|
|
|
|
re = base64_encode(cookie_out, REND_DESC_COOKIE_LEN_EXT_BASE64 + 1,
|
|
|
|
(const char *) extended_cookie, REND_DESC_COOKIE_LEN_EXT,
|
|
|
|
0);
|
|
|
|
tor_assert(re == REND_DESC_COOKIE_LEN_EXT_BASE64);
|
|
|
|
|
|
|
|
/* Remove the trailing 'A='. Auth type is encoded in the high bits
|
|
|
|
* of the last byte, so the last base64 character will always be zero
|
|
|
|
* (A). This is subtly different behavior from base64_encode_nopad. */
|
|
|
|
cookie_out[REND_DESC_COOKIE_LEN_BASE64] = '\0';
|
|
|
|
memwipe(extended_cookie, 0, sizeof(extended_cookie));
|
|
|
|
return cookie_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Decode a base64-encoded client authorization descriptor cookie.
|
|
|
|
* The descriptor_cookie can be truncated to REND_DESC_COOKIE_LEN_BASE64
|
|
|
|
* characters (as given to clients), or may include the two padding
|
|
|
|
* characters (as stored by the service).
|
|
|
|
*
|
|
|
|
* The result is stored in REND_DESC_COOKIE_LEN bytes of cookie_out.
|
|
|
|
* The rend_auth_type_t decoded from the cookie is stored in the
|
|
|
|
* optional auth_type_out parameter.
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error. The caller is responsible for
|
|
|
|
* freeing the returned err_msg.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rend_auth_decode_cookie(const char *cookie_in, uint8_t *cookie_out,
|
|
|
|
rend_auth_type_t *auth_type_out, char **err_msg_out)
|
|
|
|
{
|
|
|
|
uint8_t descriptor_cookie_decoded[REND_DESC_COOKIE_LEN_EXT + 1] = { 0 };
|
|
|
|
char descriptor_cookie_base64ext[REND_DESC_COOKIE_LEN_EXT_BASE64 + 1];
|
|
|
|
const char *descriptor_cookie = cookie_in;
|
|
|
|
char *err_msg = NULL;
|
|
|
|
int auth_type_val = 0;
|
|
|
|
int res = -1;
|
|
|
|
int decoded_len;
|
|
|
|
|
|
|
|
size_t len = strlen(descriptor_cookie);
|
|
|
|
if (len == REND_DESC_COOKIE_LEN_BASE64) {
|
|
|
|
/* Add a trailing zero byte to make base64-decoding happy. */
|
|
|
|
tor_snprintf(descriptor_cookie_base64ext,
|
|
|
|
sizeof(descriptor_cookie_base64ext),
|
|
|
|
"%sA=", descriptor_cookie);
|
|
|
|
descriptor_cookie = descriptor_cookie_base64ext;
|
|
|
|
} else if (len != REND_DESC_COOKIE_LEN_EXT_BASE64) {
|
|
|
|
tor_asprintf(&err_msg, "Authorization cookie has wrong length: %s",
|
|
|
|
escaped(cookie_in));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoded_len = base64_decode((char *) descriptor_cookie_decoded,
|
|
|
|
sizeof(descriptor_cookie_decoded),
|
|
|
|
descriptor_cookie,
|
|
|
|
REND_DESC_COOKIE_LEN_EXT_BASE64);
|
|
|
|
if (decoded_len != REND_DESC_COOKIE_LEN &&
|
|
|
|
decoded_len != REND_DESC_COOKIE_LEN_EXT) {
|
|
|
|
tor_asprintf(&err_msg, "Authorization cookie has invalid characters: %s",
|
|
|
|
escaped(cookie_in));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth_type_out) {
|
|
|
|
auth_type_val = (descriptor_cookie_decoded[REND_DESC_COOKIE_LEN] >> 4) + 1;
|
|
|
|
if (auth_type_val < 1 || auth_type_val > 2) {
|
|
|
|
tor_asprintf(&err_msg, "Authorization cookie type is unknown: %s",
|
|
|
|
escaped(cookie_in));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
*auth_type_out = auth_type_val == 1 ? REND_BASIC_AUTH : REND_STEALTH_AUTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(cookie_out, descriptor_cookie_decoded, REND_DESC_COOKIE_LEN);
|
|
|
|
res = 0;
|
|
|
|
err:
|
|
|
|
if (err_msg_out) {
|
|
|
|
*err_msg_out = err_msg;
|
|
|
|
} else {
|
|
|
|
tor_free(err_msg);
|
|
|
|
}
|
|
|
|
memwipe(descriptor_cookie_decoded, 0, sizeof(descriptor_cookie_decoded));
|
|
|
|
memwipe(descriptor_cookie_base64ext, 0, sizeof(descriptor_cookie_base64ext));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-07-14 06:04:02 +02:00
|
|
|
/* Is this a rend client or server that allows direct (non-anonymous)
|
|
|
|
* connections?
|
|
|
|
* Clients must be specifically compiled and configured in this mode.
|
|
|
|
* Onion services can be configured to start in this mode.
|
|
|
|
* Prefer rend_client_allow_non_anonymous_connection() or
|
|
|
|
* rend_service_allow_non_anonymous_connection() whenever possible, so that
|
|
|
|
* checks are specific to Single Onion Services or Tor2web. */
|
|
|
|
int
|
|
|
|
rend_allow_non_anonymous_connection(const or_options_t* options)
|
|
|
|
{
|
|
|
|
return (rend_client_allow_non_anonymous_connection(options)
|
|
|
|
|| rend_service_allow_non_anonymous_connection(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this a rend client or server in non-anonymous mode?
|
|
|
|
* Clients must be specifically compiled in this mode.
|
|
|
|
* Onion services can be configured to start in this mode.
|
|
|
|
* Prefer rend_client_non_anonymous_mode_enabled() or
|
|
|
|
* rend_service_non_anonymous_mode_enabled() whenever possible, so that checks
|
|
|
|
* are specific to Single Onion Services or Tor2web. */
|
|
|
|
int
|
|
|
|
rend_non_anonymous_mode_enabled(const or_options_t *options)
|
|
|
|
{
|
|
|
|
return (rend_client_non_anonymous_mode_enabled(options)
|
|
|
|
|| rend_service_non_anonymous_mode_enabled(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that tor only builds one-hop circuits when they would not
|
|
|
|
* compromise user anonymity.
|
|
|
|
*
|
2016-09-13 09:20:46 +02:00
|
|
|
* One-hop circuits are permitted in Tor2web or Single Onion modes.
|
2016-07-14 06:04:02 +02:00
|
|
|
*
|
2016-09-13 09:20:46 +02:00
|
|
|
* Tor2web or Single Onion modes are also allowed to make multi-hop circuits.
|
|
|
|
* For example, single onion HSDir circuits are 3-hop to prevent denial of
|
|
|
|
* service.
|
2016-07-14 06:04:02 +02:00
|
|
|
*/
|
|
|
|
void
|
2017-06-29 19:29:23 +02:00
|
|
|
assert_circ_anonymity_ok(const origin_circuit_t *circ,
|
2016-07-14 06:04:02 +02:00
|
|
|
const or_options_t *options)
|
|
|
|
{
|
|
|
|
tor_assert(options);
|
|
|
|
tor_assert(circ);
|
|
|
|
tor_assert(circ->build_state);
|
|
|
|
|
|
|
|
if (circ->build_state->onehop_tunnel) {
|
|
|
|
tor_assert(rend_allow_non_anonymous_connection(options));
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 16:24:45 +02:00
|
|
|
|
2016-05-31 20:51:30 +02:00
|
|
|
/* Return 1 iff the given <b>digest</b> of a permenanent hidden service key is
|
|
|
|
* equal to the digest in the origin circuit <b>ocirc</b> of its rend data .
|
|
|
|
* If the rend data doesn't exist, 0 is returned. This function is agnostic to
|
|
|
|
* the rend data version. */
|
|
|
|
int
|
|
|
|
rend_circuit_pk_digest_eq(const origin_circuit_t *ocirc,
|
|
|
|
const uint8_t *digest)
|
|
|
|
{
|
|
|
|
size_t rend_pk_digest_len;
|
|
|
|
const uint8_t *rend_pk_digest;
|
|
|
|
|
|
|
|
tor_assert(ocirc);
|
|
|
|
tor_assert(digest);
|
|
|
|
|
|
|
|
if (ocirc->rend_data == NULL) {
|
|
|
|
goto no_match;
|
|
|
|
}
|
|
|
|
|
|
|
|
rend_pk_digest = rend_data_get_pk_digest(ocirc->rend_data,
|
|
|
|
&rend_pk_digest_len);
|
|
|
|
if (tor_memeq(rend_pk_digest, digest, rend_pk_digest_len)) {
|
|
|
|
goto match;
|
|
|
|
}
|
|
|
|
no_match:
|
|
|
|
return 0;
|
|
|
|
match:
|
|
|
|
return 1;
|
|
|
|
}
|
2016-08-25 00:44:34 +02:00
|
|
|
|