aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/include.am30
-rw-r--r--src/tools/tor-checkkey.c89
-rw-r--r--src/tools/tor-gencert.c18
-rw-r--r--src/tools/tor-resolve.c12
-rw-r--r--src/tools/tor_runner.c102
5 files changed, 133 insertions, 118 deletions
diff --git a/src/tools/include.am b/src/tools/include.am
index d0185b5887..92cc3f10a2 100644
--- a/src/tools/include.am
+++ b/src/tools/include.am
@@ -1,5 +1,4 @@
bin_PROGRAMS+= src/tools/tor-resolve src/tools/tor-gencert
-noinst_PROGRAMS+= src/tools/tor-checkkey
if COVERAGE_ENABLED
noinst_PROGRAMS+= src/tools/tor-cov-resolve src/tools/tor-cov-gencert
@@ -9,7 +8,8 @@ src_tools_tor_resolve_SOURCES = src/tools/tor-resolve.c
src_tools_tor_resolve_LDFLAGS =
src_tools_tor_resolve_LDADD = src/common/libor.a \
src/common/libor-ctime.a \
- @TOR_LIB_MATH@ @TOR_LIB_WS32@
+ $(rust_ldadd) \
+ @TOR_LIB_MATH@ @TOR_LIB_WS32@ @TOR_LIB_USERENV@
if COVERAGE_ENABLED
src_tools_tor_cov_resolve_SOURCES = src/tools/tor-resolve.c
@@ -23,11 +23,12 @@ endif
src_tools_tor_gencert_SOURCES = src/tools/tor-gencert.c
src_tools_tor_gencert_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@
src_tools_tor_gencert_LDADD = src/common/libor.a src/common/libor-crypto.a \
- src/common/libor-ctime.a \
- $(LIBKECCAK_TINY) \
- $(LIBDONNA) \
- @TOR_LIB_MATH@ @TOR_ZLIB_LIBS@ @TOR_OPENSSL_LIBS@ \
- @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
+ src/common/libor-ctime.a \
+ $(LIBKECCAK_TINY) \
+ $(LIBDONNA) \
+ $(rust_ldadd) \
+ @TOR_LIB_MATH@ @TOR_ZLIB_LIBS@ @TOR_OPENSSL_LIBS@ \
+ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ @CURVE25519_LIBS@
if COVERAGE_ENABLED
src_tools_tor_cov_gencert_SOURCES = src/tools/tor-gencert.c
@@ -43,14 +44,9 @@ src_tools_tor_cov_gencert_LDADD = src/common/libor-testing.a \
@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
endif
-src_tools_tor_checkkey_SOURCES = src/tools/tor-checkkey.c
-src_tools_tor_checkkey_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@
-src_tools_tor_checkkey_LDADD = src/common/libor.a \
- src/common/libor-ctime.a \
- src/common/libor-crypto.a \
- $(LIBKECCAK_TINY) \
- $(LIBDONNA) \
- @TOR_LIB_MATH@ @TOR_ZLIB_LIBS@ @TOR_OPENSSL_LIBS@ \
- @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
-
EXTRA_DIST += src/tools/tor-fw-helper/README
+
+if BUILD_LIBTORRUNNER
+noinst_LIBRARIES += src/tools/libtorrunner.a
+src_tools_libtorrunner_a_SOURCES = src/tools/tor_runner.c src/or/tor_api.c
+endif
diff --git a/src/tools/tor-checkkey.c b/src/tools/tor-checkkey.c
deleted file mode 100644
index 3e16fd0336..0000000000
--- a/src/tools/tor-checkkey.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Copyright (c) 2008-2015, The Tor Project, Inc. */
-/* See LICENSE for licensing information */
-
-#include "orconfig.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "crypto.h"
-#include "torlog.h"
-#include "util.h"
-#include "compat.h"
-#include "compat_openssl.h"
-#include <openssl/bn.h>
-#include <openssl/rsa.h>
-
-int
-main(int c, char **v)
-{
- crypto_pk_t *env;
- char *str;
- RSA *rsa;
- int wantdigest=0;
- int fname_idx;
- char *fname=NULL;
- init_logging(1);
-
- if (c < 2) {
- fprintf(stderr, "Hi. I'm tor-checkkey. Tell me a filename that "
- "has a PEM-encoded RSA public key (like in a cert) and I'll "
- "dump the modulus. Use the --digest option too and I'll "
- "dump the digest.\n");
- return 1;
- }
-
- if (crypto_global_init(0, NULL, NULL)) {
- fprintf(stderr, "Couldn't initialize crypto library.\n");
- return 1;
- }
-
- if (!strcmp(v[1], "--digest")) {
- wantdigest = 1;
- fname_idx = 2;
- if (c<3) {
- fprintf(stderr, "too few arguments");
- return 1;
- }
- } else {
- wantdigest = 0;
- fname_idx = 1;
- }
-
- fname = expand_filename(v[fname_idx]);
- str = read_file_to_str(fname, 0, NULL);
- tor_free(fname);
- if (!str) {
- fprintf(stderr, "Couldn't read %s\n", v[fname_idx]);
- return 1;
- }
-
- env = crypto_pk_new();
- if (crypto_pk_read_public_key_from_string(env, str, strlen(str))<0) {
- fprintf(stderr, "Couldn't parse key.\n");
- return 1;
- }
- tor_free(str);
-
- if (wantdigest) {
- char digest[HEX_DIGEST_LEN+1];
- if (crypto_pk_get_fingerprint(env, digest, 0)<0)
- return 1;
- printf("%s\n",digest);
- } else {
- rsa = crypto_pk_get_rsa_(env);
-
- const BIGNUM *rsa_n;
-#ifdef OPENSSL_1_1_API
- const BIGNUM *rsa_e, *rsa_d;
- RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d);
-#else
- rsa_n = rsa->n;
-#endif
- str = BN_bn2hex(rsa_n);
-
- printf("%s\n", str);
- }
-
- return 0;
-}
-
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index db308485e6..fb7465c0eb 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2015, The Tor Project, Inc. */
+/* Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#include "orconfig.h"
@@ -430,7 +430,7 @@ key_to_string(EVP_PKEY *key)
static int
get_fingerprint(EVP_PKEY *pkey, char *out)
{
- int r = 1;
+ int r = -1;
crypto_pk_t *pk = crypto_new_pk_from_rsa_(EVP_PKEY_get1_RSA(pkey));
if (pk) {
r = crypto_pk_get_fingerprint(pk, out, 0);
@@ -443,7 +443,7 @@ get_fingerprint(EVP_PKEY *pkey, char *out)
static int
get_digest(EVP_PKEY *pkey, char *out)
{
- int r = 1;
+ int r = -1;
crypto_pk_t *pk = crypto_new_pk_from_rsa_(EVP_PKEY_get1_RSA(pkey));
if (pk) {
r = crypto_pk_get_digest(pk, out);
@@ -464,16 +464,20 @@ generate_certificate(void)
char expires[ISO_TIME_LEN+1];
char id_digest[DIGEST_LEN];
char fingerprint[FINGERPRINT_LEN+1];
- char *ident = key_to_string(identity_key);
- char *signing = key_to_string(signing_key);
FILE *f;
size_t signed_len;
char digest[DIGEST_LEN];
char signature[1024]; /* handles up to 8192-bit keys. */
int r;
- get_fingerprint(identity_key, fingerprint);
- get_digest(identity_key, id_digest);
+ if (get_fingerprint(identity_key, fingerprint) < 0) {
+ return -1;
+ }
+ if (get_digest(identity_key, id_digest)) {
+ return -1;
+ }
+ char *ident = key_to_string(identity_key);
+ char *signing = key_to_string(signing_key);
tor_localtime_r(&now, &tm);
tm.tm_mon += months_lifetime;
diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c
index 6ac866d3c0..966b88b3e8 100644
--- a/src/tools/tor-resolve.c
+++ b/src/tools/tor-resolve.c
@@ -1,5 +1,5 @@
/* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
- * Copyright (c) 2007-2015, The Tor Project, Inc.
+ * Copyright (c) 2007-2017, The Tor Project, Inc.
*/
/* See LICENSE for licensing information */
@@ -347,7 +347,6 @@ main(int argc, char **argv)
int n_args;
tor_addr_t result;
char *result_hostname = NULL;
- log_severity_list_t *s = tor_malloc_zero(sizeof(log_severity_list_t));
init_logging(1);
sandbox_disable_getaddrinfo_cache();
@@ -398,11 +397,14 @@ main(int argc, char **argv)
usage();
}
+ log_severity_list_t *severities =
+ tor_malloc_zero(sizeof(log_severity_list_t));
if (isVerbose)
- set_log_severity_config(LOG_DEBUG, LOG_ERR, s);
+ set_log_severity_config(LOG_DEBUG, LOG_ERR, severities);
else
- set_log_severity_config(LOG_WARN, LOG_ERR, s);
- add_stream_log(s, "<stderr>", fileno(stderr));
+ set_log_severity_config(LOG_WARN, LOG_ERR, severities);
+ add_stream_log(severities, "<stderr>", fileno(stderr));
+ tor_free(severities);
if (n_args == 1) {
log_debug(LD_CONFIG, "defaulting to localhost");
diff --git a/src/tools/tor_runner.c b/src/tools/tor_runner.c
new file mode 100644
index 0000000000..cad57a7665
--- /dev/null
+++ b/src/tools/tor_runner.c
@@ -0,0 +1,102 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * @file tor_runner.c
+ * @brief Experimental module to emulate tor_run_main() API with fork+exec
+ *
+ * The functions here are meant to allow the application developer to
+ * use the tor_run_main() API without having to care whether Tor is
+ * running in-process or out-of-process. For in-process usage, the
+ * developer can link Tor as a library and call tor_run_main(); for
+ * out-of-process usage, the developer can link this library instead.
+ *
+ * This interface is EXPERIMENTAL; please let us know if you would like
+ * to depend on it. We don't know yet whether it will be reliable in
+ * practice.
+ */
+
+/* NOTE: This module is supposed to work without the standard Tor utility
+ * functions. Don't add more dependencies!
+ */
+
+#include "tor_api.h"
+#include "tor_api_internal.h"
+
+#include "orconfig.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef __GNUC__
+#define __attribute__(x)
+#endif
+
+static void child(const tor_main_configuration_t *cfg)
+ __attribute__((noreturn));
+
+int
+tor_run_main(const tor_main_configuration_t *cfg)
+{
+ pid_t pid = fork();
+ if (pid == 0) {
+ child(cfg);
+ exit(0); /* Unreachable */
+ }
+
+ pid_t stopped_pid;
+ int status = 0;
+ do {
+ stopped_pid = waitpid(pid, &status, 0);
+ } while (stopped_pid == -1);
+
+ /* Note: these return values are not documented. No return value is
+ * documented! */
+
+ if (stopped_pid != pid) {
+ return -99999;
+ }
+ if (WIFSTOPPED(status)) {
+ return WEXITSTATUS(status);
+ }
+ if (WIFSIGNALED(status)) {
+ return -WTERMSIG(status);
+ }
+
+ return -999988;
+}
+
+/* circumlocution to avoid getting warned about calling calloc instead of
+ * tor_calloc. */
+#define real_calloc calloc
+#define real_free free
+
+static void
+child(const tor_main_configuration_t *cfg)
+{
+ /* XXXX Close unused file descriptors. */
+
+ char **args = real_calloc(cfg->argc+1, sizeof(char *));
+ memcpy(args, cfg->argv, cfg->argc * sizeof(char *));
+ args[cfg->argc] = NULL;
+
+ int rv = execv(BINDIR "/tor", args);
+
+ if (rv < 0) {
+ real_free(args);
+ exit(254);
+ } else {
+ abort(); /* Unreachable */
+ }
+}