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 | |
parent | 2cc48db67389faea965e4f67f2292e5a612f8082 (diff) | |
download | libssh-e799c0ce7d046606d9391d826461c2782f072fa0.tar.gz libssh-e799c0ce7d046606d9391d826461c2782f072fa0.tar.xz libssh-e799c0ce7d046606d9391d826461c2782f072fa0.zip |
dh: Add ssh_get_publickey().
-rw-r--r-- | include/libssh/legacy.h | 1 | ||||
-rw-r--r-- | include/libssh/libssh.h | 2 | ||||
-rw-r--r-- | src/dh.c | 29 | ||||
-rw-r--r-- | src/legacy.c | 8 |
4 files changed, 33 insertions, 7 deletions
diff --git a/include/libssh/legacy.h b/include/libssh/legacy.h index 1225daf..969544c 100644 --- a/include/libssh/legacy.h +++ b/include/libssh/legacy.h @@ -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); diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 961dfc0..d09d933 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -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); @@ -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 75926bd..65abebc 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 ****************************************************************************/ |