Help with implementing validation of fingerprint

Reid Thompson reid.thompson at crunchydata.com
Wed Jan 18 04:48:25 CET 2023


Hi All,

I'm looking for some guidance on how to validate host fingerprints.
In the code examples, theres

    /* At this point we havn't yet authenticated.  The first thing to do                                                            
     * is check the hostkey's fingerprint against our known hosts Your app                                                          
     * may have it hard coded, may go to a file, may present it to the                                                              
     * user, that's your call                                                                                                       
     */                                                                                                                             
    fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);                                                         
    fprintf(stderr, "Fingerprint: ");                                                                                               
    for(i = 0; i < 20; i++) {                                                                                                       
    fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);                                                                    
    }                                                                                                                               
    fprintf(stderr, "\n");


How do I validate against fingerprints in the various formats?
I.E. by default, my 'test' system returns the fingerprint in sha256 format.

[22:13:15][2s] rthompso at raker>~ 
$ ssh-keyscan  endpoint | ssh-keygen -E sha256 -lf -
2048 SHA256:oFL2kYEv4fhQsK0jgxyQS/RFN24pwuKpZZ4LLeAHRq4 endpoint (RSA)
256 SHA256:6jqUm4jWlMMp8NUBeAUjJc1OsenpKXiTK/SsArRqVVI endpoint (ECDSA)
256 SHA256:wsq6kh8GeUskgmCoRETyoogh3mcw8jIRG/YXhM807R4 endpoint (ED25519)

[22:12:08][1s] rthompso at raker>~ 
$ ssh-keyscan  endpoint | ssh-keygen -E sha1 -lf -
2048 SHA1:tHnoFUqw8ELtbt+hsbT/4Vdl35Q endpoint (RSA)
256 SHA1:mbpma12Bfj4Eyec7q6EWXlJPoq0 endpoint (ECDSA)
256 SHA1:axaDvVSbxdRUEX/9dyl2acFgl1s endpoint (ED25519)

[22:13:26][3s] rthompso at raker>~ 
$ ssh-keyscan  endpoint | ssh-keygen -E md5 -lf -
2048 MD5:0b:91:4b:75:52:9d:ee:4d:25:36:4a:42:d1:2c:12:72 endpoint (RSA)
256 MD5:84:5a:1a:dd:10:7d:5b:5d:d1:b3:06:9a:10:18:fd:58 endpoint (ECDSA)
256 MD5:33:78:fd:17:ff:73:d0:b0:9c:ee:71:8e:d7:29:2a:e0 endpoint (ED25519)

I've looked at tests/test_hostkey_hash.c. I see that calculate_digest(...)
creates a hex digest of the binary hash ala the fingerprint loop above and
compares that to the declared expected hash digest.  What I'm not yet able
to determine is how the above sha* type fingerprints can be compared? Can
someone point me to or provide examples?

I.E. if a user provided the fingerprint 
SHA256:6jqUm4jWlMMp8NUBeAUjJc1OsenpKXiTK/SsArRqVVI, (or any of the others
listed above) what would I need to do to verify it against the
value returned from libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_*)

also, how would I handle the situation where the version of libssh2 on the
client host doesn't support sha256 but the fingerprint is sha256? UBUNTU
20.04 installs libssh2 1.8.0, which doesn't support
LIBSSH2_HOSTKEY_HASH_SHA256, but the fingerprint provided on connection is
SHA256:6jqUm4jWlMMp8NUBeAUjJc1OsenpKXiTK/SsArRqVVI


Thanks,
Reid




More information about the libssh2-devel mailing list