Closed jetm closed 6 months ago
OK, I think found the problem. It was missing Host:
in the GET
request. With the following change, I can get an HTTP/1.1 200 OK
.
$ git --no-pager diff programs/ssl/ssl_client2.c
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 43133d901..97dfde663 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -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;
}
Summary
I am working in a HTTPS client using LWIP with mbedTLS, and when trying to access some HTTPS servers, like
https://ftp.debian.org
it returnsHTTP/1.1 421 Misdirected Request
. It's reproducible withssl_client2
too. With curl, it produces the expected output.I am not sure what I am missing, if it's a mbedTLS configuration/implementation or an HTTP client implementation.
ssl_client2 output
curl output
System information
Mbed TLS version (number or commit id): Mbed TLS 3.6.0 (build 50724864) Operating system and version: OS: Arch Linux Linux x86_64, Kernel: 6.8.8-2-cachyos Configuration (if not default, please attach
mbedtls_config.h
): mbedtls_config.h.zip Compiler and options (if you used a pre-built binary, please indicate how you obtained it): N/A Additional environment information:Expected behavior
curl --tls-max 1.2 -v https://ftp.debian.org
or a browser output.Actual behavior
Explained in the summary
Steps to reproduce
Additional information