diff options
author | lns <matzeton@googlemail.com> | 2018-04-17 22:20:07 +0200 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2018-04-17 22:20:07 +0200 |
commit | c7b3d7218d36a1c6601e48f00b4a6a82c0d5c015 (patch) | |
tree | 966a56eb002d531cb0392d242b8e378bc29d3a3c | |
parent | 2029020f79847e2bd6eda45233b879e62716373d (diff) |
POTD skeleton #13.
Signed-off-by: lns <matzeton@googlemail.com>
-rw-r--r-- | src/forward.c | 2 | ||||
-rw-r--r-- | src/server_ssh.c | 46 |
2 files changed, 35 insertions, 13 deletions
diff --git a/src/forward.c b/src/forward.c index 16fec1a..ebe8d27 100644 --- a/src/forward.c +++ b/src/forward.c @@ -37,7 +37,7 @@ int fwd_setup(forward_ctx *ctx, const char *host, const char *port) if (ctx->fwd_cbs.on_listen(ctx)) return 1; if (socket_connect_in(&ctx->sock, fwd_addr)) { - E_STRERR("Could not connect forward socket"); + E_STRERR("Connection to forward socket"); return 1; } s = socket_addrtostr_in(&ctx->sock, ctx->host_buf, ctx->service_buf); diff --git a/src/server_ssh.c b/src/server_ssh.c index 5c9e1cb..09dc9f8 100644 --- a/src/server_ssh.c +++ b/src/server_ssh.c @@ -20,14 +20,20 @@ static int set_default_keys(ssh_bind sshbind, int rsa_already_set, int dsa_already_set, int ecdsa_already_set); static int gen_default_keys(void); static int gen_export_sshkey(enum ssh_keytypes_e type, int length, const char *path); +static void ssh_log_cb(int priority, const char *function, const char *buffer, void *userdata); int ssh_init_cb(struct forward_ctx *ctx) { + N("libssh version: %d.%d.%d", + LIBSSH_VERSION_MAJOR, LIBSSH_VERSION_MINOR, + LIBSSH_VERSION_MICRO); ctx->fwd_cbs = potd_ssh_callbacks; if (ssh_init()) return 1; + ssh_set_log_callback(ssh_log_cb); + ssh_set_log_level(SSH_LOG_FUNCTIONS); ssh_data *d = (ssh_data *) calloc(1, sizeof(*d)); assert(d); d->sshbind = ssh_bind_new(); @@ -64,18 +70,26 @@ static int set_default_keys(ssh_bind sshbind, int rsa_already_set, { if (!rsa_already_set) { if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, - "./ssh_host_rsa_key")) + "./ssh_host_rsa_key")) { + E2("Faled to set RSA key: %s", ssh_get_error(sshbind)); return 1; + } } +#ifdef POTD_OBSOLETE_SSHKEY if (!dsa_already_set) { if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, - "./ssh_host_dsa_key")) + "./ssh_host_dsa_key")) { + E2("Failed to set DSA key: %s", ssh_get_error(sshbind)); return 1; + } } +#endif if (!ecdsa_already_set) { if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY, - "./ssh_host_ecdsa_key")) + "./ssh_host_ecdsa_key")) { + E2("Failed to set ECDSA key: %s", ssh_get_error(sshbind)); return 1; + } } return 0; @@ -83,12 +97,13 @@ static int set_default_keys(ssh_bind sshbind, int rsa_already_set, static int gen_default_keys(void) { - if (gen_export_sshkey(SSH_KEYTYPE_DSS, 1024, "./ssh_host_dsa_key")) - return 1; if (gen_export_sshkey(SSH_KEYTYPE_RSA, 1024, "./ssh_host_rsa_key")) return 1; + if (gen_export_sshkey(SSH_KEYTYPE_DSS, 1024, "./ssh_host_dsa_key")) + return 1; if (gen_export_sshkey(SSH_KEYTYPE_ECDSA, 1024, "./ssh_host_ecdsa_key")) return 1; + return 0; } @@ -96,6 +111,7 @@ static int gen_export_sshkey(enum ssh_keytypes_e type, int length, const char *p { ssh_key priv_key; const char *type_str = NULL; + int s; assert(path); assert(length == 1024 || length == 2048 || @@ -112,22 +128,28 @@ static int gen_export_sshkey(enum ssh_keytypes_e type, int length, const char *p type_str = "ECDSA"; break; default: + W2("Unknown SSH key type: %d", type); return 1; } N2("Generating %s key with length %d bits and save it on disk: %s", type_str, length, path); - if (ssh_pki_generate(type, length, &priv_key) != SSH_OK) { - E2("Generating %s key failed", type_str); + s = ssh_pki_generate(type, length, &priv_key); + if (s != SSH_OK) { + E2("Generating %s key failed: %d", type_str, s); return 1; } - errno = 0; - if (ssh_pki_export_privkey_file(priv_key, NULL, NULL, - NULL, path) != SSH_OK) - { - E_STRERR("SSH export to file"); + s = ssh_pki_export_privkey_file(priv_key, "", NULL, + NULL, path); + if (s != SSH_OK) { + E2("SSH private key export to file failed: %d", s); return 1; } ssh_key_free(priv_key); return 0; } + +static void ssh_log_cb(int priority, const char *function, + const char *buffer, void *userdata) +{ +} |