MHD_connection_get_info_dynamic_sz() wrote the TLS session of the
connection to the output buffer and then left the switch with "break".
So it returned MHD_SC_INFO_GET_TYPE_UNKNOWN, which the documentation
gives for an unknown info_type. An application that reads the value
only when the call reports success never got the session handle. Every
other query of this function returns MHD_SC_OK after it sets the
value.
Added a case for the TLS session to test_tls.
---
src/mhd2/conn_get_info.c | 2 +-
src/tests/client_server/libtest.h | 27 ++++++++++++
.../libtest_convenience_server_reply.c | 43 +++++++++++++++++++
src/tests/client_server/test_tls.c | 9 ++++
4 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/src/mhd2/conn_get_info.c b/src/mhd2/conn_get_info.c
index 1e03a36..186dcef 100644
--- a/src/mhd2/conn_get_info.c
+++ b/src/mhd2/conn_get_info.c
@@ -178,8 +178,8 @@ MHD_connection_get_info_dynamic_sz (
return MHD_SC_INTERNAL_ERROR;
#else /* MHD_SUPPORT_HTTPS */
mhd_tls_conn_get_tls_sess (connection->tls, &(output_buf->v_tls_session));
+ return MHD_SC_OK;
#endif /* MHD_SUPPORT_HTTPS */
- break;
case MHD_CONNECTION_INFO_DYNAMIC_SENTINEL:
default:
break;
diff --git a/src/tests/client_server/libtest.h
b/src/tests/client_server/libtest.h
index b180b04..8d91cc9 100644
--- a/src/tests/client_server/libtest.h
+++ b/src/tests/client_server/libtest.h
@@ -647,6 +647,33 @@ MHDT_server_reply_check_query (
uint_fast64_t upload_size);
+/**
+ * Checks that the TLS session of the connection can be read.
+ * If so, returns #MHD_HTTP_STATUS_NO_CONTENT.
+ *
+ * @param cls closure, unused
+ * @param request the request object
+ * @param path the requested uri (without arguments after "?")
+ * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
+ * #MHD_HTTP_METHOD_PUT, etc.)
+ * @param upload_size the size of the message upload content payload,
+ * #MHD_SIZE_UNKNOWN for chunked uploads (if the
+ * final chunk has not been processed yet)
+ * @return action how to proceed, NULL
+ * if the request must be aborted due to a serious
+ * error while handling the request (implies closure
+ * of underling data stream, for HTTP/1.1 it means
+ * socket closure).
+ */
+const struct MHD_Action *
+MHDT_server_reply_check_tls_session (
+ void *cls,
+ struct MHD_Request *MHD_RESTRICT request,
+ const struct MHD_String *MHD_RESTRICT path,
+ enum MHD_HTTP_Method method,
+ uint_fast64_t upload_size);
+
+
/**
* Checks that the client request includes the given
* custom header, both by its name and by iterating over
diff --git a/src/tests/client_server/libtest_convenience_server_reply.c
b/src/tests/client_server/libtest_convenience_server_reply.c
index 6021cc7..c42cc62 100644
--- a/src/tests/client_server/libtest_convenience_server_reply.c
+++ b/src/tests/client_server/libtest_convenience_server_reply.c
@@ -320,6 +320,49 @@ MHDT_server_reply_check_query (
}
+const struct MHD_Action *
+MHDT_server_reply_check_tls_session (
+ void *cls,
+ struct MHD_Request *MHD_RESTRICT request,
+ const struct MHD_String *MHD_RESTRICT path,
+ enum MHD_HTTP_Method method,
+ uint_fast64_t upload_size)
+{
+ union MHD_RequestInfoFixedData req_info;
+ union MHD_ConnectionInfoDynamicData conn_info;
+ enum MHD_StatusCode sc;
+
+ (void)cls;
+ (void)path;
+ (void)method;
+ (void)upload_size; /* Unused */
+
+ if (MHD_SC_OK !=
+ MHD_request_get_info_fixed (request,
+ MHD_REQUEST_INFO_FIXED_CONNECTION,
+ &req_info))
+ {
+ fprintf (stderr,
+ "Failed to get the connection of the request\n");
+ return MHD_action_abort_request (request);
+ }
+ sc = MHD_connection_get_info_dynamic (req_info.v_connection,
+
MHD_CONNECTION_INFO_DYNAMIC_TLS_SESSION,
+ &conn_info);
+ if (MHD_SC_OK != sc)
+ {
+ fprintf (stderr,
+ "Failed to get the TLS session: %u\n",
+ (unsigned int)sc);
+ return MHD_action_abort_request (request);
+ }
+ return MHD_action_from_response (
+ request,
+ MHD_response_from_empty (
+ MHD_HTTP_STATUS_NO_CONTENT));
+}
+
+
/**
* Closure for #find_header_name().
*/
diff --git a/src/tests/client_server/test_tls.c
b/src/tests/client_server/test_tls.c
index a385004..05f5b00 100644
--- a/src/tests/client_server/test_tls.c
+++ b/src/tests/client_server/test_tls.c
@@ -245,6 +245,15 @@ main (int argc, char *argv[])
.use_tls = true,
.http_version = 1,
},
+ {
+ .label = "TLS session of the connection",
+ .server_cb = &MHDT_server_reply_check_tls_session,
+ .client_cb = &MHDT_client_get_with_query,
+ .client_cb_cls = "",
+ .timeout_ms = 2500,
+ .use_tls = true,
+ .http_version = 1,
+ },
{
.label = "client request with custom header",
.server_cb = &MHDT_server_reply_check_header,
--
2.43.0