Skip to content

Commit

Permalink
HZ13: Add support for user-configurable SSL error response code
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterZ committed Oct 7, 2015
1 parent 294cfc5 commit e09fef5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ Sources
* https://github.com/flexiondotorg/nullserv (defunct)
* http://www.linksysinfo.org/index.php?threads/pixelserv-compiled-to-run-on-router-wrt54g.30509/page-3#post-229342
* http://www.dd-wrt.com/phpBB2/viewtopic.php?p=685201
* https://en.wikipedia.org/wiki/Transport_Layer_Security#Alert_protocol
6 changes: 6 additions & 0 deletions pixelserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ int main (int argc, char* argv[]) // program start
#ifdef DEBUG
int warning_time = 0;
#endif //DEBUG
char ssl_alert = DEFAULT_SSL_ALERT;

SET_LINE_NUMBER(__LINE__);

Expand All @@ -139,6 +140,9 @@ int main (int argc, char* argv[]) // program start
if ((i + 1) < argc) {
// switch on parameter letter and process subsequent argument
switch (argv[i++][1]) {
case 'c':
ssl_alert = (char)strtol(argv[i], NULL, 10);
continue;
#ifdef IF_MODE
case 'n':
ifname = argv[i];
Expand Down Expand Up @@ -192,6 +196,7 @@ int main (int argc, char* argv[]) // program start
printf("Usage:%s"
" [IP No/hostname (all)]"
" [-2 (disables HTTP 204 reply to generate_204 URLs)]"
" [-c ssl_alert_code (49 - access denied)]"
#ifndef TEST
" [-f (stay in foreground - don't daemonize)]"
#endif // !TEST
Expand Down Expand Up @@ -565,6 +570,7 @@ int main (int argc, char* argv[]) // program start
,argv[0]
,do_204
,do_redirect
,ssl_alert
#ifdef DEBUG
,warning_time
#endif //DEBUG
Expand Down
16 changes: 9 additions & 7 deletions socket_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,6 @@ static const char httpnull_ico[] =
"\x00\x00\x00\x00" // XOR B G R
"\x80\xF8\x9C\x41"; // AND ?

static const char SSL_no[] =
"\x15" // Alert (21)
"\x03\x00" // Version 3.0
"\x00\x02" // length 2
"\x02" // fatal
"\x31"; // 0 close notify, 0x28 Handshake failure 40, 0x31 TLS access denied 49

// private functions for socket_handler() use
#ifdef HEX_DUMP
// from http://sws.dett.de/mini/hexdump-c/
Expand Down Expand Up @@ -395,6 +388,7 @@ void socket_handler(int argc
,const char* const program_name
,const int do_204
,const int do_redirect
,const char ssl_alert
#ifdef DEBUG
,const int warning_time
#endif //DEBUG
Expand All @@ -414,6 +408,14 @@ void socket_handler(int argc
char* version_string = NULL;
char* stat_string = NULL;
struct timespec start_time = {0, 0};
const char SSL_no[] = {
'\x15' // Alert (21)
,'\x03','\x00' // Version 3.0
,'\x00','\x02' // length 02
,'\x02' // fatal
,ssl_alert // 0 close notify, 0x28 Handshake failure 40, 0x31 TLS access denied 49
,'\x00' // string terminator (not part of actual response)
};
#ifdef DEBUG
double time_msec = 0.0;
int do_warning = (warning_time > 0);
Expand Down
1 change: 1 addition & 0 deletions socket_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void socket_handler(int argc
,const char* const program_name
,const int do_204
,const int do_redirect
,const char ssl_alert
#ifdef DEBUG
,const int warning_time
#endif //DEBUG
Expand Down
4 changes: 3 additions & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <time.h> // struct timespec, clock_gettime(), difftime()

// preprocessor defines
#define VERSION "V35.HZ12"
#define VERSION "V35.HZ13"

#define BACKLOG SOMAXCONN // how many pending connections queue will hold
#define CHAR_BUF_SIZE 4095 // surprising how big requests can be with cookies and lengthy yahoo url!
Expand Down Expand Up @@ -63,6 +63,8 @@ static unsigned long LINE_NUMBER = __LINE__;
# define SET_LINE_NUMBER(x)
#endif //DEBUG

#define DEFAULT_SSL_ALERT (char)49

// cross-thread count variables
extern volatile sig_atomic_t count; // req
extern volatile sig_atomic_t avg; // cumulative moving average request size
Expand Down

0 comments on commit e09fef5

Please sign in to comment.