aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-06-25 20:06:58 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-06-25 20:06:58 +0200
commit1ed369561c342342377a30eb211d685335b01bd2 (patch)
tree10044fdbc230697934bd7f3e453e1547defce64a
parent8aa6cf1e9bf35a7ed0c377b5562f7554a45c1a68 (diff)
ssh server: print host key
-rw-r--r--ssh/server.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/ssh/server.c b/ssh/server.c
index fa63d34..5a2b162 100644
--- a/ssh/server.c
+++ b/ssh/server.c
@@ -404,6 +404,23 @@ int main(void) {
return 1;
}
+ ssh_key host_key;
+ if (ssh_pki_import_privkey_file("host_key", NULL, NULL, NULL, &host_key) != SSH_OK) {
+ fprintf(stderr, "Failed to read host private key file 'host_key'\n");
+ return 1;
+ }
+
+ size_t host_key_hash_length = 0;
+ unsigned char *host_key_hash = NULL;
+ if (ssh_get_publickey_hash(host_key, SSH_PUBLICKEY_HASH_SHA256, &host_key_hash, &host_key_hash_length) != SSH_OK) {
+ fprintf(stderr, "Failed to hash host key!\n");
+ return 1;
+ }
+
+ printf("Host key hash: ");
+ fflush(stdout);
+ ssh_print_hash(SSH_PUBLICKEY_HASH_SHA256, host_key_hash, host_key_hash_length);
+
ssh_bind srvbind = ssh_bind_new();
CHECK(srvbind, srvbind);
@@ -411,7 +428,7 @@ int main(void) {
CHECK(srvbind, ssh_bind_options_set(srvbind, SSH_BIND_OPTIONS_PROCESS_CONFIG, &procconfig) == SSH_OK);
int port = 2222;
CHECK(srvbind, ssh_bind_options_set(srvbind, SSH_BIND_OPTIONS_BINDPORT, &port) == SSH_OK);
- CHECK(srvbind, ssh_bind_options_set(srvbind, SSH_BIND_OPTIONS_HOSTKEY, "host_key") == SSH_OK);
+ CHECK(srvbind, ssh_bind_options_set(srvbind, SSH_BIND_OPTIONS_IMPORT_KEY, host_key) == SSH_OK);
const char *ciphers_str = "aes256-gcm@openssh.com,aes256-ctr,aes256-cbc";
CHECK(srvbind, ssh_bind_options_set(srvbind, SSH_BIND_OPTIONS_CIPHERS_C_S, ciphers_str) == SSH_OK);
CHECK(srvbind, ssh_bind_options_set(srvbind, SSH_BIND_OPTIONS_CIPHERS_S_C, ciphers_str) == SSH_OK);