mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-23 05:55:41 +02:00
Merging agent end points to a single one
This commit is contained in:
parent
87b27d8631
commit
45809a6bf7
@ -86,6 +86,7 @@ extern u_int session_id2_len;
|
|||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
|
|
||||||
extern char HomeDirLsaW[MAX_PATH];
|
extern char HomeDirLsaW[MAX_PATH];
|
||||||
|
extern int auth_sock;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -192,52 +193,24 @@ userauth_pubkey(Authctxt *authctxt)
|
|||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
{
|
{
|
||||||
#define SSH_AGENT_ROOT "SOFTWARE\\SSH\\Agent"
|
#define SSH_AGENT_ROOT "SOFTWARE\\SSH\\Agent"
|
||||||
HKEY agent_root = 0;
|
int r;
|
||||||
DWORD agent_pid = 0, tmp_size = 4, pipe_server_pid = 0xff;
|
|
||||||
int sock = -1, r;
|
|
||||||
u_char *blob = NULL;
|
u_char *blob = NULL;
|
||||||
size_t blen = 0;
|
size_t blen = 0;
|
||||||
DWORD token = 0;
|
DWORD token = 0;
|
||||||
HANDLE h = INVALID_HANDLE_VALUE;
|
|
||||||
struct sshbuf *msg = NULL;
|
struct sshbuf *msg = NULL;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE, SSH_AGENT_ROOT, 0, KEY_QUERY_VALUE, &agent_root);
|
|
||||||
if (agent_root)
|
|
||||||
RegQueryValueEx(agent_root, "ProcessId", 0, NULL, &agent_pid, &tmp_size);
|
|
||||||
|
|
||||||
|
|
||||||
h = CreateFile(
|
|
||||||
"\\\\.\\pipe\\ssh-authagent", // pipe name
|
|
||||||
GENERIC_READ | // read and write access
|
|
||||||
GENERIC_WRITE,
|
|
||||||
0, // no sharing
|
|
||||||
NULL, // default security attributes
|
|
||||||
OPEN_EXISTING, // opens existing pipe
|
|
||||||
FILE_FLAG_OVERLAPPED, // attributes
|
|
||||||
NULL); // no template file
|
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
|
||||||
debug("cannot connect to auth agent");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid)) {
|
|
||||||
debug("auth agent pid mismatch");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((sock = w32_allocate_fd_for_handle(h, FALSE)) < 0)
|
|
||||||
break;
|
|
||||||
msg = sshbuf_new();
|
msg = sshbuf_new();
|
||||||
if (!msg)
|
if (!msg)
|
||||||
break;
|
break;
|
||||||
if ((r = sshbuf_put_cstring(msg, "keyauthenticate")) != 0 ||
|
if ((r = sshbuf_put_u8(msg, 100)) != 0 ||
|
||||||
|
(r = sshbuf_put_cstring(msg, "pubkey")) != 0 ||
|
||||||
(r = sshkey_to_blob(key, &blob, &blen)) != 0 ||
|
(r = sshkey_to_blob(key, &blob, &blen)) != 0 ||
|
||||||
(r = sshbuf_put_string(msg, blob, blen)) != 0 ||
|
(r = sshbuf_put_string(msg, blob, blen)) != 0 ||
|
||||||
(r = sshbuf_put_cstring(msg, authctxt->pw->pw_name)) != 0 ||
|
(r = sshbuf_put_cstring(msg, authctxt->pw->pw_name)) != 0 ||
|
||||||
(r = sshbuf_put_string(msg, sig, slen)) != 0 ||
|
(r = sshbuf_put_string(msg, sig, slen)) != 0 ||
|
||||||
(r = sshbuf_put_string(msg, buffer_ptr(&b), buffer_len(&b))) != 0 ||
|
(r = sshbuf_put_string(msg, buffer_ptr(&b), buffer_len(&b))) != 0 ||
|
||||||
(r = ssh_request_reply(sock, msg, msg)) != 0 ||
|
(r = ssh_request_reply(auth_sock, msg, msg)) != 0 ||
|
||||||
(r = sshbuf_get_u32(msg, &token)) != 0) {
|
(r = sshbuf_get_u32(msg, &token)) != 0) {
|
||||||
debug("auth agent did not authorize client %s", authctxt->pw->pw_name);
|
debug("auth agent did not authorize client %s", authctxt->pw->pw_name);
|
||||||
break;
|
break;
|
||||||
@ -246,12 +219,8 @@ userauth_pubkey(Authctxt *authctxt)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (agent_root)
|
|
||||||
RegCloseKey(agent_root);
|
|
||||||
if (blob)
|
if (blob)
|
||||||
free(blob);
|
free(blob);
|
||||||
if (sock != -1)
|
|
||||||
close(sock);
|
|
||||||
if (msg)
|
if (msg)
|
||||||
sshbuf_free(msg);
|
sshbuf_free(msg);
|
||||||
|
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
#include "agent.h"
|
#include "agent.h"
|
||||||
|
|
||||||
|
|
||||||
int scm_start_servie(DWORD, LPWSTR*);
|
int scm_start_service(DWORD, LPWSTR*);
|
||||||
|
|
||||||
SERVICE_TABLE_ENTRYW dispatch_table[] =
|
SERVICE_TABLE_ENTRYW dispatch_table[] =
|
||||||
{
|
{
|
||||||
{ L"ssh-agent", (LPSERVICE_MAIN_FUNCTIONW)scm_start_servie },
|
{ L"ssh-agent", (LPSERVICE_MAIN_FUNCTIONW)scm_start_service },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
static SERVICE_STATUS_HANDLE service_status_handle;
|
static SERVICE_STATUS_HANDLE service_status_handle;
|
||||||
@ -141,7 +141,7 @@ int main(int argc, char **argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int scm_start_servie(DWORD num, LPWSTR* args) {
|
int scm_start_service(DWORD num, LPWSTR* args) {
|
||||||
service_status_handle = RegisterServiceCtrlHandlerW(L"ssh-agent", service_handler);
|
service_status_handle = RegisterServiceCtrlHandlerW(L"ssh-agent", service_handler);
|
||||||
ZeroMemory(&service_status, sizeof(service_status));
|
ZeroMemory(&service_status, sizeof(service_status));
|
||||||
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||||
|
@ -51,6 +51,7 @@ Buffer cfg;
|
|||||||
ServerOptions options;
|
ServerOptions options;
|
||||||
struct passwd *privsep_pw = NULL;
|
struct passwd *privsep_pw = NULL;
|
||||||
static char *config_file_name = _PATH_SERVER_CONFIG_FILE;
|
static char *config_file_name = _PATH_SERVER_CONFIG_FILE;
|
||||||
|
int auth_sock = -1;
|
||||||
|
|
||||||
int auth2_methods_valid(const char * c, int i) {
|
int auth2_methods_valid(const char * c, int i) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -167,13 +167,13 @@ done:
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AUTH_REQUEST "keyauthenticate"
|
#define AUTH_REQUEST "pubkey"
|
||||||
#define MAX_USER_NAME_LEN 256
|
#define MAX_USER_NAME_LEN 256
|
||||||
|
|
||||||
int process_authagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) {
|
int process_pubkeyauth_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) {
|
||||||
int r = -1;
|
int r = -1;
|
||||||
char *opn, *key_blob, *user, *sig, *blob;
|
char *key_blob, *user, *sig, *blob;
|
||||||
size_t opn_len, key_blob_len, user_len, sig_len, blob_len;
|
size_t key_blob_len, user_len, sig_len, blob_len;
|
||||||
struct sshkey *key = NULL;
|
struct sshkey *key = NULL;
|
||||||
HANDLE token = NULL, dup_token = NULL, client_proc = NULL;
|
HANDLE token = NULL, dup_token = NULL, client_proc = NULL;
|
||||||
wchar_t wuser[MAX_USER_NAME_LEN];
|
wchar_t wuser[MAX_USER_NAME_LEN];
|
||||||
@ -181,15 +181,12 @@ int process_authagent_request(struct sshbuf* request, struct sshbuf* response, s
|
|||||||
ULONG client_pid;
|
ULONG client_pid;
|
||||||
|
|
||||||
user = NULL;
|
user = NULL;
|
||||||
if (sshbuf_get_string_direct(request, &opn, &opn_len) != 0 ||
|
if (sshbuf_get_string_direct(request, &key_blob, &key_blob_len) != 0 ||
|
||||||
sshbuf_get_string_direct(request, &key_blob, &key_blob_len) != 0 ||
|
|
||||||
sshbuf_get_cstring(request, &user, &user_len) != 0 ||
|
sshbuf_get_cstring(request, &user, &user_len) != 0 ||
|
||||||
sshbuf_get_string_direct(request, &sig, &sig_len) != 0 ||
|
sshbuf_get_string_direct(request, &sig, &sig_len) != 0 ||
|
||||||
sshbuf_get_string_direct(request, &blob, &blob_len) != 0 ||
|
sshbuf_get_string_direct(request, &blob, &blob_len) != 0 ||
|
||||||
sshkey_from_blob(key_blob, key_blob_len, &key) != 0 ||
|
sshkey_from_blob(key_blob, key_blob_len, &key) != 0) {
|
||||||
opn_len != strlen(AUTH_REQUEST) ||
|
debug("invalid pubkey auth request");
|
||||||
memcmp(opn, AUTH_REQUEST, opn_len) != 0) {
|
|
||||||
debug("auth agent invalid request");
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,4 +228,21 @@ done:
|
|||||||
if (client_proc)
|
if (client_proc)
|
||||||
CloseHandle(client_proc);
|
CloseHandle(client_proc);
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int process_authagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) {
|
||||||
|
char *opn;
|
||||||
|
size_t opn_len;
|
||||||
|
if (sshbuf_get_string_direct(request, &opn, &opn_len) != 0) {
|
||||||
|
debug("invalid auth request");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opn_len == strlen(AUTH_REQUEST) && memcmp(opn, AUTH_REQUEST, opn_len) == 0)
|
||||||
|
return process_pubkeyauth_request(request, response, con);
|
||||||
|
else {
|
||||||
|
debug("unknown auth request: %s", opn);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -46,7 +46,7 @@ void agent_connection_on_error(struct agent_connection* con, DWORD error) {
|
|||||||
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 */
|
||||||
debug("connection io %p #bytes:%d state:%d", con, bytes, con->state);
|
debug3("connection io %p #bytes:%d state:%d", con, bytes, con->state);
|
||||||
if ((bytes == 0) && (GetOverlappedResult(con->connection, ol, &bytes, FALSE) == FALSE))
|
if ((bytes == 0) && (GetOverlappedResult(con->connection, ol, &bytes, FALSE) == FALSE))
|
||||||
ABORT_CONNECTION_RETURN(con);
|
ABORT_CONNECTION_RETURN(con);
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ get_con_client_type(HANDLE pipe) {
|
|||||||
else
|
else
|
||||||
r = OTHER;
|
r = OTHER;
|
||||||
|
|
||||||
debug("client type: %d", r);
|
debug2("client type: %d", r);
|
||||||
done:
|
done:
|
||||||
if (sshd_sid)
|
if (sshd_sid)
|
||||||
free(sshd_sid);
|
free(sshd_sid);
|
||||||
@ -167,6 +167,7 @@ done:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SSH_AGENT_AUTHENTICATE 100
|
||||||
|
|
||||||
static int
|
static int
|
||||||
process_request(struct agent_connection* con) {
|
process_request(struct agent_connection* con) {
|
||||||
@ -188,24 +189,31 @@ process_request(struct agent_connection* con) {
|
|||||||
|
|
||||||
if (sshbuf_get_u8(request, &type) != 0)
|
if (sshbuf_get_u8(request, &type) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
debug2("process key agent request type %d", type);
|
debug("process agent request type %d", type);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SSH2_AGENTC_ADD_IDENTITY:
|
case SSH2_AGENTC_ADD_IDENTITY:
|
||||||
return process_add_identity(request, response, con);
|
r = process_add_identity(request, response, con);
|
||||||
|
break;
|
||||||
case SSH2_AGENTC_REQUEST_IDENTITIES:
|
case SSH2_AGENTC_REQUEST_IDENTITIES:
|
||||||
return process_request_identities(request, response, con);
|
r = process_request_identities(request, response, con);
|
||||||
|
break;
|
||||||
case SSH2_AGENTC_SIGN_REQUEST:
|
case SSH2_AGENTC_SIGN_REQUEST:
|
||||||
return process_sign_request(request, response, con);
|
r = process_sign_request(request, response, con);
|
||||||
|
break;
|
||||||
case SSH2_AGENTC_REMOVE_IDENTITY:
|
case SSH2_AGENTC_REMOVE_IDENTITY:
|
||||||
return process_remove_key(request, response, con);
|
r = process_remove_key(request, response, con);
|
||||||
|
break;
|
||||||
case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
|
case SSH2_AGENTC_REMOVE_ALL_IDENTITIES:
|
||||||
return process_remove_all(request, response, con);
|
r = process_remove_all(request, response, con);
|
||||||
case 100:
|
break;
|
||||||
return process_authagent_request(request, response, con);
|
case SSH_AGENT_AUTHENTICATE:
|
||||||
|
r = process_authagent_request(request, response, con);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
debug("unknown agent request %d", type);
|
debug("unknown agent request %d", type);
|
||||||
return -1;
|
r = -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user