|
@@ -54,7 +54,9 @@ int have_failed = 0;
|
|
|
|
|
|
static char temp_dir[256];
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * Store it in <b>temp_dir</b>. Exit immediately if we can't create it.
|
|
|
+ * idempotent. */
|
|
|
static void
|
|
|
setup_directory(void)
|
|
|
{
|
|
@@ -79,7 +81,7 @@ setup_directory(void)
|
|
|
is_setup = 1;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static const char *
|
|
|
get_fname(const char *name)
|
|
|
{
|
|
@@ -89,7 +91,8 @@ get_fname(const char *name)
|
|
|
return buf;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * itself. */
|
|
|
static void
|
|
|
remove_directory(void)
|
|
|
{
|
|
@@ -113,12 +116,17 @@ remove_directory(void)
|
|
|
#undef CACHE_GENERATED_KEYS
|
|
|
|
|
|
static crypto_pk_env_t *pregen_keys[5] = {NULL, NULL, NULL, NULL, NULL};
|
|
|
-
|
|
|
+#define N_PREGEN_KEYS ((int)(sizeof(pregen_keys)/sizeof(pregen_keys[0])))
|
|
|
+
|
|
|
+
|
|
|
+ * the key cache optimization, we might reuse keys: we only guarantee that
|
|
|
+ * keys made with distinct values for <b>idx</b> are different. The value of
|
|
|
+ * <b>idx</b> must be at least 0, and less than N_PREGEN_KEYS. */
|
|
|
static crypto_pk_env_t *
|
|
|
pk_generate(int idx)
|
|
|
{
|
|
|
#ifdef CACHE_GENERATED_KEYS
|
|
|
- tor_assert(idx < (int)(sizeof(pregen_keys)/sizeof(pregen_keys[0])));
|
|
|
+ tor_assert(idx < N_PREGEN_KEYS);
|
|
|
if (! pregen_keys[idx]) {
|
|
|
pregen_keys[idx] = crypto_new_pk_env();
|
|
|
tor_assert(!crypto_pk_generate_key(pregen_keys[idx]));
|
|
@@ -133,12 +141,12 @@ pk_generate(int idx)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
free_pregenerated_keys(void)
|
|
|
{
|
|
|
unsigned idx;
|
|
|
- for (idx = 0; idx < sizeof(pregen_keys)/sizeof(pregen_keys[0]); ++idx) {
|
|
|
+ for (idx = 0; idx < N_PREGEN_KEYS; ++idx) {
|
|
|
if (pregen_keys[idx]) {
|
|
|
crypto_free_pk_env(pregen_keys[idx]);
|
|
|
pregen_keys[idx] = NULL;
|
|
@@ -146,7 +154,7 @@ free_pregenerated_keys(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_buffers(void)
|
|
|
{
|
|
@@ -389,7 +397,7 @@ test_buffers(void)
|
|
|
buf_free(buf2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_dh(void)
|
|
|
{
|
|
@@ -431,7 +439,8 @@ test_crypto_dh(void)
|
|
|
crypto_dh_free(dh2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ */
|
|
|
static void
|
|
|
test_crypto_rng(void)
|
|
|
{
|
|
@@ -469,7 +478,7 @@ test_crypto_rng(void)
|
|
|
;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_aes(void)
|
|
|
{
|
|
@@ -599,7 +608,7 @@ test_crypto_aes(void)
|
|
|
tor_free(data3);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_sha(void)
|
|
|
{
|
|
@@ -668,7 +677,7 @@ test_crypto_sha(void)
|
|
|
crypto_free_digest_env(d2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_pk(void)
|
|
|
{
|
|
@@ -778,7 +787,7 @@ test_crypto_pk(void)
|
|
|
tor_free(encoded);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto(void)
|
|
|
{
|
|
@@ -887,7 +896,7 @@ test_crypto(void)
|
|
|
tor_free(data3);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_s2k(void)
|
|
|
{
|
|
@@ -920,7 +929,8 @@ test_crypto_s2k(void)
|
|
|
tor_free(buf3);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * *<b>b</b>. */
|
|
|
static int
|
|
|
_compare_strs(const void **a, const void **b)
|
|
|
{
|
|
@@ -928,7 +938,8 @@ _compare_strs(const void **a, const void **b)
|
|
|
return strcmp(s1, s2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * *<b>b</b>, excluding a's first character, and ignoring case. */
|
|
|
static int
|
|
|
_compare_without_first_ch(const void *a, const void **b)
|
|
|
{
|
|
@@ -936,7 +947,7 @@ _compare_without_first_ch(const void *a, const void **b)
|
|
|
return strcasecmp(s1+1, s2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util(void)
|
|
|
{
|
|
@@ -1429,7 +1440,7 @@ _test_eq_ip6(struct in6_addr *a, struct in6_addr *b, const char *e1,
|
|
|
test_eq(port2, pt2); \
|
|
|
STMT_END
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_ip6_helpers(void)
|
|
|
{
|
|
@@ -1755,7 +1766,7 @@ test_util_ip6_helpers(void)
|
|
|
;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_smartlist_basic(void)
|
|
|
{
|
|
@@ -1794,7 +1805,7 @@ test_util_smartlist_basic(void)
|
|
|
smartlist_free(sl);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_smartlist_strings(void)
|
|
|
{
|
|
@@ -2024,7 +2035,7 @@ test_util_smartlist_strings(void)
|
|
|
tor_free(cp_alloc);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_smartlist_overlap(void)
|
|
|
{
|
|
@@ -2077,7 +2088,7 @@ test_util_smartlist_overlap(void)
|
|
|
smartlist_free(sl);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_smartlist_digests(void)
|
|
|
{
|
|
@@ -2110,7 +2121,7 @@ test_util_smartlist_digests(void)
|
|
|
smartlist_free(sl);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_smartlist_join(void)
|
|
|
{
|
|
@@ -2162,7 +2173,7 @@ test_util_smartlist_join(void)
|
|
|
tor_free(joined);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_bitarray(void)
|
|
|
{
|
|
@@ -2204,7 +2215,8 @@ test_util_bitarray(void)
|
|
|
bitarray_free(ba);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * bloom filter) */
|
|
|
static void
|
|
|
test_util_digestset(void)
|
|
|
{
|
|
@@ -2253,18 +2265,18 @@ static strmap_t *_thread_test_strmap = NULL;
|
|
|
static char *_thread1_name = NULL;
|
|
|
static char *_thread2_name = NULL;
|
|
|
|
|
|
-
|
|
|
static void _thread_test_func(void* _s) ATTR_NORETURN;
|
|
|
|
|
|
static int t1_count = 0;
|
|
|
static int t2_count = 0;
|
|
|
|
|
|
+
|
|
|
+ * subthread. It grabs its own mutex (start1 or start2) to make sure that it
|
|
|
+ * should start, then it repeatedly alters _test_thread_strmap protected by
|
|
|
+ * _thread_test_mutex. */
|
|
|
static void
|
|
|
_thread_test_func(void* _s)
|
|
|
{
|
|
|
-
|
|
|
- * start2) to make sure that it should start, then it repeatedly alters
|
|
|
- * _test_thread_strmap protected by _thread_test_mutex. */
|
|
|
char *s = _s;
|
|
|
int i, *count;
|
|
|
tor_mutex_t *m;
|
|
@@ -2299,7 +2311,7 @@ _thread_test_func(void* _s)
|
|
|
spawn_exit();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_threads(void)
|
|
|
{
|
|
@@ -2371,14 +2383,14 @@ test_util_threads(void)
|
|
|
tor_mutex_free(_thread_test_start2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static int
|
|
|
_compare_strings_for_pqueue(const void *s1, const void *s2)
|
|
|
{
|
|
|
return strcmp((const char*)s1, (const char*)s2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_pqueue(void)
|
|
|
{
|
|
@@ -2436,7 +2448,7 @@ test_util_pqueue(void)
|
|
|
smartlist_free(sl);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_gzip(void)
|
|
|
{
|
|
@@ -2543,7 +2555,7 @@ test_util_gzip(void)
|
|
|
tor_free(buf1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_strmap(void)
|
|
|
{
|
|
@@ -2634,7 +2646,7 @@ test_util_strmap(void)
|
|
|
tor_free(visited);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_mmap(void)
|
|
|
{
|
|
@@ -2711,7 +2723,7 @@ test_util_mmap(void)
|
|
|
tor_munmap_file(mapping);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_control_formats(void)
|
|
|
{
|
|
@@ -2729,7 +2741,7 @@ test_util_control_formats(void)
|
|
|
tor_free(out);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_onion_handshake(void)
|
|
|
{
|
|
@@ -2778,7 +2790,7 @@ test_onion_handshake(void)
|
|
|
|
|
|
extern smartlist_t *fingerprint_list;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_dir_format(void)
|
|
|
{
|
|
@@ -3099,7 +3111,7 @@ test_dir_format(void)
|
|
|
tor_free(dir2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_dirutil(void)
|
|
|
{
|
|
@@ -3135,7 +3147,9 @@ extern const char AUTHORITY_SIGNKEY_2[];
|
|
|
extern const char AUTHORITY_CERT_3[];
|
|
|
extern const char AUTHORITY_SIGNKEY_3[];
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * same voting authority, and that they do in fact have all the same
|
|
|
+ * information. */
|
|
|
static void
|
|
|
test_same_voter(networkstatus_voter_info_t *v1,
|
|
|
networkstatus_voter_info_t *v2)
|
|
@@ -3152,7 +3166,7 @@ test_same_voter(networkstatus_voter_info_t *v1,
|
|
|
;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_order_functions(void)
|
|
|
{
|
|
@@ -3182,7 +3196,8 @@ test_util_order_functions(void)
|
|
|
;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * given vote_routerstatus_t. */
|
|
|
static routerinfo_t *
|
|
|
generate_ri_from_rs(const vote_routerstatus_t *vrs)
|
|
|
{
|
|
@@ -3205,7 +3220,8 @@ generate_ri_from_rs(const vote_routerstatus_t *vrs)
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * documents. */
|
|
|
static void
|
|
|
test_v3_networkstatus(void)
|
|
|
{
|
|
@@ -3704,7 +3720,9 @@ test_v3_networkstatus(void)
|
|
|
ns_detached_signatures_free(dsig2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * that policies_summarize() produces the string <b>expected_summary</b> from
|
|
|
+ * it. */
|
|
|
static void
|
|
|
test_policy_summary_helper(const char *policy_str,
|
|
|
const char *expected_summary)
|
|
@@ -3731,7 +3749,7 @@ test_policy_summary_helper(const char *policy_str,
|
|
|
addr_policy_list_free(policy);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_policies(void)
|
|
|
{
|
|
@@ -3890,7 +3908,7 @@ test_policies(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_rend_fns(void)
|
|
|
{
|
|
@@ -3956,7 +3974,7 @@ test_rend_fns(void)
|
|
|
tor_free(encoded);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
bench_aes(void)
|
|
|
{
|
|
@@ -3988,7 +4006,7 @@ bench_aes(void)
|
|
|
crypto_free_cipher_env(c);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
bench_dmap(void)
|
|
|
{
|
|
@@ -4052,7 +4070,7 @@ bench_dmap(void)
|
|
|
smartlist_free(sl2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_mempool(void)
|
|
|
{
|
|
@@ -4110,7 +4128,7 @@ test_util_mempool(void)
|
|
|
mp_pool_destroy(pool);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_util_memarea(void)
|
|
|
{
|
|
@@ -4206,7 +4224,8 @@ test_util_memarea(void)
|
|
|
tor_free(malloced_ptr);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * the data directory. */
|
|
|
static void
|
|
|
test_util_datadir(void)
|
|
|
{
|
|
@@ -4239,8 +4258,7 @@ test_util_datadir(void)
|
|
|
tor_free(f);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_aes_iv(void)
|
|
|
{
|
|
@@ -4376,8 +4394,7 @@ test_crypto_aes_iv(void)
|
|
|
crypto_free_cipher_env(cipher);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_crypto_base32_decode(void)
|
|
|
{
|
|
@@ -4412,8 +4429,7 @@ test_crypto_base32_decode(void)
|
|
|
;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_rend_fns_v2(void)
|
|
|
{
|
|
@@ -4514,7 +4530,7 @@ test_rend_fns_v2(void)
|
|
|
tor_free(intro_points_encrypted);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
static void
|
|
|
test_geoip(void)
|
|
|
{
|
|
@@ -4580,6 +4596,7 @@ static struct {
|
|
|
void (*test_fn)(void);
|
|
|
int is_subent;
|
|
|
int selected;
|
|
|
+ int is_default;
|
|
|
} test_array[] = {
|
|
|
ENT(buffers),
|
|
|
ENT(crypto),
|
|
@@ -4618,11 +4635,12 @@ static struct {
|
|
|
ENT(rend_fns),
|
|
|
SUBENT(rend_fns, v2),
|
|
|
ENT(geoip),
|
|
|
- { NULL, NULL, 0, 0 },
|
|
|
+ { NULL, NULL, 0, 0, 0 },
|
|
|
};
|
|
|
|
|
|
static void syntax(void) ATTR_NORETURN;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
static void
|
|
|
syntax(void)
|
|
|
{
|
|
@@ -4638,7 +4656,8 @@ syntax(void)
|
|
|
exit(0);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ * some unit tests. */
|
|
|
int
|
|
|
main(int c, char**v)
|
|
|
{
|