From 3f63888e81789dee65c784dad260f44ea183654a Mon Sep 17 00:00:00 2001 From: Manoj Ampalam Date: Fri, 6 May 2016 15:04:52 -0700 Subject: [PATCH] 5-6 C1 --- contrib/win32/ssh-pubkey/pubkeyfd.c | 26 +++++++++++++++++++++++--- contrib/win32/ssh-pubkey/pubkeyfd.h | 11 +++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/contrib/win32/ssh-pubkey/pubkeyfd.c b/contrib/win32/ssh-pubkey/pubkeyfd.c index c26e8fd..72bf417 100644 --- a/contrib/win32/ssh-pubkey/pubkeyfd.c +++ b/contrib/win32/ssh-pubkey/pubkeyfd.c @@ -66,18 +66,38 @@ (x == SSH_COM_AGENT2_FAILURE) || \ (x == SSH2_AGENT_FAILURE)) +int +ssh_request_reply(int , struct sshbuf *, struct sshbuf *); + int ssh_add_pubkey(int sock, struct sshkey *key, const char *comment, const char* password) { struct sshbuf *msg; - int r; + u_char *blob = NULL, *status = NULL, *description = NULL, *lang_tag = NULL; + size_t blen = 0; + int r, status_code; if ((msg = sshbuf_new()) == NULL) return SSH_ERR_ALLOC_FAIL; + if ((r = sshkey_to_blob(key, &blob, &blen)) != 0) + goto out; + + if ((r = sshbuf_put_cstring(msg, PK_REQUEST_ADD)) != 0 || + (r = sshbuf_put_string(msg, blob, blen)) != 0 || + (r = sshbuf_put_u32(msg, 1)) != 0 || + (r = sshbuf_put_cstring(msg, "comment")) != 0 || + (r = sshbuf_put_cstring(msg, comment)) != 0 || + (r = sshbuf_put_u8(msg, 1)) != 0) + goto out; - if ((r = sshbuf_put_cstring(msg, PK_REQUEST_ADD)) != 0 ) + if ((r = ssh_request_reply(sock, msg, msg) != 0)) + goto out; - return 0; + +out: + if (blob) + free(blob); + return r; } int ssh_list_pubkeys(int sock, struct ssh_identitylist **idlp) { diff --git a/contrib/win32/ssh-pubkey/pubkeyfd.h b/contrib/win32/ssh-pubkey/pubkeyfd.h index 730ca57..466c4ce 100644 --- a/contrib/win32/ssh-pubkey/pubkeyfd.h +++ b/contrib/win32/ssh-pubkey/pubkeyfd.h @@ -8,6 +8,17 @@ #define PK_REQUEST_REMOVE_ALL "removeall" #define PK_REQUEST_REMOVE_BY_FP "removebyfp" +#define SSH_PUBLICKEY_SUCCESS 0 +#define SSH_PUBLICKEY_ACCESS_DENIED 1 +#define SSH_PUBLICKEY_STORAGE_EXCEEDED 2 +#define SSH_PUBLICKEY_VERSION_NOT_SUPPORTED 3 +#define SSH_PUBLICKEY_KEY_NOT_FOUND 4 +#define SSH_PUBLICKEY_KEY_NOT_SUPPORTED 5 +#define SSH_PUBLICKEY_KEY_ALREADY_PRESENT 6 +#define SSH_PUBLICKEY_GENERAL_FAILURE 7 +#define SSH_PUBLICKEY_REQUEST_NOT_SUPPORTED 8 +#define SSH_PUBLICKEY_ATTRIBUTE_NOT_SUPPORTED 9 + 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);