ssl_client2: Add Host to HTTP GET request

If an IP address shares multiple domain names with different SSL
certificates and makes a GET request without the remote server name
(host), it will fail with a 421 Misdirect Request.

Signed-off-by: Javier Tia <javier.tia@linaro.org>
This commit is contained in:
Javier Tia 2024-05-06 13:46:01 -06:00
parent c50bf9549b
commit 7a312d7247
No known key found for this signature in database
GPG Key ID: B5EEC30BA867771F

View File

@ -108,7 +108,7 @@ int main(void)
#define DFL_SRTP_MKI ""
#define DFL_KEY_OPAQUE_ALG "none"
#define GET_REQUEST "GET %s HTTP/1.0\r\nExtra-header: "
#define GET_REQUEST "GET %s HTTP/1.0\r\nHost: %s\r\nExtra-header: "
#define GET_REQUEST_END "\r\n\r\n"
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
@ -724,7 +724,7 @@ static int build_http_request(unsigned char *buf, size_t buf_size, size_t *reque
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
size_t len, tail_len, request_size;
ret = mbedtls_snprintf((char *) buf, buf_size, GET_REQUEST, opt.request_page);
ret = mbedtls_snprintf((char *) buf, buf_size, GET_REQUEST, opt.request_page, opt.server_name);
if (ret < 0) {
return ret;
}