From d386374449ea09c912875e0d35b358240b864f6a Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 22 Mar 2017 22:42:09 +0100 Subject: [PATCH] httpd: add support for https --- src/apps/httpd/httpd.c | 20 ++++++++++++++++++++ src/include/lwip/apps/httpd.h | 4 ++++ src/include/lwip/apps/httpd_opts.h | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/apps/httpd/httpd.c b/src/apps/httpd/httpd.c index 255cc013..d88ed675 100644 --- a/src/apps/httpd/httpd.c +++ b/src/apps/httpd/httpd.c @@ -98,6 +98,9 @@ #include "lwip/altcp.h" #include "lwip/altcp_tcp.h" +#if HTTPD_ENABLE_HTTPS +#include "lwip/apps/altcp_tls.h" +#endif #include /* memset */ #include /* atoi */ @@ -2589,6 +2592,23 @@ httpd_init(void) httpd_init_pcb(pcb, HTTPD_SERVER_PORT); } +#if HTTPD_ENABLE_HTTPS +void +httpd_inits(struct altcp_tls_config *conf) +{ +#if LWIP_ALTCP_TLS + struct altcp_pcb *pcb_tls; + struct altcp_pcb *pcb_tcp = altcp_tcp_new_ip_type(IPADDR_TYPE_ANY); + LWIP_ASSERT("httpd_init: tcp_new failed", pcb_tcp != NULL); + pcb_tls = altcp_tls_new(conf, pcb_tcp); + LWIP_ASSERT("httpd_init: altcp_tls_new failed", pcb_tls != NULL); + httpd_init_pcb(pcb_tls, HTTPD_SERVER_PORT_HTTPS); +#else /* LWIP_ALTCP_TLS */ + LWIP_UNUSED_ARG(conf); +#endif /* LWIP_ALTCP_TLS */ +} +#endif /* HTTPD_ENABLE_HTTPS */ + #if LWIP_HTTPD_SSI /** * Set the SSI handler function. diff --git a/src/include/lwip/apps/httpd.h b/src/include/lwip/apps/httpd.h index 40f1811e..efa20862 100644 --- a/src/include/lwip/apps/httpd.h +++ b/src/include/lwip/apps/httpd.h @@ -228,6 +228,10 @@ void httpd_post_data_recved(void *connection, u16_t recved_len); void httpd_init(void); +#if HTTPD_ENABLE_HTTPS +struct altcp_tls_config; +void httpd_inits(struct altcp_tls_config *conf); +#endif #ifdef __cplusplus } diff --git a/src/include/lwip/apps/httpd_opts.h b/src/include/lwip/apps/httpd_opts.h index 8f39d0b3..98198ce3 100644 --- a/src/include/lwip/apps/httpd_opts.h +++ b/src/include/lwip/apps/httpd_opts.h @@ -132,6 +132,16 @@ #define HTTPD_SERVER_PORT 80 #endif +/** The https server port for HTTPD to use */ +#if !defined HTTPD_SERVER_PORT_HTTPS || defined __DOXYGEN__ +#define HTTPD_SERVER_PORT_HTTPS 443 +#endif + +/** Enable https support? */ +#if !defined HTTPD_ENABLE_HTTPS || defined __DOXYGEN__ +#define HTTPD_ENABLE_HTTPS 0 +#endif + /** Maximum retries before the connection is aborted/closed. * - number of times pcb->poll is called -> default is 4*500ms = 2s; * - reset when pcb->sent is called