[ttssh2-commit] [10066] SSH_MSG_EXTINFO を処理するようにした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 7月 18日 (月) 00:39:32 JST


Revision: 10066
          https://osdn.net/projects/ttssh2/scm/svn/commits/10066
Author:   doda
Date:     2022-07-18 00:39:32 +0900 (Mon, 18 Jul 2022)
Log Message:
-----------
SSH_MSG_EXTINFO を処理するようにした

Ticket: #36111

・現状では server-sig-algs の値を保存するのみ

Ticket Links:
------------
    https://osdn.net/projects/ttssh2/tracker/detail/36111

Modified Paths:
--------------
    trunk/ttssh2/ttxssh/kex.c
    trunk/ttssh2/ttxssh/ssh.c
    trunk/ttssh2/ttxssh/ssh.h
    trunk/ttssh2/ttxssh/ttxssh.h

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/kex.c
===================================================================
--- trunk/ttssh2/ttxssh/kex.c	2022-07-17 15:39:21 UTC (rev 10065)
+++ trunk/ttssh2/ttxssh/kex.c	2022-07-17 15:39:32 UTC (rev 10066)
@@ -141,7 +141,7 @@
 {
 	static char buf[512]; // TODO: malloc()\x82ɂ\xB7\x82ׂ\xAB
 	int index;
-	int len, i;
+	int i;
 
 	// \x92ʐM\x92\x86\x82ɂ͌Ă΂\xEA\x82Ȃ\xA2\x82͂\xB8\x82\xBE\x82\xAA\x81A\x94O\x82̂\xBD\x82߁B(2006.6.26 maya)
 	if (pvar->socket != INVALID_SOCKET) {
@@ -156,9 +156,7 @@
 		strncat_s(buf, sizeof(buf), get_kex_algorithm_name(index), _TRUNCATE);
 		strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
 	}
-	len = strlen(buf);
-	if (len > 0)
-		buf[len - 1] = '\0';  // get rid of comma
+	strncat_s(buf, sizeof(buf), "ext-info-c", _TRUNCATE);
 	myproposal[PROPOSAL_KEX_ALGS] = buf; 
 }
 

Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2022-07-17 15:39:21 UTC (rev 10065)
+++ trunk/ttssh2/ttxssh/ssh.c	2022-07-17 15:39:32 UTC (rev 10066)
@@ -114,6 +114,7 @@
 static BOOL handle_SSH2_dh_gex_reply(PTInstVar pvar);
 static BOOL handle_SSH2_newkeys(PTInstVar pvar);
 static BOOL handle_SSH2_service_accept(PTInstVar pvar);
+static BOOL handle_SSH2_ext_info(PTInstVar pvar);
 static BOOL handle_SSH2_userauth_success(PTInstVar pvar);
 static BOOL handle_SSH2_userauth_failure(PTInstVar pvar);
 static BOOL handle_SSH2_userauth_banner(PTInstVar pvar);
@@ -1897,6 +1898,7 @@
 		enque_handler(pvar, SSH2_MSG_KEX_DH_GEX_REPLY, handle_SSH2_dh_gex_reply);
 		enque_handler(pvar, SSH2_MSG_NEWKEYS, handle_SSH2_newkeys);
 		enque_handler(pvar, SSH2_MSG_SERVICE_ACCEPT, handle_SSH2_service_accept);
+		enque_handler(pvar, SSH2_MSG_EXT_INFO, handle_SSH2_ext_info);
 		enque_handler(pvar, SSH2_MSG_USERAUTH_SUCCESS, handle_SSH2_userauth_success);
 		enque_handler(pvar, SSH2_MSG_USERAUTH_FAILURE, handle_SSH2_userauth_failure);
 		enque_handler(pvar, SSH2_MSG_USERAUTH_BANNER, handle_SSH2_userauth_banner);
@@ -2946,6 +2948,7 @@
 	pvar->agentfwd_enable = FALSE;
 	pvar->use_subsystem = FALSE;
 	pvar->nosession = FALSE;
+	pvar->server_sig_algs = NULL;
 
 }
 
@@ -3508,6 +3511,9 @@
 
 		pvar->tryed_ssh2_authlist = FALSE;
 
