Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMP app: fix combination of -certout and -chainout with equal filename arg #24267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions apps/cmp.c
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
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
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
4 changes: 3 additions & 1 deletion test/recipes/80-test_cmp_http_data/test_enrollment.csv
Expand Up @@ -66,7 +66,9 @@ expected,description, -section,val, -cmd,val, -newkey,val,val, -newkeypass,val,
1,disable_confirm, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, -disable_confirm,, -certout,_RESULT_DIR/test.certout_disable.pem,, -out_trusted,root.crt,,BLANK,,BLANK,,,
0,disable_confirm with parameter, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, -disable_confirm,abc, -certout,_RESULT_DIR/test.certout_disable1.pem,, -out_trusted,root.crt,,BLANK,,BLANK,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1,use certout (and chainout), -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, ,,, -out_trusted,root.crt,,BLANK,,BLANK,,,,-cert,_RESULT_DIR/test.certout_newkey.pem,-untrusted,_RESULT_DIR/test.chainout.pem
1,use certout (and chainout) , -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, ,,, -out_trusted,root.crt,,BLANK,,BLANK,,,,-cert,_RESULT_DIR/test.certout_newkey.pem,-untrusted,_RESULT_DIR/test.chainout.pem
1,certout and chainout sent to same file, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, ,,, -out_trusted,root.crt,,BLANK,,BLANK,,,,-certout,_RESULT_DIR/test.certout_chainout.pem,,-chainout,_RESULT_DIR/test.certout_chainout.pem
1,use certout and chainout from same file, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, ,,, -out_trusted,root.crt,,BLANK,,BLANK,,,,-cert,_RESULT_DIR/test.certout_chainout.pem,-untrusted,""""
0,no certout, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, -certout,"""",, -out_trusted,root.crt,,BLANK,,BLANK,,,
0,certout missing arg, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, -certout,,, -out_trusted,root.crt,,BLANK,,BLANK,,,
0,certout is non-existing directory and file, -section,, -cmd,ir, -newkey,new.key,, -newkeypass,pass:,,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,,BLANK,, -certout,idontexist/idontexist,, -out_trusted,root.crt,,BLANK,,BLANK,,,
Expand Down