1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-14 17:47:33 -05:00

Fix wrong output from ssh1_rsa_fingerprint.

I broke it last year in commit 4988fd410, when I made hash contexts
expose a BinarySink interface. I went round finding no end of long-
winded ways of pushing things into hash contexts, often reimplementing
some standard thing like the wire formatting of an mpint, and rewrote
them more concisely using one or two put_foo calls.

But I failed to notice that the hash preimage used in SSH-1 key
fingerprints is _not_ implementable by put_ssh1_mpint! It consists of
the two public-key integers encoded in multi-byte binary big-endian
form, but without any preceding length field at all. I must have
looked too hastily, 'recognised' it as just implementing an mpint
formatter yet again, and replaced it with put_ssh1_mpint. So SSH-1 key
fingerprints have been completely wrong in the snapshots for months.

Fixed now, and this time, added a comment to warn me in case I get the
urge to simplify the code again, and a regression test in cryptsuite.
This commit is contained in:
Simon Tatham
2019-01-05 08:14:32 +00:00
parent e5e520d48e
commit 4a0fa90979
2 changed files with 27 additions and 2 deletions

View File

@ -237,9 +237,19 @@ char *rsa_ssh1_fingerprint(RSAKey *key)
strbuf *out;
int i;
/*
* The hash preimage for SSH-1 key fingerprinting consists of the
* modulus and exponent _without_ any preceding length field -
* just the minimum number of bytes to represent each integer,
* stored big-endian, concatenated with no marker at the division
* between them.
*/
MD5Init(&md5c);
put_mp_ssh1(&md5c, key->modulus);
put_mp_ssh1(&md5c, key->exponent);
for (size_t i = (mp_get_nbits(key->modulus) + 7) / 8; i-- > 0 ;)
put_byte(&md5c, mp_get_byte(key->modulus, i));
for (size_t i = (mp_get_nbits(key->exponent) + 7) / 8; i-- > 0 ;)
put_byte(&md5c, mp_get_byte(key->exponent, i));
MD5Final(digest, &md5c);
out = strbuf_new();