mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
Pageant: reindent the main handler function.
Somehow it had acquired a lot of internal 2-space indentation, which is out of step with the rest of this code base's style. Before I get into making more changes in here, let's clean it up.
This commit is contained in:
parent
e617a5b768
commit
78e006b60b
424
pageant.c
424
pageant.c
@ -655,14 +655,14 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid,
|
||||||
"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;
|
RSAKey *rkey;
|
||||||
for (i = 0; NULL != (rkey = pageant_nth_ssh1_key(i)); i++) {
|
for (i = 0; NULL != (rkey = pageant_nth_ssh1_key(i)); i++) {
|
||||||
char *fingerprint = rsa_ssh1_fingerprint(rkey);
|
char *fingerprint = rsa_ssh1_fingerprint(rkey);
|
||||||
pageant_client_log(pc, reqid, "returned key: %s",
|
pageant_client_log(pc, reqid, "returned key: %s",
|
||||||
fingerprint);
|
fingerprint);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -676,17 +676,16 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
put_byte(sb, SSH2_AGENT_IDENTITIES_ANSWER);
|
put_byte(sb, SSH2_AGENT_IDENTITIES_ANSWER);
|
||||||
pageant_make_keylist2(BinarySink_UPCAST(sb));
|
pageant_make_keylist2(BinarySink_UPCAST(sb));
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "reply: SSH2_AGENT_IDENTITIES_ANSWER");
|
||||||
"reply: SSH2_AGENT_IDENTITIES_ANSWER");
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
int i;
|
int i;
|
||||||
ssh2_userkey *skey;
|
ssh2_userkey *skey;
|
||||||
for (i = 0; NULL != (skey = pageant_nth_ssh2_key(i)); i++) {
|
for (i = 0; NULL != (skey = pageant_nth_ssh2_key(i)); i++) {
|
||||||
char *fingerprint = ssh2_fingerprint(skey->key);
|
char *fingerprint = ssh2_fingerprint(skey->key);
|
||||||
pageant_client_log(pc, reqid, "returned key: %s %s",
|
pageant_client_log(pc, reqid, "returned key: %s %s",
|
||||||
fingerprint, skey->comment);
|
fingerprint, skey->comment);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -704,8 +703,7 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
unsigned char response_md5[16];
|
unsigned char response_md5[16];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "request: SSH1_AGENTC_RSA_CHALLENGE");
|
||||||
"request: SSH1_AGENTC_RSA_CHALLENGE");
|
|
||||||
|
|
||||||
response = NULL;
|
response = NULL;
|
||||||
memset(&reqkey, 0, sizeof(reqkey));
|
memset(&reqkey, 0, sizeof(reqkey));
|
||||||
@ -716,35 +714,34 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
response_type = get_uint32(msg);
|
response_type = get_uint32(msg);
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto challenge1_cleanup;
|
goto challenge1_cleanup;
|
||||||
}
|
}
|
||||||
if (response_type != 1) {
|
if (response_type != 1) {
|
||||||
fail("response type other than 1 not supported");
|
fail("response type other than 1 not supported");
|
||||||
goto challenge1_cleanup;
|
goto challenge1_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint;
|
char *fingerprint;
|
||||||
reqkey.comment = NULL;
|
reqkey.comment = NULL;
|
||||||
fingerprint = rsa_ssh1_fingerprint(&reqkey);
|
fingerprint = rsa_ssh1_fingerprint(&reqkey);
|
||||||
pageant_client_log(pc, reqid, "requested key: %s",
|
pageant_client_log(pc, reqid, "requested key: %s", fingerprint);
|
||||||
fingerprint);
|
sfree(fingerprint);
|
||||||
sfree(fingerprint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pk = findkey1(&reqkey)) == NULL) {
|
if ((pk = findkey1(&reqkey)) == NULL) {
|
||||||
fail("key not found");
|
fail("key not found");
|
||||||
goto challenge1_cleanup;
|
goto challenge1_cleanup;
|
||||||
}
|
}
|
||||||
response = rsa_ssh1_decrypt(challenge, pk->rkey);
|
response = rsa_ssh1_decrypt(challenge, pk->rkey);
|
||||||
|
|
||||||
{
|
{
|
||||||
ssh_hash *h = ssh_hash_new(&ssh_md5);
|
ssh_hash *h = ssh_hash_new(&ssh_md5);
|
||||||
for (i = 0; i < 32; i++)
|
for (i = 0; i < 32; i++)
|
||||||
put_byte(h, mp_get_byte(response, 31 - i));
|
put_byte(h, mp_get_byte(response, 31 - i));
|
||||||
put_datapl(h, session_id);
|
put_datapl(h, session_id);
|
||||||
ssh_hash_final(h, response_md5);
|
ssh_hash_final(h, response_md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
put_byte(sb, SSH1_AGENT_RSA_RESPONSE);
|
put_byte(sb, SSH1_AGENT_RSA_RESPONSE);
|
||||||
@ -752,7 +749,7 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
|
|
||||||
pageant_client_log(pc, reqid, "reply: SSH1_AGENT_RSA_RESPONSE");
|
pageant_client_log(pc, reqid, "reply: SSH1_AGENT_RSA_RESPONSE");
|
||||||
|
|
||||||
challenge1_cleanup:
|
challenge1_cleanup:
|
||||||
if (response)
|
if (response)
|
||||||
mp_free(response);
|
mp_free(response);
|
||||||
mp_free(challenge);
|
mp_free(challenge);
|
||||||
@ -775,8 +772,8 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
sigdata = get_string(msg);
|
sigdata = get_string(msg);
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -793,14 +790,13 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
have_flags = true;
|
have_flags = true;
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint = ssh2_fingerprint_blob(keyblob);
|
char *fingerprint = ssh2_fingerprint_blob(keyblob);
|
||||||
pageant_client_log(pc, reqid, "requested key: %s",
|
pageant_client_log(pc, reqid, "requested key: %s", fingerprint);
|
||||||
fingerprint);
|
sfree(fingerprint);
|
||||||
sfree(fingerprint);
|
|
||||||
}
|
}
|
||||||
if ((pk = findkey2(keyblob)) == NULL) {
|
if ((pk = findkey2(keyblob)) == NULL) {
|
||||||
fail("key not found");
|
fail("key not found");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (have_flags)
|
if (have_flags)
|
||||||
@ -834,42 +830,41 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
*/
|
*/
|
||||||
RSAKey *key;
|
RSAKey *key;
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "request: SSH1_AGENTC_ADD_RSA_IDENTITY");
|
||||||
"request: SSH1_AGENTC_ADD_RSA_IDENTITY");
|
|
||||||
|
|
||||||
key = get_rsa_ssh1_priv_agent(msg);
|
key = get_rsa_ssh1_priv_agent(msg);
|
||||||
key->comment = mkstr(get_string(msg));
|
key->comment = mkstr(get_string(msg));
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto add1_cleanup;
|
goto add1_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rsa_verify(key)) {
|
if (!rsa_verify(key)) {
|
||||||
fail("key is invalid");
|
fail("key is invalid");
|
||||||
goto add1_cleanup;
|
goto add1_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint = rsa_ssh1_fingerprint(key);
|
char *fingerprint = rsa_ssh1_fingerprint(key);
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid,
|
||||||
"submitted key: %s", fingerprint);
|
"submitted key: %s", fingerprint);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageant_add_ssh1_key(key)) {
|
if (pageant_add_ssh1_key(key)) {
|
||||||
keylist_update();
|
keylist_update();
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS");
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS");
|
||||||
key = NULL; /* don't free it in cleanup */
|
key = NULL; /* don't free it in cleanup */
|
||||||
} else {
|
} else {
|
||||||
fail("key already present");
|
fail("key already present");
|
||||||
}
|
}
|
||||||
|
|
||||||
add1_cleanup:
|
add1_cleanup:
|
||||||
if (key) {
|
if (key) {
|
||||||
freersakey(key);
|
freersakey(key);
|
||||||
sfree(key);
|
sfree(key);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -891,49 +886,49 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
key->comment = NULL;
|
key->comment = NULL;
|
||||||
alg = find_pubkey_alg_len(algpl);
|
alg = find_pubkey_alg_len(algpl);
|
||||||
if (!alg) {
|
if (!alg) {
|
||||||
fail("algorithm unknown");
|
fail("algorithm unknown");
|
||||||
goto add2_cleanup;
|
goto add2_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
key->key = ssh_key_new_priv_openssh(alg, msg);
|
key->key = ssh_key_new_priv_openssh(alg, msg);
|
||||||
|
|
||||||
if (!key->key) {
|
if (!key->key) {
|
||||||
fail("key setup failed");
|
fail("key setup failed");
|
||||||
goto add2_cleanup;
|
goto add2_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
key->comment = mkstr(get_string(msg));
|
key->comment = mkstr(get_string(msg));
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto add2_cleanup;
|
goto add2_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint = ssh2_fingerprint(key->key);
|
char *fingerprint = ssh2_fingerprint(key->key);
|
||||||
pageant_client_log(pc, reqid, "submitted key: %s %s",
|
pageant_client_log(pc, reqid, "submitted key: %s %s",
|
||||||
fingerprint, key->comment);
|
fingerprint, key->comment);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageant_add_ssh2_key(key)) {
|
if (pageant_add_ssh2_key(key)) {
|
||||||
keylist_update();
|
keylist_update();
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
|
|
||||||
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS");
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS");
|
||||||
|
|
||||||
key = NULL; /* don't clean it up */
|
key = NULL; /* don't clean it up */
|
||||||
} else {
|
} else {
|
||||||
fail("key already present");
|
fail("key already present");
|
||||||
}
|
}
|
||||||
|
|
||||||
add2_cleanup:
|
add2_cleanup:
|
||||||
if (key) {
|
if (key) {
|
||||||
if (key->key)
|
if (key->key)
|
||||||
ssh_key_free(key->key);
|
ssh_key_free(key->key);
|
||||||
if (key->comment)
|
if (key->comment)
|
||||||
sfree(key->comment);
|
sfree(key->comment);
|
||||||
sfree(key);
|
sfree(key);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -953,33 +948,33 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
get_rsa_ssh1_pub(msg, &reqkey, RSA_SSH1_EXPONENT_FIRST);
|
get_rsa_ssh1_pub(msg, &reqkey, RSA_SSH1_EXPONENT_FIRST);
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
freersakey(&reqkey);
|
freersakey(&reqkey);
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint;
|
char *fingerprint;
|
||||||
reqkey.comment = NULL;
|
reqkey.comment = NULL;
|
||||||
fingerprint = rsa_ssh1_fingerprint(&reqkey);
|
fingerprint = rsa_ssh1_fingerprint(&reqkey);
|
||||||
pageant_client_log(pc, reqid, "unwanted key: %s", fingerprint);
|
pageant_client_log(pc, reqid, "unwanted key: %s", fingerprint);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
pk = findkey1(&reqkey);
|
pk = findkey1(&reqkey);
|
||||||
freersakey(&reqkey);
|
freersakey(&reqkey);
|
||||||
if (pk) {
|
if (pk) {
|
||||||
pageant_client_log(pc, reqid, "found with comment: %s",
|
pageant_client_log(pc, reqid, "found with comment: %s",
|
||||||
pk->rkey->comment);
|
pk->rkey->comment);
|
||||||
|
|
||||||
del234(keytree, pk);
|
del234(keytree, pk);
|
||||||
keylist_update();
|
keylist_update();
|
||||||
pk_free(pk);
|
pk_free(pk);
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
|
|
||||||
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS");
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS");
|
||||||
} else {
|
} else {
|
||||||
fail("key not found");
|
fail("key not found");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -992,30 +987,28 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
PageantKey *pk;
|
PageantKey *pk;
|
||||||
ptrlen blob;
|
ptrlen blob;
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "request: SSH2_AGENTC_REMOVE_IDENTITY");
|
||||||
"request: SSH2_AGENTC_REMOVE_IDENTITY");
|
|
||||||
|
|
||||||
blob = get_string(msg);
|
blob = get_string(msg);
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint = ssh2_fingerprint_blob(blob);
|
char *fingerprint = ssh2_fingerprint_blob(blob);
|
||||||
pageant_client_log(pc, reqid, "unwanted key: %s", fingerprint);
|
pageant_client_log(pc, reqid, "unwanted key: %s", fingerprint);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
pk = findkey2(blob);
|
pk = findkey2(blob);
|
||||||
if (!pk) {
|
if (!pk) {
|
||||||
fail("key not found");
|
fail("key not found");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "found with comment: %s", pk->comment);
|
||||||
"found with comment: %s", pk->comment);
|
|
||||||
|
|
||||||
del234(keytree, pk);
|
del234(keytree, pk);
|
||||||
keylist_update();
|
keylist_update();
|
||||||
@ -1029,8 +1022,8 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
/*
|
/*
|
||||||
* Remove all SSH-1 keys. Always returns success.
|
* Remove all SSH-1 keys. Always returns success.
|
||||||
*/
|
*/
|
||||||
pageant_client_log(pc, reqid, "request:"
|
pageant_client_log(pc, reqid,
|
||||||
" SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES");
|
"request: SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES");
|
||||||
|
|
||||||
remove_all_keys(1);
|
remove_all_keys(1);
|
||||||
keylist_update();
|
keylist_update();
|
||||||
@ -1064,20 +1057,20 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
|
|
||||||
for (size_t i = 0; i < lenof(extension_names); i++)
|
for (size_t i = 0; i < lenof(extension_names); i++)
|
||||||
if (ptrlen_eq_ptrlen(extname, extension_names[i])) {
|
if (ptrlen_eq_ptrlen(extname, extension_names[i])) {
|
||||||
exttype = i;
|
exttype = i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For SSH_AGENTC_EXTENSION requests, the message
|
* For SSH_AGENTC_EXTENSION requests, the message
|
||||||
* code SSH_AGENT_FAILURE is reserved for "I don't
|
* code SSH_AGENT_FAILURE is reserved for "I don't
|
||||||
* recognise this extension name at all". For any
|
* recognise this extension name at all". For any
|
||||||
* other kind of failure while processing an
|
* other kind of failure while processing an
|
||||||
* extension we _do_ recognise, we must switch to
|
* extension we _do_ recognise, we must switch to
|
||||||
* returning a different failure code, with
|
* returning a different failure code, with
|
||||||
* semantics "I understood the extension name, but
|
* semantics "I understood the extension name, but
|
||||||
* something else went wrong".
|
* something else went wrong".
|
||||||
*/
|
*/
|
||||||
failure_type = SSH_AGENT_EXTENSION_FAILURE;
|
failure_type = SSH_AGENT_EXTENSION_FAILURE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (exttype) {
|
switch (exttype) {
|
||||||
@ -1091,16 +1084,15 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
for (size_t i = 0; i < lenof(extension_names); i++)
|
for (size_t i = 0; i < lenof(extension_names); i++)
|
||||||
put_stringpl(sb, extension_names[i]);
|
put_stringpl(sb, extension_names[i]);
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS + names");
|
||||||
"reply: SSH_AGENT_SUCCESS + names");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXT_ADD_PPK: {
|
case EXT_ADD_PPK: {
|
||||||
ptrlen keyfile = get_string(msg);
|
ptrlen keyfile = get_string(msg);
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
BinarySource src[1];
|
BinarySource src[1];
|
||||||
@ -1110,47 +1102,45 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
char *comment;
|
char *comment;
|
||||||
|
|
||||||
BinarySource_BARE_INIT_PL(src, keyfile);
|
BinarySource_BARE_INIT_PL(src, keyfile);
|
||||||
if (!ppk_loadpub_s(src, NULL,
|
if (!ppk_loadpub_s(src, NULL, BinarySink_UPCAST(public_blob),
|
||||||
BinarySink_UPCAST(public_blob),
|
|
||||||
&comment, &error)) {
|
&comment, &error)) {
|
||||||
fail("failed to extract public key blob: %s", error);
|
fail("failed to extract public key blob: %s", error);
|
||||||
goto add_ppk_cleanup;
|
goto add_ppk_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint = ssh2_fingerprint_blob(
|
char *fingerprint = ssh2_fingerprint_blob(
|
||||||
ptrlen_from_strbuf(public_blob));
|
ptrlen_from_strbuf(public_blob));
|
||||||
pageant_client_log(pc, reqid, "add-ppk: %s %s",
|
pageant_client_log(pc, reqid, "add-ppk: %s %s",
|
||||||
fingerprint, comment);
|
fingerprint, comment);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
BinarySource_BARE_INIT_PL(src, keyfile);
|
BinarySource_BARE_INIT_PL(src, keyfile);
|
||||||
bool encrypted = ppk_encrypted_s(src, NULL);
|
bool encrypted = ppk_encrypted_s(src, NULL);
|
||||||
|
|
||||||
if (!encrypted) {
|
if (!encrypted) {
|
||||||
/* If the key isn't encrypted, then we should just
|
/* If the key isn't encrypted, then we should just
|
||||||
* load and add it in the obvious way. */
|
* load and add it in the obvious way. */
|
||||||
BinarySource_BARE_INIT_PL(src, keyfile);
|
BinarySource_BARE_INIT_PL(src, keyfile);
|
||||||
ssh2_userkey *skey = ppk_load_s(src, NULL, &error);
|
ssh2_userkey *skey = ppk_load_s(src, NULL, &error);
|
||||||
if (!skey) {
|
if (!skey) {
|
||||||
fail("failed to decode private key: %s", error);
|
fail("failed to decode private key: %s", error);
|
||||||
} else if (pageant_add_ssh2_key(skey)) {
|
} else if (pageant_add_ssh2_key(skey)) {
|
||||||
keylist_update();
|
keylist_update();
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS"
|
||||||
"reply: SSH_AGENT_SUCCESS"
|
" (loaded unencrypted PPK)");
|
||||||
" (loaded unencrypted PPK)");
|
} else {
|
||||||
} else {
|
fail("key already present");
|
||||||
fail("key already present");
|
if (skey->key)
|
||||||
if (skey->key)
|
ssh_key_free(skey->key);
|
||||||
ssh_key_free(skey->key);
|
if (skey->comment)
|
||||||
if (skey->comment)
|
sfree(skey->comment);
|
||||||
sfree(skey->comment);
|
sfree(skey);
|
||||||
sfree(skey);
|
}
|
||||||
}
|
goto add_ppk_cleanup;
|
||||||
goto add_ppk_cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PageantKeySort sort =
|
PageantKeySort sort =
|
||||||
@ -1158,47 +1148,45 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
|
|
||||||
PageantKey *pk = find234(keytree, &sort, NULL);
|
PageantKey *pk = find234(keytree, &sort, NULL);
|
||||||
if (pk) {
|
if (pk) {
|
||||||
/*
|
/*
|
||||||
* This public key blob already exists in the
|
* This public key blob already exists in the
|
||||||
* keytree. Add the encrypted key file to the
|
* keytree. Add the encrypted key file to the
|
||||||
* existing record, if it doesn't have one already.
|
* existing record, if it doesn't have one already.
|
||||||
*/
|
*/
|
||||||
if (!pk->encrypted_key_file) {
|
if (!pk->encrypted_key_file) {
|
||||||
|
pk->encrypted_key_file = strbuf_new_nm();
|
||||||
|
put_datapl(pk->encrypted_key_file, keyfile);
|
||||||
|
|
||||||
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
|
pageant_client_log(
|
||||||
|
pc, reqid, "reply: SSH_AGENT_SUCCESS (added encrypted"
|
||||||
|
" PPK to existing key record)");
|
||||||
|
} else {
|
||||||
|
fail("key already present");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* We're adding a new key record containing only
|
||||||
|
* an encrypted key file.
|
||||||
|
*/
|
||||||
|
PageantKey *pk = snew(PageantKey);
|
||||||
|
memset(pk, 0, sizeof(PageantKey));
|
||||||
|
pk->blocked_requests.next = pk->blocked_requests.prev =
|
||||||
|
&pk->blocked_requests;
|
||||||
|
pk->sort.ssh_version = 2;
|
||||||
|
pk->public_blob = public_blob;
|
||||||
|
public_blob = NULL;
|
||||||
|
pk->sort.public_blob = ptrlen_from_strbuf(pk->public_blob);
|
||||||
|
pk->comment = dupstr(comment);
|
||||||
pk->encrypted_key_file = strbuf_new_nm();
|
pk->encrypted_key_file = strbuf_new_nm();
|
||||||
put_datapl(pk->encrypted_key_file, keyfile);
|
put_datapl(pk->encrypted_key_file, keyfile);
|
||||||
|
|
||||||
|
PageantKey *added = add234(keytree, pk);
|
||||||
|
assert(added == pk); (void)added;
|
||||||
|
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS (made"
|
||||||
"reply: SSH_AGENT_SUCCESS (added"
|
" new encrypted-only key record)");
|
||||||
" encrypted PPK to existing key"
|
|
||||||
" record)");
|
|
||||||
} else {
|
|
||||||
fail("key already present");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* We're adding a new key record containing only
|
|
||||||
* an encrypted key file.
|
|
||||||
*/
|
|
||||||
PageantKey *pk = snew(PageantKey);
|
|
||||||
memset(pk, 0, sizeof(PageantKey));
|
|
||||||
pk->blocked_requests.next = pk->blocked_requests.prev =
|
|
||||||
&pk->blocked_requests;
|
|
||||||
pk->sort.ssh_version = 2;
|
|
||||||
pk->public_blob = public_blob;
|
|
||||||
public_blob = NULL;
|
|
||||||
pk->sort.public_blob = ptrlen_from_strbuf(pk->public_blob);
|
|
||||||
pk->comment = dupstr(comment);
|
|
||||||
pk->encrypted_key_file = strbuf_new_nm();
|
|
||||||
put_datapl(pk->encrypted_key_file, keyfile);
|
|
||||||
|
|
||||||
PageantKey *added = add234(keytree, pk);
|
|
||||||
assert(added == pk); (void)added;
|
|
||||||
|
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
|
||||||
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS"
|
|
||||||
" (made new encrypted-only key"
|
|
||||||
" record)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_ppk_cleanup:
|
add_ppk_cleanup:
|
||||||
@ -1219,29 +1207,29 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
ptrlen blob = get_string(msg);
|
ptrlen blob = get_string(msg);
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
fail("unable to decode request");
|
fail("unable to decode request");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc->suppress_logging) {
|
if (!pc->suppress_logging) {
|
||||||
char *fingerprint = ssh2_fingerprint_blob(blob);
|
char *fingerprint = ssh2_fingerprint_blob(blob);
|
||||||
pageant_client_log(pc, reqid, "key to re-encrypt: %s",
|
pageant_client_log(pc, reqid, "key to re-encrypt: %s",
|
||||||
fingerprint);
|
fingerprint);
|
||||||
sfree(fingerprint);
|
sfree(fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
PageantKey *pk = findkey2(blob);
|
PageantKey *pk = findkey2(blob);
|
||||||
if (!pk) {
|
if (!pk) {
|
||||||
fail("key not found");
|
fail("key not found");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
pageant_client_log(pc, reqid,
|
pageant_client_log(pc, reqid,
|
||||||
"found with comment: %s", pk->comment);
|
"found with comment: %s", pk->comment);
|
||||||
|
|
||||||
if (!reencrypt_key(pk)) {
|
if (!reencrypt_key(pk)) {
|
||||||
fail("this key couldn't be re-encrypted");
|
fail("this key couldn't be re-encrypted");
|
||||||
goto responded;
|
goto responded;
|
||||||
}
|
}
|
||||||
|
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
@ -1268,20 +1256,20 @@ static PageantAsyncOp *pageant_make_op(
|
|||||||
PageantKey *pk;
|
PageantKey *pk;
|
||||||
|
|
||||||
for (int i = 0; (pk = index234(keytree, i)) != NULL; i++) {
|
for (int i = 0; (pk = index234(keytree, i)) != NULL; i++) {
|
||||||
if (reencrypt_key(pk))
|
if (reencrypt_key(pk))
|
||||||
nsuccesses++;
|
nsuccesses++;
|
||||||
else
|
else
|
||||||
nfailures++;
|
nfailures++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsuccesses == 0 && nfailures > 0) {
|
if (nsuccesses == 0 && nfailures > 0) {
|
||||||
fail("no key could be re-encrypted");
|
fail("no key could be re-encrypted");
|
||||||
} else {
|
} else {
|
||||||
put_byte(sb, SSH_AGENT_SUCCESS);
|
put_byte(sb, SSH_AGENT_SUCCESS);
|
||||||
put_uint32(sb, nfailures);
|
put_uint32(sb, nfailures);
|
||||||
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS "
|
pageant_client_log(pc, reqid, "reply: SSH_AGENT_SUCCESS "
|
||||||
"(%u keys re-encrypted, %u failures)",
|
"(%u keys re-encrypted, %u failures)",
|
||||||
nsuccesses, nfailures);
|
nsuccesses, nfailures);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user