-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqtt-sni.patch
68 lines (65 loc) · 2.27 KB
/
mqtt-sni.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
diff --git a/src/apps/altcp_tls/altcp_tls_mbedtls.c b/src/apps/altcp_tls/altcp_tls_mbedtls.c
index e787ae28..11dab664 100644
--- a/src/apps/altcp_tls/altcp_tls_mbedtls.c
+++ b/src/apps/altcp_tls/altcp_tls_mbedtls.c
@@ -107,6 +107,8 @@ struct altcp_tls_config {
u8_t pkey_count;
u8_t pkey_max;
mbedtls_x509_crt *ca;
+ /** Server name for setting SNI */
+ const char *server_name;
#if defined(MBEDTLS_SSL_CACHE_C) && ALTCP_MBEDTLS_USE_SESSION_CACHE
/** Inter-connection cache for fast connection startup */
struct mbedtls_ssl_cache_context cache;
@@ -611,6 +613,7 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
int ret;
struct altcp_tls_config *config = (struct altcp_tls_config *)conf;
altcp_mbedtls_state_t *state;
+
if (!conf) {
return ERR_ARG;
}
@@ -637,6 +640,15 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
conn->inner_conn = inner_conn;
conn->fns = &altcp_mbedtls_functions;
conn->state = state;
+
+ if (config->server_name != NULL) {
+ if ((ret = mbedtls_ssl_set_hostname(&state->ssl_context, config->server_name)) != 0) {
+ LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_set_hostname failed\n"));
+ }
+ mbedtls_ssl_conf_authmode(&config->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
+ }
+
+
return ERR_OK;
}
@@ -1330,6 +1342,14 @@ altcp_mbedtls_dealloc(struct altcp_pcb *conn)
}
}
+void altcp_tls_set_server_name(struct altcp_tls_config *config, const char *server_name) {
+ config->server_name = server_name;
+}
+
+const char *altcp_tls_get_server_name(struct altcp_tls_config *config) {
+ return config->server_name;
+}
+
const struct altcp_functions altcp_mbedtls_functions = {
altcp_mbedtls_set_poll,
altcp_mbedtls_recved,
diff --git a/src/include/lwip/altcp_tls.h b/src/include/lwip/altcp_tls.h
index fcb784d8..a62203e5 100644
--- a/src/include/lwip/altcp_tls.h
+++ b/src/include/lwip/altcp_tls.h
@@ -187,6 +187,11 @@ err_t altcp_tls_set_session(struct altcp_pcb *conn, struct altcp_tls_session *fr
*/
void altcp_tls_free_session(struct altcp_tls_session *dest);
+
+void altcp_tls_set_server_name(struct altcp_tls_config *config, const char *server_name);
+
+const char *altcp_tls_get_server_name(struct altcp_tls_config *config);
+
#ifdef __cplusplus
}
#endif