+		free(pvar->server_sig_algs);
+		pvar->server_sig_algs = NULL;
+
 		// add (2008.3.2 yutaka)
 		for (mode = 0 ; mode < MODE_MAX ; mode++) {
 			if (pvar->ssh2_keys[mode].enc.iv != NULL) {
@@ -6514,6 +6520,8 @@
 	if (!AUTH_set_supported_auth_types(pvar, type))
 		return FALSE;
 
+	SSH2_dispatch_add_message(SSH2_MSG_EXT_INFO);
+
 	SSH_notify_host_OK(pvar);
 
 
@@ -6600,6 +6608,60 @@
 	return do_SSH2_authrequest(pvar);
 }
 
+
+/*
+ * SSH_MSG_EXT_INFO:
+ *     byte       SSH_MSG_EXT_INFO (value 7)
+ *     uint32     nr-extensions
+ *     repeat the following 2 fields "nr-extensions" times:
+ *       string   extension-name
+ *       string   extension-value (binary)
+ */
+
+static BOOL handle_SSH2_ext_info(PTInstVar pvar)
+{
+	unsigned int num_of_exts, i, len;
+	unsigned char ext_name[256], ext_val[2048];
+	char *new_payload_buffer = NULL;
+
+	logputs(LOG_LEVEL_INFO, "SSH2_EXT_INFO was received.");
+
+	if (!get_uint32_from_payload(pvar, &num_of_exts)) {
+		logprintf(LOG_LEVEL_WARNING, "%s: ext info payload was corrupted", __FUNCTION__);
+		return FALSE;
+	}
+	logprintf(LOG_LEVEL_VERBOSE, "%s: %d extensions", __FUNCTION__, num_of_exts);
+
+	for (i=0; i<num_of_exts; i++) {
+		if (!get_string_from_payload(pvar, ext_name, sizeof(ext_name), &len, TRUE)) {
+			logprintf(LOG_LEVEL_WARNING, "%s: can't get extension name", __FUNCTION__);
+			return FALSE;
+		}
+		if (strcmp(ext_name, "server-sig-algs") == 0) {
+			if (!get_namelist_from_payload(pvar, ext_val, sizeof(ext_val), &len)) {
+				logprintf(LOG_LEVEL_WARNING, "%s: can't get extension value", __FUNCTION__);
+				return FALSE;
+			}
+			if (pvar->server_sig_algs) {
+				logprintf(LOG_LEVEL_WARNING, "%s: update server-sig-algs, old=%s, new=%s",
+				          __FUNCTION__, pvar->server_sig_algs, ext_val);
+				free(pvar->server_sig_algs);
+			}
+			pvar->server_sig_algs = strdup(ext_val);
+			logprintf(LOG_LEVEL_VERBOSE, "%s: extension: server-sig-algs, value: %s", __FUNCTION__, ext_val);
+		}
+		else {
+			if (!get_string_from_payload(pvar, ext_val, sizeof(ext_val), &len, TRUE)) {
+				logprintf(LOG_LEVEL_WARNING, "%s: can't get extension value", __FUNCTION__);
+				return FALSE;
+			}
+			logprintf(LOG_LEVEL_VERBOSE, "%s: extension: ext_name", __FUNCTION__, ext_name);
+		}
+	}
+
+	return TRUE;
+}
+
 // \x83\x86\x81[\x83U\x94F\x8F؃p\x83P\x83b\x83g\x82̍\\x92z
 BOOL do_SSH2_authrequest(PTInstVar pvar)
 {

Modified: trunk/ttssh2/ttxssh/ssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ssh.h	2022-07-17 15:39:21 UTC (rev 10065)
+++ trunk/ttssh2/ttxssh/ssh.h	2022-07-17 15:39:32 UTC (rev 10066)
@@ -132,6 +132,8 @@
 	SSH2_MSG_DEBUG           = 4,
 	SSH2_MSG_SERVICE_REQUEST = 5,
 	SSH2_MSG_SERVICE_ACCEPT  = 6,
+	SSH2_MSG_EXT_INFO        = 7, // RFC 8308
+	SSH2_MSG_NEWCOMPRESS     = 8, // RFC 8308
 
 	// 20..29 Algorithm negotiation (RFC 4253)
 	SSH2_MSG_KEXINIT = 20,

Modified: trunk/ttssh2/ttxssh/ttxssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.h	2022-07-17 15:39:21 UTC (rev 10065)
+++ trunk/ttssh2/ttxssh/ttxssh.h	2022-07-17 15:39:32 UTC (rev 10066)
@@ -349,6 +349,8 @@
 
 	bottom_half_known_hosts_t contents_after_known_hosts;
 
+	char *server_sig_algs;
+
 } TInstVar;
 
 // \x83o\x81[\x83W\x83\x87\x83\x93\x82ɍ\x87\x82킹\x82Ď\xA9\x93\xAE\x95ύX\x82\xB3\x82\xEA\x82\xE9\x81B \x97\xE1: TTSSH_2-81_TS_data


ttssh2-commit メーリングリストの案内
Back to archive index