aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-08-17 13:13:12 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-08-29 19:04:44 +0200
commit5b07c1aa2c024898abf50fe93f170c9a5068571a (patch)
tree7226554e529b27338267dfccabfbb3eefc764165 /examples
parent9510a538c2f13ca67fa5967288c4eda3cce99367 (diff)
downloadlibssh-5b07c1aa2c024898abf50fe93f170c9a5068571a.tar.gz
libssh-5b07c1aa2c024898abf50fe93f170c9a5068571a.tar.xz
libssh-5b07c1aa2c024898abf50fe93f170c9a5068571a.zip
examples: Use ssh_print_hash()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/knownhosts.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/knownhosts.c b/examples/knownhosts.c
index feacfa15..2c538dac 100644
--- a/examples/knownhosts.c
+++ b/examples/knownhosts.c
@@ -33,7 +33,6 @@ clients must be made or how a client should react.
#endif
int verify_knownhost(ssh_session session){
- char *hexa;
enum ssh_known_hosts_e state;
char buf[10];
unsigned char *hash = NULL;
@@ -47,7 +46,7 @@ int verify_knownhost(ssh_session session){
}
rc = ssh_get_publickey_hash(srv_pubkey,
- SSH_PUBLICKEY_HASH_SHA1,
+ SSH_PUBLICKEY_HASH_SHA256,
&hash,
&hlen);
ssh_key_free(srv_pubkey);
@@ -62,7 +61,7 @@ int verify_knownhost(ssh_session session){
break; /* ok */
case SSH_KNOWN_HOSTS_CHANGED:
fprintf(stderr,"Host key for server changed : server's one is now :\n");
- ssh_print_hexa("Public key hash",hash, hlen);
+ ssh_print_hash(SSH_PUBLICKEY_HASH_SHA256, hash, hlen);
ssh_clean_pubkey_hash(&hash);
fprintf(stderr,"For security reason, connection will be stopped\n");
return -1;
@@ -78,10 +77,10 @@ int verify_knownhost(ssh_session session){
/* fallback to SSH_SERVER_NOT_KNOWN behavior */
FALL_THROUGH;
case SSH_SERVER_NOT_KNOWN:
- hexa = ssh_get_hexa(hash, hlen);
- fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
- fprintf(stderr, "Public key hash: %s\n", hexa);
- ssh_string_free_char(hexa);
+ fprintf(stderr,
+ "The server is unknown. Do you trust the host key (yes/no)?\n");
+ ssh_print_hash(SSH_PUBLICKEY_HASH_SHA256, hash, hlen);
+
if (fgets(buf, sizeof(buf), stdin) == NULL) {
ssh_clean_pubkey_hash(&hash);
return -1;