diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2011-10-05 17:50:31 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-10-29 19:58:28 +0200 |
commit | e799c0ce7d046606d9391d826461c2782f072fa0 (patch) | |
tree | f5dc2ed2f464bf14db83d4e89dce18138bd621c3 /src | |
parent | 2cc48db67389faea965e4f67f2292e5a612f8082 (diff) | |
download | libssh-e799c0ce7d046606d9391d826461c2782f072fa0.tar.gz libssh-e799c0ce7d046606d9391d826461c2782f072fa0.tar.xz libssh-e799c0ce7d046606d9391d826461c2782f072fa0.zip |
dh: Add ssh_get_publickey().
Diffstat (limited to 'src')
-rw-r--r-- | src/dh.c | 29 | ||||
-rw-r--r-- | src/legacy.c | 8 |
2 files changed, 31 insertions, 6 deletions
@@ -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); } /** @} */ diff --git a/src/legacy.c b/src/legacy.c index 75926bd4..65abebc8 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -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 ****************************************************************************/ |