This commit is contained in:
manojampalam 2016-05-05 23:08:49 -07:00
parent c9f7185707
commit 4b5cb0d646
3 changed files with 20 additions and 4 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}