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

Re: Sending arbitrary messages between key exchange and user authentication


Ok, another patching attempt. Every issue should be fixed...

> The best way to send us a patch is documented here :
> https://red.libssh.org/projects/libssh/wiki/Patches
> That way, you'll get credit for your commit inside our git tree.

The sending part is a bit unspecific in the doc. I have decided to
attach the patch to this thread instead of using 'git send-email' and
starting a new thread.

Martin
From 4326d527b4f6b8ef3e1891bd3183d89b46dad35d Mon Sep 17 00:00:00 2001
From: Martin Drasar <drasar@xxxxxxxxxxx>
Date: Wed, 19 Oct 2011 14:42:55 +0200
Subject: [PATCH] Ignore and debug messages can be sent using public API


Signed-off-by: Martin Drasar <drasar@xxxxxxxxxxx>
---
 include/libssh/libssh.h |    2 +
 src/session.c           |  105 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 9c60eb3..c5a03ea 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -483,6 +483,8 @@ LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
                                           const char *filename);
 
 LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
+LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
+LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
 LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
 LIBSSH_API int ssh_scp_close(ssh_scp scp);
 LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
diff --git a/src/session.c b/src/session.c
index b3ee193..cd2cb2f 100644
--- a/src/session.c
+++ b/src/session.c
@@ -614,6 +614,111 @@ void ssh_socket_exception_callback(int code, int errno_code, void *user){
     leave_function();
 }
 
+/**
+ * @brief Send a message that should be ignored
+ *
+ * @param[in] session   The SSH session
+ * @param[in] data      Data to be sent
+ *
+ * @return              SSH_OK on success, SSH_ERROR otherwise.
+ */
+int ssh_send_ignore (ssh_session session, const char *data) {
+    ssh_string str = NULL;
+
+    enter_function();
+
+    if (ssh_socket_is_open(session->socket)) {
+      if (buffer_add_u8(session->out_buffer, SSH2_MSG_IGNORE) < 0) {
+        goto error;
+      }
+
+      str = ssh_string_from_char(data);
+      if (str == NULL) {
+        goto error;
+      }
+
+      if (buffer_add_ssh_string(session->out_buffer, str) < 0) {
+          ssh_string_free(str);
+          goto error;
+      }
+
+      packet_send(session);
+      ssh_handle_packets(session, 0);
+
+      ssh_string_free(str);
+    }
+
+    leave_function();
+    return SSH_OK;
+
+error:
+    buffer_reinit(session->out_buffer);
+    leave_function();
+    return SSH_ERROR;
+}
+
+/**
+ * @brief Send a debug message
+ *
+ * @param[in] session          The SSH session
+ * @param[in] message          Data to be sent
+ * @param[in] always_display   Message SHOULD be displayed by the server. It
+ *                             SHOULD NOT be displayed unless debugging
+ *                             information has been explicitly requested.
+ *
+ * @return                     SSH_OK on success, SSH_ERROR otherwise.
+ */
+int ssh_send_debug (ssh_session session, const char *message, int always_display) {
+    ssh_string str = NULL;
+
+    enter_function();
+
+    if (ssh_socket_is_open(session->socket)) {
+      if (buffer_add_u8(session->out_buffer, SSH2_MSG_DEBUG) < 0) {
+        goto error;
+      }
+
+      if (buffer_add_u8(session->out_buffer, always_display) < 0) {
+        goto error;
+      }
+
+      str = ssh_string_from_char(message);
+      if (str == NULL) {
+        goto error;
+      }
+
+      if (buffer_add_ssh_string(session->out_buffer,str) < 0) {
+          ssh_string_free(str);
+          goto error;
+      }
+
+      /* Empty language tag */
+      ssh_string_free(str);
+      str = ssh_string_from_char("");
+      if (str == NULL) {
+        goto error;
+      }
+
+      if (buffer_add_ssh_string(session->out_buffer, str) < 0) {
+        ssh_string_free(str);
+        goto error;
+      }
+
+      packet_send(session);
+      ssh_handle_packets(session, 0);
+
+      ssh_string_free(str);
+    }
+
+    leave_function();
+    return SSH_OK;
+
+error:
+    buffer_reinit(session->out_buffer);
+    leave_function();
+    return SSH_ERROR;
+}
+
 /** @} */
 
 /* vim: set ts=4 sw=4 et cindent: */
-- 
1.7.3.1.msysgit.0


Archive administrator: postmaster@lists.cynapses.org