@@ -1269,6 +1269,56 @@ static __inline enum message_type infer_iso8583_message(const char *buf,
12691269 return MSG_REQUEST;
12701270}
12711271
1272+ // NetSign 签名验签协议推断
1273+ // TCP payload: msgSeq(2B) + outer_type(1B) + outer_len(10 ASCII digits) + inner TLVs + tail(4B)
1274+ // Inner TLV: tag(1B) + type(1B) + len(12 ASCII digits) + value
1275+ //
1276+ // Known processor names and their lengths:
1277+ // RAWSignProcessor (len=16): operation tag at byte[43], len field ends at byte[56]
1278+ // PBCRAWVerifyProcessor (len=21): operation tag at byte[48], len field ends at byte[61]
1279+ // operation len last byte: '7' → "request", '8' → "response"
1280+ static __inline enum message_type infer_net_sign_message (const char *buf,
1281+ size_t count,
1282+ struct conn_info_s
1283+ *conn_info)
1284+ {
1285+ if (!protocol_port_check_2 (PROTO_NET_SIGN, conn_info))
1286+ return MSG_UNKNOWN;
1287+ if (conn_info->tuple .l4_protocol != IPPROTO_TCP || count < 62 )
1288+ return MSG_UNKNOWN;
1289+ if (is_infer_socket_valid (conn_info->socket_info_ptr )) {
1290+ if (conn_info->socket_info_ptr ->l7_proto != PROTO_NET_SIGN)
1291+ return MSG_UNKNOWN;
1292+ }
1293+
1294+ // outer_len field [3..12] must be ASCII decimal digits
1295+ if (buf[3 ] < ' 0' || buf[3 ] > ' 9' )
1296+ return MSG_UNKNOWN;
1297+ // First inner TLV tag must be TAG_PROCESSOR_NAME (0x01)
1298+ if ((uint8_t )buf[13 ] != 0x01 )
1299+ return MSG_UNKNOWN;
1300+ // processorName len field [15..26]: leading bytes must be ASCII '0'
1301+ if (buf[15 ] != ' 0' || buf[24 ] != ' 0' )
1302+ return MSG_UNKNOWN;
1303+
1304+ // RAWSignProcessor: processorName len = 16, operation tag at [43]
1305+ if (buf[25 ] == ' 1' && buf[26 ] == ' 6' && (uint8_t )buf[43 ] == 0x02 ) {
1306+ if (buf[56 ] == ' 7' )
1307+ return MSG_REQUEST; // operation = "request"
1308+ if (buf[56 ] == ' 8' )
1309+ return MSG_RESPONSE; // operation = "response"
1310+ }
1311+ // PBCRAWVerifyProcessor: processorName len = 21, operation tag at [48]
1312+ if (buf[25 ] == ' 2' && buf[26 ] == ' 1' && (uint8_t )buf[48 ] == 0x02 ) {
1313+ if (buf[61 ] == ' 7' )
1314+ return MSG_REQUEST; // operation = "request"
1315+ if (buf[61 ] == ' 8' )
1316+ return MSG_RESPONSE; // operation = "response"
1317+ }
1318+
1319+ return MSG_UNKNOWN;
1320+ }
1321+
12721322#define CSTR_LEN (s ) (sizeof (s) / sizeof (char ) - 1 )
12731323#define CSTR_MASK (s ) ((~0ull ) >> (64 - CSTR_LEN(s) * 8 ))
12741324// convert const string with length <= 8 for matching
@@ -4145,6 +4195,14 @@ infer_protocol_2(const char *infer_buf, size_t count,
41454195 syscall_infer_len,
41464196 conn_info)) != MSG_UNKNOWN) {
41474197 inferred_message.protocol = PROTO_ISO8583;
4198+ #if defined(LINUX_VER_KFUNC) || defined(LINUX_VER_5_2_PLUS)
4199+ } else if (skip_proto != PROTO_NET_SIGN && (inferred_message.type =
4200+ #else
4201+ } else if ((inferred_message.type =
4202+ #endif
4203+ infer_net_sign_message (infer_buf,
4204+ count, conn_info)) != MSG_UNKNOWN) {
4205+ inferred_message.protocol = PROTO_NET_SIGN;
41484206#if defined(LINUX_VER_KFUNC) || defined(LINUX_VER_5_2_PLUS)
41494207 } else if (skip_proto != PROTO_MEMCACHED && (inferred_message.type =
41504208#else
@@ -4493,6 +4551,14 @@ infer_protocol_1(struct ctx_info_s *ctx,
44934551 return inferred_message;
44944552 }
44954553 break ;
4554+ case PROTO_NET_SIGN:
4555+ if ((inferred_message.type =
4556+ infer_net_sign_message (infer_buf, count,
4557+ conn_info)) != MSG_UNKNOWN) {
4558+ inferred_message.protocol = PROTO_NET_SIGN;
4559+ return inferred_message;
4560+ }
4561+ break ;
44964562 case PROTO_MEMCACHED:
44974563 if ((inferred_message.type =
44984564 infer_memcached_message (infer_buf, count,
0 commit comments