aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/compat.c16
-rw-r--r--src/common/util.c2
-rw-r--r--src/or/buffers.c6
-rw-r--r--src/or/circuitlist.c19
-rw-r--r--src/or/config.c18
-rw-r--r--src/or/cpuworker.c7
-rw-r--r--src/or/directory.c6
-rw-r--r--src/or/entrynodes.c2
-rw-r--r--src/or/or.h19
-rw-r--r--src/or/routerlist.c17
-rw-r--r--src/or/routerparse.c2
-rwxr-xr-xsrc/test/bt_test.py4
-rwxr-xr-xsrc/test/ntor_ref.py49
-rw-r--r--src/test/slownacl_curve25519.py31
-rw-r--r--src/test/test_buffers.c13
-rwxr-xr-xsrc/test/test_cmdline_args.py123
-rw-r--r--src/win32/orconfig.h2
17 files changed, 190 insertions, 146 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 1ba264a0c..974f697e3 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -2429,6 +2429,12 @@ tor_pthread_helper_fn(void *_data)
func(arg);
return NULL;
}
+/**
+ * A pthread attribute to make threads start detached.
+ */
+static pthread_attr_t attr_detached;
+/** True iff we've called tor_threads_init() */
+static int threads_initialized = 0;
#endif
/** Minimalist interface to run a void function in the background. On
@@ -2452,12 +2458,12 @@ spawn_func(void (*func)(void *), void *data)
#elif defined(USE_PTHREADS)
pthread_t thread;
tor_pthread_data_t *d;
+ if (PREDICT_UNLIKELY(!threads_initialized))
+ tor_threads_init();
d = tor_malloc(sizeof(tor_pthread_data_t));
d->data = data;
d->func = func;
- if (pthread_create(&thread,NULL,tor_pthread_helper_fn,d))
- return -1;
- if (pthread_detach(thread))
+ if (pthread_create(&thread,&attr_detached,tor_pthread_helper_fn,d))
return -1;
return 0;
#else
@@ -2814,8 +2820,6 @@ tor_get_thread_id(void)
* "reentrant" mutexes (i.e., once we can re-lock if we're already holding
* them.) */
static pthread_mutexattr_t attr_reentrant;
-/** True iff we've called tor_threads_init() */
-static int threads_initialized = 0;
/** Initialize <b>mutex</b> so it can be locked. Every mutex must be set
* up with tor_mutex_init() or tor_mutex_new(); not both. */
void
@@ -2959,6 +2963,8 @@ tor_threads_init(void)
if (!threads_initialized) {
pthread_mutexattr_init(&attr_reentrant);
pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE);
+ tor_assert(0==pthread_attr_init(&attr_detached));
+ tor_assert(0==pthread_attr_setdetachstate(&attr_detached, 1));
threads_initialized = 1;
set_main_thread();
}
diff --git a/src/common/util.c b/src/common/util.c
index 86bb8baae..56235aa66 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -303,7 +303,7 @@ tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS)
/** As tor_memdup(), but add an extra 0 byte at the end of the resulting
* memory. */
void *
-tor_memdup_nulterm(const void *mem, size_t len DMALLOC_PARAMS)
+tor_memdup_nulterm_(const void *mem, size_t len DMALLOC_PARAMS)
{
char *dup;
tor_assert(len < SIZE_T_CEILING+1);
diff --git a/src/or/buffers.c b/src/or/buffers.c
index fb186081c..e54751db2 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -117,6 +117,9 @@ chunk_repack(chunk_t *chunk)
chunk->data = &chunk->mem[0];
}
+/** Keep track of total size of allocated chunks for consistency asserts */
+static size_t total_bytes_allocated_in_chunks = 0;
+
#if defined(ENABLE_BUF_FREELISTS) || defined(RUNNING_DOXYGEN)
/** A freelist of chunks. */
typedef struct chunk_freelist_t {
@@ -148,9 +151,6 @@ static chunk_freelist_t freelists[] = {
* could help with? */
static uint64_t n_freelist_miss = 0;
-/** DOCDOC */
-static size_t total_bytes_allocated_in_chunks = 0;
-
static void assert_freelist_ok(chunk_freelist_t *fl);
/** Return the freelist to hold chunks of size <b>alloc</b>, or NULL if
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index c54a95419..90fc93f3a 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1821,7 +1821,7 @@ circuit_max_queued_cell_age(const circuit_t *c, uint32_t now)
age = now - cell->inserted_time;
if (! CIRCUIT_IS_ORIGIN(c)) {
- const or_circuit_t *orcirc = TO_OR_CIRCUIT((circuit_t*)c);
+ const or_circuit_t *orcirc = CONST_TO_OR_CIRCUIT(c);
if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->p_chan_cells.head))) {
uint32_t age2 = now - cell->inserted_time;
if (age2 > age)
@@ -1863,10 +1863,10 @@ circuit_max_queued_data_age(const circuit_t *c, uint32_t now)
{
if (CIRCUIT_IS_ORIGIN(c)) {
return circuit_get_streams_max_data_age(
- TO_ORIGIN_CIRCUIT((circuit_t*)c)->p_streams, now);
+ CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
} else {
return circuit_get_streams_max_data_age(
- TO_OR_CIRCUIT((circuit_t*)c)->n_streams, now);
+ CONST_TO_OR_CIRCUIT(c)->n_streams, now);
}
}
@@ -2057,15 +2057,10 @@ assert_circuit_ok(const circuit_t *c)
tor_assert(c->purpose >= CIRCUIT_PURPOSE_MIN_ &&
c->purpose <= CIRCUIT_PURPOSE_MAX_);
- {
- /* Having a separate variable for this pleases GCC 4.2 in ways I hope I
- * never understand. -NM. */
- circuit_t *nonconst_circ = (circuit_t*) c;
- if (CIRCUIT_IS_ORIGIN(c))
- origin_circ = TO_ORIGIN_CIRCUIT(nonconst_circ);
- else
- or_circ = TO_OR_CIRCUIT(nonconst_circ);
- }
+ if (CIRCUIT_IS_ORIGIN(c))
+ origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
+ else
+ or_circ = CONST_TO_OR_CIRCUIT(c);
if (c->n_chan) {
tor_assert(!c->n_hop);
diff --git a/src/or/config.c b/src/or/config.c
index 3954c582e..1faf13871 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -237,6 +237,7 @@ static config_var_t option_vars_[] = {
V(ExitPortStatistics, BOOL, "0"),
V(ExtendAllowPrivateAddresses, BOOL, "0"),
VPORT(ExtORPort, LINELIST, NULL),
+ V(ExtORPortCookieAuthFile, STRING, NULL),
V(ExtraInfoStatistics, BOOL, "1"),
V(FallbackDir, LINELIST, NULL),
@@ -307,7 +308,7 @@ static config_var_t option_vars_[] = {
V(MaxAdvertisedBandwidth, MEMUNIT, "1 GB"),
V(MaxCircuitDirtiness, INTERVAL, "10 minutes"),
V(MaxClientCircuitsPending, UINT, "32"),
- VAR("MaxMeminQueues", MEMUNIT, MaxMemInQueues_raw, "0"),
+ VAR("MaxMemInQueues", MEMUNIT, MaxMemInQueues_raw, "0"),
OBSOLETE("MaxOnionsPending"),
V(MaxOnionQueueDelay, MSEC_INTERVAL, "1750 msec"),
V(MinMeasuredBWsForAuthToIgnoreAdvertised, INT, "500"),
@@ -356,7 +357,7 @@ static config_var_t option_vars_[] = {
V(OptimisticData, AUTOBOOL, "auto"),
V(PortForwarding, BOOL, "0"),
V(PortForwardingHelper, FILENAME, "tor-fw-helper"),
- V(PreferTunneledDirConns, BOOL, "1"),
+ OBSOLETE("PreferTunneledDirConns"),
V(ProtocolWarnings, BOOL, "0"),
V(PublishServerDescriptor, CSV, "1"),
V(PublishHidServDescriptors, BOOL, "1"),
@@ -411,7 +412,7 @@ static config_var_t option_vars_[] = {
V(TransListenAddress, LINELIST, NULL),
VPORT(TransPort, LINELIST, NULL),
V(TransProxyType, STRING, "default"),
- V(TunnelDirConns, BOOL, "1"),
+ OBSOLETE("TunnelDirConns"),
V(UpdateBridgesFromAuthority, BOOL, "0"),
V(UseBridges, BOOL, "0"),
V(UseEntryGuards, BOOL, "1"),
@@ -3274,8 +3275,6 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->UseBridges && !options->Bridges)
REJECT("If you set UseBridges, you must specify at least one bridge.");
- if (options->UseBridges && !options->TunnelDirConns)
- REJECT("If you set UseBridges, you must set TunnelDirConns.");
for (cl = options->Bridges; cl; cl = cl->next) {
bridge_line_t *bridge_line = parse_bridge_line(cl->value);
@@ -3388,15 +3387,6 @@ options_validate(or_options_t *old_options, or_options_t *options,
AF_INET6, 1, msg)<0)
return -1;
- if (options->PreferTunneledDirConns && !options->TunnelDirConns)
- REJECT("Must set TunnelDirConns if PreferTunneledDirConns is set.");
-
- if ((options->Socks4Proxy || options->Socks5Proxy) &&
- !options->HTTPProxy && !options->PreferTunneledDirConns)
- REJECT("When Socks4Proxy or Socks5Proxy is configured, "
- "PreferTunneledDirConns and TunnelDirConns must both be "
- "set to 1, or HTTPProxy must be configured.");
-
if (options->AutomapHostsSuffixes) {
SMARTLIST_FOREACH(options->AutomapHostsSuffixes, char *, suf,
{
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 6b6a68afe..61b2c29b3 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -528,7 +528,12 @@ spawn_cpuworker(void)
tor_assert(SOCKET_OK(fdarray[1]));
fd = fdarray[0];
- spawn_func(cpuworker_main, (void*)fdarray);
+ if (spawn_func(cpuworker_main, (void*)fdarray) < 0) {
+ tor_close_socket(fdarray[0]);
+ tor_close_socket(fdarray[1]);
+ tor_free(fdarray);
+ return -1;
+ }
log_debug(LD_OR,"just spawned a cpu worker.");
#ifndef TOR_IS_MULTITHREADED
tor_close_socket(fdarray[1]); /* don't need the worker's side of the pipe */
diff --git a/src/or/directory.c b/src/or/directory.c
index 8070a76a5..76cb8fa0b 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -338,8 +338,6 @@ should_use_directory_guards(const or_options_t *options)
if (options->DownloadExtraInfo || options->FetchDirInfoEarly ||
options->FetchDirInfoExtraEarly || options->FetchUselessDescriptors)
return 0;
- if (! options->PreferTunneledDirConns)
- return 0;
return 1;
}
@@ -834,6 +832,7 @@ directory_command_should_use_begindir(const or_options_t *options,
int or_port, uint8_t router_purpose,
dir_indirection_t indirection)
{
+ (void) router_purpose;
if (!or_port)
return 0; /* We don't know an ORPort -- no chance. */
if (indirection == DIRIND_DIRECT_CONN || indirection == DIRIND_ANON_DIRPORT)
@@ -842,9 +841,6 @@ directory_command_should_use_begindir(const or_options_t *options,
if (!fascist_firewall_allows_address_or(addr, or_port) ||
directory_fetches_from_authorities(options))
return 0; /* We're firewalled or are acting like a relay -- also no. */
- if (!options->TunnelDirConns &&
- router_purpose != ROUTER_PURPOSE_BRIDGE)
- return 0; /* We prefer to avoid using begindir conns. Fine. */
return 1;
}
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 70587bd75..957217ac6 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -378,7 +378,7 @@ add_an_entry_guard(const node_t *chosen, int reset_status, int prepend,
} else {
const routerstatus_t *rs;
rs = router_pick_directory_server(MICRODESC_DIRINFO|V3_DIRINFO,
- PDS_PREFER_TUNNELED_DIR_CONNS_|PDS_FOR_GUARD);
+ PDS_FOR_GUARD);
if (!rs)
return NULL;
node = node_get_by_id(rs->identity_digest);
diff --git a/src/or/or.h b/src/or/or.h
index 701877c64..6aa6b59e8 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3231,20 +3231,33 @@ typedef struct or_circuit_rendinfo_s {
/** Convert a circuit_t* to a pointer to the enclosing or_circuit_t. Assert
* if the cast is impossible. */
static or_circuit_t *TO_OR_CIRCUIT(circuit_t *);
+static const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *);
/** Convert a circuit_t* to a pointer to the enclosing origin_circuit_t.
* Assert if the cast is impossible. */
static origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *);
+static const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(const circuit_t *);
static INLINE or_circuit_t *TO_OR_CIRCUIT(circuit_t *x)
{
tor_assert(x->magic == OR_CIRCUIT_MAGIC);
return DOWNCAST(or_circuit_t, x);
}
+static INLINE const or_circuit_t *CONST_TO_OR_CIRCUIT(const circuit_t *x)
+{
+ tor_assert(x->magic == OR_CIRCUIT_MAGIC);
+ return DOWNCAST(or_circuit_t, x);
+}
static INLINE origin_circuit_t *TO_ORIGIN_CIRCUIT(circuit_t *x)
{
tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
return DOWNCAST(origin_circuit_t, x);
}
+static INLINE const origin_circuit_t *CONST_TO_ORIGIN_CIRCUIT(
+ const circuit_t *x)
+{
+ tor_assert(x->magic == ORIGIN_CIRCUIT_MAGIC);
+ return DOWNCAST(origin_circuit_t, x);
+}
/** Bitfield type: things that we're willing to use invalid routers for. */
typedef enum invalid_router_usage_t {
@@ -3873,10 +3886,6 @@ typedef struct {
* testing our DNS server. */
int EnforceDistinctSubnets; /**< If true, don't allow multiple routers in the
* same network zone in the same circuit. */
- int TunnelDirConns; /**< If true, use BEGIN_DIR rather than BEGIN when
- * possible. */
- int PreferTunneledDirConns; /**< If true, avoid dirservers that don't
- * support BEGIN_DIR, when possible. */
int PortForwarding; /**< If true, use NAT-PMP or UPnP to automatically
* forward the DirPort and ORPort on the NAT device */
char *PortForwardingHelper; /** < Filename or full path of the port
@@ -4961,8 +4970,6 @@ typedef struct dir_server_t {
* node that's currently a guard. */
#define PDS_FOR_GUARD (1<<5)
-#define PDS_PREFER_TUNNELED_DIR_CONNS_ (1<<16)
-
/** Possible ways to weight routers when choosing one randomly. See
* routerlist_sl_choose_by_bandwidth() for more information.*/
typedef enum bandwidth_weight_rule_t {
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index c15274e99..8f3477a4a 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1282,8 +1282,6 @@ const routerstatus_t *
router_pick_directory_server(dirinfo_type_t type, int flags)
{
const routerstatus_t *choice;
- if (get_options()->PreferTunneledDirConns)
- flags |= PDS_PREFER_TUNNELED_DIR_CONNS_;
if (!routerlist)
return NULL;
@@ -1385,8 +1383,6 @@ router_pick_dirserver_generic(smartlist_t *sourcelist,
{
const routerstatus_t *choice;
int busy = 0;
- if (get_options()->PreferTunneledDirConns)
- flags |= PDS_PREFER_TUNNELED_DIR_CONNS_;
choice = router_pick_trusteddirserver_impl(sourcelist, type, flags, &busy);
if (choice || !(flags & PDS_RETRY_IF_NO_SERVERS))
@@ -1411,10 +1407,7 @@ router_pick_dirserver_generic(smartlist_t *sourcelist,
/** Pick a random running valid directory server/mirror from our
* routerlist. Arguments are as for router_pick_directory_server(), except
- * that RETRY_IF_NO_SERVERS is ignored, and:
- *
- * If the PDS_PREFER_TUNNELED_DIR_CONNS_ flag is set, prefer directory servers
- * that we can use with BEGINDIR.
+ * that RETRY_IF_NO_SERVERS is ignored.
*/
static const routerstatus_t *
router_pick_directory_server_impl(dirinfo_type_t type, int flags)
@@ -1428,7 +1421,6 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags)
const networkstatus_t *consensus = networkstatus_get_latest_consensus();
int requireother = ! (flags & PDS_ALLOW_SELF);
int fascistfirewall = ! (flags & PDS_IGNORE_FASCISTFIREWALL);
- int prefer_tunnel = (flags & PDS_PREFER_TUNNELED_DIR_CONNS_);
int for_guard = (flags & PDS_FOR_GUARD);
int try_excluding = 1, n_excluded = 0;
@@ -1481,8 +1473,7 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags)
is_overloaded = status->last_dir_503_at + DIR_503_TIMEOUT > now;
- if (prefer_tunnel &&
- (!fascistfirewall ||
+ if ((!fascistfirewall ||
fascist_firewall_allows_address_or(&addr, status->or_port)))
smartlist_add(is_trusted ? trusted_tunnel :
is_overloaded ? overloaded_tunnel : tunnel, (void*)node);
@@ -1569,7 +1560,6 @@ router_pick_trusteddirserver_impl(const smartlist_t *sourcelist,
time_t now = time(NULL);
const int requireother = ! (flags & PDS_ALLOW_SELF);
const int fascistfirewall = ! (flags & PDS_IGNORE_FASCISTFIREWALL);
- const int prefer_tunnel = (flags & PDS_PREFER_TUNNELED_DIR_CONNS_);
const int no_serverdesc_fetching =(flags & PDS_NO_EXISTING_SERVERDESC_FETCH);
const int no_microdesc_fetching =(flags & PDS_NO_EXISTING_MICRODESC_FETCH);
const double auth_weight = (sourcelist == fallback_dir_servers) ?
@@ -1630,8 +1620,7 @@ router_pick_trusteddirserver_impl(const smartlist_t *sourcelist,
}
}
- if (prefer_tunnel &&
- d->or_port &&
+ if (d->or_port &&
(!fascistfirewall ||
fascist_firewall_allows_address_or(&addr, d->or_port)))
smartlist_add(is_overloaded ? overloaded_tunnel : tunnel, (void*)d);
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 14f800e7b..5add728d6 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -4129,11 +4129,13 @@ microdescs_parse_from_string(const char *s, const char *eos,
microdesc_free(md);
md = NULL;
+ SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
memarea_clear(area);
smartlist_clear(tokens);
s = start_of_next_microdesc;
}
+ SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
memarea_drop_all(area);
smartlist_free(tokens);
diff --git a/src/test/bt_test.py b/src/test/bt_test.py
index 2de9924a5..8290509fa 100755
--- a/src/test/bt_test.py
+++ b/src/test/bt_test.py
@@ -35,8 +35,8 @@ LINES = sys.stdin.readlines()
for I in range(len(LINES)):
if matches(LINES[I:], FUNCNAMES):
- print "OK"
+ print("OK")
break
else:
- print "BAD"
+ print("BAD")
diff --git a/src/test/ntor_ref.py b/src/test/ntor_ref.py
index 12eb00742..7d6e43e71 100755
--- a/src/test/ntor_ref.py
+++ b/src/test/ntor_ref.py
@@ -39,13 +39,14 @@ except ImportError:
import hashlib
import hmac
import subprocess
+import sys
# **********************************************************************
# Helpers and constants
def HMAC(key,msg):
"Return the HMAC-SHA256 of 'msg' using the key 'key'."
- H = hmac.new(key, "", hashlib.sha256)
+ H = hmac.new(key, b"", hashlib.sha256)
H.update(msg)
return H.digest()
@@ -67,10 +68,10 @@ G_LENGTH = 32
H_LENGTH = 32
PROTOID = b"ntor-curve25519-sha256-1"
-M_EXPAND = PROTOID + ":key_expand"
-T_MAC = PROTOID + ":mac"
-T_KEY = PROTOID + ":key_extract"
-T_VERIFY = PROTOID + ":verify"
+M_EXPAND = PROTOID + b":key_expand"
+T_MAC = PROTOID + b":mac"
+T_KEY = PROTOID + b":key_extract"
+T_VERIFY = PROTOID + b":verify"
def H_mac(msg): return H(msg, tweak=T_MAC)
def H_verify(msg): return H(msg, tweak=T_VERIFY)
@@ -91,7 +92,14 @@ class PrivateKey(curve25519mod.Private):
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-def kdf_rfc5869(key, salt, info, n):
+if sys.version < '3':
+ def int2byte(i):
+ return chr(i)
+else:
+ def int2byte(i):
+ return bytes([i])
+
+def kdf_rfc5869(key, salt, info, n):
prk = HMAC(key=salt, msg=key)
@@ -99,7 +107,7 @@ def kdf_rfc5869(key, salt, info, n):
last = b""
i = 1
while len(out) < n:
- m = last + info + chr(i)
+ m = last + info + int2byte(i)
last = h = HMAC(key=prk, msg=m)
out += h
i = i + 1
@@ -208,7 +216,7 @@ def server(seckey_b, my_node_id, message, keyBytes=72):
pubkey_Y.serialize() +
pubkey_X.serialize() +
PROTOID +
- "Server")
+ b"Server")
msg = pubkey_Y.serialize() + H_mac(auth_input)
@@ -270,7 +278,7 @@ def client_part2(seckey_x, msg, node_id, pubkey_B, keyBytes=72):
pubkey_B.serialize() +
pubkey_Y.serialize() +
pubkey_X.serialize() + PROTOID +
- "Server")
+ b"Server")
my_auth = H_mac(auth_input)
@@ -284,7 +292,7 @@ def client_part2(seckey_x, msg, node_id, pubkey_B, keyBytes=72):
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-def demo(node_id="iToldYouAboutStairs.", server_key=PrivateKey()):
+def demo(node_id=b"iToldYouAboutStairs.", server_key=PrivateKey()):
"""
Try to handshake with ourself.
"""
@@ -294,7 +302,7 @@ def demo(node_id="iToldYouAboutStairs.", server_key=PrivateKey()):
assert len(skeys) == 72
assert len(ckeys) == 72
assert skeys == ckeys
- print "OK"
+ print("OK")
# ======================================================================
def timing():
@@ -304,7 +312,7 @@ def timing():
import timeit
t = timeit.Timer(stmt="ntor_ref.demo(N,SK)",
setup="import ntor_ref,curve25519;N='ABCD'*5;SK=ntor_ref.PrivateKey()")
- print t.timeit(number=1000)
+ print(t.timeit(number=1000))
# ======================================================================
@@ -315,7 +323,7 @@ def kdf_vectors():
import binascii
def kdf_vec(inp):
k = kdf(inp, T_KEY, M_EXPAND, 100)
- print repr(inp), "\n\""+ binascii.b2a_hex(k)+ "\""
+ print(repr(inp), "\n\""+ binascii.b2a_hex(k)+ "\"")
kdf_vec("")
kdf_vec("Tor")
kdf_vec("AN ALARMING ITEM TO FIND ON YOUR CREDIT-RATING STATEMENT")
@@ -328,13 +336,13 @@ def test_tor():
Call the test-ntor-cl command-line program to make sure we can
interoperate with Tor's ntor program
"""
- enhex=binascii.b2a_hex
+ enhex=lambda s: binascii.b2a_hex(s)
dehex=lambda s: binascii.a2b_hex(s.strip())
- PROG = "./src/test/test-ntor-cl"
+ PROG = b"./src/test/test-ntor-cl"
def tor_client1(node_id, pubkey_B):
" returns (msg, state) "
- p = subprocess.Popen([PROG, "client1", enhex(node_id),
+ p = subprocess.Popen([PROG, b"client1", enhex(node_id),
enhex(pubkey_B.serialize())],
stdout=subprocess.PIPE)
return map(dehex, p.stdout.readlines())
@@ -352,7 +360,7 @@ def test_tor():
return map(dehex, p.stdout.readlines())
- node_id = "thisisatornodeid$#%^"
+ node_id = b"thisisatornodeid$#%^"
seckey_b = PrivateKey()
pubkey_B = seckey_b.get_public()
@@ -377,14 +385,13 @@ def test_tor():
assert c_keys == s_keys
assert len(c_keys) == 90
- print "OK"
+ print("OK")
# ======================================================================
if __name__ == '__main__':
- import sys
if len(sys.argv) < 2:
- print __doc__
+ print(__doc__)
elif sys.argv[1] == 'gen_kdf_vectors':
kdf_vectors()
elif sys.argv[1] == 'timing':
@@ -395,4 +402,4 @@ if __name__ == '__main__':
test_tor()
else:
- print __doc__
+ print(__doc__)
diff --git a/src/test/slownacl_curve25519.py b/src/test/slownacl_curve25519.py
index 25244fb12..4dabab61b 100644
--- a/src/test/slownacl_curve25519.py
+++ b/src/test/slownacl_curve25519.py
@@ -8,12 +8,14 @@
__all__ = ['smult_curve25519_base', 'smult_curve25519']
+import sys
+
P = 2 ** 255 - 19
A = 486662
def expmod(b, e, m):
if e == 0: return 1
- t = expmod(b, e / 2, m) ** 2 % m
+ t = expmod(b, e // 2, m) ** 2 % m
if e & 1: t = (t * b) % m
return t
@@ -23,12 +25,14 @@ def inv(x):
# Addition and doubling formulas taken from Appendix D of "Curve25519:
# new Diffie-Hellman speed records".
-def add((xn,zn), (xm,zm), (xd,zd)):
+def add(n,m,d):
+ (xn,zn), (xm,zm), (xd,zd) = n, m, d
x = 4 * (xm * xn - zm * zn) ** 2 * zd
z = 4 * (xm * zn - zm * xn) ** 2 * xd
return (x % P, z % P)
-def double((xn,zn)):
+def double(n):
+ (xn,zn) = n
x = (xn ** 2 - zn ** 2) ** 2
z = 4 * xn * zn * (xn ** 2 + A * xn * zn + zn ** 2)
return (x % P, z % P)
@@ -40,19 +44,34 @@ def curve25519(n, base):
# (m+1)th multiple of base.
def f(m):
if m == 1: return (one, two)
- (pm, pm1) = f(m / 2)
+ (pm, pm1) = f(m // 2)
if (m & 1):
return (add(pm, pm1, one), double(pm1))
return (double(pm), add(pm, pm1, one))
((x,z), _) = f(n)
return (x * inv(z)) % P
+if sys.version < '3':
+ def b2i(c):
+ return ord(c)
+ def i2b(i):
+ return chr(i)
+ def ba2bs(ba):
+ return "".join(ba)
+else:
+ def b2i(c):
+ return c
+ def i2b(i):
+ return i
+ def ba2bs(ba):
+ return bytes(ba)
+
def unpack(s):
if len(s) != 32: raise ValueError('Invalid Curve25519 argument')
- return sum(ord(s[i]) << (8 * i) for i in range(32))
+ return sum(b2i(s[i]) << (8 * i) for i in range(32))
def pack(n):
- return ''.join([chr((n >> (8 * i)) & 255) for i in range(32)])
+ return ba2bs([i2b((n >> (8 * i)) & 255) for i in range(32)])
def clamp(n):
n &= ~7
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c
index 125397691..cff2db1ba 100644
--- a/src/test/test_buffers.c
+++ b/src/test/test_buffers.c
@@ -481,13 +481,22 @@ test_buffer_allocation_tracking(void *arg)
fetch_from_buf(junk, 4096, buf1); /* drop a 1k chunk... */
tt_int_op(buf_allocation(buf1), ==, 3*4096); /* now 3 4k chunks */
+#ifdef ENABLE_BUF_FREELISTS
tt_int_op(buf_get_total_allocation(), ==, 16384); /* that chunk went onto
the freelist. */
+#else
+ tt_int_op(buf_get_total_allocation(), ==, 12288); /* that chunk was really
+ freed. */
+#endif
write_to_buf(junk, 4000, buf2);
tt_int_op(buf_allocation(buf2), ==, 4096); /* another 4k chunk. */
- tt_int_op(buf_get_total_allocation(), ==, 16384); /* that chunk came from
- the freelist. */
+ /*
+ * If we're using freelists, size stays at 16384 because we just pulled a
+ * chunk from the freelist. If we aren't, we bounce back up to 16384 by
+ * allocating a new chunk.
+ */
+ tt_int_op(buf_get_total_allocation(), ==, 16384);
write_to_buf(junk, 4000, buf2);
tt_int_op(buf_allocation(buf2), ==, 8192); /* another 4k chunk. */
tt_int_op(buf_get_total_allocation(), ==, 5*4096); /* that chunk was new. */
diff --git a/src/test/test_cmdline_args.py b/src/test/test_cmdline_args.py
index 6d9cf44db..55d1cdb80 100755
--- a/src/test/test_cmdline_args.py
+++ b/src/test/test_cmdline_args.py
@@ -27,6 +27,21 @@ class UnexpectedSuccess(Exception):
class UnexpectedFailure(Exception):
pass
+if sys.version < '3':
+ def b2s(b):
+ return b
+ def s2b(s):
+ return s
+ def NamedTemporaryFile():
+ return tempfile.NamedTemporaryFile(delete=False)
+else:
+ def b2s(b):
+ return str(b, 'ascii')
+ def s2b(s):
+ return s.encode('ascii')
+ def NamedTemporaryFile():
+ return tempfile.NamedTemporaryFile(mode="w",delete=False,encoding="ascii")
+
def contents(fn):
f = open(fn)
try:
@@ -42,10 +57,10 @@ def run_tor(args, failure=False):
raise UnexpectedFailure()
elif not result and failure:
raise UnexpectedSuccess()
- return output
+ return b2s(output)
def spaceify_fp(fp):
- for i in xrange(0, len(fp), 4):
+ for i in range(0, len(fp), 4):
yield fp[i:i+4]
def lines(s):
@@ -62,7 +77,7 @@ def strip_log_junk(line):
def randstring(entropy_bytes):
s = os.urandom(entropy_bytes)
- return binascii.b2a_hex(s)
+ return b2s(binascii.b2a_hex(s))
def findLineContaining(lines, s):
for ln in lines:
@@ -74,59 +89,61 @@ class CmdlineTests(unittest.TestCase):
def test_version(self):
out = run_tor(["--version"])
- self.failUnless(out.startswith("Tor version "))
- self.assertEquals(len(lines(out)), 1)
+ self.assertTrue(out.startswith("Tor version "))
+ self.assertEqual(len(lines(out)), 1)
def test_quiet(self):
out = run_tor(["--quiet", "--quumblebluffin", "1"], failure=True)
- self.assertEquals(out, "")
+ self.assertEqual(out, "")
def test_help(self):
out = run_tor(["--help"], failure=False)
out2 = run_tor(["-h"], failure=False)
- self.assert_(out.startswith("Copyright (c) 2001"))
- self.assert_(out.endswith(
+ self.assertTrue(out.startswith("Copyright (c) 2001"))
+ self.assertTrue(out.endswith(
"tor -f <torrc> [args]\n"
"See man page for options, or https://www.torproject.org/ for documentation.\n"))
- self.assert_(out == out2)
+ self.assertTrue(out == out2)
def test_hush(self):
- torrc = tempfile.NamedTemporaryFile(delete=False)
+ torrc = NamedTemporaryFile()
torrc.close()
try:
out = run_tor(["--hush", "-f", torrc.name,
"--quumblebluffin", "1"], failure=True)
finally:
os.unlink(torrc.name)
- self.assertEquals(len(lines(out)), 2)
+ self.assertEqual(len(lines(out)), 2)
ln = [ strip_log_junk(l) for l in lines(out) ]
- self.assertEquals(ln[0], "Failed to parse/validate config: Unknown option 'quumblebluffin'. Failing.")
- self.assertEquals(ln[1], "Reading config failed--see warnings above.")
+ self.assertEqual(ln[0], "Failed to parse/validate config: Unknown option 'quumblebluffin'. Failing.")
+ self.assertEqual(ln[1], "Reading config failed--see warnings above.")
def test_missing_argument(self):
out = run_tor(["--hush", "--hash-password"], failure=True)
- self.assertEquals(len(lines(out)), 2)
+ self.assertEqual(len(lines(out)), 2)
ln = [ strip_log_junk(l) for l in lines(out) ]
- self.assertEquals(ln[0], "Command-line option '--hash-password' with no value. Failing.")
+ self.assertEqual(ln[0], "Command-line option '--hash-password' with no value. Failing.")
def test_hash_password(self):
out = run_tor(["--hash-password", "woodwose"])
result = lines(out)[-1]
- self.assertEquals(result[:3], "16:")
- self.assertEquals(len(result), 61)
+ self.assertEqual(result[:3], "16:")
+ self.assertEqual(len(result), 61)
r = binascii.a2b_hex(result[3:])
- self.assertEquals(len(r), 29)
+ self.assertEqual(len(r), 29)
salt, how, hashed = r[:8], r[8], r[9:]
- self.assertEquals(len(hashed), 20)
+ self.assertEqual(len(hashed), 20)
+ if type(how) == type("A"):
+ how = ord(how)
- count = (16 + (ord(how) & 15)) << ((ord(how) >> 4) + 6)
- stuff = salt + "woodwose"
+ count = (16 + (how & 15)) << ((how >> 4) + 6)
+ stuff = salt + s2b("woodwose")
repetitions = count // len(stuff) + 1
inp = stuff * repetitions
inp = inp[:count]
- self.assertEquals(hashlib.sha1(inp).digest(), hashed)
+ self.assertEqual(hashlib.sha1(inp).digest(), hashed)
def test_digests(self):
main_c = os.path.join(TOP_SRCDIR, "src", "or", "main.c")
@@ -136,12 +153,14 @@ class CmdlineTests(unittest.TestCase):
out = run_tor(["--digests"])
main_line = [ l for l in lines(out) if l.endswith("/main.c") ]
digest, name = main_line[0].split()
- actual = hashlib.sha1(open(main_c).read()).hexdigest()
- self.assertEquals(digest, actual)
+ f = open(main_c, 'rb')
+ actual = hashlib.sha1(f.read()).hexdigest()
+ f.close()
+ self.assertEqual(digest, actual)
def test_dump_options(self):
- default_torrc = tempfile.NamedTemporaryFile(delete=False)
- torrc = tempfile.NamedTemporaryFile(delete=False)
+ default_torrc = NamedTemporaryFile()
+ torrc = NamedTemporaryFile()
torrc.write("SocksPort 9999")
torrc.close()
default_torrc.write("SafeLogging 0")
@@ -161,27 +180,27 @@ class CmdlineTests(unittest.TestCase):
os.unlink(torrc.name)
os.unlink(default_torrc.name)
- self.assertEquals(len(lines(out_sh)), 2)
- self.assert_(lines(out_sh)[0].startswith("DataDirectory "))
- self.assertEquals(lines(out_sh)[1:],
+ self.assertEqual(len(lines(out_sh)), 2)
+ self.assertTrue(lines(out_sh)[0].startswith("DataDirectory "))
+ self.assertEqual(lines(out_sh)[1:],
[ "SocksPort 9999" ])
- self.assertEquals(len(lines(out_nb)), 2)
- self.assertEquals(lines(out_nb),
+ self.assertEqual(len(lines(out_nb)), 2)
+ self.assertEqual(lines(out_nb),
[ "SafeLogging 0",
"SocksPort 9999" ])
out_fl = lines(out_fl)
- self.assert_(len(out_fl) > 100)
- self.assert_("SocksPort 9999" in out_fl)
- self.assert_("SafeLogging 0" in out_fl)
- self.assert_("ClientOnly 0" in out_fl)
+ self.assertTrue(len(out_fl) > 100)
+ self.assertTrue("SocksPort 9999" in out_fl)
+ self.assertTrue("SafeLogging 0" in out_fl)
+ self.assertTrue("ClientOnly 0" in out_fl)
- self.assert_(out_verif.endswith("Configuration was valid\n"))
+ self.assertTrue(out_verif.endswith("Configuration was valid\n"))
def test_list_fingerprint(self):
tmpdir = tempfile.mkdtemp(prefix='ttca_')
- torrc = tempfile.NamedTemporaryFile(delete=False)
+ torrc = NamedTemporaryFile()
torrc.write("ORPort 9999\n")
torrc.write("DataDirectory %s\n"%tmpdir)
torrc.write("Nickname tippi")
@@ -200,21 +219,21 @@ class CmdlineTests(unittest.TestCase):
fp = fp.strip()
nn_fp = fp.split()[0]
space_fp = " ".join(spaceify_fp(fp.split()[1]))
- self.assertEquals(lastlog,
+ self.assertEqual(lastlog,
"Your Tor server's identity key fingerprint is '%s'"%fp)
- self.assertEquals(lastline, "tippi %s"%space_fp)
- self.assertEquals(nn_fp, "tippi")
+ self.assertEqual(lastline, "tippi %s"%space_fp)
+ self.assertEqual(nn_fp, "tippi")
def test_list_options(self):
out = lines(run_tor(["--list-torrc-options"]))
- self.assert_(len(out)>100)
- self.assert_(out[0] <= 'AccountingMax')
- self.assert_("UseBridges" in out)
- self.assert_("SocksPort" in out)
+ self.assertTrue(len(out)>100)
+ self.assertTrue(out[0] <= 'AccountingMax')
+ self.assertTrue("UseBridges" in out)
+ self.assertTrue("SocksPort" in out)
def test_cmdline_args(self):
- default_torrc = tempfile.NamedTemporaryFile(delete=False)
- torrc = tempfile.NamedTemporaryFile(delete=False)
+ default_torrc = NamedTemporaryFile()
+ torrc = NamedTemporaryFile()
torrc.write("SocksPort 9999\n")
torrc.write("SocksPort 9998\n")
torrc.write("ORPort 9000\n")
@@ -242,14 +261,14 @@ class CmdlineTests(unittest.TestCase):
out_1 = [ l for l in lines(out_1) if not l.startswith("DataDir") ]
out_2 = [ l for l in lines(out_2) if not l.startswith("DataDir") ]
- self.assertEquals(out_1,
+ self.assertEqual(out_1,
["ControlPort 9500",
"Nickname eleventeen",
"ORPort 9000",
"ORPort 9001",
"SocksPort 9999",
"SocksPort 9998"])
- self.assertEquals(out_2,
+ self.assertEqual(out_2,
["ExtORPort 9005",
"Nickname eleventeen",
"ORPort 9000",
@@ -261,13 +280,13 @@ class CmdlineTests(unittest.TestCase):
fname = "nonexistent_file_"+randstring(8)
out = run_tor(["-f", fname, "--verify-config"], failure=True)
ln = [ strip_log_junk(l) for l in lines(out) ]
- self.assert_("Unable to open configuration file" in ln[-2])
- self.assert_("Reading config failed" in ln[-1])
+ self.assertTrue("Unable to open configuration file" in ln[-2])
+ self.assertTrue("Reading config failed" in ln[-1])
out = run_tor(["-f", fname, "--verify-config", "--ignore-missing-torrc"])
ln = [ strip_log_junk(l) for l in lines(out) ]
- self.assert_(findLineContaining(ln, ", using reasonable defaults"))
- self.assert_("Configuration was valid" in ln[-1])
+ self.assertTrue(findLineContaining(ln, ", using reasonable defaults"))
+ self.assertTrue("Configuration was valid" in ln[-1])
if __name__ == '__main__':
unittest.main()
diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h
index c865d5633..7b5877cf9 100644
--- a/src/win32/orconfig.h
+++ b/src/win32/orconfig.h
@@ -241,7 +241,7 @@
#define USING_TWOS_COMPLEMENT
/* Version number of package */
-#define VERSION "0.2.5.4-alpha"
+#define VERSION "0.2.5.4-alpha-dev"