tor-commits
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 216106 discussions
commit 8140b7a818a799dfa43f47c13edeb74f1f0daa20
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 16 14:49:44 2012 -0700
Add a cast to make gcc 4.4 happy.
---
src/protocol/chop.cc | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index ad8ac9f..dac4ea2 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -1158,7 +1158,7 @@ chop_conn_t::recv_handshake()
sizeof circuit_id) != sizeof circuit_id)
return -1;
- chop_circuit_table::value_type in(circuit_id, 0);
+ chop_circuit_table::value_type in(circuit_id, (chop_circuit_t *)0);
std::pair<chop_circuit_table::iterator, bool> out
= this->config->circuits.insert(in);
chop_circuit_t *ck;
1
0
[stegotorus/master] Don't enable reading and writing on half-open sockets.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit fc44f29e5cf79b6db5171cb42c9efa5f498b0bd9
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 16 15:02:31 2012 -0700
Don't enable reading and writing on half-open sockets.
---
src/network.cc | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
diff --git a/src/network.cc b/src/network.cc
index 55944fe..f312067 100644
--- a/src/network.cc
+++ b/src/network.cc
@@ -674,7 +674,6 @@ circuit_open_upstream(circuit_t *ckt)
return -1;
success:
- bufferevent_enable(buf, EV_READ|EV_WRITE);
circuit_add_upstream(ckt, buf, peername);
return 0;
}
@@ -717,7 +716,6 @@ create_one_outbound_connection(circuit_t *ckt, struct evutil_addrinfo *addr,
bufferevent_setcb(buf, downstream_read_cb, downstream_flush_cb,
is_socks ? downstream_socks_connect_cb
: downstream_connect_cb, conn);
- bufferevent_enable(buf, EV_READ|EV_WRITE);
return true;
}
@@ -790,7 +788,6 @@ create_outbound_connections_socks(circuit_t *ckt)
ckt->add_downstream(conn);
bufferevent_setcb(buf, downstream_read_cb, downstream_flush_cb,
downstream_socks_connect_cb, conn);
- bufferevent_enable(buf, EV_READ|EV_WRITE);
return;
failure:
1
0
[stegotorus/master] fixed race condition in connection establishment
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 83c892603a3953829a88a40c1ead3fa1088494b3
Author: Steven Cheung <steven.cheung(a)sri.com>
Date: Mon Apr 16 16:25:21 2012 -0700
fixed race condition in connection establishment
---
src/connections.h | 3 ++-
src/network.cc | 20 +++++++++++++++-----
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/connections.h b/src/connections.h
index 9b51ce5..ddf787a 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -19,8 +19,9 @@ struct conn_t {
unsigned int serial;
bool connected : 1;
bool flushing : 1;
+ bool ever_received : 1;
- conn_t() : connected(false), flushing(false) {}
+ conn_t() : connected(false), flushing(false), ever_received(false) {}
/** Close and deallocate a connection. If the connection is part of a
circuit, disconnect it from the circuit; this may cause the circuit
diff --git a/src/network.cc b/src/network.cc
index f312067..fb17e99 100644
--- a/src/network.cc
+++ b/src/network.cc
@@ -312,6 +312,8 @@ downstream_read_cb(struct bufferevent *bev, void *arg)
{
conn_t *down = (conn_t *)arg;
+ down->ever_received = 1;
+
log_debug(down, "%lu bytes available",
(unsigned long)evbuffer_get_length(bufferevent_get_input(bev)));
@@ -375,6 +377,11 @@ downstream_event_cb(struct bufferevent *bev, short what, void *arg)
{
conn_t *conn = (conn_t *)arg;
+ log_debug(conn, "what=%04hx enabled=%x inbound=%ld outbound=%ld",
+ what, bufferevent_get_enabled(bev),
+ evbuffer_get_length(bufferevent_get_input(bev)),
+ evbuffer_get_length(bufferevent_get_output(bev)));
+
if (what & (BEV_EVENT_ERROR|BEV_EVENT_EOF|BEV_EVENT_TIMEOUT)) {
if (what & BEV_EVENT_ERROR)
log_info(conn, "network error in %s: %s",
@@ -393,7 +400,8 @@ downstream_event_cb(struct bufferevent *bev, short what, void *arg)
/* Peer is done sending us data. */
conn->recv_eof();
if (bufferevent_get_enabled(bev) ||
- evbuffer_get_length(bufferevent_get_input(bev)) > 0) {
+ evbuffer_get_length(bufferevent_get_input(bev)) > 0 ||
+ evbuffer_get_length(bufferevent_get_output(bev)) > 0) {
log_debug(conn, "acknowledging EOF downstream");
shutdown(bufferevent_getfd(bev), SHUT_RD);
} else {
@@ -444,14 +452,15 @@ downstream_flush_cb(struct bufferevent *bev, void *arg)
{
conn_t *conn = (conn_t *)arg;
size_t remain = evbuffer_get_length(bufferevent_get_output(bev));
- log_debug(conn, "%lu bytes still to transmit%s%s%s",
+ log_debug(conn, "%lu bytes still to transmit%s%s%s%s",
(unsigned long)remain,
conn->connected ? "" : " (not connected)",
conn->flushing ? "" : " (not flushing)",
- conn->circuit() ? "" : " (no circuit)");
+ conn->circuit() ? "" : " (no circuit)",
+ conn->ever_received ? "" : " (never received)");
if (remain == 0 && ((conn->flushing && conn->connected)
- || !conn->circuit())) {
+ || (!conn->circuit() && conn->ever_received))) {
bufferevent_disable(bev, EV_WRITE);
if (bufferevent_get_enabled(bev)) {
log_debug(conn, "sending EOF downstream");
@@ -822,5 +831,6 @@ conn_do_flush(conn_t *conn)
if (remain == 0)
downstream_flush_cb(conn->buffer, conn);
else
- log_debug(conn, "flushing %lu bytes to peer", (unsigned long)remain);
+ log_debug(conn, "flushing %lu bytes to peer [enabled=%x]", (unsigned long)remain,
+ bufferevent_get_enabled(conn->buffer));
}
1
0
[stegotorus/master] Thorough spring-cleaning on pdfSteg.cc; less thorough on swfSteg.cc and some other headers.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 0538c5a704adaf8149b3a78c84200a77dc657506
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 23 14:49:52 2012 -0700
Thorough spring-cleaning on pdfSteg.cc; less thorough on swfSteg.cc and some other headers.
---
Makefile.am | 1 +
src/steg/pdfSteg.cc | 389 ++++++++++++++------------------------------
src/steg/pdfSteg.h | 38 +++--
src/steg/swfSteg.cc | 18 +--
src/steg/swfSteg.h | 23 +---
src/steg/zpack.h | 11 +-
src/test/tinytest_macros.h | 8 +-
src/util.cc | 3 -
src/util.h | 3 +
9 files changed, 167 insertions(+), 327 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 6ba1b51..86ed489 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,7 @@ stegotorus_SOURCES = \
UTGROUPS = \
src/test/unittest_crypt.cc \
+ src/test/unittest_pdfsteg.cc \
src/test/unittest_socks.cc \
src/test/unittest_config.cc \
src/test/unittest_transfer.cc
diff --git a/src/steg/pdfSteg.cc b/src/steg/pdfSteg.cc
index c67b0f8..3b4bbf0 100644
--- a/src/steg/pdfSteg.cc
+++ b/src/steg/pdfSteg.cc
@@ -1,7 +1,13 @@
-#include "payloads.h"
+#include "util.h"
#include "pdfSteg.h"
+#include "connections.h"
+#include "payloads.h"
+#include <event2/buffer.h>
+
+/* pdfSteg: A PDF-based steganography module */
-void buf_dump(unsigned char* buf, int len, FILE *out);
+#define PDF_DELIMITER '?'
+#define PDF_DELIMITER2 '.'
#define STREAM_BEGIN ">>stream"
#define STREAM_BEGIN_SIZE 8
@@ -10,45 +16,42 @@ void buf_dump(unsigned char* buf, int len, FILE *out);
#define DEBUG
-
/*
- * pdfSteg: A PDF-based steganography module
- *
- */
-
-
-/*
- * addDelimiter processes the input buffer (inbuf) of length inbuflen,
- * copies it to output buffer (outbuf) of size outbufsize,
+ * pdf_add_delimiter processes the input buffer (inbuf) of length
+ * inbuflen, copies it to output buffer (outbuf) of size outbufsize,
* and adds a two-char-long, end-of-data pattern at the end of outbuf
* based on delimiter1 and delimiter2.
*
* The end-of-data pattern consists of delimiter1 followed by a char
* that is not delimiter1. Thus, delimiter1 and delimiter2 must be
* different.
- *
- * If delimiter1 appears in the input buffer, addDelimiter puts two
- * delimiter1 char in output buffer (to enable removeDelimiter to perform
- * the back transformation)
*
- * addDelimiter returns the length of the data written to outbuf, including
- * the end-of-data pattern, if the transformation succeeds;
- * otherwise, it returns -1
+ * If delimiter1 appears in the input buffer, pdf_add_delimiter puts two
+ * delimiter1 characters in the output buffer, so that the transformation
+ * is reversible.
+ *
+ * pdf_add_delimiter returns the length of the data written to outbuf,
+ * including the end-of-data pattern, if the transformation succeeds;
+ * otherwise, it returns -1.
*
*/
-int
-addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
- const char delimiter1, const char delimiter2)
+ssize_t
+pdf_add_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ const char delimiter1, const char delimiter2)
{
- int cnt;
- char *ibp, ic, rc;
+ size_t cnt;
+ const char *ibp;
+ char ic, rc;
- if (delimiter1 == delimiter2) return -1;
+ log_assert(delimiter1 != delimiter2);
+ if (inbuflen > SIZE_T_CEILING || outbuflen > SIZE_T_CEILING)
+ return -1;
cnt = 0;
ibp = inbuf;
- while ((ibp-inbuf)<inbuflen && cnt<(outbuflen-2)) {
- ic = *(ibp++);
+ while (size_t(ibp-inbuf) < inbuflen && cnt < outbuflen-2) {
+ ic = *ibp++;
if (ic != delimiter1) {
outbuf[cnt++] = ic;
} else {
@@ -57,8 +60,9 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
}
}
- // error if outbuf is no large enough for storing the resulting data
- if (cnt >= (outbuflen-2)) return -1;
+ // error if outbuf is not large enough for storing the resulting data
+ if (cnt >= outbuflen-2)
+ return -1;
// put delimiter1 and a char that is not a delimiter1
// as the end-of-data pattern at the end of outbuf
@@ -75,8 +79,9 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
/*
- * removeDelimiter performs the reverse transformation of addDelimiter.
- *
+ * pdf_remove_delimiter performs the reverse transformation of
+ * pdf_add_delimiter.
+ *
* returns the length of data written to outbuf, if succeed;
* otherwise, it returns -1
*
@@ -84,20 +89,23 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
* delimiter1 followed by non-delimiter1) is detected
*
* escape indicates if a dangling delimiter1 has been
- * seen in the previous invocation of removeDelimiter
+ * seen in the previous invocation of pdf_remove_delimiter
*/
-int
-removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
- const char delimiter1, int *endFlag, int *escape)
+ssize_t
+pdf_remove_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ char delimiter1, bool *endFlag, bool *escape)
{
- int cnt;
- char *ibp, ic1, ic2;
+ size_t cnt;
+ const char *ibp;
+ char ic1, ic2;
cnt = 0;
- *endFlag = 0;
+ *endFlag = false;
ibp = inbuf;
- if (inbuflen <= 0) return -1;
+ if (inbuflen > SIZE_T_CEILING || outbuflen > SIZE_T_CEILING)
+ return -1;
// special case: 2-char, end-of-data pattern could be in two buffers
// if *escape == true, we need to see if
@@ -113,9 +121,9 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
}
}
- *escape = 0;
- while ((ibp-inbuf+1)<inbuflen && cnt<outbuflen) {
- ic1 = *(ibp++);
+ *escape = false;
+ while (size_t(ibp-inbuf+1) < inbuflen && cnt < outbuflen) {
+ ic1 = *ibp++;
if (ic1 != delimiter1) {
outbuf[cnt++] = ic1;
} else {
@@ -125,13 +133,14 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
if (ic2 == delimiter1) {
outbuf[cnt++] = delimiter1; ibp++;
} else { // end-of-data pattern detected
- *endFlag = 1;
+ *endFlag = true;
return cnt;
}
}
}
- if (ibp-inbuf == inbuflen) return cnt;
+ if (size_t(ibp-inbuf) == inbuflen)
+ return cnt;
// handling the last char in inbuf, if needed
ic1 = *ibp;
@@ -139,40 +148,46 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
outbuf[cnt++] = ic1;
} else {
// look at the next stream obj to handle the special cases
- *escape = 1;
+ *escape = true;
}
return cnt;
}
-
-
/*
- * pdfWrap embeds data of length dlen inside the stream objects of the PDF
+ * pdf_wrap embeds data of length dlen inside the stream objects of the PDF
* document (length plen) that appears in the body of a HTTP msg, and
* stores the result in the output buffer of size outsize
*
- * pdfWrap returns the length of the pdf document with the data embedded
+ * pdf_wrap returns the length of the pdf document with the data embedded
* inside, if succeed; otherwise, it returns -1 to indicate an error
- *
- */
-int
-pdfWrap (char *data, unsigned int dlen,
- char *pdfTemplate, unsigned int plen,
- char *outbuf, unsigned int outbufsize)
+ *
+ */
+ssize_t
+pdf_wrap(const char *data, size_t dlen,
+ const char *pdfTemplate, size_t plen,
+ char *outbuf, size_t outbufsize)
{
char data2[dlen*2+2];
- char *tp, *dp, *op, *streamStart, *streamEnd, *plimit;
- int data2len, cnt, size, size2;
+ const char *tp, *dp, *plimit;
+ char *op, *streamStart, *streamEnd;
+ size_t data2len, cnt, size, size2;
+ ssize_t rv;
- // assumption: pdfWrap is length-preserving
- if (outbufsize < plen) return -1;
+ if (dlen > SIZE_T_CEILING || plen > SIZE_T_CEILING ||
+ outbufsize > SIZE_T_CEILING)
+ return -1;
- data2len = addDelimiter(data, dlen, data2, HTTP_MSG_BUF_SIZE, PDF_DELIMITER, PDF_DELIMITER2);
- if (data2len < 1) return -1;
+ // assumption: pdf_wrap is length-preserving
+ if (outbufsize < plen) return -1;
+ rv = pdf_add_delimiter(data, dlen, data2, HTTP_MSG_BUF_SIZE,
+ PDF_DELIMITER, PDF_DELIMITER2);
+ if (rv < 1)
+ return -1;
+ data2len = rv;
- op = outbuf; // current pointer for output buffer
+ op = outbuf; // current pointer for output buffer
tp = pdfTemplate; // current pointer for http msg template
dp = data2; // current pointer for data2
cnt = 0; // number of data char encoded
@@ -185,7 +200,7 @@ pdfWrap (char *data, unsigned int dlen,
log_warn("Cannot find stream in pdf");
return -1;
}
-
+
// copy everything between tp and "stream" (inclusive) to outbuf
size = streamStart - tp + STREAM_BEGIN_SIZE;
memcpy(op, tp, size);
@@ -206,18 +221,17 @@ pdfWrap (char *data, unsigned int dlen,
size2 = data2len - cnt;
if (size < size2) {
memcpy(op, dp, size);
- op += size; tp += size; dp += size;
+ op += size; tp += size; dp += size;
memcpy(op, tp, STREAM_END_SIZE);
op += STREAM_END_SIZE; tp += STREAM_END_SIZE;
cnt += size;
} else { // done encoding data
memcpy(op, dp, size2);
- op += size2; tp += size2; dp += size2;
+ op += size2; tp += size2; dp += size2;
cnt += size2;
- // printf("Encoded %d char in pdf. Done encoding\n", size2);
break;
}
- log_debug("Encoded %d char in pdf", size);
+ log_debug("Encoded %lu bytes in pdf", (unsigned long)size);
} else { // empty stream
memcpy(op, tp, STREAM_END_SIZE);
op += STREAM_END_SIZE; tp += STREAM_END_SIZE;
@@ -228,25 +242,27 @@ pdfWrap (char *data, unsigned int dlen,
// copy the rest of pdfTemplate to outbuf
size = plimit-tp;
- log_debug("copying the rest of pdfTemplate to outbuf (size %d)", size);
+ log_debug("copying the rest of pdfTemplate to outbuf (size %lu)",
+ (unsigned long)size);
memcpy(op, tp, size);
op += size;
return (op-outbuf);
}
-
-
-
/*
- * pdfUnwrap is the inverse operation of pdfWrap
+ * pdf_unwrap is the inverse operation of pdf_wrap
*/
-int
-pdfUnwrap (char *data, unsigned int dlen,
- char *outbuf, unsigned int outbufsize)
+ssize_t
+pdf_unwrap(const char *data, size_t dlen,
+ char *outbuf, size_t outbufsize)
{
- char *dp, *op, *streamStart, *streamEnd, *dlimit, *olimit;
- int cnt, size, size2, endFlag;
- int escape = 0;
+ const char *dp, *dlimit;
+ char *op, *streamStart, *streamEnd, *olimit;
+ size_t cnt, size, size2;
+ bool endFlag, escape = false;
+
+ if (dlen > SIZE_T_CEILING || outbufsize > SIZE_T_CEILING)
+ return -1;
dp = data; // current pointer for data
op = outbuf; // current pointer for outbuf
@@ -272,11 +288,13 @@ pdfUnwrap (char *data, unsigned int dlen,
// count the number of usable char between tp and streamEnd
size = streamEnd-dp;
- if (size > 0) {
- size2 = removeDelimiter(dp, size, op, olimit-op, PDF_DELIMITER, &endFlag, &escape);
- if (size2 < 0) {
+ if (size > 0) {
+ ssize_t rv = pdf_remove_delimiter(dp, size, op, olimit-op, PDF_DELIMITER,
+ &endFlag, &escape);
+ if (rv < 0)
return -1;
- }
+
+ size2 = rv;
cnt += size2;
if (endFlag) { // Done decoding
break;
@@ -292,22 +310,16 @@ pdfUnwrap (char *data, unsigned int dlen,
return cnt;
}
-
-
-
-
int
-http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
- conn_t *conn)
+http_server_PDF_transmit(payloads &pl, struct evbuffer *source,
+ conn_t *conn)
{
-
struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
unsigned int mpdf;
char *pdfTemplate = NULL, *hend;
int pdfTemplateSize = 0;
- // char data1[HTTP_MSG_BUF_SIZE];
- char data1[(int) sbuflen];
+ char data1[sbuflen];
char outbuf[HTTP_MSG_BUF_SIZE];
int cnt, hLen, outbuflen, i;
@@ -317,10 +329,6 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
struct evbuffer_iovec *iv;
int nv;
- // for debugging pdfWrap and pdfUnwrap
- // char data2[(int) sbuflen];
- // int data2len;
-
log_debug("Entering SERVER PDF transmit with sbuflen %d", (int)sbuflen);
nv = evbuffer_peek(source, sbuflen, NULL, NULL, 0);
@@ -357,8 +365,10 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
return -1;
}
- if (get_payload(pl, HTTP_CONTENT_PDF, sbuflen, &pdfTemplate, &pdfTemplateSize) == 1) {
- log_debug("SERVER found the next HTTP response template with size %d", pdfTemplateSize);
+ if (get_payload(pl, HTTP_CONTENT_PDF, sbuflen, &pdfTemplate,
+ &pdfTemplateSize) == 1) {
+ log_debug("SERVER found the next HTTP response template with size %d",
+ pdfTemplateSize);
} else {
log_warn("SERVER couldn't find the next HTTP response template");
return -1;
@@ -371,39 +381,19 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
}
hLen = hend+4-pdfTemplate;
-
- log_debug("SERVER calling pdfWrap for data1 with length %d", cnt);
- outbuflen = pdfWrap(data1, cnt, hend+4, pdfTemplateSize-hLen, outbuf, HTTP_MSG_BUF_SIZE);
+
+ log_debug("SERVER calling pdf_wrap for data1 with length %d", cnt);
+ outbuflen = pdf_wrap(data1, cnt, hend+4, pdfTemplateSize-hLen, outbuf,
+ HTTP_MSG_BUF_SIZE);
if (outbuflen < 0) {
- log_warn("SERVER pdfWrap fails");
+ log_warn("SERVER pdf_wrap fails");
return -1;
}
- log_debug("SERVER pdfSteg sends resp with hdr len %d body len %d", hLen, outbuflen);
-
-
- // debugging
- // buf_dump((unsigned char *)data1, cnt, stderr);
-
- // data2len = pdfUnwrap(outbuf, outbuflen, data2, sbuflen);
- // if ((int)sbuflen == data2len) {
- // log_warn("sbuflen == data2len == %d", (int)sbuflen);
- // if (memcmp(data1, data2, sbuflen) == 0) {
- // log_warn("data1 and data2 match");
- // } else {
- // log_warn("data1 and data2 DO NOT match!! Dumping data1 ...");
- // buf_dump((unsigned char *)data1, cnt, stderr);
- // log_warn("data1 and data2 DO NOT match!! Dumping data2...");
- // buf_dump((unsigned char *)data2, data2len, stderr);
- // }
- // } else {
- // log_warn("*** sbuflen = %d, data2len = %d *** Dumping data1 ...", (int)sbuflen, data2len);
- // buf_dump((unsigned char *)data1, cnt, stderr);
- // log_warn("*** sbuflen = %d, data2len = %d *** Dumping data2 ...", (int)sbuflen, data2len);
- // buf_dump((unsigned char *)data2, data2len, stderr);
- // }
-
-
- newHdrLen = gen_response_header((char*) "application/pdf", 0, outbuflen, newHdr, sizeof(newHdr));
+ log_debug("SERVER pdfSteg sends resp with hdr len %d body len %d",
+ hLen, outbuflen);
+
+ 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;
@@ -413,10 +403,6 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
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");
@@ -426,14 +412,13 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
evbuffer_drain(source, sbuflen);
conn->cease_transmission();
- // downcast_steg(s)->have_transmitted = 1;
return 0;
}
-
-
int
-http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, struct evbuffer* source) {
+http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest,
+ struct evbuffer* source)
+{
struct evbuffer_ptr s2;
unsigned int response_len = 0, hdrLen;
char outbuf[HTTP_MSG_BUF_SIZE];
@@ -444,8 +429,8 @@ http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, st
s2 = evbuffer_search(source, "\r\n\r\n", sizeof ("\r\n\r\n") -1 , NULL);
if (s2.pos == -1) {
- log_warn("CLIENT Did not find end of HTTP header %d", (int) evbuffer_get_length(source));
- // evbuffer_dump(source, stderr);
+ log_warn("CLIENT Did not find end of HTTP header %d",
+ (int) evbuffer_get_length(source));
return RECV_INCOMPLETE;
}
@@ -480,154 +465,26 @@ http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, st
return RECV_BAD;
}
-
httpBody = httpHdr + hdrLen;
-
- outbuflen = pdfUnwrap(httpBody, content_len, outbuf, HTTP_MSG_BUF_SIZE);
+ outbuflen = pdf_unwrap(httpBody, content_len, outbuf, HTTP_MSG_BUF_SIZE);
if (outbuflen < 0) {
- log_warn("CLIENT ERROR: pdfUnwrap fails\n");
+ log_warn("CLIENT ERROR: pdf_unwrap fails\n");
return RECV_BAD;
}
log_debug("CLIENT unwrapped data of length %d:", outbuflen);
-
if (evbuffer_add(dest, outbuf, outbuflen)) {
log_warn("CLIENT ERROR: evbuffer_add to dest fails\n");
return RECV_BAD;
}
- // log_debug("Drained source for %d char\n", response_len);
if (evbuffer_drain(source, response_len) == -1) {
log_warn("CLIENT ERROR: failed to drain source\n");
return RECV_BAD;
}
- // downcast_steg(s)->have_received = 1;
conn->expect_close();
return RECV_GOOD;
}
-
-
-
-
-/*****
-int main() {
- char data1[] = "this is a test?? yes!";
- char data2[100];
- char data3[100];
- int dlen1, dlen2, dlen3, end;
- char last = ' ';
- printf("hello world\n");
-
- dlen2 = addDelimiter(data1, strlen(data1), data2, 100, '?', '.');
- printf("dlen2 = %d\n", dlen2);
- dlen3 = removeDelimiter(data2, dlen2, data3, 100, '?', &end, &last);
- printf("endflag = %d", end);
- printf("dlen3 = %d\n", dlen3);
- if (memcmp(data1, data3, dlen3) == 0) {
- data1[dlen3] = 0;
- printf("removeDelimiter(addDelimiter(x)) == x for |%s|\n", data1);
- } else {
- printf("removeDelimiter(addDelimiter(x)) != x for |%s|\n", data1);
- }
- return 1;
-}
- *****/
-
-/*****
-int main() {
- char data1[] = "12345";
- char data2[] = "123456789012";
- char data3[] = "12345678901";
- char data4[] = "1234567890?";
- char pdf1[] = "[PDFHDR][STUFFS1]>>streamABCDEFGHIJYYendstream[STUFFS2]>>streamABCDEFGHIJYYendstream[STUFF3][PDFTRAILER]";
- char out[200];
- char orig[200];
- int r1, r2;
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data1);
- printf("strlen(pdf1) = %d\n", (int)strlen(pdf1));
- r1 = pdfWrap(data1, strlen(data1), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data2);
- r1 = pdfWrap(data2, strlen(data2), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data3);
- r1 = pdfWrap(data3, strlen(data3), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data4);
- r1 = pdfWrap(data4, strlen(data4), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- return 0;
-}
- *****/
diff --git a/src/steg/pdfSteg.h b/src/steg/pdfSteg.h
index 3d494e1..0bd3a43 100644
--- a/src/steg/pdfSteg.h
+++ b/src/steg/pdfSteg.h
@@ -1,29 +1,31 @@
#ifndef _PDFSTEG_H
#define _PDFSTEG_H
+struct payloads;
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include "util.h"
-#include "connections.h"
-#include "steg.h"
-#include <event2/buffer.h>
+// These are the public interface.
-struct payloads;
+int http_server_PDF_transmit(payloads &pl, struct evbuffer *source,
+ conn_t *conn);
+int http_handle_client_PDF_receive(steg_t *s, conn_t *conn,
+ struct evbuffer *dest,
+ struct evbuffer* source);
-#define PDF_DELIMITER '?'
-#define PDF_DELIMITER2 '.'
+// These are exposed only for the sake of unit tests.
-int pdfWrap (char *data, unsigned int dlen, char *pdfTemplate, unsigned int plen, char *outbuf, unsigned int outbufsize);
-int pdfUnwrap (char *data, unsigned int dlen, char *outbuf, unsigned int outbufsize);
+ssize_t pdf_add_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ char delimiter1, char delimiter2);
-int addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen, const char delimiter1, const char delimiter2);
-int removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen, const char delimiter1, int* endFlag, int* escape);
+ssize_t pdf_remove_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ char delimiter1, bool *endFlag, bool *escape);
-int http_server_PDF_transmit (payloads& pl, struct evbuffer *source, conn_t *conn);
-int
-http_handle_client_PDF_receive(steg_t *s, conn_t *conn, struct evbuffer *dest, struct evbuffer* source);
+ssize_t pdf_wrap(const char *data, size_t dlen,
+ const char *pdfTemplate, size_t plen,
+ char *outbuf, size_t outbufsize);
-#endif
+ssize_t pdf_unwrap(const char *data, size_t dlen,
+ char *outbuf, size_t outbufsize);
+#endif
diff --git a/src/steg/swfSteg.cc b/src/steg/swfSteg.cc
index cd371f3..c8a18c1 100644
--- a/src/steg/swfSteg.cc
+++ b/src/steg/swfSteg.cc
@@ -1,5 +1,11 @@
+#include "util.h"
#include "swfSteg.h"
+#include "connections.h"
+#include "payloads.h"
+#include "zlib.h"
+#include "zpack.h"
+#include <event2/buffer.h>
static const char http_response_1[] =
"HTTP/1.1 200 OK\r\n"
@@ -9,17 +15,7 @@ static const char http_response_1[] =
"Content-Type: application/x-shockwave-flash\r\n"
"Content-Length: ";
-
-
-
-
-
-
-
-
-
-
-unsigned int
+unsigned int
swf_wrap(payloads& pl, char* inbuf, int in_len, char* outbuf, int out_sz) {
char* swf;
diff --git a/src/steg/swfSteg.h b/src/steg/swfSteg.h
index 712a3a3..b8336b2 100644
--- a/src/steg/swfSteg.h
+++ b/src/steg/swfSteg.h
@@ -1,38 +1,21 @@
#ifndef _SWFSTEG_H
#define _SWFSTEG_H
-
-#include "util.h"
-#include "connections.h"
-#include "steg.h"
-#include "payloads.h"
-#include "cookies.h"
-#include "pdfSteg.h"
-#include "zpack.h"
-
-
-#include <event2/buffer.h>
-#include <stdio.h>
-
struct payloads;
#define SWF_SAVE_HEADER_LEN 1500
#define SWF_SAVE_FOOTER_LEN 1500
-
-unsigned int
+unsigned int
swf_wrap(payloads& pl, char* inbuf, int in_len, char* outbuf, int out_sz);
-unsigned int
+unsigned int
swf_unwrap(char* inbuf, int in_len, char* outbuf, int out_sz);
-int
+int
http_server_SWF_transmit(payloads& pl, struct evbuffer *source, conn_t *conn);
-
int
http_handle_client_SWF_receive(steg_t *s, conn_t *conn, struct evbuffer *dest, struct evbuffer* source);
#endif
-
-
diff --git a/src/steg/zpack.h b/src/steg/zpack.h
index 65cd28d..d0e5cb2 100644
--- a/src/steg/zpack.h
+++ b/src/steg/zpack.h
@@ -1,10 +1,5 @@
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <time.h>
-#include <stdlib.h>
-#include "zlib.h"
-
+#ifndef _ZPACK_H
+#define _ZPACK_H
int def(char *source, int slen, char *dest, int dlen, int level);
int inf(char *source, int slen, char *dest, int dlen);
@@ -12,3 +7,5 @@ void zerr(int ret);
int gzInflate(char *source, int slen, char *dest, int dlen);
int gzDeflate(char* start, off_t insz, char *buf, off_t outsz, time_t mtime);
unsigned int generate_crc32c(char *buffer, size_t length);
+
+#endif
diff --git a/src/test/tinytest_macros.h b/src/test/tinytest_macros.h
index 40d17e2..cf5a2a2 100644
--- a/src/test/tinytest_macros.h
+++ b/src/test/tinytest_macros.h
@@ -168,6 +168,10 @@
tt_assert_test_type(a,b,#a" "#op" "#b,void*, \
(_val1 op _val2),"%p")
+#define tt_char_op(a,op,b) \
+ tt_assert_test_type(a,b,#a" "#op" "#b,int, \
+ (_val1 op _val2),"'%c'")
+
#define tt_str_op(a,op,b) \
tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \
(strcmp(_val1,_val2) op 0),"<%s>")
@@ -176,7 +180,7 @@
tt_assert_test_fmt_type(a,b,#a" "#op" "#b, \
const char *, \
(strncmp(_val1, _val2, len) op 0), \
- char *, "%s", \
+ char *, "<%s>", \
{ _print = xstrndup(_value, len); }, \
{ free(_print); } \
);
@@ -185,7 +189,7 @@
tt_assert_test_fmt_type(a,b,#a" "#op" "#b, \
const char *, \
(memcmp(_val1, _val2, len) op 0), \
- char *, "%s", \
+ char *, "<%s>", \
{ _print = tt_base16_encode(_value, len); }, \
{ free(_print); } \
);
diff --git a/src/util.cc b/src/util.cc
index b813ae9..a667abd 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -17,9 +17,6 @@
#include <sys/un.h>
#endif
-/** Any size_t larger than this amount is likely to be an underflow. */
-#define SIZE_T_CEILING (SIZE_MAX/2 - 16)
-
/**************************** Memory Allocation ******************************/
static void ATTR_NORETURN
diff --git a/src/util.h b/src/util.h
index 05bc6d0..167af8e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -57,6 +57,9 @@ struct event_base;
/***** Memory allocation. *****/
+/** Any size_t larger than this amount is likely to be an underflow. */
+#define SIZE_T_CEILING (SIZE_MAX/2 - 16)
+
/* Because this isn't Tor and functions named "tor_whatever" would be
confusing, I am instead following the GNU convention of naming
allocate-memory-or-crash functions "xwhatever". Also, at this time
1
0
[stegotorus/master] Const- and size_t-correctness, minor other cleanups for crc32 and zpack.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 343d961f4055f69a61bd9749d498e61234339bfc
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 23 15:40:28 2012 -0700
Const- and size_t-correctness, minor other cleanups for crc32 and zpack.
---
src/steg/crc32.cc | 7 +-
src/steg/crc32.h | 18 +----
src/steg/zpack.cc | 235 ++++++++++++++++-------------------------------------
src/steg/zpack.h | 13 ++--
4 files changed, 83 insertions(+), 190 deletions(-)
diff --git a/src/steg/crc32.cc b/src/steg/crc32.cc
index 7fdc847..1b18544 100644
--- a/src/steg/crc32.cc
+++ b/src/steg/crc32.cc
@@ -1,3 +1,4 @@
+#include "util.h"
#include "crc32.h"
#define CRC32C(c,d) (c=(c>>8)^crc_c[(c^(d))&0xFF])
@@ -69,8 +70,9 @@ static const unsigned int crc_c[256] = {
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
-
-unsigned int generate_crc32c(char *buffer, size_t length) {
+unsigned int
+generate_crc32c(const char *buffer, size_t length)
+{
size_t i;
unsigned int crc32 = ~0L;
@@ -79,4 +81,3 @@ unsigned int generate_crc32c(char *buffer, size_t length) {
}
return ~crc32;
}
-
diff --git a/src/steg/crc32.h b/src/steg/crc32.h
index 780e7bd..0a1ee03 100644
--- a/src/steg/crc32.h
+++ b/src/steg/crc32.h
@@ -1,18 +1,6 @@
-#ifndef __crc32cr_table_h__
-#define __crc32cr_table_h__
+#ifndef _CRC32_H
+#define _CRC32_H
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <sys/types.h>
-
-#if defined HAVE_STDINT_H
-# include <stdint.h>
-#elif defined HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-
-unsigned int generate_crc32c(char *string, size_t length);
+unsigned int generate_crc32c(const char *string, size_t length);
#endif
diff --git a/src/steg/zpack.cc b/src/steg/zpack.cc
index 63aa412..c3c650f 100644
--- a/src/steg/zpack.cc
+++ b/src/steg/zpack.cc
@@ -1,19 +1,7 @@
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <time.h>
-#include <stdlib.h>
-#include "zlib.h"
+#include "util.h"
#include "zpack.h"
-
-
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-# include <fcntl.h>
-# include <io.h>
-# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-# define SET_BINARY_MODE(file)
-#endif
+#include "zlib.h"
+#include "crc32.h"
#define CHUNK 16384
@@ -24,15 +12,18 @@
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
-
-int def(char *source, int slen, char *dest, int dlen, int level)
+ssize_t
+def(const char *source, size_t slen, char *dest, size_t dlen, int level)
{
int ret, flush;
- unsigned have;
+ size_t have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
- int dlen_orig = dlen;
+ size_t dlen_orig = dlen;
+
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
/* allocate deflate state */
strm.zalloc = Z_NULL;
@@ -44,7 +35,6 @@ int def(char *source, int slen, char *dest, int dlen, int level)
/* compress until end of file */
do {
-
if (slen > CHUNK)
strm.avail_in = CHUNK;
else
@@ -63,30 +53,28 @@ int def(char *source, int slen, char *dest, int dlen, int level)
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
- if ((unsigned int) dlen < have) {
- fprintf(stderr, "dest buf too small!\n");
- return Z_ERRNO;
+ if (dlen < have) {
+ log_warn("dest buf too small - have %lu, need %lu",
+ (unsigned long)dlen, (unsigned long)have);
+ return Z_ERRNO;
}
memcpy(dest, out, have);
dest += have;
dlen = dlen - have;
} while (strm.avail_out == 0);
- assert(strm.avail_in == 0); /* all input will be used */
+ log_assert(strm.avail_in == 0); /* all input will be used */
/* done when last data in file processed */
} while (flush != Z_FINISH);
- assert(ret == Z_STREAM_END); /* stream will be complete */
+ log_assert(ret == Z_STREAM_END); /* stream will be complete */
/* clean up and return */
- (void)deflateEnd(&strm);
-
- printf("hello here...\n");
+ deflateEnd(&strm);
return (dlen_orig - dlen);
- // return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
@@ -96,18 +84,18 @@ int def(char *source, int slen, char *dest, int dlen, int level)
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
-
-
-
-int inf(char *source, int slen, char *dest, int dlen)
+ssize_t
+inf(const char *source, size_t slen, char *dest, size_t dlen)
{
int ret;
- unsigned have;
+ size_t have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
- int dlen_orig = dlen;
+ size_t dlen_orig = dlen;
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
/* allocate inflate state */
strm.zalloc = Z_NULL;
@@ -121,10 +109,9 @@ int inf(char *source, int slen, char *dest, int dlen)
/* decompress until deflate stream ends or end of file */
do {
-
if (slen == 0)
break;
-
+
if (slen > CHUNK)
strm.avail_in = CHUNK;
else
@@ -133,9 +120,6 @@ int inf(char *source, int slen, char *dest, int dlen)
memcpy(in, source, strm.avail_in);
slen = slen - strm.avail_in;
source = source + strm.avail_in;
-
-
-
strm.next_in = in;
/* run inflate() on input until output buffer not full */
@@ -143,21 +127,20 @@ int inf(char *source, int slen, char *dest, int dlen)
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
- return ret;
+ inflateEnd(&strm);
+ return ret;
}
have = CHUNK - strm.avail_out;
-
- if ((unsigned int) dlen < have) {
- fprintf(stderr, "dest buf too small!\n");
- return Z_ERRNO;
+ if (dlen < have) {
+ log_warn("dest buf too small - have %lu, need %lu",
+ (unsigned long)dlen, (unsigned long)have);
+ return Z_ERRNO;
}
memcpy(dest, out, have);
@@ -170,57 +153,27 @@ int inf(char *source, int slen, char *dest, int dlen)
} while (ret != Z_STREAM_END);
/* clean up and return */
- (void)inflateEnd(&strm);
+ inflateEnd(&strm);
if (ret == Z_STREAM_END)
return dlen_orig - dlen;
return Z_DATA_ERROR;
}
-/* report a zlib or i/o error */
-void zerr(int ret)
-
-{
- fputs("zpipe: ", stderr);
- switch (ret) {
- case Z_ERRNO:
- if (ferror(stdin))
- fputs("error reading stdin\n", stderr);
- if (ferror(stdout))
- fputs("error writing stdout\n", stderr);
- break;
- case Z_STREAM_ERROR:
- fputs("invalid compression level\n", stderr);
- break;
- case Z_DATA_ERROR:
- fputs("invalid or incomplete deflate data\n", stderr);
- break;
- case Z_MEM_ERROR:
- fputs("out of memory\n", stderr);
- break;
- case Z_VERSION_ERROR:
- fputs("zlib version mismatch!\n", stderr);
- }
-}
-
-
-
-
-
-
-
-
/* assumes that we know there is exactly 10 bytes of gzip header */
-int gzInflate(char *source, int slen, char *dest, int dlen)
+ssize_t
+gzInflate(const char *source, size_t slen, char *dest, size_t dlen)
{
int ret;
- unsigned have;
+ size_t have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
- int dlen_orig = dlen;
+ size_t dlen_orig = dlen;
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
/* allocate inflate state */
strm.zalloc = Z_NULL;
@@ -229,7 +182,6 @@ int gzInflate(char *source, int slen, char *dest, int dlen)
strm.avail_in = 0;
strm.next_in = Z_NULL;
-
ret = inflateInit2(&strm, -MAX_WBITS);
if (ret != Z_OK)
return ret;
@@ -239,10 +191,9 @@ int gzInflate(char *source, int slen, char *dest, int dlen)
/* decompress until deflate stream ends or end of file */
do {
-
if (slen == 0)
break;
-
+
if (slen > CHUNK)
strm.avail_in = CHUNK;
else
@@ -251,9 +202,6 @@ int gzInflate(char *source, int slen, char *dest, int dlen)
memcpy(in, source, strm.avail_in);
slen = slen - strm.avail_in;
source = source + strm.avail_in;
-
-
-
strm.next_in = in;
/* run inflate() on input until output buffer not full */
@@ -261,20 +209,21 @@ int gzInflate(char *source, int slen, char *dest, int dlen)
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
+ ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
- return ret;
+ inflateEnd(&strm);
+ return ret;
}
have = CHUNK - strm.avail_out;
- if ((unsigned int) dlen < have) {
- fprintf(stderr, "dest buf too small!\n");
- return Z_ERRNO;
+ if (dlen < have) {
+ log_warn("dest buf too small - have %lu, need %lu",
+ (unsigned long)dlen, (unsigned long)have);
+ return Z_ERRNO;
}
memcpy(dest, out, have);
@@ -287,45 +236,43 @@ int gzInflate(char *source, int slen, char *dest, int dlen)
} while (ret != Z_STREAM_END);
/* clean up and return */
- (void)inflateEnd(&strm);
+ inflateEnd(&strm);
if (ret == Z_STREAM_END)
return dlen_orig - dlen;
return Z_DATA_ERROR;
}
-
-
-
-
-
-
-int gzDeflate(char* start, off_t insz, char *buf, off_t outsz, time_t mtime) {
+ssize_t
+gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
+ time_t mtime)
+{
unsigned char *c;
unsigned long crc;
z_stream z;
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
+
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
if (Z_OK != deflateInit2(&z,
- Z_DEFAULT_COMPRESSION,
- Z_DEFLATED,
- -MAX_WBITS, /* supress zlib-header */
- 8,
- Z_DEFAULT_STRATEGY)) {
+ Z_DEFAULT_COMPRESSION,
+ Z_DEFLATED,
+ -MAX_WBITS, /* supress zlib-header */
+ 8,
+ Z_DEFAULT_STRATEGY))
return -1;
- }
- z.next_in = (unsigned char *)start;
- z.avail_in = insz;
+ z.next_in = (Bytef *)source;
+ z.avail_in = slen;
z.total_in = 0;
-
/* write gzip header */
- c = (unsigned char *) buf;
+ c = (unsigned char *)dest;
c[0] = 0x1f;
c[1] = 0x8b;
c[2] = Z_DEFLATED;
@@ -338,19 +285,17 @@ int gzDeflate(char* start, off_t insz, char *buf, off_t outsz, time_t mtime) {
c[9] = 0x03; /* UNIX */
z.next_out = c + 10;
- z.avail_out = outsz - 10 - 8;
+ z.avail_out = dlen - 10 - 8;
z.total_out = 0;
- if (Z_STREAM_END != deflate(&z, Z_FINISH)) {
+ if (deflate(&z, Z_FINISH) != Z_STREAM_END) {
deflateEnd(&z);
return -1;
}
+ crc = generate_crc32c(source, slen);
- crc = generate_crc32c(start, insz);
-
- c = (unsigned char *)buf + 10 + z.total_out;
-
+ c = (unsigned char *)dest + 10 + z.total_out;
c[0] = (crc >> 0) & 0xff;
c[1] = (crc >> 8) & 0xff;
c[2] = (crc >> 16) & 0xff;
@@ -360,49 +305,7 @@ int gzDeflate(char* start, off_t insz, char *buf, off_t outsz, time_t mtime) {
c[6] = (z.total_in >> 16) & 0xff;
c[7] = (z.total_in >> 24) & 0xff;
-
-
- if (Z_OK != deflateEnd(&z)) {
+ if (deflateEnd(&z) != Z_OK)
return -1;
- }
-
return 10 + z.total_out + 8;
-
}
-
-
-
-
-
-/* compress or decompress from stdin to stdout */
-/* int main(int argc, char **argv) */
-/* { */
-/* int ret; */
-/* char buf1[32] = "abcasdfadfadfadf23fasdfa23sdfsdf"; */
-/* char buf2[100]; */
-/* char buf3[100]; */
-/* int i; */
-
-/* bzero(buf2, sizeof(buf2)); */
-/* bzero(buf3, sizeof(buf3)); */
-
-
-/* // ret = def(buf1, 3, buf2, 100, Z_DEFAULT_COMPRESSION); */
-/* ret = gzDeflate(buf1, sizeof(buf1), buf2, sizeof(buf2), time(NULL)); */
-/* if (ret <= 0) */
-/* zerr(ret); */
-
-/* /\* for (i=0; i < ret; i++) */
-/* putc(buf2[i], stdout); */
-/* *\/ */
-
-
-/* // printf("len = %d\n", ret); */
-
-/* ret = gzInflate(buf2, ret, buf3, 100); */
-/* if (ret <= 0) */
-/* zerr(ret); */
-/* printf("hello %s\n", buf3); */
-
-
-/* } */
diff --git a/src/steg/zpack.h b/src/steg/zpack.h
index d0e5cb2..5d3f82f 100644
--- a/src/steg/zpack.h
+++ b/src/steg/zpack.h
@@ -1,11 +1,12 @@
#ifndef _ZPACK_H
#define _ZPACK_H
-int def(char *source, int slen, char *dest, int dlen, int level);
-int inf(char *source, int slen, char *dest, int dlen);
-void zerr(int ret);
-int gzInflate(char *source, int slen, char *dest, int dlen);
-int gzDeflate(char* start, off_t insz, char *buf, off_t outsz, time_t mtime);
-unsigned int generate_crc32c(char *buffer, size_t length);
+ssize_t def(const char *source, size_t slen, char *dest, size_t dlen,
+ int level);
+ssize_t inf(const char *source, size_t slen, char *dest, size_t dlen);
+
+ssize_t gzInflate(const char *source, size_t slen, char *dest, size_t dlen);
+ssize_t gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
+ time_t mtime);
#endif
1
0
[stegotorus/master] Thorough spring-cleaning on pdfSteg.cc; less thorough on swfSteg.cc
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 177ba0f8b4265d09c321d6903eeab040faeca430
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 23 14:49:52 2012 -0700
Thorough spring-cleaning on pdfSteg.cc; less thorough on swfSteg.cc
and some other headers. Add beginnings of unit tests for pdfSteg.
---
Makefile.am | 1 +
src/steg/pdfSteg.cc | 389 +++++++++++++-----------------------------
src/steg/pdfSteg.h | 38 +++--
src/steg/swfSteg.cc | 18 +--
src/steg/swfSteg.h | 23 +---
src/steg/zpack.h | 11 +-
src/test/tinytest_macros.h | 8 +-
src/test/unittest_pdfsteg.cc | 82 +++++++++
src/util.cc | 3 -
src/util.h | 3 +
10 files changed, 249 insertions(+), 327 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 6ba1b51..86ed489 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,7 @@ stegotorus_SOURCES = \
UTGROUPS = \
src/test/unittest_crypt.cc \
+ src/test/unittest_pdfsteg.cc \
src/test/unittest_socks.cc \
src/test/unittest_config.cc \
src/test/unittest_transfer.cc
diff --git a/src/steg/pdfSteg.cc b/src/steg/pdfSteg.cc
index c67b0f8..3b4bbf0 100644
--- a/src/steg/pdfSteg.cc
+++ b/src/steg/pdfSteg.cc
@@ -1,7 +1,13 @@
-#include "payloads.h"
+#include "util.h"
#include "pdfSteg.h"
+#include "connections.h"
+#include "payloads.h"
+#include <event2/buffer.h>
+
+/* pdfSteg: A PDF-based steganography module */
-void buf_dump(unsigned char* buf, int len, FILE *out);
+#define PDF_DELIMITER '?'
+#define PDF_DELIMITER2 '.'
#define STREAM_BEGIN ">>stream"
#define STREAM_BEGIN_SIZE 8
@@ -10,45 +16,42 @@ void buf_dump(unsigned char* buf, int len, FILE *out);
#define DEBUG
-
/*
- * pdfSteg: A PDF-based steganography module
- *
- */
-
-
-/*
- * addDelimiter processes the input buffer (inbuf) of length inbuflen,
- * copies it to output buffer (outbuf) of size outbufsize,
+ * pdf_add_delimiter processes the input buffer (inbuf) of length
+ * inbuflen, copies it to output buffer (outbuf) of size outbufsize,
* and adds a two-char-long, end-of-data pattern at the end of outbuf
* based on delimiter1 and delimiter2.
*
* The end-of-data pattern consists of delimiter1 followed by a char
* that is not delimiter1. Thus, delimiter1 and delimiter2 must be
* different.
- *
- * If delimiter1 appears in the input buffer, addDelimiter puts two
- * delimiter1 char in output buffer (to enable removeDelimiter to perform
- * the back transformation)
*
- * addDelimiter returns the length of the data written to outbuf, including
- * the end-of-data pattern, if the transformation succeeds;
- * otherwise, it returns -1
+ * If delimiter1 appears in the input buffer, pdf_add_delimiter puts two
+ * delimiter1 characters in the output buffer, so that the transformation
+ * is reversible.
+ *
+ * pdf_add_delimiter returns the length of the data written to outbuf,
+ * including the end-of-data pattern, if the transformation succeeds;
+ * otherwise, it returns -1.
*
*/
-int
-addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
- const char delimiter1, const char delimiter2)
+ssize_t
+pdf_add_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ const char delimiter1, const char delimiter2)
{
- int cnt;
- char *ibp, ic, rc;
+ size_t cnt;
+ const char *ibp;
+ char ic, rc;
- if (delimiter1 == delimiter2) return -1;
+ log_assert(delimiter1 != delimiter2);
+ if (inbuflen > SIZE_T_CEILING || outbuflen > SIZE_T_CEILING)
+ return -1;
cnt = 0;
ibp = inbuf;
- while ((ibp-inbuf)<inbuflen && cnt<(outbuflen-2)) {
- ic = *(ibp++);
+ while (size_t(ibp-inbuf) < inbuflen && cnt < outbuflen-2) {
+ ic = *ibp++;
if (ic != delimiter1) {
outbuf[cnt++] = ic;
} else {
@@ -57,8 +60,9 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
}
}
- // error if outbuf is no large enough for storing the resulting data
- if (cnt >= (outbuflen-2)) return -1;
+ // error if outbuf is not large enough for storing the resulting data
+ if (cnt >= outbuflen-2)
+ return -1;
// put delimiter1 and a char that is not a delimiter1
// as the end-of-data pattern at the end of outbuf
@@ -75,8 +79,9 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
/*
- * removeDelimiter performs the reverse transformation of addDelimiter.
- *
+ * pdf_remove_delimiter performs the reverse transformation of
+ * pdf_add_delimiter.
+ *
* returns the length of data written to outbuf, if succeed;
* otherwise, it returns -1
*
@@ -84,20 +89,23 @@ addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
* delimiter1 followed by non-delimiter1) is detected
*
* escape indicates if a dangling delimiter1 has been
- * seen in the previous invocation of removeDelimiter
+ * seen in the previous invocation of pdf_remove_delimiter
*/
-int
-removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
- const char delimiter1, int *endFlag, int *escape)
+ssize_t
+pdf_remove_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ char delimiter1, bool *endFlag, bool *escape)
{
- int cnt;
- char *ibp, ic1, ic2;
+ size_t cnt;
+ const char *ibp;
+ char ic1, ic2;
cnt = 0;
- *endFlag = 0;
+ *endFlag = false;
ibp = inbuf;
- if (inbuflen <= 0) return -1;
+ if (inbuflen > SIZE_T_CEILING || outbuflen > SIZE_T_CEILING)
+ return -1;
// special case: 2-char, end-of-data pattern could be in two buffers
// if *escape == true, we need to see if
@@ -113,9 +121,9 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
}
}
- *escape = 0;
- while ((ibp-inbuf+1)<inbuflen && cnt<outbuflen) {
- ic1 = *(ibp++);
+ *escape = false;
+ while (size_t(ibp-inbuf+1) < inbuflen && cnt < outbuflen) {
+ ic1 = *ibp++;
if (ic1 != delimiter1) {
outbuf[cnt++] = ic1;
} else {
@@ -125,13 +133,14 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
if (ic2 == delimiter1) {
outbuf[cnt++] = delimiter1; ibp++;
} else { // end-of-data pattern detected
- *endFlag = 1;
+ *endFlag = true;
return cnt;
}
}
}
- if (ibp-inbuf == inbuflen) return cnt;
+ if (size_t(ibp-inbuf) == inbuflen)
+ return cnt;
// handling the last char in inbuf, if needed
ic1 = *ibp;
@@ -139,40 +148,46 @@ removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen,
outbuf[cnt++] = ic1;
} else {
// look at the next stream obj to handle the special cases
- *escape = 1;
+ *escape = true;
}
return cnt;
}
-
-
/*
- * pdfWrap embeds data of length dlen inside the stream objects of the PDF
+ * pdf_wrap embeds data of length dlen inside the stream objects of the PDF
* document (length plen) that appears in the body of a HTTP msg, and
* stores the result in the output buffer of size outsize
*
- * pdfWrap returns the length of the pdf document with the data embedded
+ * pdf_wrap returns the length of the pdf document with the data embedded
* inside, if succeed; otherwise, it returns -1 to indicate an error
- *
- */
-int
-pdfWrap (char *data, unsigned int dlen,
- char *pdfTemplate, unsigned int plen,
- char *outbuf, unsigned int outbufsize)
+ *
+ */
+ssize_t
+pdf_wrap(const char *data, size_t dlen,
+ const char *pdfTemplate, size_t plen,
+ char *outbuf, size_t outbufsize)
{
char data2[dlen*2+2];
- char *tp, *dp, *op, *streamStart, *streamEnd, *plimit;
- int data2len, cnt, size, size2;
+ const char *tp, *dp, *plimit;
+ char *op, *streamStart, *streamEnd;
+ size_t data2len, cnt, size, size2;
+ ssize_t rv;
- // assumption: pdfWrap is length-preserving
- if (outbufsize < plen) return -1;
+ if (dlen > SIZE_T_CEILING || plen > SIZE_T_CEILING ||
+ outbufsize > SIZE_T_CEILING)
+ return -1;
- data2len = addDelimiter(data, dlen, data2, HTTP_MSG_BUF_SIZE, PDF_DELIMITER, PDF_DELIMITER2);
- if (data2len < 1) return -1;
+ // assumption: pdf_wrap is length-preserving
+ if (outbufsize < plen) return -1;
+ rv = pdf_add_delimiter(data, dlen, data2, HTTP_MSG_BUF_SIZE,
+ PDF_DELIMITER, PDF_DELIMITER2);
+ if (rv < 1)
+ return -1;
+ data2len = rv;
- op = outbuf; // current pointer for output buffer
+ op = outbuf; // current pointer for output buffer
tp = pdfTemplate; // current pointer for http msg template
dp = data2; // current pointer for data2
cnt = 0; // number of data char encoded
@@ -185,7 +200,7 @@ pdfWrap (char *data, unsigned int dlen,
log_warn("Cannot find stream in pdf");
return -1;
}
-
+
// copy everything between tp and "stream" (inclusive) to outbuf
size = streamStart - tp + STREAM_BEGIN_SIZE;
memcpy(op, tp, size);
@@ -206,18 +221,17 @@ pdfWrap (char *data, unsigned int dlen,
size2 = data2len - cnt;
if (size < size2) {
memcpy(op, dp, size);
- op += size; tp += size; dp += size;
+ op += size; tp += size; dp += size;
memcpy(op, tp, STREAM_END_SIZE);
op += STREAM_END_SIZE; tp += STREAM_END_SIZE;
cnt += size;
} else { // done encoding data
memcpy(op, dp, size2);
- op += size2; tp += size2; dp += size2;
+ op += size2; tp += size2; dp += size2;
cnt += size2;
- // printf("Encoded %d char in pdf. Done encoding\n", size2);
break;
}
- log_debug("Encoded %d char in pdf", size);
+ log_debug("Encoded %lu bytes in pdf", (unsigned long)size);
} else { // empty stream
memcpy(op, tp, STREAM_END_SIZE);
op += STREAM_END_SIZE; tp += STREAM_END_SIZE;
@@ -228,25 +242,27 @@ pdfWrap (char *data, unsigned int dlen,
// copy the rest of pdfTemplate to outbuf
size = plimit-tp;
- log_debug("copying the rest of pdfTemplate to outbuf (size %d)", size);
+ log_debug("copying the rest of pdfTemplate to outbuf (size %lu)",
+ (unsigned long)size);
memcpy(op, tp, size);
op += size;
return (op-outbuf);
}
-
-
-
/*
- * pdfUnwrap is the inverse operation of pdfWrap
+ * pdf_unwrap is the inverse operation of pdf_wrap
*/
-int
-pdfUnwrap (char *data, unsigned int dlen,
- char *outbuf, unsigned int outbufsize)
+ssize_t
+pdf_unwrap(const char *data, size_t dlen,
+ char *outbuf, size_t outbufsize)
{
- char *dp, *op, *streamStart, *streamEnd, *dlimit, *olimit;
- int cnt, size, size2, endFlag;
- int escape = 0;
+ const char *dp, *dlimit;
+ char *op, *streamStart, *streamEnd, *olimit;
+ size_t cnt, size, size2;
+ bool endFlag, escape = false;
+
+ if (dlen > SIZE_T_CEILING || outbufsize > SIZE_T_CEILING)
+ return -1;
dp = data; // current pointer for data
op = outbuf; // current pointer for outbuf
@@ -272,11 +288,13 @@ pdfUnwrap (char *data, unsigned int dlen,
// count the number of usable char between tp and streamEnd
size = streamEnd-dp;
- if (size > 0) {
- size2 = removeDelimiter(dp, size, op, olimit-op, PDF_DELIMITER, &endFlag, &escape);
- if (size2 < 0) {
+ if (size > 0) {
+ ssize_t rv = pdf_remove_delimiter(dp, size, op, olimit-op, PDF_DELIMITER,
+ &endFlag, &escape);
+ if (rv < 0)
return -1;
- }
+
+ size2 = rv;
cnt += size2;
if (endFlag) { // Done decoding
break;
@@ -292,22 +310,16 @@ pdfUnwrap (char *data, unsigned int dlen,
return cnt;
}
-
-
-
-
int
-http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
- conn_t *conn)
+http_server_PDF_transmit(payloads &pl, struct evbuffer *source,
+ conn_t *conn)
{
-
struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
unsigned int mpdf;
char *pdfTemplate = NULL, *hend;
int pdfTemplateSize = 0;
- // char data1[HTTP_MSG_BUF_SIZE];
- char data1[(int) sbuflen];
+ char data1[sbuflen];
char outbuf[HTTP_MSG_BUF_SIZE];
int cnt, hLen, outbuflen, i;
@@ -317,10 +329,6 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
struct evbuffer_iovec *iv;
int nv;
- // for debugging pdfWrap and pdfUnwrap
- // char data2[(int) sbuflen];
- // int data2len;
-
log_debug("Entering SERVER PDF transmit with sbuflen %d", (int)sbuflen);
nv = evbuffer_peek(source, sbuflen, NULL, NULL, 0);
@@ -357,8 +365,10 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
return -1;
}
- if (get_payload(pl, HTTP_CONTENT_PDF, sbuflen, &pdfTemplate, &pdfTemplateSize) == 1) {
- log_debug("SERVER found the next HTTP response template with size %d", pdfTemplateSize);
+ if (get_payload(pl, HTTP_CONTENT_PDF, sbuflen, &pdfTemplate,
+ &pdfTemplateSize) == 1) {
+ log_debug("SERVER found the next HTTP response template with size %d",
+ pdfTemplateSize);
} else {
log_warn("SERVER couldn't find the next HTTP response template");
return -1;
@@ -371,39 +381,19 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
}
hLen = hend+4-pdfTemplate;
-
- log_debug("SERVER calling pdfWrap for data1 with length %d", cnt);
- outbuflen = pdfWrap(data1, cnt, hend+4, pdfTemplateSize-hLen, outbuf, HTTP_MSG_BUF_SIZE);
+
+ log_debug("SERVER calling pdf_wrap for data1 with length %d", cnt);
+ outbuflen = pdf_wrap(data1, cnt, hend+4, pdfTemplateSize-hLen, outbuf,
+ HTTP_MSG_BUF_SIZE);
if (outbuflen < 0) {
- log_warn("SERVER pdfWrap fails");
+ log_warn("SERVER pdf_wrap fails");
return -1;
}
- log_debug("SERVER pdfSteg sends resp with hdr len %d body len %d", hLen, outbuflen);
-
-
- // debugging
- // buf_dump((unsigned char *)data1, cnt, stderr);
-
- // data2len = pdfUnwrap(outbuf, outbuflen, data2, sbuflen);
- // if ((int)sbuflen == data2len) {
- // log_warn("sbuflen == data2len == %d", (int)sbuflen);
- // if (memcmp(data1, data2, sbuflen) == 0) {
- // log_warn("data1 and data2 match");
- // } else {
- // log_warn("data1 and data2 DO NOT match!! Dumping data1 ...");
- // buf_dump((unsigned char *)data1, cnt, stderr);
- // log_warn("data1 and data2 DO NOT match!! Dumping data2...");
- // buf_dump((unsigned char *)data2, data2len, stderr);
- // }
- // } else {
- // log_warn("*** sbuflen = %d, data2len = %d *** Dumping data1 ...", (int)sbuflen, data2len);
- // buf_dump((unsigned char *)data1, cnt, stderr);
- // log_warn("*** sbuflen = %d, data2len = %d *** Dumping data2 ...", (int)sbuflen, data2len);
- // buf_dump((unsigned char *)data2, data2len, stderr);
- // }
-
-
- newHdrLen = gen_response_header((char*) "application/pdf", 0, outbuflen, newHdr, sizeof(newHdr));
+ log_debug("SERVER pdfSteg sends resp with hdr len %d body len %d",
+ hLen, outbuflen);
+
+ 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;
@@ -413,10 +403,6 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
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");
@@ -426,14 +412,13 @@ http_server_PDF_transmit (payloads& pl, struct evbuffer *source,
evbuffer_drain(source, sbuflen);
conn->cease_transmission();
- // downcast_steg(s)->have_transmitted = 1;
return 0;
}
-
-
int
-http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, struct evbuffer* source) {
+http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest,
+ struct evbuffer* source)
+{
struct evbuffer_ptr s2;
unsigned int response_len = 0, hdrLen;
char outbuf[HTTP_MSG_BUF_SIZE];
@@ -444,8 +429,8 @@ http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, st
s2 = evbuffer_search(source, "\r\n\r\n", sizeof ("\r\n\r\n") -1 , NULL);
if (s2.pos == -1) {
- log_warn("CLIENT Did not find end of HTTP header %d", (int) evbuffer_get_length(source));
- // evbuffer_dump(source, stderr);
+ log_warn("CLIENT Did not find end of HTTP header %d",
+ (int) evbuffer_get_length(source));
return RECV_INCOMPLETE;
}
@@ -480,154 +465,26 @@ http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, st
return RECV_BAD;
}
-
httpBody = httpHdr + hdrLen;
-
- outbuflen = pdfUnwrap(httpBody, content_len, outbuf, HTTP_MSG_BUF_SIZE);
+ outbuflen = pdf_unwrap(httpBody, content_len, outbuf, HTTP_MSG_BUF_SIZE);
if (outbuflen < 0) {
- log_warn("CLIENT ERROR: pdfUnwrap fails\n");
+ log_warn("CLIENT ERROR: pdf_unwrap fails\n");
return RECV_BAD;
}
log_debug("CLIENT unwrapped data of length %d:", outbuflen);
-
if (evbuffer_add(dest, outbuf, outbuflen)) {
log_warn("CLIENT ERROR: evbuffer_add to dest fails\n");
return RECV_BAD;
}
- // log_debug("Drained source for %d char\n", response_len);
if (evbuffer_drain(source, response_len) == -1) {
log_warn("CLIENT ERROR: failed to drain source\n");
return RECV_BAD;
}
- // downcast_steg(s)->have_received = 1;
conn->expect_close();
return RECV_GOOD;
}
-
-
-
-
-/*****
-int main() {
- char data1[] = "this is a test?? yes!";
- char data2[100];
- char data3[100];
- int dlen1, dlen2, dlen3, end;
- char last = ' ';
- printf("hello world\n");
-
- dlen2 = addDelimiter(data1, strlen(data1), data2, 100, '?', '.');
- printf("dlen2 = %d\n", dlen2);
- dlen3 = removeDelimiter(data2, dlen2, data3, 100, '?', &end, &last);
- printf("endflag = %d", end);
- printf("dlen3 = %d\n", dlen3);
- if (memcmp(data1, data3, dlen3) == 0) {
- data1[dlen3] = 0;
- printf("removeDelimiter(addDelimiter(x)) == x for |%s|\n", data1);
- } else {
- printf("removeDelimiter(addDelimiter(x)) != x for |%s|\n", data1);
- }
- return 1;
-}
- *****/
-
-/*****
-int main() {
- char data1[] = "12345";
- char data2[] = "123456789012";
- char data3[] = "12345678901";
- char data4[] = "1234567890?";
- char pdf1[] = "[PDFHDR][STUFFS1]>>streamABCDEFGHIJYYendstream[STUFFS2]>>streamABCDEFGHIJYYendstream[STUFF3][PDFTRAILER]";
- char out[200];
- char orig[200];
- int r1, r2;
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data1);
- printf("strlen(pdf1) = %d\n", (int)strlen(pdf1));
- r1 = pdfWrap(data1, strlen(data1), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data2);
- r1 = pdfWrap(data2, strlen(data2), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data3);
- r1 = pdfWrap(data3, strlen(data3), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- printf("********************\n");
- printf("pdfwrap for %s\n", data4);
- r1 = pdfWrap(data4, strlen(data4), pdf1, strlen(pdf1), out, (int)sizeof(out));
- if (r1 > 0) {
- printf("pdfWrap returns %d\n", r1);
- out[r1] = 0;
- printf("out[] contains |%s|\n", out);
- } else {
- printf("pdfWrap returns %d\n", r1);
- }
-
- r2 = pdfUnwrap(out, r1, orig, (int)sizeof(orig));
- if (r2 > 0) {
- printf("pdfUnwrap returns %d\n", r2);
- orig[r2] = 0;
- printf("orig[] contains |%s|\n", orig);
- } else {
- printf("pdfUnwrap returns %d\n", r2);
- }
-
- return 0;
-}
- *****/
diff --git a/src/steg/pdfSteg.h b/src/steg/pdfSteg.h
index 3d494e1..0bd3a43 100644
--- a/src/steg/pdfSteg.h
+++ b/src/steg/pdfSteg.h
@@ -1,29 +1,31 @@
#ifndef _PDFSTEG_H
#define _PDFSTEG_H
+struct payloads;
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include "util.h"
-#include "connections.h"
-#include "steg.h"
-#include <event2/buffer.h>
+// These are the public interface.
-struct payloads;
+int http_server_PDF_transmit(payloads &pl, struct evbuffer *source,
+ conn_t *conn);
+int http_handle_client_PDF_receive(steg_t *s, conn_t *conn,
+ struct evbuffer *dest,
+ struct evbuffer* source);
-#define PDF_DELIMITER '?'
-#define PDF_DELIMITER2 '.'
+// These are exposed only for the sake of unit tests.
-int pdfWrap (char *data, unsigned int dlen, char *pdfTemplate, unsigned int plen, char *outbuf, unsigned int outbufsize);
-int pdfUnwrap (char *data, unsigned int dlen, char *outbuf, unsigned int outbufsize);
+ssize_t pdf_add_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ char delimiter1, char delimiter2);
-int addDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen, const char delimiter1, const char delimiter2);
-int removeDelimiter(char *inbuf, int inbuflen, char *outbuf, int outbuflen, const char delimiter1, int* endFlag, int* escape);
+ssize_t pdf_remove_delimiter(const char *inbuf, size_t inbuflen,
+ char *outbuf, size_t outbuflen,
+ char delimiter1, bool *endFlag, bool *escape);
-int http_server_PDF_transmit (payloads& pl, struct evbuffer *source, conn_t *conn);
-int
-http_handle_client_PDF_receive(steg_t *s, conn_t *conn, struct evbuffer *dest, struct evbuffer* source);
+ssize_t pdf_wrap(const char *data, size_t dlen,
+ const char *pdfTemplate, size_t plen,
+ char *outbuf, size_t outbufsize);
-#endif
+ssize_t pdf_unwrap(const char *data, size_t dlen,
+ char *outbuf, size_t outbufsize);
+#endif
diff --git a/src/steg/swfSteg.cc b/src/steg/swfSteg.cc
index cd371f3..c8a18c1 100644
--- a/src/steg/swfSteg.cc
+++ b/src/steg/swfSteg.cc
@@ -1,5 +1,11 @@
+#include "util.h"
#include "swfSteg.h"
+#include "connections.h"
+#include "payloads.h"
+#include "zlib.h"
+#include "zpack.h"
+#include <event2/buffer.h>
static const char http_response_1[] =
"HTTP/1.1 200 OK\r\n"
@@ -9,17 +15,7 @@ static const char http_response_1[] =
"Content-Type: application/x-shockwave-flash\r\n"
"Content-Length: ";
-
-
-
-
-
-
-
-
-
-
-unsigned int
+unsigned int
swf_wrap(payloads& pl, char* inbuf, int in_len, char* outbuf, int out_sz) {
char* swf;
diff --git a/src/steg/swfSteg.h b/src/steg/swfSteg.h
index 712a3a3..b8336b2 100644
--- a/src/steg/swfSteg.h
+++ b/src/steg/swfSteg.h
@@ -1,38 +1,21 @@
#ifndef _SWFSTEG_H
#define _SWFSTEG_H
-
-#include "util.h"
-#include "connections.h"
-#include "steg.h"
-#include "payloads.h"
-#include "cookies.h"
-#include "pdfSteg.h"
-#include "zpack.h"
-
-
-#include <event2/buffer.h>
-#include <stdio.h>
-
struct payloads;
#define SWF_SAVE_HEADER_LEN 1500
#define SWF_SAVE_FOOTER_LEN 1500
-
-unsigned int
+unsigned int
swf_wrap(payloads& pl, char* inbuf, int in_len, char* outbuf, int out_sz);
-unsigned int
+unsigned int
swf_unwrap(char* inbuf, int in_len, char* outbuf, int out_sz);
-int
+int
http_server_SWF_transmit(payloads& pl, struct evbuffer *source, conn_t *conn);
-
int
http_handle_client_SWF_receive(steg_t *s, conn_t *conn, struct evbuffer *dest, struct evbuffer* source);
#endif
-
-
diff --git a/src/steg/zpack.h b/src/steg/zpack.h
index 65cd28d..d0e5cb2 100644
--- a/src/steg/zpack.h
+++ b/src/steg/zpack.h
@@ -1,10 +1,5 @@
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <time.h>
-#include <stdlib.h>
-#include "zlib.h"
-
+#ifndef _ZPACK_H
+#define _ZPACK_H
int def(char *source, int slen, char *dest, int dlen, int level);
int inf(char *source, int slen, char *dest, int dlen);
@@ -12,3 +7,5 @@ void zerr(int ret);
int gzInflate(char *source, int slen, char *dest, int dlen);
int gzDeflate(char* start, off_t insz, char *buf, off_t outsz, time_t mtime);
unsigned int generate_crc32c(char *buffer, size_t length);
+
+#endif
diff --git a/src/test/tinytest_macros.h b/src/test/tinytest_macros.h
index 40d17e2..cf5a2a2 100644
--- a/src/test/tinytest_macros.h
+++ b/src/test/tinytest_macros.h
@@ -168,6 +168,10 @@
tt_assert_test_type(a,b,#a" "#op" "#b,void*, \
(_val1 op _val2),"%p")
+#define tt_char_op(a,op,b) \
+ tt_assert_test_type(a,b,#a" "#op" "#b,int, \
+ (_val1 op _val2),"'%c'")
+
#define tt_str_op(a,op,b) \
tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \
(strcmp(_val1,_val2) op 0),"<%s>")
@@ -176,7 +180,7 @@
tt_assert_test_fmt_type(a,b,#a" "#op" "#b, \
const char *, \
(strncmp(_val1, _val2, len) op 0), \
- char *, "%s", \
+ char *, "<%s>", \
{ _print = xstrndup(_value, len); }, \
{ free(_print); } \
);
@@ -185,7 +189,7 @@
tt_assert_test_fmt_type(a,b,#a" "#op" "#b, \
const char *, \
(memcmp(_val1, _val2, len) op 0), \
- char *, "%s", \
+ char *, "<%s>", \
{ _print = tt_base16_encode(_value, len); }, \
{ free(_print); } \
);
diff --git a/src/test/unittest_pdfsteg.cc b/src/test/unittest_pdfsteg.cc
new file mode 100644
index 0000000..cf9e97d
--- /dev/null
+++ b/src/test/unittest_pdfsteg.cc
@@ -0,0 +1,82 @@
+/* Copyright 2011, 2012 SRI International
+ See LICENSE for other credits and copying information */
+
+#include "util.h"
+#include "unittest.h"
+#include "../steg/pdfSteg.h"
+
+static void
+test_pdf_add_remove_delimiters(void *)
+{
+ const char *data1 = "this is a test?? yes!";
+ char data2[100];
+ char data3[100];
+ int dlen2, dlen3;
+ bool end = false, escape = false;
+
+ memset(data2, 0, sizeof data2);
+ memset(data3, 0, sizeof data3);
+
+ dlen2 = pdf_add_delimiter(data1, strlen(data1), data2, 100, '?', '.');
+ tt_int_op(dlen2, ==, 25);
+ tt_stn_op(data2, ==, "this is a test???? yes!?", 24);
+ tt_char_op(data2[24], !=, '?');
+
+ dlen3 = pdf_remove_delimiter(data2, dlen2, data3, 100, '?', &end, &escape);
+ tt_int_op(dlen3, ==, 21);
+ tt_str_op(data3, ==, data1);
+ tt_bool_op(end, ==, true);
+ tt_bool_op(escape, ==, false);
+
+ end:;
+}
+
+static void
+test_pdf_wrap_unwrap(void *)
+{
+ const char *pdf =
+ "[PDFHDR][STUFFS1]>>streamABCDEFGHIJYYendstream"
+ "[STUFFS2]>>streamABCDEFGHIJYYendstream[STUFF3][PDFTRAILER]";
+
+ const char *const tests[] = {
+ "12345",
+ "123456789012",
+ "12345678901",
+ "1234567890?",
+ 0
+ };
+
+ char out[200];
+ char orig[200];
+ int i;
+ size_t r1, r2;
+ ssize_t rv;
+
+ for (i = 0; tests[i]; i++) {
+ memset(out, 0, sizeof out);
+ memset(orig, 0, sizeof out);
+ rv = pdf_wrap(tests[i], strlen(tests[i]),
+ pdf, strlen(pdf),
+ out, sizeof out);
+ tt_int_op(rv, >, 0);
+ r1 = rv;
+ tt_int_op(r1, ==, strlen(pdf));
+
+ rv = pdf_unwrap(out, r1, orig, sizeof orig);
+ tt_int_op(rv, >, 0);
+ r2 = rv;
+ tt_int_op(r2, ==, strlen(tests[i]));
+ tt_stn_op(orig, ==, tests[i], r2);
+ }
+
+ end:;
+}
+
+#define T(name) \
+ { #name, test_pdf_##name, 0, 0, 0 }
+
+struct testcase_t pdf_tests[] = {
+ T(add_remove_delimiters),
+ T(wrap_unwrap),
+ END_OF_TESTCASES
+};
diff --git a/src/util.cc b/src/util.cc
index b813ae9..a667abd 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -17,9 +17,6 @@
#include <sys/un.h>
#endif
-/** Any size_t larger than this amount is likely to be an underflow. */
-#define SIZE_T_CEILING (SIZE_MAX/2 - 16)
-
/**************************** Memory Allocation ******************************/
static void ATTR_NORETURN
diff --git a/src/util.h b/src/util.h
index 05bc6d0..167af8e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -57,6 +57,9 @@ struct event_base;
/***** Memory allocation. *****/
+/** Any size_t larger than this amount is likely to be an underflow. */
+#define SIZE_T_CEILING (SIZE_MAX/2 - 16)
+
/* Because this isn't Tor and functions named "tor_whatever" would be
confusing, I am instead following the GNU convention of naming
allocate-memory-or-crash functions "xwhatever". Also, at this time
1
0
[stegotorus/master] Merge branch 'master' of https://git.safdef.isc.org/git/stegotorus
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 560b952671f90505ca7193371410c370c9769f62
Merge: 343d961 0538c5a
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 23 15:41:50 2012 -0700
Merge branch 'master' of https://git.safdef.isc.org/git/stegotorus
Conflicts:
src/steg/zpack.h
1
0
[stegotorus/master] crc32.{cc, h} and zpack.{cc, h} are not really steg code, pull them up one.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit dfc8211422231ad3065de3d32c9002277615d423
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 23 15:44:35 2012 -0700
crc32.{cc,h} and zpack.{cc,h} are not really steg code, pull them up one.
---
Makefile.am | 6 +-
src/crc32.cc | 83 ++++++++++++++
src/crc32.h | 6 +
src/steg/crc32.cc | 83 --------------
src/steg/crc32.h | 6 -
src/steg/zpack.cc | 311 -----------------------------------------------------
src/steg/zpack.h | 12 --
src/zpack.cc | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/zpack.h | 12 ++
9 files changed, 415 insertions(+), 415 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 86ed489..7d72a96 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,7 +19,6 @@ PROTOCOLS = \
STEGANOGRAPHERS = \
src/steg/b64cookies.cc \
src/steg/cookies.cc \
- src/steg/crc32.cc \
src/steg/embed.cc \
src/steg/http.cc \
src/steg/jsSteg.cc \
@@ -27,11 +26,11 @@ STEGANOGRAPHERS = \
src/steg/nosteg_rr.cc \
src/steg/payloads.cc \
src/steg/pdfSteg.cc \
- src/steg/swfSteg.cc \
- src/steg/zpack.cc
+ src/steg/swfSteg.cc
libstegotorus_a_SOURCES = \
src/base64.cc \
+ src/crc32.cc \
src/connections.cc \
src/crypt.cc \
src/network.cc \
@@ -40,6 +39,7 @@ libstegotorus_a_SOURCES = \
src/socks.cc \
src/steg.cc \
src/util.cc \
+ src/zpack.cc \
$(PROTOCOLS) $(STEGANOGRAPHERS)
nodist_libstegotorus_a_SOURCES = protolist.cc steglist.cc
diff --git a/src/crc32.cc b/src/crc32.cc
new file mode 100644
index 0000000..1b18544
--- /dev/null
+++ b/src/crc32.cc
@@ -0,0 +1,83 @@
+#include "util.h"
+#include "crc32.h"
+
+#define CRC32C(c,d) (c=(c>>8)^crc_c[(c^(d))&0xFF])
+
+static const unsigned int crc_c[256] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
+ 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
+ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
+ 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
+ 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
+ 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
+ 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
+ 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
+ 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
+ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
+ 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
+ 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
+ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
+ 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
+ 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
+ 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
+ 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
+ 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
+ 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
+ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
+ 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
+ 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
+};
+
+unsigned int
+generate_crc32c(const char *buffer, size_t length)
+{
+ size_t i;
+ unsigned int crc32 = ~0L;
+
+ for (i = 0; i < length; i++){
+ CRC32C(crc32, (unsigned char)buffer[i]);
+ }
+ return ~crc32;
+}
diff --git a/src/crc32.h b/src/crc32.h
new file mode 100644
index 0000000..0a1ee03
--- /dev/null
+++ b/src/crc32.h
@@ -0,0 +1,6 @@
+#ifndef _CRC32_H
+#define _CRC32_H
+
+unsigned int generate_crc32c(const char *string, size_t length);
+
+#endif
diff --git a/src/steg/crc32.cc b/src/steg/crc32.cc
deleted file mode 100644
index 1b18544..0000000
--- a/src/steg/crc32.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "util.h"
-#include "crc32.h"
-
-#define CRC32C(c,d) (c=(c>>8)^crc_c[(c^(d))&0xFF])
-
-static const unsigned int crc_c[256] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
- 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
- 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
- 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
- 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
- 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
- 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
- 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
- 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
- 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
- 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
- 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
- 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
- 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
- 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
- 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
- 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
- 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
-};
-
-unsigned int
-generate_crc32c(const char *buffer, size_t length)
-{
- size_t i;
- unsigned int crc32 = ~0L;
-
- for (i = 0; i < length; i++){
- CRC32C(crc32, (unsigned char)buffer[i]);
- }
- return ~crc32;
-}
diff --git a/src/steg/crc32.h b/src/steg/crc32.h
deleted file mode 100644
index 0a1ee03..0000000
--- a/src/steg/crc32.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _CRC32_H
-#define _CRC32_H
-
-unsigned int generate_crc32c(const char *string, size_t length);
-
-#endif
diff --git a/src/steg/zpack.cc b/src/steg/zpack.cc
deleted file mode 100644
index c3c650f..0000000
--- a/src/steg/zpack.cc
+++ /dev/null
@@ -1,311 +0,0 @@
-#include "util.h"
-#include "zpack.h"
-#include "zlib.h"
-#include "crc32.h"
-
-#define CHUNK 16384
-
-/* Compress from file source to file dest until EOF on source.
- def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
- allocated for processing, Z_STREAM_ERROR if an invalid compression
- level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
- version of the library linked do not match, or Z_ERRNO if there is
- an error reading or writing the files. */
-
-ssize_t
-def(const char *source, size_t slen, char *dest, size_t dlen, int level)
-{
- int ret, flush;
- size_t have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
- size_t dlen_orig = dlen;
-
- if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
- return -1;
-
- /* allocate deflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&strm, level);
- if (ret != Z_OK)
- return ret;
-
- /* compress until end of file */
- do {
- if (slen > CHUNK)
- strm.avail_in = CHUNK;
- else
- strm.avail_in = slen;
-
- memcpy (in, source, strm.avail_in);
- slen = slen - strm.avail_in;
- source = source + strm.avail_in;
-
- flush = (slen == 0) ? Z_FINISH : Z_NO_FLUSH;
- strm.next_in = in;
-
- /* run deflate() on input until output buffer not full, finish
- compression if all of source has been read in */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = deflate(&strm, flush); /* no bad return value */
- log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- have = CHUNK - strm.avail_out;
-
- if (dlen < have) {
- log_warn("dest buf too small - have %lu, need %lu",
- (unsigned long)dlen, (unsigned long)have);
- return Z_ERRNO;
- }
-
- memcpy(dest, out, have);
- dest += have;
- dlen = dlen - have;
- } while (strm.avail_out == 0);
- log_assert(strm.avail_in == 0); /* all input will be used */
-
- /* done when last data in file processed */
- } while (flush != Z_FINISH);
- log_assert(ret == Z_STREAM_END); /* stream will be complete */
-
- /* clean up and return */
- deflateEnd(&strm);
- return (dlen_orig - dlen);
-}
-
-/* Decompress from file source to file dest until stream ends or EOF.
- inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
- allocated for processing, Z_DATA_ERROR if the deflate data is
- invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
- the version of the library linked do not match, or Z_ERRNO if there
- is an error reading or writing the files. */
-
-ssize_t
-inf(const char *source, size_t slen, char *dest, size_t dlen)
-{
- int ret;
- size_t have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
- size_t dlen_orig = dlen;
-
- if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
- return -1;
-
- /* allocate inflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm);
- if (ret != Z_OK)
- return ret;
-
- /* decompress until deflate stream ends or end of file */
- do {
- if (slen == 0)
- break;
-
- if (slen > CHUNK)
- strm.avail_in = CHUNK;
- else
- strm.avail_in = slen;
-
- memcpy(in, source, strm.avail_in);
- slen = slen - strm.avail_in;
- source = source + strm.avail_in;
- strm.next_in = in;
-
- /* run inflate() on input until output buffer not full */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = inflate(&strm, Z_NO_FLUSH);
- log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- switch (ret) {
- case Z_NEED_DICT:
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- inflateEnd(&strm);
- return ret;
- }
- have = CHUNK - strm.avail_out;
-
- if (dlen < have) {
- log_warn("dest buf too small - have %lu, need %lu",
- (unsigned long)dlen, (unsigned long)have);
- return Z_ERRNO;
- }
-
- memcpy(dest, out, have);
- dest += have;
- dlen = dlen - have;
-
- } while (strm.avail_out == 0);
-
- /* done when inflate() says it's done */
- } while (ret != Z_STREAM_END);
-
- /* clean up and return */
- inflateEnd(&strm);
-
- if (ret == Z_STREAM_END)
- return dlen_orig - dlen;
- return Z_DATA_ERROR;
-}
-
-/* assumes that we know there is exactly 10 bytes of gzip header */
-
-ssize_t
-gzInflate(const char *source, size_t slen, char *dest, size_t dlen)
-{
- int ret;
- size_t have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
- size_t dlen_orig = dlen;
-
- if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
- return -1;
-
- /* allocate inflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
-
- ret = inflateInit2(&strm, -MAX_WBITS);
- if (ret != Z_OK)
- return ret;
-
- source = source + 10;
- slen -= 10;
-
- /* decompress until deflate stream ends or end of file */
- do {
- if (slen == 0)
- break;
-
- if (slen > CHUNK)
- strm.avail_in = CHUNK;
- else
- strm.avail_in = slen;
-
- memcpy(in, source, strm.avail_in);
- slen = slen - strm.avail_in;
- source = source + strm.avail_in;
- strm.next_in = in;
-
- /* run inflate() on input until output buffer not full */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = inflate(&strm, Z_NO_FLUSH);
- log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- switch (ret) {
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- inflateEnd(&strm);
- return ret;
- }
- have = CHUNK - strm.avail_out;
-
- if (dlen < have) {
- log_warn("dest buf too small - have %lu, need %lu",
- (unsigned long)dlen, (unsigned long)have);
- return Z_ERRNO;
- }
-
- memcpy(dest, out, have);
- dest += have;
- dlen = dlen - have;
-
- } while (strm.avail_out == 0);
-
- /* done when inflate() says it's done */
- } while (ret != Z_STREAM_END);
-
- /* clean up and return */
- inflateEnd(&strm);
-
- if (ret == Z_STREAM_END)
- return dlen_orig - dlen;
- return Z_DATA_ERROR;
-}
-
-ssize_t
-gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
- time_t mtime)
-{
- unsigned char *c;
- unsigned long crc;
- z_stream z;
-
- if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
- return -1;
-
- z.zalloc = Z_NULL;
- z.zfree = Z_NULL;
- z.opaque = Z_NULL;
-
- if (Z_OK != deflateInit2(&z,
- Z_DEFAULT_COMPRESSION,
- Z_DEFLATED,
- -MAX_WBITS, /* supress zlib-header */
- 8,
- Z_DEFAULT_STRATEGY))
- return -1;
-
- z.next_in = (Bytef *)source;
- z.avail_in = slen;
- z.total_in = 0;
-
- /* write gzip header */
-
- c = (unsigned char *)dest;
- c[0] = 0x1f;
- c[1] = 0x8b;
- c[2] = Z_DEFLATED;
- c[3] = 0; /* options */
- c[4] = (mtime >> 0) & 0xff;
- c[5] = (mtime >> 8) & 0xff;
- c[6] = (mtime >> 16) & 0xff;
- c[7] = (mtime >> 24) & 0xff;
- c[8] = 0x00; /* extra flags */
- c[9] = 0x03; /* UNIX */
-
- z.next_out = c + 10;
- z.avail_out = dlen - 10 - 8;
- z.total_out = 0;
-
- if (deflate(&z, Z_FINISH) != Z_STREAM_END) {
- deflateEnd(&z);
- return -1;
- }
-
- crc = generate_crc32c(source, slen);
-
- c = (unsigned char *)dest + 10 + z.total_out;
- c[0] = (crc >> 0) & 0xff;
- c[1] = (crc >> 8) & 0xff;
- c[2] = (crc >> 16) & 0xff;
- c[3] = (crc >> 24) & 0xff;
- c[4] = (z.total_in >> 0) & 0xff;
- c[5] = (z.total_in >> 8) & 0xff;
- c[6] = (z.total_in >> 16) & 0xff;
- c[7] = (z.total_in >> 24) & 0xff;
-
- if (deflateEnd(&z) != Z_OK)
- return -1;
- return 10 + z.total_out + 8;
-}
diff --git a/src/steg/zpack.h b/src/steg/zpack.h
deleted file mode 100644
index 5d3f82f..0000000
--- a/src/steg/zpack.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _ZPACK_H
-#define _ZPACK_H
-
-ssize_t def(const char *source, size_t slen, char *dest, size_t dlen,
- int level);
-ssize_t inf(const char *source, size_t slen, char *dest, size_t dlen);
-
-ssize_t gzInflate(const char *source, size_t slen, char *dest, size_t dlen);
-ssize_t gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
- time_t mtime);
-
-#endif
diff --git a/src/zpack.cc b/src/zpack.cc
new file mode 100644
index 0000000..c3c650f
--- /dev/null
+++ b/src/zpack.cc
@@ -0,0 +1,311 @@
+#include "util.h"
+#include "zpack.h"
+#include "zlib.h"
+#include "crc32.h"
+
+#define CHUNK 16384
+
+/* Compress from file source to file dest until EOF on source.
+ def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
+ allocated for processing, Z_STREAM_ERROR if an invalid compression
+ level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
+ version of the library linked do not match, or Z_ERRNO if there is
+ an error reading or writing the files. */
+
+ssize_t
+def(const char *source, size_t slen, char *dest, size_t dlen, int level)
+{
+ int ret, flush;
+ size_t have;
+ z_stream strm;
+ unsigned char in[CHUNK];
+ unsigned char out[CHUNK];
+ size_t dlen_orig = dlen;
+
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
+
+ /* allocate deflate state */
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ ret = deflateInit(&strm, level);
+ if (ret != Z_OK)
+ return ret;
+
+ /* compress until end of file */
+ do {
+ if (slen > CHUNK)
+ strm.avail_in = CHUNK;
+ else
+ strm.avail_in = slen;
+
+ memcpy (in, source, strm.avail_in);
+ slen = slen - strm.avail_in;
+ source = source + strm.avail_in;
+
+ flush = (slen == 0) ? Z_FINISH : Z_NO_FLUSH;
+ strm.next_in = in;
+
+ /* run deflate() on input until output buffer not full, finish
+ compression if all of source has been read in */
+ do {
+ strm.avail_out = CHUNK;
+ strm.next_out = out;
+ ret = deflate(&strm, flush); /* no bad return value */
+ log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ have = CHUNK - strm.avail_out;
+
+ if (dlen < have) {
+ log_warn("dest buf too small - have %lu, need %lu",
+ (unsigned long)dlen, (unsigned long)have);
+ return Z_ERRNO;
+ }
+
+ memcpy(dest, out, have);
+ dest += have;
+ dlen = dlen - have;
+ } while (strm.avail_out == 0);
+ log_assert(strm.avail_in == 0); /* all input will be used */
+
+ /* done when last data in file processed */
+ } while (flush != Z_FINISH);
+ log_assert(ret == Z_STREAM_END); /* stream will be complete */
+
+ /* clean up and return */
+ deflateEnd(&strm);
+ return (dlen_orig - dlen);
+}
+
+/* Decompress from file source to file dest until stream ends or EOF.
+ inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
+ allocated for processing, Z_DATA_ERROR if the deflate data is
+ invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
+ the version of the library linked do not match, or Z_ERRNO if there
+ is an error reading or writing the files. */
+
+ssize_t
+inf(const char *source, size_t slen, char *dest, size_t dlen)
+{
+ int ret;
+ size_t have;
+ z_stream strm;
+ unsigned char in[CHUNK];
+ unsigned char out[CHUNK];
+ size_t dlen_orig = dlen;
+
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
+
+ /* allocate inflate state */
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit(&strm);
+ if (ret != Z_OK)
+ return ret;
+
+ /* decompress until deflate stream ends or end of file */
+ do {
+ if (slen == 0)
+ break;
+
+ if (slen > CHUNK)
+ strm.avail_in = CHUNK;
+ else
+ strm.avail_in = slen;
+
+ memcpy(in, source, strm.avail_in);
+ slen = slen - strm.avail_in;
+ source = source + strm.avail_in;
+ strm.next_in = in;
+
+ /* run inflate() on input until output buffer not full */
+ do {
+ strm.avail_out = CHUNK;
+ strm.next_out = out;
+ ret = inflate(&strm, Z_NO_FLUSH);
+ log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ switch (ret) {
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ inflateEnd(&strm);
+ return ret;
+ }
+ have = CHUNK - strm.avail_out;
+
+ if (dlen < have) {
+ log_warn("dest buf too small - have %lu, need %lu",
+ (unsigned long)dlen, (unsigned long)have);
+ return Z_ERRNO;
+ }
+
+ memcpy(dest, out, have);
+ dest += have;
+ dlen = dlen - have;
+
+ } while (strm.avail_out == 0);
+
+ /* done when inflate() says it's done */
+ } while (ret != Z_STREAM_END);
+
+ /* clean up and return */
+ inflateEnd(&strm);
+
+ if (ret == Z_STREAM_END)
+ return dlen_orig - dlen;
+ return Z_DATA_ERROR;
+}
+
+/* assumes that we know there is exactly 10 bytes of gzip header */
+
+ssize_t
+gzInflate(const char *source, size_t slen, char *dest, size_t dlen)
+{
+ int ret;
+ size_t have;
+ z_stream strm;
+ unsigned char in[CHUNK];
+ unsigned char out[CHUNK];
+ size_t dlen_orig = dlen;
+
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
+
+ /* allocate inflate state */
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+
+ ret = inflateInit2(&strm, -MAX_WBITS);
+ if (ret != Z_OK)
+ return ret;
+
+ source = source + 10;
+ slen -= 10;
+
+ /* decompress until deflate stream ends or end of file */
+ do {
+ if (slen == 0)
+ break;
+
+ if (slen > CHUNK)
+ strm.avail_in = CHUNK;
+ else
+ strm.avail_in = slen;
+
+ memcpy(in, source, strm.avail_in);
+ slen = slen - strm.avail_in;
+ source = source + strm.avail_in;
+ strm.next_in = in;
+
+ /* run inflate() on input until output buffer not full */
+ do {
+ strm.avail_out = CHUNK;
+ strm.next_out = out;
+ ret = inflate(&strm, Z_NO_FLUSH);
+ log_assert(ret != Z_STREAM_ERROR); /* state not clobbered */
+ switch (ret) {
+ case Z_NEED_DICT:
+ ret = Z_DATA_ERROR; /* and fall through */
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ inflateEnd(&strm);
+ return ret;
+ }
+ have = CHUNK - strm.avail_out;
+
+ if (dlen < have) {
+ log_warn("dest buf too small - have %lu, need %lu",
+ (unsigned long)dlen, (unsigned long)have);
+ return Z_ERRNO;
+ }
+
+ memcpy(dest, out, have);
+ dest += have;
+ dlen = dlen - have;
+
+ } while (strm.avail_out == 0);
+
+ /* done when inflate() says it's done */
+ } while (ret != Z_STREAM_END);
+
+ /* clean up and return */
+ inflateEnd(&strm);
+
+ if (ret == Z_STREAM_END)
+ return dlen_orig - dlen;
+ return Z_DATA_ERROR;
+}
+
+ssize_t
+gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
+ time_t mtime)
+{
+ unsigned char *c;
+ unsigned long crc;
+ z_stream z;
+
+ if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
+ return -1;
+
+ z.zalloc = Z_NULL;
+ z.zfree = Z_NULL;
+ z.opaque = Z_NULL;
+
+ if (Z_OK != deflateInit2(&z,
+ Z_DEFAULT_COMPRESSION,
+ Z_DEFLATED,
+ -MAX_WBITS, /* supress zlib-header */
+ 8,
+ Z_DEFAULT_STRATEGY))
+ return -1;
+
+ z.next_in = (Bytef *)source;
+ z.avail_in = slen;
+ z.total_in = 0;
+
+ /* write gzip header */
+
+ c = (unsigned char *)dest;
+ c[0] = 0x1f;
+ c[1] = 0x8b;
+ c[2] = Z_DEFLATED;
+ c[3] = 0; /* options */
+ c[4] = (mtime >> 0) & 0xff;
+ c[5] = (mtime >> 8) & 0xff;
+ c[6] = (mtime >> 16) & 0xff;
+ c[7] = (mtime >> 24) & 0xff;
+ c[8] = 0x00; /* extra flags */
+ c[9] = 0x03; /* UNIX */
+
+ z.next_out = c + 10;
+ z.avail_out = dlen - 10 - 8;
+ z.total_out = 0;
+
+ if (deflate(&z, Z_FINISH) != Z_STREAM_END) {
+ deflateEnd(&z);
+ return -1;
+ }
+
+ crc = generate_crc32c(source, slen);
+
+ c = (unsigned char *)dest + 10 + z.total_out;
+ c[0] = (crc >> 0) & 0xff;
+ c[1] = (crc >> 8) & 0xff;
+ c[2] = (crc >> 16) & 0xff;
+ c[3] = (crc >> 24) & 0xff;
+ c[4] = (z.total_in >> 0) & 0xff;
+ c[5] = (z.total_in >> 8) & 0xff;
+ c[6] = (z.total_in >> 16) & 0xff;
+ c[7] = (z.total_in >> 24) & 0xff;
+
+ if (deflateEnd(&z) != Z_OK)
+ return -1;
+ return 10 + z.total_out + 8;
+}
diff --git a/src/zpack.h b/src/zpack.h
new file mode 100644
index 0000000..5d3f82f
--- /dev/null
+++ b/src/zpack.h
@@ -0,0 +1,12 @@
+#ifndef _ZPACK_H
+#define _ZPACK_H
+
+ssize_t def(const char *source, size_t slen, char *dest, size_t dlen,
+ int level);
+ssize_t inf(const char *source, size_t slen, char *dest, size_t dlen);
+
+ssize_t gzInflate(const char *source, size_t slen, char *dest, size_t dlen);
+ssize_t gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
+ time_t mtime);
+
+#endif
1
0
[stegotorus/master] Switch zpack.h API from plain char* to uint8_t*
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit f2883a1507f67e8b0b34fc479d3fbeb52f310afc
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 30 11:54:10 2012 -0700
Switch zpack.h API from plain char* to uint8_t*
---
src/steg/jsSteg.cc | 8 +++--
src/steg/swfSteg.cc | 7 +++-
src/zpack.cc | 72 ++++++++++++++++++++++++--------------------------
src/zpack.h | 12 +++++---
4 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/src/steg/jsSteg.cc b/src/steg/jsSteg.cc
index 7cfd056..8fee7cb 100644
--- a/src/steg/jsSteg.cc
+++ b/src/steg/jsSteg.cc
@@ -724,7 +724,7 @@ http_server_JS_transmit (payloads& pl, struct evbuffer *source, conn_t *conn,
char newHdr[MAX_RESP_HDR_SIZE];
unsigned int datalen = 0, cnt = 0, mjs = 0;
int r, i, mode, jsLen, hLen, cLen, newHdrLen = 0, outbuf2len;
-
+
int gzipMode = JS_GZIP_RESP;
@@ -828,7 +828,8 @@ http_server_JS_transmit (payloads& pl, struct evbuffer *source, conn_t *conn,
// sizeof outbuf2 = cLen + 10-byte for gzip header + 8-byte for crc
outbuf2 = (char *)xmalloc(cLen+18);
- outbuf2len = gzDeflate(outbuf, cLen, outbuf2, cLen+18, time(NULL));
+ outbuf2len = gzDeflate((const uint8_t *)outbuf, cLen,
+ (uint8_t *)outbuf2, cLen+18, time(NULL));
if (outbuf2len <= 0) {
log_warn("gzDeflate for outbuf fails");
@@ -991,7 +992,8 @@ http_handle_client_JS_receive(steg_t *, conn_t *conn, struct evbuffer *dest, str
gzipMode = isGzipContent(respMsg);
if (gzipMode) {
log_debug("gzip content encoding detected");
- buf2len = gzInflate(httpBody, httpBodyLen, buf2, HTTP_MSG_BUF_SIZE);
+ buf2len = gzInflate((const uint8_t *)httpBody, httpBodyLen,
+ (uint8_t *)buf2, HTTP_MSG_BUF_SIZE);
if (buf2len <= 0) {
log_warn("gzInflate for httpBody fails");
fprintf(stderr, "gzInflate for httpBody fails");
diff --git a/src/steg/swfSteg.cc b/src/steg/swfSteg.cc
index 4358fe3..77c425b 100644
--- a/src/steg/swfSteg.cc
+++ b/src/steg/swfSteg.cc
@@ -62,7 +62,9 @@ swf_wrap(payloads& pl, char* inbuf, int in_len, char* outbuf, int out_sz) {
memcpy(tmp_buf, swf+8, SWF_SAVE_HEADER_LEN);
memcpy(tmp_buf+SWF_SAVE_HEADER_LEN, inbuf, in_len);
memcpy(tmp_buf+SWF_SAVE_HEADER_LEN+in_len, swf + in_swf_len - SWF_SAVE_FOOTER_LEN, SWF_SAVE_FOOTER_LEN);
- out_swf_len = def(tmp_buf, SWF_SAVE_HEADER_LEN + in_len + SWF_SAVE_FOOTER_LEN, tmp_buf2+8,
+ out_swf_len = def((const uint8_t *)tmp_buf,
+ SWF_SAVE_HEADER_LEN + in_len + SWF_SAVE_FOOTER_LEN,
+ (uint8_t *)tmp_buf2+8,
in_len + SWF_SAVE_HEADER_LEN + SWF_SAVE_FOOTER_LEN + 512-8,
Z_DEFAULT_COMPRESSION);
@@ -98,7 +100,8 @@ swf_unwrap(char* inbuf, int in_len, char* outbuf, int out_sz) {
tmp_buf = (char *)xmalloc(in_len * 8);
- inf_len = inf(inbuf + 8, in_len - 8, tmp_buf, in_len * 8);
+ inf_len = inf((const uint8_t *)inbuf + 8, in_len - 8,
+ (uint8_t *)tmp_buf, in_len * 8);
// fprintf(stderr, "in_swf_len = %d\n", in_len -8 );
diff --git a/src/zpack.cc b/src/zpack.cc
index 2a7adfc..24c64fd 100644
--- a/src/zpack.cc
+++ b/src/zpack.cc
@@ -17,13 +17,13 @@
an error reading or writing the files. */
ssize_t
-def(const char *source, size_t slen, char *dest, size_t dlen, int level)
+def(const uint8_t *source, size_t slen, uint8_t *dest, size_t dlen, int level)
{
int ret, flush;
size_t have;
z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
+ uint8_t in[CHUNK];
+ uint8_t out[CHUNK];
size_t dlen_orig = dlen;
if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
@@ -89,13 +89,13 @@ def(const char *source, size_t slen, char *dest, size_t dlen, int level)
is an error reading or writing the files. */
ssize_t
-inf(const char *source, size_t slen, char *dest, size_t dlen)
+inf(const uint8_t *source, size_t slen, uint8_t *dest, size_t dlen)
{
int ret;
size_t have;
z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
+ uint8_t in[CHUNK];
+ uint8_t out[CHUNK];
size_t dlen_orig = dlen;
if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
@@ -167,13 +167,13 @@ inf(const char *source, size_t slen, char *dest, size_t dlen)
/* assumes that we know there is exactly 10 bytes of gzip header */
ssize_t
-gzInflate(const char *source, size_t slen, char *dest, size_t dlen)
+gzInflate(const uint8_t *source, size_t slen, uint8_t *dest, size_t dlen)
{
int ret;
size_t have;
z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
+ uint8_t in[CHUNK];
+ uint8_t out[CHUNK];
size_t dlen_orig = dlen;
if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
@@ -248,11 +248,10 @@ gzInflate(const char *source, size_t slen, char *dest, size_t dlen)
}
ssize_t
-gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
+gzDeflate(const uint8_t *source, size_t slen, uint8_t *dest, size_t dlen,
time_t mtime)
{
- unsigned char *c;
- unsigned long crc;
+ uint32_t crc;
z_stream z;
if (slen > SIZE_T_CEILING || dlen > SIZE_T_CEILING)
@@ -270,25 +269,24 @@ gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
Z_DEFAULT_STRATEGY))
return -1;
- z.next_in = (Bytef *)source;
+ z.next_in = const_cast<uint8_t*>(source);
z.avail_in = slen;
z.total_in = 0;
/* write gzip header */
- c = (unsigned char *)dest;
- c[0] = 0x1f;
- c[1] = 0x8b;
- c[2] = Z_DEFLATED;
- c[3] = 0; /* options */
- c[4] = (mtime >> 0) & 0xff;
- c[5] = (mtime >> 8) & 0xff;
- c[6] = (mtime >> 16) & 0xff;
- c[7] = (mtime >> 24) & 0xff;
- c[8] = 0x00; /* extra flags */
- c[9] = 0x03; /* UNIX */
-
- z.next_out = c + 10;
+ dest[0] = 0x1f;
+ dest[1] = 0x8b;
+ dest[2] = Z_DEFLATED;
+ dest[3] = 0; /* options */
+ dest[4] = (mtime >> 0) & 0xff;
+ dest[5] = (mtime >> 8) & 0xff;
+ dest[6] = (mtime >> 16) & 0xff;
+ dest[7] = (mtime >> 24) & 0xff;
+ dest[8] = 0x00; /* extra flags */
+ dest[9] = 0x03; /* UNIX */
+
+ z.next_out = dest + 10;
z.avail_out = dlen - 10 - 8;
z.total_out = 0;
@@ -297,17 +295,17 @@ gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
return -1;
}
- crc = generate_crc32c((const uint8_t *)source, slen);
-
- c = (unsigned char *)dest + 10 + z.total_out;
- c[0] = (crc >> 0) & 0xff;
- c[1] = (crc >> 8) & 0xff;
- c[2] = (crc >> 16) & 0xff;
- c[3] = (crc >> 24) & 0xff;
- c[4] = (z.total_in >> 0) & 0xff;
- c[5] = (z.total_in >> 8) & 0xff;
- c[6] = (z.total_in >> 16) & 0xff;
- c[7] = (z.total_in >> 24) & 0xff;
+ crc = generate_crc32c(source, slen);
+
+ dest = dest + 10 + z.total_out;
+ dest[0] = (crc >> 0) & 0xff;
+ dest[1] = (crc >> 8) & 0xff;
+ dest[2] = (crc >> 16) & 0xff;
+ dest[3] = (crc >> 24) & 0xff;
+ dest[4] = (z.total_in >> 0) & 0xff;
+ dest[5] = (z.total_in >> 8) & 0xff;
+ dest[6] = (z.total_in >> 16) & 0xff;
+ dest[7] = (z.total_in >> 24) & 0xff;
if (deflateEnd(&z) != Z_OK)
return -1;
diff --git a/src/zpack.h b/src/zpack.h
index e1e1c2c..438c9dc 100644
--- a/src/zpack.h
+++ b/src/zpack.h
@@ -4,12 +4,16 @@
#ifndef _ZPACK_H
#define _ZPACK_H
-ssize_t def(const char *source, size_t slen, char *dest, size_t dlen,
+ssize_t def(const uint8_t *source, size_t slen,
+ uint8_t *dest, size_t dlen,
int level);
-ssize_t inf(const char *source, size_t slen, char *dest, size_t dlen);
+ssize_t inf(const uint8_t *source, size_t slen,
+ uint8_t *dest, size_t dlen);
-ssize_t gzInflate(const char *source, size_t slen, char *dest, size_t dlen);
-ssize_t gzDeflate(const char *source, size_t slen, char *dest, size_t dlen,
+ssize_t gzInflate(const uint8_t *source, size_t slen,
+ uint8_t *dest, size_t dlen);
+ssize_t gzDeflate(const uint8_t *source, size_t slen,
+ uint8_t *dest, size_t dlen,
time_t mtime);
uint32_t generate_crc32c(const uint8_t *string, size_t length);
1
0
[stegotorus/master] Add/update copyright and licensing boilerplate on all files.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 9f06d160d0091d2e9ba39efdf26c48e201efe811
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Apr 23 16:15:24 2012 -0700
Add/update copyright and licensing boilerplate on all files.
---
LICENSE | 40 ++++++++--------------------------------
Makefile.am | 4 ++--
configure.ac | 4 ++++
scripts/benchmark-plot.R | 6 ++++++
scripts/benchmark.py | 6 ++++++
scripts/bm-fixedrate-cgi.c | 7 +++++++
scripts/bm-genfiles.py | 6 ++++++
scripts/bm-mcurl.c | 8 +++++++-
scripts/bm-tor-controller.py | 6 ++++++
scripts/start-stegotorus.sh | 6 ++++++
src/audit-globals.sh | 2 ++
src/connections.cc | 7 ++++---
src/connections.h | 7 ++++---
src/crc32.cc | 3 +++
src/crc32.h | 4 ++++
src/crypt.cc | 7 ++++---
src/crypt.h | 8 ++++----
src/genmodtable.sh | 2 ++
src/listener.h | 5 ++---
src/main.cc | 5 +++--
src/main.h | 5 ++---
src/network.cc | 5 +++--
src/protocol.cc | 5 +++--
src/protocol.h | 5 +++--
src/protocol/chop.cc | 21 ++++++---------------
src/protocol/null.cc | 5 +++--
src/rng.cc | 7 ++++---
src/rng.h | 6 +++---
src/socks.cc | 5 +++--
src/socks.h | 5 ++---
src/steg.cc | 8 ++++----
src/steg.h | 7 +++----
src/steg/b64cookies.cc | 3 +++
src/steg/b64cookies.h | 4 ++++
src/steg/cookies.cc | 3 +++
src/steg/cookies.h | 6 ++++--
src/steg/embed.cc | 4 ++++
src/steg/http.cc | 36 +++---------------------------------
src/steg/jsSteg.cc | 4 ++++
src/steg/jsSteg.h | 4 ++++
src/steg/nosteg.cc | 36 +++---------------------------------
src/steg/nosteg_rr.cc | 36 +++---------------------------------
src/steg/payloads.cc | 4 ++++
src/steg/payloads.h | 4 ++++
src/steg/pdfSteg.cc | 4 ++++
src/steg/pdfSteg.h | 4 ++++
src/steg/swfSteg.cc | 3 +++
src/steg/swfSteg.h | 4 ++++
src/test/genunitgrps.sh | 2 ++
src/test/itestlib.py | 3 +++
src/test/test_socks.py | 3 +++
src/test/test_tl.py | 3 +++
src/test/tinytest.cc | 23 +----------------------
src/test/tinytest.h | 23 +----------------------
src/test/tinytest_macros.h | 24 ++----------------------
src/test/tl_oneway_c2s | 3 +++
src/test/tl_oneway_s2c | 3 +++
src/test/tl_snark | 2 ++
src/test/tltester.cc | 5 +++--
src/test/unittest.cc | 5 +++--
src/test/unittest.h | 7 ++++---
src/test/unittest_config.cc | 5 +++--
src/test/unittest_crypt.cc | 6 +++---
src/test/unittest_pdfsteg.cc | 3 ++-
src/test/unittest_socks.cc | 5 +++--
src/test/unittest_transfer.cc | 5 +++--
src/util.cc | 6 +++---
src/util.h | 5 +++--
src/zpack.cc | 3 +++
src/zpack.h | 3 +++
70 files changed, 246 insertions(+), 287 deletions(-)
diff --git a/LICENSE b/LICENSE
index 05950d7..3bcae2b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,8 @@
StegoTorus is Licensed under the 3-clause BSD license:
-Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
+Copyright 2009, 2010 Nick Mathewson
+Copyright 2011 Nick Mathewson, George Kadianakis
+Copyright 2011, 2012 SRI International
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@@ -30,35 +32,9 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-========
-The src/test/tinytest* files are part of the "tinytest" unit test suite.
-Their license:
-
- Copyright 2009-2010 Nick Mathewson
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-=======
-The m4/pkg.m4 macro used by is distributed under GPLv2+ with autoconf
-exemption. See m4/pkg.m4 for details. This license DOES NOT apply to the
-generated configure file, or to any of stegotorus's code.
+=====
+The files in m4/ and scripts/ each have their own individual copyright
+and licensing, which may be more or less permissive than the above
+license. However, those licenses DO NOT extend to the collective
+work, the generated configure script, or to StegoTorus itself.
diff --git a/Makefile.am b/Makefile.am
index 7d72a96..11f8ac3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
-# Makefile for stegotorus
-# Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
+# Copyright 2011 Nick Mathewson, George Kadianakis
+# Copyright 2011, 2012 SRI International
# See LICENSE for other credits and copying information
ACLOCAL_AMFLAGS = -I m4 --install
diff --git a/configure.ac b/configure.ac
index 87cb713..647879a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,3 +1,7 @@
+dnl Copyright 2011 Nick Mathewson, George Kadianakis
+dnl Copyright 2011, 2012 SRI International
+dnl See LICENSE for other credits and copying information
+dnl
AC_PREREQ([2.61])dnl Possibly earlier will do, but this is what I have
AC_INIT([stegotorus], [0.0])
AC_CONFIG_SRCDIR([src/main.cc])
diff --git a/scripts/benchmark-plot.R b/scripts/benchmark-plot.R
index 1ae178d..c586ac4 100644
--- a/scripts/benchmark-plot.R
+++ b/scripts/benchmark-plot.R
@@ -1,4 +1,10 @@
#! /usr/bin/Rscript
+# Copyright 2012 Zachary Weinberg
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
suppressPackageStartupMessages({
library(plyr)
diff --git a/scripts/benchmark.py b/scripts/benchmark.py
index 8029f11..d9a4506 100755
--- a/scripts/benchmark.py
+++ b/scripts/benchmark.py
@@ -1,4 +1,10 @@
#! /usr/bin/python
+# Copyright 2012 Zachary Weinberg
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
# Stegotorus benchmarking script.
# Several different computers are involved:
diff --git a/scripts/bm-fixedrate-cgi.c b/scripts/bm-fixedrate-cgi.c
index 851cda7..8f4b31e 100644
--- a/scripts/bm-fixedrate-cgi.c
+++ b/scripts/bm-fixedrate-cgi.c
@@ -1,3 +1,10 @@
+/* Copyright 2012 Zachary Weinberg
+ *
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice
+ * and this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ */
#define _XOPEN_SOURCE 600
#define _POSIX_C_SOURCE 200112
diff --git a/scripts/bm-genfiles.py b/scripts/bm-genfiles.py
index dcd1030..57f3a65 100755
--- a/scripts/bm-genfiles.py
+++ b/scripts/bm-genfiles.py
@@ -1,4 +1,10 @@
#! /usr/bin/python
+# Copyright 2012 Zachary Weinberg
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
"""Generate files for network performance testing.
diff --git a/scripts/bm-mcurl.c b/scripts/bm-mcurl.c
index 7fb03a0..e7b75c5 100644
--- a/scripts/bm-mcurl.c
+++ b/scripts/bm-mcurl.c
@@ -1,4 +1,10 @@
-/* Use libcurl to retrieve many URLs, according to a wildcard pattern,
+/* Copyright 2012 Zachary Weinberg
+ Copying and distribution of this file, with or without modification, are
+ permitted in any medium without royalty provided the copyright notice
+ and this notice are preserved. This file is offered as-is, without any
+ warranty.
+
+ Use libcurl to retrieve many URLs, according to a wildcard pattern,
starting new connections at a constant rate until we hit a limit.
Command line arguments -- all are required, but 'proxy' may be an
diff --git a/scripts/bm-tor-controller.py b/scripts/bm-tor-controller.py
index f10d8d2..e54038e 100755
--- a/scripts/bm-tor-controller.py
+++ b/scripts/bm-tor-controller.py
@@ -1,4 +1,10 @@
#! /usr/bin/python
+# Copyright 2012 Zachary Weinberg
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
from torctl import TorCtl, TorUtil, PathSupport
import sys
diff --git a/scripts/start-stegotorus.sh b/scripts/start-stegotorus.sh
index 9ea5be7..55f72fd 100644
--- a/scripts/start-stegotorus.sh
+++ b/scripts/start-stegotorus.sh
@@ -1,4 +1,10 @@
#!/bin/bash
+# Copyright 2012 SRI International
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
################################################################################
# variables with default values
diff --git a/src/audit-globals.sh b/src/audit-globals.sh
index 3c21643..21d6633 100644
--- a/src/audit-globals.sh
+++ b/src/audit-globals.sh
@@ -1,4 +1,6 @@
#! /bin/sh
+# Copyright 2012 SRI International
+# See LICENSE for other credits and copying information
# Due to the multi-listener architecture of stegotorus, nearly all
# global variables are bugs. This program enforces a white-list of
diff --git a/src/connections.cc b/src/connections.cc
index 39191b2..4f95d12 100644
--- a/src/connections.cc
+++ b/src/connections.cc
@@ -1,6 +1,7 @@
-/* Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 Nick Mathewson, George Kadianakis
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
diff --git a/src/connections.h b/src/connections.h
index ddf787a..64a4252 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -1,6 +1,7 @@
-/* Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 Nick Mathewson, George Kadianakis
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef CONNECTIONS_H
#define CONNECTIONS_H
diff --git a/src/crc32.cc b/src/crc32.cc
index 1b18544..151eae1 100644
--- a/src/crc32.cc
+++ b/src/crc32.cc
@@ -1,3 +1,6 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "crc32.h"
diff --git a/src/crc32.h b/src/crc32.h
index 0a1ee03..67bb48a 100644
--- a/src/crc32.h
+++ b/src/crc32.h
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _CRC32_H
#define _CRC32_H
diff --git a/src/crypt.cc b/src/crypt.cc
index d964708..e60cc41 100644
--- a/src/crypt.cc
+++ b/src/crypt.cc
@@ -1,6 +1,7 @@
-/* Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 Nick Mathewson, George Kadianakis
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "crypt.h"
diff --git a/src/crypt.h b/src/crypt.h
index b3bbcfa..d7e5fbf 100644
--- a/src/crypt.h
+++ b/src/crypt.h
@@ -1,7 +1,7 @@
-/* Copyright 2011, 2012 Nick Mathewson, George Kadianakis, Zack Weinberg
- See LICENSE for other credits and copying information
-*/
-
+/* Copyright 2011 Nick Mathewson, George Kadianakis
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef CRYPT_H
#define CRYPT_H
diff --git a/src/genmodtable.sh b/src/genmodtable.sh
index c37b90e..8c922b3 100755
--- a/src/genmodtable.sh
+++ b/src/genmodtable.sh
@@ -1,4 +1,6 @@
#! /bin/sh
+# Copyright 2011 SRI International
+# See LICENSE for other credits and copying information
set -e
diff --git a/src/listener.h b/src/listener.h
index 4fac10a..6a73d1d 100644
--- a/src/listener.h
+++ b/src/listener.h
@@ -1,7 +1,6 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
-
+ * See LICENSE for other credits and copying information
+ */
#ifndef LISTENER_H
#define LISTENER_H
diff --git a/src/main.cc b/src/main.cc
index 1c8e55f..8c1407f 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "main.h"
diff --git a/src/main.h b/src/main.h
index 8814499..5786569 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1,7 +1,6 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
-
+ * See LICENSE for other credits and copying information
+ */
#ifndef MAIN_H
#define MAIN_H
diff --git a/src/network.cc b/src/network.cc
index fb17e99..6039df0 100644
--- a/src/network.cc
+++ b/src/network.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "listener.h"
diff --git a/src/protocol.cc b/src/protocol.cc
index cb8db24..e63b6c2 100644
--- a/src/protocol.cc
+++ b/src/protocol.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "protocol.h"
diff --git a/src/protocol.h b/src/protocol.h
index 4f0d6cd..fbc459e 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef PROTOCOL_H
#define PROTOCOL_H
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index dac4ea2..5451925 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -1,9 +1,6 @@
-/* Copyright 2011, 2012 Zack Weinberg
- See LICENSE for other credits and copying information
-
- The chopper is the core StegoTorus protocol implementation.
- For its design, see doc/chopper.txt. Note that it is still
- being implemented, and may change incompatibly. */
+/* Copyright 2011, SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
@@ -19,9 +16,9 @@
#include <event2/event.h>
#include <event2/buffer.h>
-#ifdef HAVE_EXECINFO_H
-#include <execinfo.h>
-#endif
+/* The chopper is the core StegoTorus protocol implementation.
+ For its design, see doc/chopper.txt. Note that it is still
+ being implemented, and may change incompatibly. */
using std::tr1::unordered_map;
using std::tr1::unordered_set;
@@ -557,12 +554,6 @@ chop_circuit_t::~chop_circuit_t()
sent_fin ? '+' : '-', received_fin ? '+' : '-',
upstream_eof ? '+' : '-',
(unsigned long)downstreams.size());
-#ifdef HAVE_EXECINFO_H
- int n;
- void *backtracebuf[256];
- n = backtrace(backtracebuf, sizeof backtracebuf / sizeof(void*));
- backtrace_symbols_fd(backtracebuf, n, 2);
-#endif
}
for (unordered_set<chop_conn_t *>::iterator i = downstreams.begin();
diff --git a/src/protocol/null.cc b/src/protocol/null.cc
index 277eb59..90abec2 100644
--- a/src/protocol/null.cc
+++ b/src/protocol/null.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
diff --git a/src/rng.cc b/src/rng.cc
index cfddd87..b76ba79 100644
--- a/src/rng.cc
+++ b/src/rng.cc
@@ -1,6 +1,7 @@
-/* Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 Nick Mathewson, George Kadianakis
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "rng.h"
diff --git a/src/rng.h b/src/rng.h
index 5cc0a5a..b34012c 100644
--- a/src/rng.h
+++ b/src/rng.h
@@ -1,6 +1,6 @@
-/* Copyright 2011 Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef RNG_H
#define RNG_H
diff --git a/src/socks.cc b/src/socks.cc
index 05da3f4..7203683 100644
--- a/src/socks.cc
+++ b/src/socks.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
diff --git a/src/socks.h b/src/socks.h
index c22b1bb..3d28568 100644
--- a/src/socks.h
+++ b/src/socks.h
@@ -1,7 +1,6 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
-
+ * See LICENSE for other credits and copying information
+ */
#ifndef SOCKS_H
#define SOCKS_H
diff --git a/src/steg.cc b/src/steg.cc
index 12ea291..ee9a1a1 100644
--- a/src/steg.cc
+++ b/src/steg.cc
@@ -1,6 +1,6 @@
-/* Copyright 2011 Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "steg.h"
@@ -24,7 +24,7 @@ steg_new(const char *name, config_t *cfg)
const steg_module *const *s;
for (s = supported_stegs; *s; s++)
if (!strcmp(name, (**s).name))
- return (**s).new_(cfg);
+ return (**s).new_(cfg);
return 0;
}
diff --git a/src/steg.h b/src/steg.h
index ad6b829..fe8ef5e 100644
--- a/src/steg.h
+++ b/src/steg.h
@@ -1,7 +1,6 @@
-/* Copyright 2011 Zack Weinberg
- See LICENSE for other credits and copying information
-*/
-
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef STEG_H
#define STEG_H
diff --git a/src/steg/b64cookies.cc b/src/steg/b64cookies.cc
index d0268be..b75bedc 100644
--- a/src/steg/b64cookies.cc
+++ b/src/steg/b64cookies.cc
@@ -1,3 +1,6 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "b64cookies.h"
diff --git a/src/steg/b64cookies.h b/src/steg/b64cookies.h
index 2ce40f4..1556cdd 100644
--- a/src/steg/b64cookies.h
+++ b/src/steg/b64cookies.h
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _B64_COOKIES_H
#define _B64_COOKIES_H
diff --git a/src/steg/cookies.cc b/src/steg/cookies.cc
index aa2d108..885c8cb 100644
--- a/src/steg/cookies.cc
+++ b/src/steg/cookies.cc
@@ -1,3 +1,6 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "cookies.h"
diff --git a/src/steg/cookies.h b/src/steg/cookies.h
index abda927..a7ed856 100644
--- a/src/steg/cookies.h
+++ b/src/steg/cookies.h
@@ -1,8 +1,10 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _COOKIES_H
#define _COOKIES_H
-
-
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
diff --git a/src/steg/embed.cc b/src/steg/embed.cc
index d301620..327c7c4 100644
--- a/src/steg/embed.cc
+++ b/src/steg/embed.cc
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#include "util.h"
#include "connections.h"
#include "protocol.h"
diff --git a/src/steg/http.cc b/src/steg/http.cc
index a41afb8..7267e6f 100644
--- a/src/steg/http.cc
+++ b/src/steg/http.cc
@@ -1,36 +1,6 @@
-/* Copyright (c) 2011, SRI International
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
-
- * Neither the names of the copyright owners nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Contributors: Zack Weinberg, Vinod Yegneswaran
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
diff --git a/src/steg/jsSteg.cc b/src/steg/jsSteg.cc
index 06d31e4..7cfd056 100644
--- a/src/steg/jsSteg.cc
+++ b/src/steg/jsSteg.cc
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#include "payloads.h"
#include "jsSteg.h"
#include "cookies.h"
diff --git a/src/steg/jsSteg.h b/src/steg/jsSteg.h
index 709ceb0..576f91f 100644
--- a/src/steg/jsSteg.h
+++ b/src/steg/jsSteg.h
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _JSSTEG_H
#define _JSSTEG_H
diff --git a/src/steg/nosteg.cc b/src/steg/nosteg.cc
index 328a1d6..8b8bf70 100644
--- a/src/steg/nosteg.cc
+++ b/src/steg/nosteg.cc
@@ -1,36 +1,6 @@
-/* Copyright (c) 2011, SRI International
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
-
- * Neither the names of the copyright owners nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Contributors: Zack Weinberg, Vinod Yegneswaran
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
diff --git a/src/steg/nosteg_rr.cc b/src/steg/nosteg_rr.cc
index adde6c8..6719584 100644
--- a/src/steg/nosteg_rr.cc
+++ b/src/steg/nosteg_rr.cc
@@ -1,36 +1,6 @@
-/* Copyright (c) 2011, SRI International
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
-
- * Neither the names of the copyright owners nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Contributors: Zack Weinberg, Vinod Yegneswaran
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
diff --git a/src/steg/payloads.cc b/src/steg/payloads.cc
index f5f35b8..d24711f 100644
--- a/src/steg/payloads.cc
+++ b/src/steg/payloads.cc
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#include "util.h"
#include "payloads.h"
#include "swfSteg.h"
diff --git a/src/steg/payloads.h b/src/steg/payloads.h
index 05a7307..cb809ba 100644
--- a/src/steg/payloads.h
+++ b/src/steg/payloads.h
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _PAYLOADS_H
#define _PAYLOADS_H
diff --git a/src/steg/pdfSteg.cc b/src/steg/pdfSteg.cc
index 3b4bbf0..658c319 100644
--- a/src/steg/pdfSteg.cc
+++ b/src/steg/pdfSteg.cc
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#include "util.h"
#include "pdfSteg.h"
#include "connections.h"
diff --git a/src/steg/pdfSteg.h b/src/steg/pdfSteg.h
index 0bd3a43..0b295b1 100644
--- a/src/steg/pdfSteg.h
+++ b/src/steg/pdfSteg.h
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _PDFSTEG_H
#define _PDFSTEG_H
diff --git a/src/steg/swfSteg.cc b/src/steg/swfSteg.cc
index c8a18c1..4358fe3 100644
--- a/src/steg/swfSteg.cc
+++ b/src/steg/swfSteg.cc
@@ -1,3 +1,6 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "swfSteg.h"
#include "connections.h"
diff --git a/src/steg/swfSteg.h b/src/steg/swfSteg.h
index b8336b2..938b05a 100644
--- a/src/steg/swfSteg.h
+++ b/src/steg/swfSteg.h
@@ -1,3 +1,7 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
+
#ifndef _SWFSTEG_H
#define _SWFSTEG_H
diff --git a/src/test/genunitgrps.sh b/src/test/genunitgrps.sh
index 63b9df7..d051e8e 100644
--- a/src/test/genunitgrps.sh
+++ b/src/test/genunitgrps.sh
@@ -1,4 +1,6 @@
#! /bin/sh
+# Copyright 2011 SRI International
+# See LICENSE for other credits and copying information
set -e
diff --git a/src/test/itestlib.py b/src/test/itestlib.py
index 1c483f3..90b1906 100644
--- a/src/test/itestlib.py
+++ b/src/test/itestlib.py
@@ -1,3 +1,6 @@
+# Copyright 2011, 2012 SRI International
+# See LICENSE for other credits and copying information
+
# Integration tests for stegotorus - library routines.
import difflib
diff --git a/src/test/test_socks.py b/src/test/test_socks.py
index d71da5e..b6c66e2 100644
--- a/src/test/test_socks.py
+++ b/src/test/test_socks.py
@@ -1,3 +1,6 @@
+# Copyright 2011, 2012 SRI International
+# See LICENSE for other credits and copying information
+
# Integration tests for stegotorus - socks mode.
import re
diff --git a/src/test/test_tl.py b/src/test/test_tl.py
index eb61f31..46e5d5a 100644
--- a/src/test/test_tl.py
+++ b/src/test/test_tl.py
@@ -1,3 +1,6 @@
+# Copyright 2011, 2012 SRI International
+# See LICENSE for other credits and copying information
+
# Integration tests for stegotorus - "timeline" tests.
#
# These tests use the 'tltester' utility to script a sequence of
diff --git a/src/test/tinytest.cc b/src/test/tinytest.cc
index 03ffd0d..21d14ee 100644
--- a/src/test/tinytest.cc
+++ b/src/test/tinytest.cc
@@ -1,26 +1,5 @@
/* tinytest.c -- Copyright 2009-2010 Nick Mathewson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * See LICENSE for other credits and copying information
*/
#include "tinytest_macros.h"
diff --git a/src/test/tinytest.h b/src/test/tinytest.h
index 2db71e9..1a995b9 100644
--- a/src/test/tinytest.h
+++ b/src/test/tinytest.h
@@ -1,26 +1,5 @@
/* tinytest.h -- Copyright 2009-2010 Nick Mathewson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * See LICENSE for other credits and copying information
*/
#ifndef _TINYTEST_H
diff --git a/src/test/tinytest_macros.h b/src/test/tinytest_macros.h
index cf5a2a2..00d8732 100644
--- a/src/test/tinytest_macros.h
+++ b/src/test/tinytest_macros.h
@@ -1,26 +1,6 @@
/* tinytest_macros.h -- Copyright 2009-2010 Nick Mathewson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
*/
#ifndef _TINYTEST_MACROS_H
diff --git a/src/test/tl_oneway_c2s b/src/test/tl_oneway_c2s
index 994ed59..6718112 100644
--- a/src/test/tl_oneway_c2s
+++ b/src/test/tl_oneway_c2s
@@ -1,3 +1,6 @@
+# Copyright 2011 SRI International
+# See LICENSE for other credits and copying information
+#
# lots of client-to-server, no server-to-client
> I
diff --git a/src/test/tl_oneway_s2c b/src/test/tl_oneway_s2c
index a286b46..a9ec7c4 100644
--- a/src/test/tl_oneway_s2c
+++ b/src/test/tl_oneway_s2c
@@ -1,3 +1,6 @@
+# Copyright 2011 SRI International
+# See LICENSE for other credits and copying information
+#
# lots of server-to-client, no client-to-server
< I
diff --git a/src/test/tl_snark b/src/test/tl_snark
index 95e8b88..a5e785a 100644
--- a/src/test/tl_snark
+++ b/src/test/tl_snark
@@ -1,3 +1,5 @@
+# All significant creative work in this file was done by
+# Lewis Carroll, and is in the public domain. Text derived
# from http://www.gutenberg.org/files/13/13-h/13-h.htm
> Fit the First
diff --git a/src/test/tltester.cc b/src/test/tltester.cc
index ca4c9b5..3876ef7 100644
--- a/src/test/tltester.cc
+++ b/src/test/tltester.cc
@@ -1,5 +1,6 @@
-/* Copyright 2011 Zack Weinberg
- See LICENSE for other credits and copying information. */
+/* Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
diff --git a/src/test/unittest.cc b/src/test/unittest.cc
index d09c2a6..cba4906 100644
--- a/src/test/unittest.cc
+++ b/src/test/unittest.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "unittest.h"
diff --git a/src/test/unittest.h b/src/test/unittest.h
index 9efe27b..81c873a 100644
--- a/src/test/unittest.h
+++ b/src/test/unittest.h
@@ -1,6 +1,7 @@
-/* Copyright 2011 Nick Mathewson, George Kadianakis, Zack Weinberg
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011 Nick Mathewson, George Kadianakis
+ * Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef UNITTEST_H
#define UNITTEST_H
diff --git a/src/test/unittest_config.cc b/src/test/unittest_config.cc
index 58571e9..72b39bd 100644
--- a/src/test/unittest_config.cc
+++ b/src/test/unittest_config.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "unittest.h"
diff --git a/src/test/unittest_crypt.cc b/src/test/unittest_crypt.cc
index 0053646..c411386 100644
--- a/src/test/unittest_crypt.cc
+++ b/src/test/unittest_crypt.cc
@@ -1,6 +1,6 @@
-/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "unittest.h"
diff --git a/src/test/unittest_pdfsteg.cc b/src/test/unittest_pdfsteg.cc
index cf9e97d..36a1167 100644
--- a/src/test/unittest_pdfsteg.cc
+++ b/src/test/unittest_pdfsteg.cc
@@ -1,5 +1,6 @@
/* Copyright 2011, 2012 SRI International
- See LICENSE for other credits and copying information */
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "unittest.h"
diff --git a/src/test/unittest_socks.cc b/src/test/unittest_socks.cc
index 84c256b..0dbfdc5 100644
--- a/src/test/unittest_socks.cc
+++ b/src/test/unittest_socks.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "unittest.h"
diff --git a/src/test/unittest_transfer.cc b/src/test/unittest_transfer.cc
index d1a7bbf..de17ed0 100644
--- a/src/test/unittest_transfer.cc
+++ b/src/test/unittest_transfer.cc
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "unittest.h"
diff --git a/src/util.cc b/src/util.cc
index a667abd..c94275c 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1,7 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
-
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "connections.h"
diff --git a/src/util.h b/src/util.h
index 167af8e..62908d1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,6 +1,7 @@
/* Copyright 2011 Nick Mathewson, George Kadianakis
- See LICENSE for other credits and copying information
-*/
+ * Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef UTIL_H
#define UTIL_H
diff --git a/src/zpack.cc b/src/zpack.cc
index c3c650f..751c96e 100644
--- a/src/zpack.cc
+++ b/src/zpack.cc
@@ -1,3 +1,6 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#include "util.h"
#include "zpack.h"
#include "zlib.h"
diff --git a/src/zpack.h b/src/zpack.h
index 5d3f82f..18bb531 100644
--- a/src/zpack.h
+++ b/src/zpack.h
@@ -1,3 +1,6 @@
+/* Copyright 2011, 2012 SRI International
+ * See LICENSE for other credits and copying information
+ */
#ifndef _ZPACK_H
#define _ZPACK_H
1
0