[or-cvs] r18478: {tor} Enhance tor-checkkey tool so it can generate key hashes too. (tor/trunk/src/tools)

nickm at seul.org nickm at seul.org
Tue Feb 10 20:03:58 UTC 2009


Author: nickm
Date: 2009-02-10 15:03:58 -0500 (Tue, 10 Feb 2009)
New Revision: 18478

Modified:
   tor/trunk/src/tools/tor-checkkey.c
Log:
Enhance tor-checkkey tool so it can generate key hashes too.

Modified: tor/trunk/src/tools/tor-checkkey.c
===================================================================
--- tor/trunk/src/tools/tor-checkkey.c	2009-02-10 18:52:47 UTC (rev 18477)
+++ tor/trunk/src/tools/tor-checkkey.c	2009-02-10 20:03:58 UTC (rev 18478)
@@ -17,12 +17,15 @@
   crypto_pk_env_t *env;
   char *str;
   RSA *rsa;
+  int wantdigest=0;
+  int fname_idx;
   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");
+            "dump the modulus.  Use the --digest option too and I'll "
+            "dump the digest.\n");
     return 1;
   }
 
@@ -31,9 +34,21 @@
     return 1;
   }
 
-  str = read_file_to_str(v[1], 0, NULL);
+  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;
+  }
+
+  str = read_file_to_str(v[fname_idx], 0, NULL);
   if (!str) {
-    fprintf(stderr, "Couldn't read %s\n", v[1]);
+    fprintf(stderr, "Couldn't read %s\n", v[fname_idx]);
     return 1;
   }
 
@@ -44,10 +59,17 @@
   }
   tor_free(str);
 
-  rsa = _crypto_pk_env_get_rsa(env);
-  str = BN_bn2hex(rsa->n);
+  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_env_get_rsa(env);
+    str = BN_bn2hex(rsa->n);
 
-  printf("%s\n", str);
+    printf("%s\n", str);
+  }
 
   return 0;
 }



More information about the tor-commits mailing list