summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author贺岚风 <[email protected]>2024-09-11 14:22:13 +0800
committer贺岚风 <[email protected]>2024-09-11 14:33:55 +0800
commitcbffc08893e073447283ef7646fc33766bd7ae09 (patch)
treec694f0c52f741210ef9cff5d7d4767add9fa9f46
parent58e00281ba3d6fc549a3a2b5fc5cce7c394c4c44 (diff)
add dtls_msg APPLICATION_START and APPLICATION_END
-rw-r--r--decoders/dtls/dtls_parse.c18
-rw-r--r--decoders/dtls/dtls_parse.h1
-rw-r--r--decoders/dtls/dtls_plugin.c6
-rw-r--r--decoders/dtls/test/dtls_decoder_gtest.cpp7
-rw-r--r--include/stellar/dtls.h6
-rw-r--r--test/decoders/dtls/dtls_decoder_test_plug.cpp11
-rw-r--r--test/decoders/dtls/pcap/1_dtls_with_sni.json3
-rw-r--r--test/decoders/dtls/pcap/2_dtls_with_stun.json3
-rw-r--r--test/decoders/dtls/pcap/3_dtls_only_client_hello_with_sni.json3
-rw-r--r--test/decoders/dtls/pcap/4_dtls_only_client_hello.json3
-rw-r--r--test/decoders/dtls/pcap/5_dtls_handshake.json3
-rw-r--r--test/decoders/dtls/pcap/6_dtls_application.json3
-rw-r--r--test/decoders/dtls/pcap/7_sni_len_is_0.json3
13 files changed, 55 insertions, 15 deletions
diff --git a/decoders/dtls/dtls_parse.c b/decoders/dtls/dtls_parse.c
index 84863c1..cc9491b 100644
--- a/decoders/dtls/dtls_parse.c
+++ b/decoders/dtls/dtls_parse.c
@@ -592,10 +592,18 @@ int32_t dtls_parser_handshake(struct session *sess, struct dtls_parse_ctx **pars
return ret;
}
-int32_t dtls_parser_application_data(struct session *sess, struct dtls_header *header, struct dtls_message *dtls_msg, void *logger)
+int32_t dtls_parser_application_data(struct session *sess, struct dtls_header *header,
+ struct dtls_parse_ctx **parse_ctx, struct dtls_message *dtls_msg, void *logger)
{
(void)sess;
(void)logger;
+
+ struct dtls_parse_ctx *ctx = *parse_ctx;
+ if(ctx == NULL) {
+ ctx = (struct dtls_parse_ctx *)calloc(1, sizeof(struct dtls_parse_ctx));
+ *parse_ctx = ctx;
+ }
+
struct dtls_application_data_info *app_info = (struct dtls_application_data_info *)calloc(1, sizeof(struct dtls_application_data_info));
app_info->version_str = get_version_name(header->version);
app_info->application_data_length = header->length;
@@ -603,6 +611,10 @@ int32_t dtls_parser_application_data(struct session *sess, struct dtls_header *h
dtls_msg->msg_type = DTLS_MSG_TYPE_APPLICATION_DATA;
dtls_msg->msg_content = app_info;
+ if(ctx->application_start == 0) {
+ dtls_msg->msg_type = DTLS_MSG_TYPE_APPLICATION_DATA_START;
+ ctx->application_start = 1;
+ }
return DTLS_PARSER_OK;
}
@@ -656,7 +668,7 @@ int8_t dtls_parser_entry(struct session *sess, struct dtls_parse_ctx **parse_ctx
break;
}
} else if(DTLS_CONTENT_TYPE_APPLICATION_DATA == header.content_type) {
- dtls_parser_application_data(sess, &header, dtls_msg, logger);
+ dtls_parser_application_data(sess, &header, parse_ctx, dtls_msg, logger);
break;
} else {
STELLAR_LOG_INFO(logger, "dtls_header", "[%s] This content_type:%d is not supported.",
@@ -961,7 +973,7 @@ const char *dtls_message_get0_application_data(struct dtls_message *dtls_msg, si
return NULL;
}
- if(dtls_msg->msg_type != DTLS_MSG_TYPE_APPLICATION_DATA) {
+ if(dtls_msg->msg_type != DTLS_MSG_TYPE_APPLICATION_DATA && dtls_msg->msg_type != DTLS_MSG_TYPE_APPLICATION_DATA_START) {
return NULL;
}
diff --git a/decoders/dtls/dtls_parse.h b/decoders/dtls/dtls_parse.h
index bb12b8a..eb91dda 100644
--- a/decoders/dtls/dtls_parse.h
+++ b/decoders/dtls/dtls_parse.h
@@ -218,6 +218,7 @@ struct dtls_fragment
struct dtls_parse_ctx
{
+ uint32_t application_start;
struct dtls_fragment *fragments_head;
};
diff --git a/decoders/dtls/dtls_plugin.c b/decoders/dtls/dtls_plugin.c
index 6025a1c..bc165e4 100644
--- a/decoders/dtls/dtls_plugin.c
+++ b/decoders/dtls/dtls_plugin.c
@@ -112,6 +112,12 @@ void dtls_decoder_on_message(struct session *sess, int topic_id, const void *msg
}
break;
+ case SESSION_STATE_CLOSED:
+ {
+ struct dtls_message *send_msg = (struct dtls_message *)calloc(1, sizeof(struct dtls_message));
+ send_msg->msg_type = DTLS_MSG_TYPE_APPLICATION_DATA_END;
+ session_mq_publish_message(sess, dtls_plugin_cfg->pub_topic_id, send_msg);
+ }
default:
return;
}
diff --git a/decoders/dtls/test/dtls_decoder_gtest.cpp b/decoders/dtls/test/dtls_decoder_gtest.cpp
index 44ca97c..cae6a51 100644
--- a/decoders/dtls/test/dtls_decoder_gtest.cpp
+++ b/decoders/dtls/test/dtls_decoder_gtest.cpp
@@ -3,7 +3,6 @@
#include <stdio.h>
#include "stellar/dtls.h"
-
#ifdef __cplusplus
extern "C"
{
@@ -15,6 +14,7 @@ extern int32_t dtls_parser_handshake_header(const uint8_t *dtls_payload, uint32_
struct dtls_parse_ctx **parse_ctx, struct dtls_handshake *handshake_hs, void *logger);
extern int dtls_try_assemble_fragments(struct dtls_parse_ctx **parse_ctx, struct dtls_handshake *handshake_hs);
extern int32_t dtls_parser_hello(struct session *sess, struct dtls_handshake *handshake, struct dtls_message *dtls_msg, void *logger);
+extern void *dtls_decoder_session_ctx_new(struct session *sess, void *plugin_env);
extern void dtls_decoder_session_ctx_free(struct session *sess, void *session_ctx, void *plugin_env);
#ifdef __cplusplus
}
@@ -118,7 +118,10 @@ TEST(dtls_decoder, dtls_try_assemble_fragments)
sni_str[sni_sz] = '\0';
EXPECT_STREQ(sni_str, "localhost");
- dtls_decoder_session_ctx_free(NULL, parse_ctx, NULL);
+ free(dtls_msg.msg_content);
+ free(parse_ctx->fragments_head->fragment_content);
+ free(parse_ctx->fragments_head);
+ free(parse_ctx);
return ;
}
diff --git a/include/stellar/dtls.h b/include/stellar/dtls.h
index 08b231b..ff14fff 100644
--- a/include/stellar/dtls.h
+++ b/include/stellar/dtls.h
@@ -16,9 +16,9 @@ enum dtls_message_type
DTLS_MSG_TYPE_CLIENT_HELLO = 0, //inlcude sni
DTLS_MSG_TYPE_SERVER_HELLO,
DTLS_MSG_TYPE_HELLO_VERIFY_REQUEST,
- // DTLS_MSG_TYPE_APPLICATION_DATA_START, //inlcude application_data
+ DTLS_MSG_TYPE_APPLICATION_DATA_START, //inlcude application_data
DTLS_MSG_TYPE_APPLICATION_DATA,
- // DTLS_MSG_TYPE_APPLICATION_DATA_END,
+ DTLS_MSG_TYPE_APPLICATION_DATA_END,
DTLS_MSG_TYPE_UNKNOWN,
};
@@ -75,7 +75,7 @@ void dtls_message_get_compression_methods(struct dtls_message *dtls_msg, uint8_t
void dtls_message_get_extensions(struct dtls_message *dtls_msg, uint16_t **type, char ***value, size_t **value_sz, size_t *n_extensions);
-//application data
+//application data start and application data
const char *dtls_message_get0_application_data(struct dtls_message *dtls_msg, size_t *application_data_sz);
#ifdef __cplusplus
diff --git a/test/decoders/dtls/dtls_decoder_test_plug.cpp b/test/decoders/dtls/dtls_decoder_test_plug.cpp
index c91472b..e97d5d3 100644
--- a/test/decoders/dtls/dtls_decoder_test_plug.cpp
+++ b/test/decoders/dtls/dtls_decoder_test_plug.cpp
@@ -176,6 +176,8 @@ static void dtls_record_server_hello(struct dtls_message *dtls_msg, cJSON *log)
cJSON_AddItemToArray(cipher_suites_array, cJSON_CreateString(cipher_suites[i]));
}
cJSON_AddItemToObject(log, "server_hello_cipher_suites", cipher_suites_array);
+ free(cipher_suites);
+ free(cipher_suites_sz);
char **compression_methods = NULL;
size_t *compression_methods_sz = NULL;
@@ -186,6 +188,8 @@ static void dtls_record_server_hello(struct dtls_message *dtls_msg, cJSON *log)
cJSON_AddItemToArray(compression_methods_array, cJSON_CreateString(compression_methods[i]));
}
cJSON_AddItemToObject(log, "server_hello_compression_methods", compression_methods_array);
+ free(compression_methods);
+ free(compression_methods_sz);
char **extensions = NULL;
size_t *extensions_sz = NULL;
@@ -196,6 +200,9 @@ static void dtls_record_server_hello(struct dtls_message *dtls_msg, cJSON *log)
cJSON_AddItemToArray(extensions_array, cJSON_CreateString(extensions[i]));
}
cJSON_AddItemToObject(log, "server_hello_extensions", extensions_array);
+ free(extensions);
+ free(extensions_sz);
+
return;
}
@@ -251,12 +258,16 @@ extern "C" void dtls_decoder_test_entry(struct session *sess, int topic_id, cons
case DTLS_MSG_TYPE_HELLO_VERIFY_REQUEST:
dtls_record_hello_verify_req(dtls_msg, json_root);
break;
+ case DTLS_MSG_TYPE_APPLICATION_DATA_START:
case DTLS_MSG_TYPE_APPLICATION_DATA:
if(test_ctx->application_flag == 0) {
dtls_record_application_data(dtls_msg, json_root);
test_ctx->application_flag = 1;
}
break;
+ case DTLS_MSG_TYPE_APPLICATION_DATA_END:
+ cJSON_AddStringToObject(json_root, "test_result:", session_get0_readable_addr(sess));
+ break;
default:
break;
}
diff --git a/test/decoders/dtls/pcap/1_dtls_with_sni.json b/test/decoders/dtls/pcap/1_dtls_with_sni.json
index 7259089..9631bb5 100644
--- a/test/decoders/dtls/pcap/1_dtls_with_sni.json
+++ b/test/decoders/dtls/pcap/1_dtls_with_sni.json
@@ -19,5 +19,6 @@
"server_hello_compression_methods": ["No Compression"],
"server_hello_extensions": ["renegotiation_info", "ec_point_formats", "session_ticket", "extended_master_secret"],
"application_data_size": 124,
- "application_data": "b2a4a9a5db212218410d1f9a10ee6a27"
+ "application_data": "b2a4a9a5db212218410d1f9a10ee6a27",
+ "test_result:": "192.168.44.32:39336-192.168.40.131:23232-17-0"
}] \ No newline at end of file
diff --git a/test/decoders/dtls/pcap/2_dtls_with_stun.json b/test/decoders/dtls/pcap/2_dtls_with_stun.json
index 79df983..127e6f7 100644
--- a/test/decoders/dtls/pcap/2_dtls_with_stun.json
+++ b/test/decoders/dtls/pcap/2_dtls_with_stun.json
@@ -10,5 +10,6 @@
"server_hello_compression_methods": ["No Compression"],
"server_hello_extensions": ["extended_master_secret", "renegotiation_info", "ec_point_formats", "session_ticket", "use_srtp"],
"application_data_size": 68,
- "application_data": "00010000000000010809043303319505"
+ "application_data": "00010000000000010809043303319505",
+ "test_result:": "192.168.56.33:56076-117.167.196.106:27357-17-0"
}]
diff --git a/test/decoders/dtls/pcap/3_dtls_only_client_hello_with_sni.json b/test/decoders/dtls/pcap/3_dtls_only_client_hello_with_sni.json
index e941cfb..4d08e38 100644
--- a/test/decoders/dtls/pcap/3_dtls_only_client_hello_with_sni.json
+++ b/test/decoders/dtls/pcap/3_dtls_only_client_hello_with_sni.json
@@ -7,5 +7,6 @@
"client_hello_extensions": ["server_name", "encrypt_then_mac", "signature_algorithms"],
"client_hello_sni": "hangzhou.ciscovnp.com",
"application_data_size": 1331,
- "application_data": "0001000000000004c7ffffdadf5a4ea8"
+ "application_data": "0001000000000004c7ffffdadf5a4ea8",
+ "test_result:": "10.90.141.219:54122-106.14.18.226:443-17-0"
}]
diff --git a/test/decoders/dtls/pcap/4_dtls_only_client_hello.json b/test/decoders/dtls/pcap/4_dtls_only_client_hello.json
index 0ddb2af..fb6a99e 100644
--- a/test/decoders/dtls/pcap/4_dtls_only_client_hello.json
+++ b/test/decoders/dtls/pcap/4_dtls_only_client_hello.json
@@ -5,5 +5,6 @@
"client_hello_compression_methods": ["No Compression"],
"client_hello_extensions": ["extended_master_secret", "renegotiation_info", "supported_groups", "ec_point_formats", "session_ticket", "signature_algorithms", "use_srtp"],
"application_data_size": 60,
- "application_data": "494535324075fb8c628e5f9d5e3da0ec"
+ "application_data": "494535324075fb8c628e5f9d5e3da0ec",
+ "test_result:": "10.92.137.247:63120-223.64.32.252:18407-17-0"
}]
diff --git a/test/decoders/dtls/pcap/5_dtls_handshake.json b/test/decoders/dtls/pcap/5_dtls_handshake.json
index d8bd814..e9cccea 100644
--- a/test/decoders/dtls/pcap/5_dtls_handshake.json
+++ b/test/decoders/dtls/pcap/5_dtls_handshake.json
@@ -11,5 +11,6 @@
"server_hello_compression_methods": ["No Compression"],
"server_hello_extensions": ["renegotiation_info", "ec_point_formats", "session_ticket", "extended_master_secret"],
"application_data_size": 76,
- "application_data": "6db70eaa347fa330e8bfce40909e1d5b"
+ "application_data": "6db70eaa347fa330e8bfce40909e1d5b",
+ "test_result:": "10.88.221.238:42982-123.60.18.122:3478-17-0"
}] \ No newline at end of file
diff --git a/test/decoders/dtls/pcap/6_dtls_application.json b/test/decoders/dtls/pcap/6_dtls_application.json
index d226268..ee9885a 100644
--- a/test/decoders/dtls/pcap/6_dtls_application.json
+++ b/test/decoders/dtls/pcap/6_dtls_application.json
@@ -1,4 +1,5 @@
[{
"application_data_size": 60,
- "application_data": "c2a2ea09b85ae5bc51b36fe7f1efb98b"
+ "application_data": "c2a2ea09b85ae5bc51b36fe7f1efb98b",
+ "test_result:": "192.168.64.38:58756-180.213.87.11:7517-17-0"
}] \ No newline at end of file
diff --git a/test/decoders/dtls/pcap/7_sni_len_is_0.json b/test/decoders/dtls/pcap/7_sni_len_is_0.json
index 0f984b9..867e70a 100644
--- a/test/decoders/dtls/pcap/7_sni_len_is_0.json
+++ b/test/decoders/dtls/pcap/7_sni_len_is_0.json
@@ -3,5 +3,6 @@
"server_hello_random": "a3941a47f9b6421c1eacb5c19818f599990c7e08f5c2d37809676926",
"server_hello_cipher_suites": ["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],
"server_hello_compression_methods": ["No Compression"],
- "server_hello_extensions": ["renegotiation_info", "server_name", "ec_point_formats", "session_ticket"]
+ "server_hello_extensions": ["renegotiation_info", "server_name", "ec_point_formats", "session_ticket"],
+ "test_result:": "10.126.166.84:64247-165.225.117.2:443-17-0"
}] \ No newline at end of file