Read private key, if any.

This commit is contained in:
Michael Jumper 2013-10-30 15:46:13 -07:00
parent 15796cbc4d
commit 678ec69ebe
3 changed files with 52 additions and 0 deletions

View File

@ -66,6 +66,10 @@ const char* GUAC_CLIENT_ARGS[] = {
"font-name", "font-name",
"font-size", "font-size",
"enable-sftp", "enable-sftp",
#ifdef ENABLE_SSH_PUBLIC_KEY
"private-key",
"passphrase",
#endif
NULL NULL
}; };
@ -106,6 +110,18 @@ enum __SSH_ARGS_IDX {
*/ */
IDX_ENABLE_SFTP, IDX_ENABLE_SFTP,
#ifdef ENABLE_SSH_PUBLIC_KEY
/**
* The private key to use for authentication, if any.
*/
IDX_PRIVATE_KEY,
/**
* The passphrase required to decrypt the private key, if any.
*/
IDX_PASSPHRASE,
#endif
SSH_ARGS_COUNT SSH_ARGS_COUNT
}; };
@ -133,6 +149,29 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
strcpy(client_data->username, argv[IDX_USERNAME]); strcpy(client_data->username, argv[IDX_USERNAME]);
strcpy(client_data->password, argv[IDX_PASSWORD]); strcpy(client_data->password, argv[IDX_PASSWORD]);
#ifdef ENABLE_SSH_PUBLIC_KEY
client_data->key = NULL;
/* Read private key, if given */
if (argv[IDX_PRIVATE_KEY][0] != 0) {
/* Pull parameters */
const char* private_key = argv[IDX_PRIVATE_KEY];
const char* passphrase = argv[IDX_PASSPHRASE];
if (passphrase[0] == 0)
passphrase = NULL;
/* Read key */
if (ssh_pki_import_privkey_base64(private_key, passphrase,
NULL, NULL, &client_data->key) == SSH_OK)
guac_client_log_info(client, "Auth key successfully imported.");
else
guac_client_log_error(client, "Auth key import failed.");
}
#endif
/* Read font name */ /* Read font name */
if (argv[IDX_FONT_NAME][0] != 0) if (argv[IDX_FONT_NAME][0] != 0)
strcpy(client_data->font_name, argv[IDX_FONT_NAME]); strcpy(client_data->font_name, argv[IDX_FONT_NAME]);

View File

@ -72,6 +72,13 @@ typedef struct ssh_guac_client_data {
*/ */
char password[1024]; char password[1024];
#ifdef ENABLE_SSH_PUBLIC_KEY
/**
* The private key to use for authentication, if any.
*/
ssh_key key;
#endif
/** /**
* The name of the font to use for display rendering. * The name of the font to use for display rendering.
*/ */

View File

@ -443,6 +443,12 @@ int ssh_guac_client_free_handler(guac_client* client) {
/* Free session */ /* Free session */
ssh_free(guac_client_data->session); ssh_free(guac_client_data->session);
#ifdef ENABLE_SSH_PUBLIC_KEY
/* Free auth key */
if (guac_client_data->key != NULL)
ssh_key_free(guac_client_data->key);
#endif
/* Free clipboard data */ /* Free clipboard data */
free(guac_client_data->clipboard_data); free(guac_client_data->clipboard_data);