aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-09-12 18:05:54 +0000
committerNick Mathewson <nickm@torproject.org>2006-09-12 18:05:54 +0000
commit8870621e1de271894efd70b034d4dcc8855d20a2 (patch)
tree130a9679a5eb580cb23b93ab4866fd14993381cc
parentb790efa2d2243a9ed0414593e40a1084a1196677 (diff)
downloadtor-8870621e1de271894efd70b034d4dcc8855d20a2.tar
tor-8870621e1de271894efd70b034d4dcc8855d20a2.tar.gz
r8785@Kushana: nickm | 2006-09-12 14:05:46 -0400
Add non-dist utility for weasel svn:r8373
-rw-r--r--contrib/id_to_fp.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/id_to_fp.c b/contrib/id_to_fp.c
new file mode 100644
index 000000000..c8f74ff16
--- /dev/null
+++ b/contrib/id_to_fp.c
@@ -0,0 +1,50 @@
+/* Copyright 2006 Nick Mathewson; see LICENSE for licensing information */
+/* $Id$ */
+
+/* id_to_fp.c : Helper for directory authority ops. When somebody sends us
+ * a private key, this utility converts the private key into a fingerprint
+ * so you can de-list that fingerprint.
+ */
+
+#include <openssl/rsa.h>
+#include <openssl/bio.h>
+#include <openssl/sha.h>
+#include <openssl/pem.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define die(s) do { fprintf(stderr, s "\n"); return 1; } while (0)
+
+int
+main(int argc, char **argv)
+{
+ BIO *b;
+ RSA *key;
+ unsigned char *buf, *bufp;
+ int len, i;
+ unsigned char digest[20];
+
+ if (argc != 2)
+ die("I want a filename");
+ if (!(b = BIO_new_file(argv[1], "r")))
+ die("couldn't open file");
+
+ if (!(key = PEM_read_bio_RSAPrivateKey(b, NULL, NULL, NULL)))
+ die("couldn't parse key");
+
+ len = i2d_RSAPublicKey(key, NULL);
+ bufp = buf = malloc(len+1);
+ len = i2d_RSAPublicKey(key, &bufp);
+ if (len < 0)
+ die("Bizarre key");
+
+ SHA1(buf, len, digest);
+ for (i=0; i < 20; i += 2) {
+ printf("%02X%02X ", (int)digest[i], (int)digest[i+1]);
+ }
+ printf("\n");
+
+ return 0;
+}
+