[Ttssh2-commit] [6302] 下記に示すHMAC受信時エラーの問題調査のため、HMAC受信処理におけるエラーログを追加した。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2016年 2月 13日 (土) 23:52:14 JST


Revision: 6302
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6302
Author:   yutakapon
Date:     2016-02-13 23:52:14 +0900 (Sat, 13 Feb 2016)
Log Message:
-----------
下記に示すHMAC受信時エラーの問題調査のため、HMAC受信処理におけるエラーログを追加した。
TTSSH.LOGへのログ追加で、16進ダンプ出力ができる logprintf_hexdump() を新設した。

TTSSH Error: Detected Corrupted Data
http://logmett.com/support-forums/8/ttssh-error-detected-corrupted-data-2827

Modified Paths:
--------------
    trunk/ttssh2/ttxssh/crypt.c
    trunk/ttssh2/ttxssh/ttxssh.c
    trunk/ttssh2/ttxssh/ttxssh.h

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/crypt.c
===================================================================
--- trunk/ttssh2/ttxssh/crypt.c	2016-02-13 11:15:32 UTC (rev 6301)
+++ trunk/ttssh2/ttxssh/crypt.c	2016-02-13 14:52:14 UTC (rev 6302)
@@ -1038,7 +1038,7 @@
 // \x81\xA6\x96{\x8A֐\x94\x82\xCD SSH2 \x82ł̂ݎg\x97p\x82\xB3\x82\xEA\x82\xE9\x81B
 // (2004.12.17 yutaka)
 BOOL CRYPT_verify_receiver_MAC(PTInstVar pvar, uint32 sequence_number,
-                               char FAR * data, int len, char FAR * MAC)
+	char FAR * data, int len, char FAR * MAC)
 {
 	HMAC_CTX c;
 	unsigned char m[EVP_MAX_MD_SIZE];
@@ -1048,14 +1048,19 @@
 	mac = &pvar->ssh2_keys[MODE_IN].mac;
 
 	// HMAC\x82\xAA\x82܂\xBE\x97L\x8C\xF8\x82łȂ\xA2\x8Fꍇ\x82́A\x8C\x9F\x8F\xD8OK\x82Ƃ\xB5\x82ĕԂ\xB7\x81B
-	if (mac == NULL || mac->enabled == 0) 
+	if (mac == NULL || mac->enabled == 0)
 		return TRUE;
 
-	if (mac->key == NULL)
+	if (mac->key == NULL) {
+		logprintf(pvar, LOG_LEVEL_VERBOSE, "HMAC key is NULL(seq %lu len %d)", sequence_number, len);
 		goto error;
+	}
 
-	if ((u_int)mac->mac_len > sizeof(m))
+	if ((u_int)mac->mac_len > sizeof(m)) {
+		logprintf(pvar, LOG_LEVEL_VERBOSE, "HMAC len(%d) is larger than %d bytes(seq %lu len %d)", 
+			mac->mac_len, sizeof(m), sequence_number, len);
 		goto error;
+	}
 
 	HMAC_Init(&c, mac->key, mac->key_len, mac->md);
 	set_uint32_MSBfirst(b, sequence_number);
@@ -1065,6 +1070,9 @@
 	HMAC_cleanup(&c);
 
 	if (memcmp(m, MAC, mac->mac_len)) {
+		logprintf(pvar, LOG_LEVEL_VERBOSE, "HMAC key is not matched(seq %lu len %d)", sequence_number, len);
+		logprintf_hexdump(pvar, LOG_LEVEL_VERBOSE, m, mac->mac_len, "m:");
+		logprintf_hexdump(pvar, LOG_LEVEL_VERBOSE, MAC, mac->mac_len, "MAC:");
 		goto error;
 	}
 

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2016-02-13 11:15:32 UTC (rev 6301)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2016-02-13 14:52:14 UTC (rev 6302)
@@ -980,6 +980,87 @@
 	}
 }
 
