mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 14:39:24 -05: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:
parent
7dd0351254
commit
873ec97302
@ -282,6 +282,8 @@ static inline void BinarySource_INIT__(BinarySource *src, ptrlen data)
|
|||||||
BinarySource_get_rsa_ssh1_pub(BinarySource_UPCAST(src), rsa, order)
|
BinarySource_get_rsa_ssh1_pub(BinarySource_UPCAST(src), rsa, order)
|
||||||
#define get_rsa_ssh1_priv(src, rsa) \
|
#define get_rsa_ssh1_priv(src, rsa) \
|
||||||
BinarySource_get_rsa_ssh1_priv(BinarySource_UPCAST(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_err(src) (BinarySource_UPCAST(src)->err)
|
||||||
#define get_avail(src) (BinarySource_UPCAST(src)->len - \
|
#define get_avail(src) (BinarySource_UPCAST(src)->len - \
|
||||||
|
14
pageant.c
14
pageant.c
@ -379,19 +379,7 @@ void pageant_handle_msg(BinarySink *bs,
|
|||||||
|
|
||||||
plog(logctx, logfn, "request: SSH1_AGENTC_ADD_RSA_IDENTITY");
|
plog(logctx, logfn, "request: SSH1_AGENTC_ADD_RSA_IDENTITY");
|
||||||
|
|
||||||
key = snew(RSAKey);
|
key = get_rsa_ssh1_priv_agent(msg);
|
||||||
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->comment = mkstr(get_string(msg));
|
key->comment = mkstr(get_string(msg));
|
||||||
|
|
||||||
if (get_err(msg)) {
|
if (get_err(msg)) {
|
||||||
|
1
ssh.h
1
ssh.h
@ -539,6 +539,7 @@ void BinarySource_get_rsa_ssh1_pub(
|
|||||||
BinarySource *src, RSAKey *result, RsaSsh1Order order);
|
BinarySource *src, RSAKey *result, RsaSsh1Order order);
|
||||||
void BinarySource_get_rsa_ssh1_priv(
|
void BinarySource_get_rsa_ssh1_priv(
|
||||||
BinarySource *src, RSAKey *rsa);
|
BinarySource *src, RSAKey *rsa);
|
||||||
|
RSAKey *BinarySource_get_rsa_ssh1_priv_agent(BinarySource *src);
|
||||||
bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key);
|
bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key);
|
||||||
mp_int *rsa_ssh1_decrypt(mp_int *input, RSAKey *key);
|
mp_int *rsa_ssh1_decrypt(mp_int *input, RSAKey *key);
|
||||||
bool rsa_ssh1_decrypt_pkcs1(mp_int *input, RSAKey *key, strbuf *outbuf);
|
bool rsa_ssh1_decrypt_pkcs1(mp_int *input, RSAKey *key, strbuf *outbuf);
|
||||||
|
18
sshrsa.c
18
sshrsa.c
@ -43,6 +43,24 @@ void BinarySource_get_rsa_ssh1_priv(
|
|||||||
rsa->private_exponent = get_mp_ssh1(src);
|
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)
|
bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
|
||||||
{
|
{
|
||||||
mp_int *b1, *b2;
|
mp_int *b1, *b2;
|
||||||
|
@ -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)
|
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(val_rsakex, ssh_rsakex_newkey, val_string_ptrlen)
|
||||||
FUNC1(uint, ssh_rsakex_klen, val_rsakex)
|
FUNC1(uint, ssh_rsakex_klen, val_rsakex)
|
||||||
FUNC3(val_string, ssh_rsakex_encrypt, val_rsakex, hashalg, val_string_ptrlen)
|
FUNC3(val_string, ssh_rsakex_encrypt, val_rsakex, hashalg, val_string_ptrlen)
|
||||||
FUNC3(val_mpint, ssh_rsakex_decrypt, 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
|
* Bare RSA keys as used in SSH-1. The construction API functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user