Skip to content

Commit

Permalink
Add Server Name Identification to ALTCP TLS
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
marceloalcocer committed Nov 20, 2024
1 parent 239918c commit bc80f0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/apps/altcp_tls/altcp_tls_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct altcp_tls_config {
u8_t pkey_count;
u8_t pkey_max;
mbedtls_x509_crt *ca;
char host[256];
#if defined(MBEDTLS_SSL_CACHE_C) && ALTCP_MBEDTLS_USE_SESSION_CACHE
/** Inter-connection cache for fast connection startup */
struct mbedtls_ssl_cache_context cache;
Expand Down Expand Up @@ -633,6 +634,7 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
/* tell mbedtls about our I/O functions */
mbedtls_ssl_set_bio(&state->ssl_context, conn, altcp_mbedtls_bio_send, altcp_mbedtls_bio_recv, NULL);

mbedtls_ssl_set_hostname(&state->ssl_context, config->host);
altcp_mbedtls_setup_callbacks(conn, inner_conn);
conn->inner_conn = inner_conn;
conn->fns = &altcp_mbedtls_functions;
Expand Down Expand Up @@ -942,7 +944,7 @@ altcp_tls_create_config_server_privkey_cert(const u8_t *privkey, size_t privkey_
}

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

mbedtls_ssl_conf_ca_chain(&conf->conf, conf->ca, NULL);
}
memcpy(conf->host, host, sizeof(conf->host));
return conf;
}

struct altcp_tls_config *
altcp_tls_create_config_client(const u8_t *ca, size_t ca_len)
altcp_tls_create_config_client(const u8_t *ca, size_t ca_len, char* host)
{
return altcp_tls_create_config_client_common(ca, ca_len, 0);
return altcp_tls_create_config_client_common(ca, ca_len, 0, host);
}

struct altcp_tls_config *
Expand All @@ -986,7 +989,7 @@ altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_
return NULL;
}

conf = altcp_tls_create_config_client_common(ca, ca_len, 1);
conf = altcp_tls_create_config_client_common(ca, ca_len, 1, NULL);
if (conf == NULL) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/include/lwip/altcp_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct altcp_tls_config *altcp_tls_create_config_server_privkey_cert(const u8_t
/** @ingroup altcp_tls
* Create an ALTCP_TLS client configuration handle
*/
struct altcp_tls_config *altcp_tls_create_config_client(const u8_t *cert, size_t cert_len);
struct altcp_tls_config *altcp_tls_create_config_client(const u8_t *cert, size_t cert_len, char* host);

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

0 comments on commit bc80f0b

Please sign in to comment.