Skip to content

Commit 495db5b

Browse files
authored
Fixes to ssh-agent issues
PowerShell/Win32-OpenSSH#1263 Issue: ssh-agent is using default sign algorithm, without considering related flags in request Fix: parse flags and consider sign algorithm input PowerShell/Win32-OpenSSH#1234 Issue: ssh-agent has old logic to lookup sshd account Fix: remove this redundant logic
1 parent c6fa13b commit 495db5b

File tree

3 files changed

+8
-43
lines changed

3 files changed

+8
-43
lines changed

contrib/win32/win32compat/ssh-agent/agent.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ con_type_to_string(struct agent_connection* con)
227227
return "restricted user";
228228
case ADMIN_USER:
229229
return "administrator";
230-
case SSHD_SERVICE:
231-
return "sshd service";
232230
case SYSTEM:
233231
return "system";
234232
case SERVICE:
@@ -243,7 +241,6 @@ get_con_client_info(struct agent_connection* con)
243241
{
244242
int r = -1;
245243
char sid[SECURITY_MAX_SID_SIZE];
246-
wchar_t *sshd_act = L"NT SERVICE\\SSHD", *ref_dom = NULL;
247244
ULONG client_pid;
248245
DWORD reg_dom_len = 0, info_len = 0, sid_size;
249246
DWORD sshd_sid_len = 0;
@@ -273,38 +270,6 @@ get_con_client_info(struct agent_connection* con)
273270
goto done;
274271
}
275272

276-
/* check if its SSHD service */
277-
{
278-
/* Does NT Service/SSHD exist */
279-
LookupAccountNameW(NULL, sshd_act, NULL, &sshd_sid_len, NULL, &reg_dom_len, &nuse);
280-
281-
if (GetLastError() == ERROR_NONE_MAPPED)
282-
debug3("Cannot look up SSHD account, its likely not installed");
283-
else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
284-
error("LookupAccountNameW on SSHD account failed with %d", GetLastError());
285-
goto done;
286-
}
287-
else {
288-
if ((sshd_sid = malloc(sshd_sid_len)) == NULL ||
289-
(ref_dom = (wchar_t*)malloc(reg_dom_len * 2)) == NULL ||
290-
LookupAccountNameW(NULL, sshd_act, sshd_sid, &sshd_sid_len, ref_dom, &reg_dom_len, &nuse) == FALSE)
291-
goto done;
292-
293-
if (EqualSid(info->User.Sid, sshd_sid)) {
294-
con->client_type = SSHD_SERVICE;
295-
r = 0;
296-
goto done;
297-
}
298-
if (CheckTokenMembership(client_impersonation_token, sshd_sid, &isMember) == FALSE)
299-
goto done;
300-
if (isMember) {
301-
con->client_type = SSHD_SERVICE;
302-
r = 0;
303-
goto done;
304-
}
305-
}
306-
}
307-
308273
/* check if its LS or NS */
309274
if (IsWellKnownSid(info->User.Sid, WinNetworkServiceSid) ||
310275
IsWellKnownSid(info->User.Sid, WinLocalServiceSid)) {
@@ -335,8 +300,6 @@ get_con_client_info(struct agent_connection* con)
335300

336301
if (sshd_sid)
337302
free(sshd_sid);
338-
if (ref_dom)
339-
free(ref_dom);
340303
if (info)
341304
free(info);
342305
if (client_primary_token)

contrib/win32/win32compat/ssh-agent/agent.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct agent_connection {
3333
UNKNOWN = 0,
3434
NONADMIN_USER, /* client is running as a nonadmin user */
3535
ADMIN_USER, /* client is running as admin */
36-
SSHD_SERVICE, /* client is sshd service */
3736
SYSTEM, /* client is running as System */
3837
SERVICE, /* client is running as LS or NS */
3938
} client_type;

contrib/win32/win32compat/ssh-agent/keyagent-request.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int sign_blob(const struct sshkey *pubkey, u_char ** sig, size_t *siglen,
204204
HKEY reg = 0, sub = 0, user_root = 0;
205205
int r = 0, success = 0;
206206
struct sshkey* prikey = NULL;
207-
char *thumbprint = NULL, *regdata = NULL;
207+
char *thumbprint = NULL, *regdata = NULL, *algo = NULL;
208208
DWORD regdatalen = 0, keyblob_len = 0;
209209
struct sshbuf* tmpbuf = NULL;
210210
char *keyblob = NULL;
@@ -225,8 +225,13 @@ static int sign_blob(const struct sshkey *pubkey, u_char ** sig, size_t *siglen,
225225
(tmpbuf = sshbuf_from(keyblob, keyblob_len)) == NULL)
226226
goto done;
227227

228+
if (flags & SSH_AGENT_RSA_SHA2_256)
229+
algo = "rsa-sha2-256";
230+
else if (flags & SSH_AGENT_RSA_SHA2_512)
231+
algo = "rsa-sha2-512";
232+
228233
if (sshkey_private_deserialize(tmpbuf, &prikey) != 0 ||
229-
sshkey_sign(prikey, sig, siglen, blob, blen, NULL, 0) != 0) {
234+
sshkey_sign(prikey, sig, siglen, blob, blen, algo, 0) != 0) {
230235
debug("cannot sign using retrieved key");
231236
goto done;
232237
}
@@ -272,9 +277,7 @@ process_sign_request(struct sshbuf* request, struct sshbuf* response, struct age
272277
goto done;
273278
}
274279

275-
/* TODO - flags?*/
276-
277-
if (sign_blob(key, &signature, &slen, data, dlen, 0, con) != 0)
280+
if (sign_blob(key, &signature, &slen, data, dlen, flags, con) != 0)
278281
goto done;
279282

280283
success = 1;

0 commit comments

Comments
 (0)