aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <[email protected]>2015-11-05 12:59:33 +0000
committerNeal H. Walfield <[email protected]>2015-11-05 12:59:33 +0000
commitcd2d685230ecafb7df504ef2b16cf1ec9a014300 (patch)
tree37f70754c64c4e703391653650079c11a5f7be6e
parentdoc: Add documentation for gpgkey2ssh. (diff)
downloadgnupg-cd2d685230ecafb7df504ef2b16cf1ec9a014300.tar.gz
gnupg-cd2d685230ecafb7df504ef2b16cf1ec9a014300.zip
tools: Fix gpgkey2ssh's most gratuitous errors. Use gpg2, not gpg.
* tools/gpgkey2ssh.c (main): Add support for --help. Replace the most gratuitous asserts with error messages. Invoke gpg2, not gpg. -- Signed-off-by: Neal H. Walfield <[email protected]> Debian-bug-id: 380241
-rw-r--r--tools/gpgkey2ssh.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/tools/gpgkey2ssh.c b/tools/gpgkey2ssh.c
index d22c5acf2..20541509c 100644
--- a/tools/gpgkey2ssh.c
+++ b/tools/gpgkey2ssh.c
@@ -248,7 +248,7 @@ main (int argc, char **argv)
int algorithm_id;
pkdbuf_t *pkdbuf;
size_t pkdbuf_n;
- char *command;
+ char *command = NULL;
FILE *fp;
int ret;
gcry_error_t err;
@@ -263,21 +263,50 @@ main (int argc, char **argv)
algorithm_id = 0; /* (avoid cc warning) */
identifier = NULL; /* (avoid cc warning) */
- assert (argc == 2);
+ if (argc != 2)
+ {
+ fprintf (stderr, "Usage: %s KEYID\n", argv[0]);
+ exit (1);
+ }
+ if (strcmp (argv[1], "--help") == 0)
+ {
+ fprintf (stderr, "Usage: %s KEYID\n", argv[0]);
+ fprintf (stderr, "\n");
+ fprintf (stderr,
+ "Convert a gpg key to a format appropriate for inclusion in an\n"
+ "ssh authorized_keys file.\n");
+ exit (0);
+ }
keyid = argv[1];
- ret = asprintf (&command,
- "gpg --list-keys --with-colons --with-key-data '%s'",
- keyid);
- assert (ret > 0);
+ asprintf (&command,
+ "gpg2 --list-keys --with-colons --with-key-data '%s'",
+ keyid);
+ if (! command)
+ {
+ fprintf (stderr, "Out of memory.\n");
+ exit (1);
+ }
fp = popen (command, "r");
- assert (fp);
+ if (! fp)
+ {
+ fprintf (stderr, "Failed to running: '%s'\n", command);
+ exit (1);
+ }
err = retrieve_key_material (fp, keyid, &algorithm_id, &pkdbuf, &pkdbuf_n);
- assert (! err);
- assert ((algorithm_id == 1) || (algorithm_id == 17));
+ if (err)
+ {
+ fprintf (stderr, "Error looking up key: %s\n", gpg_strerror (err));
+ exit (1);
+ }
+ if (! ((algorithm_id == 1) || (algorithm_id == 17)))
+ {
+ fprintf (stderr, "Unsupported algorithm: %d\n", algorithm_id);
+ exit (1);
+ }
if (algorithm_id == 1)
{