aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-07-09 23:01:34 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-07-09 23:01:34 +0200
commitb68a1e782c4a4567dd5252fac1795804e2c20458 (patch)
tree024f06fccaf67b4bb3dc9302c5d6b4134b68d196
parent295e4d6da821521b0956c7e8fe2eed55c3953f73 (diff)
ssh: Add userdata to sshnc hostkey checker
-rw-r--r--ssh/client.c5
-rw-r--r--ssh/sshnc.c3
-rw-r--r--ssh/sshnc.h8
3 files changed, 11 insertions, 5 deletions
diff --git a/ssh/client.c b/ssh/client.c
index b9bd52a..5c7f084 100644
--- a/ssh/client.c
+++ b/ssh/client.c
@@ -45,7 +45,8 @@ static bool prompt_yn(const char *text) {
return response;
}
-static bool hostkey_checker(const unsigned char *hash, size_t length) {
+static bool hostkey_checker(const unsigned char *hash, size_t length, void *userdata) {
+ (void)userdata;
printf("Server host key hash: %s\n", sshnc_print_hash(hash, length));
bool response = prompt_yn(
@@ -75,7 +76,7 @@ int main(int argc, char **argv) {
struct sshnc_client *client;
enum sshnc_retval ret = sshnc_connect(
- server_host, port, "tomsg", "tomsg", hostkey_checker, &client);
+ server_host, port, "tomsg", "tomsg", hostkey_checker, NULL, &client);
if (ret != SSHNC_OK) {
fprintf(stderr, "Could not connect: %s\n", sshnc_strerror(ret));
diff --git a/ssh/sshnc.c b/ssh/sshnc.c
index 3a13e08..7d1ad3e 100644
--- a/ssh/sshnc.c
+++ b/ssh/sshnc.c
@@ -139,6 +139,7 @@ enum sshnc_retval sshnc_connect(
const char *username,
const char *subsystem,
sshnc_hostkey_checker_t checker,
+ void *userdata,
struct sshnc_client **clientp // output
) {
clear_additional_error();
@@ -186,7 +187,7 @@ enum sshnc_retval sshnc_connect(
RETURN(SSHNC_ERR_GETKEY);
}
- if (!checker(host_key_hash, host_key_hash_length)) {
+ if (!checker(host_key_hash, host_key_hash_length, userdata)) {
RETURN(SSHNC_ERR_UNTRUSTED);
}
diff --git a/ssh/sshnc.h b/ssh/sshnc.h
index 3e4bcfe..77edc8d 100644
--- a/ssh/sshnc.h
+++ b/ssh/sshnc.h
@@ -14,8 +14,10 @@
struct sshnc_client;
// Should return 'true' if the key is trusted, 'false' otherwise. The hash is
-// sha256 in byte form, not yet encoded in hexadecimal or similar.
-typedef bool (*sshnc_hostkey_checker_t)(const unsigned char *hash, size_t length);
+// sha256 in byte form, not yet encoded in hexadecimal or similar. The
+// 'userdata' pointer comes from the 'sshnc_connect' invocation.
+typedef bool (*sshnc_hostkey_checker_t)(
+ const unsigned char *hash, size_t length, void *userdata);
// Convenience function to convert a hash to a human-readable form. Returns a
// reference to an internal static buffer.
@@ -55,12 +57,14 @@ const char* sshnc_strerror(enum sshnc_retval code);
// If successful, stores a new connection structure in 'client' and returns
// SSHNC_OK. On error, stores NULL in 'client' and returns an error code.
+// The hostkey checker is invoked with the 'userdata' pointer.
enum sshnc_retval sshnc_connect(
const char *hostname,
int port,
const char *username,
const char *subsystem,
sshnc_hostkey_checker_t checker,
+ void *userdata,
struct sshnc_client **client // output
);