mirror of https://github.com/D4-project/d4-core
added hmac from the header and payload in the header
parent
8e00adae42
commit
0978d5cc0f
12
client/d4.c
12
client/d4.c
|
@ -164,10 +164,12 @@ void d4_transfert(d4_t* d4)
|
||||||
{
|
{
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
char* buf;
|
char* buf;
|
||||||
|
unsigned char* hmac;
|
||||||
|
|
||||||
buf = calloc(1, d4->snaplen);
|
buf = calloc(1, d4->snaplen);
|
||||||
|
hmac = calloc(1,SZHMAC);
|
||||||
//TODO error handling -> insert error message
|
//TODO error handling -> insert error message
|
||||||
if (!buf)
|
if ((buf == NULL) && (hmac == NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d4_prepare_header(d4);
|
d4_prepare_header(d4);
|
||||||
|
@ -177,9 +179,15 @@ void d4_transfert(d4_t* d4)
|
||||||
nread = read(d4->source.fd, buf, d4->snaplen);
|
nread = read(d4->source.fd, buf, d4->snaplen);
|
||||||
if ( nread > 0 ) {
|
if ( nread > 0 ) {
|
||||||
d4_update_header(d4, nread);
|
d4_update_header(d4, nread);
|
||||||
//TODO hmac header and payload
|
//Do HMAC on header and payload. HMAC field is 0 during computation
|
||||||
|
hmac_sha256_update(d4->ctx, (const unsigned char*)&d4->header,
|
||||||
|
sizeof(d4_header_t));
|
||||||
|
hmac_sha256_update(d4->ctx, (const unsigned char*)buf, nread);
|
||||||
write(d4->destination.fd, &d4->header, sizeof(d4->header));
|
write(d4->destination.fd, &d4->header, sizeof(d4->header));
|
||||||
write(d4->destination.fd,buf,nread);
|
write(d4->destination.fd,buf,nread);
|
||||||
|
hmac_sha256_final(d4->ctx, hmac, SZHMAC);
|
||||||
|
//Add it to the header
|
||||||
|
memcpy(d4->header.hmac, hmac, SZHMAC);
|
||||||
} else{
|
} else{
|
||||||
//FIXME no data available, sleep, abort, retry
|
//FIXME no data available, sleep, abort, retry
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#define NERRORS 100
|
#define NERRORS 100
|
||||||
#define SZCONFVALUE 1024
|
#define SZCONFVALUE 1024
|
||||||
#define SZERRVALUE 1024
|
#define SZERRVALUE 1024
|
||||||
|
#define SZHMAC 32
|
||||||
|
|
||||||
#define STDIN "stdin"
|
#define STDIN "stdin"
|
||||||
#define STDOUT "stdout"
|
#define STDOUT "stdout"
|
||||||
|
@ -24,7 +25,7 @@ typedef struct d4_header_s {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t uuid[SZUUID];
|
uint8_t uuid[SZUUID];
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
uint8_t hmac[256];
|
uint8_t hmac[SZHMAC];
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
} d4_header_t;
|
} d4_header_t;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue