Changeset View
Changeset View
Standalone View
Standalone View
crypto/cmp/cmp_client.c
Context not available. | |||||
break; | break; | ||||
default: | default: | ||||
if (IS_CREP(rcvd_type)) { | if (IS_CREP(rcvd_type)) { | ||||
int any_rid = OSSL_CMP_CERTREQID_NONE; | |||||
OSSL_CMP_CERTREPMESSAGE *crepmsg = rep->body->value.ip; | OSSL_CMP_CERTREPMESSAGE *crepmsg = rep->body->value.ip; | ||||
OSSL_CMP_CERTRESPONSE *crep = | OSSL_CMP_CERTRESPONSE *crep = | ||||
ossl_cmp_certrepmessage_get0_certresponse(crepmsg, | ossl_cmp_certrepmessage_get0_certresponse(crepmsg, any_rid); | ||||
-1 /* any rid */); | |||||
if (sk_OSSL_CMP_CERTRESPONSE_num(crepmsg->response) > 1) | if (sk_OSSL_CMP_CERTRESPONSE_num(crepmsg->response) > 1) | ||||
return -1; | return -1; | ||||
Context not available. | |||||
* Send certConf for IR, CR or KUR sequences and check response, | * Send certConf for IR, CR or KUR sequences and check response, | ||||
* not modifying ctx->status during the certConf exchange | * not modifying ctx->status during the certConf exchange | ||||
*/ | */ | ||||
int ossl_cmp_exchange_certConf(OSSL_CMP_CTX *ctx, int fail_info, | int ossl_cmp_exchange_certConf(OSSL_CMP_CTX *ctx, int certReqId, | ||||
const char *txt) | int fail_info, const char *txt) | ||||
{ | { | ||||
OSSL_CMP_MSG *certConf; | OSSL_CMP_MSG *certConf; | ||||
OSSL_CMP_MSG *PKIconf = NULL; | OSSL_CMP_MSG *PKIconf = NULL; | ||||
int res = 0; | int res = 0; | ||||
/* OSSL_CMP_certConf_new() also checks if all necessary options are set */ | /* OSSL_CMP_certConf_new() also checks if all necessary options are set */ | ||||
if ((certConf = ossl_cmp_certConf_new(ctx, fail_info, txt)) == NULL) | certConf = ossl_cmp_certConf_new(ctx, certReqId, fail_info, txt); | ||||
if (certConf == NULL) | |||||
goto err; | goto err; | ||||
res = send_receive_check(ctx, certConf, &PKIconf, OSSL_CMP_PKIBODY_PKICONF); | res = send_receive_check(ctx, certConf, &PKIconf, OSSL_CMP_PKIBODY_PKICONF); | ||||
Context not available. | |||||
{ | { | ||||
char buf[OSSL_CMP_PKISI_BUFLEN]; | char buf[OSSL_CMP_PKISI_BUFLEN]; | ||||
X509 *crt = NULL; | X509 *crt = NULL; | ||||
EVP_PKEY *privkey; | |||||
if (!ossl_assert(ctx != NULL && crep != NULL)) | if (!ossl_assert(ctx != NULL && crep != NULL)) | ||||
return NULL; | return NULL; | ||||
privkey = OSSL_CMP_CTX_get0_newPkey(ctx, 1); | |||||
switch (ossl_cmp_pkisi_get_status(crep->status)) { | switch (ossl_cmp_pkisi_get_status(crep->status)) { | ||||
case OSSL_CMP_PKISTATUS_waiting: | case OSSL_CMP_PKISTATUS_waiting: | ||||
ossl_cmp_err(ctx, | ossl_cmp_err(ctx, | ||||
Context not available. | |||||
ERR_raise(ERR_LIB_CMP, CMP_R_UNKNOWN_PKISTATUS); | ERR_raise(ERR_LIB_CMP, CMP_R_UNKNOWN_PKISTATUS); | ||||
goto err; | goto err; | ||||
} | } | ||||
crt = ossl_cmp_certresponse_get1_cert(crep, ctx, privkey); | crt = ossl_cmp_certresponse_get1_cert(ctx, crep); | ||||
if (crt == NULL) /* according to PKIStatus, we can expect a cert */ | if (crt == NULL) /* according to PKIStatus, we can expect a cert */ | ||||
ERR_raise(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_FOUND); | ERR_raise(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_FOUND); | ||||
Context not available. | |||||
if (fail_info != 0) /* accept any error flagged by CMP core library */ | if (fail_info != 0) /* accept any error flagged by CMP core library */ | ||||
return fail_info; | return fail_info; | ||||
ossl_cmp_debug(ctx, "trying to build chain for newly enrolled cert"); | if (out_trusted == NULL) { | ||||
chain = X509_build_chain(cert, ctx->untrusted, out_trusted /* maybe NULL */, | ossl_cmp_debug(ctx, "trying to build chain for newly enrolled cert"); | ||||
0, ctx->libctx, ctx->propq); | chain = X509_build_chain(cert, ctx->untrusted, out_trusted, | ||||
0, ctx->libctx, ctx->propq); | |||||
} else { | |||||
X509_STORE_CTX *csc = X509_STORE_CTX_new_ex(ctx->libctx, ctx->propq); | |||||
ossl_cmp_debug(ctx, "validating newly enrolled cert"); | |||||
if (csc == NULL) | |||||
goto err; | |||||
if (!X509_STORE_CTX_init(csc, out_trusted, cert, ctx->untrusted)) | |||||
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)); | |||||
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)) { | |||||
sk_X509_free(chain); | |||||
chain = NULL; | |||||
} | |||||
err: | |||||
X509_STORE_CTX_free(csc); | |||||
} | |||||
if (sk_X509_num(chain) > 0) | if (sk_X509_num(chain) > 0) | ||||
X509_free(sk_X509_shift(chain)); /* remove leaf (EE) cert */ | X509_free(sk_X509_shift(chain)); /* remove leaf (EE) cert */ | ||||
if (out_trusted != NULL) { | if (out_trusted != NULL) { | ||||
if (chain == NULL) { | if (chain == NULL) { | ||||
ossl_cmp_err(ctx, "failed building chain for newly enrolled cert"); | ossl_cmp_err(ctx, "failed to validate newly enrolled cert"); | ||||
fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_incorrectData; | fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_incorrectData; | ||||
} else { | } else { | ||||
ossl_cmp_debug(ctx, | ossl_cmp_debug(ctx, | ||||
"succeeded building proper chain for newly enrolled cert"); | "success validating newly enrolled cert"); | ||||
} | } | ||||
} else if (chain == NULL) { | } else if (chain == NULL) { | ||||
ossl_cmp_warn(ctx, "could not build approximate chain for newly enrolled cert, resorting to received extraCerts"); | ossl_cmp_warn(ctx, "could not build approximate chain for newly enrolled cert, resorting to received extraCerts"); | ||||
Context not available. | |||||
/*- | /*- | ||||
* Perform the generic handling of certificate responses for IR/CR/KUR/P10CR. | * Perform the generic handling of certificate responses for IR/CR/KUR/P10CR. | ||||
* |rid| must be OSSL_CMP_CERTREQID_NONE if not available, namely for p10cr | |||||
* Returns -1 on receiving pollRep if sleep == 0, setting the checkAfter value. | * Returns -1 on receiving pollRep if sleep == 0, setting the checkAfter value. | ||||
* Returns 1 on success and provides the received PKIMESSAGE in *resp. | * Returns 1 on success and provides the received PKIMESSAGE in *resp. | ||||
* Returns 0 on error (which includes the case that timeout has been reached). | * Returns 0 on error (which includes the case that timeout has been reached). | ||||
Context not available. | |||||
OSSL_CMP_MSG **resp, int *checkAfter, | OSSL_CMP_MSG **resp, int *checkAfter, | ||||
int req_type, int expected_type) | int req_type, int expected_type) | ||||
{ | { | ||||
EVP_PKEY *rkey = OSSL_CMP_CTX_get0_newPkey(ctx /* may be NULL */, 0); | EVP_PKEY *rkey = ossl_cmp_ctx_get0_newPubkey(ctx); | ||||
int fail_info = 0; /* no failure */ | int fail_info = 0; /* no failure */ | ||||
const char *txt = NULL; | const char *txt = NULL; | ||||
OSSL_CMP_CERTREPMESSAGE *crepmsg; | OSSL_CMP_CERTREPMESSAGE *crepmsg; | ||||
Context not available. | |||||
return 0; | return 0; | ||||
if (!save_statusInfo(ctx, crep->status)) | if (!save_statusInfo(ctx, crep->status)) | ||||
return 0; | return 0; | ||||
if (rid == -1) { | if (rid == OSSL_CMP_CERTREQID_NONE) { /* used for OSSL_CMP_PKIBODY_P10CR */ | ||||
/* for OSSL_CMP_PKIBODY_P10CR learn CertReqId from response */ | |||||
rid = ossl_cmp_asn1_get_int(crep->certReqId); | rid = ossl_cmp_asn1_get_int(crep->certReqId); | ||||
if (rid == -1) { | if (rid != OSSL_CMP_CERTREQID_NONE) { | ||||
ERR_raise(ERR_LIB_CMP, CMP_R_BAD_REQUEST_ID); | ERR_raise(ERR_LIB_CMP, CMP_R_BAD_REQUEST_ID); | ||||
return 0; | return 0; | ||||
} | } | ||||
Context not available. | |||||
"rejecting newly enrolled cert with subject: %s", subj); | "rejecting newly enrolled cert with subject: %s", subj); | ||||
if (!ctx->disableConfirm | if (!ctx->disableConfirm | ||||
&& !ossl_cmp_hdr_has_implicitConfirm((*resp)->header)) { | && !ossl_cmp_hdr_has_implicitConfirm((*resp)->header)) { | ||||
if (!ossl_cmp_exchange_certConf(ctx, fail_info, txt)) | if (!ossl_cmp_exchange_certConf(ctx, rid, fail_info, txt)) | ||||
ret = 0; | ret = 0; | ||||
} | } | ||||
Context not available. | |||||
ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_ACCEPTED, | ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_ACCEPTED, | ||||
"rejecting newly enrolled cert with subject: %s; %s", | "rejecting newly enrolled cert with subject: %s; %s", | ||||
subj, txt); | subj, txt); | ||||
ctx->status = OSSL_CMP_PKISTATUS_rejection; | |||||
ret = 0; | ret = 0; | ||||
} | } | ||||
OPENSSL_free(subj); | OPENSSL_free(subj); | ||||
Context not available. | |||||
{ | { | ||||
OSSL_CMP_MSG *rep = NULL; | OSSL_CMP_MSG *rep = NULL; | ||||
int is_p10 = req_type == OSSL_CMP_PKIBODY_P10CR; | int is_p10 = req_type == OSSL_CMP_PKIBODY_P10CR; | ||||
int rid = is_p10 ? -1 : OSSL_CMP_CERTREQID; | int rid = is_p10 ? OSSL_CMP_CERTREQID_NONE : OSSL_CMP_CERTREQID; | ||||
int rep_type = is_p10 ? OSSL_CMP_PKIBODY_CP : req_type + 1; | int rep_type = is_p10 ? OSSL_CMP_PKIBODY_CP : req_type + 1; | ||||
int res = 0; | int res = 0; | ||||
Context not available. | |||||
OSSL_CMP_MSG *rep = NULL; | OSSL_CMP_MSG *rep = NULL; | ||||
int is_p10 = req_type == OSSL_CMP_PKIBODY_P10CR; | int is_p10 = req_type == OSSL_CMP_PKIBODY_P10CR; | ||||
int rid = is_p10 ? -1 : OSSL_CMP_CERTREQID; | int rid = is_p10 ? OSSL_CMP_CERTREQID_NONE : OSSL_CMP_CERTREQID; | ||||
int rep_type = is_p10 ? OSSL_CMP_PKIBODY_CP : req_type + 1; | int rep_type = is_p10 ? OSSL_CMP_PKIBODY_CP : req_type + 1; | ||||
X509 *result = NULL; | X509 *result = NULL; | ||||
Context not available. |