first add

This commit is contained in:
liumengyan
2020-05-12 12:18:02 +08:00
commit c0ed0eb78f
17 changed files with 2676 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
Debug
bin
*.o
*.d
*.so
.cproject
.project
.settings/

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# gquic
gquic protocol parse plugin

55
src/Makefile Normal file
View File

@@ -0,0 +1,55 @@
CC = gcc
CCC = g++
INCLUDES = -I/opt/MESA/include/ -I/home/sjzn/workspace/iquic_ngtcp2/openssl/build/include
LIB = -L./opt/MESA/lib/ -L/home/sjzn/workspace/iquic_ngtcp2/openssl/build/lib -lssl -lcrypto
#CFLAGS = -g3 -Wall -fPIC $(INCLUDES)
#CCCFLAGS = -std=c++11 -g3 -Wall -fPIC $(INCLUDES)
CFLAGS = -g3 -Wall -fPIC
CCCFLAGS = -std=c++11 -g3 -Wall -fPIC
TARGET = quic.so
INF = quic.inf
INSTALL_TARGET=$(TARGET)
LIB_FILE = $(wildcard ../lib/*.a)
SOURCES = $(wildcard *.c) $(wildcard gquic/*.c)
OBJECTS = $(SOURCES:.c=.o)
DEPS = $(SOURCES:.c=.d)
all:$(TARGET)
$(TARGET):$(OBJECTS) $(LIB_FILE)
$(CCC) -shared $(CFLAGS) $(OBJECTS) $(LIB) -o $@
cp $(TARGET) ../bin/
%.o:%.c
$(CC) -c -o $@ $(CFLAGS) $< $(INCLUDES)
%.o:%.cpp
$(CCC) -c -o $@ $(CCCFLAGS) $< $(INCLUDES)
-include $(DEPS)
clean :
rm -f $(OBJECTS) $(DEPS) $(TARGET)
help:
@echo "-------OBJECTS--------" $(OBJECTS)
PLUGIN_PATH=./plug/protocol
CONFLIST_NAME=conflist_protocol.inf
PLUGIN_DIR_NAME=quic
PLUGIN_INF_NAME=quic.inf
PAPP_PATH=/home/sjzn/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)
@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)

107
src/gquic.h Normal file
View File

@@ -0,0 +1,107 @@
/*
* quic.h
*
* Created on: 2019-4-4
* Author: root
*/
#ifndef SRC_GQUIC_H_
#define SRC_GQUIC_H_
//#include <stream.h>
#include <MESA/stream.h>
#define MAX_EXTENSION_NUM 128
#define MAX_TAG_VALUE_LEN 257
#define SERVER_NAME_LEN 128
//add in 20191207
#define USER_AGENT_LEN 512
#define RANDOM_LEN 32
#define QUIC_VERSION_LEN 4
#define QUIC_INTEREST_KEY (1<<QUIC_INTEREST_KEY_MASK)
#define QUIC_CLIENT_HELLO (1<<QUIC_CLIENT_HELLO_MASK)
#define QUIC_SERVER_HELLO (1<<QUIC_SERVER_HELLO_MASK)
#define QUIC_CACHED_CERT (1<<QUIC_CACHED_CERT_MASK)
#define QUIC_COMM_CERT (1<<QUIC_COMM_CERT_MASK)
#define QUIC_CERT_CHAIN (1<<QUIC_CERT_CHAIN_MASK)
#define QUIC_APPLICATION_DATA (1<<QUIC_APPLICATION_DATA_MASK)
#define QUIC_VERSION (1<<QUIC_VERSION_MASK)
enum quic_interested_region {
QUIC_INTEREST_KEY_MASK = 0,
QUIC_CLIENT_HELLO_MASK,
QUIC_SERVER_HELLO_MASK,
QUIC_CACHED_CERT_MASK,
QUIC_COMM_CERT_MASK,
QUIC_CERT_CHAIN_MASK,
QUIC_APPLICATION_DATA_MASK,
QUIC_VERSION_MASK
};
typedef struct quic_tlv{
unsigned int type;
unsigned int length;
void *ptr_value;
}quic_tlv_t;
struct quic_business_info
{
void* param;
uint8_t return_value;
};
struct quic_client_hello {
int server_name_len;
char server_name[SERVER_NAME_LEN];
int user_agent_len;
char user_agent[USER_AGENT_LEN];
uint16_t ext_tag_num; //number of extensions or tags
quic_tlv_t** ext_tags; //extensions or tags
};
struct quic_server_hello {
// char random[RANDOM_LEN];
// struct quic_tlv_t session;
// uint16_t ciphersuit;
// uint8_t com_method; //compress method
uint16_t ext_tag_num; //number of extensions or tags
quic_tlv_t** ext_tags; //extensions or tags
};
struct quic_stream {
unsigned char link_state;
uint8_t version_cfm;
uint32_t version;
uint8_t fin_flag;
// uint8_t is_0rtt;
uint8_t is_quic_stream;
uint64_t gquic_cID;
// struct quic_tlv_t* p_output_buffer;
struct quic_client_hello st_client_hello;
struct quic_server_hello st_server_hello;
struct quic_tlv cert_chain; //only gquic
struct quic_tlv cached_cert; //only gquic
struct quic_tlv common_cert; //only gquic
struct quic_business_info* business;
enum quic_interested_region output_region_mask;
uint64_t output_region_flag;
};
struct st_quic_client_hello* quic_get_clienthello(void* app_info);
struct st_quic_server_hello* quic_get_serverhello(void* app_info);
uint32_t quic_get_version(void* app_info);
struct quic_tlv_t* quic_get_cert_chain(void* app_info);
struct quic_tlv_t* quic_get_cached_cert(void* app_info);
struct quic_tlv_t* quic_get_common_cert(void* app_info);
void* quic_get_application_data(void* app_info);
#endif /* SRC_GQUIC_H_ */

1082
src/gquic_process.c Normal file

File diff suppressed because it is too large Load Diff

218
src/gquic_process.h Normal file
View File

@@ -0,0 +1,218 @@
/*
* gquic_process.h
*
* Created on: 2019<31><39>4<EFBFBD><34>2<EFBFBD><32>
* Author: root
*/
#ifndef SRC_GQUIC_GQUIC_PROCESS_H_
#define SRC_GQUIC_GQUIC_PROCESS_H_
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "gquic.h"
#define VERSION_LEN 4
#define VER_Q046 0x51303436
/**************************************************************************/
/* Public flag */
/**************************************************************************/
#define PACKET_PUBLIC_FLAGS_MAX 0x7f
#define PUBLIC_FLAG_VER_FST_BYTE 0x51
#define PUBLIC_FLAG_VER 0x01
#define PUBLIC_FLAG_RST 0x02
#define PUBLIC_FLAG_NONCE 0x04
#define BYTE_CNTID_8 0x08
#define BYTE_CNTID_0 0x00
enum gquic_connid_len {
PACKET_0BYTE_CONNECTION_ID = 0,
PACKET_8BYTE_CONNECTION_ID = 8
};
#define PKT_NUM_6 0x30
#define PKT_NUM_4 0x20
#define PKT_NUM_2 0x10
#define PKT_NUM_1 0x00
//enum gquic_pkt_num_len {
// PACKET_1BYTE_PACKET_NUMBER = 1,
// PACKET_2BYTE_PACKET_NUMBER = 2,
// PACKET_4BYTE_PACKET_NUMBER = 4,
// PACKET_6BYTE_PACKET_NUMBER = 6
//};
// Used to indicate a QuicSequenceNumberLength using two flag bits.
enum gquic_pkt_num_len_flags {
PACKET_FLAGS_1BYTE_PACKET = 0, // 00
PACKET_FLAGS_2BYTE_PACKET = 1, // 01
PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10
PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11
};
//#define PUBLIC_FLAG_MULTIPATH 0x40
#define UNUSE 0x80
#define MSG_AUTH_HASH_LEN 12
#define PUB_HEAD_SEQ_SFT 4
/**************************************************************************/
/* Frame type */
/**************************************************************************/
#define FRAM_SPECIAL 0xE0
#define STREAM 0x80
#define STREAM_F 0x40 //fin
#define STREAM_D 0x20 //data length
#define STREAM_OOO 0x1C //offset length
#define STREAM_SS 0x03 //stream length
#define ACK 0x40
#define ACK_LL 0x0c
#define ACK_MM 0x03
#define ACK_N 0x20
#define CONGESTION_FEEDBACK 0x20
#define PADDING 0x00
#define RST_STREAM 0x01
#define CONNECTION_CLOSE 0x02
#define GOAWAY 0x03
#define WINDOW_UPDATE 0x04
#define BLOCKED 0x05
#define STOP_WAITING 0x06
#define PING 0x07
#define STREAM_ID_1BYTE 0x00
#define STREAM_ID_2BYTE 0x01
#define STREAM_ID_3BYTE 0x02
#define STREAM_ID_4BYTE 0x03
enum frame_type_t{
FRAME_UNKNOWN = 0,
FRAME_STREAM,
FRAME_ACK,
FRAME_CONGESTION_FEEDBACK,
FRAME_PADDING,
FRAME_RST_STREAM,
FRAME_CONNECTION_CLOSE,
FRAME_GOAWAY,
FRAME_WINDOW_UPDATE,
FRAME_BLOCKED,
FRAME_STOP_WAITING,
FRAME_PING
};
/**************************************************************************/
/* Message tag */
/**************************************************************************/
#define CHLO 0x43484C4F
#define SHLO 0x53484C4F
#define REJ 0x52454A00
#define PRST 0x50525354
enum message_tag_t{
MTAG_UNKNOWN = 0,
MTAG_CHLO,
MTAG_SHLO,
MTAG_REJ,
MTAG_PRST
};
struct gquic_frame_hdr{
enum frame_type_t frame_type;
UCHAR is_fin;
UCHAR data_len_byte;
UCHAR offset_len;
UCHAR stream_id_len;
UINT8 stream_id;
UINT16 data_len;
UCHAR padding_len;
enum message_tag_t tag;
UINT32 tag_num;
};
struct gquic_pkt_hdr{
UINT64 connection_id;
int connection_id_len;
UINT8 nonce_flag;
UINT8 reset_flag;
UINT8 version_flag;
UINT32 packet_number_len;
UINT32 version;
UINT8 version_int8;
UINT32 packet_number;
UCHAR auth_hash[MSG_AUTH_HASH_LEN];
// struct gquic_frame_hdr* frame_hdr;
};
/**************************************************************************/
/* Tag */
/**************************************************************************/
#define TAG_PAD 0x50414400
#define TAG_SNI 0x534E4900
#define TAG_VER 0x56455200
#define TAG_CCS 0x43435300
#define TAG_UAID 0x55414944
#define TAG_PDMD 0x50444d44
#define TAG_STK 0x53544b00
#define TAG_SNO 0x534E4F00
#define TAG_PROF 0x50524F46
#define TAG_SCFG 0x53434647
#define TAG_RREJ 0x5252454A
#define TAG_CRT 0x435254FF
#define TAG_AEAD 0x41454144
#define TAG_SCID 0x53434944
#define TAG_PUBS 0x50554253
#define TAG_KEXS 0x4B455853
#define TAG_OBIT 0x4F424954
#define TAG_EXPY 0x45585059
#define TAG_NONC 0x4E4F4E43
#define TAG_MSPC 0x4D535043
#define TAG_TCID 0x54434944
#define TAG_SRBF 0x53524246
#define TAG_ICSL 0x4943534C
#define TAG_SCLS 0x53434C53
#define TAG_COPT 0x434F5054
#define TAG_CCRT 0x43435254
#define TAG_IRTT 0x49525454
#define TAG_CFCW 0x43464357
#define TAG_SFCW 0x53464357
#define TAG_CETV 0x43455456
#define TAG_XLCT 0x584C4354
#define TAG_NONP 0x4E4F4E50
#define TAG_CSCT 0x43534354
#define TAG_CTIM 0x4354494D
#define TAG_MIDS 0x4D494453
#define TAG_FHOL 0x46484F4C
#define TAG_STTL 0x5354544C
#define TAG_SMHL 0x534D484C
#define TAG_TBKP 0x54424B50
/* Public Reset Tag */
#define TAG_RNON 0x524E4F4E
#define TAG_RSEQ 0x52534551
#define TAG_CADR 0x43414452
UINT8 gquic_process(struct streaminfo *pstream, struct quic_stream* a_quic_stream,
unsigned long long region_flag, int thread_seq, void* a_packet, char* quic_data, UINT32 quic_data_len);
//UCHAR is_handshake_pkt(struct quic_stream* a_quic_stream, struct gquic_pkt_hdr* gquic_hdr, char * quic_data, UINT32 quic_data_len, UINT32 offset);
//void gquic_proc_unencrypt(struct streaminfo *pstream, struct gquic_pkt_hdr* gquic_hdr, struct quic_stream* a_quic_stream,
// unsigned long long region_flag, int thread_seq, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 g_pos_t);
//UINT8 gquic_proc_tag(struct streaminfo *pstream, struct gquic_pkt_hdr* gquic_hdr, struct quic_stream *a_quic_stream, UINT16 tag_num, UINT8 direction,
// unsigned long long region_flag, int thread_seq, void* a_packet, char * quic_data, UINT32 quic_data_len, UINT32 g_pos_t);
UINT32 read_offset_len(UINT8 frame_type);
UINT32 read_stream_len(UINT8 frame_type);
UINT32 read_largest_observed_len(UINT8 frame_type);
UINT32 read_missing_packet_len(UINT8 frame_type);
UINT32 get_stream_id(char* g_data_t, UINT32 offset, UINT8 stream_id_len);
UINT32 get_pkn(char* g_data_t, UINT32 offset, UINT8 pkn_len);
UINT32 read_seq_num_len(UINT8 flags);
int read_conn_id_len(UINT8 flags);
#endif

432
src/quic_analysis.c Normal file
View File

@@ -0,0 +1,432 @@
/*
* quic_analysis.c
*
* Created on: 2019<31><39>4<EFBFBD><34>2<EFBFBD><32>
* Author: root
*/
#include "gquic.h"
#include "quic_analysis.h"
#include "gquic_process.h"
#include <stdio.h>
#include <MESA/stream_inc/stream_base.h>
struct quic_param_t g_quic_param;
int QUIC_INIT(void)
{
memset(&g_quic_param,0,sizeof(struct quic_param_t));
strcat(g_quic_param.quic_conf_filename, "./conf/quic/quic.conf");
if(0!=readconf(g_quic_param.quic_conf_filename)){
return -1;
}
return 0;
}/*QUICINIT*/
void QUIC_DESTROY(void)
{
return ;
}/*QUICDESTROY*/
void QUIC_GETPLUGID(unsigned short plugid)
{
g_quic_param.quic_plugid = plugid;
}
void QUIC_PROT_FUNSTAT(unsigned long long protflag)
{
if(0==protflag){
return;
}
g_quic_param.quic_interested_region_flag = protflag;
return;
}/*PROT_FUNSTAT*/
unsigned long long quic_getRegionID(char *string, int str_len,const char g_string[MAX_REGION_NUM][REGION_NAME_LEN])
{
unsigned long long i=0;
for(i=0;i<g_quic_param.quic_region_cnt;i++)
{
if(0==strcasecmp(g_string[i], string))
{
return i;
}
}
return 0;
}
long long QUIC_FLAG_CHANGE(char* flag_str)
{
if(flag_str==NULL) return -1;
long long protflag = 0;
long long region_id = 0;
char *start_token = flag_str;
char *end_token = flag_str;
char *end_pos = flag_str+strlen(flag_str);
char region_name[REGION_NAME_LEN] = {0};
while (end_token < end_pos)
{
end_token = (char*)memchr(start_token, ',', end_pos-start_token);
if(end_token!=NULL)
{
memcpy(region_name, start_token, end_token-start_token);
start_token = end_token+1;
end_token += 1;
}
else
{
memcpy(region_name, start_token, end_pos-start_token);
end_token = end_pos;
}
region_id = quic_getRegionID(region_name, strlen(region_name), g_quic_param.quic_conf_regionname);
if(-1==region_id)
{
#ifdef PRINTF
printf( "quic.so : PROT_CHANGE %s read %s error\n", flag_str, region_name);
#endif
return -1;
}
protflag |= ((long long)1)<<region_id;
memset(region_name, 0, REGION_NAME_LEN);
}
return protflag;
}
char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq, void *a_pcaket)
{
uint8_t return_val=0;
switch(quic_doWithInsterestedRegion(pstream))
{
case APP_STATE_DROPME:
return APP_STATE_DROPME;
default:
break;
}
struct quic_stream* a_quic_stream = NULL;
switch(pstream->opstate)
{
case OP_STATE_PENDING:
return_val = quic_init_stream(pstream, pme, thread_seq);
if(return_val < 0){
#ifdef PRINTF
printf("initQuicStream error\n");
#endif
return APP_STATE_DROPME;
}
case OP_STATE_DATA:
return_val = quic_analyseStream(pstream, pme, thread_seq, a_pcaket);
if(return_val == QUIC_RETURN_DROPME){
quic_release_stream(pstream, pme, thread_seq, a_pcaket);
*pme = NULL;
return APP_STATE_DROPME;
}
break;
case OP_STATE_CLOSE:
a_quic_stream = (struct quic_stream *)*pme;
if(a_quic_stream!=NULL)
{
a_quic_stream->fin_flag = QUIC_TRUE;
}
return_val = quic_analyseStream(pstream, pme, thread_seq, a_pcaket);
if(a_quic_stream!=NULL)
{
quic_release_stream(pstream, pme, thread_seq, a_pcaket);
*pme = NULL;
}
return APP_STATE_DROPME;
}
return APP_STATE_GIVEME;
}/*QUICNIT*/
void quic_init_clientHello(struct quic_client_hello* stClientHello, UINT32 tag_num, int thread_seq)
{
if(stClientHello==NULL) return ;
if(tag_num == 0){
}else{
(stClientHello->ext_tags) = (quic_tlv_t **)dictator_malloc(thread_seq,tag_num*sizeof(quic_tlv_t*));
int i=0;
for(i=0;i<tag_num;i++)
{
stClientHello->ext_tags[i] = (quic_tlv_t *)dictator_malloc(thread_seq, sizeof(quic_tlv_t) );
memset(stClientHello->ext_tags[i], 0, sizeof(quic_tlv_t));
stClientHello->ext_tags[i]->ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*MAX_TAG_VALUE_LEN);
stClientHello->ext_tags[i]->length = 0;
stClientHello->ext_tags[i]->type = 0;
}
}
// stClientHello->ext_tag_len = 0;
stClientHello->ext_tag_num = tag_num;
memset(stClientHello->server_name, 0, SERVER_NAME_LEN);
memset(stClientHello->user_agent, 0, SERVER_NAME_LEN);
return;
}
//void quic_init_clientHello(struct quic_client_hello* stClientHello, UINT32 tag_num, int thread_seq)
//{
// if(stClientHello==NULL) return ;
// stClientHello->session.ptr_value = NULL;
// stClientHello->session.length = 0;
// stClientHello->ciphersuits.ptr_value = NULL;
// stClientHello->ciphersuits.length = 0;
// stClientHello->com_method.ptr_value = NULL;
// stClientHello->com_method.length = 0;
// memset(&stClientHello->random, 0, RANDOM_LEN);
// (stClientHello->ext_tags) = (struct quic_tlv_t **)dictator_malloc(thread_seq,tag_num*sizeof(struct quic_tlv_t*));
//
// int i=0;
// for(i=0;i<tag_num;i++)
// {
// stClientHello->ext_tags[i] = (struct quic_tlv_t *)dictator_malloc(thread_seq, sizeof(struct quic_tlv_t) );
// memset(stClientHello->ext_tags[i], 0, sizeof(struct quic_tlv_t));
// stClientHello->ext_tags[i]->ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*MAX_TAG_VALUE_LEN);
// stClientHello->ext_tags[i]->length = 0;
// stClientHello->ext_tags[i]->type = 0;
// }
// stClientHello->ext_tag_len = 0;
// stClientHello->ext_tag_num = tag_num;
// memset(&stClientHello->server_name, 0, sizeof(stClientHello->server_name));
// memset(&stClientHello->user_agent, 0, sizeof(stClientHello->user_agent));
// return;
//}
void quic_init_serverHello(struct quic_server_hello* stServerHello, UINT32 tag_num, int thread_seq)
{
if(stServerHello==NULL) return ;
// stServerHello->session.ptr_value = NULL;
// stServerHello->session.length = 0;
// memset(&stServerHello->random, 0, RANDOM_LEN);
if(tag_num == 0){
}else{
(stServerHello->ext_tags) = (struct quic_tlv_t **)dictator_malloc(thread_seq,tag_num*sizeof(struct quic_tlv_t*));
int i=0;
for(i=0;i<tag_num;i++)
{
// stServerHello->ext_tags[i] = (struct quic_tlv_t *)dictator_malloc(thread_seq, sizeof(quic_tlv_t)*20);
stServerHello->ext_tags[i] = (struct quic_tlv_t *)dictator_malloc(thread_seq, sizeof(quic_tlv_t));
memset(stServerHello->ext_tags[i], 0, sizeof(quic_tlv_t));
stServerHello->ext_tags[i]->ptr_value = (char *)dictator_malloc(thread_seq, sizeof(char)*MAX_TAG_VALUE_LEN);
stServerHello->ext_tags[i]->length = 0;
stServerHello->ext_tags[i]->type = 0;
}
}
stServerHello->ext_tag_num = tag_num;
return;
}
int quic_init_stream(struct streaminfo *pstream, void **pme, int thread_seq){
struct quic_stream *a_quic_stream = (struct quic_stream *)*pme;
if(NULL != a_quic_stream)
return -1;
a_quic_stream = (struct quic_stream *)dictator_malloc(thread_seq, sizeof(struct quic_stream));
memset(a_quic_stream,0,sizeof(struct quic_stream));
if (NULL == a_quic_stream)
{
return -1;
}
a_quic_stream->output_region_flag = g_quic_param.quic_interested_region_flag;
a_quic_stream->output_region_mask = QUIC_INTEREST_KEY_MASK;
// a_quic_stream->type = UNKNOWN_QUIC_TYPE;
// a_quic_stream->handshake_type = UNKNOWN_HANDSHAKE_TYPE;
a_quic_stream->is_quic_stream = QUIC_FALSE;
a_quic_stream->version_cfm = QUIC_FALSE;
a_quic_stream->version = 0;
a_quic_stream->link_state = QUIC_FALSE;
a_quic_stream->fin_flag = QUIC_FALSE;
// a_quic_stream->p_output_buffer = (struct quic_tlv_t*)dictator_malloc(thread_seq, sizeof(struct quic_tlv_t));
// a_quic_stream->p_output_buffer->length = 0;
// a_quic_stream->p_output_buffer->ptr_value = 0;
a_quic_stream->business = (struct quic_business_info *)dictator_malloc(thread_seq,sizeof(struct quic_business_info));
a_quic_stream->business->param = NULL;
a_quic_stream->business->return_value = PROT_STATE_GIVEME;
*pme = (void*)a_quic_stream;
return 0;
}
void quic_release_clientHello(int thread_seq, struct quic_client_hello* st_client_hello)
{
if(st_client_hello==NULL) return ;
// if(st_client_hello->random.ptr_value!=NULL)
// {
// dictator_free(thread_seq,st_client_hello->random.ptr_value);
// st_client_hello->random.ptr_value = NULL;
// }
// if(st_client_hello->session.ptr_value!=NULL)
// {
// dictator_free(thread_seq,st_client_hello->session.ptr_value);
// st_client_hello->session.ptr_value = NULL;
// }
// if(st_client_hello->ciphersuits.ptr_value!=NULL)
// {
// dictator_free(thread_seq,st_client_hello->ciphersuits.ptr_value);
// st_client_hello->ciphersuits.ptr_value = NULL;
// }
// if(st_client_hello->com_method.ptr_value!=NULL)
// {
// dictator_free(thread_seq,st_client_hello->com_method.ptr_value);
// st_client_hello->com_method.ptr_value = NULL;
// }
if(st_client_hello->ext_tags != NULL){
quic_release_exts(thread_seq, st_client_hello->ext_tags, st_client_hello->ext_tag_num);
dictator_free(thread_seq, st_client_hello->ext_tags);
st_client_hello->ext_tags = NULL;
}
return;
}
void quic_release_serverHello(int thread_seq,struct quic_server_hello* st_server_hello)
{
if(st_server_hello==NULL) return ;
// if(st_server_hello->session.ptr_value!=NULL)
// {
// dictator_free(thread_seq,st_server_hello->session.ptr_value);
// st_server_hello->session.ptr_value = NULL;
// }
if(st_server_hello->ext_tags != NULL){
quic_release_exts(thread_seq, st_server_hello->ext_tags, st_server_hello->ext_tag_num);
dictator_free(thread_seq, st_server_hello->ext_tags);
st_server_hello->ext_tags = NULL;
}
return ;
}
void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num){
if(ext_tags == NULL) return;
int i = 0;
for(i = 0; i < ext_tag_num; i++){
if(ext_tags[i] != NULL){
if(ext_tags[i]->ptr_value != NULL){
dictator_free(thread_seq, ext_tags[i]->ptr_value);
ext_tags[i]->ptr_value = NULL;
}
dictator_free(thread_seq, ext_tags[i]);
ext_tags[i] = NULL;
}
}
}
void quic_release_stream(struct streaminfo *a_tcp, void** pme, int thread_seq,void *a_packet)
{
struct quic_stream *a_quic_stream = (struct quic_stream *)*pme;
if(NULL == a_quic_stream) return;
a_quic_stream->fin_flag = QUIC_TRUE;
// if(NULL != a_quic_stream->p_output_buffer)
// {
// if(a_quic_stream->p_output_buffer->ptr_value!=NULL)
// {
// dictator_free(thread_seq,a_quic_stream->p_output_buffer->ptr_value);
// a_quic_stream->p_output_buffer->ptr_value = NULL;
// }
// dictator_free(thread_seq,a_quic_stream->p_output_buffer);
// a_quic_stream->p_output_buffer = NULL;
// }
if(NULL != a_quic_stream->business)
{
if(a_quic_stream->business->param !=NULL){
dictator_free(thread_seq,a_quic_stream->business->param);
a_quic_stream->business->param = NULL;
}
dictator_free(thread_seq,a_quic_stream->business);
a_quic_stream->business = NULL;
}
if(NULL != a_quic_stream->cert_chain.ptr_value)
{
dictator_free(thread_seq,a_quic_stream->cert_chain.ptr_value);
a_quic_stream->cert_chain.ptr_value = NULL;
}
if(NULL != a_quic_stream->common_cert.ptr_value)
{
dictator_free(thread_seq,a_quic_stream->common_cert.ptr_value);
a_quic_stream->common_cert.ptr_value = NULL;
}
if(NULL != a_quic_stream->cached_cert.ptr_value)
{
dictator_free(thread_seq,a_quic_stream->cached_cert.ptr_value);
a_quic_stream->cached_cert.ptr_value = NULL;
}
quic_release_serverHello(thread_seq, &a_quic_stream->st_server_hello);
quic_release_clientHello(thread_seq, &a_quic_stream->st_client_hello);
dictator_free(thread_seq,a_quic_stream);
a_quic_stream = NULL;
return;
}
UINT8 quic_analyseStream(struct streaminfo *pstream, void** pme, int thread_seq, void *a_packet){
struct quic_stream* a_quic_stream = (struct quic_stream *)*pme;
if(a_quic_stream == NULL){
return QUIC_RETURN_DROPME;
}
UINT8 return_val = QUIC_RETURN_NORM;
struct udpdetail *udp_detail = (struct udpdetail *) pstream->pdetail;
if(udp_detail->datalen <= 0){
return QUIC_RETURN_NORM;
}
char* g_data_t = (char *)udp_detail->pdata;
UINT32 g_len_t = udp_detail->datalen;
if(!a_quic_stream->is_quic_stream){
if(g_len_t <= GQUIC_HEADER_LEN){
return QUIC_RETURN_DROPME;
}
if(g_len_t > GQUIC_HEADER_LEN){
return_val = gquic_process(pstream, a_quic_stream, a_quic_stream->output_region_flag, thread_seq, a_packet, g_data_t, g_len_t);
}
}else if(a_quic_stream->is_quic_stream){
if(g_len_t > GQUIC_HEADER_LEN){
gquic_process(pstream, a_quic_stream, a_quic_stream->output_region_flag, thread_seq, a_packet, g_data_t, g_len_t);
}
return QUIC_RETURN_NORM;
}
return return_val;
}
int quic_getLinkState(struct quic_stream *a_quic_stream)
{
UCHAR state = 0;
if(QUIC_FALSE==(a_quic_stream)->link_state)
{
if(QUIC_TRUE==(a_quic_stream)->fin_flag)
state = SESSION_STATE_CLOSE | SESSION_STATE_PENDING;
else
state = SESSION_STATE_PENDING;
}
else
{
if(QUIC_TRUE==(a_quic_stream)->fin_flag)
{
state = SESSION_STATE_CLOSE;
}
else
state = SESSION_STATE_DATA;
}
(a_quic_stream)->link_state = QUIC_TRUE;
return state;
}
UCHAR quic_doWithInsterestedRegion(struct streaminfo *pstream)
{
/*ҵ<><D2B5><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4>*/
if(g_quic_param.quic_interested_region_flag < QUIC_KEY){
return APP_STATE_DROPME;
}
return QUIC_RETURN_NORM;
}/*ssl_doWithInsterestedRegion*/

