/* * Author: Manoj Ampalam * * Copyright (c) 2015 Microsoft Corp. * All rights reserved * * Protocol code that talks to public key agent using * https://tools.ietf.org/html/rfc4819 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" #include #include #include #include #include #include #include #include #include #include #include "xmalloc.h" #include "ssh.h" #include "rsa.h" #include "sshbuf.h" #include "sshkey.h" #include "authfd.h" #include "cipher.h" #include "compat.h" #include "log.h" #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 */ /* macro to check for "agent failure" message */ #define agent_failed(x) \ ((x == SSH_AGENT_FAILURE) || \ (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; 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 = ssh_request_reply(sock, msg, msg) != 0)) goto out; out: if (blob) free(blob); return r; } int ssh_list_pubkeys(int sock, struct ssh_identitylist **idlp) { return 0; } int ssh_remove_pubkey(int sock, struct sshkey *key) { return 0; } int ssh_remove_pubkey_by_fp(int sock, const char *fingerprint) { return 0; } int ssh_remove_all_pubkeys(int sock) { return 0; }