diff options
Diffstat (limited to 'crypto/openssl/crypto/cmp/cmp_client.c')
| -rw-r--r-- | crypto/openssl/crypto/cmp/cmp_client.c | 264 |
1 files changed, 136 insertions, 128 deletions
diff --git a/crypto/openssl/crypto/cmp/cmp_client.c b/crypto/openssl/crypto/cmp/cmp_client.c index e129705e0e63..d6a4230d243e 100644 --- a/crypto/openssl/crypto/cmp/cmp_client.c +++ b/crypto/openssl/crypto/cmp/cmp_client.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2025 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2007-2026 The OpenSSL Project Authors. All Rights Reserved. * Copyright Nokia 2007-2019 * Copyright Siemens AG 2015-2019 * @@ -21,7 +21,7 @@ #include <openssl/cmp_util.h> #define IS_CREP(t) ((t) == OSSL_CMP_PKIBODY_IP || (t) == OSSL_CMP_PKIBODY_CP \ - || (t) == OSSL_CMP_PKIBODY_KUP) + || (t) == OSSL_CMP_PKIBODY_KUP) /*- * Evaluate whether there's an exception (violating the standard) configured for @@ -29,9 +29,9 @@ * Returns 1 on acceptance, 0 on rejection, or -1 on (internal) error. */ static int unprotected_exception(const OSSL_CMP_CTX *ctx, - const OSSL_CMP_MSG *rep, - int invalid_protection, - ossl_unused int expected_type) + const OSSL_CMP_MSG *rep, + int invalid_protection, + ossl_unused int expected_type) { int rcvd_type = OSSL_CMP_MSG_get_bodytype(rep /* may be NULL */); const char *msg_type = NULL; @@ -46,18 +46,16 @@ static int unprotected_exception(const OSSL_CMP_CTX *ctx, case OSSL_CMP_PKIBODY_ERROR: msg_type = "error response"; break; - case OSSL_CMP_PKIBODY_RP: - { - OSSL_CMP_PKISI *si = - ossl_cmp_revrepcontent_get_pkisi(rep->body->value.rp, - OSSL_CMP_REVREQSID); - - if (si == NULL) - return -1; - if (ossl_cmp_pkisi_get_status(si) == OSSL_CMP_PKISTATUS_rejection) - msg_type = "revocation response message with rejection status"; - break; - } + case OSSL_CMP_PKIBODY_RP: { + OSSL_CMP_PKISI *si = ossl_cmp_revrepcontent_get_pkisi(rep->body->value.rp, + OSSL_CMP_REVREQSID); + + if (si == NULL) + return -1; + if (ossl_cmp_pkisi_get_status(si) == OSSL_CMP_PKISTATUS_rejection) + msg_type = "revocation response message with rejection status"; + break; + } case OSSL_CMP_PKIBODY_PKICONF: msg_type = "PKI Confirmation message"; break; @@ -65,8 +63,7 @@ static int unprotected_exception(const OSSL_CMP_CTX *ctx, if (IS_CREP(rcvd_type)) { int any_rid = OSSL_CMP_CERTREQID_NONE; OSSL_CMP_CERTREPMESSAGE *crepmsg = rep->body->value.ip; - OSSL_CMP_CERTRESPONSE *crep = - ossl_cmp_certrepmessage_get0_certresponse(crepmsg, any_rid); + OSSL_CMP_CERTRESPONSE *crep = ossl_cmp_certrepmessage_get0_certresponse(crepmsg, any_rid); if (sk_OSSL_CMP_CERTRESPONSE_num(crepmsg->response) > 1) return -1; @@ -80,7 +77,7 @@ static int unprotected_exception(const OSSL_CMP_CTX *ctx, if (msg_type == NULL) return 0; ossl_cmp_log2(WARN, ctx, "ignoring %s protection of %s", - invalid_protection ? "invalid" : "missing", msg_type); + invalid_protection ? "invalid" : "missing", msg_type); return 1; } @@ -100,7 +97,7 @@ static int save_statusInfo(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si) ctx->failInfoCode = ossl_cmp_pkisi_get_pkifailureinfo(si); if (!ossl_cmp_ctx_set0_statusString(ctx, sk_ASN1_UTF8STRING_new_null()) - || (ctx->statusString == NULL)) + || (ctx->statusString == NULL)) return 0; ss = si->statusString; /* may be NULL */ @@ -129,7 +126,7 @@ static int is_crep_with_waiting(const OSSL_CMP_MSG *resp, int rid) crep = ossl_cmp_certrepmessage_get0_certresponse(crepmsg, rid); return (crep != NULL - && ossl_cmp_pkisi_get_status(crep->status) + && ossl_cmp_pkisi_get_status(crep->status) == OSSL_CMP_PKISTATUS_waiting); } @@ -140,13 +137,11 @@ static int is_crep_with_waiting(const OSSL_CMP_MSG *resp, int rid) * Regardless of success, caller is responsible for freeing *rep (unless NULL). */ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, - OSSL_CMP_MSG **rep, int expected_type) + OSSL_CMP_MSG **rep, int expected_type) { - int begin_transaction = - expected_type != OSSL_CMP_PKIBODY_POLLREP + int begin_transaction = expected_type != OSSL_CMP_PKIBODY_POLLREP && expected_type != OSSL_CMP_PKIBODY_PKICONF; - const char *req_type_str = - ossl_cmp_bodytype_to_string(OSSL_CMP_MSG_get_bodytype(req)); + const char *req_type_str = ossl_cmp_bodytype_to_string(OSSL_CMP_MSG_get_bodytype(req)); const char *expected_type_str = ossl_cmp_bodytype_to_string(expected_type); int bak_msg_timeout = ctx->msg_timeout; int bt; @@ -154,6 +149,7 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, int time_left; OSSL_CMP_transfer_cb_t transfer_cb = ctx->transfer_cb; + ctx->status = OSSL_CMP_PKISTATUS_trans; #ifndef OPENSSL_NO_HTTP if (transfer_cb == NULL) transfer_cb = OSSL_CMP_MSG_http_perform; @@ -180,7 +176,7 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, /* should print error queue since transfer_cb may call ERR_clear_error() */ OSSL_CMP_CTX_print_errors(ctx); - if (ctx->server != NULL) + if (ctx->server != NULL || ctx->transfer_cb != NULL) ossl_cmp_log1(INFO, ctx, "sending %s", req_type_str); *rep = (*transfer_cb)(ctx, req); @@ -188,13 +184,13 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, if (*rep == NULL) { ERR_raise_data(ERR_LIB_CMP, - ctx->total_timeout != 0 && time(NULL) >= ctx->end_time ? - CMP_R_TOTAL_TIMEOUT : CMP_R_TRANSFER_ERROR, - "request sent: %s, expected response: %s", - req_type_str, expected_type_str); + ctx->total_timeout != 0 && time(NULL) >= ctx->end_time ? CMP_R_TOTAL_TIMEOUT : CMP_R_TRANSFER_ERROR, + "request sent: %s, expected response: %s", + req_type_str, expected_type_str); return 0; } + ctx->status = OSSL_CMP_PKISTATUS_checking_response; bt = OSSL_CMP_MSG_get_bodytype(*rep); /* * The body type in the 'bt' variable is not yet verified. @@ -202,15 +198,15 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, * the following msg verification may also produce log entries and may fail. */ ossl_cmp_log2(INFO, ctx, "received %s%s", ossl_cmp_bodytype_to_string(bt), - ossl_cmp_is_error_with_waiting(*rep) ? " (waiting)" : ""); + ossl_cmp_is_error_with_waiting(*rep) ? " (waiting)" : ""); /* copy received extraCerts to ctx->extraCertsIn so they can be retrieved */ if (bt != OSSL_CMP_PKIBODY_POLLREP && bt != OSSL_CMP_PKIBODY_PKICONF - && !ossl_cmp_ctx_set1_extraCertsIn(ctx, (*rep)->extraCerts)) + && !ossl_cmp_ctx_set1_extraCertsIn(ctx, (*rep)->extraCerts)) return 0; if (!ossl_cmp_msg_check_update(ctx, *rep, unprotected_exception, - expected_type)) + expected_type)) return 0; /* @@ -222,33 +218,34 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, */ if (bt == expected_type || (expected_type == OSSL_CMP_PKIBODY_POLLREP - ? bt != OSSL_CMP_PKIBODY_ERROR - : ossl_cmp_is_error_with_waiting(*rep))) + ? bt != OSSL_CMP_PKIBODY_ERROR + : ossl_cmp_is_error_with_waiting(*rep))) return 1; /* received message type is not one of the expected ones (e.g., error) */ - ERR_raise(ERR_LIB_CMP, bt == OSSL_CMP_PKIBODY_ERROR ? CMP_R_RECEIVED_ERROR : - CMP_R_UNEXPECTED_PKIBODY); /* in next line for mkerr.pl */ + ERR_raise(ERR_LIB_CMP, bt == OSSL_CMP_PKIBODY_ERROR ? CMP_R_RECEIVED_ERROR : CMP_R_UNEXPECTED_PKIBODY); /* in next line for mkerr.pl */ if (bt != OSSL_CMP_PKIBODY_ERROR) { ERR_add_error_data(3, "message type is '", - ossl_cmp_bodytype_to_string(bt), "'"); + ossl_cmp_bodytype_to_string(bt), "'"); } else { OSSL_CMP_ERRORMSGCONTENT *emc = (*rep)->body->value.error; OSSL_CMP_PKISI *si = emc->pKIStatusInfo; char buf[OSSL_CMP_PKISI_BUFLEN]; if (save_statusInfo(ctx, si) - && OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, - sizeof(buf)) != NULL) + && OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, + sizeof(buf)) + != NULL) ERR_add_error_data(1, buf); if (emc->errorCode != NULL - && BIO_snprintf(buf, sizeof(buf), "; errorCode: %08lX", - ASN1_INTEGER_get(emc->errorCode)) > 0) + && BIO_snprintf(buf, sizeof(buf), "; errorCode: %08lX", + ASN1_INTEGER_get(emc->errorCode)) + > 0) ERR_add_error_data(1, buf); if (emc->errorDetails != NULL) { char *text = ossl_sk_ASN1_UTF8STRING2text(emc->errorDetails, ", ", - OSSL_CMP_PKISI_BUFLEN - 1); + OSSL_CMP_PKISI_BUFLEN - 1); if (text != NULL && *text != '\0') ERR_add_error_data(2, "; errorDetails: ", text); @@ -280,20 +277,24 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, * or a response with 'waiting' status has been received). */ static int poll_for_response(OSSL_CMP_CTX *ctx, int sleep, int rid, - OSSL_CMP_MSG **rep, int *checkAfter) + OSSL_CMP_MSG **rep, int *checkAfter) { OSSL_CMP_MSG *preq = NULL; OSSL_CMP_MSG *prep = NULL; ossl_cmp_info(ctx, - "received 'waiting' PKIStatus, starting to poll for response"); + "received 'waiting' PKIStatus, starting to poll for response"); *rep = NULL; for (;;) { + int bak = ctx->status; + + ctx->status = OSSL_CMP_PKISTATUS_request; if ((preq = ossl_cmp_pollReq_new(ctx, rid)) == NULL) goto err; if (!send_receive_check(ctx, preq, &prep, OSSL_CMP_PKIBODY_POLLREP)) goto err; + ctx->status = bak; /* handle potential pollRep */ if (OSSL_CMP_MSG_get_bodytype(prep) == OSSL_CMP_PKIBODY_POLLREP) { @@ -315,38 +316,41 @@ static int poll_for_response(OSSL_CMP_CTX *ctx, int sleep, int rid, ERR_raise(ERR_LIB_CMP, CMP_R_BAD_CHECKAFTER_IN_POLLREP); goto err; } - if (check_after < 0 || (uint64_t)check_after - > (sleep ? ULONG_MAX / 1000 : INT_MAX)) { + if (check_after < 0 || (uint64_t)check_after > (sleep ? ULONG_MAX / 1000 : INT_MAX)) { ERR_raise(ERR_LIB_CMP, CMP_R_CHECKAFTER_OUT_OF_RANGE); if (BIO_snprintf(str, OSSL_CMP_PKISI_BUFLEN, "value = %jd", - check_after) >= 0) + check_after) + >= 0) ERR_add_error_data(1, str); goto err; } if (pollRep->reason == NULL - || (len = BIO_snprintf(str, OSSL_CMP_PKISI_BUFLEN, - " with reason = '")) < 0) { + || (len = BIO_snprintf(str, OSSL_CMP_PKISI_BUFLEN, + " with reason = '")) + < 0) { *str = '\0'; } else { char *text = ossl_sk_ASN1_UTF8STRING2text(pollRep->reason, ", ", - sizeof(str) - len - 2); + sizeof(str) - len - 2); if (text == NULL - || BIO_snprintf(str + len, sizeof(str) - len, - "%s'", text) < 0) + || BIO_snprintf(str + len, sizeof(str) - len, + "%s'", text) + < 0) *str = '\0'; OPENSSL_free(text); } ossl_cmp_log2(INFO, ctx, - "received polling response%s; checkAfter = %ld seconds", - str, check_after); + "received polling response%s; checkAfter = %ld seconds", + str, check_after); if (ctx->total_timeout != 0) { /* timeout is not infinite */ const int exp = OSSL_CMP_EXPECTED_RESP_TIME; int64_t time_left = (int64_t)(ctx->end_time - exp - time(NULL)); if (time_left <= 0) { + ctx->status = OSSL_CMP_PKISTATUS_trans; ERR_raise(ERR_LIB_CMP, CMP_R_TOTAL_TIMEOUT); goto err; } @@ -367,18 +371,18 @@ static int poll_for_response(OSSL_CMP_CTX *ctx, int sleep, int rid, return -1; /* exits the loop */ } } else if (is_crep_with_waiting(prep, rid) - || ossl_cmp_is_error_with_waiting(prep)) { + || ossl_cmp_is_error_with_waiting(prep)) { /* received status must not be 'waiting' */ (void)ossl_cmp_exchange_error(ctx, OSSL_CMP_PKISTATUS_rejection, - OSSL_CMP_CTX_FAILINFO_badRequest, - "polling already started", - 0 /* errorCode */, NULL); + OSSL_CMP_CTX_FAILINFO_badRequest, + "polling already started", + 0 /* errorCode */, NULL); ERR_raise(ERR_LIB_CMP, CMP_R_UNEXPECTED_PKISTATUS); goto err; } else { ossl_cmp_info(ctx, "received final response after polling"); if (!ossl_cmp_ctx_set1_first_senderNonce(ctx, NULL)) - return 0; + goto err; break; } } @@ -389,7 +393,7 @@ static int poll_for_response(OSSL_CMP_CTX *ctx, int sleep, int rid, *rep = prep; return 1; - err: +err: (void)ossl_cmp_ctx_set1_first_senderNonce(ctx, NULL); OSSL_CMP_MSG_free(preq); OSSL_CMP_MSG_free(prep); @@ -397,7 +401,7 @@ static int poll_for_response(OSSL_CMP_CTX *ctx, int sleep, int rid, } static int save_senderNonce_if_waiting(OSSL_CMP_CTX *ctx, - const OSSL_CMP_MSG *rep, int rid) + const OSSL_CMP_MSG *rep, int rid) { /* * Lightweight CMP Profile section 4.4 states: the senderNonce of the @@ -405,7 +409,7 @@ static int save_senderNonce_if_waiting(OSSL_CMP_CTX *ctx, * the recipNonce of the final response to be received after polling. */ if ((is_crep_with_waiting(rep, rid) - || ossl_cmp_is_error_with_waiting(rep)) + || ossl_cmp_is_error_with_waiting(rep)) && !ossl_cmp_ctx_set1_first_senderNonce(ctx, ctx->senderNonce)) return 0; @@ -417,7 +421,7 @@ static int save_senderNonce_if_waiting(OSSL_CMP_CTX *ctx, * Polling for ip/cp/kup/ with 'waiting' status is handled by cert_response(). */ static int send_receive_also_delayed(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, - OSSL_CMP_MSG **rep, int expected_type) + OSSL_CMP_MSG **rep, int expected_type) { if (!send_receive_check(ctx, req, rep, expected_type)) @@ -435,7 +439,8 @@ static int send_receive_also_delayed(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, *rep = NULL; if (poll_for_response(ctx, 1 /* can sleep */, OSSL_CMP_CERTREQID_NONE, - rep, NULL /* checkAfter */) <= 0) { + rep, NULL /* checkAfter */) + <= 0) { ERR_raise(ERR_LIB_CMP, CMP_R_POLLING_FAILED); return 0; } @@ -452,21 +457,26 @@ static int send_receive_also_delayed(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, * not modifying ctx->status during the certConf exchange */ int ossl_cmp_exchange_certConf(OSSL_CMP_CTX *ctx, int certReqId, - int fail_info, const char *txt) + int fail_info, const char *txt) { OSSL_CMP_MSG *certConf; OSSL_CMP_MSG *PKIconf = NULL; int res = 0; + int bak = ctx->status; + ctx->status = OSSL_CMP_PKISTATUS_request; /* OSSL_CMP_certConf_new() also checks if all necessary options are set */ certConf = ossl_cmp_certConf_new(ctx, certReqId, fail_info, txt); if (certConf == NULL) goto err; res = send_receive_also_delayed(ctx, certConf, &PKIconf, - OSSL_CMP_PKIBODY_PKICONF); + OSSL_CMP_PKIBODY_PKICONF); + + if (res) + ctx->status = bak; - err: +err: OSSL_CMP_MSG_free(certConf); OSSL_CMP_MSG_free(PKIconf); return res; @@ -474,13 +484,14 @@ int ossl_cmp_exchange_certConf(OSSL_CMP_CTX *ctx, int certReqId, /* Send given error and check response */ int ossl_cmp_exchange_error(OSSL_CMP_CTX *ctx, int status, int fail_info, - const char *txt, int errorCode, const char *details) + const char *txt, int errorCode, const char *details) { OSSL_CMP_MSG *error = NULL; OSSL_CMP_PKISI *si = NULL; OSSL_CMP_MSG *PKIconf = NULL; int res = 0; + ctx->status = OSSL_CMP_PKISTATUS_request; /* not overwriting ctx->status on error exchange */ if ((si = OSSL_CMP_STATUSINFO_new(status, fail_info, txt)) == NULL) goto err; @@ -489,9 +500,10 @@ int ossl_cmp_exchange_error(OSSL_CMP_CTX *ctx, int status, int fail_info, goto err; res = send_receive_also_delayed(ctx, error, - &PKIconf, OSSL_CMP_PKIBODY_PKICONF); + &PKIconf, OSSL_CMP_PKIBODY_PKICONF); + ctx->status = OSSL_CMP_PKISTATUS_rejected_by_client; - err: +err: OSSL_CMP_MSG_free(error); OSSL_CMP_PKISI_free(si); OSSL_CMP_MSG_free(PKIconf); @@ -504,7 +516,7 @@ int ossl_cmp_exchange_error(OSSL_CMP_CTX *ctx, int status, int fail_info, * Returns NULL if not found or on error. */ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, - OSSL_CMP_CERTRESPONSE *crep) + OSSL_CMP_CERTRESPONSE *crep) { char buf[OSSL_CMP_PKISI_BUFLEN]; X509 *crt = NULL; @@ -515,7 +527,7 @@ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, switch (ossl_cmp_pkisi_get_status(crep->status)) { case OSSL_CMP_PKISTATUS_waiting: ossl_cmp_err(ctx, - "received \"waiting\" status for cert when actually aiming to extract cert"); + "received \"waiting\" status for cert when actually aiming to extract cert"); ERR_raise(ERR_LIB_CMP, CMP_R_ENCOUNTERED_WAITING); goto err; case OSSL_CMP_PKISTATUS_grantedWithMods: @@ -530,11 +542,11 @@ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, goto err; case OSSL_CMP_PKISTATUS_revocationWarning: ossl_cmp_warn(ctx, - "received \"revocationWarning\" - a revocation of the cert is imminent"); + "received \"revocationWarning\" - a revocation of the cert is imminent"); break; case OSSL_CMP_PKISTATUS_revocationNotification: ossl_cmp_warn(ctx, - "received \"revocationNotification\" - a revocation of the cert has occurred"); + "received \"revocationNotification\" - a revocation of the cert has occurred"); break; case OSSL_CMP_PKISTATUS_keyUpdateWarning: if (bodytype != OSSL_CMP_PKIBODY_KUR) { @@ -544,8 +556,8 @@ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, break; default: ossl_cmp_log1(ERROR, ctx, - "received unsupported PKIStatus %d for certificate", - ctx->status); + "received unsupported PKIStatus %d for certificate", + ctx->status); ERR_raise(ERR_LIB_CMP, CMP_R_UNKNOWN_PKISTATUS); goto err; } @@ -555,7 +567,7 @@ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, return crt; - err: +err: if (OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, sizeof(buf)) != NULL) ERR_add_error_data(1, buf); return NULL; @@ -566,11 +578,11 @@ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, * ctx->certConf_cb_arg, which has been initialized using opt_out_trusted, and * ctx->untrusted, which at this point already contains msg->extraCerts. * Returns 0 on acceptance, else a bit field reflecting PKIFailureInfo. - * Quoting from RFC 4210 section 5.1. Overall PKI Message: + * Quoting from RFC 9810 section 5.1. Overall PKI Message: * The extraCerts field can contain certificates that may be useful to * the recipient. For example, this can be used by a CA or RA to * present an end entity with certificates that it needs to verify its - * own new certificate (if, for example, the CA that issued the end + * own new certificate (for example, if the CA that issued the end * entity's certificate is not a root CA for the end entity). Note that * this field does not necessarily contain a certification path; the * recipient may have to sort, select from, or otherwise process the @@ -579,7 +591,7 @@ static X509 *get1_cert_status(OSSL_CMP_CTX *ctx, int bodytype, * an EE must be able to validate the certificates it gets enrolled. */ int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, - const char **text) + const char **text) { X509_STORE *out_trusted = OSSL_CMP_CTX_get_certConf_cb_arg(ctx); STACK_OF(X509) *chain = NULL; @@ -592,7 +604,7 @@ int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, if (out_trusted == NULL) { ossl_cmp_debug(ctx, "trying to build chain for newly enrolled cert"); chain = X509_build_chain(cert, ctx->untrusted, out_trusted, - 0, ctx->libctx, ctx->propq); + 0, ctx->libctx, ctx->propq); } else { X509_STORE_CTX *csc = X509_STORE_CTX_new_ex(ctx->libctx, ctx->propq); @@ -603,16 +615,16 @@ int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, goto err; /* disable any cert status/revocation checking etc. */ X509_VERIFY_PARAM_clear_flags(X509_STORE_CTX_get0_param(csc), - ~(X509_V_FLAG_USE_CHECK_TIME - | X509_V_FLAG_NO_CHECK_TIME - | X509_V_FLAG_PARTIAL_CHAIN - | X509_V_FLAG_POLICY_CHECK)); + ~(X509_V_FLAG_USE_CHECK_TIME + | X509_V_FLAG_NO_CHECK_TIME + | X509_V_FLAG_PARTIAL_CHAIN + | X509_V_FLAG_POLICY_CHECK)); if (X509_verify_cert(csc) <= 0) goto err; if (!ossl_x509_add_certs_new(&chain, X509_STORE_CTX_get0_chain(csc), - X509_ADD_FLAG_UP_REF | X509_ADD_FLAG_NO_DUP - | X509_ADD_FLAG_NO_SS)) { + X509_ADD_FLAG_UP_REF | X509_ADD_FLAG_NO_DUP + | X509_ADD_FLAG_NO_SS)) { sk_X509_free(chain); chain = NULL; } @@ -628,14 +640,14 @@ int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_incorrectData; } else { ossl_cmp_debug(ctx, - "success validating newly enrolled cert"); + "success validating newly enrolled cert"); } } else if (chain == NULL) { ossl_cmp_warn(ctx, "could not build approximate chain for newly enrolled cert, resorting to received extraCerts"); chain = OSSL_CMP_CTX_get1_extraCertsIn(ctx); } else { ossl_cmp_debug(ctx, - "success building approximate chain for newly enrolled cert"); + "success building approximate chain for newly enrolled cert"); } (void)ossl_cmp_ctx_set1_newChain(ctx, chain); OSSL_STACK_OF_X509_free(chain); @@ -652,9 +664,9 @@ int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, * Regardless of success, caller is responsible for freeing *resp (unless NULL). */ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, - OSSL_CMP_MSG **resp, int *checkAfter, - ossl_unused int req_type, - ossl_unused int expected_type) + OSSL_CMP_MSG **resp, int *checkAfter, + ossl_unused int req_type, + ossl_unused int expected_type) { EVP_PKEY *rkey = NULL; int fail_info = 0; /* no failure */ @@ -671,7 +683,7 @@ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, if (!ossl_assert(ctx != NULL)) return 0; - retry: +retry: rcvd_type = OSSL_CMP_MSG_get_bodytype(*resp); if (IS_CREP(rcvd_type)) { crepmsg = (*resp)->body->value.ip; /* same for cp and kup */ @@ -746,14 +758,14 @@ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, * to the context so that they can be retrieved if necessary */ if (crepmsg != NULL && crepmsg->caPubs != NULL - && !ossl_cmp_ctx_set1_caPubs(ctx, crepmsg->caPubs)) + && !ossl_cmp_ctx_set1_caPubs(ctx, crepmsg->caPubs)) return 0; subj = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0); rkey = ossl_cmp_ctx_get0_newPubkey(ctx); if (rkey != NULL /* X509_check_private_key() also works if rkey is just public key */ - && !(X509_check_private_key(ctx->newCert, rkey))) { + && !(X509_check_private_key(ctx->newCert, rkey))) { fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_incorrectData; txt = "public key in new certificate does not match our enrollment key"; /*- @@ -772,17 +784,17 @@ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, */ cb = ctx->certConf_cb != NULL ? ctx->certConf_cb : OSSL_CMP_certConf_cb; if ((fail_info = cb(ctx, ctx->newCert, fail_info, &txt)) != 0 - && txt == NULL) + && txt == NULL) txt = "CMP client did not accept it"; if (fail_info != 0) /* immediately log error before any certConf exchange */ ossl_cmp_log1(ERROR, ctx, - "rejecting newly enrolled cert with subject: %s", subj); + "rejecting newly enrolled cert with subject: %s", subj); /* * certConf exchange should better be moved to do_certreq_seq() such that * also more low-level errors with CertReqMessages get reported to server */ if (!ctx->disableConfirm - && !ossl_cmp_hdr_has_implicitConfirm((*resp)->header)) { + && !ossl_cmp_hdr_has_implicitConfirm((*resp)->header)) { if (!ossl_cmp_exchange_certConf(ctx, rid, fail_info, txt)) ret = 0; } @@ -790,9 +802,9 @@ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, /* not throwing failure earlier as transfer_cb may call ERR_clear_error() */ if (fail_info != 0) { ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_ACCEPTED, - "rejecting newly enrolled cert with subject: %s; %s", - subj, txt); - ctx->status = OSSL_CMP_PKISTATUS_rejection; + "rejecting newly enrolled cert with subject: %s; %s", + subj, txt); + ctx->status = OSSL_CMP_PKISTATUS_rejected_by_client; ret = 0; } OPENSSL_free(subj); @@ -800,8 +812,8 @@ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, } static int initial_certreq(OSSL_CMP_CTX *ctx, - int req_type, const OSSL_CRMF_MSG *crm, - OSSL_CMP_MSG **p_rep, int rep_type) + int req_type, const OSSL_CRMF_MSG *crm, + OSSL_CMP_MSG **p_rep, int rep_type) { OSSL_CMP_MSG *req; int res; @@ -814,14 +826,13 @@ static int initial_certreq(OSSL_CMP_CTX *ctx, if ((req = ossl_cmp_certreq_new(ctx, req_type, crm)) == NULL) return 0; - ctx->status = OSSL_CMP_PKISTATUS_trans; res = send_receive_check(ctx, req, p_rep, rep_type); OSSL_CMP_MSG_free(req); return res; } int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type, - const OSSL_CRMF_MSG *crm, int *checkAfter) + const OSSL_CRMF_MSG *crm, int *checkAfter) { OSSL_CMP_MSG *rep = NULL; int is_p10 = req_type == OSSL_CMP_PKIBODY_P10CR; @@ -839,20 +850,20 @@ int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type, goto err; if (!save_senderNonce_if_waiting(ctx, rep, rid)) - return 0; + goto err; } else { if (req_type < 0) return ossl_cmp_exchange_error(ctx, OSSL_CMP_PKISTATUS_rejection, - 0, "polling aborted", - 0 /* errorCode */, "by application"); + 0, "polling aborted", + 0 /* errorCode */, "by application"); res = poll_for_response(ctx, 0 /* no sleep */, rid, &rep, checkAfter); if (res <= 0) /* waiting or error */ return res; } res = cert_response(ctx, 0 /* no sleep */, rid, &rep, checkAfter, - req_type, rep_type); + req_type, rep_type); - err: +err: OSSL_CMP_MSG_free(rep); return res; } @@ -865,7 +876,7 @@ int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type, * Returns pointer to received certificate, or NULL if none was received. */ X509 *OSSL_CMP_exec_certreq(OSSL_CMP_CTX *ctx, int req_type, - const OSSL_CRMF_MSG *crm) + const OSSL_CRMF_MSG *crm) { OSSL_CMP_MSG *rep = NULL; int is_p10 = req_type == OSSL_CMP_PKIBODY_P10CR; @@ -882,14 +893,14 @@ X509 *OSSL_CMP_exec_certreq(OSSL_CMP_CTX *ctx, int req_type, goto err; if (!save_senderNonce_if_waiting(ctx, rep, rid)) - return 0; + goto err; if (cert_response(ctx, 1 /* sleep */, rid, &rep, NULL, req_type, rep_type) <= 0) goto err; result = ctx->newCert; - err: +err: OSSL_CMP_MSG_free(rep); return result; } @@ -920,7 +931,6 @@ int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx) if ((rr = ossl_cmp_rr_new(ctx)) == NULL) goto end; - ctx->status = OSSL_CMP_PKISTATUS_trans; if (!send_receive_also_delayed(ctx, rr, &rp, OSSL_CMP_PKIBODY_RP)) goto end; @@ -960,7 +970,7 @@ int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx) case OSSL_CMP_PKISTATUS_revocationNotification: /* interpretation as warning or error depends on CA */ ossl_cmp_warn(ctx, - "revocation accepted (PKIStatus=revocationNotification)"); + "revocation accepted (PKIStatus=revocationNotification)"); ret = 1; break; case OSSL_CMP_PKISTATUS_waiting: @@ -975,11 +985,9 @@ int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx) /* check any present CertId in optional revCerts field */ if (sk_OSSL_CRMF_CERTID_num(rrep->revCerts) >= 1) { OSSL_CRMF_CERTID *cid; - OSSL_CRMF_CERTTEMPLATE *tmpl = - sk_OSSL_CMP_REVDETAILS_value(rr->body->value.rr, rsid)->certDetails; + OSSL_CRMF_CERTTEMPLATE *tmpl = sk_OSSL_CMP_REVDETAILS_value(rr->body->value.rr, rsid)->certDetails; const X509_NAME *issuer = OSSL_CRMF_CERTTEMPLATE_get0_issuer(tmpl); - const ASN1_INTEGER *serial = - OSSL_CRMF_CERTTEMPLATE_get0_serialNumber(tmpl); + const ASN1_INTEGER *serial = OSSL_CRMF_CERTTEMPLATE_get0_serialNumber(tmpl); if (sk_OSSL_CRMF_CERTID_num(rrep->revCerts) != num_RevDetails) { ERR_raise(ERR_LIB_CMP, CMP_R_WRONG_RP_COMPONENT_COUNT); @@ -999,7 +1007,8 @@ int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx) #endif } if (ASN1_INTEGER_cmp(serial, - OSSL_CRMF_CERTID_get0_serialNumber(cid)) != 0) { + OSSL_CRMF_CERTID_get0_serialNumber(cid)) + != 0) { #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION ERR_raise(ERR_LIB_CMP, CMP_R_WRONG_SERIAL_IN_RP); ret = 0; @@ -1015,12 +1024,12 @@ int OSSL_CMP_exec_RR_ses(OSSL_CMP_CTX *ctx) goto err; } - err: +err: if (ret == 0 - && OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, sizeof(buf)) != NULL) + && OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, sizeof(buf)) != NULL) ERR_add_error_data(1, buf); - end: +end: OSSL_CMP_MSG_free(rr); OSSL_CMP_MSG_free(rp); return ret; @@ -1041,7 +1050,6 @@ STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses(OSSL_CMP_CTX *ctx) if ((genm = ossl_cmp_genm_new(ctx)) == NULL) goto err; - ctx->status = OSSL_CMP_PKISTATUS_trans; if (!send_receive_also_delayed(ctx, genm, &genp, OSSL_CMP_PKIBODY_GENP)) goto err; ctx->status = OSSL_CMP_PKISTATUS_accepted; @@ -1052,7 +1060,7 @@ STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses(OSSL_CMP_CTX *ctx) /* received stack of itavs not to be freed with the genp */ genp->body->value.genp = NULL; - err: +err: OSSL_CMP_MSG_free(genm); OSSL_CMP_MSG_free(genp); |
