Skip to content

Commit

Permalink
Unix Pageant: provide public-key extraction options.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgtatham committed May 12, 2015
1 parent 8682246 commit e533097
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pageant.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions pageant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 33 additions & 4 deletions unix/uxpgnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down

0 comments on commit e533097

Please sign in to comment.