Skip to content

Commit

Permalink
CMP app: fix combination of -certout and -chainout with equal filenam…
Browse files Browse the repository at this point in the history
…e argument
  • Loading branch information
DDvO committed Apr 25, 2024
1 parent 15d6114 commit 1e7bec7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
27 changes: 21 additions & 6 deletions apps/cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3435,13 +3435,28 @@ int cmp_main(int argc, char **argv)
opt_extracertsout, "extra") < 0)
goto err;
if (newcert != NULL && (opt_cmd == CMP_IR || opt_cmd == CMP_CR
|| opt_cmd == CMP_KUR || opt_cmd == CMP_P10CR))
if (!save_cert_or_delete(newcert, opt_certout, "newly enrolled")
|| save_free_certs(OSSL_CMP_CTX_get1_newChain(cmp_ctx),
opt_chainout, "chain") < 0
|| save_free_certs(OSSL_CMP_CTX_get1_caPubs(cmp_ctx),
opt_cacertsout, "CA") < 0)
|| opt_cmd == CMP_KUR || opt_cmd == CMP_P10CR)) {
STACK_OF(X509) *newchain = OSSL_CMP_CTX_get1_newChain(cmp_ctx);

if (newcert != NULL && newchain != NULL /* NULL is on error only */
&& opt_certout != NULL && opt_chainout != NULL
&& strcmp(opt_certout, opt_chainout) == 0) {
if (!X509_add_cert(newchain, newcert, X509_ADD_FLAG_PREPEND
| X509_ADD_FLAG_UP_REF)) {
sk_X509_pop_free(newchain, X509_free);
goto err;
}
if (!save_free_certs(newchain, opt_chainout, "newly enrolled cert and chain"))
goto err;
} else {
if (save_free_certs(newchain, opt_chainout, "chain") < 0
|| !save_cert_or_delete(newcert, opt_certout, "newly enrolled"))
goto err;
}
if (save_free_certs(OSSL_CMP_CTX_get1_caPubs(cmp_ctx),
opt_cacertsout, "CA") < 0)
goto err;
}
if (!OSSL_CMP_CTX_reinit(cmp_ctx))
goto err;
}
Expand Down
6 changes: 6 additions & 0 deletions doc/man1/openssl-cmp.pod.in
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ The file where any newly enrolled certificate should be saved.
=item B<-chainout> I<filename>

The file where the chain of any newly enrolled certificate should be saved.
This chain excludes the leaf certificate, i.e., the newly enrolled certificate.
Also the trust anchor (the root certificate) is not included.

If the B<-certout> option is given, too, with equal I<filename> argument,
then the file produced contains both outputs concatenated:
the newly enrolled certificate followed by its chain.

=back

Expand Down
2 changes: 2 additions & 0 deletions doc/man3/OSSL_CMP_CTX_new.pod
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ If the callback argument is NULL the function tries building an approximate
chain as far as possible using the same untrusted certificates from the I<ctx>,
and if this fails it takes the received extraCerts as fallback.
The resulting cert chain can be retrieved using OSSL_CMP_CTX_get1_newChain().
This chain excludes the leaf certificate, i.e., the newly enrolled certificate.
Also the trust anchor (the root certificate) is not included.

OSSL_CMP_CTX_set_certConf_cb() sets the callback used for evaluating the newly
enrolled certificate before the library sends, depending on its result,
Expand Down

0 comments on commit 1e7bec7

Please sign in to comment.