mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
hs-v2: Removal of service and relay support
This is unfortunately massive but both functionalities were extremely intertwined and it would have required us to actually change the HSv2 code in order to be able to split this into multiple commits. After this commit, there are still artefacts of v2 in the code but there is no more support for service, intro point and HSDir. The v2 support for rendezvous circuit is still available since that code is the same for the v3 and we will leave it in so if a client is able to rendezvous on v2 then it can still transfer traffic. Once the entire network has moved away from v2, we can remove v2 rendezvous point support. Related to #40266 Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
/* Copyright (c) 2016-2020, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
#include "core/or/or.h"
|
||||
#include "feature/dirparse/unparseable.h"
|
||||
#include "feature/rend/rendcommon.h"
|
||||
#include "feature/rend/rendparse.h"
|
||||
#include "lib/crypt_ops/crypto_ed25519.h"
|
||||
#include "test/fuzz/fuzzing.h"
|
||||
|
||||
static void
|
||||
mock_dump_desc__nodump(const char *desc, const char *type)
|
||||
{
|
||||
(void)desc;
|
||||
(void)type;
|
||||
}
|
||||
|
||||
int
|
||||
fuzz_init(void)
|
||||
{
|
||||
disable_signature_checking();
|
||||
MOCK(dump_desc, mock_dump_desc__nodump);
|
||||
ed25519_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fuzz_cleanup(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fuzz_main(const uint8_t *data, size_t sz)
|
||||
{
|
||||
rend_service_descriptor_t *desc = NULL;
|
||||
char desc_id[64];
|
||||
char *ipts = NULL;
|
||||
size_t ipts_size, esize;
|
||||
const char *next;
|
||||
char *str = tor_memdup_nulterm(data, sz);
|
||||
(void) rend_parse_v2_service_descriptor(&desc, desc_id, &ipts, &ipts_size,
|
||||
&esize, &next, str, 1);
|
||||
if (desc) {
|
||||
log_debug(LD_GENERAL, "Parsing okay");
|
||||
rend_service_descriptor_free(desc);
|
||||
} else {
|
||||
log_debug(LD_GENERAL, "Parsing failed");
|
||||
}
|
||||
tor_free(ipts);
|
||||
tor_free(str);
|
||||
return 0;
|
||||
}
|
||||
@@ -83,16 +83,6 @@ src_test_fuzz_fuzz_extrainfo_LDFLAGS = $(FUZZING_LDFLAG)
|
||||
src_test_fuzz_fuzz_extrainfo_LDADD = $(FUZZING_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_fuzz_hsdescv2_SOURCES = \
|
||||
src/test/fuzz/fuzzing_common.c \
|
||||
src/test/fuzz/fuzz_hsdescv2.c
|
||||
src_test_fuzz_fuzz_hsdescv2_CPPFLAGS = $(FUZZING_CPPFLAGS)
|
||||
src_test_fuzz_fuzz_hsdescv2_CFLAGS = $(FUZZING_CFLAGS)
|
||||
src_test_fuzz_fuzz_hsdescv2_LDFLAGS = $(FUZZING_LDFLAG)
|
||||
src_test_fuzz_fuzz_hsdescv2_LDADD = $(FUZZING_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_fuzz_hsdescv3_SOURCES = \
|
||||
src/test/fuzz/fuzzing_common.c \
|
||||
@@ -123,16 +113,6 @@ src_test_fuzz_fuzz_http_connect_LDFLAGS = $(FUZZING_LDFLAG)
|
||||
src_test_fuzz_fuzz_http_connect_LDADD = $(FUZZING_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_fuzz_iptsv2_SOURCES = \
|
||||
src/test/fuzz/fuzzing_common.c \
|
||||
src/test/fuzz/fuzz_iptsv2.c
|
||||
src_test_fuzz_fuzz_iptsv2_CPPFLAGS = $(FUZZING_CPPFLAGS)
|
||||
src_test_fuzz_fuzz_iptsv2_CFLAGS = $(FUZZING_CFLAGS)
|
||||
src_test_fuzz_fuzz_iptsv2_LDFLAGS = $(FUZZING_LDFLAG)
|
||||
src_test_fuzz_fuzz_iptsv2_LDADD = $(FUZZING_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_fuzz_microdesc_SOURCES = \
|
||||
src/test/fuzz/fuzzing_common.c \
|
||||
@@ -180,11 +160,9 @@ FUZZERS = \
|
||||
src/test/fuzz/fuzz-diff \
|
||||
src/test/fuzz/fuzz-diff-apply \
|
||||
src/test/fuzz/fuzz-extrainfo \
|
||||
src/test/fuzz/fuzz-hsdescv2 \
|
||||
src/test/fuzz/fuzz-hsdescv3 \
|
||||
src/test/fuzz/fuzz-http \
|
||||
src/test/fuzz/fuzz-http-connect \
|
||||
src/test/fuzz/fuzz-iptsv2 \
|
||||
src/test/fuzz/fuzz-microdesc \
|
||||
src/test/fuzz/fuzz-socks \
|
||||
src/test/fuzz/fuzz-strops \
|
||||
@@ -239,15 +217,6 @@ src_test_fuzz_lf_fuzz_extrainfo_LDFLAGS = $(LIBFUZZER_LDFLAG)
|
||||
src_test_fuzz_lf_fuzz_extrainfo_LDADD = $(LIBFUZZER_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_lf_fuzz_hsdescv2_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_hsdescv2_SOURCES)
|
||||
src_test_fuzz_lf_fuzz_hsdescv2_CPPFLAGS = $(LIBFUZZER_CPPFLAGS)
|
||||
src_test_fuzz_lf_fuzz_hsdescv2_CFLAGS = $(LIBFUZZER_CFLAGS)
|
||||
src_test_fuzz_lf_fuzz_hsdescv2_LDFLAGS = $(LIBFUZZER_LDFLAG)
|
||||
src_test_fuzz_lf_fuzz_hsdescv2_LDADD = $(LIBFUZZER_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_lf_fuzz_hsdescv3_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_hsdescv3_SOURCES)
|
||||
@@ -275,15 +244,6 @@ src_test_fuzz_lf_fuzz_http_connect_LDFLAGS = $(LIBFUZZER_LDFLAG)
|
||||
src_test_fuzz_lf_fuzz_http_connect_LDADD = $(LIBFUZZER_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_lf_fuzz_iptsv2_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_iptsv2_SOURCES)
|
||||
src_test_fuzz_lf_fuzz_iptsv2_CPPFLAGS = $(LIBFUZZER_CPPFLAGS)
|
||||
src_test_fuzz_lf_fuzz_iptsv2_CFLAGS = $(LIBFUZZER_CFLAGS)
|
||||
src_test_fuzz_lf_fuzz_iptsv2_LDFLAGS = $(LIBFUZZER_LDFLAG)
|
||||
src_test_fuzz_lf_fuzz_iptsv2_LDADD = $(LIBFUZZER_LIBS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_lf_fuzz_microdesc_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_microdesc_SOURCES)
|
||||
@@ -326,11 +286,9 @@ LIBFUZZER_FUZZERS = \
|
||||
src/test/fuzz/lf-fuzz-diff \
|
||||
src/test/fuzz/lf-fuzz-diff-apply \
|
||||
src/test/fuzz/lf-fuzz-extrainfo \
|
||||
src/test/fuzz/lf-fuzz-hsdescv2 \
|
||||
src/test/fuzz/lf-fuzz-hsdescv3 \
|
||||
src/test/fuzz/lf-fuzz-http \
|
||||
src/test/fuzz/lf-fuzz-http-connect \
|
||||
src/test/fuzz/lf-fuzz-iptsv2 \
|
||||
src/test/fuzz/lf-fuzz-microdesc \
|
||||
src/test/fuzz/lf-fuzz-socks \
|
||||
src/test/fuzz/lf-fuzz-strops \
|
||||
@@ -378,13 +336,6 @@ src_test_fuzz_liboss_fuzz_extrainfo_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
|
||||
src_test_fuzz_liboss_fuzz_extrainfo_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_liboss_fuzz_hsdescv2_a_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_hsdescv2_SOURCES)
|
||||
src_test_fuzz_liboss_fuzz_hsdescv2_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
|
||||
src_test_fuzz_liboss_fuzz_hsdescv2_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_liboss_fuzz_hsdescv3_a_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_hsdescv3_SOURCES)
|
||||
@@ -406,13 +357,6 @@ src_test_fuzz_liboss_fuzz_http_connect_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
|
||||
src_test_fuzz_liboss_fuzz_http_connect_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_liboss_fuzz_iptsv2_a_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_iptsv2_SOURCES)
|
||||
src_test_fuzz_liboss_fuzz_iptsv2_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
|
||||
src_test_fuzz_liboss_fuzz_iptsv2_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
|
||||
endif
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
src_test_fuzz_liboss_fuzz_microdesc_a_SOURCES = \
|
||||
$(src_test_fuzz_fuzz_microdesc_SOURCES)
|
||||
@@ -447,11 +391,9 @@ OSS_FUZZ_FUZZERS = \
|
||||
src/test/fuzz/liboss-fuzz-diff.a \
|
||||
src/test/fuzz/liboss-fuzz-diff-apply.a \
|
||||
src/test/fuzz/liboss-fuzz-extrainfo.a \
|
||||
src/test/fuzz/liboss-fuzz-hsdescv2.a \
|
||||
src/test/fuzz/liboss-fuzz-hsdescv3.a \
|
||||
src/test/fuzz/liboss-fuzz-http.a \
|
||||
src/test/fuzz/liboss-fuzz-http-connect.a \
|
||||
src/test/fuzz/liboss-fuzz-iptsv2.a \
|
||||
src/test/fuzz/liboss-fuzz-microdesc.a \
|
||||
src/test/fuzz/liboss-fuzz-socks.a \
|
||||
src/test/fuzz/liboss-fuzz-strops.a \
|
||||
|
||||
@@ -130,7 +130,6 @@ src_test_test_SOURCES += \
|
||||
src/test/log_test_helpers.c \
|
||||
src/test/hs_test_helpers.c \
|
||||
src/test/opts_test_helpers.c \
|
||||
src/test/rend_test_helpers.c \
|
||||
src/test/resolve_test_helpers.c \
|
||||
src/test/rng_test_helpers.c \
|
||||
src/test/test.c \
|
||||
@@ -181,7 +180,6 @@ src_test_test_SOURCES += \
|
||||
src/test/test_geoip.c \
|
||||
src/test/test_guardfraction.c \
|
||||
src/test/test_extorport.c \
|
||||
src/test/test_hs.c \
|
||||
src/test/test_hs_common.c \
|
||||
src/test/test_hs_config.c \
|
||||
src/test/test_hs_cell.c \
|
||||
@@ -196,7 +194,6 @@ src_test_test_SOURCES += \
|
||||
src/test/test_hs_descriptor.c \
|
||||
src/test/test_hs_dos.c \
|
||||
src/test/test_hs_metrics.c \
|
||||
src/test/test_introduce.c \
|
||||
src/test/test_keypin.c \
|
||||
src/test/test_link_handshake.c \
|
||||
src/test/test_logging.c \
|
||||
@@ -227,7 +224,6 @@ src_test_test_SOURCES += \
|
||||
src/test/test_relay.c \
|
||||
src/test/test_relaycell.c \
|
||||
src/test/test_relaycrypt.c \
|
||||
src/test/test_rendcache.c \
|
||||
src/test/test_replay.c \
|
||||
src/test/test_router.c \
|
||||
src/test/test_routerkeys.c \
|
||||
@@ -380,7 +376,6 @@ noinst_HEADERS+= \
|
||||
src/test/hs_test_helpers.h \
|
||||
src/test/log_test_helpers.h \
|
||||
src/test/opts_test_helpers.h \
|
||||
src/test/rend_test_helpers.h \
|
||||
src/test/resolve_test_helpers.h \
|
||||
src/test/rng_test_helpers.h \
|
||||
src/test/test.h \
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
/* Copyright (c) 2014-2020, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#include "core/or/or.h"
|
||||
#include "core/or/extendinfo.h"
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
#include "test/test.h"
|
||||
#include "feature/rend/rendcommon.h"
|
||||
#include "test/rend_test_helpers.h"
|
||||
|
||||
#include "core/or/extend_info_st.h"
|
||||
#include "feature/rend/rend_intro_point_st.h"
|
||||
#include "feature/rend/rend_service_descriptor_st.h"
|
||||
|
||||
void
|
||||
generate_desc(int time_diff, rend_encoded_v2_service_descriptor_t **desc,
|
||||
char **service_id, int intro_points)
|
||||
{
|
||||
rend_service_descriptor_t *generated = NULL;
|
||||
smartlist_t *descs = smartlist_new();
|
||||
time_t now;
|
||||
|
||||
now = time(NULL) + time_diff;
|
||||
create_descriptor(&generated, service_id, intro_points);
|
||||
generated->timestamp = now;
|
||||
|
||||
rend_encode_v2_descriptors(descs, generated, now, 0, REND_NO_AUTH, NULL,
|
||||
NULL);
|
||||
tor_assert(smartlist_len(descs) > 1);
|
||||
*desc = smartlist_get(descs, 0);
|
||||
smartlist_set(descs, 0, NULL);
|
||||
|
||||
SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
|
||||
rend_encoded_v2_service_descriptor_free(d));
|
||||
smartlist_free(descs);
|
||||
rend_service_descriptor_free(generated);
|
||||
}
|
||||
|
||||
void
|
||||
create_descriptor(rend_service_descriptor_t **generated, char **service_id,
|
||||
int intro_points)
|
||||
{
|
||||
crypto_pk_t *pk1 = NULL;
|
||||
crypto_pk_t *pk2 = NULL;
|
||||
int i;
|
||||
|
||||
*service_id = tor_malloc(REND_SERVICE_ID_LEN_BASE32+1);
|
||||
pk1 = pk_generate(0);
|
||||
pk2 = pk_generate(1);
|
||||
|
||||
*generated = tor_malloc_zero(sizeof(rend_service_descriptor_t));
|
||||
(*generated)->pk = crypto_pk_dup_key(pk1);
|
||||
rend_get_service_id((*generated)->pk, *service_id);
|
||||
|
||||
(*generated)->version = 2;
|
||||
(*generated)->protocols = 42;
|
||||
(*generated)->intro_nodes = smartlist_new();
|
||||
|
||||
for (i = 0; i < intro_points; i++) {
|
||||
rend_intro_point_t *intro = tor_malloc_zero(sizeof(rend_intro_point_t));
|
||||
crypto_pk_t *okey = pk_generate(2 + i);
|
||||
intro->extend_info =
|
||||
extend_info_new(NULL, NULL, NULL, NULL, NULL, NULL, 0);
|
||||
intro->extend_info->onion_key = okey;
|
||||
crypto_pk_get_digest(intro->extend_info->onion_key,
|
||||
intro->extend_info->identity_digest);
|
||||
intro->extend_info->nickname[0] = '$';
|
||||
base16_encode(intro->extend_info->nickname + 1,
|
||||
sizeof(intro->extend_info->nickname) - 1,
|
||||
intro->extend_info->identity_digest, DIGEST_LEN);
|
||||
tor_addr_t addr;
|
||||
uint16_t port;
|
||||
/* Does not cover all IP addresses. */
|
||||
tor_addr_from_ipv4h(&addr, crypto_rand_int(65536) + 1);
|
||||
port = 1 + crypto_rand_int(65535);
|
||||
extend_info_add_orport(intro->extend_info, &addr, port);
|
||||
intro->intro_key = crypto_pk_dup_key(pk2);
|
||||
smartlist_add((*generated)->intro_nodes, intro);
|
||||
}
|
||||
|
||||
crypto_pk_free(pk1);
|
||||
crypto_pk_free(pk2);
|
||||
}
|
||||
|
||||
rend_data_t *
|
||||
mock_rend_data(const char *onion_address)
|
||||
{
|
||||
rend_data_v2_t *v2_data = tor_malloc_zero(sizeof(*v2_data));
|
||||
rend_data_t *rend_query = &v2_data->base_;
|
||||
rend_query->version = 2;
|
||||
|
||||
strlcpy(v2_data->onion_address, onion_address,
|
||||
sizeof(v2_data->onion_address));
|
||||
v2_data->auth_type = REND_NO_AUTH;
|
||||
rend_query->hsdirs_fp = smartlist_new();
|
||||
smartlist_add(rend_query->hsdirs_fp, tor_memdup("aaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
DIGEST_LEN));
|
||||
return rend_query;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/* Copyright (c) 2014-2020, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#include "core/or/or.h"
|
||||
|
||||
#ifndef TOR_REND_TEST_HELPERS_H
|
||||
#define TOR_REND_TEST_HELPERS_H
|
||||
|
||||
void generate_desc(int time_diff, rend_encoded_v2_service_descriptor_t **desc,
|
||||
char **service_id, int intro_points);
|
||||
void create_descriptor(rend_service_descriptor_t **generated,
|
||||
char **service_id, int intro_points);
|
||||
rend_data_t *mock_rend_data(const char *onion_address);
|
||||
|
||||
#endif /* !defined(TOR_REND_TEST_HELPERS_H) */
|
||||
|
||||
-131
@@ -45,9 +45,6 @@
|
||||
#include "app/config/config.h"
|
||||
#include "core/or/connection_edge.h"
|
||||
#include "core/or/extendinfo.h"
|
||||
#include "feature/rend/rendcommon.h"
|
||||
#include "feature/rend/rendcache.h"
|
||||
#include "feature/rend/rendparse.h"
|
||||
#include "test/test.h"
|
||||
#include "core/mainloop/mainloop.h"
|
||||
#include "lib/memarea/memarea.h"
|
||||
@@ -62,9 +59,6 @@
|
||||
|
||||
#include "core/or/extend_info_st.h"
|
||||
#include "core/or/or_circuit_st.h"
|
||||
#include "feature/rend/rend_encoded_v2_service_descriptor_st.h"
|
||||
#include "feature/rend/rend_intro_point_st.h"
|
||||
#include "feature/rend/rend_service_descriptor_st.h"
|
||||
#include "feature/relay/onion_queue.h"
|
||||
|
||||
/** Run unit tests for the onion handshake code. */
|
||||
@@ -619,127 +613,6 @@ test_circuit_timeout(void *arg)
|
||||
testing_disable_deterministic_rng();
|
||||
}
|
||||
|
||||
/** Test encoding and parsing of rendezvous service descriptors. */
|
||||
static void
|
||||
test_rend_fns(void *arg)
|
||||
{
|
||||
rend_service_descriptor_t *generated = NULL, *parsed = NULL;
|
||||
char service_id[DIGEST_LEN];
|
||||
char service_id_base32[REND_SERVICE_ID_LEN_BASE32+1];
|
||||
const char *next_desc;
|
||||
smartlist_t *descs = smartlist_new();
|
||||
char computed_desc_id[DIGEST_LEN];
|
||||
char parsed_desc_id[DIGEST_LEN];
|
||||
crypto_pk_t *pk1 = NULL, *pk2 = NULL;
|
||||
time_t now;
|
||||
char *intro_points_encrypted = NULL;
|
||||
size_t intro_points_size;
|
||||
size_t encoded_size;
|
||||
int i;
|
||||
|
||||
(void)arg;
|
||||
|
||||
/* Initialize the service cache. */
|
||||
rend_cache_init();
|
||||
|
||||
pk1 = pk_generate(0);
|
||||
pk2 = pk_generate(1);
|
||||
generated = tor_malloc_zero(sizeof(rend_service_descriptor_t));
|
||||
generated->pk = crypto_pk_dup_key(pk1);
|
||||
crypto_pk_get_digest(generated->pk, service_id);
|
||||
base32_encode(service_id_base32, REND_SERVICE_ID_LEN_BASE32+1,
|
||||
service_id, REND_SERVICE_ID_LEN);
|
||||
now = time(NULL);
|
||||
generated->timestamp = now;
|
||||
generated->version = 2;
|
||||
generated->protocols = 42;
|
||||
generated->intro_nodes = smartlist_new();
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
rend_intro_point_t *intro = tor_malloc_zero(sizeof(rend_intro_point_t));
|
||||
crypto_pk_t *okey = pk_generate(2 + i);
|
||||
intro->extend_info =
|
||||
extend_info_new(NULL, NULL, NULL, NULL, NULL, NULL, 0);
|
||||
intro->extend_info->onion_key = okey;
|
||||
crypto_pk_get_digest(intro->extend_info->onion_key,
|
||||
intro->extend_info->identity_digest);
|
||||
//crypto_rand(info->identity_digest, DIGEST_LEN); /* Would this work? */
|
||||
intro->extend_info->nickname[0] = '$';
|
||||
base16_encode(intro->extend_info->nickname + 1,
|
||||
sizeof(intro->extend_info->nickname) - 1,
|
||||
intro->extend_info->identity_digest, DIGEST_LEN);
|
||||
tor_addr_t addr;
|
||||
uint16_t port;
|
||||
/* Does not cover all IP addresses. */
|
||||
tor_addr_from_ipv4h(&addr, crypto_rand_int(65536) + 1);
|
||||
port = 1 + crypto_rand_int(65535);
|
||||
extend_info_add_orport(intro->extend_info, &addr, port);
|
||||
intro->intro_key = crypto_pk_dup_key(pk2);
|
||||
smartlist_add(generated->intro_nodes, intro);
|
||||
}
|
||||
int rv = rend_encode_v2_descriptors(descs, generated, now, 0,
|
||||
REND_NO_AUTH, NULL, NULL);
|
||||
tt_int_op(rv, OP_GT, 0);
|
||||
rv = rend_compute_v2_desc_id(computed_desc_id, service_id_base32, NULL,
|
||||
now, 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_mem_op(((rend_encoded_v2_service_descriptor_t *)
|
||||
smartlist_get(descs, 0))->desc_id, OP_EQ,
|
||||
computed_desc_id, DIGEST_LEN);
|
||||
rv = rend_parse_v2_service_descriptor(&parsed, parsed_desc_id,
|
||||
&intro_points_encrypted, &intro_points_size, &encoded_size,
|
||||
&next_desc,
|
||||
((rend_encoded_v2_service_descriptor_t *)smartlist_get(descs, 0))
|
||||
->desc_str, 1);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(parsed);
|
||||
tt_mem_op(((rend_encoded_v2_service_descriptor_t *)
|
||||
smartlist_get(descs, 0))->desc_id,OP_EQ, parsed_desc_id, DIGEST_LEN);
|
||||
tt_int_op(rend_parse_introduction_points(parsed, intro_points_encrypted,
|
||||
intro_points_size),OP_EQ, 3);
|
||||
tt_assert(!crypto_pk_cmp_keys(generated->pk, parsed->pk));
|
||||
tt_int_op(parsed->timestamp,OP_EQ, now);
|
||||
tt_int_op(parsed->version,OP_EQ, 2);
|
||||
tt_int_op(parsed->protocols,OP_EQ, 42);
|
||||
tt_int_op(smartlist_len(parsed->intro_nodes),OP_EQ, 3);
|
||||
for (i = 0; i < smartlist_len(parsed->intro_nodes); i++) {
|
||||
rend_intro_point_t *par_intro = smartlist_get(parsed->intro_nodes, i),
|
||||
*gen_intro = smartlist_get(generated->intro_nodes, i);
|
||||
extend_info_t *par_info = par_intro->extend_info;
|
||||
extend_info_t *gen_info = gen_intro->extend_info;
|
||||
tt_assert(!crypto_pk_cmp_keys(gen_info->onion_key, par_info->onion_key));
|
||||
tt_mem_op(gen_info->identity_digest,OP_EQ, par_info->identity_digest,
|
||||
DIGEST_LEN);
|
||||
tt_str_op(gen_info->nickname,OP_EQ, par_info->nickname);
|
||||
const tor_addr_port_t *a1, *a2;
|
||||
a1 = extend_info_get_orport(gen_info, AF_INET);
|
||||
a2 = extend_info_get_orport(par_info, AF_INET);
|
||||
tt_assert(a1 && a2);
|
||||
tt_assert(tor_addr_eq(&a1->addr, &a2->addr));
|
||||
tt_int_op(a2->port,OP_EQ, a2->port);
|
||||
}
|
||||
|
||||
rend_service_descriptor_free(parsed);
|
||||
rend_service_descriptor_free(generated);
|
||||
parsed = generated = NULL;
|
||||
|
||||
done:
|
||||
if (descs) {
|
||||
for (i = 0; i < smartlist_len(descs); i++)
|
||||
rend_encoded_v2_service_descriptor_free_(smartlist_get(descs, i));
|
||||
smartlist_free(descs);
|
||||
}
|
||||
if (parsed)
|
||||
rend_service_descriptor_free(parsed);
|
||||
if (generated)
|
||||
rend_service_descriptor_free(generated);
|
||||
if (pk1)
|
||||
crypto_pk_free(pk1);
|
||||
if (pk2)
|
||||
crypto_pk_free(pk2);
|
||||
tor_free(intro_points_encrypted);
|
||||
}
|
||||
|
||||
#define ENT(name) \
|
||||
{ #name, test_ ## name , 0, NULL, NULL }
|
||||
#define FORK(name) \
|
||||
@@ -753,7 +626,6 @@ static struct testcase_t test_array[] = {
|
||||
{ "fast_handshake", test_fast_handshake, 0, NULL, NULL },
|
||||
FORK(circuit_timeout),
|
||||
FORK(circuit_timeout_xm_alpha),
|
||||
FORK(rend_fns),
|
||||
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
@@ -828,9 +700,7 @@ struct testgroup_t testgroups[] = {
|
||||
{ "hs_ntor/", hs_ntor_tests },
|
||||
{ "hs_ob/", hs_ob_tests },
|
||||
{ "hs_service/", hs_service_tests },
|
||||
{ "introduce/", introduce_tests },
|
||||
{ "keypin/", keypin_tests },
|
||||
{ "legacy_hs/", hs_tests },
|
||||
{ "link-handshake/", link_handshake_tests },
|
||||
{ "mainloop/", mainloop_tests },
|
||||
{ "metrics/", metrics_tests },
|
||||
@@ -856,7 +726,6 @@ struct testgroup_t testgroups[] = {
|
||||
{ "relay/" , relay_tests },
|
||||
{ "relaycell/", relaycell_tests },
|
||||
{ "relaycrypt/", relaycrypt_tests },
|
||||
{ "rend_cache/", rend_cache_tests },
|
||||
{ "replaycache/", replaycache_tests },
|
||||
{ "router/", router_tests },
|
||||
{ "routerkeys/", routerkeys_tests },
|
||||
|
||||
@@ -145,8 +145,6 @@ extern struct testcase_t hs_metrics_tests[];
|
||||
extern struct testcase_t hs_ntor_tests[];
|
||||
extern struct testcase_t hs_ob_tests[];
|
||||
extern struct testcase_t hs_service_tests[];
|
||||
extern struct testcase_t hs_tests[];
|
||||
extern struct testcase_t introduce_tests[];
|
||||
extern struct testcase_t keypin_tests[];
|
||||
extern struct testcase_t link_handshake_tests[];
|
||||
extern struct testcase_t logging_tests[];
|
||||
@@ -179,7 +177,6 @@ extern struct testcase_t pubsub_msg_tests[];
|
||||
extern struct testcase_t relay_tests[];
|
||||
extern struct testcase_t relaycell_tests[];
|
||||
extern struct testcase_t relaycrypt_tests[];
|
||||
extern struct testcase_t rend_cache_tests[];
|
||||
extern struct testcase_t replaycache_tests[];
|
||||
extern struct testcase_t router_tests[];
|
||||
extern struct testcase_t routerkeys_tests[];
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "feature/nodelist/networkstatus.h"
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
#include "core/or/policies.h"
|
||||
#include "feature/rend/rendservice.h"
|
||||
#include "feature/relay/relay_find_addr.h"
|
||||
#include "feature/relay/router.h"
|
||||
#include "feature/relay/routermode.h"
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "feature/nodelist/microdesc.h"
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
#include "feature/nodelist/networkstatus.h"
|
||||
#include "feature/rend/rendcache.h"
|
||||
#include "feature/dircommon/directory.h"
|
||||
#include "core/or/connection_or.h"
|
||||
#include "lib/net/resolve.h"
|
||||
@@ -38,10 +37,6 @@ static void * test_conn_get_basic_setup(const struct testcase_t *tc);
|
||||
static int test_conn_get_basic_teardown(const struct testcase_t *tc,
|
||||
void *arg);
|
||||
|
||||
static void * test_conn_get_rend_setup(const struct testcase_t *tc);
|
||||
static int test_conn_get_rend_teardown(const struct testcase_t *tc,
|
||||
void *arg);
|
||||
|
||||
static void * test_conn_get_rsrc_setup(const struct testcase_t *tc);
|
||||
static int test_conn_get_rsrc_teardown(const struct testcase_t *tc,
|
||||
void *arg);
|
||||
@@ -179,52 +174,6 @@ test_conn_get_basic_teardown(const struct testcase_t *tc, void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
test_conn_get_rend_setup(const struct testcase_t *tc)
|
||||
{
|
||||
dir_connection_t *conn = DOWNCAST(dir_connection_t,
|
||||
test_conn_get_connection(
|
||||
TEST_CONN_STATE,
|
||||
TEST_CONN_TYPE,
|
||||
TEST_CONN_REND_PURPOSE));
|
||||
tt_assert(conn);
|
||||
assert_connection_ok(&conn->base_, time(NULL));
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
/* TODO: use directory_initiate_request() to do this - maybe? */
|
||||
tor_assert(strlen(TEST_CONN_REND_ADDR) == REND_SERVICE_ID_LEN_BASE32);
|
||||
conn->rend_data = rend_data_client_create(TEST_CONN_REND_ADDR, NULL, NULL,
|
||||
REND_NO_AUTH);
|
||||
assert_connection_ok(&conn->base_, time(NULL));
|
||||
return conn;
|
||||
|
||||
/* On failure */
|
||||
done:
|
||||
test_conn_get_rend_teardown(tc, conn);
|
||||
/* Returning NULL causes the unit test to fail */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
test_conn_get_rend_teardown(const struct testcase_t *tc, void *arg)
|
||||
{
|
||||
dir_connection_t *conn = DOWNCAST(dir_connection_t, arg);
|
||||
int rv = 0;
|
||||
|
||||
tt_assert(conn);
|
||||
assert_connection_ok(&conn->base_, time(NULL));
|
||||
|
||||
/* avoid a last-ditch attempt to refetch the descriptor */
|
||||
conn->base_.purpose = TEST_CONN_REND_PURPOSE_SUCCESSFUL;
|
||||
|
||||
/* connection_free_() cleans up rend_data */
|
||||
rv = test_conn_get_basic_teardown(tc, arg);
|
||||
done:
|
||||
rend_cache_free_all();
|
||||
return rv;
|
||||
}
|
||||
|
||||
static dir_connection_t *
|
||||
test_conn_download_status_add_a_connection(const char *resource)
|
||||
{
|
||||
@@ -369,10 +318,6 @@ static struct testcase_setup_t test_conn_get_basic_st = {
|
||||
test_conn_get_basic_setup, test_conn_get_basic_teardown
|
||||
};
|
||||
|
||||
static struct testcase_setup_t test_conn_get_rend_st = {
|
||||
test_conn_get_rend_setup, test_conn_get_rend_teardown
|
||||
};
|
||||
|
||||
static struct testcase_setup_t test_conn_get_rsrc_st = {
|
||||
test_conn_get_rsrc_setup, test_conn_get_rsrc_teardown
|
||||
};
|
||||
@@ -489,37 +434,6 @@ test_conn_get_basic(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_conn_get_rend(void *arg)
|
||||
{
|
||||
dir_connection_t *conn = DOWNCAST(dir_connection_t, arg);
|
||||
tt_assert(conn);
|
||||
assert_connection_ok(&conn->base_, time(NULL));
|
||||
|
||||
tt_assert(connection_get_by_type_state_rendquery(
|
||||
conn->base_.type,
|
||||
conn->base_.state,
|
||||
rend_data_get_address(
|
||||
conn->rend_data))
|
||||
== TO_CONN(conn));
|
||||
tt_assert(connection_get_by_type_state_rendquery(
|
||||
TEST_CONN_TYPE,
|
||||
TEST_CONN_STATE,
|
||||
TEST_CONN_REND_ADDR)
|
||||
== TO_CONN(conn));
|
||||
tt_assert(connection_get_by_type_state_rendquery(TEST_CONN_REND_TYPE_2,
|
||||
!conn->base_.state,
|
||||
"")
|
||||
== NULL);
|
||||
tt_assert(connection_get_by_type_state_rendquery(TEST_CONN_REND_TYPE_2,
|
||||
!TEST_CONN_STATE,
|
||||
TEST_CONN_REND_ADDR_2)
|
||||
== NULL);
|
||||
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
||||
#define sl_is_conn_assert(sl_input, conn) \
|
||||
do { \
|
||||
the_sl = (sl_input); \
|
||||
@@ -1091,7 +1005,6 @@ static const unsigned int PROXY_HAPROXY_ARG = PROXY_HAPROXY;
|
||||
|
||||
struct testcase_t connection_tests[] = {
|
||||
CONNECTION_TESTCASE(get_basic, TT_FORK, test_conn_get_basic_st),
|
||||
CONNECTION_TESTCASE(get_rend, TT_FORK, test_conn_get_rend_st),
|
||||
CONNECTION_TESTCASE(get_rsrc, TT_FORK, test_conn_get_rsrc_st),
|
||||
|
||||
CONNECTION_TESTCASE_ARG(download_status, TT_FORK,
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "feature/dircache/dirserv.h"
|
||||
#include "feature/hs/hs_common.h"
|
||||
#include "feature/nodelist/networkstatus.h"
|
||||
#include "feature/rend/rendservice.h"
|
||||
#include "feature/nodelist/authcert.h"
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
#include "feature/stats/rephist.h"
|
||||
@@ -316,110 +315,6 @@ test_add_onion_helper_keyarg_v3(void *arg)
|
||||
UNMOCK(control_write_reply);
|
||||
}
|
||||
|
||||
static void
|
||||
test_add_onion_helper_keyarg_v2(void *arg)
|
||||
{
|
||||
int ret, hs_version;
|
||||
add_onion_secret_key_t pk;
|
||||
crypto_pk_t *pk1 = NULL;
|
||||
const char *key_new_alg = NULL;
|
||||
char *key_new_blob = NULL;
|
||||
char *encoded = NULL;
|
||||
char *arg_str = NULL;
|
||||
|
||||
(void) arg;
|
||||
MOCK(control_write_reply, mock_control_write_reply);
|
||||
|
||||
memset(&pk, 0, sizeof(pk));
|
||||
|
||||
/* Test explicit RSA1024 key generation. */
|
||||
tor_free(reply_str);
|
||||
ret = add_onion_helper_keyarg("NEW:RSA1024", 0, &key_new_alg, &key_new_blob,
|
||||
&pk, &hs_version, NULL);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
tt_int_op(hs_version, OP_EQ, HS_VERSION_TWO);
|
||||
tt_assert(pk.v2);
|
||||
tt_str_op(key_new_alg, OP_EQ, "RSA1024");
|
||||
tt_assert(key_new_blob);
|
||||
tt_ptr_op(reply_str, OP_EQ, NULL);
|
||||
|
||||
/* Test discarding the private key. */
|
||||
crypto_pk_free(pk.v2); pk.v2 = NULL;
|
||||
tor_free(key_new_blob);
|
||||
ret = add_onion_helper_keyarg("NEW:RSA1024", 1, &key_new_alg, &key_new_blob,
|
||||
&pk, &hs_version, NULL);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
tt_int_op(hs_version, OP_EQ, HS_VERSION_TWO);
|
||||
tt_assert(pk.v2);
|
||||
tt_ptr_op(key_new_alg, OP_EQ, NULL);
|
||||
tt_ptr_op(key_new_blob, OP_EQ, NULL);
|
||||
tt_ptr_op(reply_str, OP_EQ, NULL);
|
||||
|
||||
/* Test generating a invalid key type. */
|
||||
crypto_pk_free(pk.v2); pk.v2 = NULL;
|
||||
ret = add_onion_helper_keyarg("NEW:RSA512", 0, &key_new_alg, &key_new_blob,
|
||||
&pk, &hs_version, NULL);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
tt_int_op(hs_version, OP_EQ, HS_VERSION_TWO);
|
||||
tt_assert(!pk.v2);
|
||||
tt_ptr_op(key_new_alg, OP_EQ, NULL);
|
||||
tt_ptr_op(key_new_blob, OP_EQ, NULL);
|
||||
tt_assert(reply_str);
|
||||
|
||||
/* Test loading a RSA1024 key. */
|
||||
tor_free(reply_str);
|
||||
pk1 = pk_generate(0);
|
||||
tt_int_op(0, OP_EQ, crypto_pk_base64_encode_private(pk1, &encoded));
|
||||
tor_asprintf(&arg_str, "RSA1024:%s", encoded);
|
||||
ret = add_onion_helper_keyarg(arg_str, 0, &key_new_alg, &key_new_blob,
|
||||
&pk, &hs_version, NULL);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
tt_int_op(hs_version, OP_EQ, HS_VERSION_TWO);
|
||||
tt_assert(pk.v2);
|
||||
tt_ptr_op(key_new_alg, OP_EQ, NULL);
|
||||
tt_ptr_op(key_new_blob, OP_EQ, NULL);
|
||||
tt_ptr_op(reply_str, OP_EQ, NULL);
|
||||
tt_int_op(crypto_pk_cmp_keys(pk1, pk.v2), OP_EQ, 0);
|
||||
|
||||
/* Test loading a invalid key type. */
|
||||
tor_free(arg_str);
|
||||
crypto_pk_free(pk1); pk1 = NULL;
|
||||
crypto_pk_free(pk.v2); pk.v2 = NULL;
|
||||
tor_asprintf(&arg_str, "RSA512:%s", encoded);
|
||||
ret = add_onion_helper_keyarg(arg_str, 0, &key_new_alg, &key_new_blob,
|
||||
&pk, &hs_version, NULL);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
tt_int_op(hs_version, OP_EQ, HS_VERSION_TWO);
|
||||
tt_assert(!pk.v2);
|
||||
tt_ptr_op(key_new_alg, OP_EQ, NULL);
|
||||
tt_ptr_op(key_new_blob, OP_EQ, NULL);
|
||||
tt_assert(reply_str);
|
||||
|
||||
/* Test loading a invalid key. */
|
||||
tor_free(arg_str);
|
||||
crypto_pk_free(pk.v2); pk.v2 = NULL;
|
||||
tor_free(reply_str);
|
||||
encoded[strlen(encoded)/2] = '\0';
|
||||
tor_asprintf(&arg_str, "RSA1024:%s", encoded);
|
||||
ret = add_onion_helper_keyarg(arg_str, 0, &key_new_alg, &key_new_blob,
|
||||
&pk, &hs_version, NULL);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
tt_int_op(hs_version, OP_EQ, HS_VERSION_TWO);
|
||||
tt_assert(!pk.v2);
|
||||
tt_ptr_op(key_new_alg, OP_EQ, NULL);
|
||||
tt_ptr_op(key_new_blob, OP_EQ, NULL);
|
||||
tt_assert(reply_str);
|
||||
|
||||
done:
|
||||
crypto_pk_free(pk1);
|
||||
crypto_pk_free(pk.v2);
|
||||
tor_free(key_new_blob);
|
||||
tor_free(reply_str);
|
||||
tor_free(encoded);
|
||||
tor_free(arg_str);
|
||||
UNMOCK(control_write_reply);
|
||||
}
|
||||
|
||||
static void
|
||||
test_getinfo_helper_onion(void *arg)
|
||||
{
|
||||
@@ -567,58 +462,6 @@ test_hs_parse_port_config(void *arg)
|
||||
tor_free(err_msg);
|
||||
}
|
||||
|
||||
static void
|
||||
test_add_onion_helper_clientauth(void *arg)
|
||||
{
|
||||
rend_authorized_client_t *client = NULL;
|
||||
int created = 0;
|
||||
|
||||
(void)arg;
|
||||
|
||||
MOCK(control_write_reply, mock_control_write_reply);
|
||||
/* Test "ClientName" only. */
|
||||
tor_free(reply_str);
|
||||
client = add_onion_helper_clientauth("alice", &created, NULL);
|
||||
tt_assert(client);
|
||||
tt_assert(created);
|
||||
tt_ptr_op(reply_str, OP_EQ, NULL);
|
||||
rend_authorized_client_free(client);
|
||||
|
||||
/* Test "ClientName:Blob" */
|
||||
tor_free(reply_str);
|
||||
client = add_onion_helper_clientauth("alice:475hGBHPlq7Mc0cRZitK/B",
|
||||
&created, NULL);
|
||||
tt_assert(client);
|
||||
tt_assert(!created);
|
||||
tt_ptr_op(reply_str, OP_EQ, NULL);
|
||||
rend_authorized_client_free(client);
|
||||
|
||||
/* Test invalid client names */
|
||||
tor_free(reply_str);
|
||||
client = add_onion_helper_clientauth("no*asterisks*allowed", &created,
|
||||
NULL);
|
||||
tt_ptr_op(client, OP_EQ, NULL);
|
||||
tt_assert(reply_str);
|
||||
|
||||
/* Test invalid auth cookie */
|
||||
tor_free(reply_str);
|
||||
client = add_onion_helper_clientauth("alice:12345", &created, NULL);
|
||||
tt_ptr_op(client, OP_EQ, NULL);
|
||||
tt_assert(reply_str);
|
||||
|
||||
/* Test invalid syntax */
|
||||
tor_free(reply_str);
|
||||
client = add_onion_helper_clientauth(":475hGBHPlq7Mc0cRZitK/B", &created,
|
||||
NULL);
|
||||
tt_ptr_op(client, OP_EQ, NULL);
|
||||
tt_assert(reply_str);
|
||||
|
||||
done:
|
||||
rend_authorized_client_free(client);
|
||||
tor_free(reply_str);
|
||||
UNMOCK(control_write_reply);
|
||||
}
|
||||
|
||||
/* Mocks and data/variables used for GETINFO download status tests */
|
||||
|
||||
static const download_status_t dl_status_default =
|
||||
@@ -2209,15 +2052,11 @@ struct testcase_t controller_tests[] = {
|
||||
PARSER_TEST(no_args_one_obj),
|
||||
PARSER_TEST(no_args_kwargs),
|
||||
PARSER_TEST(one_arg_kwargs),
|
||||
{ "add_onion_helper_keyarg_v2", test_add_onion_helper_keyarg_v2, 0,
|
||||
NULL, NULL },
|
||||
{ "add_onion_helper_keyarg_v3", test_add_onion_helper_keyarg_v3, 0,
|
||||
NULL, NULL },
|
||||
{ "getinfo_helper_onion", test_getinfo_helper_onion, 0, NULL, NULL },
|
||||
{ "hs_parse_port_config", test_hs_parse_port_config, 0,
|
||||
NULL, NULL },
|
||||
{ "add_onion_helper_clientauth", test_add_onion_helper_clientauth, 0, NULL,
|
||||
NULL },
|
||||
{ "download_status_consensus", test_download_status_consensus, 0, NULL,
|
||||
NULL },
|
||||
{"getinfo_helper_current_consensus_from_cache",
|
||||
|
||||
@@ -4848,9 +4848,6 @@ test_dir_purpose_needs_anonymity_returns_true_for_bridges(void *arg)
|
||||
tt_int_op(1, OP_EQ, purpose_needs_anonymity(0, ROUTER_PURPOSE_BRIDGE, NULL));
|
||||
tt_int_op(1, OP_EQ, purpose_needs_anonymity(0, ROUTER_PURPOSE_BRIDGE,
|
||||
"foobar"));
|
||||
tt_int_op(1, OP_EQ,
|
||||
purpose_needs_anonymity(DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2,
|
||||
ROUTER_PURPOSE_BRIDGE, NULL));
|
||||
done: ;
|
||||
}
|
||||
|
||||
@@ -4864,21 +4861,6 @@ test_dir_purpose_needs_anonymity_returns_false_for_own_bridge_desc(void *arg)
|
||||
done: ;
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_purpose_needs_anonymity_returns_true_for_sensitive_purpose(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
tt_int_op(1, OP_EQ, purpose_needs_anonymity(
|
||||
DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2,
|
||||
ROUTER_PURPOSE_GENERAL, NULL));
|
||||
tt_int_op(1, OP_EQ, purpose_needs_anonymity(
|
||||
DIR_PURPOSE_UPLOAD_RENDDESC_V2, 0, NULL));
|
||||
tt_int_op(1, OP_EQ, purpose_needs_anonymity(
|
||||
DIR_PURPOSE_FETCH_RENDDESC_V2, 0, NULL));
|
||||
done: ;
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_purpose_needs_anonymity_ret_false_for_non_sensitive_conn(void *arg)
|
||||
{
|
||||
@@ -4937,12 +4919,6 @@ test_dir_fetch_type(void *arg)
|
||||
tt_int_op(dir_fetch_type(DIR_PURPOSE_FETCH_MICRODESC, ROUTER_PURPOSE_GENERAL,
|
||||
NULL), OP_EQ, MICRODESC_DIRINFO);
|
||||
|
||||
/* This will give a warning, because this function isn't supposed to be
|
||||
* used for HS descriptors. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
tt_int_op(dir_fetch_type(DIR_PURPOSE_FETCH_RENDDESC_V2,
|
||||
ROUTER_PURPOSE_GENERAL, NULL), OP_EQ, NO_DIRINFO);
|
||||
expect_single_log_msg_containing("Unexpected purpose");
|
||||
done:
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
@@ -5300,10 +5276,6 @@ test_dir_conn_purpose_to_string(void *data)
|
||||
EXPECT_CONN_PURPOSE(DIR_PURPOSE_FETCH_STATUS_VOTE, "status vote fetch");
|
||||
EXPECT_CONN_PURPOSE(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES,
|
||||
"consensus signature fetch");
|
||||
EXPECT_CONN_PURPOSE(DIR_PURPOSE_FETCH_RENDDESC_V2,
|
||||
"hidden-service v2 descriptor fetch");
|
||||
EXPECT_CONN_PURPOSE(DIR_PURPOSE_UPLOAD_RENDDESC_V2,
|
||||
"hidden-service v2 descriptor upload");
|
||||
EXPECT_CONN_PURPOSE(DIR_PURPOSE_FETCH_MICRODESC, "microdescriptor fetch");
|
||||
|
||||
/* This will give a warning, because there is no purpose 1024. */
|
||||
@@ -7311,7 +7283,6 @@ struct testcase_t dir_tests[] = {
|
||||
DIR(purpose_needs_anonymity_returns_true_for_bridges, 0),
|
||||
DIR(purpose_needs_anonymity_returns_false_for_own_bridge_desc, 0),
|
||||
DIR(purpose_needs_anonymity_returns_true_by_default, 0),
|
||||
DIR(purpose_needs_anonymity_returns_true_for_sensitive_purpose, 0),
|
||||
DIR(purpose_needs_anonymity_ret_false_for_non_sensitive_conn, 0),
|
||||
DIR(post_parsing, 0),
|
||||
DIR(fetch_type, 0),
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
#include "feature/dircache/dircache.h"
|
||||
#include "test/test.h"
|
||||
#include "lib/compress/compress.h"
|
||||
#include "feature/rend/rendcommon.h"
|
||||
#include "feature/rend/rendcache.h"
|
||||
#include "feature/relay/relay_config.h"
|
||||
#include "feature/relay/router.h"
|
||||
#include "feature/nodelist/authcert.h"
|
||||
#include "feature/nodelist/dirlist.h"
|
||||
#include "feature/nodelist/routerlist.h"
|
||||
#include "test/rend_test_helpers.h"
|
||||
#include "feature/nodelist/microdesc.h"
|
||||
#include "test/test_helpers.h"
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
@@ -44,7 +41,6 @@
|
||||
#include "feature/dircommon/dir_connection_st.h"
|
||||
#include "feature/dirclient/dir_server_st.h"
|
||||
#include "feature/nodelist/networkstatus_st.h"
|
||||
#include "feature/rend/rend_encoded_v2_service_descriptor_st.h"
|
||||
#include "feature/nodelist/routerinfo_st.h"
|
||||
#include "feature/nodelist/routerlist_st.h"
|
||||
|
||||
@@ -261,125 +257,6 @@ test_dir_handle_get_robots_txt(void *data)
|
||||
tor_free(body);
|
||||
}
|
||||
|
||||
#define RENDEZVOUS2_GET(descid) GET("/tor/rendezvous2/" descid)
|
||||
static void
|
||||
test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data)
|
||||
{
|
||||
dir_connection_t *conn = NULL;
|
||||
char *header = NULL;
|
||||
(void) data;
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
|
||||
conn = new_dir_conn();
|
||||
|
||||
// connection is not encrypted
|
||||
tt_assert(!connection_dir_is_encrypted(conn));
|
||||
|
||||
tt_int_op(directory_handle_command_get(conn, RENDEZVOUS2_GET(), NULL, 0),
|
||||
OP_EQ, 0);
|
||||
fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
||||
NULL, NULL, 1, 0);
|
||||
|
||||
tt_str_op(NOT_FOUND, OP_EQ, header);
|
||||
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
|
||||
void *data)
|
||||
{
|
||||
dir_connection_t *conn = NULL;
|
||||
char *header = NULL;
|
||||
(void) data;
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
conn = new_dir_conn();
|
||||
|
||||
// connection is encrypted
|
||||
TO_CONN(conn)->linked = 1;
|
||||
tt_assert(connection_dir_is_encrypted(conn));
|
||||
|
||||
tt_int_op(directory_handle_command_get(conn,
|
||||
RENDEZVOUS2_GET("invalid-desc-id"), NULL, 0), OP_EQ, 0);
|
||||
fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
||||
NULL, NULL, 1, 0);
|
||||
|
||||
tt_str_op(header, OP_EQ, BAD_REQUEST);
|
||||
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data)
|
||||
{
|
||||
dir_connection_t *conn = NULL;
|
||||
char *header = NULL;
|
||||
(void) data;
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
conn = new_dir_conn();
|
||||
|
||||
// connection is encrypted
|
||||
TO_CONN(conn)->linked = 1;
|
||||
tt_assert(connection_dir_is_encrypted(conn));
|
||||
|
||||
//TODO: this can't be reached because rend_valid_descriptor_id() prevents
|
||||
//this case to happen. This test is the same as
|
||||
//test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id We
|
||||
//should refactor to remove the case from the switch.
|
||||
|
||||
const char *req = RENDEZVOUS2_GET("1bababababababababababababababab");
|
||||
tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
|
||||
|
||||
fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
||||
NULL, NULL, 1, 0);
|
||||
|
||||
tt_str_op(header, OP_EQ, BAD_REQUEST);
|
||||
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_handle_get_rendezvous2_not_found(void *data)
|
||||
{
|
||||
dir_connection_t *conn = NULL;
|
||||
char *header = NULL;
|
||||
(void) data;
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
conn = new_dir_conn();
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
// connection is encrypted
|
||||
TO_CONN(conn)->linked = 1;
|
||||
tt_assert(connection_dir_is_encrypted(conn));
|
||||
|
||||
const char *req = RENDEZVOUS2_GET("3xqunszqnaolrrfmtzgaki7mxelgvkje");
|
||||
tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
|
||||
fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
||||
NULL, NULL, 1, 0);
|
||||
|
||||
tt_str_op(NOT_FOUND, OP_EQ, header);
|
||||
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
rend_cache_free_all();
|
||||
}
|
||||
|
||||
static const routerinfo_t * dhg_tests_router_get_my_routerinfo(void);
|
||||
ATTR_UNUSED static int dhg_tests_router_get_my_routerinfo_called = 0;
|
||||
|
||||
@@ -395,76 +272,6 @@ dhg_tests_router_get_my_routerinfo(void)
|
||||
return mock_routerinfo;
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
||||
{
|
||||
dir_connection_t *conn = NULL;
|
||||
char *header = NULL;
|
||||
char *body = NULL;
|
||||
size_t body_used = 0;
|
||||
char buff[30];
|
||||
char req[70];
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
|
||||
char *service_id = NULL;
|
||||
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
||||
size_t body_len = 0;
|
||||
(void) data;
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
dhg_tests_router_get_my_routerinfo);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
/* 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, 0);
|
||||
|
||||
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
|
||||
DIGEST_LEN);
|
||||
|
||||
conn = new_dir_conn();
|
||||
|
||||
// connection is encrypted
|
||||
TO_CONN(conn)->linked = 1;
|
||||
tt_assert(connection_dir_is_encrypted(conn));
|
||||
|
||||
tor_snprintf(req, sizeof(req), RENDEZVOUS2_GET("%s"), desc_id_base32);
|
||||
|
||||
tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
|
||||
|
||||
body_len = strlen(desc_holder->desc_str);
|
||||
fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
||||
&body, &body_used, body_len+1, 0);
|
||||
|
||||
tt_assert(header);
|
||||
tt_assert(body);
|
||||
|
||||
tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
|
||||
tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
|
||||
tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
|
||||
tt_assert(strstr(header, "Pragma: no-cache\r\n"));
|
||||
tor_snprintf(buff, sizeof(buff), "Content-Length: %ld\r\n", (long) body_len);
|
||||
tt_assert(strstr(header, buff));
|
||||
|
||||
tt_int_op(body_used, OP_EQ, strlen(body));
|
||||
tt_str_op(body, OP_EQ, desc_holder->desc_str);
|
||||
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
tor_free(body);
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
rend_cache_free_all();
|
||||
}
|
||||
|
||||
#define MICRODESC_GET(digest) GET("/tor/micro/d/" digest)
|
||||
static void
|
||||
test_dir_handle_get_micro_d_not_found(void *data)
|
||||
@@ -2934,11 +2741,6 @@ struct testcase_t dir_handle_get_tests[] = {
|
||||
DIR_HANDLE_CMD(v1_command_not_found, 0),
|
||||
DIR_HANDLE_CMD(v1_command, 0),
|
||||
DIR_HANDLE_CMD(robots_txt, 0),
|
||||
DIR_HANDLE_CMD(rendezvous2_not_found_if_not_encrypted, 0),
|
||||
DIR_HANDLE_CMD(rendezvous2_not_found, 0),
|
||||
DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_with_invalid_desc_id, 0),
|
||||
DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_not_well_formed, 0),
|
||||
DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_success, 0),
|
||||
DIR_HANDLE_CMD(micro_d_not_found, 0),
|
||||
DIR_HANDLE_CMD(micro_d_server_busy, 0),
|
||||
DIR_HANDLE_CMD(micro_d, 0),
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
|
||||
#include "feature/hs/hs_cache.h"
|
||||
#include "feature/rend/rendcache.h"
|
||||
|
||||
#include "core/or/entry_connection_st.h"
|
||||
#include "core/or/socks_request_st.h"
|
||||
@@ -748,7 +747,6 @@ test_entryconn_rewrite_onion_v3(void *arg)
|
||||
/* Make an onion connection using the SOCKS request */
|
||||
conn->entry_cfg.onion_traffic = 1;
|
||||
ENTRY_TO_CONN(conn)->state = AP_CONN_STATE_SOCKS_WAIT;
|
||||
tt_assert(!ENTRY_TO_EDGE_CONN(conn)->rend_data);
|
||||
tt_assert(!ENTRY_TO_EDGE_CONN(conn)->hs_ident);
|
||||
|
||||
/* Handle SOCKS and rewrite! */
|
||||
@@ -763,7 +761,6 @@ test_entryconn_rewrite_onion_v3(void *arg)
|
||||
"25njqamcweflpvkl73j4szahhihoc4xt3ktcgjnpaingr5yhkenl5sid");
|
||||
/* check that HS information got attached to the connection */
|
||||
tt_assert(ENTRY_TO_EDGE_CONN(conn)->hs_ident);
|
||||
tt_assert(!ENTRY_TO_EDGE_CONN(conn)->rend_data);
|
||||
|
||||
done:
|
||||
hs_free_all();
|
||||
|
||||
-1003
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "trunnel/ed25519_cert.h"
|
||||
#include "feature/hs/hs_cache.h"
|
||||
#include "feature/rend/rendcache.h"
|
||||
#include "feature/dircache/dircache.h"
|
||||
#include "feature/dirclient/dirclient.h"
|
||||
#include "feature/nodelist/networkstatus.h"
|
||||
@@ -51,8 +50,6 @@ init_test(void)
|
||||
{
|
||||
/* Always needed. Initialize the subsystem. */
|
||||
hs_cache_init();
|
||||
/* We need the v2 cache since our OOM and cache cleanup does poke at it. */
|
||||
rend_cache_init();
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
+10
-127
@@ -19,7 +19,6 @@
|
||||
#include "test/test.h"
|
||||
#include "test/test_helpers.h"
|
||||
#include "test/log_test_helpers.h"
|
||||
#include "test/rend_test_helpers.h"
|
||||
#include "test/hs_test_helpers.h"
|
||||
|
||||
#include "app/config/config.h"
|
||||
@@ -38,7 +37,6 @@
|
||||
#include "feature/hs/hs_config.h"
|
||||
#include "feature/hs/hs_ident.h"
|
||||
#include "feature/hs/hs_cache.h"
|
||||
#include "feature/rend/rendcache.h"
|
||||
#include "core/or/circuitlist.h"
|
||||
#include "core/or/circuitbuild.h"
|
||||
#include "core/or/extendinfo.h"
|
||||
@@ -137,12 +135,9 @@ helper_add_random_client_auth(const ed25519_public_key_t *service_pk)
|
||||
* hidden service. */
|
||||
static int
|
||||
helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out,
|
||||
connection_t **conn_out,
|
||||
int is_legacy)
|
||||
connection_t **conn_out)
|
||||
{
|
||||
int retval;
|
||||
channel_tls_t *n_chan=NULL;
|
||||
rend_data_t *conn_rend_data = NULL;
|
||||
origin_circuit_t *or_circ = NULL;
|
||||
connection_t *conn = NULL;
|
||||
ed25519_public_key_t service_pk;
|
||||
@@ -151,20 +146,13 @@ helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out,
|
||||
conn = test_conn_get_connection(AP_CONN_STATE_CIRCUIT_WAIT,
|
||||
CONN_TYPE_AP /* ??? */,
|
||||
0);
|
||||
if (is_legacy) {
|
||||
/* Legacy: Setup rend_data of stream */
|
||||
char service_id[REND_SERVICE_ID_LEN_BASE32+1] = {0};
|
||||
TO_EDGE_CONN(conn)->rend_data = mock_rend_data(service_id);
|
||||
conn_rend_data = TO_EDGE_CONN(conn)->rend_data;
|
||||
} else {
|
||||
/* prop224: Setup hs conn identifier on the stream */
|
||||
ed25519_secret_key_t sk;
|
||||
tt_int_op(0, OP_EQ, ed25519_secret_key_generate(&sk, 0));
|
||||
tt_int_op(0, OP_EQ, ed25519_public_key_generate(&service_pk, &sk));
|
||||
/* prop224: Setup hs conn identifier on the stream */
|
||||
ed25519_secret_key_t sk;
|
||||
tt_int_op(0, OP_EQ, ed25519_secret_key_generate(&sk, 0));
|
||||
tt_int_op(0, OP_EQ, ed25519_public_key_generate(&service_pk, &sk));
|
||||
|
||||
/* Setup hs_conn_identifier of stream */
|
||||
TO_EDGE_CONN(conn)->hs_ident = hs_ident_edge_conn_new(&service_pk);
|
||||
}
|
||||
/* Setup hs_conn_identifier of stream */
|
||||
TO_EDGE_CONN(conn)->hs_ident = hs_ident_edge_conn_new(&service_pk);
|
||||
|
||||
/* Make it wait for circuit */
|
||||
connection_ap_mark_as_pending_circuit(TO_ENTRY_CONN(conn));
|
||||
@@ -184,23 +172,8 @@ helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out,
|
||||
or_circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
|
||||
or_circ->build_state->is_internal = 1;
|
||||
|
||||
if (is_legacy) {
|
||||
/* Legacy: Setup rend data and final cpath */
|
||||
or_circ->build_state->pending_final_cpath =
|
||||
tor_malloc_zero(sizeof(crypt_path_t));
|
||||
or_circ->build_state->pending_final_cpath->magic = CRYPT_PATH_MAGIC;
|
||||
or_circ->build_state->pending_final_cpath->rend_dh_handshake_state =
|
||||
crypto_dh_new(DH_TYPE_REND);
|
||||
tt_assert(
|
||||
or_circ->build_state->pending_final_cpath->rend_dh_handshake_state);
|
||||
retval = crypto_dh_generate_public(
|
||||
or_circ->build_state->pending_final_cpath->rend_dh_handshake_state);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
or_circ->rend_data = rend_data_dup(conn_rend_data);
|
||||
} else {
|
||||
/* prop224: Setup hs ident on the circuit */
|
||||
or_circ->hs_ident = hs_ident_circuit_new(&service_pk);
|
||||
}
|
||||
/* prop224: Setup hs ident on the circuit */
|
||||
or_circ->hs_ident = hs_ident_circuit_new(&service_pk);
|
||||
|
||||
TO_CIRCUIT(or_circ)->state = CIRCUIT_STATE_OPEN;
|
||||
|
||||
@@ -219,91 +192,6 @@ helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Test: Ensure that setting up legacy e2e rendezvous circuits works
|
||||
* correctly. */
|
||||
static void
|
||||
test_e2e_rend_circuit_setup_legacy(void *arg)
|
||||
{
|
||||
ssize_t retval;
|
||||
origin_circuit_t *or_circ = NULL;
|
||||
connection_t *conn = NULL;
|
||||
|
||||
(void) arg;
|
||||
|
||||
/** In this test we create a v2 legacy HS stream and a circuit with the same
|
||||
* hidden service destination. We make the stream wait for circuits to be
|
||||
* established to the hidden service, and then we complete the circuit using
|
||||
* the hs_circuit_setup_e2e_rend_circ_legacy_client() function. We then
|
||||
* check that the end-to-end cpath was setup correctly and that the stream
|
||||
* was attached to the circuit as expected. */
|
||||
|
||||
MOCK(connection_ap_handshake_send_begin,
|
||||
mock_connection_ap_handshake_send_begin);
|
||||
|
||||
/* Setup */
|
||||
retval = helper_get_circ_and_stream_for_test( &or_circ, &conn, 1);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
tt_assert(or_circ);
|
||||
tt_assert(conn);
|
||||
|
||||
/* Check number of hops */
|
||||
retval = cpath_get_n_hops(&or_circ->cpath);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
|
||||
/* Check that our stream is not attached on any circuits */
|
||||
tt_ptr_op(TO_EDGE_CONN(conn)->on_circuit, OP_EQ, NULL);
|
||||
|
||||
/********************************************** */
|
||||
|
||||
/* Make a good RENDEZVOUS1 cell body because it needs to pass key exchange
|
||||
* digest verification... */
|
||||
uint8_t rend_cell_body[DH1024_KEY_LEN+DIGEST_LEN] = {2};
|
||||
{
|
||||
char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN];
|
||||
crypto_dh_t *dh_state =
|
||||
or_circ->build_state->pending_final_cpath->rend_dh_handshake_state;
|
||||
/* compute and overwrite digest of cell body with the right value */
|
||||
retval = crypto_dh_compute_secret(LOG_PROTOCOL_WARN, dh_state,
|
||||
(char*)rend_cell_body, DH1024_KEY_LEN,
|
||||
keys, DIGEST_LEN+CPATH_KEY_MATERIAL_LEN);
|
||||
tt_int_op(retval, OP_GT, 0);
|
||||
memcpy(rend_cell_body+DH1024_KEY_LEN, keys, DIGEST_LEN);
|
||||
}
|
||||
|
||||
/* Setup the circuit */
|
||||
retval = hs_circuit_setup_e2e_rend_circ_legacy_client(or_circ,
|
||||
rend_cell_body);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
|
||||
/**********************************************/
|
||||
|
||||
/* See that a hop was added to the circuit's cpath */
|
||||
retval = cpath_get_n_hops(&or_circ->cpath);
|
||||
tt_int_op(retval, OP_EQ, 1);
|
||||
|
||||
/* Check the digest algo */
|
||||
tt_int_op(
|
||||
crypto_digest_get_algorithm(or_circ->cpath->pvt_crypto.f_digest),
|
||||
OP_EQ, DIGEST_SHA1);
|
||||
tt_int_op(
|
||||
crypto_digest_get_algorithm(or_circ->cpath->pvt_crypto.b_digest),
|
||||
OP_EQ, DIGEST_SHA1);
|
||||
tt_assert(or_circ->cpath->pvt_crypto.f_crypto);
|
||||
tt_assert(or_circ->cpath->pvt_crypto.b_crypto);
|
||||
|
||||
/* Ensure that circ purpose was changed */
|
||||
tt_int_op(or_circ->base_.purpose, OP_EQ, CIRCUIT_PURPOSE_C_REND_JOINED);
|
||||
|
||||
/* Test that stream got attached */
|
||||
tt_ptr_op(TO_EDGE_CONN(conn)->on_circuit, OP_EQ, TO_CIRCUIT(or_circ));
|
||||
|
||||
done:
|
||||
connection_free_minimal(conn);
|
||||
if (or_circ)
|
||||
tor_free(TO_CIRCUIT(or_circ)->n_chan);
|
||||
circuit_free_(TO_CIRCUIT(or_circ));
|
||||
}
|
||||
|
||||
/* Test: Ensure that setting up v3 rendezvous circuits works correctly. */
|
||||
static void
|
||||
test_e2e_rend_circuit_setup(void *arg)
|
||||
@@ -326,7 +214,7 @@ test_e2e_rend_circuit_setup(void *arg)
|
||||
mock_connection_ap_handshake_send_begin);
|
||||
|
||||
/* Setup */
|
||||
retval = helper_get_circ_and_stream_for_test(&or_circ, &conn, 0);
|
||||
retval = helper_get_circ_and_stream_for_test(&or_circ, &conn);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
tt_assert(or_circ);
|
||||
tt_assert(conn);
|
||||
@@ -974,7 +862,6 @@ test_close_intro_circuits_new_desc(void *arg)
|
||||
(void) arg;
|
||||
|
||||
hs_init();
|
||||
rend_cache_init();
|
||||
|
||||
/* This is needed because of the client cache expiration timestamp is based
|
||||
* on having a consensus. See cached_client_descriptor_has_expired(). */
|
||||
@@ -1120,7 +1007,6 @@ test_close_intro_circuits_cache_clean(void *arg)
|
||||
(void) arg;
|
||||
|
||||
hs_init();
|
||||
rend_cache_init();
|
||||
|
||||
/* This is needed because of the client cache expiration timestamp is based
|
||||
* on having a consensus. See cached_client_descriptor_has_expired(). */
|
||||
@@ -1189,7 +1075,6 @@ test_close_intro_circuits_cache_clean(void *arg)
|
||||
circuit_free(circ);
|
||||
hs_descriptor_free(desc1);
|
||||
hs_free_all();
|
||||
rend_cache_free_all();
|
||||
UNMOCK(networkstatus_get_reasonably_live_consensus);
|
||||
}
|
||||
|
||||
@@ -1554,8 +1439,6 @@ test_purge_ephemeral_client_auth(void *arg)
|
||||
}
|
||||
|
||||
struct testcase_t hs_client_tests[] = {
|
||||
{ "e2e_rend_circuit_setup_legacy", test_e2e_rend_circuit_setup_legacy,
|
||||
TT_FORK, NULL, NULL },
|
||||
{ "e2e_rend_circuit_setup", test_e2e_rend_circuit_setup,
|
||||
TT_FORK, NULL, NULL },
|
||||
{ "client_pick_intro", test_client_pick_intro,
|
||||
|
||||
+11
-164
@@ -18,7 +18,6 @@
|
||||
#include "feature/hs/hs_common.h"
|
||||
#include "feature/hs/hs_config.h"
|
||||
#include "feature/hs/hs_service.h"
|
||||
#include "feature/rend/rendservice.h"
|
||||
|
||||
static int
|
||||
helper_config_service(const char *conf, int validate_only)
|
||||
@@ -49,7 +48,7 @@ test_invalid_service(void *arg)
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
expect_log_msg_containing("HiddenServiceVersion must be between 2 and 3");
|
||||
expect_log_msg_containing("HiddenServiceVersion must be between 3 and 3");
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
@@ -57,7 +56,7 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServiceAllowUnknownPorts 2\n"; /* Should be 0 or 1. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
@@ -72,7 +71,7 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServiceDirGroupReadable 2\n"; /* Should be 0 or 1. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
@@ -87,7 +86,7 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServiceMaxStreamsCloseCircuit 2\n"; /* Should be 0 or 1. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
@@ -102,7 +101,7 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceMaxStreams 65536\n"; /* One too many. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
@@ -117,10 +116,10 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 81\n";
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
@@ -134,7 +133,7 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 65536\n";
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
@@ -147,7 +146,7 @@ test_invalid_service(void *arg)
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 80 127.0.0.1 8000\n";
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, 1);
|
||||
@@ -160,7 +159,7 @@ test_invalid_service(void *arg)
|
||||
/* Out of order directives. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServicePort 80\n";
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
@@ -182,18 +181,11 @@ test_valid_service(void *arg)
|
||||
|
||||
(void) arg;
|
||||
|
||||
/* Mix of v2 and v3. Still valid. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 81\n"
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 82\n";
|
||||
"HiddenServicePort 81\n";
|
||||
ret = helper_config_service(conf, 1);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
@@ -202,127 +194,6 @@ test_valid_service(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_invalid_service_v2(void *arg)
|
||||
{
|
||||
int validate_only = 1, ret;
|
||||
|
||||
(void) arg;
|
||||
|
||||
/* Try with a missing port configuration. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n";
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, validate_only);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
expect_log_msg_containing("with no ports configured.");
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
/* Too many introduction points. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceNumIntroductionPoints 11\n"; /* One too many. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, validate_only);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
expect_log_msg_containing("HiddenServiceNumIntroductionPoints must "
|
||||
"be between 0 and 10, not 11.");
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
/* Too little introduction points. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceNumIntroductionPoints -1\n";
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, validate_only);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
expect_log_msg_containing("Could not parse "
|
||||
"HiddenServiceNumIntroductionPoints: "
|
||||
"Integer -1 is malformed or out of bounds.");
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
/* Bad authorized client type. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceAuthorizeClient blah alice,bob\n"; /* blah is no good. */
|
||||
setup_full_capture_of_logs(LOG_WARN);
|
||||
ret = helper_config_service(conf, validate_only);
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
expect_log_msg_containing("HiddenServiceAuthorizeClient contains "
|
||||
"unrecognized auth-type");
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_valid_service_v2(void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
(void) arg;
|
||||
mock_hostname_resolver();
|
||||
|
||||
/* Valid complex configuration. Basic client authorization. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServicePort 22 localhost:22\n"
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
"HiddenServicePort 42 unix:/path/to/socket\n"
|
||||
#endif
|
||||
"HiddenServiceAuthorizeClient basic alice,bob,eve\n"
|
||||
"HiddenServiceAllowUnknownPorts 1\n"
|
||||
"HiddenServiceMaxStreams 42\n"
|
||||
"HiddenServiceMaxStreamsCloseCircuit 0\n"
|
||||
"HiddenServiceDirGroupReadable 1\n"
|
||||
"HiddenServiceNumIntroductionPoints 7\n";
|
||||
ret = helper_config_service(conf, 1);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
/* Valid complex configuration. Stealth client authorization. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 65535\n"
|
||||
"HiddenServicePort 22 1.1.1.1:22\n"
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
"HiddenServicePort 9000 unix:/path/to/socket\n"
|
||||
#endif
|
||||
"HiddenServiceAuthorizeClient stealth charlie,romeo\n"
|
||||
"HiddenServiceAllowUnknownPorts 0\n"
|
||||
"HiddenServiceMaxStreams 42\n"
|
||||
"HiddenServiceMaxStreamsCloseCircuit 0\n"
|
||||
"HiddenServiceDirGroupReadable 1\n"
|
||||
"HiddenServiceNumIntroductionPoints 8\n";
|
||||
ret = helper_config_service(conf, 1);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
done:
|
||||
unmock_hostname_resolver();
|
||||
}
|
||||
|
||||
static void
|
||||
test_invalid_service_v3(void *arg)
|
||||
{
|
||||
@@ -438,22 +309,6 @@ test_valid_service_v3(void *arg)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
/* Mix of v2 and v3. Still valid. */
|
||||
{
|
||||
const char *conf =
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 80\n"
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
|
||||
"HiddenServiceVersion 3\n"
|
||||
"HiddenServicePort 81\n"
|
||||
"HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
|
||||
"HiddenServiceVersion 2\n"
|
||||
"HiddenServicePort 82\n";
|
||||
ret = helper_config_service(conf, 1);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
done:
|
||||
unmock_hostname_resolver();
|
||||
}
|
||||
@@ -489,8 +344,6 @@ test_staging_service_v3(void *arg)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
/* Ok, we have a service in our map! Registration went well. */
|
||||
tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 1);
|
||||
/* Make sure we don't have a magic v2 service out of this. */
|
||||
tt_int_op(rend_num_services(), OP_EQ, 0);
|
||||
|
||||
done:
|
||||
hs_free_all();
|
||||
@@ -611,12 +464,6 @@ struct testcase_t hs_config_tests[] = {
|
||||
{ "valid_service", test_valid_service, TT_FORK,
|
||||
NULL, NULL },
|
||||
|
||||
/* Test case only for version 2. */
|
||||
{ "invalid_service_v2", test_invalid_service_v2, TT_FORK,
|
||||
NULL, NULL },
|
||||
{ "valid_service_v2", test_valid_service_v2, TT_FORK,
|
||||
NULL, NULL },
|
||||
|
||||
/* Test case only for version 3. */
|
||||
{ "invalid_service_v3", test_invalid_service_v3, TT_FORK,
|
||||
NULL, NULL },
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "feature/hs/hs_client.h"
|
||||
#include "feature/hs/hs_control.h"
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
#include "feature/rend/rendservice.h"
|
||||
|
||||
#include "feature/nodelist/node_st.h"
|
||||
#include "feature/nodelist/routerstatus_st.h"
|
||||
@@ -797,7 +796,7 @@ test_hs_control_add_onion_helper_add_service(void *arg)
|
||||
hs_service_authorized_client_t *client_good, *client_bad;
|
||||
smartlist_t *list_good, *list_bad;
|
||||
hs_service_ht *global_map;
|
||||
rend_service_port_config_t *portcfg;
|
||||
hs_port_config_t *portcfg;
|
||||
smartlist_t *portcfgs;
|
||||
char *address_out_good, *address_out_bad;
|
||||
hs_service_t *service_good = NULL;
|
||||
@@ -808,7 +807,7 @@ test_hs_control_add_onion_helper_add_service(void *arg)
|
||||
hs_init();
|
||||
global_map = get_hs_service_map();
|
||||
|
||||
portcfg = rend_service_parse_port_config("8080", ",", NULL);
|
||||
portcfg = hs_parse_port_config("8080", ",", NULL);
|
||||
portcfgs = smartlist_new();
|
||||
smartlist_add(portcfgs, portcfg);
|
||||
|
||||
@@ -831,7 +830,7 @@ test_hs_control_add_onion_helper_add_service(void *arg)
|
||||
smartlist_add(list_good, client_good);
|
||||
|
||||
add_onion_helper_add_service(HS_VERSION_THREE, &sk_good, portcfgs, 1, 1,
|
||||
REND_V3_AUTH, NULL, list_good, &address_out_good);
|
||||
list_good, &address_out_good);
|
||||
|
||||
service_good = find_service(global_map, &pk_good);
|
||||
tt_int_op(smartlist_len(service_good->config.clients), OP_EQ, 1);
|
||||
@@ -841,12 +840,12 @@ test_hs_control_add_onion_helper_add_service(void *arg)
|
||||
list_bad = smartlist_new();
|
||||
smartlist_add(list_bad, client_bad);
|
||||
|
||||
portcfg = rend_service_parse_port_config("8080", ",", NULL);
|
||||
portcfg = hs_parse_port_config("8080", ",", NULL);
|
||||
portcfgs = smartlist_new();
|
||||
smartlist_add(portcfgs, portcfg);
|
||||
|
||||
add_onion_helper_add_service(HS_VERSION_THREE, &sk_bad, portcfgs, 1, 1,
|
||||
REND_V3_AUTH, NULL, list_bad, &address_out_bad);
|
||||
list_bad, &address_out_bad);
|
||||
|
||||
service_bad = find_service(global_map, &pk_bad);
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "core/or/circuituse.h"
|
||||
#include "ht.h"
|
||||
#include "core/or/relay.h"
|
||||
#include "feature/rend/rendservice.h"
|
||||
|
||||
#include "feature/hs/hs_cell.h"
|
||||
#include "feature/hs/hs_circuitmap.h"
|
||||
@@ -517,42 +516,6 @@ helper_establish_intro_v3(or_circuit_t *intro_circ)
|
||||
return cell;
|
||||
}
|
||||
|
||||
/* Helper function: Send a well-formed v2 ESTABLISH_INTRO cell to
|
||||
* <b>intro_circ</b>. Return the public key advertised in the cell. */
|
||||
static crypto_pk_t *
|
||||
helper_establish_intro_v2(or_circuit_t *intro_circ)
|
||||
{
|
||||
crypto_pk_t *key1 = NULL;
|
||||
int retval;
|
||||
uint8_t cell_body[RELAY_PAYLOAD_SIZE];
|
||||
ssize_t cell_len = 0;
|
||||
char circ_nonce[DIGEST_LEN] = {0};
|
||||
|
||||
tt_assert(intro_circ);
|
||||
|
||||
/* Prepare the circuit for the incoming ESTABLISH_INTRO */
|
||||
crypto_rand(circ_nonce, sizeof(circ_nonce));
|
||||
helper_prepare_circ_for_intro(intro_circ, circ_nonce);
|
||||
|
||||
/* Send legacy establish_intro */
|
||||
key1 = pk_generate(0);
|
||||
|
||||
/* Use old circ_nonce why not */
|
||||
cell_len = rend_service_encode_establish_intro_cell(
|
||||
(char*)cell_body,
|
||||
sizeof(cell_body), key1,
|
||||
circ_nonce);
|
||||
tt_int_op(cell_len, OP_GT, 0);
|
||||
|
||||
/* Receive legacy establish_intro */
|
||||
retval = hs_intro_received_establish_intro(intro_circ,
|
||||
cell_body, (size_t) cell_len);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
return key1;
|
||||
}
|
||||
|
||||
/* Helper function: test circuitmap free_all function outside of
|
||||
* test_intro_point_registration to prevent Coverity from seeing a
|
||||
* double free if the assertion hypothetically fails.
|
||||
@@ -571,21 +534,17 @@ test_circuitmap_free_all(void)
|
||||
;
|
||||
}
|
||||
|
||||
/** Successfully register a v2 intro point and a v3 intro point. Ensure that HS
|
||||
/** Successfully register a v3 intro point. Ensure that HS
|
||||
* circuitmap is maintained properly. */
|
||||
static void
|
||||
test_intro_point_registration(void *arg)
|
||||
{
|
||||
int retval;
|
||||
hs_circuitmap_ht *the_hs_circuitmap = NULL;
|
||||
|
||||
or_circuit_t *intro_circ = NULL;
|
||||
trn_cell_establish_intro_t *establish_intro_cell = NULL;
|
||||
ed25519_public_key_t auth_key;
|
||||
|
||||
crypto_pk_t *legacy_auth_key = NULL;
|
||||
or_circuit_t *legacy_intro_circ = NULL;
|
||||
|
||||
or_circuit_t *returned_intro_circ = NULL;
|
||||
|
||||
(void) arg;
|
||||
@@ -621,35 +580,11 @@ test_intro_point_registration(void *arg)
|
||||
tt_ptr_op(intro_circ, OP_EQ, returned_intro_circ);
|
||||
}
|
||||
|
||||
/* Create a v2 intro point */
|
||||
{
|
||||
char key_digest[DIGEST_LEN];
|
||||
|
||||
legacy_intro_circ = or_circuit_new(1, NULL);
|
||||
tt_assert(legacy_intro_circ);
|
||||
legacy_auth_key = helper_establish_intro_v2(legacy_intro_circ);
|
||||
tt_assert(legacy_auth_key);
|
||||
|
||||
/* Check that the circuitmap now has two elements */
|
||||
the_hs_circuitmap = get_hs_circuitmap();
|
||||
tt_assert(the_hs_circuitmap);
|
||||
tt_int_op(2, OP_EQ, HT_SIZE(the_hs_circuitmap));
|
||||
|
||||
/* Check that the new element is our legacy intro circuit. */
|
||||
retval = crypto_pk_get_digest(legacy_auth_key, key_digest);
|
||||
tt_int_op(retval, OP_EQ, 0);
|
||||
returned_intro_circ =
|
||||
hs_circuitmap_get_intro_circ_v2_relay_side((uint8_t*)key_digest);
|
||||
tt_ptr_op(legacy_intro_circ, OP_EQ, returned_intro_circ);
|
||||
}
|
||||
|
||||
/* XXX Continue test and try to register a second v3 intro point with the
|
||||
* same auth key. Make sure that old intro circuit gets closed. */
|
||||
|
||||
done:
|
||||
crypto_pk_free(legacy_auth_key);
|
||||
circuit_free_(TO_CIRCUIT(intro_circ));
|
||||
circuit_free_(TO_CIRCUIT(legacy_intro_circ));
|
||||
trn_cell_establish_intro_free(establish_intro_cell);
|
||||
test_circuitmap_free_all();
|
||||
|
||||
@@ -719,31 +654,6 @@ test_introduce1_suitable_circuit(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_introduce1_is_legacy(void *arg)
|
||||
{
|
||||
int ret;
|
||||
uint8_t request[256];
|
||||
|
||||
(void) arg;
|
||||
|
||||
/* For a cell to be considered legacy, according to the specification, the
|
||||
* first 20 bytes MUST BE non-zero else it's a v3 cell. */
|
||||
memset(request, 'a', DIGEST_LEN);
|
||||
memset(request + DIGEST_LEN, 0, sizeof(request) - DIGEST_LEN);
|
||||
ret = introduce1_cell_is_legacy(request);
|
||||
tt_int_op(ret, OP_EQ, 1);
|
||||
|
||||
/* This is a NON legacy cell. */
|
||||
memset(request, 0, DIGEST_LEN);
|
||||
memset(request + DIGEST_LEN, 'a', sizeof(request) - DIGEST_LEN);
|
||||
ret = introduce1_cell_is_legacy(request);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_introduce1_validation(void *arg)
|
||||
{
|
||||
@@ -757,20 +667,6 @@ test_introduce1_validation(void *arg)
|
||||
cell = helper_create_introduce1_cell();
|
||||
tt_assert(cell);
|
||||
|
||||
#ifndef ALL_BUGS_ARE_FATAL
|
||||
/* It should NOT be a legacy cell which will trigger a BUG(). */
|
||||
memset(cell->legacy_key_id, 'a', sizeof(cell->legacy_key_id));
|
||||
tor_capture_bugs_(1);
|
||||
ret = validate_introduce1_parsed_cell(cell);
|
||||
tor_end_capture_bugs_();
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
#endif /* !defined(ALL_BUGS_ARE_FATAL) */
|
||||
|
||||
/* Reset legacy ID and make sure it's correct. */
|
||||
memset(cell->legacy_key_id, 0, sizeof(cell->legacy_key_id));
|
||||
ret = validate_introduce1_parsed_cell(cell);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Non existing auth key type. */
|
||||
cell->auth_key_type = 42;
|
||||
ret = validate_introduce1_parsed_cell(cell);
|
||||
@@ -877,35 +773,6 @@ test_received_introduce1_handling(void *arg)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
/* Valid legacy cell. */
|
||||
{
|
||||
tor_free(request);
|
||||
trn_cell_introduce1_free(cell);
|
||||
cell = helper_create_introduce1_cell();
|
||||
uint8_t *legacy_key_id = trn_cell_introduce1_getarray_legacy_key_id(cell);
|
||||
memset(legacy_key_id, 'a', DIGEST_LEN);
|
||||
/* Add an arbitrary amount of data for the payload of a v2 cell. */
|
||||
size_t request_len = trn_cell_introduce1_encoded_len(cell) + 256;
|
||||
tt_size_op(request_len, OP_GT, 0);
|
||||
request = tor_malloc_zero(request_len + 256);
|
||||
ssize_t encoded_len =
|
||||
trn_cell_introduce1_encode(request, request_len, cell);
|
||||
tt_int_op((int)encoded_len, OP_GT, 0);
|
||||
|
||||
circ = helper_create_intro_circuit();
|
||||
or_circuit_t *service_circ = helper_create_intro_circuit();
|
||||
circuit_change_purpose(TO_CIRCUIT(service_circ),
|
||||
CIRCUIT_PURPOSE_INTRO_POINT);
|
||||
/* Register the circuit in the map for the auth key of the cell. */
|
||||
uint8_t token[REND_TOKEN_LEN];
|
||||
memcpy(token, legacy_key_id, sizeof(token));
|
||||
hs_circuitmap_register_intro_circ_v2_relay_side(service_circ, token);
|
||||
ret = hs_intro_received_introduce1(circ, request, request_len);
|
||||
circuit_free_(TO_CIRCUIT(circ));
|
||||
circuit_free_(TO_CIRCUIT(service_circ));
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
done:
|
||||
trn_cell_introduce1_free(cell);
|
||||
tor_free(request);
|
||||
@@ -1109,9 +976,6 @@ struct testcase_t hs_intropoint_tests[] = {
|
||||
{ "introduce1_suitable_circuit",
|
||||
test_introduce1_suitable_circuit, TT_FORK, NULL, &test_setup},
|
||||
|
||||
{ "introduce1_is_legacy",
|
||||
test_introduce1_is_legacy, TT_FORK, NULL, &test_setup},
|
||||
|
||||
{ "introduce1_validation",
|
||||
test_introduce1_validation, TT_FORK, NULL, &test_setup},
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "test/test.h"
|
||||
#include "test/test_helpers.h"
|
||||
#include "test/log_test_helpers.h"
|
||||
#include "test/rend_test_helpers.h"
|
||||
#include "test/hs_test_helpers.h"
|
||||
|
||||
#include "core/or/or.h"
|
||||
@@ -58,7 +57,6 @@
|
||||
#include "feature/hs/hs_service.h"
|
||||
#include "feature/nodelist/networkstatus.h"
|
||||
#include "feature/nodelist/nodelist.h"
|
||||
#include "feature/rend/rendservice.h"
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
#include "lib/fs/dir.h"
|
||||
|
||||
@@ -383,14 +381,13 @@ test_load_keys(void *arg)
|
||||
{
|
||||
int ret;
|
||||
char *conf = NULL;
|
||||
char *hsdir_v2 = tor_strdup(get_fname("hs2"));
|
||||
char *hsdir_v3 = tor_strdup(get_fname("hs3"));
|
||||
char addr[HS_SERVICE_ADDR_LEN_BASE32 + 1];
|
||||
|
||||
(void) arg;
|
||||
|
||||
/* We'll register two services, a v2 and a v3, then we'll load keys and
|
||||
* validate that both are in a correct state. */
|
||||
/* We'll register one service then we'll load keys and validate that both
|
||||
* are in a correct state. */
|
||||
|
||||
hs_init();
|
||||
|
||||
@@ -399,15 +396,6 @@ test_load_keys(void *arg)
|
||||
"HiddenServiceVersion %d\n" \
|
||||
"HiddenServicePort 65535\n"
|
||||
|
||||
/* v2 service. */
|
||||
tor_asprintf(&conf, conf_fmt, hsdir_v2, HS_VERSION_TWO);
|
||||
ret = helper_config_service(conf);
|
||||
tor_free(conf);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
/* This one should now be registered into the v2 list. */
|
||||
tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 0);
|
||||
tt_int_op(rend_num_services(), OP_EQ, 1);
|
||||
|
||||
/* v3 service. */
|
||||
tor_asprintf(&conf, conf_fmt, hsdir_v3, HS_VERSION_THREE);
|
||||
ret = helper_config_service(conf);
|
||||
@@ -441,7 +429,6 @@ test_load_keys(void *arg)
|
||||
tt_assert(!s->config.is_client_auth_enabled);
|
||||
|
||||
done:
|
||||
tor_free(hsdir_v2);
|
||||
tor_free(hsdir_v3);
|
||||
hs_free_all();
|
||||
}
|
||||
@@ -634,8 +621,8 @@ test_access_service(void *arg)
|
||||
|
||||
(void) arg;
|
||||
|
||||
/* We'll register two services, a v2 and a v3, then we'll load keys and
|
||||
* validate that both are in a correct state. */
|
||||
/* We'll register one service then we'll load keys and validate that both
|
||||
* are in a correct state. */
|
||||
|
||||
hs_init();
|
||||
|
||||
|
||||
@@ -1,539 +0,0 @@
|
||||
/* Copyright (c) 2012-2020, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#include "orconfig.h"
|
||||
#include "lib/crypt_ops/crypto_cipher.h"
|
||||
#include "core/or/or.h"
|
||||
#include "test/test.h"
|
||||
|
||||
#define RENDSERVICE_PRIVATE
|
||||
#include "feature/rend/rendservice.h"
|
||||
|
||||
static uint8_t v0_test_plaintext[] =
|
||||
/* 20 bytes of rendezvous point nickname */
|
||||
{ 0x4e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
/* 20 bytes dummy rendezvous cookie */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 128 bytes dummy DH handshake data */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
|
||||
|
||||
static uint8_t v1_test_plaintext[] =
|
||||
/* Version byte */
|
||||
{ 0x01,
|
||||
/* 42 bytes of dummy rendezvous point hex digest */
|
||||
0x24, 0x30, 0x30, 0x30, 0x31, 0x30, 0x32, 0x30,
|
||||
0x33, 0x30, 0x34, 0x30, 0x35, 0x30, 0x36, 0x30,
|
||||
0x37, 0x30, 0x38, 0x30, 0x39, 0x30, 0x41, 0x30,
|
||||
0x42, 0x30, 0x43, 0x30, 0x44, 0x30, 0x45, 0x30,
|
||||
0x46, 0x31, 0x30, 0x31, 0x31, 0x31, 0x32, 0x31,
|
||||
0x33, 0x00,
|
||||
/* 20 bytes dummy rendezvous cookie */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 128 bytes dummy DH handshake data */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
|
||||
|
||||
static uint8_t v2_test_plaintext[] =
|
||||
/* Version byte */
|
||||
{ 0x02,
|
||||
/* 4 bytes rendezvous point's IP address */
|
||||
0xc0, 0xa8, 0x00, 0x01,
|
||||
/* 2 bytes rendezvous point's OR port */
|
||||
0x23, 0x5a,
|
||||
/* 20 bytes dummy rendezvous point's identity digest */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 2 bytes length of onion key */
|
||||
0x00, 0x8c,
|
||||
/* Onion key (140 bytes taken from live test) */
|
||||
0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb1,
|
||||
0xcd, 0x46, 0xa9, 0x18, 0xd2, 0x0f, 0x01, 0xf8,
|
||||
0xb2, 0xad, 0xa4, 0x79, 0xb4, 0xbb, 0x4b, 0xf4,
|
||||
0x54, 0x1e, 0x3f, 0x03, 0x54, 0xcf, 0x7c, 0xb6,
|
||||
0xb5, 0xf0, 0xfe, 0xed, 0x4b, 0x7d, 0xd7, 0x61,
|
||||
0xdb, 0x6d, 0xd9, 0x19, 0xe2, 0x72, 0x04, 0xaa,
|
||||
0x3e, 0x89, 0x26, 0x14, 0x62, 0x9a, 0x6c, 0x11,
|
||||
0x0b, 0x35, 0x99, 0x2c, 0x9f, 0x2c, 0x64, 0xa1,
|
||||
0xd9, 0xe2, 0x88, 0xce, 0xf6, 0x54, 0xfe, 0x1d,
|
||||
0x37, 0x5e, 0x6d, 0x73, 0x95, 0x54, 0x90, 0xf0,
|
||||
0x7b, 0xfa, 0xd4, 0x44, 0xac, 0xb2, 0x23, 0x9f,
|
||||
0x75, 0x36, 0xe2, 0x78, 0x62, 0x82, 0x80, 0xa4,
|
||||
0x23, 0x22, 0xc9, 0xbf, 0xc4, 0x36, 0xd1, 0x31,
|
||||
0x33, 0x8e, 0x64, 0xb4, 0xa9, 0x74, 0xa1, 0xcb,
|
||||
0x42, 0x8d, 0x60, 0xc7, 0xbb, 0x8e, 0x6e, 0x0f,
|
||||
0x36, 0x74, 0x8e, 0xf4, 0x08, 0x99, 0x06, 0x92,
|
||||
0xb1, 0x3f, 0xb3, 0xdd, 0xed, 0xf7, 0xc9, 0x02,
|
||||
0x03, 0x01, 0x00, 0x01,
|
||||
/* 20 bytes dummy rendezvous cookie */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 128 bytes dummy DH handshake data */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
|
||||
|
||||
static uint8_t v3_no_auth_test_plaintext[] =
|
||||
/* Version byte */
|
||||
{ 0x03,
|
||||
/* Auth type (0 for no auth len/auth data) */
|
||||
0x00,
|
||||
/* Timestamp */
|
||||
0x50, 0x0b, 0xb5, 0xaa,
|
||||
/* 4 bytes rendezvous point's IP address */
|
||||
0xc0, 0xa8, 0x00, 0x01,
|
||||
/* 2 bytes rendezvous point's OR port */
|
||||
0x23, 0x5a,
|
||||
/* 20 bytes dummy rendezvous point's identity digest */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 2 bytes length of onion key */
|
||||
0x00, 0x8c,
|
||||
/* Onion key (140 bytes taken from live test) */
|
||||
0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb1,
|
||||
0xcd, 0x46, 0xa9, 0x18, 0xd2, 0x0f, 0x01, 0xf8,
|
||||
0xb2, 0xad, 0xa4, 0x79, 0xb4, 0xbb, 0x4b, 0xf4,
|
||||
0x54, 0x1e, 0x3f, 0x03, 0x54, 0xcf, 0x7c, 0xb6,
|
||||
0xb5, 0xf0, 0xfe, 0xed, 0x4b, 0x7d, 0xd7, 0x61,
|
||||
0xdb, 0x6d, 0xd9, 0x19, 0xe2, 0x72, 0x04, 0xaa,
|
||||
0x3e, 0x89, 0x26, 0x14, 0x62, 0x9a, 0x6c, 0x11,
|
||||
0x0b, 0x35, 0x99, 0x2c, 0x9f, 0x2c, 0x64, 0xa1,
|
||||
0xd9, 0xe2, 0x88, 0xce, 0xf6, 0x54, 0xfe, 0x1d,
|
||||
0x37, 0x5e, 0x6d, 0x73, 0x95, 0x54, 0x90, 0xf0,
|
||||
0x7b, 0xfa, 0xd4, 0x44, 0xac, 0xb2, 0x23, 0x9f,
|
||||
0x75, 0x36, 0xe2, 0x78, 0x62, 0x82, 0x80, 0xa4,
|
||||
0x23, 0x22, 0xc9, 0xbf, 0xc4, 0x36, 0xd1, 0x31,
|
||||
0x33, 0x8e, 0x64, 0xb4, 0xa9, 0x74, 0xa1, 0xcb,
|
||||
0x42, 0x8d, 0x60, 0xc7, 0xbb, 0x8e, 0x6e, 0x0f,
|
||||
0x36, 0x74, 0x8e, 0xf4, 0x08, 0x99, 0x06, 0x92,
|
||||
0xb1, 0x3f, 0xb3, 0xdd, 0xed, 0xf7, 0xc9, 0x02,
|
||||
0x03, 0x01, 0x00, 0x01,
|
||||
/* 20 bytes dummy rendezvous cookie */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 128 bytes dummy DH handshake data */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
|
||||
|
||||
static uint8_t v3_basic_auth_test_plaintext[] =
|
||||
/* Version byte */
|
||||
{ 0x03,
|
||||
/* Auth type (1 for REND_BASIC_AUTH) */
|
||||
0x01,
|
||||
/* Auth len (must be 16 bytes for REND_BASIC_AUTH) */
|
||||
0x00, 0x10,
|
||||
/* Auth data (a 16-byte dummy descriptor cookie) */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
/* Timestamp */
|
||||
0x50, 0x0b, 0xb5, 0xaa,
|
||||
/* 4 bytes rendezvous point's IP address */
|
||||
0xc0, 0xa8, 0x00, 0x01,
|
||||
/* 2 bytes rendezvous point's OR port */
|
||||
0x23, 0x5a,
|
||||
/* 20 bytes dummy rendezvous point's identity digest */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 2 bytes length of onion key */
|
||||
0x00, 0x8c,
|
||||
/* Onion key (140 bytes taken from live test) */
|
||||
0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb1,
|
||||
0xcd, 0x46, 0xa9, 0x18, 0xd2, 0x0f, 0x01, 0xf8,
|
||||
0xb2, 0xad, 0xa4, 0x79, 0xb4, 0xbb, 0x4b, 0xf4,
|
||||
0x54, 0x1e, 0x3f, 0x03, 0x54, 0xcf, 0x7c, 0xb6,
|
||||
0xb5, 0xf0, 0xfe, 0xed, 0x4b, 0x7d, 0xd7, 0x61,
|
||||
0xdb, 0x6d, 0xd9, 0x19, 0xe2, 0x72, 0x04, 0xaa,
|
||||
0x3e, 0x89, 0x26, 0x14, 0x62, 0x9a, 0x6c, 0x11,
|
||||
0x0b, 0x35, 0x99, 0x2c, 0x9f, 0x2c, 0x64, 0xa1,
|
||||
0xd9, 0xe2, 0x88, 0xce, 0xf6, 0x54, 0xfe, 0x1d,
|
||||
0x37, 0x5e, 0x6d, 0x73, 0x95, 0x54, 0x90, 0xf0,
|
||||
0x7b, 0xfa, 0xd4, 0x44, 0xac, 0xb2, 0x23, 0x9f,
|
||||
0x75, 0x36, 0xe2, 0x78, 0x62, 0x82, 0x80, 0xa4,
|
||||
0x23, 0x22, 0xc9, 0xbf, 0xc4, 0x36, 0xd1, 0x31,
|
||||
0x33, 0x8e, 0x64, 0xb4, 0xa9, 0x74, 0xa1, 0xcb,
|
||||
0x42, 0x8d, 0x60, 0xc7, 0xbb, 0x8e, 0x6e, 0x0f,
|
||||
0x36, 0x74, 0x8e, 0xf4, 0x08, 0x99, 0x06, 0x92,
|
||||
0xb1, 0x3f, 0xb3, 0xdd, 0xed, 0xf7, 0xc9, 0x02,
|
||||
0x03, 0x01, 0x00, 0x01,
|
||||
/* 20 bytes dummy rendezvous cookie */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13,
|
||||
/* 128 bytes dummy DH handshake data */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
|
||||
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
|
||||
|
||||
static void do_decrypt_test(uint8_t *plaintext, size_t plaintext_len);
|
||||
static void do_early_parse_test(uint8_t *plaintext, size_t plaintext_len);
|
||||
static void do_late_parse_test(uint8_t *plaintext, size_t plaintext_len);
|
||||
static void do_parse_test(uint8_t *plaintext, size_t plaintext_len, int phase);
|
||||
static ssize_t make_intro_from_plaintext(
|
||||
void *buf, size_t len, crypto_pk_t *key, void **cell_out);
|
||||
|
||||
#define EARLY_PARSE_ONLY 1
|
||||
#define DECRYPT_ONLY 2
|
||||
#define ALL_PARSING 3
|
||||
|
||||
static void
|
||||
do_early_parse_test(uint8_t *plaintext, size_t plaintext_len)
|
||||
{
|
||||
do_parse_test(plaintext, plaintext_len, EARLY_PARSE_ONLY);
|
||||
}
|
||||
|
||||
static void
|
||||
do_decrypt_test(uint8_t *plaintext, size_t plaintext_len)
|
||||
{
|
||||
do_parse_test(plaintext, plaintext_len, DECRYPT_ONLY);
|
||||
}
|
||||
|
||||
static void
|
||||
do_late_parse_test(uint8_t *plaintext, size_t plaintext_len)
|
||||
{
|
||||
do_parse_test(plaintext, plaintext_len, ALL_PARSING);
|
||||
}
|
||||
|
||||
/** Test utility function: checks that the <b>plaintext_len</b>-byte string at
|
||||
* <b>plaintext</b> is at least superficially parseable.
|
||||
*/
|
||||
static void
|
||||
do_parse_test(uint8_t *plaintext, size_t plaintext_len, int phase)
|
||||
{
|
||||
crypto_pk_t *k = NULL;
|
||||
ssize_t r;
|
||||
uint8_t *cell = NULL;
|
||||
size_t cell_len;
|
||||
rend_intro_cell_t *parsed_req = NULL;
|
||||
char *err_msg = NULL;
|
||||
char digest[DIGEST_LEN];
|
||||
|
||||
/* Get a key */
|
||||
k = crypto_pk_new();
|
||||
tt_assert(k);
|
||||
r = crypto_pk_read_private_key_from_string(k, AUTHORITY_SIGNKEY_1, -1);
|
||||
tt_assert(!r);
|
||||
|
||||
/* Get digest for future comparison */
|
||||
r = crypto_pk_get_digest(k, digest);
|
||||
tt_assert(r >= 0);
|
||||
|
||||
/* Make a cell out of it */
|
||||
r = make_intro_from_plaintext(
|
||||
plaintext, plaintext_len,
|
||||
k, (void **)(&cell));
|
||||
tt_assert(r > 0);
|
||||
tt_assert(cell);
|
||||
cell_len = r;
|
||||
|
||||
/* Do early parsing */
|
||||
parsed_req = rend_service_begin_parse_intro(cell, cell_len, 2, &err_msg);
|
||||
tt_assert(parsed_req);
|
||||
tt_ptr_op(err_msg, OP_EQ, NULL);
|
||||
tt_mem_op(parsed_req->pk,OP_EQ, digest, DIGEST_LEN);
|
||||
tt_assert(parsed_req->ciphertext);
|
||||
tt_assert(parsed_req->ciphertext_len > 0);
|
||||
|
||||
if (phase == EARLY_PARSE_ONLY)
|
||||
goto done;
|
||||
|
||||
/* Do decryption */
|
||||
r = rend_service_decrypt_intro(parsed_req, k, &err_msg);
|
||||
tt_assert(!r);
|
||||
tt_ptr_op(err_msg, OP_EQ, NULL);
|
||||
tt_assert(parsed_req->plaintext);
|
||||
tt_assert(parsed_req->plaintext_len > 0);
|
||||
|
||||
if (phase == DECRYPT_ONLY)
|
||||
goto done;
|
||||
|
||||
/* Do late parsing */
|
||||
r = rend_service_parse_intro_plaintext(parsed_req, &err_msg);
|
||||
tt_assert(!r);
|
||||
tt_ptr_op(err_msg, OP_EQ, NULL);
|
||||
tt_assert(parsed_req->parsed);
|
||||
|
||||
done:
|
||||
tor_free(cell);
|
||||
crypto_pk_free(k);
|
||||
rend_service_free_intro(parsed_req);
|
||||
tor_free(err_msg);
|
||||
}
|
||||
|
||||
/** Given the plaintext of the encrypted part of an INTRODUCE1/2 and a key,
|
||||
* construct the encrypted cell for testing.
|
||||
*/
|
||||
|
||||
static ssize_t
|
||||
make_intro_from_plaintext(
|
||||
void *buf, size_t len, crypto_pk_t *key, void **cell_out)
|
||||
{
|
||||
char *cell = NULL;
|
||||
ssize_t cell_len = -1, r;
|
||||
/* Assemble key digest and ciphertext, then construct the cell */
|
||||
ssize_t ciphertext_size;
|
||||
|
||||
if (!(buf && key && len > 0 && cell_out)) goto done;
|
||||
|
||||
/*
|
||||
* Figure out an upper bound on how big the ciphertext will be
|
||||
* (see crypto_pk_obsolete_public_hybrid_encrypt())
|
||||
*/
|
||||
ciphertext_size = PKCS1_OAEP_PADDING_OVERHEAD;
|
||||
ciphertext_size += crypto_pk_keysize(key);
|
||||
ciphertext_size += CIPHER_KEY_LEN;
|
||||
ciphertext_size += len;
|
||||
|
||||
/*
|
||||
* Allocate space for the cell
|
||||
*/
|
||||
cell = tor_malloc(DIGEST_LEN + ciphertext_size);
|
||||
|
||||
/* Compute key digest (will be first DIGEST_LEN octets of cell) */
|
||||
r = crypto_pk_get_digest(key, cell);
|
||||
tt_assert(r >= 0);
|
||||
|
||||
/* Do encryption */
|
||||
r = crypto_pk_obsolete_public_hybrid_encrypt(
|
||||
key, cell + DIGEST_LEN, ciphertext_size,
|
||||
buf, len,
|
||||
PK_PKCS1_OAEP_PADDING, 0);
|
||||
tt_assert(r >= 0);
|
||||
|
||||
/* Figure out cell length */
|
||||
cell_len = DIGEST_LEN + r;
|
||||
|
||||
/* Output the cell */
|
||||
*cell_out = cell;
|
||||
cell = NULL;
|
||||
|
||||
done:
|
||||
tor_free(cell);
|
||||
return cell_len;
|
||||
}
|
||||
|
||||
/** Test v0 INTRODUCE2 parsing through decryption only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_decrypt_v0(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_decrypt_test(v0_test_plaintext, sizeof(v0_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v1 INTRODUCE2 parsing through decryption only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_decrypt_v1(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_decrypt_test(v1_test_plaintext, sizeof(v1_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v2 INTRODUCE2 parsing through decryption only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_decrypt_v2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_decrypt_test(v2_test_plaintext, sizeof(v2_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v3 INTRODUCE2 parsing through decryption only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_decrypt_v3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_decrypt_test(
|
||||
v3_no_auth_test_plaintext, sizeof(v3_no_auth_test_plaintext));
|
||||
do_decrypt_test(
|
||||
v3_basic_auth_test_plaintext, sizeof(v3_basic_auth_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v0 INTRODUCE2 parsing through early parsing only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_early_parse_v0(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_early_parse_test(v0_test_plaintext, sizeof(v0_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v1 INTRODUCE2 parsing through early parsing only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_early_parse_v1(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_early_parse_test(v1_test_plaintext, sizeof(v1_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v2 INTRODUCE2 parsing through early parsing only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_early_parse_v2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_early_parse_test(v2_test_plaintext, sizeof(v2_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v3 INTRODUCE2 parsing through early parsing only
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_early_parse_v3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_early_parse_test(
|
||||
v3_no_auth_test_plaintext, sizeof(v3_no_auth_test_plaintext));
|
||||
do_early_parse_test(
|
||||
v3_basic_auth_test_plaintext, sizeof(v3_basic_auth_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v0 INTRODUCE2 parsing
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_late_parse_v0(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_late_parse_test(v0_test_plaintext, sizeof(v0_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v1 INTRODUCE2 parsing
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_late_parse_v1(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_late_parse_test(v1_test_plaintext, sizeof(v1_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v2 INTRODUCE2 parsing
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_late_parse_v2(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_late_parse_test(v2_test_plaintext, sizeof(v2_test_plaintext));
|
||||
}
|
||||
|
||||
/** Test v3 INTRODUCE2 parsing
|
||||
*/
|
||||
|
||||
static void
|
||||
test_introduce_late_parse_v3(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
do_late_parse_test(
|
||||
v3_no_auth_test_plaintext, sizeof(v3_no_auth_test_plaintext));
|
||||
do_late_parse_test(
|
||||
v3_basic_auth_test_plaintext, sizeof(v3_basic_auth_test_plaintext));
|
||||
}
|
||||
|
||||
#define INTRODUCE_LEGACY(name) \
|
||||
{ #name, test_introduce_ ## name , 0, NULL, NULL }
|
||||
|
||||
struct testcase_t introduce_tests[] = {
|
||||
INTRODUCE_LEGACY(early_parse_v0),
|
||||
INTRODUCE_LEGACY(early_parse_v1),
|
||||
INTRODUCE_LEGACY(early_parse_v2),
|
||||
INTRODUCE_LEGACY(early_parse_v3),
|
||||
INTRODUCE_LEGACY(decrypt_v0),
|
||||
INTRODUCE_LEGACY(decrypt_v1),
|
||||
INTRODUCE_LEGACY(decrypt_v2),
|
||||
INTRODUCE_LEGACY(decrypt_v3),
|
||||
INTRODUCE_LEGACY(late_parse_v0),
|
||||
INTRODUCE_LEGACY(late_parse_v1),
|
||||
INTRODUCE_LEGACY(late_parse_v2),
|
||||
INTRODUCE_LEGACY(late_parse_v3),
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user