mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-05 21:42:47 -05:00
Centralise SSH-2 key fingerprinting into sshpubk.c.
There were ad-hoc functions for fingerprinting a bare key blob in both cmdgen.c and pageant.c, not quite doing the same thing. Also, every SSH-2 public key algorithm in the code base included a dedicated fingerprint() method, which is completely pointless since SSH-2 key fingerprints are computed in an algorithm-independent way (just hash the standard-format public key blob), so each of those methods was just duplicating the work of the public_blob() method with a less general output mechanism. Now sshpubk.c centrally provides an ssh2_fingerprint_blob() function that does all the real work, plus an ssh2_fingerprint() function that wraps it and deals with calling public_blob() to get something to fingerprint. And the fingerprint() method has been completely removed from ssh_signkey and all its implementations, and good riddance.
This commit is contained in:
36
sshrsa.c
36
sshrsa.c
@ -775,41 +775,6 @@ static int rsa2_pubkey_bits(const void *blob, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *rsa2_fingerprint(void *key)
|
||||
{
|
||||
struct RSAKey *rsa = (struct RSAKey *) key;
|
||||
struct MD5Context md5c;
|
||||
unsigned char digest[16], lenbuf[4];
|
||||
char buffer[16 * 3 + 40];
|
||||
char *ret;
|
||||
int numlen, i;
|
||||
|
||||
MD5Init(&md5c);
|
||||
MD5Update(&md5c, (unsigned char *)"\0\0\0\7ssh-rsa", 11);
|
||||
|
||||
#define ADD_BIGNUM(bignum) \
|
||||
numlen = (bignum_bitcount(bignum)+8)/8; \
|
||||
PUT_32BIT(lenbuf, numlen); MD5Update(&md5c, lenbuf, 4); \
|
||||
for (i = numlen; i-- ;) { \
|
||||
unsigned char c = bignum_byte(bignum, i); \
|
||||
MD5Update(&md5c, &c, 1); \
|
||||
}
|
||||
ADD_BIGNUM(rsa->exponent);
|
||||
ADD_BIGNUM(rsa->modulus);
|
||||
#undef ADD_BIGNUM
|
||||
|
||||
MD5Final(digest, &md5c);
|
||||
|
||||
sprintf(buffer, "ssh-rsa %d ", bignum_bitcount(rsa->modulus));
|
||||
for (i = 0; i < 16; i++)
|
||||
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
|
||||
digest[i]);
|
||||
ret = snewn(strlen(buffer) + 1, char);
|
||||
if (ret)
|
||||
strcpy(ret, buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the magic ASN.1/DER prefix that goes in the decoded
|
||||
* signature, between the string of FFs and the actual SHA hash
|
||||
@ -945,7 +910,6 @@ const struct ssh_signkey ssh_rsa = {
|
||||
rsa2_openssh_fmtkey,
|
||||
6 /* n,e,d,iqmp,q,p */,
|
||||
rsa2_pubkey_bits,
|
||||
rsa2_fingerprint,
|
||||
rsa2_verifysig,
|
||||
rsa2_sign,
|
||||
"ssh-rsa",
|
||||
|
Reference in New Issue
Block a user