2011-11-14 15:57:52 +01:00
|
|
|
/*
|
|
|
|
* digest.c, SJ
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <piler.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
|
|
|
|
|
2011-11-16 14:47:47 +01:00
|
|
|
int make_body_digest(struct session_data *sdata, struct __config *cfg){
|
2011-11-14 15:57:52 +01:00
|
|
|
int i=0, n, fd;
|
|
|
|
char *p, *body=NULL;
|
2011-11-16 14:47:47 +01:00
|
|
|
unsigned char buf[MAXBUFSIZE], md[DIGEST_LENGTH];
|
|
|
|
SHA256_CTX context;
|
|
|
|
|
|
|
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: digesting", sdata->ttmpfile);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
|
|
|
memset(sdata->bodydigest, 0, 2*DIGEST_LENGTH+1);
|
2011-11-16 14:47:47 +01:00
|
|
|
SHA256_Init(&context);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
|
|
|
fd = open(sdata->ttmpfile, O_RDONLY);
|
|
|
|
if(fd == -1) return -1;
|
|
|
|
|
|
|
|
while((n = read(fd, buf, MAXBUFSIZE)) > 0){
|
|
|
|
body = (char *)&buf[0];
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(i == 1){
|
|
|
|
p = strstr((char*)buf, "\n\n");
|
|
|
|
if(p){
|
|
|
|
body = p+2;
|
|
|
|
n = strlen(body);
|
|
|
|
} else {
|
|
|
|
p = strstr((char*)buf, "\n\r\n");
|
|
|
|
if(p){
|
|
|
|
body = p+3;
|
|
|
|
n = strlen(body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-16 14:47:47 +01:00
|
|
|
SHA256_Update(&context, body, n);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2011-11-16 14:47:47 +01:00
|
|
|
SHA256_Final(md, &context);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
|
|
|
for(i=0;i<DIGEST_LENGTH;i++)
|
2011-11-16 14:47:47 +01:00
|
|
|
snprintf(sdata->bodydigest + i*2, 2*DIGEST_LENGTH, "%02x", md[i]);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|