Add -quiet option to pkcs7 for -print_certs

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17708)
This commit is contained in:
Raul Ferrando 2022-02-15 16:02:41 +01:00 committed by Pauli
parent 42659159f4
commit 632e8be2b5
4 changed files with 60 additions and 5 deletions

View File

@ -23,8 +23,8 @@
typedef enum OPTION_choice {
OPT_COMMON,
OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_NOOUT,
OPT_TEXT, OPT_PRINT, OPT_PRINT_CERTS, OPT_ENGINE,
OPT_PROV_ENUM
OPT_TEXT, OPT_PRINT, OPT_PRINT_CERTS, OPT_QUIET,
OPT_ENGINE, OPT_PROV_ENUM
} OPTION_CHOICE;
const OPTIONS pkcs7_options[] = {
@ -46,6 +46,8 @@ const OPTIONS pkcs7_options[] = {
{"print", OPT_PRINT, '-', "Print out all fields of the PKCS7 structure"},
{"print_certs", OPT_PRINT_CERTS, '-',
"Print_certs print any certs or crl in the input"},
{"quiet", OPT_QUIET, '-',
"When used with -print_certs, it produces a cleaner output"},
OPT_PROV_OPTIONS,
{NULL}
@ -58,7 +60,7 @@ int pkcs7_main(int argc, char **argv)
BIO *in = NULL, *out = NULL;
int informat = FORMAT_PEM, outformat = FORMAT_PEM;
char *infile = NULL, *outfile = NULL, *prog;
int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, ret = 1;
int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, quiet = 0, ret = 1;
OPTION_CHOICE o;
OSSL_LIB_CTX *libctx = app_get0_libctx();
@ -100,6 +102,9 @@ int pkcs7_main(int argc, char **argv)
case OPT_PRINT_CERTS:
print_certs = 1;
break;
case OPT_QUIET:
quiet = 1;
break;
case OPT_ENGINE:
e = setup_engine(opt_arg(), 0);
break;
@ -171,7 +176,7 @@ int pkcs7_main(int argc, char **argv)
x = sk_X509_value(certs, i);
if (text)
X509_print(out, x);
else
else if (!quiet)
dump_cert_text(out, x);
if (!noout)

View File

@ -19,6 +19,7 @@ B<openssl> B<pkcs7>
[B<-out> I<filename>]
[B<-print>]
[B<-print_certs>]
[B<-quiet>]
[B<-text>]
[B<-noout>]
{- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_provider_synopsis -}
@ -63,6 +64,11 @@ Print out the full PKCS7 object.
Prints out any certificates or CRLs contained in the file. They are
preceded by their subject and issuer names in one line format.
=item B<-quiet>
When used with -print_certs, prints out just the PEM-encoded
certificates without any other output.
=item B<-text>
Prints out certificate details in full rather than just subject and

View File

@ -15,10 +15,15 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
setup("test_pkcs7");
plan tests => 3;
plan tests => 6;
require_ok(srctop_file('test','recipes','tconversion.pl'));
my @path = qw(test certs);
my $pemfile = "grfc.pem";
my $p7file = "grfc.p7b";
my $out = "grfc.out";
subtest 'pkcs7 conversions -- pkcs7' => sub {
tconversion( -type => 'p7', -in => srctop_file("test", "testp7.pem"),
-args => ["pkcs7"] );
@ -27,3 +32,11 @@ subtest 'pkcs7 conversions -- pkcs7d' => sub {
tconversion( -type => 'p7d', -in => srctop_file("test", "pkcs7-1.pem"),
-args => ["pkcs7"] );
};
ok(run(app(["openssl", "crl2pkcs7", "-nocrl",
"-certfile", srctop_file(@path, $pemfile),
"-out", $p7file])));
ok(run(app(["openssl", "pkcs7", "-print_certs", "-quiet",
"-in", $p7file,
"-out", $out])));
is(cmp_text($out, srctop_file('test', 'recipes', '25-test_pkcs7_data', 'grfc.out')),
0, 'Comparing output');

View File

@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFGDCCBMegAwIBAgIQDIxAk7vmk71DC/UYJgMdBTAIBgYqhQMCAgMwggEWMRgw
FgYFKoUDZAESDTEwMjc3MzkzMzQ0NzkxGjAYBggqhQMDgQMBARIMMDA3NzA2MjI4
MjE4MTowOAYDVQQJDDHQlNC10YDQsdC10L3QtdCy0YHQutCw0Y8g0L3QsNCxLiDQ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