Merge branch 'feature/esp-tls' into 'master'
esp-tls: Fix HTTP2 failure See merge request idf/esp-idf!2277
This commit is contained in:
commit
63ce43affc
4 changed files with 12 additions and 3 deletions
|
@ -182,6 +182,10 @@ static int create_ssl_handle(esp_tls_t *tls, const char *hostname, size_t hostle
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cfg->alpn_protos) {
|
||||||
|
mbedtls_ssl_conf_alpn_protocols(&tls->conf, cfg->alpn_protos);
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg->cacert_pem_buf != NULL) {
|
if (cfg->cacert_pem_buf != NULL) {
|
||||||
mbedtls_x509_crt_init(&tls->cacert);
|
mbedtls_x509_crt_init(&tls->cacert);
|
||||||
ret = mbedtls_x509_crt_parse(&tls->cacert, cfg->cacert_pem_buf, cfg->cacert_pem_bytes);
|
ret = mbedtls_x509_crt_parse(&tls->cacert, cfg->cacert_pem_buf, cfg->cacert_pem_bytes);
|
||||||
|
|
|
@ -36,7 +36,7 @@ extern "C" {
|
||||||
* @brief ESP-TLS configuration parameters
|
* @brief ESP-TLS configuration parameters
|
||||||
*/
|
*/
|
||||||
typedef struct esp_tls_cfg {
|
typedef struct esp_tls_cfg {
|
||||||
const unsigned char *alpn_protos; /*!< Application protocols required for HTTP2.
|
const char **alpn_protos; /*!< Application protocols required for HTTP2.
|
||||||
If HTTP2/ALPN support is required, a list
|
If HTTP2/ALPN support is required, a list
|
||||||
of protocols that should be negotiated.
|
of protocols that should be negotiated.
|
||||||
The format is length followed by protocol
|
The format is length followed by protocol
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
#include <http_parser.h>
|
||||||
|
|
||||||
#include "sh2lib.h"
|
#include "sh2lib.h"
|
||||||
|
|
||||||
|
@ -240,14 +241,19 @@ static int do_http2_connect(struct sh2lib_handle *hd)
|
||||||
int sh2lib_connect(struct sh2lib_handle *hd, const char *uri)
|
int sh2lib_connect(struct sh2lib_handle *hd, const char *uri)
|
||||||
{
|
{
|
||||||
memset(hd, 0, sizeof(*hd));
|
memset(hd, 0, sizeof(*hd));
|
||||||
|
const char *proto[] = {"h2", NULL};
|
||||||
esp_tls_cfg_t tls_cfg = {
|
esp_tls_cfg_t tls_cfg = {
|
||||||
.alpn_protos = (unsigned char *) "\x02h2",
|
.alpn_protos = proto,
|
||||||
.non_block = true,
|
.non_block = true,
|
||||||
};
|
};
|
||||||
if ((hd->http2_tls = esp_tls_conn_http_new(uri, &tls_cfg)) == NULL) {
|
if ((hd->http2_tls = esp_tls_conn_http_new(uri, &tls_cfg)) == NULL) {
|
||||||
ESP_LOGE(TAG, "[sh2-connect] esp-tls connection failed");
|
ESP_LOGE(TAG, "[sh2-connect] esp-tls connection failed");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
struct http_parser_url u;
|
||||||
|
http_parser_url_init(&u);
|
||||||
|
http_parser_parse_url(uri, strlen(uri), 0, &u);
|
||||||
|
hd->hostname = strndup(&uri[u.field_data[UF_HOST].off], u.field_data[UF_HOST].len);
|
||||||
|
|
||||||
/* HTTP/2 Connection */
|
/* HTTP/2 Connection */
|
||||||
if (do_http2_connect(hd) != 0) {
|
if (do_http2_connect(hd) != 0) {
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
*/
|
*/
|
||||||
struct sh2lib_handle {
|
struct sh2lib_handle {
|
||||||
nghttp2_session *http2_sess; /*!< Pointer to the HTTP2 session handle */
|
nghttp2_session *http2_sess; /*!< Pointer to the HTTP2 session handle */
|
||||||
int sockfd; /*!< Socket file descriptor */
|
|
||||||
char *hostname; /*!< The hostname we are connected to */
|
char *hostname; /*!< The hostname we are connected to */
|
||||||
struct esp_tls *http2_tls; /*!< Pointer to the TLS session handle */
|
struct esp_tls *http2_tls; /*!< Pointer to the TLS session handle */
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue