[or-cvs] r14580: New (temporary) tool to dump the modulus of a key. May help (in tor/trunk: . src/common src/tools)

nickm at seul.org nickm at seul.org
Fri May 9 08:35:38 UTC 2008


Author: nickm
Date: 2008-05-09 04:35:38 -0400 (Fri, 09 May 2008)
New Revision: 14580

Added:
   tor/trunk/src/tools/tor-checkkey.c
Modified:
   tor/trunk/
   tor/trunk/src/common/crypto.c
   tor/trunk/src/common/crypto.h
   tor/trunk/src/tools/Makefile.am
Log:
 r15558 at 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.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r15558] on 49666b30-7950-49c5-bedf-9dc8f3168102

Modified: tor/trunk/src/common/crypto.c
===================================================================
--- tor/trunk/src/common/crypto.c	2008-05-09 08:11:26 UTC (rev 14579)
+++ tor/trunk/src/common/crypto.c	2008-05-09 08:35:38 UTC (rev 14580)
@@ -258,6 +258,12 @@
   return _crypto_new_pk_env_rsa(rsa);
 }
 
+RSA *
+_crypto_pk_env_get_rsa(crypto_pk_env_t *env)
+{
+  return env->key;
+}
+
 /** used by tortls.c: get an equivalent EVP_PKEY* for a crypto_pk_env_t.  Iff
  * private is set, include the private-key portion of the key. */
 EVP_PKEY *

Modified: tor/trunk/src/common/crypto.h
===================================================================
--- tor/trunk/src/common/crypto.h	2008-05-09 08:11:26 UTC (rev 14579)
+++ tor/trunk/src/common/crypto.h	2008-05-09 08:35:38 UTC (rev 14580)
@@ -199,6 +199,7 @@
 struct rsa_st;
 struct evp_pkey_st;
 struct dh_st;
+struct rsa_st *_crypto_pk_env_get_rsa(crypto_pk_env_t *env);
 crypto_pk_env_t *_crypto_new_pk_env_rsa(struct rsa_st *rsa);
 crypto_pk_env_t *_crypto_new_pk_env_evp_pkey(struct evp_pkey_st *pkey);
 struct evp_pkey_st *_crypto_pk_env_get_evp_pkey(crypto_pk_env_t *env,

Modified: tor/trunk/src/tools/Makefile.am
===================================================================
--- tor/trunk/src/tools/Makefile.am	2008-05-09 08:11:26 UTC (rev 14579)
+++ tor/trunk/src/tools/Makefile.am	2008-05-09 08:35:38 UTC (rev 14580)
@@ -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_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@

Added: tor/trunk/src/tools/tor-checkkey.c
===================================================================
--- tor/trunk/src/tools/tor-checkkey.c	                        (rev 0)
+++ tor/trunk/src/tools/tor-checkkey.c	2008-05-09 08:35:38 UTC (rev 14580)
@@ -0,0 +1,49 @@
+
+#define CRYPTO_PRIVATE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "crypto.h"
+#include "log.h"
+#include "util.h"
+#include "compat.h"
+#include <openssl/bn.h>
+#include <openssl/rsa.h>
+
+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;
+}



More information about the tor-commits mailing list