Skip to content

Commit

Permalink
code cleanup and adaptation of regex probe
Browse files Browse the repository at this point in the history
  • Loading branch information
yrutschle committed Dec 4, 2018
1 parent d3d4fd6 commit 33ab9d5
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 425 deletions.
2 changes: 1 addition & 1 deletion common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/*
* Settings that depend on the command line or the config file
*/
struct config_item cfg;
struct sslhcfg_item cfg;

struct addrinfo *addr_listen = NULL; /* what addresses do we listen to? */

Expand Down
4 changes: 2 additions & 2 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct queue {
struct connection {
enum connection_state state;
time_t probe_timeout;
struct config_protocols_item* proto;
struct sslhcfg_protocols_item* proto;

/* q[0]: queue for external connection (client);
* q[1]: queue for internal connection (httpd or sshd);
Expand Down Expand Up @@ -123,7 +123,7 @@ int flush_deferred(struct queue *q);

extern int probing_timeout, verbose, inetd, foreground,
background, transparent, numeric;
extern struct config_item cfg;
extern struct sslhcfg_item cfg;
extern struct sockaddr_storage addr_ssl, addr_ssh, addr_openvpn;
extern struct addrinfo *addr_listen;
extern const char* USAGE_STRING;
Expand Down
48 changes: 24 additions & 24 deletions probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@



static int is_ssh_protocol(const char *p, int len, struct config_protocols_item*);
static int is_openvpn_protocol(const char *p, int len, struct config_protocols_item*);
static int is_tinc_protocol(const char *p, int len, struct config_protocols_item*);
static int is_xmpp_protocol(const char *p, int len, struct config_protocols_item*);
static int is_http_protocol(const char *p, int len, struct config_protocols_item*);
static int is_tls_protocol(const char *p, int len, struct config_protocols_item*);
static int is_adb_protocol(const char *p, int len, struct config_protocols_item*);
static int is_socks5_protocol(const char *p, int len, struct config_protocols_item*);
static int is_true(const char *p, int len, struct config_protocols_item* proto) { return 1; }
static int is_ssh_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_openvpn_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_tinc_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_xmpp_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_http_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_tls_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_adb_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_socks5_protocol(const char *p, int len, struct sslhcfg_protocols_item*);
static int is_true(const char *p, int len, struct sslhcfg_protocols_item* proto) { return 1; }

struct protocol_probe_desc {
const char* name;
Expand All @@ -64,11 +64,11 @@ static struct protocol_probe_desc builtins[] = {
{ "anyprot", is_true }
};

static struct config_protocols_item *protocols;
static struct sslhcfg_protocols_item *protocols;
static char* on_timeout = "ssh";

/* TODO I think this has to go */
struct config_protocols_item* get_builtins(void) {
struct sslhcfg_protocols_item* get_builtins(void) {
return NULL;
}

Expand All @@ -86,7 +86,7 @@ void set_ontimeout(const char* name)
/* Returns the protocol to connect to in case of timeout;
* if not found, return the first protocol specified
*/
struct config_protocols_item* timeout_protocol(void)
struct sslhcfg_protocols_item* timeout_protocol(void)
{
int i;
for (i = 0; i < cfg.protocols_len; i++) {
Expand All @@ -97,12 +97,12 @@ struct config_protocols_item* timeout_protocol(void)
}

/* returns the first protocol (caller can then follow the *next pointers) */
struct config_protocols_item* get_first_protocol(void)
struct sslhcfg_protocols_item* get_first_protocol(void)
{
return protocols;
}

void set_protocol_list(struct config_protocols_item* prots)
void set_protocol_list(struct sslhcfg_protocols_item* prots)
{
#if 0
protocols = prots;
Expand Down Expand Up @@ -143,7 +143,7 @@ void hexdump(const char *mem, unsigned int len)
}

/* Is the buffer the beginning of an SSH connection? */
static int is_ssh_protocol(const char *p, int len, struct config_protocols_item* proto)
static int is_ssh_protocol(const char *p, int len, struct sslhcfg_protocols_item* proto)
{
if (len < 4)
return PROBE_AGAIN;
Expand All @@ -161,7 +161,7 @@ static int is_ssh_protocol(const char *p, int len, struct config_protocols_item*
* http://www.fengnet.com/book/vpns%20illustrated%20tunnels%20%20vpnsand%20ipsec/ch08lev1sec5.html
* and OpenVPN ssl.c, ssl.h and options.c
*/
static int is_openvpn_protocol (const char*p,int len, struct config_protocols_item* proto)
static int is_openvpn_protocol (const char*p,int len, struct sslhcfg_protocols_item* proto)
{
int packet_len;

Expand All @@ -176,7 +176,7 @@ static int is_openvpn_protocol (const char*p,int len, struct config_protocols_it
* Protocol is documented here: http://www.tinc-vpn.org/documentation/tinc.pdf
* First connection starts with "0 " in 1.0.15)
* */
static int is_tinc_protocol( const char *p, int len, struct config_protocols_item* proto)
static int is_tinc_protocol( const char *p, int len, struct sslhcfg_protocols_item* proto)
{
if (len < 2)
return PROBE_AGAIN;
Expand All @@ -188,7 +188,7 @@ static int is_tinc_protocol( const char *p, int len, struct config_protocols_ite
* (Protocol is documented (http://tools.ietf.org/html/rfc6120) but for lazy
* clients, just checking first frame containing "jabber" in xml entity)
* */
static int is_xmpp_protocol( const char *p, int len, struct config_protocols_item* proto)
static int is_xmpp_protocol( const char *p, int len, struct sslhcfg_protocols_item* proto)
{
if (memmem(p, len, "jabber", 6))
return PROBE_MATCH;
Expand All @@ -211,7 +211,7 @@ static int probe_http_method(const char *p, int len, const char *opt)
}

/* Is the buffer the beginning of an HTTP connection? */
static int is_http_protocol(const char *p, int len, struct config_protocols_item* proto)
static int is_http_protocol(const char *p, int len, struct sslhcfg_protocols_item* proto)
{
int res;
/* If it's got HTTP in the request (HTTP/1.1) then it's HTTP */
Expand All @@ -237,7 +237,7 @@ static int is_http_protocol(const char *p, int len, struct config_protocols_item
}

/* Says if it's TLS, optionally with SNI and ALPN lists in proto->data */
static int is_tls_protocol(const char *p, int len, struct config_protocols_item* proto)
static int is_tls_protocol(const char *p, int len, struct sslhcfg_protocols_item* proto)
{
switch (parse_tls_header(proto->data, p, len)) {
case TLS_MATCH: return PROBE_MATCH;
Expand All @@ -257,7 +257,7 @@ static int probe_adb_cnxn_message(const char *p)
return !memcmp(&p[0], "CNXN", 4) && !memcmp(&p[24], "host:", 5);
}

static int is_adb_protocol(const char *p, int len, struct config_protocols_item* proto)
static int is_adb_protocol(const char *p, int len, struct sslhcfg_protocols_item* proto)
{
/* amessage.data_length is not being checked, under the assumption that
* a packet >= 30 bytes will have "something" in the payload field.
Expand Down Expand Up @@ -296,7 +296,7 @@ static int is_adb_protocol(const char *p, int len, struct config_protocols_item*
return probe_adb_cnxn_message(&p[sizeof(empty_message)]);
}

static int is_socks5_protocol(const char *p_in, int len, struct config_protocols_item* proto)
static int is_socks5_protocol(const char *p_in, int len, struct sslhcfg_protocols_item* proto)
{
unsigned char* p = (unsigned char*)p_in;
int i;
Expand Down Expand Up @@ -329,7 +329,7 @@ static int is_socks5_protocol(const char *p_in, int len, struct config_protocols
return PROBE_MATCH;
}

static int regex_probe(const char *p, int len, struct config_protocols_item* proto)
static int regex_probe(const char *p, int len, struct sslhcfg_protocols_item* proto)
{
#ifdef ENABLE_REGEX
regex_t **probe = proto->data;
Expand All @@ -355,7 +355,7 @@ static int regex_probe(const char *p, int len, struct config_protocols_item* pro
int probe_client_protocol(struct connection *cnx)
{
char buffer[BUFSIZ];
struct config_protocols_item* p, *last_p = cnx->proto;
struct sslhcfg_protocols_item* p, *last_p = cnx->proto;
int i, n, res, again = 0;

n = read(cnx->q[0].fd, buffer, sizeof(buffer));
Expand Down
12 changes: 6 additions & 6 deletions probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ typedef enum {
PROBE_AGAIN, /* Not enough data for this probe, try again with more data */
} probe_result;

struct config_protocols_item;
typedef int T_PROBE(const char*, int, struct config_protocols_item*);
struct sslhcfg_protocols_item;
typedef int T_PROBE(const char*, int, struct sslhcfg_protocols_item*);

#include "sslh-conf.h"

Expand All @@ -39,7 +39,7 @@ struct proto {
#endif

/* Returns a pointer to the array of builtin protocols */
struct config_protocols_item* get_builtins(void);
struct sslhcfg_protocols_item* get_builtins(void);

/* Returns the number of builtin protocols */
int get_num_builtins(void);
Expand All @@ -48,10 +48,10 @@ int get_num_builtins(void);
T_PROBE* get_probe(const char* description);

/* Returns the head of the configured protocols */
struct config_protocols_item* get_first_protocol(void);
struct sslhcfg_protocols_item* get_first_protocol(void);

/* Set the list of configured protocols */
void set_protocol_list(struct config_protocols_item*);
void set_protocol_list(struct sslhcfg_protocols_item*);

/* probe_client_protocol
*
Expand All @@ -69,7 +69,7 @@ void set_ontimeout(const char* name);
*
* Returns the protocol to connect to in case of timeout
*/
struct config_protocols_item* timeout_protocol(void);
struct sslhcfg_protocols_item* timeout_protocol(void);

void hexdump(const char*, unsigned int);

Expand Down
Loading

0 comments on commit 33ab9d5

Please sign in to comment.