aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorVic Lee <llyzs@163.com>2009-12-30 10:40:34 +0800
committerAndreas Schneider <mail@cynapses.org>2009-12-30 19:05:29 +0100
commitf2ca2d50b5ef5559e66ed6cced71eaadec8ef866 (patch)
tree55dba3c6dbc607fe39f0b20608e9fdda79ccacac /libssh
parentb361fb5898831af8d2e34ba0f2ea10cff0640d62 (diff)
downloadlibssh-f2ca2d50b5ef5559e66ed6cced71eaadec8ef866.tar.gz
libssh-f2ca2d50b5ef5559e66ed6cced71eaadec8ef866.tar.xz
libssh-f2ca2d50b5ef5559e66ed6cced71eaadec8ef866.zip
In ssh_userauth_pubkey, if publickey argument is NULL, generate it from privatekey.
Signed-off-by: Vic Lee <llyzs@163.com> Signed-off-by: Andreas Schneider <mail@cynapses.org>
Diffstat (limited to 'libssh')
-rw-r--r--libssh/auth.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/libssh/auth.c b/libssh/auth.c
index 48bd6ea2..1d94135a 100644
--- a/libssh/auth.c
+++ b/libssh/auth.c
@@ -467,7 +467,8 @@ error:
* ssh_option_set_username() has been used. You cannot try
* two different logins in a row.
*
- * @param publickey A public key returned by publickey_from_file().
+ * @param publickey A public key returned by publickey_from_file(), or NULL
+ * to generate automatically from privatekey.
*
* @param privatekey A private key returned by privatekey_from_file().
*
@@ -489,6 +490,8 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
ssh_string method = NULL;
ssh_string algo = NULL;
ssh_string sign = NULL;
+ ssh_public_key pk = NULL;
+ ssh_string pkstr = NULL;
int rc = SSH_AUTH_ERROR;
enter_function();
@@ -534,6 +537,17 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
if (algo == NULL) {
goto error;
}
+ if (publickey == NULL) {
+ pk = publickey_from_privatekey(privatekey);
+ if (pk == NULL) {
+ goto error;
+ }
+ pkstr = publickey_to_string(pk);
+ publickey_free(pk);
+ if (pkstr == NULL) {
+ goto error;
+ }
+ }
/* we said previously the public key was accepted */
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST) < 0 ||
@@ -542,7 +556,7 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
buffer_add_ssh_string(session->out_buffer, method) < 0 ||
buffer_add_u8(session->out_buffer, 1) < 0 ||
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
- buffer_add_ssh_string(session->out_buffer, publickey) < 0) {
+ buffer_add_ssh_string(session->out_buffer, (publickey == NULL ? pkstr : publickey)) < 0) {
goto error;
}
@@ -550,6 +564,7 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
string_free(service);
string_free(method);
string_free(algo);
+ string_free(pkstr);
sign = ssh_do_sign(session,session->out_buffer, privatekey);
if (sign) {
@@ -573,6 +588,7 @@ error:
string_free(service);
string_free(method);
string_free(algo);
+ string_free(pkstr);
leave_function();
return rc;