diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-15 10:59:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-15 10:59:49 +0000 |
commit | 06ab78ee651fdda7cf37a7c012445bb087060a05 (patch) | |
tree | 3bc1c510eb0c1440406245832ab0aacc8ad011cd | |
parent | 6ae1a7d3bab29dd9d75c268aee9d0e0e002acf6c (diff) | |
download | gnunet-06ab78ee651fdda7cf37a7c012445bb087060a05.tar.gz gnunet-06ab78ee651fdda7cf37a7c012445bb087060a05.zip |
add -P option for printing peer identities with gnunet-rsa
-rw-r--r-- | doc/man/gnunet-rsa.1 | 9 | ||||
-rw-r--r-- | src/util/gnunet-rsa.c | 31 |
2 files changed, 31 insertions, 9 deletions
diff --git a/doc/man/gnunet-rsa.1 b/doc/man/gnunet-rsa.1 index 3d9aae8af..f3b1df3d3 100644 --- a/doc/man/gnunet-rsa.1 +++ b/doc/man/gnunet-rsa.1 | |||
@@ -1,4 +1,4 @@ | |||
1 | .TH GNUNET\-RSA 1 "Jan 4, 2012" "GNUnet" | 1 | .TH GNUNET\-RSA 1 "Mar 15, 2012" "GNUnet" |
2 | 2 | ||
3 | .SH NAME | 3 | .SH NAME |
4 | gnunet\-rsa \- manipulate GNUnet RSA key files | 4 | gnunet\-rsa \- manipulate GNUnet RSA key files |
@@ -13,8 +13,11 @@ gnunet\-rsa \- manipulate GNUnet RSA key files | |||
13 | 13 | ||
14 | .SH OPTIONS | 14 | .SH OPTIONS |
15 | .B | 15 | .B |
16 | .IP "\-p, \-\-print" | 16 | .IP "\-p, \-\-print-public-key" |
17 | Print the corresponding public key (to stdout). | 17 | Print the corresponding public key to stdout. |
18 | .B | ||
19 | .IP "\-P, \-\-print-peer-identity" | ||
20 | Print the corresponding peer identity (hash of the public key) to stdout. | ||
18 | .B | 21 | .B |
19 | .IP "\-c FILENAME, \-\-config=FILENAME" | 22 | .IP "\-c FILENAME, \-\-config=FILENAME" |
20 | Use the configuration file FILENAME. | 23 | Use the configuration file FILENAME. |
diff --git a/src/util/gnunet-rsa.c b/src/util/gnunet-rsa.c index 2dd1f376f..bfd854e65 100644 --- a/src/util/gnunet-rsa.c +++ b/src/util/gnunet-rsa.c | |||
@@ -28,9 +28,14 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Flag for reverse lookup. | 31 | * Flag for printing public key. |
32 | */ | 32 | */ |
33 | static int print; | 33 | static int print_public_key; |
34 | |||
35 | /** | ||
36 | * Flag for printing hash of public key. | ||
37 | */ | ||
38 | static int print_peer_identity; | ||
34 | 39 | ||
35 | 40 | ||
36 | /** | 41 | /** |
@@ -47,7 +52,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
47 | { | 52 | { |
48 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; | 53 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; |
49 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 54 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
50 | char *s; | 55 | struct GNUNET_PeerIdentity pid; |
51 | 56 | ||
52 | if (NULL == args[0]) | 57 | if (NULL == args[0]) |
53 | { | 58 | { |
@@ -55,13 +60,24 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
55 | return; | 60 | return; |
56 | } | 61 | } |
57 | pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); | 62 | pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); |
58 | if (print) | 63 | if (print_public_key) |
59 | { | 64 | { |
65 | char *s; | ||
66 | |||
60 | GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); | 67 | GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); |
61 | s = GNUNET_CRYPTO_rsa_public_key_to_string (&pub); | 68 | s = GNUNET_CRYPTO_rsa_public_key_to_string (&pub); |
62 | fprintf (stdout, "%s\n", s); | 69 | fprintf (stdout, "%s\n", s); |
63 | GNUNET_free (s); | 70 | GNUNET_free (s); |
64 | } | 71 | } |
72 | if (print_peer_identity) | ||
73 | { | ||
74 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | ||
75 | |||
76 | GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); | ||
77 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); | ||
78 | GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc); | ||
79 | fprintf (stdout, "%s\n", enc.encoding); | ||
80 | } | ||
65 | GNUNET_CRYPTO_rsa_key_free (pk); | 81 | GNUNET_CRYPTO_rsa_key_free (pk); |
66 | } | 82 | } |
67 | 83 | ||
@@ -77,9 +93,12 @@ int | |||
77 | main (int argc, char *const *argv) | 93 | main (int argc, char *const *argv) |
78 | { | 94 | { |
79 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 95 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
80 | { 'p', "print", NULL, | 96 | { 'p', "print-public-key", NULL, |
81 | gettext_noop ("print the public key in ASCII format"), | 97 | gettext_noop ("print the public key in ASCII format"), |
82 | 0, &GNUNET_GETOPT_set_one, &print }, | 98 | 0, &GNUNET_GETOPT_set_one, &print_public_key }, |
99 | { 'P', "print-peer-identity", NULL, | ||
100 | gettext_noop ("print the hash of the public key in ASCII format"), | ||
101 | 0, &GNUNET_GETOPT_set_one, &print_peer_identity }, | ||
83 | GNUNET_GETOPT_OPTION_END | 102 | GNUNET_GETOPT_OPTION_END |
84 | }; | 103 | }; |
85 | return (GNUNET_OK == | 104 | return (GNUNET_OK == |