1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Factor out get_rsa_ssh1_priv_agent from Pageant.

The code that reads an SSH1_AGENTC_ADD_RSA_IDENTITY message and parses
an RSA private key out of it now does it by calling a BinarySource
function in sshrsa.c, instead of doing inline in the Pageant message
handler. This has no functional change, except that now I can expose
that separate function in the testcrypt API, where it provides me with
a mechanism for creating a bare RSAKey structure for purposes of
testing RSA key exchange.
This commit is contained in:
Simon Tatham 2019-12-15 20:12:36 +00:00
parent 7dd0351254
commit 873ec97302
5 changed files with 26 additions and 14 deletions

View File

@ -282,6 +282,8 @@ static inline void BinarySource_INIT__(BinarySource *src, ptrlen data)
BinarySource_get_rsa_ssh1_pub(BinarySource_UPCAST(src), rsa, order)
#define get_rsa_ssh1_priv(src, rsa) \
BinarySource_get_rsa_ssh1_priv(BinarySource_UPCAST(src), rsa)
#define get_rsa_ssh1_priv_agent(src) \
BinarySource_get_rsa_ssh1_priv_agent(BinarySource_UPCAST(src))
#define get_err(src) (BinarySource_UPCAST(src)->err)
#define get_avail(src) (BinarySource_UPCAST(src)->len - \

View File

@ -379,19 +379,7 @@ void pageant_handle_msg(BinarySink *bs,
plog(logctx, logfn, "request: SSH1_AGENTC_ADD_RSA_IDENTITY");
key = snew(RSAKey);
memset(key, 0, sizeof(RSAKey));
get_rsa_ssh1_pub(msg, key, RSA_SSH1_MODULUS_FIRST);
get_rsa_ssh1_priv(msg, key);
/* SSH-1 names p and q the other way round, i.e. we have
* the inverse of p mod q and not of q mod p. We swap the
* names, because our internal RSA wants iqmp. */
key->iqmp = get_mp_ssh1(msg);
key->q = get_mp_ssh1(msg);
key->p = get_mp_ssh1(msg);
key = get_rsa_ssh1_priv_agent(msg);
key->comment = mkstr(get_string(msg));
if (get_err(msg)) {

1
ssh.h
View File

@ -539,6 +539,7 @@ void BinarySource_get_rsa_ssh1_pub(
BinarySource *src, RSAKey *result, RsaSsh1Order order);
void BinarySource_get_rsa_ssh1_priv(
BinarySource *src, RSAKey *rsa);
RSAKey *BinarySource_get_rsa_ssh1_priv_agent(BinarySource *src);
bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key);
mp_int *rsa_ssh1_decrypt(mp_int *input, RSAKey *key);
bool rsa_ssh1_decrypt_pkcs1(mp_int *input, RSAKey *key, strbuf *outbuf);

View File

@ -43,6 +43,24 @@ void BinarySource_get_rsa_ssh1_priv(
rsa->private_exponent = get_mp_ssh1(src);
}
RSAKey *BinarySource_get_rsa_ssh1_priv_agent(BinarySource *src)
{
RSAKey *rsa = snew(RSAKey);
memset(rsa, 0, sizeof(RSAKey));
get_rsa_ssh1_pub(src, rsa, RSA_SSH1_MODULUS_FIRST);
get_rsa_ssh1_priv(src, rsa);
/* SSH-1 names p and q the other way round, i.e. we have the
* inverse of p mod q and not of q mod p. We swap the names,
* because our internal RSA wants iqmp. */
rsa->iqmp = get_mp_ssh1(src);
rsa->q = get_mp_ssh1(src);
rsa->p = get_mp_ssh1(src);
return rsa;
}
bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
{
mp_int *b1, *b2;

View File

@ -187,12 +187,15 @@ FUNC2(void, ssh_ecdhkex_getpublic, val_ecdh, out_val_string_binarysink)
FUNC2(val_mpint, ssh_ecdhkex_getkey, val_ecdh, val_string_ptrlen)
/*
* RSA key exchange.
* RSA key exchange, and also the BinarySource get function
* get_ssh1_rsa_priv_agent, which is a convenient way to make an
* RSAKey for RSA kex testing purposes.
*/
FUNC1(val_rsakex, ssh_rsakex_newkey, val_string_ptrlen)
FUNC1(uint, ssh_rsakex_klen, val_rsakex)
FUNC3(val_string, ssh_rsakex_encrypt, val_rsakex, hashalg, val_string_ptrlen)
FUNC3(val_mpint, ssh_rsakex_decrypt, val_rsakex, hashalg, val_string_ptrlen)
FUNC1(val_rsakex, get_rsa_ssh1_priv_agent, val_string_binarysource)
/*
* Bare RSA keys as used in SSH-1. The construction API functions