From c29237832779060dc26c6f5efba25c96a7ef0dc8 Mon Sep 17 00:00:00 2001 From: Peter Stuge Date: Wed, 5 Oct 2011 16:55:58 +0200 Subject: [PATCH] example/ssh2_agent: Print host key fingerprint before authentication Also moves the comment about not being authenticated to before the agent authentication takes place, so that it better matches the code. --- example/ssh2_agent.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index ab7a8c3..9ca1a42 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -99,6 +99,18 @@ int main(int argc, char *argv[]) return 1; } + /* At this point we havn't authenticated. The first thing to do is check + * the hostkey's fingerprint against our known hosts Your app may have it + * hard coded, may go to a file, may present it to the user, that's your + * call + */ + fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); + printf("Fingerprint: "); + for(i = 0; i < 20; i++) { + printf("%02X ", (unsigned char)fingerprint[i]); + } + printf("\n"); + /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, strlen(username)); printf("Authentication methods: %s\n", userauthlist); @@ -151,17 +163,7 @@ int main(int argc, char *argv[]) goto shutdown; } - /* At this point we havn't authenticated. The first thing to do is check - * the hostkey's fingerprint against our known hosts Your app may have it - * hard coded, may go to a file, may present it to the user, that's your - * call - */ - fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); - printf("Fingerprint: "); - for(i = 0; i < 20; i++) { - printf("%02X ", (unsigned char)fingerprint[i]); - } - printf("\n"); + /* We're authenticated now. */ /* Request a shell */ if (!(channel = libssh2_channel_open_session(session))) {