aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/Makefile.am6
-rw-r--r--src/tools/tor-checkkey.c14
-rw-r--r--src/tools/tor-gencert.c28
-rw-r--r--src/tools/tor-resolve.c8
4 files changed, 36 insertions, 20 deletions
diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index 41786e437..1bb507684 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -3,16 +3,16 @@ noinst_PROGRAMS = tor-checkkey
tor_resolve_SOURCES = tor-resolve.c
tor_resolve_LDFLAGS = @TOR_LDFLAGS_libevent@
-tor_resolve_LDADD = ../common/libor.a @TOR_LIBEVENT_LIBS@ @TOR_LIB_WS32@
+tor_resolve_LDADD = ../common/libor.a -lm @TOR_LIBEVENT_LIBS@ @TOR_LIB_WS32@
tor_gencert_SOURCES = tor-gencert.c
tor_gencert_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
@TOR_LDFLAGS_libevent@
tor_gencert_LDADD = ../common/libor.a ../common/libor-crypto.a \
- -lz @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
+ -lm @TOR_ZLIB_LIBS@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
tor_checkkey_SOURCES = tor-checkkey.c
tor_checkkey_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
@TOR_LDFLAGS_libevent@
tor_checkkey_LDADD = ../common/libor.a ../common/libor-crypto.a \
- -lz @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
+ -lm @TOR_ZLIB_LIBS@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
diff --git a/src/tools/tor-checkkey.c b/src/tools/tor-checkkey.c
index b29b52d8d..94c8cbd44 100644
--- a/src/tools/tor-checkkey.c
+++ b/src/tools/tor-checkkey.c
@@ -6,19 +6,21 @@
#include <stdio.h>
#include <stdlib.h>
#include "crypto.h"
-#include "log.h"
-#include "util.h"
+#include "torlog.h"
+#include "../common/util.h"
#include "compat.h"
#include <openssl/bn.h>
#include <openssl/rsa.h>
-int main(int c, char **v)
+int
+main(int c, char **v)
{
crypto_pk_env_t *env;
char *str;
RSA *rsa;
int wantdigest=0;
int fname_idx;
+ char *fname=NULL;
init_logging();
if (c < 2) {
@@ -29,7 +31,7 @@ int main(int c, char **v)
return 1;
}
- if (crypto_global_init(0)) {
+ if (crypto_global_init(0, NULL, NULL)) {
fprintf(stderr, "Couldn't initialize crypto library.\n");
return 1;
}
@@ -46,7 +48,9 @@ int main(int c, char **v)
fname_idx = 1;
}
- str = read_file_to_str(v[fname_idx], 0, NULL);
+ 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;
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index e6b09963b..a04eddafc 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -13,6 +13,7 @@
#include <openssl/evp.h>
#include <openssl/pem.h>
+#include <openssl/rsa.h>
#include <openssl/objects.h>
#include <openssl/obj_mac.h>
#include <openssl/err.h>
@@ -27,8 +28,8 @@
#define CRYPTO_PRIVATE
#include "compat.h"
-#include "util.h"
-#include "log.h"
+#include "../common/util.h"
+#include "../common/torlog.h"
#include "crypto.h"
#include "address.h"
@@ -63,7 +64,6 @@ show_help(void)
"[-c certificate_file]\n"
" [-m lifetime_in_months] [-a address:port] "
"[--passphrase-fd <fd>]\n");
-
}
/* XXXX copied from crypto.c */
@@ -218,6 +218,20 @@ parse_commandline(int argc, char **argv)
return 0;
}
+static RSA *
+generate_key(int bits)
+{
+ RSA *rsa = NULL;
+ crypto_pk_env_t *env = crypto_new_pk_env();
+ if (crypto_pk_generate_key_with_bits(env,bits)<0)
+ goto done;
+ rsa = _crypto_pk_env_get_rsa(env);
+ rsa = RSAPrivateKey_dup(rsa);
+ done:
+ crypto_free_pk_env(env);
+ return rsa;
+}
+
/** Try to read the identity key from <b>identity_key_file</b>. If no such
* file exists and create_identity_key is set, make a new identity key and
* store it. Return 0 on success, nonzero on failure.
@@ -238,7 +252,7 @@ load_identity_key(void)
}
log_notice(LD_GENERAL, "Generating %d-bit RSA identity key.",
IDENTITY_KEY_BITS);
- if (!(key = RSA_generate_key(IDENTITY_KEY_BITS, 65537, NULL, NULL))) {
+ if (!(key = generate_key(IDENTITY_KEY_BITS))) {
log_err(LD_GENERAL, "Couldn't generate identity key.");
crypto_log_errors(LOG_ERR, "Generating identity key");
return 1;
@@ -323,7 +337,7 @@ generate_signing_key(void)
RSA *key;
log_notice(LD_GENERAL, "Generating %d-bit RSA signing key.",
SIGNING_KEY_BITS);
- if (!(key = RSA_generate_key(SIGNING_KEY_BITS, 65537, NULL, NULL))) {
+ if (!(key = generate_key(SIGNING_KEY_BITS))) {
log_err(LD_GENERAL, "Couldn't generate signing key.");
crypto_log_errors(LOG_ERR, "Generating signing key");
return 1;
@@ -393,7 +407,6 @@ get_fingerprint(EVP_PKEY *pkey, char *out)
return r;
}
-
/** Set <b>out</b> to the hex-encoded fingerprint of <b>pkey</b>. */
static int
get_digest(EVP_PKEY *pkey, char *out)
@@ -487,7 +500,6 @@ generate_certificate(void)
return 0;
}
-
/** Entry point to tor-gencert */
int
main(int argc, char **argv)
@@ -496,7 +508,7 @@ main(int argc, char **argv)
init_logging();
/* Don't bother using acceleration. */
- if (crypto_global_init(0)) {
+ if (crypto_global_init(0, NULL, NULL)) {
fprintf(stderr, "Couldn't initialize crypto library.\n");
return 1;
}
diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c
index 4d9d57a31..12349d9d1 100644
--- a/src/tools/tor-resolve.c
+++ b/src/tools/tor-resolve.c
@@ -6,9 +6,9 @@
#include "orconfig.h"
#include "compat.h"
-#include "util.h"
+#include "../common/util.h"
#include "address.h"
-#include "log.h"
+#include "../common/torlog.h"
#include <stdio.h>
#include <stdlib.h>
@@ -148,7 +148,7 @@ parse_socks4a_resolve_response(const char *hostname,
static const char *
socks5_reason_to_string(char reason)
{
- switch(reason) {
+ switch (reason) {
case SOCKS5_SUCCEEDED:
return "succeeded";
case SOCKS5_GENERAL_ERROR:
@@ -251,7 +251,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
}
if (parse_socks4a_resolve_response(hostname,
reply_buf, RESPONSE_LEN_4,
- result_addr)<0){
+ result_addr)<0) {
return -1;
}
} else {