From 0824591133ebfa5a360df92e22bdde0454f43b1d Mon Sep 17 00:00:00 2001 From: corvid Date: Wed, 3 Sep 2014 22:17:07 +0000 Subject: a couple of quick https improvements --- dpi/https.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'dpi') diff --git a/dpi/https.c b/dpi/https.c index e6d2b0e9..f0b4ec89 100644 --- a/dpi/https.c +++ b/dpi/https.c @@ -156,9 +156,11 @@ static void yes_ssl_support(void) } } - /* Do not use the SSLv2 protocol. */ + /* Do not use the obsolete insecure SSLv2 protocol, and everyone disabled + * TLS compression when the CRIME exploit became widely known in 2012. + */ if (exit_error == 0){ - SSL_CTX_set_options(ssl_context, SSL_OP_NO_SSLv2); + SSL_CTX_set_options(ssl_context, SSL_OP_NO_SSLv2|SSL_OP_NO_COMPRESSION); } /*Set directory to load certificates from*/ @@ -188,10 +190,11 @@ static void yes_ssl_support(void) } if (exit_error == 0){ - /* Need to do the following if we want to deal with all - * possible ciphers + /* Don't want: eNULL, which has no encryption; aNULL, which has no + * authentication; LOW, which as of 2014 use 64 or 56-bit encryption; + * EXPORT40, which uses 40-bit encryption. */ - SSL_set_cipher_list(ssl_connection, "ALL"); + SSL_CTX_set_cipher_list(ssl_context, "ALL:!aNULL:!eNULL:!LOW:!EXPORT40"); /* Need to do this if we want to have the option of dealing * with self-signed certs -- cgit v1.2.3 From 1126f75f2141329c6839c4bc6c58d6bb947689fd Mon Sep 17 00:00:00 2001 From: corvid Date: Fri, 17 Oct 2014 01:36:00 +0000 Subject: everyone's finally disabling SSL3; let's do so too --- dpi/https.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'dpi') diff --git a/dpi/https.c b/dpi/https.c index f0b4ec89..da75b9e8 100644 --- a/dpi/https.c +++ b/dpi/https.c @@ -156,11 +156,12 @@ static void yes_ssl_support(void) } } - /* Do not use the obsolete insecure SSLv2 protocol, and everyone disabled - * TLS compression when the CRIME exploit became widely known in 2012. + /* SSL2 has been known to be insecure forever, disabling SSL3 is in response + * to POODLE, and disabling compression is in response to CRIME. */ if (exit_error == 0){ - SSL_CTX_set_options(ssl_context, SSL_OP_NO_SSLv2|SSL_OP_NO_COMPRESSION); + SSL_CTX_set_options(ssl_context, + SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_COMPRESSION); } /*Set directory to load certificates from*/ -- cgit v1.2.3 From 24cff71d47c8b5cd15129a53295a4a27b93f89c0 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Tue, 26 May 2015 11:29:21 -0300 Subject: Fix view-source dpi to handle null characters correctly Although not allowed in text contexts, null characters should not stop/halt/fail dpi protocol, thus the patch. Test Example. Display a file with these contents: null padding^@^@ (two trailing null characters) and view source for it. Note that dillo will not _display_ the file completely correct, it will eat a char after each null, but this is not a problem in dpi nor dpip but in rendering, the cache gets it right. Adding code to correctly _display_ these anomalous pages is probably not worth the effort though. --- doc/Dpid.txt | 5 +++-- dpi/vsource.c | 56 +++++++++++++++++++++++++++++++------------------------- dpip/dpip.c | 21 ++++++++++++++++++--- dpip/dpip.h | 1 + 4 files changed, 53 insertions(+), 30 deletions(-) (limited to 'dpi') diff --git a/doc/Dpid.txt b/doc/Dpid.txt index 82b81311..6c418f57 100644 --- a/doc/Dpid.txt +++ b/doc/Dpid.txt @@ -285,9 +285,10 @@ commented code in hello.c and start making changes! Debugging a dpi --------------- - The simplest way is to add printf() feedback using the MSG* + The simplest way is to add printf-like feedback using the MSG* macros. You can start the dpid by hand on a terminal to force -messages to go there. +messages to go there. Filter dpis use sdterr and server dpis +stdout. Sometimes more complex dpis need more than MSG*. In this case you can use gdb like this. diff --git a/dpi/vsource.c b/dpi/vsource.c index 2f1129cb..c28e7b49 100644 --- a/dpi/vsource.c +++ b/dpi/vsource.c @@ -3,7 +3,7 @@ * * This server is an example. Play with it and modify to your taste. * - * Copyright 2010 Jorge Arellano Cid + * Copyright 2010-2015 Jorge Arellano Cid * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ * Debugging macros */ #define _MSG(...) -#define MSG(...) printf("[vsource dpi]: " __VA_ARGS__) +#define MSG(...) fprintf(stderr, "[vsource dpi]: " __VA_ARGS__) /*---------------------------------------------------------------------------*/ @@ -42,38 +42,41 @@ void send_dpip_tag(Dsh *sh, char *dpip_tag) /* * Send source as plain text + * (handles embedded null chars correctly). */ void send_plain_text(Dsh *sh, int data_size) { - int bytes_read = 0; - char *src_str; + char *token; + int bytes_read = 0, token_size; /* Send HTTP header for plain text MIME type */ a_Dpip_dsh_write_str(sh, 0, "Content-type: text/plain\n\n"); while (bytes_read < data_size && - (src_str = a_Dpip_dsh_read_token(sh, 1))) { - bytes_read += strlen(src_str); - a_Dpip_dsh_write_str(sh, 1, src_str); - dFree(src_str); + (token = a_Dpip_dsh_read_token2(sh, 1, &token_size))) { + bytes_read += token_size; + _MSG("data_size=%d bytes_read=%d\n", data_size, bytes_read); + a_Dpip_dsh_write(sh, 1, token, token_size); + dFree(token); } } /* * Send source as plain text with line numbers + * (handles embedded null chars correctly). */ void send_numbered_text(Dsh *sh, int data_size) { - int bytes_read = 0, line = 1; - char *p, *q, *src_str, line_str[32]; + int bytes_read = 0, line = 1, token_size = 0; + char *p, *q, *token, line_str[32]; /* Send HTTP header for plain text MIME type */ a_Dpip_dsh_write_str(sh, 0, "Content-type: text/plain\n\n"); while (bytes_read < data_size && - (src_str = a_Dpip_dsh_read_token(sh, 1))) { - bytes_read += strlen(src_str); - p = q = src_str; + (token = a_Dpip_dsh_read_token2(sh, 1, &token_size))) { + bytes_read += token_size; + p = q = token; while (*p) { snprintf(line_str, 32, "%2d: ", line); @@ -84,28 +87,30 @@ void send_numbered_text(Dsh *sh, int data_size) ++p; ++line; } else { - a_Dpip_dsh_write_str(sh, 1, q); + /* send all the rest */ + a_Dpip_dsh_write(sh, 1, q, token_size - (q - token)); break; } q = ++p; } - dFree(src_str); + dFree(token); } } /* * Send source as html text with line numbers + * (handles embedded null chars correctly). */ void send_html_text(Dsh *sh, const char *url, int data_size) { - int bytes_read = 0, old_line = 0, line = 1; - char *p, *q, *src_str, line_str[128]; + int bytes_read = 0, old_line = 0, line = 1, token_size = 0; + char *p, *q, *token, line_str[128]; if (dStrnAsciiCasecmp(url, "dpi:", 4) == 0 && strncmp(url+4, "/vsource/:", 10) == 0) url += 14; - /* Send HTTP header for plain text MIME type */ + /* Send HTTP header for html text MIME type */ a_Dpip_dsh_write_str(sh, 0, "Content-type: text/html\n\n"); a_Dpip_dsh_write_str(sh, 0, DOCTYPE); @@ -119,9 +124,9 @@ void send_html_text(Dsh *sh, const char *url, int data_size) "\n\n", url); while (bytes_read < data_size && - (src_str = a_Dpip_dsh_read_token(sh, 1))) { - bytes_read += strlen(src_str); - p = q = src_str; + (token = a_Dpip_dsh_read_token2(sh, 1, &token_size))) { + bytes_read += token_size; + p = q = token; while (*p) { if (line > old_line) { @@ -143,13 +148,14 @@ void send_html_text(Dsh *sh, const char *url, int data_size) a_Dpip_dsh_write(sh, 0, q, p - q); a_Dpip_dsh_write_str(sh, 0, (*p == '<') ? "<" : "&"); } - } else { - a_Dpip_dsh_write_str(sh, 1, q); + } else { + /* send all the rest */ + a_Dpip_dsh_write(sh, 1, q, token_size - (q - token)); break; } q = ++p; } - dFree(src_str); + dFree(token); } if (data_size > 0) @@ -194,7 +200,7 @@ int main(void) * asking from us. a_Dpip_dsh_read_token() will block and return * a full dpip token or null on error (it's commented in dpip.c) */ dpip_tag = a_Dpip_dsh_read_token(sh, 1); - MSG("tag = [%s]\n", dpip_tag); + _MSG("tag = [%s]\n", dpip_tag); /* Now that we have the dpip_tag, let's isolate the command and url */ cmd = a_Dpip_get_attr(dpip_tag, "cmd"); diff --git a/dpip/dpip.c b/dpip/dpip.c index f4ce1bf0..2906ba2a 100644 --- a/dpip/dpip.c +++ b/dpip/dpip.c @@ -1,7 +1,7 @@ /* * File: dpip.c * - * Copyright 2005-2007 Jorge Arellano Cid + * Copyright 2005-2015 Jorge Arellano Cid * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -427,11 +427,13 @@ static void Dpip_dsh_read(Dsh *dsh, int blocking) /* * Return a newlly allocated string with the next dpip token in the socket. - * Return value: token string on success, NULL otherwise + * Return value: token string and length on success, NULL otherwise. + * (useful for handling null characters in the data stream) */ -char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) +char *a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize) { char *p, *ret = NULL; + *DataSize = 0; /* Read all available data without blocking */ Dpip_dsh_read(dsh, 0); @@ -462,6 +464,7 @@ char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) /* return a full tag */ if ((p = strstr(dsh->rdbuf->str, DPIP_TAG_END))) { ret = dStrndup(dsh->rdbuf->str, p - dsh->rdbuf->str + 3); + *DataSize = p - dsh->rdbuf->str + 3; dStr_erase(dsh->rdbuf, 0, p - dsh->rdbuf->str + 3); if (strstr(ret, DPIP_MODE_SWITCH_TAG)) dsh->mode |= DPIP_LAST_TAG; @@ -470,6 +473,7 @@ char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) /* raw mode, return what we have "as is" */ if (dsh->rdbuf->len > 0) { ret = dStrndup(dsh->rdbuf->str, dsh->rdbuf->len); + *DataSize = dsh->rdbuf->len; dStr_truncate(dsh->rdbuf, 0); } } @@ -477,6 +481,17 @@ char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) return ret; } +/* + * Return a newlly allocated string with the next dpip token in the socket. + * Return value: token string on success, NULL otherwise + */ +char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) +{ + int token_size; + + return a_Dpip_dsh_read_token2(dsh, blocking, &token_size); +} + /* * Close this socket for reading and writing. * (flush pending data) diff --git a/dpip/dpip.h b/dpip/dpip.h index 1a1846df..a63eb658 100644 --- a/dpip/dpip.h +++ b/dpip/dpip.h @@ -70,6 +70,7 @@ int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str); int a_Dpip_dsh_tryflush(Dsh *dsh); int a_Dpip_dsh_trywrite(Dsh *dsh, const char *Data, int DataSize); char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking); +char *a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize); void a_Dpip_dsh_close(Dsh *dsh); void a_Dpip_dsh_free(Dsh *dsh); -- cgit v1.2.3 From 468bea9977fabc5ca544bb3f668b74a97e20ae28 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Wed, 27 May 2015 11:07:04 -0300 Subject: Made view-source dpi use CSS formatting (it's shorter and cleaner) BTW, is there a point in using a monospaced font? Besides it looks like code printing (which is good), a proportional-spaced font may be easier to read. --- dpi/vsource.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'dpi') diff --git a/dpi/vsource.c b/dpi/vsource.c index c28e7b49..9d5694b5 100644 --- a/dpi/vsource.c +++ b/dpi/vsource.c @@ -118,7 +118,10 @@ void send_html_text(Dsh *sh, const char *url, int data_size) "\n" "\n" "Source for %s\n" - "\n" "\n" "\n
\n", url); @@ -131,10 +134,9 @@ void send_html_text(Dsh *sh, const char *url, int data_size) while (*p) { if (line > old_line) { snprintf(line_str, 128, - "%s
%d%s
",
-                     (line > 1) ? "
" : "", - (line & 1) ? "#B87333" : "#DD7F32", line, - (line == 1 || (line % 10) == 0) ? "  " : ""); + "
%d%s", + (line & 1) ? "r1" : "r2", line, + (line == 1 || (line % 10) == 0) ? " " : ""); a_Dpip_dsh_write_str(sh, 0, line_str); old_line = line; } @@ -158,8 +160,6 @@ void send_html_text(Dsh *sh, const char *url, int data_size) dFree(token); } - if (data_size > 0) - a_Dpip_dsh_write_str(sh, 0, ""); a_Dpip_dsh_write_str(sh, 1, "
"); } -- cgit v1.2.3 From 8395c48df79d75ec9a1961db88bbc8f3bbd530eb Mon Sep 17 00:00:00 2001 From: corvid Date: Wed, 10 Jun 2015 22:08:12 +0000 Subject: https rm RC4 from cipher list --- dpi/https.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'dpi') diff --git a/dpi/https.c b/dpi/https.c index da75b9e8..545d6a9b 100644 --- a/dpi/https.c +++ b/dpi/https.c @@ -193,9 +193,11 @@ static void yes_ssl_support(void) if (exit_error == 0){ /* Don't want: eNULL, which has no encryption; aNULL, which has no * authentication; LOW, which as of 2014 use 64 or 56-bit encryption; - * EXPORT40, which uses 40-bit encryption. + * EXPORT40, which uses 40-bit encryption; RC4, for which methods were + * found in 2013 to defeat it somewhat too easily. */ - SSL_CTX_set_cipher_list(ssl_context, "ALL:!aNULL:!eNULL:!LOW:!EXPORT40"); + SSL_CTX_set_cipher_list(ssl_context, + "ALL:!aNULL:!eNULL:!LOW:!EXPORT40:!RC4"); /* Need to do this if we want to have the option of dealing * with self-signed certs -- cgit v1.2.3 From 6339752fb3fa2790c293bce40282bcf21cdf1918 Mon Sep 17 00:00:00 2001 From: corvid Date: Wed, 22 Oct 2014 01:29:46 +0000 Subject: trim the publicsuffix TLDs yet again in January 2010, there were 42 entries. Now there are 22, and nearly all of them are rather...marginal. --- dpi/cookies.c | 7 +++---- src/url.c | 11 ++++------- test/cookies.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 19 deletions(-) (limited to 'dpi') diff --git a/dpi/cookies.c b/dpi/cookies.c index 6c5e958e..b858bd53 100644 --- a/dpi/cookies.c +++ b/dpi/cookies.c @@ -1042,14 +1042,13 @@ static uint_t Cookies_internal_dots_required(const char *host) if (tld_len > 0) { /* These TLDs were chosen by examining the current publicsuffix list - * in February 2014 and picking out those where it was simplest for + * in October 2014 and picking out those where it was simplest for * them to describe the situation by beginning with a "*.[tld]" rule * or every rule was "[something].[tld]". */ - const char *const tlds[] = {"bd","bn","ck","cy","er","et","fj","fk", + const char *const tlds[] = {"bd","bn","ck","cy","er","fj","fk", "gu","il","jm","ke","kh","kw","mm","mz", - "ni","np","nz","pg","tr","uk","ye","za", - "zm","zw"}; + "ni","np","pg","ye","za","zm","zw"}; uint_t i, tld_num = sizeof(tlds) / sizeof(tlds[0]); for (i = 0; i < tld_num; i++) { diff --git a/src/url.c b/src/url.c index 1c6b3b0f..a46e7f90 100644 --- a/src/url.c +++ b/src/url.c @@ -688,20 +688,17 @@ static uint_t Url_host_public_internal_dots(const char *host) if (tld_len > 0) { /* These TLDs were chosen by examining the current publicsuffix list - * in February 2014 and picking out those where it was simplest for + * in October 2014 and picking out those where it was simplest for * them to describe the situation by beginning with a "*.[tld]" rule * or every rule was "[something].[tld]". * * TODO: Consider the old publicsuffix code again. This TLD list has * shrunk and shrunk over the years, and has become a poorer and - * poorer approximation of administrative boundaries -- and, as of - * mid-2014, even NZ and UK are allowing domains to be registered - * at the second level, which doesn't leave much. + * poorer approximation of administrative boundaries. */ - const char *const tlds[] = {"bd","bn","ck","cy","er","et","fj","fk", + const char *const tlds[] = {"bd","bn","ck","cy","er","fj","fk", "gu","il","jm","ke","kh","kw","mm","mz", - "ni","np","nz","pg","tr","uk","ye","za", - "zm","zw"}; + "ni","np","pg","ye","za","zm","zw"}; uint_t i, tld_num = sizeof(tlds) / sizeof(tlds[0]); for (i = 0; i < tld_num; i++) { diff --git a/test/cookies.c b/test/cookies.c index 40661650..ff744c97 100644 --- a/test/cookies.c +++ b/test/cookies.c @@ -880,17 +880,17 @@ int main() path(); /* LEADING/TRAILING DOTS AND A LITTLE PUBLIC SUFFIX */ - a_Cookies_set("name=val; domain=co.uk", "www.co.uk", "/", NULL); - expect(__LINE__, "", "http", "www.co.uk", "/"); + a_Cookies_set("name=val; domain=co.il", "www.co.il", "/", NULL); + expect(__LINE__, "", "http", "www.co.il", "/"); - a_Cookies_set("name=val; domain=.co.uk", "www.co.uk", "/", NULL); - expect(__LINE__, "", "http", "www.co.uk", "/"); + a_Cookies_set("name=val; domain=.co.il", "www.co.il", "/", NULL); + expect(__LINE__, "", "http", "www.co.il", "/"); - a_Cookies_set("name=val; domain=co.uk.", "www.co.uk.", "/", NULL); - expect(__LINE__, "", "http", "www.co.uk.", "/"); + a_Cookies_set("name=val; domain=co.il.", "www.co.il.", "/", NULL); + expect(__LINE__, "", "http", "www.co.il.", "/"); - a_Cookies_set("name=val; domain=.co.uk.", "www.co.uk.", "/", NULL); - expect(__LINE__, "", "http", ".www.co.uk.", "/"); + a_Cookies_set("name=val; domain=.co.il.", "www.co.il.", "/", NULL); + expect(__LINE__, "", "http", ".www.co.il.", "/"); a_Cookies_set("name=val; domain=co.org", "www.co.org", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "www.co.org", "/"); -- cgit v1.2.3 From c1b4f7f51ab8a9190bcaabc13015ffeff292a4a1 Mon Sep 17 00:00:00 2001 From: corvid Date: Wed, 30 Jul 2014 02:46:27 +0000 Subject: KB --- dpi/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dpi') diff --git a/dpi/file.c b/dpi/file.c index 5f1459ad..00e10468 100644 --- a/dpi/file.c +++ b/dpi/file.c @@ -346,10 +346,10 @@ static void File_info2html(ClientInfo *client, FileInfo *finfo, int n) sizeunits = "bytes"; } else if (finfo->size / 1024 <= 9999) { size = finfo->size / 1024 + (finfo->size % 1024 >= 1024 / 2); - sizeunits = "Kb"; + sizeunits = "KB"; } else { size = finfo->size / 1048576 + (finfo->size % 1048576 >= 1048576 / 2); - sizeunits = "Mb"; + sizeunits = "MB"; } /* we could note if it's a symlink... */ -- cgit v1.2.3 From 78659997b1836892163e7df2338846cb8879cf5b Mon Sep 17 00:00:00 2001 From: corvid Date: Mon, 15 Jun 2015 18:07:15 +0000 Subject: handle openssl derivatives in the license permissions for the https dpi FWIW, wget currently does it as follows: "If you modify this program, or any covered work, by linking or combining it with the OpenSSL project's OpenSSL library (or a modified version of that library), containing parts covered by the terms of the OpenSSL or SSLeay licenses, the Free Software Foundation grants you additional permission to convey the resulting work. Corresponding Source for a non-source form of such a combination shall include the source code for the parts of OpenSSL used as well as that of the covered work." --- dpi/https.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'dpi') diff --git a/dpi/https.c b/dpi/https.c index 545d6a9b..766b3afb 100644 --- a/dpi/https.c +++ b/dpi/https.c @@ -22,11 +22,12 @@ * (at your option) any later version. * * As a special exception permission is granted to link the code of - * the https dillo plugin with the OpenSSL project's "OpenSSL" - * library, and distribute the linked executables, without including - * the source code for OpenSSL in the source distribution. You must - * obey the GNU General Public License, version 3, in all respects - * for all of the code used other than "OpenSSL". + * the https dillo plugin with the OpenSSL project's OpenSSL library + * (or a modified version of that library), and distribute the linked + * executables, without including the source code for the SSL library + * in the source distribution. You must obey the GNU General Public + * License, version 3, in all respects for all of the code used other + * than the SSL library. * */ -- cgit v1.2.3