[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] session: add getters for session cipher names


Hi,

The attached patch exposes getters for the in/out ciphers
used for a given session.  The usecase for this is that
it may be interesting information to have in the server
context.


-Jon
From aa1bafdd47bd9d391e349abf6ff81d15a5114a45 Mon Sep 17 00:00:00 2001
From: Jon Simons <jon@xxxxxxxxxxxxx>
Date: Tue, 28 Jan 2014 09:52:38 -0800
Subject: [PATCH] session: add getters for session cipher names

---
 include/libssh/libssh.h |  2 ++
 src/session.c           | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 31bcc86..1f9670e 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -628,6 +628,8 @@ LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
 LIBSSH_API void ssh_event_free(ssh_event event);
 LIBSSH_API const char* ssh_get_clientbanner(ssh_session session);
 LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
+LIBSSH_API const char* ssh_get_cipher_in(ssh_session session);
+LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
 
 #ifndef LIBSSH_LEGACY_0_4
 #include "libssh/legacy.h"
diff --git a/src/session.c b/src/session.c
index 71d4548..8d0b91c 100644
--- a/src/session.c
+++ b/src/session.c
@@ -310,6 +310,38 @@ const char* ssh_get_serverbanner(ssh_session session) {
 }
 
 /**
+ * @brief get the name of the input for the given session.
+ *
+ * @param[in] session The SSH session.
+ *
+ * @return Returns cipher name or NULL.
+ */
+const char* ssh_get_cipher_in(ssh_session session) {
+    if (session &&
+        session->current_crypto &&
+        session->current_crypto->in_cipher) {
+        return session->current_crypto->in_cipher->name;
+    }
+    return NULL;
+}
+
+/**
+ * @brief get the name of the output cipher for the given session.
+ *
+ * @param[in] session The SSH session.
+ *
+ * @return Returns cipher name or NULL.
+ */
+const char* ssh_get_cipher_out(ssh_session session) {
+    if (session &&
+        session->current_crypto &&
+        session->current_crypto->out_cipher) {
+        return session->current_crypto->out_cipher->name;
+    }
+    return NULL;
+}
+
+/**
  * @brief Disconnect impolitely from a remote host by closing the socket.
  *
  * Suitable if you forked and want to destroy this session.
-- 
1.8.4.21.g992c386



Follow-Ups:
Re: [PATCH] session: add getters for session cipher namesAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org