Commit 667acf5282 for openssl.org
commit 667acf5282afe0ebf538148cd6f73885be8537a6
Author: Dr. David von Oheimb <dev@ddvo.net>
Date: Fri Nov 6 13:26:16 2026 +0100
CMP: internally fix name of validatedSrvCert to be validatedPeerCert
Rename validatedSrvCert, as it should be validatedPeerCert instead,
because it is used not only by the client side, but also by the server.
Likewise, adapt the related internal function name and its internal
documentation. A test case is added just to exert the new internal
function name.
The related API function OSSL_CMP_CTX_get0_validatedSrvCert() is left
untouched to preserve API compatibility; it should be okay because
its intended use (and actual use in the CLI) is only for the client.
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Merge-date: Mon Nov 16 12:27:54 2026
Merged-from: https://github.com/openssl/openssl/pull/33583
diff --git a/crypto/cmp/cmp_ctx.c b/crypto/cmp/cmp_ctx.c
index 7e1c43a89c..dc7d858888 100644
--- a/crypto/cmp/cmp_ctx.c
+++ b/crypto/cmp/cmp_ctx.c
@@ -192,7 +192,7 @@ int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx)
&& ossl_cmp_ctx_set1_newChain(ctx, NULL)
&& ossl_cmp_ctx_set1_caPubs(ctx, NULL)
&& ossl_cmp_ctx_set1_extraCertsIn(ctx, NULL)
- && ossl_cmp_ctx_set1_validatedSrvCert(ctx, NULL)
+ && ossl_cmp_ctx_set1_validatedPeerCert(ctx, NULL)
&& ossl_cmp_ctx_set1_first_senderNonce(ctx, NULL)
&& OSSL_CMP_CTX_set1_transactionID(ctx, NULL)
&& OSSL_CMP_CTX_set1_senderNonce(ctx, NULL)
@@ -218,7 +218,7 @@ void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx)
OPENSSL_free(ctx->no_proxy);
X509_free(ctx->srvCert);
- X509_free(ctx->validatedSrvCert);
+ X509_free(ctx->validatedPeerCert);
X509_NAME_free(ctx->expected_sender);
X509_STORE_free(ctx->trusted);
OSSL_STACK_OF_X509_free(ctx->untrusted);
@@ -614,7 +614,7 @@ DEFINE_OSSL_CMP_CTX_get1_certs(caPubs)
return 1; \
}
- DEFINE_OSSL_set1_up_ref(ossl_cmp_ctx, validatedSrvCert, X509)
+ DEFINE_OSSL_set1_up_ref(ossl_cmp_ctx, validatedPeerCert, X509)
/*
* Pins the server certificate to be directly trusted (even if it is expired)
@@ -753,7 +753,7 @@ DEFINE_OSSL_set1_up_ref(OSSL_CMP_CTX, oldCert, X509)
DEFINE_OSSL_set0(ossl_cmp_ctx, newCert, X509)
/* Get successfully validated sender cert, if any, of current transaction */
- DEFINE_OSSL_CMP_CTX_get0(validatedSrvCert, X509)
+ DEFINE_OSSL_CMP_CTX_get0_NAME(validatedSrvCert, validatedPeerCert, X509)
/*
* Get the (newly received in IP/KUP/CP) client certificate from the context
diff --git a/crypto/cmp/cmp_local.h b/crypto/cmp/cmp_local.h
index ac892f62bd..e9cdd4e96c 100644
--- a/crypto/cmp/cmp_local.h
+++ b/crypto/cmp/cmp_local.h
@@ -58,7 +58,7 @@ struct ossl_cmp_ctx_st {
int nonmatchedErrorNonces; /* accept missing/wrong transactionID or recipNonce in error msgs */
int noCacheExtraCerts;
X509 *srvCert; /* certificate used to identify the server */
- X509 *validatedSrvCert; /* caches any already validated sender cert */
+ X509 *validatedPeerCert; /* caches first validated sender cert in transaction */
X509_NAME *expected_sender; /* expected sender in header of response */
X509_STORE *trusted; /* trust store maybe w CRLs and cert verify callback */
STACK_OF(X509) *untrusted; /* untrusted (intermediate CA) certs */
@@ -852,7 +852,7 @@ int ossl_cmp_print_log(OSSL_CMP_severity level, const OSSL_CMP_CTX *ctx,
#define ossl_cmp_info(ctx, msg) ossl_cmp_log(INFO, ctx, msg)
#define ossl_cmp_debug(ctx, msg) ossl_cmp_log(DEBUG, ctx, msg)
#define ossl_cmp_trace(ctx, msg) ossl_cmp_log(TRACE, ctx, msg)
-int ossl_cmp_ctx_set1_validatedSrvCert(OSSL_CMP_CTX *ctx, X509 *cert);
+int ossl_cmp_ctx_set1_validatedPeerCert(OSSL_CMP_CTX *ctx, X509 *cert);
int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status);
int ossl_cmp_ctx_set0_statusString(OSSL_CMP_CTX *ctx,
OSSL_CMP_PKIFREETEXT *text);
diff --git a/crypto/cmp/cmp_msg.c b/crypto/cmp/cmp_msg.c
index 02ef59caae..5e5528ac10 100644
--- a/crypto/cmp/cmp_msg.c
+++ b/crypto/cmp/cmp_msg.c
@@ -470,7 +470,7 @@ static OSSL_CRMF_ENCRYPTEDKEY *enc_privkey(OSSL_CMP_CTX *ctx, const EVP_PKEY *pk
CMS_EnvelopedData *envData = NULL;
BIO *privbio = NULL;
EVP_CIPHER *cipher = NULL;
- X509 *recip = ctx->validatedSrvCert; /* this is the client cert */
+ X509 *recip = ctx->validatedPeerCert; /* this is the client cert */
STACK_OF(X509) *encryption_recips = sk_X509_new_reserve(NULL, 1);
if (encryption_recips == NULL
diff --git a/crypto/cmp/cmp_vfy.c b/crypto/cmp/cmp_vfy.c
index 647dd044f2..77f680eb69 100644
--- a/crypto/cmp/cmp_vfy.c
+++ b/crypto/cmp/cmp_vfy.c
@@ -393,7 +393,7 @@ static int check_msg_given_cert(const OSSL_CMP_CTX *ctx, X509 *cert,
/*-
* Try all certs in given list for verifying msg, normally or in 3GPP mode.
* If already_checked1 == NULL then certs are assumed to be the msg->extraCerts.
- * On success cache the found cert using ossl_cmp_ctx_set1_validatedSrvCert().
+ * On success cache the found cert using ossl_cmp_ctx_set1_validatedPeerCert().
*/
static int check_msg_with_certs(OSSL_CMP_CTX *ctx, const STACK_OF(X509) *certs,
const char *desc,
@@ -422,7 +422,7 @@ static int check_msg_with_certs(OSSL_CMP_CTX *ctx, const STACK_OF(X509) *certs,
if (mode_3gpp ? check_cert_path_3gpp(ctx, msg, cert)
: check_cert_path(ctx, ctx->trusted, cert)) {
/* store successful sender cert for further msgs in transaction */
- return ossl_cmp_ctx_set1_validatedSrvCert(ctx, cert);
+ return ossl_cmp_ctx_set1_validatedPeerCert(ctx, cert);
}
}
if (in_extraCerts && n_acceptable_certs == 0)
@@ -433,7 +433,7 @@ static int check_msg_with_certs(OSSL_CMP_CTX *ctx, const STACK_OF(X509) *certs,
/*-
* Verify msg trying first ctx->untrusted, which should include extraCerts
* at its front, then trying the trusted certs in truststore (if any) of ctx.
- * On success cache the found cert using ossl_cmp_ctx_set1_validatedSrvCert().
+ * On success cache the found cert using ossl_cmp_ctx_set1_validatedPeerCert().
*/
static int check_msg_all_certs(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg,
int mode_3gpp)
@@ -470,11 +470,11 @@ static int check_msg_all_certs(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg,
/*-
* Verify message signature with any acceptable and valid candidate cert.
- * On success cache the found cert using ossl_cmp_ctx_set1_validatedSrvCert().
+ * On success cache the found cert using ossl_cmp_ctx_set1_validatedPeerCert().
*/
static int check_msg_find_cert(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg)
{
- X509 *scrt = ctx->validatedSrvCert; /* previous successful sender cert */
+ X509 *scrt = ctx->validatedPeerCert; /* first successfully sender cert */
GENERAL_NAME *sender = msg->header->sender;
char *sname = NULL;
char *skid_str = NULL;
@@ -516,7 +516,7 @@ static int check_msg_find_cert(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg)
ctx->log_cb = backup_log_cb;
(void)check_msg_given_cert(ctx, scrt, msg);
ctx->log_cb = NULL;
- (void)ossl_cmp_ctx_set1_validatedSrvCert(ctx, NULL); /* this invalidates scrt */
+ (void)ossl_cmp_ctx_set1_validatedPeerCert(ctx, NULL); /* this invalidates scrt */
}
res = check_msg_all_certs(ctx, msg, 0 /* using ctx->trusted */)
@@ -567,7 +567,7 @@ end:
* the sender certificate can have been pinned by providing it in ctx->srvCert,
* else it is searched in msg->extraCerts, ctx->untrusted, in ctx->trusted
* (in this order) and is path is validated against ctx->trusted.
- * On success cache the found cert using ossl_cmp_ctx_set1_validatedSrvCert().
+ * On success cache the found cert using ossl_cmp_ctx_set1_validatedPeerCert().
*
* If ctx->permitTAInExtraCertsForIR is true, when validating a CMP IP message,
* trust anchors for validating the IP message (and any subsequent responses
@@ -666,7 +666,7 @@ int OSSL_CMP_validate_msg(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg)
if (verify_signature(ctx, msg, scrt)) {
ossl_cmp_debug(ctx,
"successfully validated signature-based CMP message protection using pinned sender cert");
- return ossl_cmp_ctx_set1_validatedSrvCert(ctx, scrt);
+ return ossl_cmp_ctx_set1_validatedPeerCert(ctx, scrt);
}
ossl_cmp_warn(ctx, "CMP message signature verification failed");
ERR_raise(ERR_LIB_CMP, CMP_R_SRVCERT_DOES_NOT_VALIDATE_MSG);
diff --git a/doc/internal/man3/ossl_cmp_ctx_set1_caPubs.pod b/doc/internal/man3/ossl_cmp_ctx_set1_caPubs.pod
index 3c5cf9f9a7..c9dfe45c9b 100644
--- a/doc/internal/man3/ossl_cmp_ctx_set1_caPubs.pod
+++ b/doc/internal/man3/ossl_cmp_ctx_set1_caPubs.pod
@@ -3,7 +3,7 @@
=head1 NAME
ossl_cmp_ctx_set1_caPubs,
-ossl_cmp_ctx_set0_validatedSrvCert,
+ossl_cmp_ctx_set1_validatedPeerCert,
ossl_cmp_ctx_set_status,
ossl_cmp_ctx_set0_statusString,
ossl_cmp_ctx_set_failInfoCode,
@@ -17,7 +17,7 @@ ossl_cmp_ctx_set1_recipNonce
#include <openssl/cmp.h>
int ossl_cmp_ctx_set1_caPubs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *caPubs);
- int ossl_cmp_ctx_set0_validatedSrvCert(OSSL_CMP_CTX *ctx, X509 *cert);
+ int ossl_cmp_ctx_set1_validatedPeerCert(OSSL_CMP_CTX *ctx, X509 *cert);
int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status);
int ossl_cmp_ctx_set0_statusString(OSSL_CMP_CTX *ctx,
OSSL_CMP_PKIFREETEXT *text);
@@ -34,8 +34,8 @@ ossl_cmp_ctx_set1_caPubs() copies the given stack of CA certificates
to the caPubs field of the context.
The reference counts of those certificates handled successfully are increased.
-ossl_cmp_ctx_set0_validatedSrvCert() sets the validatedSrvCert of the context,
-which caches any already validated server cert, or NULL if not available.
+ossl_cmp_ctx_set1_validatedPeerCert() sets the validatedPeerCert of the context,
+which caches any already validated sender cert, or NULL if not available.
ossl_cmp_ctx_set_status() sets the status field of the context.
diff --git a/test/cmp_ctx_test.c b/test/cmp_ctx_test.c
index bdbea2030c..bbcce5a3e7 100644
--- a/test/cmp_ctx_test.c
+++ b/test/cmp_ctx_test.c
@@ -74,7 +74,7 @@ static int execute_CTX_reinit_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
|| !ossl_cmp_ctx_set1_newChain(ctx, certs)
|| !ossl_cmp_ctx_set1_caPubs(ctx, certs)
|| !ossl_cmp_ctx_set1_extraCertsIn(ctx, certs)
- || !ossl_cmp_ctx_set1_validatedSrvCert(ctx, cert)
+ || !ossl_cmp_ctx_set1_validatedPeerCert(ctx, cert)
|| !TEST_ptr(bytes = ASN1_OCTET_STRING_new())
|| !OSSL_CMP_CTX_set1_transactionID(ctx, bytes)
|| !OSSL_CMP_CTX_set1_senderNonce(ctx, bytes)
@@ -92,7 +92,7 @@ static int execute_CTX_reinit_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
&& ctx->newChain == NULL
&& ctx->caPubs == NULL
&& ctx->extraCertsIn == NULL
- && ctx->validatedSrvCert == NULL
+ && ctx->validatedPeerCert == NULL
&& ctx->transactionID == NULL
&& ctx->senderNonce == NULL
&& ctx->recipNonce == NULL))
@@ -765,7 +765,13 @@ DEFINE_SET_CB_TEST(transfer_cb)
DEFINE_SET_GET_P_VOID_TEST(transfer_cb_arg)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, srvCert, X509)
-DEFINE_SET_GET_TEST(ossl_cmp, ctx, 1, 0, 0, validatedSrvCert, X509)
+
+static X509 *OSSL_CMP_CTX_get0_validatedPeerCert(const CMP_CTX *ctx)
+{
+ return OSSL_CMP_CTX_get0_validatedSrvCert(ctx);
+}
+DEFINE_SET_GET_TEST(ossl_cmp, ctx, 1, 0, 0, validatedPeerCert, X509)
+
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, expected_sender, X509_NAME)
DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set0, get0, 0, trusted,
X509_STORE *, NULL,
@@ -858,7 +864,7 @@ int setup_tests(void)
ADD_TEST(test_CTX_set_get_transfer_cb_arg);
/* server authentication: */
ADD_TEST(test_CTX_set1_get0_srvCert);
- ADD_TEST(test_CTX_set1_get0_validatedSrvCert);
+ ADD_TEST(test_CTX_set1_get0_validatedPeerCert);
ADD_TEST(test_CTX_set1_get0_expected_sender);
ADD_TEST(test_CTX_set0_get0_trusted);
ADD_TEST(test_CTX_set1_get0_untrusted);