From 473841c4cc0d96dceeef107400df13e09f4f4d21 Mon Sep 17 00:00:00 2001 From: Manoj Ampalam Date: Sun, 8 May 2016 10:31:46 -0700 Subject: [PATCH] 5-8 C1 --- authfd.c | 2 +- contrib/win32/openssh/Win32-OpenSSH.sln | 3 +- contrib/win32/openssh/ssh-agent.vcxproj | 4 +- .../win32compat/ssh-agent/agent-request.h | 6 +-- contrib/win32/win32compat/ssh-agent/agent.c | 13 ++++--- .../win32compat/ssh-agent/authagent-request.c | 37 +++++++++++++++++++ .../win32/win32compat/ssh-agent/connection.c | 24 ++++-------- .../{agent-request.c => keyagent-request.c} | 19 ++++++++++ .../ssh-agent/pubkeyagent-request.c | 37 +++++++++++++++++++ 9 files changed, 116 insertions(+), 29 deletions(-) create mode 100644 contrib/win32/win32compat/ssh-agent/authagent-request.c rename contrib/win32/win32compat/ssh-agent/{agent-request.c => keyagent-request.c} (95%) create mode 100644 contrib/win32/win32compat/ssh-agent/pubkeyagent-request.c diff --git a/authfd.c b/authfd.c index 9ec6eb8..e9f6826 100644 --- a/authfd.c +++ b/authfd.c @@ -105,7 +105,7 @@ ssh_get_authentication_socket(int *fdp) } HANDLE h = CreateFile( - "\\\\.\\pipe\\ssh-agent", // pipe name + "\\\\.\\pipe\\ssh-keyagent", // pipe name GENERIC_READ | // read and write access GENERIC_WRITE, 0, // no sharing diff --git a/contrib/win32/openssh/Win32-OpenSSH.sln b/contrib/win32/openssh/Win32-OpenSSH.sln index 30cf59d..637236d 100644 --- a/contrib/win32/openssh/Win32-OpenSSH.sln +++ b/contrib/win32/openssh/Win32-OpenSSH.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssh", "ssh.vcxproj", "{74E69D5E-A1EF-46EA-9173-19A412774104}" ProjectSection(ProjectDependencies) = postProject @@ -89,6 +89,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssh-add", "ssh-add.vcxproj", "{029797FF-C986-43DE-95CD-2E771E86AEBC}" ProjectSection(ProjectDependencies) = postProject {05E1115F-8529-46D0-AAAF-52A404CE79A7} = {05E1115F-8529-46D0-AAAF-52A404CE79A7} + {8F9D3B74-8D33-448E-9762-26E8DCC6B2F4} = {8F9D3B74-8D33-448E-9762-26E8DCC6B2F4} {DD483F7D-C553-4740-BC1A-903805AD0174} = {DD483F7D-C553-4740-BC1A-903805AD0174} {0D02F0F0-013B-4EE3-906D-86517F3822C0} = {0D02F0F0-013B-4EE3-906D-86517F3822C0} {8660C2FE-9874-432D-B047-E042BB41DBE0} = {8660C2FE-9874-432D-B047-E042BB41DBE0} diff --git a/contrib/win32/openssh/ssh-agent.vcxproj b/contrib/win32/openssh/ssh-agent.vcxproj index d8de160..06a5397 100644 --- a/contrib/win32/openssh/ssh-agent.vcxproj +++ b/contrib/win32/openssh/ssh-agent.vcxproj @@ -206,9 +206,11 @@ + - + + diff --git a/contrib/win32/win32compat/ssh-agent/agent-request.h b/contrib/win32/win32compat/ssh-agent/agent-request.h index 18c8aa9..2bdd591 100644 --- a/contrib/win32/win32compat/ssh-agent/agent-request.h +++ b/contrib/win32/win32compat/ssh-agent/agent-request.h @@ -11,6 +11,6 @@ typedef unsigned __int64 u_int64_t; #include "digest.h" -int process_add_identity(struct sshbuf*, struct sshbuf*, struct agent_connection*); -int process_request_identities(struct sshbuf*, struct sshbuf*, struct agent_connection*); -int process_sign_request(struct sshbuf*, struct sshbuf*, struct agent_connection*); \ No newline at end of file +int process_keyagent_request(struct sshbuf*, struct sshbuf*, struct agent_connection*); +int process_pubkeyagent_request(struct sshbuf*, struct sshbuf*, struct agent_connection*); +int process_authagent_request(struct sshbuf*, struct sshbuf*, struct agent_connection*); \ No newline at end of file diff --git a/contrib/win32/win32compat/ssh-agent/agent.c b/contrib/win32/win32compat/ssh-agent/agent.c index 4c00555..3cefc24 100644 --- a/contrib/win32/win32compat/ssh-agent/agent.c +++ b/contrib/win32/win32compat/ssh-agent/agent.c @@ -28,18 +28,19 @@ * (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 "agent.h" -#define AGENT_PIPE_ID L"\\\\.\\pipe\\ssh-agent" +#include "agent.h"s #define BUFSIZE 5 * 1024 static HANDLE ioc_port = NULL; static BOOL debug_mode = FALSE; -#define NUM_LISTENERS 1 -#define KEY_AGENT_PIPE_ID L"\\\\.\\pipe\\ssh-agent" +#define NUM_LISTENERS 3 +#define KEY_AGENT_PIPE_ID L"\\\\.\\pipe\\ssh-keyagent" +#define PUBKEY_AGENT_PIPE_ID L"\\\\.\\pipe\\ssh-pubkeyagent" +#define AUTH_AGENT_PIPE_ID L"\\\\.\\pipe\\ssh-authagent" -static wchar_t *pipe_ids[NUM_LISTENERS] = { KEY_AGENT_PIPE_ID }; -static enum agent_type types[NUM_LISTENERS] = { KEY_AGENT }; +static wchar_t *pipe_ids[NUM_LISTENERS] = { KEY_AGENT_PIPE_ID, PUBKEY_AGENT_PIPE_ID, AUTH_AGENT_PIPE_ID }; +static enum agent_type types[NUM_LISTENERS] = { KEY_AGENT, PUBKEY_AGENT, PUBKEY_AUTH_AGENT}; HANDLE event_stop_agent; struct listener { diff --git a/contrib/win32/win32compat/ssh-agent/authagent-request.c b/contrib/win32/win32compat/ssh-agent/authagent-request.c new file mode 100644 index 0000000..0afc853 --- /dev/null +++ b/contrib/win32/win32compat/ssh-agent/authagent-request.c @@ -0,0 +1,37 @@ +/* +* Author: Manoj Ampalam +* ssh-agent implementation on Windows +* +* Copyright (c) 2015 Microsoft Corp. +* All rights reserved +* +* Microsoft openssh win32 port +* +* 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 "agent.h" +#include "agent-request.h" + +int process_authagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) { + return -1; +} \ No newline at end of file diff --git a/contrib/win32/win32compat/ssh-agent/connection.c b/contrib/win32/win32compat/ssh-agent/connection.c index 2c07564..dbebe11 100644 --- a/contrib/win32/win32compat/ssh-agent/connection.c +++ b/contrib/win32/win32compat/ssh-agent/connection.c @@ -119,7 +119,6 @@ static int process_request(struct agent_connection* con) { int r; struct sshbuf *request = NULL, *response = NULL; - u_char type; request = sshbuf_from(con->io_buf.buf, con->io_buf.num_bytes); response = sshbuf_new(); @@ -128,23 +127,14 @@ process_request(struct agent_connection* con) { goto done; } - if ((r = sshbuf_get_u8(request, &type)) != 0) - goto done; - - switch (type) { - case SSH2_AGENTC_ADD_IDENTITY: - r = process_add_identity(request, response, con); - break; - case SSH2_AGENTC_REQUEST_IDENTITIES: - r = process_request_identities(request, response, con); - break; - case SSH2_AGENTC_SIGN_REQUEST: - r = process_sign_request(request, response, con); - break; - default: + if (con->type == KEY_AGENT) + r = process_keyagent_request(request, response, con); + else if (con->type == PUBKEY_AGENT) + r = process_pubkeyagent_request(request, response, con); + else if (con->type == PUBKEY_AUTH_AGENT) + r = process_authagent_request(request, response, con); + else r = EINVAL; - goto done; - } done: if (request) diff --git a/contrib/win32/win32compat/ssh-agent/agent-request.c b/contrib/win32/win32compat/ssh-agent/keyagent-request.c similarity index 95% rename from contrib/win32/win32compat/ssh-agent/agent-request.c rename to contrib/win32/win32compat/ssh-agent/keyagent-request.c index fa361ac..c96f206 100644 --- a/contrib/win32/win32compat/ssh-agent/agent-request.c +++ b/contrib/win32/win32compat/ssh-agent/keyagent-request.c @@ -380,4 +380,23 @@ done: if (sub) RegCloseKey(sub); return r; +} + + +int process_keyagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) { + int r; + u_char type; + + if ((r = sshbuf_get_u8(request, &type)) != 0) + return r; + switch (type) { + case SSH2_AGENTC_ADD_IDENTITY: + return process_add_identity(request, response, con); + case SSH2_AGENTC_REQUEST_IDENTITIES: + return process_request_identities(request, response, con); + case SSH2_AGENTC_SIGN_REQUEST: + return process_sign_request(request, response, con); + default: + return EINVAL; + } } \ No newline at end of file diff --git a/contrib/win32/win32compat/ssh-agent/pubkeyagent-request.c b/contrib/win32/win32compat/ssh-agent/pubkeyagent-request.c new file mode 100644 index 0000000..362b343 --- /dev/null +++ b/contrib/win32/win32compat/ssh-agent/pubkeyagent-request.c @@ -0,0 +1,37 @@ +/* +* Author: Manoj Ampalam +* ssh-agent implementation on Windows +* +* Copyright (c) 2015 Microsoft Corp. +* All rights reserved +* +* Microsoft openssh win32 port +* +* 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 "agent.h" +#include "agent-request.h" + +int process_pubkeyagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) { + return -1; +} \ No newline at end of file