1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-08 19:02:06 +03:00

dh: Add ssh_get_publickey().

This commit is contained in:
Andreas Schneider
2011-10-05 17:50:31 +02:00
parent 2cc48db673
commit e799c0ce7d
4 changed files with 33 additions and 7 deletions

View File

@@ -105,6 +105,7 @@ LIBSSH_API int ssh_try_publickey_from_file(ssh_session session, const char *keyf
ssh_string *publickey, int *type);
LIBSSH_API enum ssh_keytypes_e ssh_privatekey_type(ssh_private_key privatekey);
LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype);
LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);

View File

@@ -398,7 +398,7 @@ LIBSSH_API socket_t ssh_get_fd(ssh_session session);
LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
LIBSSH_API int ssh_get_openssh_version(ssh_session session);
LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
LIBSSH_API int ssh_get_random(void *where,int len,int strong);
LIBSSH_API int ssh_get_version(ssh_session session);

View File

@@ -56,6 +56,7 @@
#include "libssh/misc.h"
#include "libssh/dh.h"
#include "libssh/ssh2.h"
#include "libssh/pki.h"
/* todo: remove it */
#include "libssh/string.h"
@@ -1021,12 +1022,28 @@ void ssh_clean_pubkey_hash(unsigned char **hash) {
*hash = NULL;
}
ssh_string ssh_get_pubkey(ssh_session session){
if(session==NULL || session->current_crypto ==NULL ||
session->current_crypto->server_pubkey==NULL)
return NULL;
else
return ssh_string_copy(session->current_crypto->server_pubkey);
/**
* @brief Get the server public key from a session.
*
* @param[in] session The session to get the key from.
*
* @param[out] key A pointer to store the allocated key. You need to free
* the key.
*
* @return SSH_OK on success, SSH_ERROR on errror.
*
* @see ssh_key_free()
*/
int ssh_get_publickey(ssh_session session, ssh_key *key)
{
if (session==NULL ||
session->current_crypto ==NULL ||
session->current_crypto->server_pubkey == NULL) {
return SSH_ERROR;
}
return ssh_pki_import_pubkey_blob(session->current_crypto->server_pubkey,
key);
}
/** @} */

View File

@@ -696,6 +696,14 @@ int ssh_try_publickey_from_file(ssh_session session,
return 0;
}
ssh_string ssh_get_pubkey(ssh_session session){
if(session==NULL || session->current_crypto ==NULL ||
session->current_crypto->server_pubkey==NULL)
return NULL;
else
return ssh_string_copy(session->current_crypto->server_pubkey);
}
/****************************************************************************
* SERVER SUPPORT
****************************************************************************/