1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Refactor pageant_nth_ssh*_key.

I've merged the two previous functions, with different return types
per SSH version, into a single one that returns the containing
PageantKey instead of pulling out one of its internal fields.

This actually fixes a bug, though it would only have come up in the
Unix Pageant debugging mode: an encrypted-only key would have
terminated the key list in the diagnostic messages, because
pageant_nth_ssh2_key would have returned pk->skey which was NULL. Now
it returns pk itself, which isn't.
This commit is contained in:
Simon Tatham 2021-04-02 11:42:17 +01:00
parent 30c87c2896
commit e0bbe1e6c0

View File

@ -128,8 +128,7 @@ static bool gui_request_in_progress = false;
static void failure(PageantClient *pc, PageantClientRequestId *reqid, static void failure(PageantClient *pc, PageantClientRequestId *reqid,
strbuf *sb, unsigned char type, const char *fmt, ...); strbuf *sb, unsigned char type, const char *fmt, ...);
static void fail_requests_for_key(PageantKey *pk, const char *reason); static void fail_requests_for_key(PageantKey *pk, const char *reason);
static RSAKey *pageant_nth_ssh1_key(int i); static PageantKey *pageant_nth_key(int ssh_version, int i);
static ssh2_userkey *pageant_nth_ssh2_key(int i);
static void pk_free(PageantKey *pk) static void pk_free(PageantKey *pk)
{ {
@ -679,9 +678,9 @@ static PageantAsyncOp *pageant_make_op(
"reply: SSH1_AGENT_RSA_IDENTITIES_ANSWER"); "reply: SSH1_AGENT_RSA_IDENTITIES_ANSWER");
if (!pc->suppress_logging) { if (!pc->suppress_logging) {
int i; int i;
RSAKey *rkey; PageantKey *pk;
for (i = 0; NULL != (rkey = pageant_nth_ssh1_key(i)); i++) { for (i = 0; NULL != (pk = pageant_nth_key(1, i)); i++) {
char *fingerprint = rsa_ssh1_fingerprint(rkey); char *fingerprint = rsa_ssh1_fingerprint(pk->rkey);
pageant_client_log(pc, reqid, "returned key: %s", pageant_client_log(pc, reqid, "returned key: %s",
fingerprint); fingerprint);
sfree(fingerprint); sfree(fingerprint);
@ -702,12 +701,12 @@ static PageantAsyncOp *pageant_make_op(
pageant_client_log(pc, reqid, "reply: SSH2_AGENT_IDENTITIES_ANSWER"); pageant_client_log(pc, reqid, "reply: SSH2_AGENT_IDENTITIES_ANSWER");
if (!pc->suppress_logging) { if (!pc->suppress_logging) {
int i; int i;
ssh2_userkey *skey; PageantKey *pk;
for (i = 0; NULL != (skey = pageant_nth_ssh2_key(i)); i++) { for (i = 0; NULL != (pk = pageant_nth_key(2, i)); i++) {
char *fingerprint = ssh2_fingerprint( char *fingerprint = ssh2_fingerprint_blob(
skey->key, SSH_FPTYPE_DEFAULT); ptrlen_from_strbuf(pk->public_blob), SSH_FPTYPE_DEFAULT);
pageant_client_log(pc, reqid, "returned key: %s %s", pageant_client_log(pc, reqid, "returned key: %s %s",
fingerprint, skey->comment); fingerprint, pk->comment);
sfree(fingerprint); sfree(fingerprint);
} }
} }
@ -1323,12 +1322,13 @@ static PageantAsyncOp *pageant_make_op(
"reply: SSH2_AGENT_SUCCESS + key list"); "reply: SSH2_AGENT_SUCCESS + key list");
if (!pc->suppress_logging) { if (!pc->suppress_logging) {
int i; int i;
ssh2_userkey *skey; PageantKey *pk;
for (i = 0; NULL != (skey = pageant_nth_ssh2_key(i)); i++) { for (i = 0; NULL != (pk = pageant_nth_key(2, i)); i++) {
char *fingerprint = ssh2_fingerprint( char *fingerprint = ssh2_fingerprint_blob(
skey->key, SSH_FPTYPE_DEFAULT); ptrlen_from_strbuf(pk->public_blob),
SSH_FPTYPE_DEFAULT);
pageant_client_log(pc, reqid, "returned key: %s %s", pageant_client_log(pc, reqid, "returned key: %s %s",
fingerprint, skey->comment); fingerprint, pk->comment);
sfree(fingerprint); sfree(fingerprint);
} }
} }
@ -1372,20 +1372,12 @@ void pageant_init(void)
keytree = newtree234(cmpkeys); keytree = newtree234(cmpkeys);
} }
static RSAKey *pageant_nth_ssh1_key(int i) static PageantKey *pageant_nth_key(int ssh_version, int i)
{ {
PageantKey *pk = index234(keytree, find_first_key_for_version(1) + i); PageantKey *pk = index234(
if (pk && pk->sort.ssh_version == 1) keytree, find_first_key_for_version(ssh_version) + i);
return pk->rkey; if (pk && pk->sort.ssh_version == ssh_version)
else return pk;
return NULL;
}
static ssh2_userkey *pageant_nth_ssh2_key(int i)
{
PageantKey *pk = index234(keytree, find_first_key_for_version(2) + i);
if (pk && pk->sort.ssh_version == 2)
return pk->skey;
else else
return NULL; return NULL;
} }