Skip to content

Commit e87dfe3

Browse files
committed
Merge pull request #226 from neutronth/devel-ssl-use-sni
Add SSLUseSNI support
2 parents dbac483 + 06538e7 commit e87dfe3

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

configure.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ if test "x$enable_cyassl" = xyes; then
9494
AC_SEARCH_LIBS([CyaSSLv23_client_method], [cyassl wolfssl], [], [
9595
AC_MSG_ERROR([unable to find the CyaSSLv23_client_method function.])
9696
])
97+
98+
AC_MSG_CHECKING([for the CyaSSL SNI enabled])
99+
AC_LINK_IFELSE([AC_LANG_PROGRAM(
100+
[[
101+
#define HAVE_SNI
102+
#include <cyassl/ssl.h>
103+
]], [[
104+
CYASSL_CTX *ctx;
105+
CyaSSL_Init();
106+
ctx = CyaSSL_CTX_new(CyaTLSv1_client_method());
107+
CyaSSL_CTX_UseSNI(ctx, CYASSL_SNI_HOST_NAME, "wifidog.org", 11);
108+
]])], [enabled_sni=yes], [enabled_sni=no])
109+
110+
if test "x$enabled_sni" = xyes; then
111+
AC_MSG_RESULT([yes])
112+
AC_DEFINE([HAVE_SNI],, "Compile with CyaSSL SNI support")
113+
else
114+
AC_MSG_RESULT([no])
115+
fi
116+
97117
AC_DEFINE(USE_CYASSL,, "Compile with CyaSSL support")
98118
fi
99119
])

src/conf.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ typedef enum {
103103
oSSLPeerVerification,
104104
oSSLCertPath,
105105
oSSLAllowedCipherList,
106+
oSSLUseSNI,
106107
} OpCodes;
107108

108109
/** @internal
@@ -149,6 +150,7 @@ static const struct {
149150
"sslpeerverification", oSSLPeerVerification}, {
150151
"sslcertpath", oSSLCertPath}, {
151152
"sslallowedcipherlist", oSSLAllowedCipherList}, {
153+
"sslusesni", oSSLUseSNI}, {
152154
NULL, oBadOption},};
153155

154156
static void config_notnull(const void *, const char *);
@@ -204,6 +206,7 @@ config_init(void)
204206
config.deltatraffic = DEFAULT_DELTATRAFFIC;
205207
config.ssl_cipher_list = NULL;
206208
config.arp_table_path = safe_strdup(DEFAULT_ARPTABLE);
209+
config.ssl_use_sni = DEFAULT_AUTHSERVSSLSNI;
207210

208211
debugconf.log_stderr = 1;
209212
debugconf.debuglevel = DEFAULT_DEBUGLEVEL;
@@ -789,6 +792,21 @@ config_read(const char *filename)
789792
config.ssl_cipher_list = safe_strdup(p1);
790793
#ifndef USE_CYASSL
791794
debug(LOG_WARNING, "SSLAllowedCipherList is set but no SSL compiled in. Ignoring!");
795+
#endif
796+
break;
797+
case oSSLUseSNI:
798+
config.ssl_use_sni = parse_boolean_value(p1);
799+
if (config.ssl_use_sni < 0) {
800+
debug(LOG_WARNING, "Bad syntax for Parameter: SSLUseSNI on line %d " "in %s."
801+
"The syntax is yes or no." , linenum, filename);
802+
exit(-1);
803+
}
804+
#ifndef USE_CYASSL
805+
debug(LOG_WARNING, "SSLUseSNI is set but no SSL compiled in. Ignoring!");
806+
#else
807+
#ifndef HAVE_SNI
808+
debug(LOG_WARNING, "SSLUseSNI is set but no CyaSSL SNI enabled. Ignoring!");
809+
#endif
792810
#endif
793811
break;
794812
case oBadOption:

src/conf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#define DEFAULT_AUTHSERVSSLPEERVER 1 /* 0 means: Enable peer verification */
6868
#define DEFAULT_DELTATRAFFIC 0 /* 0 means: Enable peer verification */
6969
#define DEFAULT_ARPTABLE "/proc/net/arp"
70+
#define DEFAULT_AUTHSERVSSLSNI 0 /* 0 means: Disable SNI */
7071
/*@}*/
7172