78
src/quic_analysis.h Normal file
View File

@@ -0,0 +1,78 @@
/*
* quic_analysis.h
*
* Created on: 2019<31><39>4<EFBFBD><34>2<EFBFBD><32>
* Author: root
*/
#ifndef SRC_QUIC_ANALYSIS_H_
#define SRC_QUIC_ANALYSIS_H_
#include <stdint.h>
#include "quic_util.h"
#define QUIC_TRUE 0x01
#define QUIC_FALSE 0x00
#define QUIC_HALF_CLOSE 0x01
#define QUIC_WHOLE_CLOSE 0x02
#define QUIC_DATA 0x03
#define QUIC_KEY 1
#define CT_GNUC_SO_EXPORT __attribute__ ((visibility("default"))) //<2F><><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>so<73>ļ<EFBFBD>
#define CT_GNUC_SO_LOCAL __attribute__ ((visibility("hidden"))) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD>so<73>ļ<EFBFBD><C4BC><EFBFBD>
#define QUIC_RETURN_NORM 0x60
#define QUIC_RETURN_UNNORM 0x61
#define QUIC_RETURN_RESET_BUFFER 0x62
#define QUIC_RETURN_DROPME 0x63
#define MAX_REGION_NUM 15
#define REGION_NAME_LEN 32
#define GQUIC_HEADER_LEN 1+8+1
#define IQUIC_HEADER_LEN 1+8+1
#define ENC_BIG_ENDIAN 0x00000000
#define ENC_LITTLE_ENDIAN 0x80000000
#define DIR_C2S 0x01
#define DIR_S2C 0x02
#define DIR_DOUBLE 0x03
struct quic_param_t
{
unsigned long long quic_interested_region_flag;
unsigned long long quic_region_cnt;
char quic_conf_filename[256];
unsigned short quic_plugid;
char quic_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN];
};
enum quic_mes_type{
VER_NEGO = 0, //vertion negotiation packet
PUB_RST, //public reset packet
FRAME, //frame packet
FEC, //FEC packet
Initial, //iquic
Retey, //iquic
Handshake, //iquic
MSG_UNKNOWN = 255
};
int QUIC_INIT(void);
char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq,void *a_pcaket);
void QUIC_DESTROY(void);
void QUIC_GETPLUGID(unsigned short plugid);
void QUIC_PROT_FUNSTAT(unsigned long long protflag);
long long QUIC_FLAG_CHANGE(char* flag_str);
unsigned long long quic_getRegionID(char *string, int str_len,
const char g_string[MAX_REGION_NUM][REGION_NAME_LEN]);
UINT8 quic_analyseStream(struct streaminfo *pstream, void** pme, int thread_seq,void *a_packet);
int quic_init_stream(struct streaminfo *pstream, void **pme, int thread_seq);
void quic_init_clientHello(struct quic_client_hello* stClientHello, UINT32 tag_num, int thread_seq);
void quic_init_serverHello(struct quic_server_hello* stServerHello, UINT32 tag_num, int thread_seq);
void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num);
void quic_release_clientHello(int thread_seq,struct quic_client_hello* stClientHello);
void quic_release_serverHello(int thread_seq,struct quic_server_hello* stServerHello);
void quic_release_stream(struct streaminfo *a_tcp, void** pme, int thread_seq,void *a_packet);
UINT8 quic_analyseStream(struct streaminfo *pstream, void** pme, int thread_seq,void *a_packet);
int quic_getLinkState(struct quic_stream *a_quic_stream);
UCHAR quic_doWithInsterestedRegion(struct streaminfo *pstream);
#endif /* SRC_QUIC_ANALYSIS_H_ */

