diff options
Diffstat (limited to 'crypto/cmp/cmp_http.c')
-rw-r--r-- | crypto/cmp/cmp_http.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/crypto/cmp/cmp_http.c b/crypto/cmp/cmp_http.c index d29bfa8674ad..c0226e562a32 100644 --- a/crypto/cmp/cmp_http.c +++ b/crypto/cmp/cmp_http.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2007-2025 The OpenSSL Project Authors. All Rights Reserved. * Copyright Nokia 2007-2019 * Copyright Siemens AG 2015-2019 * @@ -14,7 +14,6 @@ #include <openssl/asn1t.h> #include <openssl/http.h> -#include "internal/sockets.h" #include <openssl/cmp.h> #include "cmp_local.h" @@ -25,12 +24,11 @@ #include <stdlib.h> #include <openssl/bio.h> #include <openssl/buffer.h> -#include <openssl/cmp.h> #include <openssl/err.h> -static int keep_alive(int keep_alive, int body_type) +static int keep_alive(int keep_alive, int body_type, BIO **bios) { - if (keep_alive != 0 + if (keep_alive != 0 && bios == NULL /* * Ask for persistent connection only if may need more round trips. * Do so even with disableConfirm because polling might be needed. @@ -46,7 +44,6 @@ static int keep_alive(int keep_alive, int body_type) /* * Send the PKIMessage req and on success return the response, else NULL. - * Any previous error queue entries will likely be removed by ERR_clear_error(). */ OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req) @@ -57,6 +54,7 @@ OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, int tls_used; const ASN1_ITEM *it = ASN1_ITEM_rptr(OSSL_CMP_MSG); BIO *req_mem, *rsp; + BIO **bios; /* optionally used as bio and rbio */ OSSL_CMP_MSG *res = NULL; if (ctx == NULL || req == NULL) { @@ -69,24 +67,40 @@ OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, if ((req_mem = ASN1_item_i2d_mem_bio(it, (const ASN1_VALUE *)req)) == NULL) goto err; + bios = OSSL_CMP_CTX_get_transfer_cb_arg(ctx); if (ctx->serverPort != 0) BIO_snprintf(server_port, sizeof(server_port), "%d", ctx->serverPort); - tls_used = OSSL_CMP_CTX_get_http_cb_arg(ctx) != NULL; - if (ctx->http_ctx == NULL) - ossl_cmp_log3(DEBUG, ctx, "connecting to CMP server %s:%s%s", - ctx->server, server_port, tls_used ? " using TLS" : ""); + tls_used = ctx->tls_used >= 0 ? ctx->tls_used != 0 + : OSSL_CMP_CTX_get_http_cb_arg(ctx) != NULL; /* backward compat */ + if (ctx->http_ctx == NULL) { /* using existing connection or yet not set up own connection */ + const char *path = ctx->serverPath; + + if (path == NULL) + path = ""; + if (*path == '/') + path++; + if (bios == NULL) + ossl_cmp_log4(DEBUG, ctx, + "connecting to CMP server via http%s://%s:%s%s/%s", + tls_used ? "s" : "", ctx->server, server_port, path); + else + ossl_cmp_log3(DEBUG, ctx, + "using existing connection with CMP server %s%s and HTTP path /%s", + ctx->server, server_port, path); + } rsp = OSSL_HTTP_transfer(&ctx->http_ctx, ctx->server, server_port, ctx->serverPath, tls_used, ctx->proxy, ctx->no_proxy, - NULL /* bio */, NULL /* rbio */, + bios == NULL ? NULL : bios[0] /* bio */, + bios == NULL ? NULL : bios[1] /* rbio */, ctx->http_cb, OSSL_CMP_CTX_get_http_cb_arg(ctx), 0 /* buf_size */, headers, content_type_pkix, req_mem, content_type_pkix, 1 /* expect_asn1 */, OSSL_HTTP_DEFAULT_MAX_RESP_LEN, ctx->msg_timeout, - keep_alive(ctx->keep_alive, req->body->type)); + keep_alive(ctx->keep_alive, req->body->type, bios)); BIO_free(req_mem); res = (OSSL_CMP_MSG *)ASN1_item_d2i_bio(it, rsp, NULL); BIO_free(rsp); @@ -94,9 +108,11 @@ OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, if (ctx->http_ctx == NULL) ossl_cmp_debug(ctx, "disconnected from CMP server"); /* - * Note that on normal successful end of the transaction the connection - * is not closed at this level, but this will be done by the CMP client - * application via OSSL_CMP_CTX_free() or OSSL_CMP_CTX_reinit(). + * Note that on normal successful end of the transaction the + * HTTP connection is not closed at this level if keep_alive(...) != 0. + * It should be closed by the CMP client application + * using OSSL_CMP_CTX_free() or OSSL_CMP_CTX_reinit(). + * Any pre-existing bio (== ctx->transfer_cb_arg) is not freed. */ if (res != NULL) ossl_cmp_debug(ctx, "finished reading response from CMP server"); |