mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Merge remote-tracking branch 'arma/ticket18332-try3'
This commit is contained in:
commit
ddd30f966a
10
changes/ticket18332
Normal file
10
changes/ticket18332
Normal file
@ -0,0 +1,10 @@
|
||||
o Removed features:
|
||||
- Streamline relay-side hsdir handling: when relays consider whether
|
||||
to accept an uploaded hidden service descriptor, they no longer
|
||||
check whether they are one of the relays in the network that is
|
||||
"supposed" to handle that descriptor. Implements ticket 18332.
|
||||
|
||||
o Minor bugfixes:
|
||||
- Bridges now refuse "rendezvous2" (hidden service descriptor)
|
||||
publish attempts. Suggested by ticket 18332.
|
||||
|
@ -2297,11 +2297,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
||||
{
|
||||
rend_cache_entry_t *entry = NULL;
|
||||
|
||||
switch (rend_cache_store_v2_desc_as_client(body,
|
||||
conn->requested_resource, conn->rend_data,
|
||||
&entry)) {
|
||||
case RCS_BADDESC:
|
||||
case RCS_NOTDIR: /* Impossible */
|
||||
if (rend_cache_store_v2_desc_as_client(body,
|
||||
conn->requested_resource, conn->rend_data, &entry) < 0) {
|
||||
log_warn(LD_REND,"Fetching v2 rendezvous descriptor failed. "
|
||||
"Retrying at another directory.");
|
||||
/* We'll retry when connection_about_to_close_connection()
|
||||
@ -2309,11 +2306,9 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
||||
SEND_HS_DESC_FAILED_EVENT("BAD_DESC");
|
||||
SEND_HS_DESC_FAILED_CONTENT();
|
||||
break;
|
||||
case RCS_OKAY:
|
||||
default:
|
||||
{
|
||||
} else {
|
||||
char service_id[REND_SERVICE_ID_LEN_BASE32 + 1];
|
||||
/* Should never be NULL here for an OKAY returned code. */
|
||||
/* Should never be NULL here if we found the descriptor. */
|
||||
tor_assert(entry);
|
||||
rend_get_service_id(entry->parsed->pk, service_id);
|
||||
|
||||
@ -2331,7 +2326,6 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
||||
rend_client_desc_trynow(service_id);
|
||||
memwipe(service_id, 0, sizeof(service_id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3418,6 +3412,13 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
|
||||
|
||||
conn->base_.state = DIR_CONN_STATE_SERVER_WRITING;
|
||||
|
||||
if (!public_server_mode(options)) {
|
||||
log_info(LD_DIR, "Rejected dir post request from %s "
|
||||
"since we're not a public relay.", conn->base_.address);
|
||||
write_http_status_line(conn, 503, "Not acting as a public relay");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (parse_http_url(headers, &url) < 0) {
|
||||
write_http_status_line(conn, 400, "Bad request");
|
||||
return 0;
|
||||
@ -3427,22 +3428,12 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
|
||||
/* Handle v2 rendezvous service publish request. */
|
||||
if (connection_dir_is_encrypted(conn) &&
|
||||
!strcmpstart(url,"/tor/rendezvous2/publish")) {
|
||||
switch (rend_cache_store_v2_desc_as_dir(body)) {
|
||||
case RCS_NOTDIR:
|
||||
log_info(LD_REND, "Rejected v2 rend descriptor (length %d) from %s "
|
||||
"since we're not currently a hidden service directory.",
|
||||
(int)body_len, conn->base_.address);
|
||||
write_http_status_line(conn, 503, "Currently not acting as v2 "
|
||||
"hidden service directory");
|
||||
break;
|
||||
case RCS_BADDESC:
|
||||
if (rend_cache_store_v2_desc_as_dir(body) < 0) {
|
||||
log_warn(LD_REND, "Rejected v2 rend descriptor (length %d) from %s.",
|
||||
(int)body_len, conn->base_.address);
|
||||
write_http_status_line(conn, 400,
|
||||
"Invalid v2 service descriptor rejected");
|
||||
break;
|
||||
case RCS_OKAY:
|
||||
default:
|
||||
} else {
|
||||
write_http_status_line(conn, 200, "Service descriptor (v2) stored");
|
||||
log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
|
||||
}
|
||||
|
@ -483,8 +483,7 @@ rend_cache_clean_v2_descs_as_dir(time_t now, size_t force_remove)
|
||||
digestmap_iter_get(iter, &key, &val);
|
||||
ent = val;
|
||||
if (ent->parsed->timestamp < cutoff ||
|
||||
ent->last_served < last_served_cutoff ||
|
||||
!hid_serv_responsible_for_desc_id(key)) {
|
||||
ent->last_served < last_served_cutoff) {
|
||||
char key_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
||||
base32_encode(key_base32, sizeof(key_base32), key, DIGEST_LEN);
|
||||
log_info(LD_REND, "Removing descriptor with ID '%s' from cache",
|
||||
@ -623,9 +622,11 @@ rend_cache_lookup_v2_desc_as_dir(const char *desc_id, const char **desc)
|
||||
* If we have a newer descriptor with the same ID, ignore this one.
|
||||
* If we have an older descriptor with the same ID, replace it.
|
||||
*
|
||||
* Return an appropriate rend_cache_store_status_t.
|
||||
* Return 0 on success, or -1 if we couldn't parse any of them.
|
||||
*
|
||||
* We should only call this function for public (e.g. non bridge) relays.
|
||||
*/
|
||||
rend_cache_store_status_t
|
||||
int
|
||||
rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||
{
|
||||
const or_options_t *options = get_options();
|
||||
@ -642,12 +643,6 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||
time_t now = time(NULL);
|
||||
tor_assert(rend_cache_v2_dir);
|
||||
tor_assert(desc);
|
||||
if (!hid_serv_acting_as_directory()) {
|
||||
/* Cannot store descs, because we are (currently) not acting as
|
||||
* hidden service directory. */
|
||||
log_info(LD_REND, "Cannot store descs: Not acting as hs dir");
|
||||
return RCS_NOTDIR;
|
||||
}
|
||||
while (rend_parse_v2_service_descriptor(&parsed, desc_id, &intro_content,
|
||||
&intro_size, &encoded_size,
|
||||
&next_desc, current_desc, 1) >= 0) {
|
||||
@ -657,14 +652,6 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||
/* For pretty log statements. */
|
||||
base32_encode(desc_id_base32, sizeof(desc_id_base32),
|
||||
desc_id, DIGEST_LEN);
|
||||
/* Is desc ID in the range that we are (directly or indirectly) responsible
|
||||
* for? */
|
||||
if (!hid_serv_responsible_for_desc_id(desc_id)) {
|
||||
log_info(LD_REND, "Service descriptor with desc ID %s is not in "
|
||||
"interval that we are responsible for.",
|
||||
safe_str_client(desc_id_base32));
|
||||
goto skip;
|
||||
}
|
||||
/* Is descriptor too old? */
|
||||
if (parsed->timestamp < now - REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) {
|
||||
log_info(LD_REND, "Service descriptor with desc ID %s is too old.",
|
||||
@ -732,11 +719,11 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||
}
|
||||
if (!number_parsed) {
|
||||
log_info(LD_REND, "Could not parse any descriptor.");
|
||||
return RCS_BADDESC;
|
||||
return -1;
|
||||
}
|
||||
log_info(LD_REND, "Parsed %d and added %d descriptor%s.",
|
||||
number_parsed, number_stored, number_stored != 1 ? "s" : "");
|
||||
return RCS_OKAY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Parse the v2 service descriptor in <b>desc</b> and store it to the
|
||||
@ -746,9 +733,9 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||
* If we have a newer descriptor with the same ID, ignore this one.
|
||||
* If we have an older descriptor with the same ID, replace it.
|
||||
*
|
||||
* Return an appropriate rend_cache_store_status_t.
|
||||
* Return 0 on success, or -1 if we couldn't understand the descriptor.
|
||||
*/
|
||||
rend_cache_store_status_t
|
||||
int
|
||||
rend_cache_store_v2_desc_as_service(const char *desc)
|
||||
{
|
||||
rend_service_descriptor_t *parsed = NULL;
|
||||
@ -759,7 +746,7 @@ rend_cache_store_v2_desc_as_service(const char *desc)
|
||||
const char *next_desc;
|
||||
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
|
||||
rend_cache_entry_t *e;
|
||||
rend_cache_store_status_t retval = RCS_BADDESC;
|
||||
int retval = -1;
|
||||
tor_assert(rend_cache_local_service);
|
||||
tor_assert(desc);
|
||||
|
||||
@ -802,10 +789,10 @@ rend_cache_store_v2_desc_as_service(const char *desc)
|
||||
rend_cache_increment_allocation(rend_cache_entry_allocation(e));
|
||||
log_debug(LD_REND,"Successfully stored rend desc '%s', len %d.",
|
||||
safe_str_client(service_id), (int)encoded_size);
|
||||
return RCS_OKAY;
|
||||
return 0;
|
||||
|
||||
okay:
|
||||
retval = RCS_OKAY;
|
||||
retval = 0;
|
||||
|
||||
err:
|
||||
rend_service_descriptor_free(parsed);
|
||||
@ -826,10 +813,10 @@ rend_cache_store_v2_desc_as_service(const char *desc)
|
||||
* If the descriptor's descriptor ID doesn't match <b>desc_id_base32</b>,
|
||||
* reject it.
|
||||
*
|
||||
* Return an appropriate rend_cache_store_status_t. If entry is not NULL,
|
||||
* set it with the cache entry pointer of the descriptor.
|
||||
* Return 0 on success, or -1 if we rejected the descriptor.
|
||||
* If entry is not NULL, set it with the cache entry pointer of the descriptor.
|
||||
*/
|
||||
rend_cache_store_status_t
|
||||
int
|
||||
rend_cache_store_v2_desc_as_client(const char *desc,
|
||||
const char *desc_id_base32,
|
||||
const rend_data_t *rend_query,
|
||||
@ -861,7 +848,7 @@ rend_cache_store_v2_desc_as_client(const char *desc,
|
||||
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
|
||||
char want_desc_id[DIGEST_LEN];
|
||||
rend_cache_entry_t *e;
|
||||
rend_cache_store_status_t retval = RCS_BADDESC;
|
||||
int retval = -1;
|
||||
tor_assert(rend_cache);
|
||||
tor_assert(desc);
|
||||
tor_assert(desc_id_base32);
|
||||
@ -1008,13 +995,13 @@ rend_cache_store_v2_desc_as_client(const char *desc,
|
||||
if (entry) {
|
||||
*entry = e;
|
||||
}
|
||||
return RCS_OKAY;
|
||||
return 0;
|
||||
|
||||
okay:
|
||||
if (entry) {
|
||||
*entry = e;
|
||||
}
|
||||
retval = RCS_OKAY;
|
||||
retval = 0;
|
||||
|
||||
err:
|
||||
rend_service_descriptor_free(parsed);
|
||||
|
@ -64,20 +64,13 @@ int rend_cache_lookup_entry(const char *query, int version,
|
||||
int rend_cache_lookup_v2_desc_as_service(const char *query,
|
||||
rend_cache_entry_t **entry_out);
|
||||
int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
|
||||
/** Return value from rend_cache_store_v2_desc_as_{dir,client}. */
|
||||
typedef enum {
|
||||
RCS_NOTDIR = -2, /**< We're not a directory */
|
||||
RCS_BADDESC = -1, /**< This descriptor is no good. */
|
||||
RCS_OKAY = 0 /**< All worked as expected */
|
||||
} rend_cache_store_status_t;
|
||||
|
||||
rend_cache_store_status_t rend_cache_store_v2_desc_as_dir(const char *desc);
|
||||
rend_cache_store_status_t rend_cache_store_v2_desc_as_service(
|
||||
const char *desc);
|
||||
rend_cache_store_status_t rend_cache_store_v2_desc_as_client(const char *desc,
|
||||
const char *desc_id_base32,
|
||||
const rend_data_t *rend_query,
|
||||
rend_cache_entry_t **entry);
|
||||
int rend_cache_store_v2_desc_as_dir(const char *desc);
|
||||
int rend_cache_store_v2_desc_as_service(const char *desc);
|
||||
int rend_cache_store_v2_desc_as_client(const char *desc,
|
||||
const char *desc_id_base32,
|
||||
const rend_data_t *rend_query,
|
||||
rend_cache_entry_t **entry);
|
||||
size_t rend_cache_get_total_allocation(void);
|
||||
|
||||
void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
|
||||
|
@ -688,37 +688,6 @@ rend_get_service_id(crypto_pk_t *pk, char *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Determines whether <b>a</b> is in the interval of <b>b</b> (excluded) and
|
||||
* <b>c</b> (included) in a circular digest ring; returns 1 if this is the
|
||||
* case, and 0 otherwise.
|
||||
*/
|
||||
int
|
||||
rend_id_is_in_interval(const char *a, const char *b, const char *c)
|
||||
{
|
||||
int a_b, b_c, c_a;
|
||||
tor_assert(a);
|
||||
tor_assert(b);
|
||||
tor_assert(c);
|
||||
|
||||
/* There are five cases in which a is outside the interval ]b,c]: */
|
||||
a_b = tor_memcmp(a,b,DIGEST_LEN);
|
||||
if (a_b == 0)
|
||||
return 0; /* 1. a == b (b is excluded) */
|
||||
b_c = tor_memcmp(b,c,DIGEST_LEN);
|
||||
if (b_c == 0)
|
||||
return 0; /* 2. b == c (interval is empty) */
|
||||
else if (a_b <= 0 && b_c < 0)
|
||||
return 0; /* 3. a b c */
|
||||
c_a = tor_memcmp(c,a,DIGEST_LEN);
|
||||
if (c_a < 0 && a_b <= 0)
|
||||
return 0; /* 4. c a b */
|
||||
else if (b_c < 0 && c_a < 0)
|
||||
return 0; /* 5. b c a */
|
||||
|
||||
/* In the other cases (a c b; b a c; c b a), a is inside the interval. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Return true iff <b>query</b> is a syntactically valid service ID (as
|
||||
* generated by rend_get_service_id). */
|
||||
int
|
||||
@ -972,41 +941,3 @@ hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
||||
return smartlist_len(responsible_dirs) ? 0 : -1;
|
||||
}
|
||||
|
||||
/** Return true if this node is currently acting as hidden service
|
||||
* directory, false otherwise. */
|
||||
int
|
||||
hid_serv_acting_as_directory(void)
|
||||
{
|
||||
const routerinfo_t *me = router_get_my_routerinfo();
|
||||
if (!me)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Return true if this node is responsible for storing the descriptor ID
|
||||
* in <b>query</b> and false otherwise. */
|
||||
MOCK_IMPL(int, hid_serv_responsible_for_desc_id,
|
||||
(const char *query))
|
||||
{
|
||||
const routerinfo_t *me;
|
||||
routerstatus_t *last_rs;
|
||||
const char *my_id, *last_id;
|
||||
int result;
|
||||
smartlist_t *responsible;
|
||||
if (!hid_serv_acting_as_directory())
|
||||
return 0;
|
||||
if (!(me = router_get_my_routerinfo()))
|
||||
return 0; /* This is redundant, but let's be paranoid. */
|
||||
my_id = me->cache_info.identity_digest;
|
||||
responsible = smartlist_new();
|
||||
if (hid_serv_get_responsible_directories(responsible, query) < 0) {
|
||||
smartlist_free(responsible);
|
||||
return 0;
|
||||
}
|
||||
last_rs = smartlist_get(responsible, smartlist_len(responsible)-1);
|
||||
last_id = last_rs->identity_digest;
|
||||
result = rend_id_is_in_interval(my_id, query, last_id);
|
||||
smartlist_free(responsible);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -53,14 +53,11 @@ int rend_encode_v2_descriptors(smartlist_t *descs_out,
|
||||
int rend_compute_v2_desc_id(char *desc_id_out, const char *service_id,
|
||||
const char *descriptor_cookie,
|
||||
time_t now, uint8_t replica);
|
||||
int rend_id_is_in_interval(const char *a, const char *b, const char *c);
|
||||
void rend_get_descriptor_id_bytes(char *descriptor_id_out,
|
||||
const char *service_id,
|
||||
const char *secret_id_part);
|
||||
int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
||||
const char *id);
|
||||
int hid_serv_acting_as_directory(void);
|
||||
MOCK_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
||||
|
||||
rend_data_t *rend_data_dup(const rend_data_t *data);
|
||||
rend_data_t *rend_data_client_create(const char *onion_address,
|
||||
|
@ -389,10 +389,8 @@ test_dir_handle_get_rendezvous2_not_found(void *data)
|
||||
}
|
||||
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
||||
|
||||
static routerinfo_t *mock_routerinfo;
|
||||
static int hid_serv_responsible_for_desc_id_response;
|
||||
|
||||
static const routerinfo_t *
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
@ -404,13 +402,6 @@ NS(router_get_my_routerinfo)(void)
|
||||
return mock_routerinfo;
|
||||
}
|
||||
|
||||
static int
|
||||
NS(hid_serv_responsible_for_desc_id)(const char *id)
|
||||
{
|
||||
(void)id;
|
||||
return hid_serv_responsible_for_desc_id_response;
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
||||
{
|
||||
@ -428,17 +419,15 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
NS_MOCK(hid_serv_responsible_for_desc_id);
|
||||
|
||||
rend_cache_init();
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
|
||||
/* create a valid rend service descriptor */
|
||||
#define RECENT_TIME -10
|
||||
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
||||
|
||||
tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder->desc_str),
|
||||
OP_EQ, RCS_OKAY);
|
||||
OP_EQ, 0);
|
||||
|
||||
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
|
||||
DIGEST_LEN);
|
||||
@ -473,9 +462,6 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
NS_UNMOCK(hid_serv_responsible_for_desc_id);
|
||||
tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
|
||||
tor_free(mock_routerinfo);
|
||||
|
||||
connection_free_(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
|
@ -91,7 +91,7 @@ test_rend_cache_lookup_entry(void *data)
|
||||
static void
|
||||
test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
{
|
||||
rend_cache_store_status_t ret;
|
||||
int ret;
|
||||
rend_data_t *mock_rend_query;
|
||||
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
||||
rend_cache_entry_t *entry = NULL;
|
||||
@ -112,7 +112,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
desc_id_base32, mock_rend_query,
|
||||
&entry);
|
||||
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
tt_assert(entry);
|
||||
tt_int_op(entry->len, OP_EQ, strlen(desc_holder->desc_str));
|
||||
tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
|
||||
@ -124,7 +124,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
/* desc_holder->desc_str, */
|
||||
/* "3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG", */
|
||||
/* &mock_rend_query, NULL); */
|
||||
/* tt_int_op(ret, OP_EQ, RCS_BADDESC); */
|
||||
/* tt_int_op(ret, OP_EQ, -1); */
|
||||
|
||||
// Test bad base32 failure
|
||||
// This causes an assertion failure if we're running with assertions.
|
||||
@ -132,13 +132,13 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
#ifdef DISABLE_ASSERTS_IN_UNIT_TESTS
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
"!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
#endif
|
||||
|
||||
// Test invalid descriptor
|
||||
ret = rend_cache_store_v2_desc_as_client("invalid descriptor",
|
||||
"3xqunszqnaolrrfmtzgaki7mxelgvkje", mock_rend_query, NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
|
||||
// TODO: it doesn't seem to be possible to test invalid service ID condition.
|
||||
// that means it is likely not possible to have that condition without
|
||||
@ -152,7 +152,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32,
|
||||
mock_rend_query, NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
rend_cache_free_all();
|
||||
rend_data_free(mock_rend_query);
|
||||
|
||||
@ -163,7 +163,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
desc_id_base32[0]--;
|
||||
rend_cache_free_all();
|
||||
|
||||
@ -181,7 +181,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32,
|
||||
mock_rend_query, NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
rend_cache_free_all();
|
||||
|
||||
// Test too new descriptor (in the future)
|
||||
@ -198,7 +198,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
rend_cache_free_all();
|
||||
|
||||
// Test when a descriptor is already in the cache
|
||||
@ -217,12 +217,12 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
&entry);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
tt_assert(entry);
|
||||
rend_cache_free_all();
|
||||
|
||||
@ -243,7 +243,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
rend_cache_free_all();
|
||||
|
||||
// Test successful run when we have REND_BASIC_AUTH but not cookie
|
||||
@ -260,7 +260,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
rend_cache_free_all();
|
||||
|
||||
@ -277,7 +277,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
rend_cache_free_all();
|
||||
|
||||
// Test when we have too many intro points
|
||||
@ -293,7 +293,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
|
||||
done:
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
@ -305,7 +305,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
||||
static void
|
||||
test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
||||
{
|
||||
rend_cache_store_status_t ret;
|
||||
int ret;
|
||||
rend_data_t *mock_rend_query;
|
||||
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
||||
rend_service_descriptor_t *generated = NULL;
|
||||
@ -350,7 +350,7 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
rend_cache_free_all();
|
||||
|
||||
@ -361,7 +361,7 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
||||
ret = rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
|
||||
desc_id_base32, mock_rend_query,
|
||||
NULL);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder_newer);
|
||||
@ -377,10 +377,8 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
||||
|
||||
#define NS_SUBMODULE lookup_v2_desc_as_dir
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
||||
|
||||
static routerinfo_t *mock_routerinfo;
|
||||
static int hid_serv_responsible_for_desc_id_response;
|
||||
|
||||
static const routerinfo_t *
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
@ -392,13 +390,6 @@ NS(router_get_my_routerinfo)(void)
|
||||
return mock_routerinfo;
|
||||
}
|
||||
|
||||
static int
|
||||
NS(hid_serv_responsible_for_desc_id)(const char *id)
|
||||
{
|
||||
(void)id;
|
||||
return hid_serv_responsible_for_desc_id_response;
|
||||
}
|
||||
|
||||
static void
|
||||
test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
{
|
||||
@ -411,7 +402,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
(void)data;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
NS_MOCK(hid_serv_responsible_for_desc_id);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -425,7 +415,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
// Test existing descriptor
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
||||
rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
|
||||
@ -436,7 +425,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
NS_UNMOCK(hid_serv_responsible_for_desc_id);
|
||||
tor_free(mock_routerinfo);
|
||||
rend_cache_free_all();
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
@ -447,7 +435,6 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
|
||||
#define NS_SUBMODULE store_v2_desc_as_dir
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
||||
|
||||
static const routerinfo_t *
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
@ -455,51 +442,27 @@ NS(router_get_my_routerinfo)(void)
|
||||
return mock_routerinfo;
|
||||
}
|
||||
|
||||
static int
|
||||
NS(hid_serv_responsible_for_desc_id)(const char *id)
|
||||
{
|
||||
(void)id;
|
||||
return hid_serv_responsible_for_desc_id_response;
|
||||
}
|
||||
|
||||
static void
|
||||
test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||
{
|
||||
(void)data;
|
||||
rend_cache_store_status_t ret;
|
||||
int ret;
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
|
||||
char *service_id = NULL;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
NS_MOCK(hid_serv_responsible_for_desc_id);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
// Test when we are not an HS dir
|
||||
mock_routerinfo = NULL;
|
||||
ret = rend_cache_store_v2_desc_as_dir("");
|
||||
tt_int_op(ret, OP_EQ, RCS_NOTDIR);
|
||||
|
||||
// Test when we can't parse the descriptor
|
||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
ret = rend_cache_store_v2_desc_as_dir("unparseable");
|
||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
||||
|
||||
// Test when we are not responsible for an HS
|
||||
hid_serv_responsible_for_desc_id_response = 0;
|
||||
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
|
||||
// Test when we have an old descriptor
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
@ -507,7 +470,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||
// Test when we have a descriptor in the future
|
||||
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
@ -515,7 +478,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||
// Test when two descriptors
|
||||
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
@ -525,11 +488,10 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
||||
get_options_mutable()->HiddenServiceStatistics = 1;
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
NS_UNMOCK(hid_serv_responsible_for_desc_id);
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
rend_cache_free_all();
|
||||
@ -541,7 +503,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
rend_cache_store_status_t ret;
|
||||
int ret;
|
||||
rend_service_descriptor_t *generated = NULL;
|
||||
smartlist_t *descs = smartlist_new();
|
||||
time_t t;
|
||||
@ -550,7 +512,6 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder_older;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
NS_MOCK(hid_serv_responsible_for_desc_id);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -577,20 +538,18 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
||||
|
||||
// Test when we have a newer descriptor stored
|
||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
// Test when we have an old descriptor stored
|
||||
rend_cache_purge();
|
||||
rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
NS_UNMOCK(hid_serv_responsible_for_desc_id);
|
||||
rend_cache_free_all();
|
||||
rend_service_descriptor_free(generated);
|
||||
tor_free(service_id);
|
||||
@ -607,7 +566,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
rend_cache_store_status_t ret;
|
||||
int ret;
|
||||
rend_service_descriptor_t *generated = NULL;
|
||||
smartlist_t *descs = smartlist_new();
|
||||
time_t t;
|
||||
@ -616,7 +575,6 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
NS_MOCK(hid_serv_responsible_for_desc_id);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -645,14 +603,12 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
||||
|
||||
// Test when we have another descriptor stored, with a different descriptor
|
||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
|
||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
|
||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
NS_UNMOCK(hid_serv_responsible_for_desc_id);
|
||||
rend_cache_free_all();
|
||||
rend_service_descriptor_free(generated);
|
||||
tor_free(service_id);
|
||||
@ -1113,14 +1069,6 @@ test_rend_cache_intro_failure_note(void *data)
|
||||
}
|
||||
|
||||
#define NS_SUBMODULE clean_v2_descs_as_dir
|
||||
NS_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
||||
|
||||
static int
|
||||
NS(hid_serv_responsible_for_desc_id)(const char *id)
|
||||
{
|
||||
(void)id;
|
||||
return hid_serv_responsible_for_desc_id_response;
|
||||
}
|
||||
|
||||
static void
|
||||
test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
@ -1133,7 +1081,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
|
||||
(void)data;
|
||||
|
||||
NS_MOCK(hid_serv_responsible_for_desc_id);
|
||||
rend_cache_init();
|
||||
|
||||
// Test running with an empty cache
|
||||
@ -1149,7 +1096,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
e->parsed = desc;
|
||||
digestmap_set(rend_cache_v2_dir, key, e);
|
||||
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
rend_cache_clean_v2_descs_as_dir(now, 0);
|
||||
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
|
||||
|
||||
@ -1158,20 +1104,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
rend_cache_clean_v2_descs_as_dir(now, 0);
|
||||
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
|
||||
|
||||
// Test with one entry that is not under the responsibility of this
|
||||
// hidden service
|
||||
e = tor_malloc_zero(sizeof(rend_cache_entry_t));
|
||||
e->last_served = now;
|
||||
desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
|
||||
desc->timestamp = now;
|
||||
desc->pk = pk_generate(0);
|
||||
e->parsed = desc;
|
||||
digestmap_set(rend_cache_v2_dir, key, e);
|
||||
|
||||
hid_serv_responsible_for_desc_id_response = 0;
|
||||
rend_cache_clean_v2_descs_as_dir(now, 0);
|
||||
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
|
||||
|
||||
// Test with one entry that has an old last served
|
||||
e = tor_malloc_zero(sizeof(rend_cache_entry_t));
|
||||
e->last_served = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW + 1000);
|
||||
@ -1181,7 +1113,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
e->parsed = desc;
|
||||
digestmap_set(rend_cache_v2_dir, key, e);
|
||||
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
rend_cache_clean_v2_descs_as_dir(now, 0);
|
||||
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
|
||||
|
||||
@ -1194,12 +1125,10 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
e->parsed = desc;
|
||||
digestmap_set(rend_cache_v2_dir, key, e);
|
||||
|
||||
hid_serv_responsible_for_desc_id_response = 1;
|
||||
rend_cache_clean_v2_descs_as_dir(now, 20000);
|
||||
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(hid_serv_responsible_for_desc_id);
|
||||
rend_cache_free_all();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user