106
src/quic_callback.c Normal file
View File

@@ -0,0 +1,106 @@
/*
* quic_callback.c
*
* Created on: 2019<31><39>4<EFBFBD><34>13<31><33>
* Author: root
*/
#include "gquic.h"
#include "quic_analysis.h"
extern struct quic_param_t g_quic_param;
UCHAR quic_callPlugins(struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
stSessionInfo session_info;
region_flag = (region_flag >> (*a_quic_stream)->output_region_mask) % 2;
if( QUIC_TRUE==region_flag || (*a_quic_stream)->fin_flag==QUIC_TRUE )
{
if (PROT_STATE_DROPME != (*a_quic_stream)->business->return_value)
{
session_info.plugid = g_quic_param.quic_plugid;
session_info.prot_flag = (((unsigned long long)1)<<(*a_quic_stream)->output_region_mask);
session_info.session_state = quic_getLinkState(*a_quic_stream) ;
session_info.app_info = (void*)(*a_quic_stream);
// session_info.buf = (*a_quic_stream)->p_output_buffer->ptr_value;
// session_info.buflen = (*a_quic_stream)->p_output_buffer->length;
(*a_quic_stream)->business->return_value = PROT_PROCESS(&session_info,
&((*a_quic_stream)->business->param),thread_seq,pstream, a_packet);
}
}
return QUIC_RETURN_NORM;
}
UCHAR quic_proc_interest_region(enum quic_interested_region region_mask,struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
UCHAR return_val = QUIC_RETURN_NORM;
(*a_quic_stream)->output_region_mask = region_mask;
return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet);
(*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK;
return return_val;
}
/*
UCHAR quic_doWithVersion(struct quic_stream** a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
UCHAR return_val = QUIC_RETURN_NORM;
if(!(g_quic_param.quic_interested_region_flag & QUIC_VERSION)) return return_val;
(*a_quic_stream)->output_region_mask = QUIC_VERSION_MASK;
(*a_quic_stream)->p_output_buffer->ptr_value = (void*)(*a_quic_stream)->version;
(*a_quic_stream)->p_output_buffer->length = 4;
return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet);
(*a_quic_stream)->p_output_buffer->ptr_value = NULL;
(*a_quic_stream)->p_output_buffer->length = 0;
(*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK;
return return_val;
}
UCHAR quic_doWithApplicationData(char *pc_quic_data, int data_len, struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
UCHAR return_val = QUIC_RETURN_NORM;
(*a_quic_stream)->output_region_mask = QUIC_APPLICATION_DATA_MASK;
(*a_quic_stream)->p_output_buffer->ptr_value = pc_quic_data;
(*a_quic_stream)->p_output_buffer->length = data_len;
return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet);
(*a_quic_stream)->p_output_buffer->ptr_value = NULL;
(*a_quic_stream)->p_output_buffer->length = 0;
(*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK;
return return_val;
}
UCHAR quic_doWithClientHello(struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
UCHAR return_val = QUIC_RETURN_NORM;
(*a_quic_stream)->output_region_mask = QUIC_CLIENT_HELLO_MASK;
return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet);
(*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK;
return return_val;
}
UCHAR quic_doWithServerHello(struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
UCHAR return_val = QUIC_RETURN_NORM;
(*a_quic_stream)->output_region_mask = QUIC_SERVER_HELLO_MASK;
return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet);
(*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK;
return return_val;
}
UCHAR quic_doWithCert(char *pc_quic_data, int data_len, enum quic_interested_region cert, struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet)
{
UCHAR return_val = QUIC_RETURN_NORM;
(*a_quic_stream)->output_region_mask = cert;
(*a_quic_stream)->p_output_buffer->ptr_value = pc_quic_data;
(*a_quic_stream)->p_output_buffer->length = data_len;
return_val = quic_callPlugins(a_quic_stream, pstream, region_flag, thread_seq, a_packet);
(*a_quic_stream)->p_output_buffer->ptr_value = NULL;
(*a_quic_stream)->p_output_buffer->length = 0;
(*a_quic_stream)->output_region_mask = QUIC_INTEREST_KEY_MASK;
return return_val;
}
*/

