Skip to content

Commit 0b5540b

Browse files
authored
Merge pull request libgit2#5307 from palmin/hash_sha256
ssh: include sha256 host key hash when supported
2 parents dfea071 + 48c3f7e commit 0b5540b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/git2/cert.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ typedef enum {
7878
GIT_CERT_SSH_MD5 = (1 << 0),
7979
/** SHA-1 is available */
8080
GIT_CERT_SSH_SHA1 = (1 << 1),
81+
/** SHA-256 is available */
82+
GIT_CERT_SSH_SHA256 = (1 << 2),
8183
} git_cert_ssh_t;
8284

8385
/**
@@ -103,6 +105,12 @@ typedef struct {
103105
* have the SHA-1 hash of the hostkey.
104106
*/
105107
unsigned char hash_sha1[20];
108+
109+
/**
110+
* Hostkey hash. If type has `GIT_CERT_SSH_SHA256` set, this will
111+
* have the SHA-256 hash of the hostkey.
112+
*/
113+
unsigned char hash_sha256[32];
106114
} git_cert_hostkey;
107115

108116
/**

src/transports/ssh.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,14 @@ static int _git_ssh_setup_conn(
566566

567567
cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
568568

569+
#ifdef LIBSSH2_HOSTKEY_HASH_SHA256
570+
key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256);
571+
if (key != NULL) {
572+
cert.type |= GIT_CERT_SSH_SHA256;
573+
memcpy(&cert.hash_sha256, key, 32);
574+
}
575+
#endif
576+
569577
key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
570578
if (key != NULL) {
571579
cert.type |= GIT_CERT_SSH_SHA1;

0 commit comments

Comments
 (0)