May 2019
Intermediate to advanced
478 pages
11h 21m
English
Once the SSH session is established, we can get the server's public key using the ssh_get_server_publickey() function. The following code illustrates this function call:
/*ssh_auth.c excerpt*/ ssh_key key; if (ssh_get_server_publickey(ssh, &key) != SSH_OK) { fprintf(stderr, "ssh_get_server_publickey() failed.\n%s\n", ssh_get_error(ssh)); return -1; }
It is often useful to obtain and display a hash of the server's SSH public key. Users can look at hashes and compare these to known keys. The libssh library provides the ssh_get_publickey_hash() function for this purpose.
The following code prints out an SHA1 hash of the public key obtained earlier:
/*ssh_auth.c excerpt*/ unsigned char *hash; size_t hash_len; if (ssh_get_publickey_hash(key, ...
Read now
Unlock full access