[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stegotorus/master] Modified jsSteg and pdfSteg to generate fixed HTTP headers for the responses, and modified x_http2 and jsSteg to respond with html when html is requested, and to respond with js when js is requested.
commit 67f7f83208f1e34d2e8b070afcff4b296f0df431
Author: Steven Cheung <cheung@xxxxxxxxxxx>
Date: Wed Nov 2 17:38:25 2011 +0000
Modified jsSteg and pdfSteg to generate fixed HTTP headers for the responses, and modified x_http2 and jsSteg to respond with html when html is requested, and to respond with js when js is requested.
git-svn-id: svn+ssh://spartan.csl.sri.com/svn/private/DEFIANCE@114 a58ff0ac-194c-e011-a152-003048836090
---
src/steg/jsSteg.c | 112 +++++++++++++++++++++++++--------------------------
src/steg/jsSteg.h | 2 +-
src/steg/payloads.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++----
src/steg/payloads.h | 12 +++--
src/steg/pdfSteg.c | 31 +++++++++-----
src/steg/x_http2.c | 29 ++++++++++++-
6 files changed, 216 insertions(+), 83 deletions(-)
diff --git a/src/steg/jsSteg.c b/src/steg/jsSteg.c
index 5946062..9c67949 100644
--- a/src/steg/jsSteg.c
+++ b/src/steg/jsSteg.c
@@ -2,6 +2,8 @@
#include "jsSteg.h"
#include "cookies.h"
+void buf_dump(unsigned char* buf, int len, FILE *out);
+
/*
* jsSteg: A Javascript-based steganography module
@@ -610,7 +612,7 @@ int testDecode2(char *inBuf, char *outBuf,
int
-x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
+x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn, unsigned int content_type) {
struct evbuffer_iovec *iv;
int nv;
@@ -620,6 +622,9 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
char data[(int) sbuflen*2];
unsigned int datalen;
+ char newHdr[MAX_RESP_HDR_SIZE];
+ int newHdrLen = 0;
+
size_t sofar = 0;
unsigned int cnt = 0;
int r;
@@ -638,12 +643,12 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
int mode;
char *hend;
unsigned int hLen;
- unsigned int mjs;
+ unsigned int mjs = 0;
char *jsTemplate = NULL;
int jsTemplateSize = 0;
-
+
/* int hdrLen;
@@ -660,6 +665,13 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
log_debug("sbuflen = %d sofar = %d\n", (int) sbuflen, (int) sofar);
+
+ if (content_type != HTTP_CONTENT_JAVASCRIPT &&
+ content_type != HTTP_CONTENT_HTML) {
+ log_warn("SERVER ERROR: Unknown content type (%d)", content_type);
+ return -1;
+ }
+
// log_debug("SERVER: dumping data with length %d:", (int) sbuflen);
// evbuffer_dump(source, stderr);
// Convert data in 'source' to hexadecimal and write it to data
@@ -675,15 +687,19 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
// jsTemplate should be init already, by x_http2_new or the previous invocation
// of this function
- mjs = get_max_JS_capacity();
+ if (content_type == HTTP_CONTENT_JAVASCRIPT) {
+ mjs = get_max_JS_capacity();
+ } else if (content_type == HTTP_CONTENT_HTML) {
+ mjs = get_max_HTML_capacity();
+ }
if (mjs <= 0) {
- log_debug("SERVER ERROR: (server_transmit) No JavaScript found in jsTemplate\n");
+ log_warn("SERVER ERROR: No JavaScript found in jsTemplate");
return -1;
- }
+ }
if (sbuflen > (size_t) mjs) {
- log_debug("SERVER ERROR: (server_transmit) jsTemplate cannot accommodate data %d %dn",
+ log_warn("SERVER ERROR: (server_transmit) jsTemplate cannot accommodate data %d %dn",
(int) sbuflen, (int) mjs);
return -1;
}
@@ -712,10 +728,10 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
- if (get_payload(HTTP_CONTENT_JAVASCRIPT, datalen, &jsTemplate, &jsTemplateSize) == 1) {
+ if (get_payload(content_type, datalen, &jsTemplate, &jsTemplateSize) == 1) {
log_debug("SERVER found the next HTTP response template with size %d", jsTemplateSize);
} else {
- log_debug("SERVER couldn't find the next HTTP response template; reusing the previous one");
+ log_warn("SERVER couldn't find the next HTTP response template; reusing the previous one");
}
log_debug("MJS %d %d", datalen, mjs);
@@ -747,34 +763,10 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
log_debug("SERVER: using HTTP resp template of length = %d\n", jsLen);
// log_debug("HTTP resp tempmlate:");
// buf_dump((unsigned char*)jsTemplate, jsLen, stderr);
- // fprintf(stderr, "==========================\n");
hLen = hend+4-jsTemplate;
r = encodeHTTPBody(data, hend+4, outbuf, datalen, jsLen-hLen, HTTP_MSG_BUF_SIZE, mode);
-
-
-
- /// NEW STUFF
-
-
-/* hdrLen = strstr(jsTemplate, "\r\n\r\n") - jsTemplate + 4;
- tmp = strstr(jsTemplate, "Content-Length: ") + strlen("Content-Length: ");
-
- content_len = atoi(tmp);
-
-
- decCnt = decodeHTTPBody(jsTemplate + hdrLen, data2, content_len, HTTP_MSG_BUF_SIZE, &fin2, mode);
-
-
- if (decCnt == (int) datalen)
- fprintf(stderr, "cnts match\n");
- else
- fprintf(stderr, "cnts don't match %d %d\n", decCnt, datalen);
-
-*/
-
-
if (r < 0 || ((unsigned int) r < datalen)) {
fprintf(stderr, "incomplete data encoding\n");
exit(-1);
@@ -782,20 +774,32 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
return -1;
}
- // note: the transformation is length-preserving for now
- log_debug("SERVER: HTTP body with encoded data:");
- // buf_dump((unsigned char*)outbuf, jsLen-hLen, stderr);
- // fprintf(stderr, "==========================\n");
+ if (mode == CONTENT_JAVASCRIPT) { // JavaScript in HTTP body
+ newHdrLen = gen_response_header((char*) "application/x-javascript", 0, jsLen-hLen, newHdr, sizeof(newHdr));
+ } else if (mode == CONTENT_HTML_JAVASCRIPT) { // JavaScript(s) embedded in HTML doc
+ newHdrLen = gen_response_header((char*) "text/html", 0, jsLen-hLen, newHdr, sizeof(newHdr));
+ } else { // unknown mode
+ log_warn("SERVER ERROR: unknown mode for creating the HTTP response header");
+ return -1;
+ }
+ if (newHdrLen < 0) {
+ log_warn("SERVER ERROR: gen_response_header fails for jsSteg");
+ return -1;
+ }
- if (evbuffer_add(dest, jsTemplate, hLen)) {
- log_debug("SERVER ERROR: x_http2_server_transmit: evbuffer_add() fails for jsTemplate");
+ if (evbuffer_add(dest, newHdr, newHdrLen)) {
+ log_warn("SERVER ERROR: evbuffer_add() fails for newHdr");
return -1;
}
- // fprintf(stderr, "HELLO ==========================\n");
+ // if (evbuffer_add(dest, jsTemplate, hLen)) {
+ // log_warn("SERVER ERROR: evbuffer_add() fails for jsTemplate");
+ // return -1;
+ // }
+
if (evbuffer_add(dest, outbuf, jsLen-hLen)) {
- log_debug("SERVER ERROR: x_http2_server_transmit: evbuffer_add() fails for outbuf");
+ log_warn("SERVER ERROR: evbuffer_add() fails for outbuf");
return -1;
}
@@ -804,7 +808,6 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
// } while (sbuflen > sofar);
-
// fprintf(stderr, "SERVER TRANSMITTED payload of size %d\n", (int) sbuflen);
// obtain a usable HTTP response template for the next data, and
@@ -814,10 +817,6 @@ x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn) {
log_debug("SERVER finding the next HTTP response template");
-
-
-
- // conn_cease_transmission(conn);
conn_close_after_transmit(conn);
// downcast_steg(s)->have_transmitted = 1;
return 0;
@@ -920,9 +919,9 @@ x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest,
}
log_debug("CLIENT received HTTP response with length %d\n", response_len);
- log_debug("HTTP response:");
- // buf_dump((unsigned char*)respMsg, response_len, stderr);
- // fprintf(stderr, "==========================\n");
+ // buf_dump((unsigned char*)respMsg, response_len, stderr);
+ // log_debug("HTTP response header:");
+ // buf_dump((unsigned char*)respMsg, hdrLen, stderr);
httpBody = respMsg + hdrLen;
@@ -936,7 +935,6 @@ x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest,
log_debug("CLIENT Before decodeHTTPBody; mode: %d\n", mode);
- // call decodeHTTPBody
decCnt = decodeHTTPBody(httpBody, data, response_len-hdrLen, HTTP_MSG_BUF_SIZE, &fin, mode);
data[decCnt] = 0;
@@ -950,12 +948,12 @@ x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest,
}
if (! isxString(data)) {
- log_debug("CLIENT ERROR: Data received not hex");
+ log_warn("CLIENT ERROR: Data received not hex");
// buf_dump((unsigned char*)data, decCnt, stderr);
return RECV_BAD;
}
- log_debug("Hex data received:");
+ // log_debug("Hex data received:");
// buf_dump ((unsigned char*)data, decCnt, stderr);
// get a scratch buffer
@@ -963,7 +961,7 @@ x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest,
if (!scratch) return RECV_BAD;
if (evbuffer_expand(scratch, decCnt/2)) {
- log_debug("CLIENT ERROR: Evbuffer expand failed \n");
+ log_warn("CLIENT ERROR: Evbuffer expand failed \n");
evbuffer_free(scratch);
return RECV_BAD;
}
@@ -975,16 +973,16 @@ x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest,
evbuffer_add(scratch, &c, 1);
}
- log_debug("CLIENT Done converting hex data to binary:\n");
+ // log_debug("CLIENT Done converting hex data to binary:\n");
// evbuffer_dump(scratch, stderr);
// fprintf(stderr, "CLIENT RECEIVED payload of size %d\n", (int) evbuffer_get_length(scratch));
- // add the scratch buffer (which contains the data) to dest
+ // add the scratch buffer (which contains the data) to dest
if (evbuffer_add_buffer(dest, scratch)) {
evbuffer_free(scratch);
- log_debug("CLIENT ERROR: Failed to transfer buffer");
+ log_warn("CLIENT ERROR: Failed to transfer buffer");
return RECV_BAD;
}
log_debug("Added scratch (buffer) to dest\n");
@@ -994,7 +992,7 @@ x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest,
if (response_len <= evbuffer_get_length(source)) {
if (evbuffer_drain(source, response_len) == -1) {
- log_debug("CLIENT ERROR: Added scratch (buffer) to dest\n");
+ log_warn("CLIENT ERROR: Failed to drain source");
return RECV_BAD;
}
}
diff --git a/src/steg/jsSteg.h b/src/steg/jsSteg.h
index 3c5f6ae..c076460 100644
--- a/src/steg/jsSteg.h
+++ b/src/steg/jsSteg.h
@@ -53,7 +53,7 @@ int testDecode2(char *inBuf, char *outBuf,
int
-x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn);
+x_http2_server_JS_transmit (steg_t* s, struct evbuffer *source, conn_t *conn, unsigned int content_type);
int
x_http2_handle_client_JS_receive(steg_t *s, conn_t *conn, struct evbuffer *dest, struct evbuffer* source);
diff --git a/src/steg/payloads.c b/src/steg/payloads.c
index 8d0b8fe..017c469 100644
--- a/src/steg/payloads.c
+++ b/src/steg/payloads.c
@@ -12,6 +12,7 @@ static int typePayloadCap[MAX_CONTENT_TYPE][MAX_PAYLOADS];
static unsigned int max_JS_capacity = 0;
+static unsigned int max_HTML_capacity = 0;
static unsigned int max_PDF_capacity = 0;
@@ -25,6 +26,10 @@ unsigned int get_max_JS_capacity() {
return max_JS_capacity;
}
+unsigned int get_max_HTML_capacity() {
+ return max_HTML_capacity;
+}
+
unsigned int get_max_PDF_capacity() {
return max_PDF_capacity;
}
@@ -422,12 +427,15 @@ find_uri_type(char* buf) {
if (!strncmp(ext, ".swf", 4) || !strncmp(ext, ".SWF", 4))
return HTTP_CONTENT_SWF;
- // if (!strncmp(ext, ".js", 3) || !strncmp(ext, ".JS", 3))
- return HTTP_CONTENT_JAVASCRIPT;
+ if (!strncmp(ext, ".js", 3) || !strncmp(ext, ".JS", 3))
+ return HTTP_CONTENT_JAVASCRIPT;
if (!strncmp(ext-1, "html", 4) || !strncmp(ext, "htm", 3) || strchr(ext-1, '.') == NULL)
return HTTP_CONTENT_HTML;
+ // default type
+ return HTTP_CONTENT_HTML;
+ // return HTTP_CONTENT_JAVASCRIPT;
return -1;
}
@@ -441,7 +449,6 @@ find_uri_type(char* buf) {
-
unsigned int find_client_payload(char* buf, int len, int type) {
int r = rand() % payload_count;
int cnt = 0;
@@ -455,8 +462,10 @@ unsigned int find_client_payload(char* buf, int len, int type) {
if (p->ptype == type) {
inbuf = payloads[r];
if (find_uri_type(inbuf) != HTTP_CONTENT_SWF &&
- find_uri_type(inbuf) != HTTP_CONTENT_JAVASCRIPT)
+ find_uri_type(inbuf) != HTTP_CONTENT_HTML &&
+ find_uri_type(inbuf) != HTTP_CONTENT_JAVASCRIPT) {
goto next;
+ }
if (p->length > len) {
fprintf(stderr, "BUFFER TOO SMALL... \n");
goto next;
@@ -490,7 +499,7 @@ unsigned int find_client_payload(char* buf, int len, int type) {
* keyword
*
* todo:
- * Use a more efficient algo (e.g., Aho-Corasick) in the next iteration
+ * Use a more efficient regular expression matching algo
*/
int skipJSPattern (char *cp, int len) {
@@ -864,10 +873,10 @@ int has_eligible_HTTP_content (char* buf, int len, int type) {
#endif
if (type != HTTP_CONTENT_JAVASCRIPT &&
+ type != HTTP_CONTENT_HTML &&
type != HTTP_CONTENT_PDF && type != HTTP_CONTENT_SWF)
return 0;
-
// assumption: buf is null-terminated
if (!strstr(buf, "\r\n\r\n"))
return 0;
@@ -918,7 +927,8 @@ int has_eligible_HTTP_content (char* buf, int len, int type) {
tjFlag, thFlag, ceFlag, teFlag, http304Flag, clZeroFlag);
#endif
- if (type == HTTP_CONTENT_JAVASCRIPT) {
+ // if (type == HTTP_CONTENT_JAVASCRIPT)
+ if (type == HTTP_CONTENT_JAVASCRIPT || type == HTTP_CONTENT_HTML) {
// empty body if it's HTTP not modified (304) or zero Content-Length
if (http304Flag || clZeroFlag) return 0;
@@ -1072,7 +1082,7 @@ int init_JS_payload_pool(int len, int type, int minCapacity) {
msgbuf = payloads[r];
mode = has_eligible_HTTP_content(msgbuf, p->length, HTTP_CONTENT_JAVASCRIPT);
- if (mode > 0) {
+ if (mode == CONTENT_JAVASCRIPT) {
cap = capacityJS3(msgbuf, p->length, mode);
if (cap < JS_DELIMITER_SIZE)
@@ -1124,6 +1134,93 @@ int init_JS_payload_pool(int len, int type, int minCapacity) {
}
+int init_HTML_payload_pool(int len, int type, int minCapacity) {
+
+ // stat for usable payload
+ int minPayloadSize = 0, maxPayloadSize = 0;
+ int sumPayloadSize = 0;
+ int minPayloadCap = 0, maxPayloadCap = 0;
+ int sumPayloadCap = 0;
+
+ unsigned int contentType = HTTP_CONTENT_HTML;
+
+ int cnt = 0;
+ int r;
+ pentry_header* p;
+ char* msgbuf;
+ int cap;
+ int mode;
+
+
+
+ if (payload_count == 0) {
+ log_debug("payload_count == 0; forgot to run load_payloads()?\n");
+ return 0;
+ }
+
+ if (initTypePayload[contentType] != 0) return 1; // init is done already
+
+
+ for (r = 0; r < payload_count; r++) {
+ p = &payload_hdrs[r];
+ if (p->ptype != type || p->length > len) {
+ continue;
+ }
+
+ msgbuf = payloads[r];
+
+ mode = has_eligible_HTTP_content(msgbuf, p->length, HTTP_CONTENT_HTML);
+ if (mode == CONTENT_HTML_JAVASCRIPT) {
+
+ cap = capacityJS3(msgbuf, p->length, mode);
+ if (cap < JS_DELIMITER_SIZE)
+ continue;
+
+ cap = (cap - JS_DELIMITER_SIZE)/2;
+
+ if (cap > minCapacity) {
+ typePayloadCap[contentType][cnt] = cap; // (cap-JS_DELIMITER_SIZE)/2;
+ // because we use 2 hex char to encode every data byte, the available
+ // capacity for encoding data is divided by 2
+ typePayload[contentType][cnt] = r;
+ cnt++;
+
+ // update stat
+ if (cnt == 1) {
+ minPayloadSize = p->length; maxPayloadSize = p->length;
+ minPayloadCap = cap; maxPayloadCap = cap;
+ }
+ else {
+ if (minPayloadSize > p->length) minPayloadSize = p->length;
+ if (maxPayloadSize < p->length) maxPayloadSize = p->length;
+ if (minPayloadCap > cap) minPayloadCap = cap;
+ if (maxPayloadCap < cap) {
+ maxPayloadCap = cap;
+ }
+
+ }
+ sumPayloadSize += p->length; sumPayloadCap += cap;
+ }
+ }
+ }
+
+
+ max_HTML_capacity = maxPayloadCap;
+
+
+ initTypePayload[contentType] = 1;
+ typePayloadCount[contentType] = cnt;
+ log_debug("init_payload_pool: typePayloadCount for contentType %d = %d",
+ contentType, typePayloadCount[contentType]);
+ log_debug("minPayloadSize = %d", minPayloadSize);
+ log_debug("maxPayloadSize = %d", maxPayloadSize);
+ log_debug("avgPayloadSize = %f", (float)sumPayloadSize/(float)cnt);
+ log_debug("minPayloadCap = %d", minPayloadCap);
+ log_debug("maxPayloadCap = %d", maxPayloadCap);
+ log_debug("avgPayloadCap = %f", (float)sumPayloadCap/(float)cnt);
+ return 1;
+}
+
diff --git a/src/steg/payloads.h b/src/steg/payloads.h
index b3fcc9d..56729fe 100644
--- a/src/steg/payloads.h
+++ b/src/steg/payloads.h
@@ -28,7 +28,8 @@
#define NO_NEXT_STATE -1
#define MAX_PAYLOADS 10000
-// #define HTTP_MSG_BUF_SIZE 100000
+#define MAX_RESP_HDR_SIZE 512
+
// jsSteg-specific defines
#define JS_DELIMITER '?'
@@ -39,13 +40,12 @@
// data encoding will be replaced by JS_DELIMITER_REPLACEMENT
#define JS_DELIMITER_SIZE 1
-#define JS_MIN_AVAIL_SIZE 2050
+// #define JS_MIN_AVAIL_SIZE 2050
+#define JS_MIN_AVAIL_SIZE 1026
// JS_MIN_AVAIL_SIZE should reflect the min number of data bytes
// a JavaScript may encapsulate
-// Using hex-based encoding, it takes 2 hex char in JS
-// to encode 1 data byte. Thus the size of data that can be encoded
-// is about half this value
+#define HTML_MIN_AVAIL_SIZE 1026
#define PDF_DELIMITER_SIZE 2
#define PDF_MIN_AVAIL_SIZE 10240
@@ -128,6 +128,7 @@ unsigned int find_server_payload(char** buf, int len, int type, int contentType)
int init_JS_payload_pool(int len, int type, int minCapacity);
int init_SWF_payload_pool(int len, int type, int minCapacity);
int init_PDF_payload_pool(int len, int type,int minCapacity);
+int init_HTML_payload_pool(int len, int type, int minCapacity);
int get_next_payload (int contentType, char** buf, int* size, int* cap);
@@ -145,6 +146,7 @@ int offset2Hex (char *p, int range, int isLastCharHex);
unsigned int capacityJS (char* buf, int len, int mode);
unsigned int capacityJS3 (char* buf, int len, int mode);
unsigned int get_max_JS_capacity(void);
+unsigned int get_max_HTML_capacity(void);
char * strInBinary (const char *pattern, unsigned int patternLen, const char *blob, unsigned int blobLen);
diff --git a/src/steg/pdfSteg.c b/src/steg/pdfSteg.c
index 05216f9..4a91e55 100644
--- a/src/steg/pdfSteg.c
+++ b/src/steg/pdfSteg.c
@@ -79,8 +79,12 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
*
* returns the length of data written to outbuf, if succeed;
* otherwise, it returns -1
+ *
* endFlag indicates whether the end-of-encoding byte pattern (i.e.,
* delimiter1 followed by non-delimiter1) is detected
+ *
+ * escape indicates if a dangling delimiter1 has been
+ * seen in the previous invocation of removeDelimiter
*/
int
removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
@@ -113,16 +117,13 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
while ((ibp-inbuf+1)<inbuflen && cnt<outbuflen) {
ic1 = *(ibp++);
if (ic1 != delimiter1) {
- // *escape = 0;
outbuf[cnt++] = ic1;
} else {
- // *escape = 1;
// lookahead 1 char
ic2 = *ibp;
// if the next char is delimiter1
if (ic2 == delimiter1) {
outbuf[cnt++] = delimiter1; ibp++;
- // *escape = 0;
} else { // end-of-data pattern detected
*endFlag = 1;
break;
@@ -130,10 +131,6 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
}
}
- // if (*escape) {
- // *escape = 0;
- // return cnt;
- // }
if (ibp-inbuf == inbuflen) return cnt;
// handling the last char in inbuf, if needed
@@ -217,7 +214,7 @@ pdfWrap (char *data, unsigned int dlen,
memcpy(op, dp, size2);
op += size2; tp += size2; dp += size2;
cnt += size2;
- printf("Encoded %d char in pdf. Done encoding\n", size2);
+ // printf("Encoded %d char in pdf. Done encoding\n", size2);
break;
}
log_debug("Encoded %d char in pdf", size);
@@ -311,6 +308,9 @@ int x_http2_server_PDF_transmit (steg_t* s, struct evbuffer *source, conn_t *con
char outbuf[HTTP_MSG_BUF_SIZE];
int cnt, hLen, outbuflen, i;
+ char newHdr[MAX_RESP_HDR_SIZE];
+ int newHdrLen = 0;
+
struct evbuffer_iovec *iv;
int nv;
@@ -400,10 +400,21 @@ int x_http2_server_PDF_transmit (steg_t* s, struct evbuffer *source, conn_t *con
// }
- if (evbuffer_add(dest, pdfTemplate, hLen)) {
- log_warn("SERVER ERROR: evbuffer_add() fails for pdfTemplate");
+ newHdrLen = gen_response_header((char*) "application/pdf", 0, outbuflen, newHdr, sizeof(newHdr));
+ if (newHdrLen < 0) {
+ log_warn("SERVER ERROR: gen_response_header fails for pdfSteg");
return -1;
}
+
+ if (evbuffer_add(dest, newHdr, newHdrLen)) {
+ log_warn("SERVER ERROR: evbuffer_add() fails for newHdr");
+ return -1;
+ }
+ // if (evbuffer_add(dest, pdfTemplate, hLen)) {
+ // log_warn("SERVER ERROR: evbuffer_add() fails for pdfTemplate");
+ // return -1;
+ // }
+
if (evbuffer_add(dest, outbuf, outbuflen)) {
log_warn("SERVER ERROR: evbuffer_add() fails for outbuf");
return -1;
diff --git a/src/steg/x_http2.c b/src/steg/x_http2.c
index 0710fa7..f3789b2 100644
--- a/src/steg/x_http2.c
+++ b/src/steg/x_http2.c
@@ -49,6 +49,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
#define MIN_COOKIE_SIZE 128
#define MAX_COOKIE_SIZE 2048
@@ -154,6 +156,7 @@ x_http2_new(rng_t *rng, unsigned int is_clientside)
else {
load_payloads("traces/server.out");
init_JS_payload_pool(HTTP_MSG_BUF_SIZE, TYPE_HTTP_RESPONSE, JS_MIN_AVAIL_SIZE);
+ init_HTML_payload_pool(HTTP_MSG_BUF_SIZE, TYPE_HTTP_RESPONSE, HTML_MIN_AVAIL_SIZE);
// init_PDF_payload_pool(HTTP_MSG_BUF_SIZE, TYPE_HTTP_RESPONSE, PDF_MIN_AVAIL_SIZE);
init_SWF_payload_pool(HTTP_MSG_BUF_SIZE, TYPE_HTTP_RESPONSE, 0);
}
@@ -304,6 +307,17 @@ x_http2_transmit_room(steg_t *s, conn_t *conn)
log_warn("js capacity too small\n");
exit(-1);
+ case HTTP_CONTENT_HTML:
+ mjc = get_max_HTML_capacity() / 2;
+ if (mjc > 1024) {
+ // it should be 1024 + ...., but seems like we need to be a little bit smaller (chopper bug?)
+ int rval = 512 + rand()%(mjc - 1024);
+ // fprintf(stderr, "returning rval %d, mjc %d\n", rval, mjc);
+ return rval;
+ }
+ log_warn("js capacity too small\n");
+ exit(-1);
+
case HTTP_CONTENT_PDF:
// return 1024 + rand()%(get_max_PDF_capacity() - 1024)
return PDF_MIN_AVAIL_SIZE;
@@ -462,7 +476,11 @@ x_http2_client_transmit (steg_t *s, struct evbuffer *source, conn_t *conn) {
log_debug("error ***********************");
return -1;
}
-
+
+ // debug
+ // log_warn("CLIENT HTTP request header:");
+ // buf_dump((unsigned char*)buf, len, stderr);
+
// sofar += datalen/2;
evbuffer_drain(source, datalen/2);
@@ -517,8 +535,13 @@ x_http2_transmit(steg_t *s, struct evbuffer *source, conn_t *conn)
case HTTP_CONTENT_SWF:
rval = x_http2_server_SWF_transmit(s, source, conn);
break;
+
case HTTP_CONTENT_JAVASCRIPT:
- rval = x_http2_server_JS_transmit(s, source, conn);
+ rval = x_http2_server_JS_transmit(s, source, conn, HTTP_CONTENT_JAVASCRIPT);
+ break;
+
+ case HTTP_CONTENT_HTML:
+ rval = x_http2_server_JS_transmit(s, source, conn, HTTP_CONTENT_HTML);
break;
case HTTP_CONTENT_PDF:
@@ -680,7 +703,9 @@ x_http2_receive(steg_t *s, conn_t *conn, struct evbuffer *dest)
case HTTP_CONTENT_SWF:
rval = x_http2_handle_client_SWF_receive(s, conn, dest, source);
break;
+
case HTTP_CONTENT_JAVASCRIPT:
+ case HTTP_CONTENT_HTML:
rval = x_http2_handle_client_JS_receive(s, conn, dest, source);
break;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits