Skip to content

Commit 1f444e9

Browse files
jetmtrini
authored andcommitted
net: lwip: Add Support Server Name Indication support
SNI, or Server Name Indication, is an addition to the TLS encryption protocol that enables a client device to specify the domain name it is trying to reach in the first step of the TLS handshake, preventing common name mismatch errors and not reaching to HTTPS server that enforce this condition. Since most of the websites require it nowadays add support for it. It's worth noting that this is already sent to lwIP [0] [0] lwip-tcpip/lwip#47 Signed-off-by: Javier Tia <[email protected]> Reviewed-by: Jerome Forissier <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
1 parent 514f18f commit 1f444e9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Application layered TCP/TLS connection API (to be used from TCPIP thread)
44
*
55
* This file provides a TLS layer using mbedTLS
6-
*
6+
*
77
* This version is currently compatible with the 2.x.x branch (current LTS).
88
*/
99

@@ -106,6 +106,7 @@ struct altcp_tls_config {
106106
u8_t pkey_count;
107107
u8_t pkey_max;
108108
mbedtls_x509_crt *ca;
109+
char host[256];
109110
#if defined(MBEDTLS_SSL_CACHE_C) && ALTCP_MBEDTLS_USE_SESSION_CACHE
110111
/** Inter-connection cache for fast connection startup */
111112
struct mbedtls_ssl_cache_context cache;
@@ -642,6 +643,7 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
642643
/* tell mbedtls about our I/O functions */
643644
mbedtls_ssl_set_bio(&state->ssl_context, conn, altcp_mbedtls_bio_send, altcp_mbedtls_bio_recv, NULL);
644645

646+
mbedtls_ssl_set_hostname(&state->ssl_context, config->host);
645647
altcp_mbedtls_setup_callbacks(conn, inner_conn);
646648
conn->inner_conn = inner_conn;
647649
conn->fns = &altcp_mbedtls_functions;
@@ -951,7 +953,7 @@ altcp_tls_create_config_server_privkey_cert(const u8_t *privkey, size_t privkey_
951953
}
952954

953955
static struct altcp_tls_config *
954-
altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2wayauth)
956+
altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2wayauth, char *host)
955957
{
956958
int ret;
957959
struct altcp_tls_config *conf = altcp_tls_create_config(0, (is_2wayauth) ? 1 : 0, (is_2wayauth) ? 1 : 0, ca != NULL);
@@ -973,13 +975,15 @@ altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2way
973975

974976
mbedtls_ssl_conf_ca_chain(&conf->conf, conf->ca, NULL);
975977
}
978+
strlcpy(conf->host, host, sizeof(conf->host));
979+
976980
return conf;
977981
}
978982

979983
struct altcp_tls_config *
980-
altcp_tls_create_config_client(const u8_t *ca, size_t ca_len)
984+
altcp_tls_create_config_client(const u8_t *ca, size_t ca_len, char *host)
981985
{
982-
return altcp_tls_create_config_client_common(ca, ca_len, 0);
986+
return altcp_tls_create_config_client_common(ca, ca_len, 0, host);
983987
}
984988

985989
struct altcp_tls_config *
@@ -995,7 +999,7 @@ altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_
995999
return NULL;
9961000
}
9971001

998-
conf = altcp_tls_create_config_client_common(ca, ca_len, 1);
1002+
conf = altcp_tls_create_config_client_common(ca, ca_len, 1, NULL);
9991003
if (conf == NULL) {
10001004
return NULL;
10011005
}

lib/lwip/lwip/src/core/tcp_out.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno,
20282028
u16_t local_port, u16_t remote_port)
20292029
{
20302030
struct pbuf *p;
2031-
2031+
20322032
p = tcp_rst_common(pcb, seqno, ackno, local_ip, remote_ip, local_port, remote_port);
20332033
if (p != NULL) {
20342034
tcp_output_control_segment(pcb, p, local_ip, remote_ip);

lib/lwip/lwip/src/include/lwip/altcp_tls.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct altcp_tls_config *altcp_tls_create_config_server_privkey_cert(const u8_t
9292
/** @ingroup altcp_tls
9393
* Create an ALTCP_TLS client configuration handle
9494
*/
95-
struct altcp_tls_config *altcp_tls_create_config_client(const u8_t *cert, size_t cert_len);
95+
struct altcp_tls_config *altcp_tls_create_config_client(const u8_t *cert, size_t cert_len, char *host);
9696

9797
/** @ingroup altcp_tls
9898
* Create an ALTCP_TLS client configuration handle with two-way server/client authentication

0 commit comments

Comments
 (0)