7273
/*@{*/
@@ -189,6 +190,8 @@ typedef struct {
189190
int ssl_verify; /**< @brief boolean, whether to enable
190191
auth server certificate verification */
191192
char *ssl_cipher_list; /**< @brief List of SSL ciphers allowed. Optional. */
193+
int ssl_use_sni; /**< @brief boolean, whether to enable
194+
auth server for server name indication, the TLS extension */
192195
t_firewall_ruleset *rulesets; /**< @brief firewall rules */
193196
t_trusted_mac *trustedmaclist; /**< @brief list of trusted macs */
194197
char *arp_table_path; /**< @brief Path to custom ARP table, formatted

src/simple_http.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#endif
4747

4848
#ifdef USE_CYASSL
49-
static CYASSL_CTX *get_cyassl_ctx(void);
49+
static CYASSL_CTX *get_cyassl_ctx(const char *hostname);
5050
#endif
5151

5252
/**
@@ -151,7 +151,7 @@ static pthread_mutex_t cyassl_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
151151
} while (0)
152152

153153
static CYASSL_CTX *
154-
get_cyassl_ctx(void)
154+
get_cyassl_ctx(const char *hostname)
155155
{
156156
int err;
157157
CYASSL_CTX *ret;
@@ -179,6 +179,21 @@ get_cyassl_ctx(void)
179179
}
180180
}
181181

182+
#ifdef HAVE_SNI
183+
if (config->ssl_use_sni) {
184+
debug(LOG_INFO, "Setting SSL using SNI for hostname %s",
185+
hostname);
186+
err = CyaSSL_CTX_UseSNI(cyassl_ctx, CYASSL_SNI_HOST_NAME, hostname,
187+
strlen(hostname));
188+
if (SSL_SUCCESS != err) {
189+
debug(LOG_ERR, "Could not setup SSL using SNI for hostname %s",
190+
hostname);
191+
UNLOCK_CYASSL_CTX();
192+
return NULL;
193+
}
194+
}
195+
#endif
196+
182197
if (config->ssl_verify) {
183198
/* Use trusted certs */
184199
/* Note: CyaSSL requires that the certificates are named by their hash values */
@@ -233,7 +248,7 @@ https_get(const int sockfd, const char *req, const char *hostname)
233248
s_config *config;
234249
config = config_get_config();
235250

236-
ctx = get_cyassl_ctx();
251+
ctx = get_cyassl_ctx(hostname);
237252
if (NULL == ctx) {
238253
debug(LOG_ERR, "Could not get CyaSSL Context!");
239254
goto error;

wifidog.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@ ClientTimeout 5
225225
#
226226
# SSLAllowedCipherList ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA256:ECDH-RSA-AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA:ECDH-RSA-AES128-SHA:ECDH-RSA-AES256-SHA:AES128-SHA:AES256-SHA
227227

228+
# Parameter: SSLUseSNI
229+
# Default: no
230+
# Optional
231+
#
232+
# Enable SNI (Server Name Indication) TLS extension.
233+
# Enabling this setting is mainly useful if the auth server is hosted
234+
# multiple secure (HTTPS) websites. The WifiDog should indicate which hostname
235+
# it is attempting to connect to at the start of the handshaking process.
236+
#
237+
# This setting requires that WifiDog is compiled with SSL support.
238+
# It will be ignored otherwise.
239+
#
240+
# SSLUseSNI no
241+
228242
# Parameter: TrustedMACList
229243
# Default: none
230244
# Optional

0 commit comments

Comments
 (0)