From 5e0ce1db8fe7c0c761c62f42b7cea0b0f3c9608c Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Mon, 26 Aug 2024 16:28:32 -0400 Subject: [PATCH] GUACAMOLE-1290: Move public key import in SSH connection code. --- src/protocols/ssh/ssh.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 5a0a7e742..199064de6 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -134,33 +134,34 @@ static guac_common_ssh_user* guac_ssh_get_user(guac_client* client) { guac_client_log(client, GUAC_LOG_INFO, "Auth key successfully imported."); - } /* end if key given */ + /* Import public key, if available. */ + if (settings->public_key_base64 != NULL) { - if (settings->public_key_base64 != NULL) { + guac_client_log(client, GUAC_LOG_DEBUG, + "Attempting public key import"); - guac_client_log(client, GUAC_LOG_DEBUG, - "Attempting public key import"); + /* Attempt to read public key */ + if (guac_common_ssh_user_import_public_key(user, + settings->public_key_base64)) { - /* Attempt to read public key */ - if (guac_common_ssh_user_import_public_key(user, - settings->public_key_base64)) { + /* Public key import fails. */ + guac_client_abort(client, + GUAC_PROTOCOL_STATUS_CLIENT_UNAUTHORIZED, + "Auth public key import failed: %s", + guac_common_ssh_key_error()); - /* If failing*/ - guac_client_abort(client, - GUAC_PROTOCOL_STATUS_CLIENT_UNAUTHORIZED, - "Auth public key import failed: %s", - guac_common_ssh_key_error()); + guac_common_ssh_destroy_user(user); + return NULL; - guac_common_ssh_destroy_user(user); - return NULL; + } - } + /* Success */ + guac_client_log(client, GUAC_LOG_INFO, + "Auth public key successfully imported."); - /* Success */ - guac_client_log(client, GUAC_LOG_INFO, - "Auth public key successfully imported."); + } - } + } /* end if key given */ /* If available, get password from settings */ else if (settings->password != NULL) {