summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
author刘学利 <[email protected]>2021-08-23 11:15:11 +0000
committer刘学利 <[email protected]>2021-08-23 11:15:11 +0000
commitf68700112e61d6b920799a0cad54e1c2fe539b6e (patch)
tree2471cc1f228b0c847c0633309ed9d1ec17bd2179 /test
parent13ba53b5a9a6d11f4349f6b2ec0997db1d08283a (diff)
TSG-7298: QUIC解析层支持解析quic-ietf加密SNI
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt41
-rw-r--r--test/Makefile61
-rw-r--r--test/conflist.inf8
-rw-r--r--test/dpkt_plug_gquic.cpp118
-rw-r--r--test/dpkt_plug_gquic.h25
-rw-r--r--test/dpkt_plug_gquic.inf13
-rw-r--r--test/empty_array.json1
-rwxr-xr-xtest/pcap/1-iquic.pcapbin0 -> 73949 bytes
-rw-r--r--test/quic_result.json6
-rw-r--r--test/quic_test_plug.cpp91
-rw-r--r--test/quic_test_plug.inf11
-rw-r--r--test/test_protocol_run.zipbin0 -> 795325 bytes
12 files changed, 158 insertions, 217 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..4f07859
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,41 @@
+cmake_minimum_required (VERSION 2.8)
+
+set(lib_name quic)
+project(${lib_name}_test)
+
+include(ExternalProject)
+#### Protoco_test_run
+
+
+ExternalProject_Add(ProtoTest PREFIX ProtoTest
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/test_protocol_run.zip
+ URL_MD5 71d8284b59af0286b5f31f0a3160bc44
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/conf/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/bin/${lib_name}.conf <SOURCE_DIR>/conf/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/conflist.inf <SOURCE_DIR>/plug/
+ COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/plug/protocol/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/bin/${lib_name}.inf <SOURCE_DIR>/plug/protocol/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/plug/business/${lib_name}_test_plug/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/test/${lib_name}_test_plug.inf <SOURCE_DIR>/plug/business/${lib_name}_test_plug/)
+
+ExternalProject_Get_Property(ProtoTest INSTALL_DIR)
+ExternalProject_Get_Property(ProtoTest SOURCE_DIR)
+set(PROTO_TEST_RUN_DIR ${SOURCE_DIR})
+
+add_executable(proto_test_main IMPORTED GLOBAL)
+add_dependencies(proto_test_main ProtoTest)
+set_property(TARGET proto_test_main PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/test_protocol_plug_main)
+
+
+add_library(${lib_name}_test_plug SHARED ${lib_name}_test_plug.cpp)
+target_link_libraries(${lib_name}_test_plug MESA_prof_load cjson)
+set_target_properties(${lib_name}_test_plug PROPERTIES PREFIX "")
+
+add_test(NAME COPY_FTP_SO COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/${lib_name}.so ${PROTO_TEST_RUN_DIR}/plug/protocol/${lib_name}/${lib_name}.so")
+add_test(NAME COPY_TEST_SO COMMAND sh -c "cp ${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_test_plug.so ${PROTO_TEST_RUN_DIR}/plug/business/${lib_name}_test_plug/${lib_name}_test_plug.so")
+add_test(NAME QUIC_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/${lib_name}_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})
+
diff --git a/test/Makefile b/test/Makefile
deleted file mode 100644
index 124fb04..0000000
--- a/test/Makefile
+++ /dev/null
@@ -1,61 +0,0 @@
-CC = gcc
-CCC = g++
-
-INCLUDES += -I/opt/MESA/include/
-LIB = -L./opt/MESA/lib/ -lpthread
-CFLAGS = -g3 -Wall -fPIC
-CFLAGS += $(INCLUDES)
-
-TARGET = dpkt_plug_gquic.so
-INF = dpkt_plug_gquic.inf
-INSTALL_TARGET=$(TARGET)
-LIB_FILE = $(wildcard ../lib/*.a)
-SOURCES = $(wildcard *.cpp)
-OBJECTS = $(SOURCES:.cpp=.o)
-DEPS = $(SOURCES:.cpp=.d)
-
-INF=dpkt_plug_gquic.inf
-INSTALL_TARGET=dpkt_plug_gquic.so
-# $(CONF)
-INSTALL_DIR=/home/mesasoft/sapp/plug/business/dpkt_plug_gquic/
-
-all:$(TARGET)
-$(TARGET):$(OBJECTS) $(LIB_FILE)
- $(CCC) -shared $(CFLAGS) $(OBJECTS) $(LIB) -o $@
- mkdir -p $(INSTALL_DIR)
- cp -r $(INSTALL_TARGET) $(INF) $(INSTALL_DIR) -f
-# cp $(TARGET) ../bin/
-
-.c.o:
-%.d:%.c
- $(CCC) $< -MM $(INCLUDES) > $@
-
-%.o:%.cpp
- $(CCC) -c -o $@ $(CFLAGS) $< $(INCLUDES)
-
--include $(DEPS)
-
-clean :
- rm -f $(OBJECTS) $(DEPS) $(TARGET)
-
-PLUGIN_PATH=./plug/business
-CONFLIST_NAME=conflist_business.inf
-PLUGIN_DIR_NAME=dpkt_plug_gquic
-PLUGIN_INF_NAME=dpkt_plug_gquic.inf
-PAPP_PATH=/home/dk/gitFile/ceiec/sapp
-
-TARGET_DIR=$(PAPP_PATH)/$(PLUGIN_PATH)/$(PLUGIN_DIR_NAME)/
-INSERT_FILE=$(PAPP_PATH)/$(PLUGIN_PATH)/$(CONFLIST_NAME)
-INSERT_CONTENT=$(PLUGIN_PATH)/$(PLUGIN_DIR_NAME)/$(PLUGIN_INF_NAME)
-install:
- mkdir -p $(TARGET_DIR)
- cp -r ../bin/*.inf $(TARGET_DIR)
- cp -r ../bin/*.so $(TARGET_DIR)
- cp -r ../bin/*.conf $(TARGET_DIR)
- @ret=`cat $(INSERT_FILE)|grep $(INSERT_CONTENT)|wc -l`;if [ $$ret -eq 0 ];then echo $(INSERT_CONTENT) >>$(INSERT_FILE);fi
-
-CONF_DIR=$(PAPP_PATH)/conf/
-conf:
- mkdir -p $(CONF_DIR)
- cp -r ../bin/quic $(CONF_DIR)
-
diff --git a/test/conflist.inf b/test/conflist.inf
new file mode 100644
index 0000000..bf103c3
--- /dev/null
+++ b/test/conflist.inf
@@ -0,0 +1,8 @@
+[platform]
+
+[protocol]
+./plug/protocol/quic/quic.inf
+
+
+[business]
+./plug/business/quic_test_plug/quic_test_plug.inf
diff --git a/test/dpkt_plug_gquic.cpp b/test/dpkt_plug_gquic.cpp
deleted file mode 100644
index 276f978..0000000
--- a/test/dpkt_plug_gquic.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-
-#include "dpkt_plug_gquic.h"
-
-#include <stdio.h>
-#include <dlfcn.h>
-#include "gquic.h"
-
-
-void a_ntoa( unsigned int in, char *buffer)
-{
- unsigned char *bytes = (unsigned char *) &in;
- int i = snprintf( buffer, 15, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
-}
-
-int DPKT_GQUIC_INIT()
-{
- int plugid = DK_PLUGID_GQUIC;
- return plugid;
-}
-
-void DPKT_GQUIC_DESTROY()
-{
- return;
-}
-
-
-char DPKT_GQUIC_ENTRY(stSessionInfo* session_info, void **pme, int _thread_num, struct streaminfo *pstream, void *a_packet)
-{
- int thread_num = pstream->threadnum;
-
- if(session_info->session_state & SESSION_STATE_CLOSE)
- {
- return PROT_STATE_GIVEME;
- }
-
- if(session_info->app_info ==NULL)
- {
- return PROT_STATE_GIVEME;
- }
-
- if(session_info->prot_flag == QUIC_CLIENT_HELLO){
- printf("DPKT_QUIC_ENTRY\tQUIC_CLIENT_HELLO\n");
- struct quic_stream *quic = (struct quic_stream*)session_info->app_info;
- if(quic){
- struct quic_client_hello client_hello = quic->st_client_hello;
-
- printf("BUSINESS PLUG:QUIC_CLIENT_HELLO ext_tag_num=%d--------------------\n",client_hello.ext_tag_num);
- if(quic->version){
- printf("BUSINESS PLUG:QUIC_CLIENT_HELLO version=%d--------------------\n",quic->version);
-
- }
- if(client_hello.server_name){
- printf("BUSINESS PLUG:QUIC_CLIENT_HELLO server_name=%s--------------------\n",client_hello.server_name);
-
- }
- if(client_hello.user_agent){
- printf("BUSINESS PLUG:QUIC_CLIENT_HELLO user_agent=%s--------------------\n",client_hello.user_agent);
- }
- }
- }
-
-
- int i = 0, j = 0;
- if(session_info->prot_flag == QUIC_VERSION){
- printf("DPKT_QUIC_ENTRY\tQUIC_VERSION\n");
- struct quic_stream *quic = (struct quic_stream*)session_info->app_info;
- if(quic){
- printf("version:%d\n",quic->version);
- }
- }
-
- if(session_info->prot_flag == QUIC_SERVER_HELLO){
- printf("DPKT_QUIC_ENTRY\tQUIC_SERVER_HELLO\n");
- struct quic_stream *quic = (struct quic_stream*)session_info->app_info;
- struct quic_server_hello server_hello = quic->st_server_hello;
- printf("BUSINESS PLUG:QUIC_SERVER_HELLO ext_tag_num=%d--------------------\n",server_hello.ext_tag_num);
- }
-
- if(session_info->prot_flag == QUIC_CACHED_CERT){
- printf("DPKT_QUIC_ENTRY\tQUIC_CACHED_CERT\n");
- struct quic_stream *quic = (struct quic_stream*)session_info->app_info;
- quic_tlv_t cached_cert = quic->cached_cert;
- printf("--------------------BUSINESS PLUG:QUIC_CACHED_CERT cached_cert_length=%d--------------------\n",cached_cert.length);
- for(i = 0; i < cached_cert.length; i++){
- printf("%02X",((unsigned char*)cached_cert.ptr_value)[i]);
- }
- printf("----------------------------------------\n");
- }
-
- if(session_info->prot_flag == QUIC_COMM_CERT){
- printf("DPKT_QUIC_ENTRY\tQUIC_COMM_CERT\n");
- struct quic_stream *quic = (struct quic_stream*)session_info->app_info;
- quic_tlv_t comm_cert = quic->common_cert;
- printf("--------------------BUSINESS PLUG:QUIC_COMM_CERT common_cert_length=%d--------------------\n",comm_cert.length);
- for(i = 0; i < comm_cert.length; i++){
- printf("%02X",((unsigned char*)comm_cert.ptr_value)[i]);
- }
- printf("--------------------T--------------------\n");
- }
-
- if(session_info->prot_flag == QUIC_CERT_CHAIN){
- printf("DPKT_QUIC_ENTRY\tQUIC_CERT_CHAIN\n");
- struct quic_stream *quic = (struct quic_stream*)session_info->app_info;
- quic_tlv_t cert_chain = quic->cert_chain;
- printf("--------------------BUSINESS PLUG:QUIC_CERT_CHAIN cert_chain_length=%d--------------------\n",cert_chain.length);
- for(i = 0; i < cert_chain.length; i++){
- printf("%02X",((unsigned char*)cert_chain.ptr_value)[i]);
- }
- printf("----------------------------------------\n");
- }
-
-
- return PROT_STATE_GIVEME;
-
-}
-
-
-
diff --git a/test/dpkt_plug_gquic.h b/test/dpkt_plug_gquic.h
deleted file mode 100644
index 867f143..0000000
--- a/test/dpkt_plug_gquic.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * dk_plug_quic.h
- *
- * Created on:
- * Author: root
- */
-
-#ifndef SRC_DPKT_PLUG_QUIC_H_
-#define SRC_DPKT_PLUG_QUIC_H_
-
-#include "stream.h"
-
-#define DK_PLUGID_GQUIC 1003
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int DPKT_GQUIC_INIT();
-void DPKT_GQUIC_DESTROY();
-char DPKT_GQUIC_ENTRY(stSessionInfo* session_info, void **pme, int _thread_num, struct streaminfo *pstream, void *a_packet);
-
-#ifdef __cplusplus
- }
-#endif
-#endif /* SRC_DPKT_PLUG_QUIC_H_ */
diff --git a/test/dpkt_plug_gquic.inf b/test/dpkt_plug_gquic.inf
deleted file mode 100644
index cb2c2c4..0000000
--- a/test/dpkt_plug_gquic.inf
+++ /dev/null
@@ -1,13 +0,0 @@
-[PLUGINFO]
-PLUGNAME=dpkt_plug_gquic
-SO_PATH=./plug/business/dpkt_plug_gquic/dpkt_plug_gquic.so
-INIT_FUNC=DPKT_GQUIC_INIT
-DESTROY_FUNC=DPKT_GQUIC_DESTROY
-
-[QUIC]
-#FUNC_FLAG=QUIC_CLIENT_HELLO,QUIC_SERVER_HELLO,QUIC_CACHED_CERT,QUIC_COMM_CERT,QUIC_CERT_CHAIN,QUIC_VERSION,QUIC_APPLICATION_DATA
-
-FUNC_FLAG=QUIC_CLIENT_HELLO
-FUNC_NAME=DPKT_GQUIC_ENTRY
-
-
diff --git a/test/empty_array.json b/test/empty_array.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/test/empty_array.json
@@ -0,0 +1 @@
+[] \ No newline at end of file
diff --git a/test/pcap/1-iquic.pcap b/test/pcap/1-iquic.pcap
new file mode 100755
index 0000000..dcd22db
--- /dev/null
+++ b/test/pcap/1-iquic.pcap
Binary files differ
diff --git a/test/quic_result.json b/test/quic_result.json
new file mode 100644
index 0000000..b536765
--- /dev/null
+++ b/test/quic_result.json
@@ -0,0 +1,6 @@
+[{
+ "Tuple4": "192.168.50.29.61891>31.13.77.35.443",
+ "VERSION": "IETF QUIC 29",
+ "SNI": "www.facebook.com",
+ "name": "QUIC_RESULT_1"
+ }]
diff --git a/test/quic_test_plug.cpp b/test/quic_test_plug.cpp
new file mode 100644
index 0000000..1c0ffcb
--- /dev/null
+++ b/test/quic_test_plug.cpp
@@ -0,0 +1,91 @@
+/*
+ * author:yangwei
+ * create time:2021-8-21
+ *
+ */
+
+
+
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "cJSON.h"
+#include "gquic.h"
+#include "MESA_prof_load.h"
+#include <MESA/stream.h>
+
+extern "C" int commit_test_result_json(cJSON *node, const char *name);
+
+static int g_result_count = 1;
+
+extern "C" unsigned char QUIC_TEST_PLUG_ENTRY(stSessionInfo *session_info, void **pme,
+ int thread_seq, struct streaminfo *a_tcp, void *a_packet)
+{
+ assert(NULL != session_info || pme != NULL);
+
+ cJSON *ctx = (cJSON *)*pme;
+ struct _quic_info *quic_info=NULL;
+ char version_str[128]={0};
+ unsigned int version = 0;
+
+ if (session_info->session_state & SESSION_STATE_PENDING)
+ {
+ if (*pme == NULL)
+ {
+ ctx = cJSON_CreateObject();
+ *pme = (void *)ctx;
+ cJSON_AddStringToObject(ctx, "Tuple4", printaddr(&a_tcp->addr, a_tcp->threadnum));
+ }
+ }
+
+ switch (session_info->prot_flag)
+ {
+ case QUIC_CLIENT_HELLO:
+ if (session_info == NULL || session_info->app_info == NULL)
+ {
+ break;
+ }
+ quic_info = (struct _quic_info *)session_info->app_info;
+ cJSON_AddStringToObject(ctx, "SNI", (char *)(quic_info->client_hello->ext_tags[quic_info->client_hello->sni_idx].value));
+ break;
+ case QUIC_USEING_VERSION:
+ version = *(unsigned int *)(session_info->buf);
+ quic_version_int2string(version, version_str, sizeof(version_str));
+ cJSON_AddStringToObject(ctx, "VERSION", version_str);
+ break;
+ default:
+ break;
+ }
+
+ if(session_info->session_state&SESSION_STATE_CLOSE)
+ {
+ if(ctx)
+ {
+ char result_name[16]="";
+ sprintf(result_name,"QUIC_RESULT_%d", g_result_count);
+ commit_test_result_json(ctx, result_name);
+ g_result_count+=1;
+ }
+ *pme = NULL;
+ return PROT_STATE_DROPME;
+
+ }
+
+ return PROT_STATE_GIVEME;
+
+}
+
+extern "C" int QUIC_TEST_PLUG_INIT()
+{
+ return 0;
+}
+
+extern "C" void QUIC_TEST_PLUG_DESTROY(void)
+{
+ return ;
+}/*CHAR_DESTRORY*/
+
+
+
diff --git a/test/quic_test_plug.inf b/test/quic_test_plug.inf
new file mode 100644
index 0000000..53a66c1
--- /dev/null
+++ b/test/quic_test_plug.inf
@@ -0,0 +1,11 @@
+[PLUGINFO]
+PLUGNAME=QUIC_TEST_PLUG
+SO_PATH=./plug/business/quic_test_plug/quic_test_plug.so
+INIT_FUNC=QUIC_TEST_PLUG_INIT
+DESTROY_FUNC=QUIC_TEST_PLUG_DESTROY
+
+[QUIC]
+FUNC_FLAG=QUIC_CLIENT_HELLO,QUIC_SERVER_HELLO,QUIC_CACHED_CERT,QUIC_COMM_CERT,QUIC_CERT_CHAIN,QUIC_VERSION,QUIC_APPLICATION_DATA
+FUNC_NAME=QUIC_TEST_PLUG_ENTRY
+
+
diff --git a/test/test_protocol_run.zip b/test/test_protocol_run.zip
new file mode 100644
index 0000000..996f3fa
--- /dev/null
+++ b/test/test_protocol_run.zip
Binary files differ