21
src/quic_callback.h Normal file
View File

@@ -0,0 +1,21 @@
/*
* quic_callback.h
*
* Created on: 2019<31><39>4<EFBFBD><34>13<31><33>
* Author: root
*/
#ifndef SRC_QUIC_CALLBACK_H_
#define SRC_QUIC_CALLBACK_H_
#include "gquic.h"
UCHAR quic_callPlugins(struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet);
UCHAR quic_proc_interest_region(enum quic_interested_region region_mask,struct quic_stream **a_quic_stream, struct streaminfo *pstream,
unsigned long long region_flag, int thread_seq, void *a_packet);
//UCHAR quic_doWithVersion(struct quic_stream** a_quic_stream, struct streaminfo *pstream,
// unsigned long long region_flag, int thread_seq, void *a_packet);
//UCHAR quic_doWithApplicationData(char *pc_quic_data, int data_len, struct quic_stream **a_quic_stream, struct streaminfo *pstream,
// unsigned long long region_flag, int thread_seq, void *a_packet);
#endif /* SRC_QUIC_CALLBACK_H_ */

210
src/quic_util.c Normal file
View File

@@ -0,0 +1,210 @@
/*
* quic_util.c
*
* Created on: 2019<31><39>4<EFBFBD><34>4<EFBFBD><34>
* Author: root
*/
#include "quic_analysis.h"
#include<stdio.h>
extern struct quic_param_t g_quic_param;
int readconf(const char* filename)
{
FILE *fp = NULL;
char buf[2048] = {0};
int region_id = 0;
int temp = 0;
char region_name[REGION_NAME_LEN] = {0};
if(((fp = fopen(filename, "r"))!=NULL))
{
while( fgets(buf, sizeof(buf), fp))
{
temp = sscanf(buf, "%d\t%s", &region_id, region_name);
if ( 2 > temp )
{
#ifdef PRINTF
printf( "quic.so : quic.conf %s read error\n", filename);
#endif
return -1;
}
if(region_id>MAX_REGION_NUM)
{
#ifdef PRINTF
printf( "quic.so : quic.conf %d bigger than MAX_REGION_NUM\n", region_id);
#endif
return -1;
}
strncpy(g_quic_param.quic_conf_regionname[region_id], region_name, strlen(region_name));
g_quic_param.quic_region_cnt++;
memset(region_name, 0, sizeof(region_name));
}
fclose(fp);
}
else
{
#ifdef PRINTF
printf( "quic.so : quic.conf %s open error\n", filename);
#endif
return -1;
}
return 0;
}
bool a_readUInt64(UINT64* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
}
bool a_readUInt32(UINT32* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
}
bool a_readUInt8(UINT8* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
}
bool a_readUInt16(UINT16* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset){
return a_readBytes(buf, sizeof(*buf), quic_data, quic_data_len, offset);
}
bool a_readBytes(void* buf, UINT32 len, char * quic_data, UINT32 quic_data_len, UINT32* quic_offset) {
UINT32 offset = *quic_offset;
if (!a_canRead(len, quic_data_len, offset)) {
return false;
}
memcpy(buf, quic_data + offset, len);
offset += len;
*quic_offset = offset;
return true;
}
bool a_canRead(size_t bytes, UINT32 g_len_t, UINT32 g_pos_t) {
if(g_pos_t >= g_len_t){
return false;
}
return bytes <= (g_len_t - g_pos_t);
}
UINT64 a_pletoh64(const void *p, UINT32 offset)
{
return (UINT64)*((const UINT8 *)(p)+7+offset)<<56|
(UINT64)*((const UINT8 *)(p)+6+offset)<<48|
(UINT64)*((const UINT8 *)(p)+5+offset)<<40|
(UINT64)*((const UINT8 *)(p)+4+offset)<<32|
(UINT64)*((const UINT8 *)(p)+3+offset)<<24|
(UINT64)*((const UINT8 *)(p)+2+offset)<<16|
(UINT64)*((const UINT8 *)(p)+1+offset)<<8|
(UINT64)*((const UINT8 *)(p)+0+offset)<<0;
}
UINT64 a_pletoh48(const void *p, UINT32 offset)
{
return (UINT64)*((const UINT8 *)(p)+5+offset)<<40|
(UINT64)*((const UINT8 *)(p)+4+offset)<<32|
(UINT64)*((const UINT8 *)(p)+3+offset)<<24|
(UINT64)*((const UINT8 *)(p)+2+offset)<<16|
(UINT64)*((const UINT8 *)(p)+1+offset)<<8|
(UINT64)*((const UINT8 *)(p)+0+offset)<<0;
}
UINT32 a_pletoh32(const void *p, UINT32 offset)
{
return (UINT32)*((const UINT8 *)(p)+3+offset)<<24|
(UINT32)*((const UINT8 *)(p)+2+offset)<<16|
(UINT32)*((const UINT8 *)(p)+1+offset)<<8|
(UINT32)*((const UINT8 *)(p)+0+offset)<<0;
}
UINT32 a_pletoh24(const void *p, UINT32 offset)
{
return (UINT32)*((const UINT8 *)(p)+2+offset)<<16|
(UINT32)*((const UINT8 *)(p)+1+offset)<<8|
(UINT32)*((const UINT8 *)(p)+0+offset)<<0;
}
//UINT16 a_pletoh16(const void *p)
//{
// UINT32 offset = g_pos_t;
// return (UINT16)*((const UINT8 *)(p)+0+offset)<<0|
// (UINT16)*((const UINT8 *)(p)+1+offset)<<8;
//}
UINT16 a_pletoh16(const void *p, UINT32 offset){
return (UINT16)*((const UINT8 *)(p)+0+offset)<<0|
(UINT16)*((const UINT8 *)(p)+1+offset)<<8;
}
UINT16 a_pntoh16(const void *p, UINT32 offset)
{
return (UINT16)*((const UINT8 *)(p)+1+offset)<<0|
(UINT16)*((const UINT8 *)(p)+0+offset)<<8;
}
UINT32 a_pntoh24(const void *p, UINT32 offset)
{
return (UINT32)*((const UINT8 *)(p)+0+offset)<<16|
(UINT32)*((const UINT8 *)(p)+1+offset)<<8|
(UINT32)*((const UINT8 *)(p)+2+offset)<<0;
}
UINT32 a_pntoh32(const void *p, UINT32 offset)
{
return (UINT32)*((const UINT8 *)(p)+0+offset)<<24|
(UINT32)*((const UINT8 *)(p)+1+offset)<<16|
(UINT32)*((const UINT8 *)(p)+2+offset)<<8|
(UINT32)*((const UINT8 *)(p)+3+offset)<<0;
}
UINT64 a_pntoh48(const void *p, UINT32 offset)
{
return (UINT64)*((const UINT8 *)(p)+0+offset)<<40|
(UINT64)*((const UINT8 *)(p)+1+offset)<<32|
(UINT64)*((const UINT8 *)(p)+2+offset)<<24|
(UINT64)*((const UINT8 *)(p)+3+offset)<<16|
(UINT64)*((const UINT8 *)(p)+4+offset)<<8|
(UINT64)*((const UINT8 *)(p)+5+offset)<<0;
}
UINT64 a_pntoh64(const void *p, UINT32 offset)
{
return (UINT64)*((const UINT8 *)(p)+0+offset)<<56|
(UINT64)*((const UINT8 *)(p)+1+offset)<<48|
(UINT64)*((const UINT8 *)(p)+2+offset)<<40|
(UINT64)*((const UINT8 *)(p)+3+offset)<<32|
(UINT64)*((const UINT8 *)(p)+4+offset)<<24|
(UINT64)*((const UINT8 *)(p)+5+offset)<<16|
(UINT64)*((const UINT8 *)(p)+6+offset)<<8|
(UINT64)*((const UINT8 *)(p)+7+offset)<<0;
}
void a_phton64(UINT8 *p, UINT64 v) {
p[0] = (UINT8)(v >> 56);
p[1] = (UINT8)(v >> 48);
p[2] = (UINT8)(v >> 40);
p[3] = (UINT8)(v >> 32);
p[4] = (UINT8)(v >> 24);
p[5] = (UINT8)(v >> 16);
p[6] = (UINT8)(v >> 8);
p[7] = (UINT8)(v >> 0);
}
int get_remaining_len(UINT32 g_len_t, UINT32 offset){
return g_len_t - offset;
}
void a_ntoa( unsigned int in, char *buffer)
{
unsigned char *bytes = (unsigned char *) &in;
snprintf( buffer, 15, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
}
//char* a_ntoa( unsigned int in, char * str)
//{
//
// char buffer[64];
// unsigned char *bytes = (unsigned char *) &in;
// printf("%s %d.%d.%d.%d\t", str, bytes[0], bytes[1], bytes[2], bytes[3] );
// snprintf( buffer, sizeof (buffer), "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
// return buffer;
//}

40
src/quic_util.h Normal file
View File

@@ -0,0 +1,40 @@
/*
* quic_util.h
*
* Created on: 2019-4-4
* Author: root
*/
#ifndef SRC_QUIC_UTIL_H_
#define SRC_QUIC_UTIL_H_
#include <stddef.h>
#include <dlfcn.h>
#include <stdbool.h>
#include "gquic.h"
int readconf(const char* filename);
bool a_readUInt64(UINT64* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset);
bool a_readUInt32(UINT32* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset);
bool a_readUInt8(UINT8* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset);
bool a_readUInt16(UINT16* buf, char* quic_data, UINT32 quic_data_len, UINT32* offset);
bool a_readBytes(void* buf, UINT32 len, char * quic_data, UINT32 quic_data_len, UINT32* quic_offset);
bool a_canRead(size_t bytes, UINT32 g_len_t, UINT32 g_pos_t);
UINT64 a_pletoh64(const void *p, UINT32 offset);
UINT64 a_pletoh48(const void *p, UINT32 offset);
UINT32 a_pletoh32(const void *p, UINT32 offset);
UINT32 a_pletoh24(const void *p, UINT32 offset);
UINT16 a_pletoh16(const void *p, UINT32 offset);
UINT16 a_pntoh16(const void *p, UINT32 offset);
UINT32 a_pntoh24(const void *p, UINT32 offset);
UINT32 a_pntoh32(const void *p, UINT32 offset);
UINT64 a_pntoh48(const void *p, UINT32 offset);
UINT64 a_pntoh64(const void *p, UINT32 offset);
void a_phton64(UINT8 *p, UINT64 v);
int get_remaining_len(UINT32 g_len_t, UINT32 offset);
void a_ntoa( unsigned int in, char *buffer);
#endif /* SRC_QUIC_UTIL_H_ */

61
test/Makefile Normal file
View File

@@ -0,0 +1,61 @@
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)

