mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -05:00
Add API for getting all of a key's fingerprints.
ssh2_all_fingerprints() and friends will return a small 'char **' array, containing all the fingerprints of a key that we know how to generate, indexed by the FingerprintType enum. The result requires complex freeing, so there's an ssh2_free_all_fingerprints as well. For SSH-1 RSA keys, we refuse to generate any fingerprint except the old SSH-1 MD5 version, because there's no other fingerprint type I know of that anyone else uses. So I've got a function that returns the same 'char **' for an SSH-1 key, but it only fills in the MD5 slot, and leaves the rest NULL. As a result, I also need a dynamic function that takes a fingerprint list and returns the id of the most preferred fingerprint type in it _that actually exists_. NFC: this API is introduced, but not yet used.
This commit is contained in:
24
sshpubk.c
24
sshpubk.c
@ -1794,6 +1794,14 @@ char *ssh2_fingerprint_blob(ptrlen blob, FingerprintType fptype)
|
||||
return strbuf_to_str(sb);
|
||||
}
|
||||
|
||||
char **ssh2_all_fingerprints_for_blob(ptrlen blob)
|
||||
{
|
||||
char **fps = snewn(SSH_N_FPTYPES, char *);
|
||||
for (unsigned i = 0; i < SSH_N_FPTYPES; i++)
|
||||
fps[i] = ssh2_fingerprint_blob(blob, i);
|
||||
return fps;
|
||||
}
|
||||
|
||||
char *ssh2_fingerprint(ssh_key *data, FingerprintType fptype)
|
||||
{
|
||||
strbuf *blob = strbuf_new();
|
||||
@ -1803,6 +1811,22 @@ char *ssh2_fingerprint(ssh_key *data, FingerprintType fptype)
|
||||
return ret;
|
||||
}
|
||||
|
||||
char **ssh2_all_fingerprints(ssh_key *data)
|
||||
{
|
||||
strbuf *blob = strbuf_new();
|
||||
ssh_key_public_blob(data, BinarySink_UPCAST(blob));
|
||||
char **ret = ssh2_all_fingerprints_for_blob(ptrlen_from_strbuf(blob));
|
||||
strbuf_free(blob);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ssh2_free_all_fingerprints(char **fps)
|
||||
{
|
||||
for (unsigned i = 0; i < SSH_N_FPTYPES; i++)
|
||||
sfree(fps[i]);
|
||||
sfree(fps);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Determine the type of a private key file.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user