|
@@ -221,7 +221,7 @@ int update_flow(flow *f, uint8_t *record, uint8_t incoming) {
|
|
update_finish_hash(f, p);
|
|
update_finish_hash(f, p);
|
|
break;
|
|
break;
|
|
case TLS_FINISHED:
|
|
case TLS_FINISHED:
|
|
- printf("Received finished (%x:%d -> %x:%d)\n", f->src_ip.s_addr, ntohs(f->src_port), f->dst_ip.s_addr, ntohs(f->dst_port));
|
|
|
|
|
|
+ printf("Received finished (%d) (%x:%d -> %x:%d)\n", incoming, f->src_ip.s_addr, ntohs(f->src_port), f->dst_ip.s_addr, ntohs(f->dst_port));
|
|
verify_finish_hash(f,p, incoming);
|
|
verify_finish_hash(f,p, incoming);
|
|
update_finish_hash(f, p);
|
|
update_finish_hash(f, p);
|
|
if((f->in_encrypted == 2) && (f->out_encrypted == 2)){
|
|
if((f->in_encrypted == 2) && (f->out_encrypted == 2)){
|
|
@@ -235,7 +235,7 @@ int update_flow(flow *f, uint8_t *record, uint8_t incoming) {
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case APP:
|
|
case APP:
|
|
- printf("Application Data\n");
|
|
|
|
|
|
+ printf("Application Data (%x:%d -> %x:%d)...\n", f->src_ip.s_addr, ntohs(f->src_port), f->dst_ip.s_addr, ntohs(f->dst_port));
|
|
break;
|
|
break;
|
|
case CCS:
|
|
case CCS:
|
|
printf("CCS (%x:%d -> %x:%d) \n", f->src_ip.s_addr, ntohs(f->src_port), f->dst_ip.s_addr, ntohs(f->dst_port));
|
|
printf("CCS (%x:%d -> %x:%d) \n", f->src_ip.s_addr, ntohs(f->src_port), f->dst_ip.s_addr, ntohs(f->dst_port));
|
|
@@ -328,6 +328,7 @@ int remove_flow(flow *f) {
|
|
tmp = f->ds_packet_chain->first_packet;
|
|
tmp = f->ds_packet_chain->first_packet;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ free(f->ds_packet_chain);
|
|
|
|
|
|
if(f->us_packet_chain != NULL){
|
|
if(f->us_packet_chain != NULL){
|
|
packet *tmp = f->us_packet_chain->first_packet;
|
|
packet *tmp = f->us_packet_chain->first_packet;
|
|
@@ -340,6 +341,7 @@ int remove_flow(flow *f) {
|
|
tmp = f->us_packet_chain->first_packet;
|
|
tmp = f->us_packet_chain->first_packet;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ free(f->us_packet_chain);
|
|
|
|
|
|
if(f->upstream_queue != NULL){
|
|
if(f->upstream_queue != NULL){
|
|
queue_block *tmp = f->upstream_queue;
|
|
queue_block *tmp = f->upstream_queue;
|
|
@@ -765,12 +767,10 @@ int add_packet(flow *f, struct packet_info *info){
|
|
}
|
|
}
|
|
|
|
|
|
packet *new_packet = calloc(1, sizeof(packet));
|
|
packet *new_packet = calloc(1, sizeof(packet));
|
|
- printf("Allocated new packet %p\n", new_packet);
|
|
|
|
new_packet->seq_num = ntohl(info->tcp_hdr->sequence_num);
|
|
new_packet->seq_num = ntohl(info->tcp_hdr->sequence_num);
|
|
new_packet->len = info->app_data_len;
|
|
new_packet->len = info->app_data_len;
|
|
|
|
|
|
uint8_t *packet_data = calloc(1, new_packet->len);
|
|
uint8_t *packet_data = calloc(1, new_packet->len);
|
|
- printf("Allocated new packet data %p\n", packet_data);
|
|
|
|
memcpy(packet_data, info->app_data, new_packet->len);
|
|
memcpy(packet_data, info->app_data, new_packet->len);
|
|
|
|
|
|
new_packet->data = packet_data;
|
|
new_packet->data = packet_data;
|
|
@@ -781,7 +781,7 @@ int add_packet(flow *f, struct packet_info *info){
|
|
|
|
|
|
if(new_packet->seq_num < chain->expected_seq_num){
|
|
if(new_packet->seq_num < chain->expected_seq_num){
|
|
//see if this packet contains any data we are missing
|
|
//see if this packet contains any data we are missing
|
|
- printf("Received repeat packet (expected %d, received %d\n", chain->expected_seq_num, new_packet->seq_num);
|
|
|
|
|
|
+ printf("Received replayed packet O.o\n");
|
|
free(new_packet->data);
|
|
free(new_packet->data);
|
|
free(new_packet);
|
|
free(new_packet);
|
|
|
|
|
|
@@ -797,7 +797,6 @@ int add_packet(flow *f, struct packet_info *info){
|
|
|
|
|
|
//place packet after current
|
|
//place packet after current
|
|
if(previous == NULL){
|
|
if(previous == NULL){
|
|
- printf("Packet goes to beginning of chain\n");
|
|
|
|
//goes at the beginning of chain
|
|
//goes at the beginning of chain
|
|
new_packet->next = chain->first_packet;
|
|
new_packet->next = chain->first_packet;
|
|
chain->first_packet = new_packet;
|
|
chain->first_packet = new_packet;
|
|
@@ -807,21 +806,14 @@ int add_packet(flow *f, struct packet_info *info){
|
|
const struct record_header *record_hdr = (struct record_header *) new_packet->data;
|
|
const struct record_header *record_hdr = (struct record_header *) new_packet->data;
|
|
chain->record_len = RECORD_LEN(record_hdr)+RECORD_HEADER_LEN;
|
|
chain->record_len = RECORD_LEN(record_hdr)+RECORD_HEADER_LEN;
|
|
chain->remaining_record_len = chain->record_len;
|
|
chain->remaining_record_len = chain->record_len;
|
|
- fprintf(stdout, "New Record:\n");
|
|
|
|
- for(int i=0; i< RECORD_HEADER_LEN; i++){
|
|
|
|
- printf("%02x ", ((uint8_t *) record_hdr)[i]);
|
|
|
|
- }
|
|
|
|
- printf("\n");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
} else {
|
|
} else {
|
|
- printf("Appended packet to chain\n");
|
|
|
|
new_packet->next = next;
|
|
new_packet->next = next;
|
|
previous->next = new_packet;
|
|
previous->next = new_packet;
|
|
}
|
|
}
|
|
|
|
|
|
if(new_packet->seq_num == chain->expected_seq_num){
|
|
if(new_packet->seq_num == chain->expected_seq_num){
|
|
- printf("Received expected packet (expected %u)\n", chain->expected_seq_num);
|
|
|
|
chain->expected_seq_num += new_packet->len;
|
|
chain->expected_seq_num += new_packet->len;
|
|
|
|
|
|
//while there is still data left:
|
|
//while there is still data left:
|
|
@@ -830,9 +822,9 @@ int add_packet(flow *f, struct packet_info *info){
|
|
|
|
|
|
//if full record, give to update_flow
|
|
//if full record, give to update_flow
|
|
if(chain->remaining_record_len <= new_packet->len){
|
|
if(chain->remaining_record_len <= new_packet->len){
|
|
- printf("Completed remaining record!\n");
|
|
|
|
chain->remaining_record_len = 0;
|
|
chain->remaining_record_len = 0;
|
|
uint8_t *record = calloc(1, chain->record_len);
|
|
uint8_t *record = calloc(1, chain->record_len);
|
|
|
|
+ uint32_t record_len = chain->record_len;
|
|
uint32_t tmp_len = chain->record_len;
|
|
uint32_t tmp_len = chain->record_len;
|
|
packet *next = chain->first_packet;
|
|
packet *next = chain->first_packet;
|
|
while(tmp_len > 0){
|
|
while(tmp_len > 0){
|
|
@@ -844,7 +836,6 @@ int add_packet(flow *f, struct packet_info *info){
|
|
free(next->data);
|
|
free(next->data);
|
|
free(next);
|
|
free(next);
|
|
next = chain->first_packet;
|
|
next = chain->first_packet;
|
|
- printf("used up packet\n");
|
|
|
|
available_data = 0;
|
|
available_data = 0;
|
|
} else {
|
|
} else {
|
|
memcpy(record+chain->record_len - tmp_len, next->data, tmp_len);
|
|
memcpy(record+chain->record_len - tmp_len, next->data, tmp_len);
|
|
@@ -852,23 +843,30 @@ int add_packet(flow *f, struct packet_info *info){
|
|
next->len -= tmp_len;
|
|
next->len -= tmp_len;
|
|
available_data -= tmp_len;
|
|
available_data -= tmp_len;
|
|
tmp_len = 0;
|
|
tmp_len = 0;
|
|
- printf("There are %d bytes of packet remaining\n", next->len);
|
|
|
|
//this is going to be a new record
|
|
//this is going to be a new record
|
|
const struct record_header *record_hdr = (struct record_header *) next->data;
|
|
const struct record_header *record_hdr = (struct record_header *) next->data;
|
|
chain->record_len = RECORD_LEN(record_hdr)+RECORD_HEADER_LEN;
|
|
chain->record_len = RECORD_LEN(record_hdr)+RECORD_HEADER_LEN;
|
|
chain->remaining_record_len = chain->record_len;
|
|
chain->remaining_record_len = chain->record_len;
|
|
- fprintf(stdout, "New Record:\n");
|
|
|
|
- for(int i=0; i< RECORD_HEADER_LEN; i++){
|
|
|
|
- printf("%02x ", ((uint8_t *) record_hdr)[i]);
|
|
|
|
- }
|
|
|
|
- printf("\n");
|
|
|
|
|
|
+ printf("Found record of type %d\n", record_hdr->type);
|
|
|
|
+ fflush(stdout);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- update_flow(f, record, incoming);
|
|
|
|
|
|
+ //if handshake is complete, send to relay code
|
|
|
|
+ if(f->application == 1){
|
|
|
|
+ //update packet info and send to replace_packet
|
|
|
|
+ printf("Packet contains application data!\n");
|
|
|
|
+ struct packet_info *copy_info = copy_packet_info(info);
|
|
|
|
+ copy_info->app_data = record;
|
|
|
|
+ copy_info->app_data_len = record_len;
|
|
|
|
+ replace_packet(f, copy_info);
|
|
|
|
+ free(copy_info->app_data);
|
|
|
|
+ free(copy_info);
|
|
|
|
+ } else {
|
|
|
|
+ update_flow(f, record, incoming);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
chain->remaining_record_len -= new_packet->len;
|
|
chain->remaining_record_len -= new_packet->len;
|
|
- printf("Still have %d bytes remaining in record\n", chain->remaining_record_len);
|
|
|
|
//see if this packet filled a hole
|
|
//see if this packet filled a hole
|
|
new_packet = new_packet->next;
|
|
new_packet = new_packet->next;
|
|
if(new_packet != NULL &&
|
|
if(new_packet != NULL &&
|