]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Unix Pageant: provide public-key extraction options.
authorSimon Tatham <anakin@pobox.com>
Tue, 12 May 2015 13:48:32 +0000 (14:48 +0100)
committerSimon Tatham <anakin@pobox.com>
Tue, 12 May 2015 13:56:39 +0000 (14:56 +0100)
I've decided against implementing an option exactly analogous to
'ssh-add -L' (printing the full public key of everything in the
agent). Instead, you can identify a specific key to display in full,
by any of the same means -d lets you use, and then print it in either
of the public key formats we support.

pageant.c
pageant.h
unix/uxpgnt.c

index c249a3b7188cc93dd6a7c3458ab1e1dc6f0a5dce..e3928cdec1fa19bb531cde25fb924c62b0882218 100644 (file)
--- a/pageant.c
+++ b/pageant.c
@@ -1624,6 +1624,7 @@ int pageant_enum_keys(pageant_key_enum_fn_t callback, void *callback_ctx,
         p += n, keylistlen -= n;
 
         cbkey.blob = rsa_public_blob(&rkey, &cbkey.bloblen);
+        cbkey.comment = comment;
         cbkey.ssh_version = 1;
         callback(callback_ctx, fingerprint, comment, &cbkey);
         sfree(cbkey.blob);
@@ -1694,6 +1695,7 @@ int pageant_enum_keys(pageant_key_enum_fn_t callback, void *callback_ctx,
         p += n, keylistlen -= n;
 
         cbkey.ssh_version = 2;
+        cbkey.comment = comment;
         callback(callback_ctx, fingerprint, comment, &cbkey);
         sfree(fingerprint);
         sfree(comment);
@@ -1751,12 +1753,14 @@ struct pageant_pubkey *pageant_pubkey_copy(struct pageant_pubkey *key)
     ret->blob = snewn(key->bloblen, unsigned char);
     memcpy(ret->blob, key->blob, key->bloblen);
     ret->bloblen = key->bloblen;
+    ret->comment = key->comment ? dupstr(key->comment) : NULL;
     ret->ssh_version = key->ssh_version;
     return ret;
 }
 
 void pageant_pubkey_free(struct pageant_pubkey *key)
 {
+    sfree(key->comment);
     sfree(key->blob);
     sfree(key);
 }
index 4a26ad93b10863e166a7eed6a0cf43c059c1bf9a..451fe7e59d3e04ec03cf5aff35445a8b06c41456 100644 (file)
--- a/pageant.h
+++ b/pageant.h
@@ -127,6 +127,7 @@ struct pageant_pubkey {
      * later */
     void *blob;
     int bloblen;
+    char *comment;
     int ssh_version;
 };
 struct pageant_pubkey *pageant_pubkey_copy(struct pageant_pubkey *key);
index 6e5923c2b5068f7aea81402e2950117a8312e285..4a46b657d8b71beb1e76ea15e78edea8a371d132 100644 (file)
@@ -240,7 +240,8 @@ typedef enum {
     KEYACT_CLIENT_DEL,
     KEYACT_CLIENT_DEL_ALL,
     KEYACT_CLIENT_LIST,
-    KEYACT_CLIENT_LIST_FULL,
+    KEYACT_CLIENT_PUBLIC_OPENSSH,
+    KEYACT_CLIENT_PUBLIC
 } keyact;
 struct cmdline_key_action {
     struct cmdline_key_action *next;
@@ -564,8 +565,34 @@ void run_client(void)
             if (key)
                 pageant_pubkey_free(key);
             break;
+          case KEYACT_CLIENT_PUBLIC_OPENSSH:
+          case KEYACT_CLIENT_PUBLIC:
+            key = NULL;
+            if (!(key = find_key(act->filename, &retstr))) {
+                fprintf(stderr, "pageant: finding key '%s': %s\n",
+                        act->filename, retstr);
+                sfree(retstr);
+                errors = TRUE;
+            } else {
+                FILE *fp = stdout;     /* FIXME: add a -o option? */
+
+                if (key->ssh_version == 1) {
+                    struct RSAKey rkey;
+                    memset(&rkey, 0, sizeof(rkey));
+                    rkey.comment = dupstr(key->comment);
+                    makekey(key->blob, key->bloblen, &rkey, NULL, 0);
+                    ssh1_write_pubkey(fp, &rkey);
+                    freersakey(&rkey);
+                } else {
+                    ssh2_write_pubkey(fp, key->comment, key->blob,key->bloblen,
+                                      (act->action == KEYACT_CLIENT_PUBLIC ?
+                                       SSH_KEYTYPE_SSH2_PUBLIC_RFC4716 :
+                                       SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH));
+                }
+                pageant_pubkey_free(key);
+            }
+            break;
           case KEYACT_CLIENT_DEL_ALL:
-          case KEYACT_CLIENT_LIST_FULL:
             fprintf(stderr, "NYI\n");
             errors = TRUE;
             break;
@@ -892,8 +919,10 @@ int main(int argc, char **argv)
                 add_keyact(KEYACT_CLIENT_DEL_ALL, NULL);
             } else if (!strcmp(p, "-l")) {
                 add_keyact(KEYACT_CLIENT_LIST, NULL);
-            } else if (!strcmp(p, "-L")) {
-                add_keyact(KEYACT_CLIENT_LIST_FULL, NULL);
+            } else if (!strcmp(p, "--public")) {
+                curr_keyact = KEYACT_CLIENT_PUBLIC;
+            } else if (!strcmp(p, "--public-openssh")) {
+                curr_keyact = KEYACT_CLIENT_PUBLIC_OPENSSH;
             } else if (!strcmp(p, "-X")) {
                 life = LIFE_X11;
             } else if (!strcmp(p, "-T")) {