Skip to content

Commit f3d43cc

Browse files
committed
Add SSLUseSNI support
* The TLS extension - SNI (Server Name Indication) is required for the auth server that hosted multiple secure (HTTPS) websites. see: https://en.wikipedia.org/wiki/Server_Name_Indication The SSLUseSNI field was added to the configuration file as an optional, default is "no" SNI setup.
1 parent dbac483 commit f3d43cc

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/conf.c

Lines changed: 14 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,17 @@ 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!");
792806
#endif
793807
break;
794808
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: 16 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,19 @@ get_cyassl_ctx(void)
179179
}
180180
}
181181

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

236-
ctx = get_cyassl_ctx();
249+
ctx = get_cyassl_ctx(hostname);
237250
if (NULL == ctx) {
238251
debug(LOG_ERR, "Could not get CyaSSL Context!");
239252
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)