mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-26 07:25:25 +02:00
4-16 V1
This commit is contained in:
parent
8f247d5c00
commit
54deeb7911
@ -23,8 +23,10 @@
|
|||||||
<ClCompile Include="..\win32compat\ssh-agent\agent-main.c" />
|
<ClCompile Include="..\win32compat\ssh-agent\agent-main.c" />
|
||||||
<ClCompile Include="..\win32compat\ssh-agent\agent.c" />
|
<ClCompile Include="..\win32compat\ssh-agent\agent.c" />
|
||||||
<ClCompile Include="..\win32compat\ssh-agent\connection.c" />
|
<ClCompile Include="..\win32compat\ssh-agent\connection.c" />
|
||||||
|
<ClCompile Include="..\win32compat\ssh-agent\agent-request.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\win32compat\ssh-agent\agent-request.h" />
|
||||||
<ClInclude Include="..\win32compat\ssh-agent\agent.h" />
|
<ClInclude Include="..\win32compat\ssh-agent\agent.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
@ -107,8 +109,7 @@
|
|||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>_WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>false</SDLCheck>
|
<SDLCheck>false</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(OpenSSH-Src-Path);$(OpenSSL-Win32-Debug-Path)include</AdditionalIncludeDirectories>
|
||||||
</AdditionalIncludeDirectories>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -127,8 +128,7 @@
|
|||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>_WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>false</SDLCheck>
|
<SDLCheck>false</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(OpenSSH-Src-Path);$(OpenSSL-x64-Debug-Path)include</AdditionalIncludeDirectories>
|
||||||
</AdditionalIncludeDirectories>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -149,8 +149,7 @@
|
|||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>_WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>false</SDLCheck>
|
<SDLCheck>false</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(OpenSSH-Src-Path);$(OpenSSL-Win32-Release-Path)include</AdditionalIncludeDirectories>
|
||||||
</AdditionalIncludeDirectories>
|
|
||||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@ -172,8 +171,7 @@
|
|||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>_WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>false</SDLCheck>
|
<SDLCheck>false</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(OpenSSH-Src-Path);$(OpenSSL-64-Release-Path)include</AdditionalIncludeDirectories>
|
||||||
</AdditionalIncludeDirectories>
|
|
||||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
|
38
contrib/win32/win32compat/ssh-agent/agent-request.c
Normal file
38
contrib/win32/win32compat/ssh-agent/agent-request.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
|
||||||
|
* 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-request.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
process_add_identity(struct sshbuf* request, struct sshbuf* response, HANDLE client) {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
13
contrib/win32/win32compat/ssh-agent/agent-request.h
Normal file
13
contrib/win32/win32compat/ssh-agent/agent-request.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <Windows.h>
|
||||||
|
typedef unsigned char u_int8_t;
|
||||||
|
typedef unsigned short u_int16_t;
|
||||||
|
typedef unsigned int u_int32_t;
|
||||||
|
typedef unsigned __int64 u_int64_t;
|
||||||
|
#define __attribute__(a)
|
||||||
|
#include "rsa.h"
|
||||||
|
#include "sshbuf.h"
|
||||||
|
#include "sshkey.h"
|
||||||
|
#include "authfd.h"
|
||||||
|
|
||||||
|
|
||||||
|
int process_add_identity(struct sshbuf*, struct sshbuf*, HANDLE);
|
@ -1,16 +1,18 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define BUFSIZE 5 * 1024
|
#define MAX_MESSAGE_SIZE 5 * 1024
|
||||||
|
|
||||||
#define HEADER_SIZE 4
|
#define HEADER_SIZE 4
|
||||||
struct agent_connection {
|
struct agent_connection {
|
||||||
OVERLAPPED ol;
|
OVERLAPPED ol;
|
||||||
HANDLE connection;
|
HANDLE connection;
|
||||||
|
HANDLE client_token;
|
||||||
struct {
|
struct {
|
||||||
DWORD size;
|
DWORD num_bytes;
|
||||||
DWORD read;
|
DWORD transferred;
|
||||||
char buf[BUFSIZE];
|
char buf[MAX_MESSAGE_SIZE];
|
||||||
} request;
|
DWORD buf_size;
|
||||||
|
} io_buf;
|
||||||
enum {
|
enum {
|
||||||
LISTENING = 0,
|
LISTENING = 0,
|
||||||
READING_HEADER,
|
READING_HEADER,
|
||||||
|
@ -29,20 +29,25 @@
|
|||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include "agent.h"
|
#include "agent.h"
|
||||||
|
#include "agent-request.h"
|
||||||
|
|
||||||
|
void process_request(struct agent_connection*);
|
||||||
|
|
||||||
|
#define ABORT_CONNECTION_RETURN(c) do { \
|
||||||
|
con->state = DONE; \
|
||||||
|
agent_cleanup_connection(con); \
|
||||||
|
return; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
void agent_connection_on_error(struct agent_connection* con, DWORD error) {
|
void agent_connection_on_error(struct agent_connection* con, DWORD error) {
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(con);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPED* ol) {
|
void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPED* ol) {
|
||||||
|
|
||||||
/* process error */
|
/* process error */
|
||||||
if ( (bytes == 0) && (GetOverlappedResult(con->connection, ol, &bytes, FALSE) == FALSE)) {
|
if ((bytes == 0) && (GetOverlappedResult(con->connection, ol, &bytes, FALSE) == FALSE))
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(c);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (con->state == DONE)
|
if (con->state == DONE)
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
@ -54,56 +59,47 @@ void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPE
|
|||||||
agent_listen();
|
agent_listen();
|
||||||
case WRITING:
|
case WRITING:
|
||||||
/* Writing is done, read next request */
|
/* Writing is done, read next request */
|
||||||
|
/* assert on assumption that write always completes on sending all bytes*/
|
||||||
|
if (bytes != con->io_buf.num_bytes)
|
||||||
|
DebugBreak();
|
||||||
con->state = READING_HEADER;
|
con->state = READING_HEADER;
|
||||||
ZeroMemory(&con->request, sizeof(con->request));
|
ZeroMemory(&con->io_buf, sizeof(con->io_buf));
|
||||||
if (!ReadFile(con->connection, con->request.buf,
|
if (!ReadFile(con->connection, con->io_buf.buf,
|
||||||
HEADER_SIZE, NULL, &con->ol) && (GetLastError() != ERROR_IO_PENDING)) {
|
HEADER_SIZE, NULL, &con->ol) && (GetLastError() != ERROR_IO_PENDING))
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(c);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case READING_HEADER:
|
case READING_HEADER:
|
||||||
con->request.read += bytes;
|
con->io_buf.transferred += bytes;
|
||||||
if (con->request.read == HEADER_SIZE) {
|
if (con->io_buf.transferred == HEADER_SIZE) {
|
||||||
con->request.size = *((DWORD*)con->request.buf);
|
con->io_buf.num_bytes = PEEK_U32(con->io_buf.buf);
|
||||||
con->request.read = 0;
|
con->io_buf.transferred = 0;
|
||||||
|
if (con->io_buf.num_bytes > MAX_MESSAGE_SIZE)
|
||||||
|
ABORT_CONNECTION_RETURN(c);
|
||||||
|
|
||||||
con->state = READING;
|
con->state = READING;
|
||||||
if (!ReadFile(con->connection, con->request.buf,
|
if (!ReadFile(con->connection, con->io_buf.buf,
|
||||||
con->request.size, NULL, &con->ol)&&(GetLastError() != ERROR_IO_PENDING)) {
|
con->io_buf.num_bytes, NULL, &con->ol)&&(GetLastError() != ERROR_IO_PENDING))
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(c);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!ReadFile(con->connection, con->request.buf + con->request.read,
|
if (!ReadFile(con->connection, con->io_buf.buf + con->io_buf.num_bytes,
|
||||||
HEADER_SIZE - con->request.read, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING)) {
|
HEADER_SIZE - con->io_buf.num_bytes, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING))
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(c);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case READING:
|
case READING:
|
||||||
con->request.read += bytes;
|
con->io_buf.transferred += bytes;
|
||||||
if (con->request.read == con->request.size) {
|
if (con->io_buf.transferred == con->io_buf.num_bytes) {
|
||||||
/* process request and get response */
|
process_request(con);
|
||||||
con->state = WRITING;
|
con->state = WRITING;
|
||||||
if (!WriteFile(con->connection, con->request.buf,
|
if (!WriteFile(con->connection, con->io_buf.buf,
|
||||||
con->request.size, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING) ){
|
con->io_buf.num_bytes, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING) )
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(c);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!ReadFile(con->connection, con->request.buf + con->request.read,
|
if (!ReadFile(con->connection, con->io_buf.buf + con->io_buf.transferred,
|
||||||
con->request.size - con->request.read, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING)) {
|
con->io_buf.num_bytes - con->io_buf.transferred, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING))
|
||||||
con->state = DONE;
|
ABORT_CONNECTION_RETURN(c);
|
||||||
agent_cleanup_connection(con);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -116,3 +112,48 @@ void agent_connection_disconnect(struct agent_connection* con) {
|
|||||||
CancelIoEx(con->connection, NULL);
|
CancelIoEx(con->connection, NULL);
|
||||||
DisconnectNamedPipe(con->connection);
|
DisconnectNamedPipe(con->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
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();
|
||||||
|
if ((request == NULL) || (response == NULL)) {
|
||||||
|
r = ENOMEM;
|
||||||
|
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->client_token);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
r = EINVAL;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (request)
|
||||||
|
sshbuf_free(request);
|
||||||
|
|
||||||
|
ZeroMemory(&con->io_buf, sizeof(con->io_buf));
|
||||||
|
if (r == 0) {
|
||||||
|
POKE_U32(con->io_buf.buf, sshbuf_len(response));
|
||||||
|
memcpy(con->io_buf.buf + 4, sshbuf_ptr(response), sshbuf_len(response));
|
||||||
|
con->io_buf.num_bytes = sshbuf_len(response) + 4;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
POKE_U32(con->io_buf.buf, 1);
|
||||||
|
*(con->io_buf.buf + 4) = SSH_AGENT_FAILURE;
|
||||||
|
con->io_buf.num_bytes = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response)
|
||||||
|
sshbuf_free(response);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user