+static void format_line_hexdump(char *buf, int buflen, int addr, int *bytes, int byte_cnt)
+{
+	int i, c;
+	char tmp[128];
+
+	buf[0] = 0;
+
+	/* \x90擪\x82̃A\x83h\x83\x8C\x83X\x95\\x8E\xA6 */
+	_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%08X : ", addr);
+	strncat_s(buf, buflen, tmp, _TRUNCATE);
+
+	/* \x83o\x83C\x83i\x83\x8A\x95\\x8E\xA6\x81i4\x83o\x83C\x83g\x82\xB2\x82Ƃɋ󔒂\xF0\x91}\x93\xFC\x81j*/
+	for (i = 0; i < byte_cnt; i++) {
+		if (i > 0 && i % 4 == 0) {
+			strncat_s(buf, buflen, " ", _TRUNCATE);
+		}
+
+		_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02X", bytes[i]);
+		strncat_s(buf, buflen, tmp, _TRUNCATE);
+	}
+
+	/* ASCII\x95\\x8E\xA6\x95\x94\x95\xAA\x82܂ł̋󔒂\xF0\x95₤ */
+	_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "   %*s%*s", (16 - byte_cnt) * 2 + 1, " ", (16 - byte_cnt + 3) / 4, " ");
+	strncat_s(buf, buflen, tmp, _TRUNCATE);
+
+	/* ASCII\x95\\x8E\xA6 */
+	for (i = 0; i < byte_cnt; i++) {
+		c = bytes[i];
+		if (isprint(c)) {
+			_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%c", c);
+			strncat_s(buf, buflen, tmp, _TRUNCATE);
+		}
+		else {
+			strncat_s(buf, buflen, ".", _TRUNCATE);
+		}
+	}
+
+	//strncat_s(buf, buflen, "\n", _TRUNCATE);
+}
+
+void logprintf_hexdump(PTInstVar pvar, int level, char *data, int len, char *fmt, ...)
+{
+	char buff[4096];
+	va_list params;
+	int c, addr;
+	int bytes[16], *ptr;
+	int byte_cnt;
+	int i;
+
+	if (level <= pvar->session_settings.LogLevel) {
+		va_start(params, fmt);
+		vsnprintf_s(buff, sizeof(buff), _TRUNCATE, fmt, params);
+		va_end(params);
+
+		notify_verbose_message(pvar, buff, level);
+
+		addr = 0;
+		byte_cnt = 0;
+		ptr = bytes;
+		for (i = 0; i < len; i++) {
+			c = data[i];
+			*ptr++ = c & 0xff;
+			byte_cnt++;
+
+			if (byte_cnt == 16) {
+				format_line_hexdump(buff, sizeof(buff), addr, bytes, byte_cnt);
+				notify_verbose_message(pvar, buff, level);
+
+				addr += 16;
+				byte_cnt = 0;
+				ptr = bytes;
+			}
+		}
+
+		if (byte_cnt > 0) {
+			format_line_hexdump(buff, sizeof(buff), addr, bytes, byte_cnt);
+			notify_verbose_message(pvar, buff, level);
+		}
+	}
+}
+
 static void PASCAL FAR TTXOpenTCP(TTXSockHooks FAR * hooks)
 {
 	if (pvar->settings.Enabled) {

Modified: trunk/ttssh2/ttxssh/ttxssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.h	2016-02-13 11:15:32 UTC (rev 6301)
+++ trunk/ttssh2/ttxssh/ttxssh.h	2016-02-13 14:52:14 UTC (rev 6302)
@@ -341,7 +341,9 @@
 void notify_fatal_error(PTInstVar pvar, char FAR * msg, BOOL send_disconnect);
 void notify_verbose_message(PTInstVar pvar, char FAR * msg, int level);
 void logprintf(PTInstVar pvar, int level, char *fmt, ...);
+void logprintf_hexdump(PTInstVar pvar, int level, char *data, int len, char *fmt, ...);
 
+
 void get_teraterm_dir_relative_name(char FAR * buf, int bufsize, char FAR * basename);
 int copy_teraterm_dir_relative_path(char FAR * dest, int destsize, char FAR * basename);
 void get_file_version(char *exefile, int *major, int *minor, int *release, int *build);



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