aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-10-05 17:50:31 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-10-29 19:58:28 +0200
commite799c0ce7d046606d9391d826461c2782f072fa0 (patch)
treef5dc2ed2f464bf14db83d4e89dce18138bd621c3 /src
parent2cc48db67389faea965e4f67f2292e5a612f8082 (diff)
downloadlibssh-e799c0ce7d046606d9391d826461c2782f072fa0.tar.gz
libssh-e799c0ce7d046606d9391d826461c2782f072fa0.tar.xz
libssh-e799c0ce7d046606d9391d826461c2782f072fa0.zip
dh: Add ssh_get_publickey().
Diffstat (limited to 'src')
-rw-r--r--src/dh.c29
-rw-r--r--src/legacy.c8
2 files changed, 31 insertions, 6 deletions
diff --git a/src/dh.c b/src/dh.c
index 109c4608..c37051b0 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -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
****************************************************************************/