Skip to content

Commit bc80f0b

Browse files
Add Server Name Identification to ALTCP TLS
This is a known missing feature; * [lwip-tcpip#47][gh-lwip-pr] * [lwip-tcpip/lwip@c53c9d020][gh-lwip-commit] Added here again for compatibility with [pico-sdk][gh-pico] v1.5.x. See discussion in [marceloalcocer/picohttps#1][gh-issue] for more details. [gh-lwip-pr]: lwip-tcpip#47 [gh-lwip-commit] lwip-tcpip@c53c9d0 [gh-pico]: https://github.com/raspberrypi/pico-sdk [gh-issue]: marceloalcocer/picohttps#1 (comment)
1 parent 239918c commit bc80f0b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/apps/altcp_tls/altcp_tls_mbedtls.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct altcp_tls_config {
107107
u8_t pkey_count;
108108
u8_t pkey_max;
109109
mbedtls_x509_crt *ca;
110+
char host[256];
110111
#if defined(MBEDTLS_SSL_CACHE_C) && ALTCP_MBEDTLS_USE_SESSION_CACHE
111112
/** Inter-connection cache for fast connection startup */
112113
struct mbedtls_ssl_cache_context cache;
@@ -633,6 +634,7 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
633634
/* tell mbedtls about our I/O functions */
634635
mbedtls_ssl_set_bio(&state->ssl_context, conn, altcp_mbedtls_bio_send, altcp_mbedtls_bio_recv, NULL);
635636

637+
mbedtls_ssl_set_hostname(&state->ssl_context, config->host);
636638
altcp_mbedtls_setup_callbacks(conn, inner_conn);
637639
conn->inner_conn = inner_conn;
638640
conn->fns = &altcp_mbedtls_functions;
@@ -942,7 +944,7 @@ altcp_tls_create_config_server_privkey_cert(const u8_t *privkey, size_t privkey_
942944
}
943945

944946
static struct altcp_tls_config *
945-
altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2wayauth)
947+
altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2wayauth, char* host)
946948
{
947949
int ret;
948950
struct altcp_tls_config *conf = altcp_tls_create_config(0, (is_2wayauth) ? 1 : 0, (is_2wayauth) ? 1 : 0, ca != NULL);
@@ -964,13 +966,14 @@ altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2way
964966

965967
mbedtls_ssl_conf_ca_chain(&conf->conf, conf->ca, NULL);
966968
}
969+
memcpy(conf->host, host, sizeof(conf->host));
967970
return conf;
968971
}
969972

970973
struct altcp_tls_config *
971-
altcp_tls_create_config_client(const u8_t *ca, size_t ca_len)
974+
altcp_tls_create_config_client(const u8_t *ca, size_t ca_len, char* host)
972975
{
973-
return altcp_tls_create_config_client_common(ca, ca_len, 0);
976+
return altcp_tls_create_config_client_common(ca, ca_len, 0, host);
974977
}
975978

976979
struct altcp_tls_config *
@@ -986,7 +989,7 @@ altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_
986989
return NULL;
987990
}
988991

989-
conf = altcp_tls_create_config_client_common(ca, ca_len, 1);
992+
conf = altcp_tls_create_config_client_common(ca, ca_len, 1, NULL);
990993
if (conf == NULL) {
991994
return NULL;
992995
}

src/include/lwip/altcp_tls.h

Lines changed: 1 addition & 1 deletion
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)