diff --git a/contrib/win32/ssh-pubkey/pubkeyfd.c b/contrib/win32/ssh-pubkey/pubkeyfd.c index eac2a39..c26e8fd 100644 --- a/contrib/win32/ssh-pubkey/pubkeyfd.c +++ b/contrib/win32/ssh-pubkey/pubkeyfd.c @@ -55,6 +55,7 @@ #include "atomicio.h" #include "misc.h" #include "ssherr.h" +#include "pubkeyfd.h" #define MAX_AGENT_IDENTITIES 2048 /* Max keys in agent reply */ #define MAX_AGENT_REPLY_LEN (256 * 1024) /* Max bytes in agent reply */ @@ -66,7 +67,16 @@ (x == SSH2_AGENT_FAILURE)) -int ssh_add_pubkey(int sock, struct sshkey *key, const char *comment) { +int ssh_add_pubkey(int sock, struct sshkey *key, const char *comment, const char* password) { + struct sshbuf *msg; + int r; + + if ((msg = sshbuf_new()) == NULL) + return SSH_ERR_ALLOC_FAIL; + + if ((r = sshbuf_put_cstring(msg, PK_REQUEST_ADD)) != 0 ) + + return 0; } diff --git a/contrib/win32/ssh-pubkey/pubkeyfd.h b/contrib/win32/ssh-pubkey/pubkeyfd.h index 0bac919..730ca57 100644 --- a/contrib/win32/ssh-pubkey/pubkeyfd.h +++ b/contrib/win32/ssh-pubkey/pubkeyfd.h @@ -8,7 +8,7 @@ #define PK_REQUEST_REMOVE_ALL "removeall" #define PK_REQUEST_REMOVE_BY_FP "removebyfp" -int ssh_add_pubkey(int sock, struct sshkey *key, const char *comment); +int ssh_add_pubkey(int sock, struct sshkey *key, const char *comment, const char* password); int ssh_list_pubkeys(int sock, struct ssh_identitylist **idlp); int ssh_remove_pubkey(int sock, struct sshkey *key); int ssh_remove_pubkey_by_fp(int sock, const char *fingerprint); diff --git a/contrib/win32/ssh-pubkey/ssh-pubkey.c b/contrib/win32/ssh-pubkey/ssh-pubkey.c index cd99ddd..f5b3d1d 100644 --- a/contrib/win32/ssh-pubkey/ssh-pubkey.c +++ b/contrib/win32/ssh-pubkey/ssh-pubkey.c @@ -143,7 +143,7 @@ static int do_file(int agent_fd, int deleting, char *filename) { struct sshkey *public; - char *comment = NULL; + char *comment = NULL, *password = NULL; int r, ret = -1; if ((r = sshkey_load_public(filename, &public, &comment)) != 0) { @@ -161,7 +161,13 @@ do_file(int agent_fd, int deleting, char *filename) filename, ssh_err(r)); } else { - if ((r = ssh_add_pubkey(agent_fd, public, comment)) == 0) { + if ((password = read_passphrase("Enter your password: ", + RP_ALLOW_STDIN)) == NULL) { + ret = ENOMEM; + goto out; + } + + if ((r = ssh_add_pubkey(agent_fd, public, comment, password)) == 0) { fprintf(stderr, "Public key added: %s (%s)\n", filename, comment); ret = 0; }