Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 3d0f297

Browse files
committed
examples: Use ssh_print_hash()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> (cherry picked from commit 5b07c1a)
1 parent 230929a commit 3d0f297

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

examples/knownhosts.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ clients must be made or how a client should react.
3333
#endif
3434

3535
int verify_knownhost(ssh_session session){
36-
char *hexa;
3736
enum ssh_known_hosts_e state;
3837
char buf[10];
3938
unsigned char *hash = NULL;
@@ -47,7 +46,7 @@ int verify_knownhost(ssh_session session){
4746
}
4847

4948
rc = ssh_get_publickey_hash(srv_pubkey,
50-
SSH_PUBLICKEY_HASH_SHA1,
49+
SSH_PUBLICKEY_HASH_SHA256,
5150
&hash,
5251
&hlen);
5352
ssh_key_free(srv_pubkey);
@@ -62,7 +61,7 @@ int verify_knownhost(ssh_session session){
6261
break; /* ok */
6362
case SSH_KNOWN_HOSTS_CHANGED:
6463
fprintf(stderr,"Host key for server changed : server's one is now :\n");
65-
ssh_print_hexa("Public key hash",hash, hlen);
64+
ssh_print_hash(SSH_PUBLICKEY_HASH_SHA256, hash, hlen);
6665
ssh_clean_pubkey_hash(&hash);
6766
fprintf(stderr,"For security reason, connection will be stopped\n");
6867
return -1;
@@ -78,10 +77,10 @@ int verify_knownhost(ssh_session session){
7877
/* fallback to SSH_SERVER_NOT_KNOWN behavior */
7978
FALL_THROUGH;
8079
case SSH_SERVER_NOT_KNOWN:
81-
hexa = ssh_get_hexa(hash, hlen);
82-
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
83-
fprintf(stderr, "Public key hash: %s\n", hexa);
84-
ssh_string_free_char(hexa);
80+
fprintf(stderr,
81+
"The server is unknown. Do you trust the host key (yes/no)?\n");
82+
ssh_print_hash(SSH_PUBLICKEY_HASH_SHA256, hash, hlen);
83+
8584
if (fgets(buf, sizeof(buf), stdin) == NULL) {
8685
ssh_clean_pubkey_hash(&hash);
8786
return -1;

0 commit comments

Comments
 (0)