From b7a80920e26f53e354975a7252e3a1f33ef9192b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 9 May 2008 08:35:38 +0000 Subject: r15558@tombo: nickm | 2008-05-09 04:35:12 -0400 New (temporary) tool to dump the modulus of a key. May help with a project of weasel's. svn:r14580 --- src/tools/Makefile.am | 6 ++++++ src/tools/tor-checkkey.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/tools/tor-checkkey.c (limited to 'src/tools') diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index 7d7f2c7b8f..79393d6854 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -1,4 +1,5 @@ bin_PROGRAMS = tor-resolve tor-gencert +noinst_PROGRAMS = tor-checkkey tor_resolve_SOURCES = tor-resolve.c tor_resolve_LDFLAGS = @TOR_LDFLAGS_libevent@ @@ -10,3 +11,8 @@ tor_gencert_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \ tor_gencert_LDADD = ../common/libor.a ../common/libor-crypto.a \ -lz -lcrypto -levent @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 -lcrypto -levent @TOR_LIB_WS32@ @TOR_LIB_GDI@ diff --git a/src/tools/tor-checkkey.c b/src/tools/tor-checkkey.c new file mode 100644 index 0000000000..e0be6d7287 --- /dev/null +++ b/src/tools/tor-checkkey.c @@ -0,0 +1,49 @@ + +#define CRYPTO_PRIVATE + +#include +#include +#include "crypto.h" +#include "log.h" +#include "util.h" +#include "compat.h" +#include +#include + +int main(int c, char **v) +{ + crypto_pk_env_t *env; + char *str; + RSA *rsa; + init_logging(); + + 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.\n"); + return 1; + } + + if (crypto_global_init(0)) { + fprintf(stderr, "Couldn't initialize crypto library.\n"); + return 1; + } + + str = read_file_to_str(v[1], 0, NULL); + if (!str) { + fprintf(stderr, "Couldn't read %s\n", v[1]); + return 1; + } + + env = crypto_new_pk_env(); + 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); + + rsa = _crypto_pk_env_get_rsa(env); + str = BN_bn2hex(rsa->n); + + printf("%s\n", str); + + return 0; +} -- cgit v1.2.3-54-g00ecf