118
test/dpkt_plug_gquic.cpp Normal file
View File

@@ -0,0 +1,118 @@
#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;
}

25
test/dpkt_plug_gquic.h Normal file
View File

@@ -0,0 +1,25 @@
/*
* 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_ */

13
test/dpkt_plug_gquic.inf Normal file
View File

@@ -0,0 +1,13 @@
[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

99
test/gquic.h Normal file
View File

@@ -0,0 +1,99 @@
/*
* quic.h
*
* Created on: 2019-4-4
* Author: root
*/
#ifndef SRC_GQUIC_H_
#define SRC_GQUIC_H_
#include <MESA/stream.h>
#define MAX_EXTENSION_NUM 128
#define MAX_TAG_VALUE_LEN 257
#define SERVER_NAME_LEN 64
//add in 20191207
#define USER_AGENT_LEN 256
#define RANDOM_LEN 32
#define QUIC_VERSION_LEN 4
#define QUIC_INTEREST_KEY (1<<QUIC_INTEREST_KEY_MASK)
#define QUIC_CLIENT_HELLO (1<<QUIC_CLIENT_HELLO_MASK)
#define QUIC_SERVER_HELLO (1<<QUIC_SERVER_HELLO_MASK)
#define QUIC_CACHED_CERT (1<<QUIC_CACHED_CERT_MASK)
#define QUIC_COMM_CERT (1<<QUIC_COMM_CERT_MASK)
#define QUIC_CERT_CHAIN (1<<QUIC_CERT_CHAIN_MASK)
#define QUIC_APPLICATION_DATA (1<<QUIC_APPLICATION_DATA_MASK)
#define QUIC_VERSION (1<<QUIC_VERSION_MASK)
enum quic_interested_region {
QUIC_INTEREST_KEY_MASK = 0,
QUIC_CLIENT_HELLO_MASK,
QUIC_SERVER_HELLO_MASK,
QUIC_CACHED_CERT_MASK,
QUIC_COMM_CERT_MASK,
QUIC_CERT_CHAIN_MASK,
QUIC_APPLICATION_DATA_MASK,
QUIC_VERSION_MASK
};
typedef struct quic_tlv{
unsigned int type;
unsigned int length;
void *ptr_value;
}quic_tlv_t;
struct quic_business_info
{
void* param;
uint8_t return_value;
};
struct quic_client_hello {
int server_name_len;
char server_name[SERVER_NAME_LEN];
int user_agent_len;
char user_agent[USER_AGENT_LEN];
uint16_t ext_tag_num; //number of extensions or tags
quic_tlv_t** ext_tags; //extensions or tags
};
struct quic_server_hello {
/*include random,session,ciphersuit,compress_method...*/
uint16_t ext_tag_num; //number of extensions or tags
quic_tlv_t** ext_tags; //extensions or tags
};
struct quic_stream {
unsigned char link_state;
uint8_t version_cfm;
uint32_t version;
uint8_t fin_flag;
uint8_t is_quic_stream;
uint64_t gquic_cID;
struct quic_client_hello st_client_hello;
struct quic_server_hello st_server_hello;
struct quic_tlv cert_chain;
struct quic_tlv cached_cert;
struct quic_tlv common_cert;
struct quic_business_info* business;
enum quic_interested_region output_region_mask;
uint64_t output_region_flag;
};
//struct st_quic_client_hello* quic_get_clienthello(void* app_info);
//struct st_quic_server_hello* quic_get_serverhello(void* app_info);
//uint32_t quic_get_version(void* app_info);
//quic_tlv_t* quic_get_cert_chain(void* app_info);
//quic_tlv_t* quic_get_cached_cert(void* app_info);
//quic_tlv_t* quic_get_common_cert(void* app_info);
//void* quic_get_application_data(void* app_info);
#endif /* SRC_GQUIC_H_ */