Skip to content

Commit 66966e5

Browse files
Merge pull request #30 from TrustedComputingGroup/cli_fixes
Cli fixes
2 parents a1b86ec + 880a4e3 commit 66966e5

File tree

4 files changed

+131
-13
lines changed

4 files changed

+131
-13
lines changed

apps/acert.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ typedef enum OPTION_choice {
6464
OPT_DAYS, OPT_SET_SERIAL, OPT_STARTDATE, OPT_ENDDATE,
6565
OPT_ADDEXT, OPT_ACERTEXTS,
6666
OPT_SECTION,
67-
OPT_PROV_ENUM, OPT_MD
67+
OPT_PROV_ENUM, OPT_MD,
68+
OPT_ASSERTED_BEFORE, OPT_TARGET_CERT
6869
} OPTION_CHOICE;
6970

7071
const OPTIONS acert_options[] = {
@@ -104,6 +105,10 @@ const OPTIONS acert_options[] = {
104105
"Additional cert extension key=value pair (may be given more than once)"},
105106
{"acertexts", OPT_ACERTEXTS, 's',
106107
"Attribute certificate extension section (override value in config file)"},
108+
{"asserted-before", OPT_ASSERTED_BEFORE, '-',
109+
"Fail verification if the attribute certificate contains the singleUse extension."},
110+
{"target-cert", OPT_TARGET_CERT, '<',
111+
"The target certificate path to check against the targetingInformation extension"},
107112

108113
OPT_SECTION("Signing"),
109114
{"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"},
@@ -189,21 +194,25 @@ int acert_main(int argc, char **argv)
189194
EVP_PKEY_CTX *genctx = NULL;
190195
STACK_OF(OPENSSL_STRING) *pkeyopts = NULL, *sigopts = NULL;
191196
LHASH_OF(OPENSSL_STRING) *addexts = NULL;
192-
X509 *AAcert = NULL, *holder = NULL;
197+
X509 *AAcert = NULL, *holder = NULL, *target_x509 = NULL;
198+
TARGET_CERT *target_cert = NULL;
199+
OSSL_ISSUER_SERIAL *target_iss_ser = NULL;
200+
GENERAL_NAME *target_cert_name = NULL;
201+
TARGET *target = NULL;
193202
X509_ACERT *acert = NULL;
194203
BIO *addext_bio = NULL;
195204
const char *infile = NULL, *AAfile = NULL, *AAkeyfile = NULL;
196-
const char *holderfile = NULL;
205+
const char *holderfile = NULL, *targetfile = NULL;
197206
int hldr_basecertid = 0, hldr_entity = 0;
198207
char *outfile = NULL, *digest = NULL;
199208
char *keyalgstr = NULL, *p, *prog;
200209
char *passin = NULL, *passinarg = NULL;
201210
char *acert_exts = NULL;
202-
X509_NAME *fsubj = NULL;
211+
X509_NAME *fsubj = NULL, *target_subj = NULL;
203212
char *template = default_config_file;
204213
OPTION_CHOICE o;
205214
int days = DEFAULT_DAYS;
206-
int ret = 1, i = 0, newacert = 0, verbose = 0;
215+
int ret = 1, i = 0, newacert = 0, verbose = 0, asserted_before = 0;
207216
int informat = FORMAT_PEM, outformat = FORMAT_PEM, keyform = FORMAT_UNDEF;
208217
int verify = 0, noout = 0, text = 0;
209218
unsigned long chtype = MBSTRING_ASC, certflag = 0;
@@ -310,6 +319,12 @@ int acert_main(int argc, char **argv)
310319
case OPT_ENDDATE:
311320
enddate = opt_arg();
312321
break;
322+
case OPT_ASSERTED_BEFORE:
323+
asserted_before = 1;
324+
break;
325+
case OPT_TARGET_CERT:
326+
targetfile = opt_arg();
327+
break;
313328
case OPT_DAYS:
314329
days = atoi(opt_arg());
315330
if (days < -1) {
@@ -559,15 +574,29 @@ int acert_main(int argc, char **argv)
559574
}
560575

561576
if (verify) {
562-
if (holderfile == NULL) {
563-
BIO_printf(bio_err, "'-holder' option required to verify.\n");
564-
goto end;
565-
}
566-
if (holder == NULL) {
567-
BIO_printf(bio_err, "Holder certificate could not be loaded.\n");
568-
goto end;
577+
if (targetfile) {
578+
if ((target_x509 = load_cert_pass(targetfile, FORMAT_UNDEF, 1, passin,
579+
"target certificate")) == NULL)
580+
goto end;
581+
target_iss_ser = OSSL_ISSUER_SERIAL_new();
582+
if (OSSL_ISSUER_SERIAL_set1_issuer(target_iss_ser, X509_get_issuer_name(target_x509)) == 0)
583+
goto end;
584+
if (OSSL_ISSUER_SERIAL_set1_serial(target_iss_ser, X509_get_serialNumber(target_x509)) == 0)
585+
goto end;
586+
587+
target_cert_name = GENERAL_NAME_new();
588+
target_subj = X509_NAME_dup(X509_get_subject_name(target_x509));
589+
if (target_subj == NULL)
590+
goto end;
591+
GENERAL_NAME_set0_value(target_cert_name, GEN_DIRNAME, target_subj);
592+
target_cert = TARGET_CERT_new();
593+
target_cert->targetCertificate = target_iss_ser;
594+
target_cert->targetName = target_cert_name;
595+
target = TARGET_new();
596+
target->type = TGT_TARGET_CERT;
597+
target->choice.targetCert = target_cert;
569598
}
570-
ret = X509_attr_cert_verify_ex(acert, AAcert, holder, NULL, 0);
599+
ret = X509_attr_cert_verify_ex(acert, AAcert, holder, target, asserted_before);
571600
if (ret != X509_V_OK) {
572601
BIO_printf(bio_err, "Attribute certificate is invalid.\n");
573602
goto end;

doc/build.info

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,10 @@ DEPEND[html/man3/X509_add_cert.html]=man3/X509_add_cert.pod
28792879
GENERATE[html/man3/X509_add_cert.html]=man3/X509_add_cert.pod
28802880
DEPEND[man/man3/X509_add_cert.3]=man3/X509_add_cert.pod
28812881
GENERATE[man/man3/X509_add_cert.3]=man3/X509_add_cert.pod
2882+
DEPEND[html/man3/X509_attr_cert_verify.html]=man3/X509_attr_cert_verify.pod
2883+
GENERATE[html/man3/X509_attr_cert_verify.html]=man3/X509_attr_cert_verify.pod
2884+
DEPEND[man/man3/X509_attr_cert_verify.3]=man3/X509_attr_cert_verify.pod
2885+
GENERATE[man/man3/X509_attr_cert_verify.3]=man3/X509_attr_cert_verify.pod
28822886
DEPEND[html/man3/X509_check_ca.html]=man3/X509_check_ca.pod
28832887
GENERATE[html/man3/X509_check_ca.html]=man3/X509_check_ca.pod
28842888
DEPEND[man/man3/X509_check_ca.3]=man3/X509_check_ca.pod
@@ -3625,6 +3629,7 @@ html/man3/X509_STORE_new.html \
36253629
html/man3/X509_STORE_set_verify_cb_func.html \
36263630
html/man3/X509_VERIFY_PARAM_set_flags.html \
36273631
html/man3/X509_add_cert.html \
3632+
html/man3/X509_attr_cert_verify.html \
36283633
html/man3/X509_check_ca.html \
36293634
html/man3/X509_check_host.html \
36303635
html/man3/X509_check_issued.html \
@@ -4262,6 +4267,7 @@ man/man3/X509_STORE_new.3 \
42624267
man/man3/X509_STORE_set_verify_cb_func.3 \
42634268
man/man3/X509_VERIFY_PARAM_set_flags.3 \
42644269
man/man3/X509_add_cert.3 \
4270+
man/man3/X509_attr_cert_verify.3 \
42654271
man/man3/X509_check_ca.3 \
42664272
man/man3/X509_check_host.3 \
42674273
man/man3/X509_check_issued.3 \

doc/man1/openssl-acert.pod.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ B<openssl> B<acert>
2525
[B<-holder> I<filename>]
2626
[B<-use-holder-basecertid>]
2727
[B<-use-holder-name>]
28+
[B<-target-cert>]
29+
[B<-asserted-before>]
2830
[B<-AA> I<filename>|I<uri>]
2931
[B<-AAkey> I<filename>|I<uri>]
3032
[B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>]
@@ -121,6 +123,24 @@ holder in the new attribute certificate.
121123
Use the holder certificate's subject name to identify the holder
122124
in the new attribute certificate.
123125

126+
=item B<-target-cert> I<filename>
127+
128+
The target certificate file, from which a TARGET (using the targetCert
129+
alternative) is constructed and compared against the targets listed in the
130+
targetingInformation X.509v3 extension, if it is present. This argument takes
131+
effect if the B<acert> command is used with the B<-verify> option.
132+
133+
Verification will not fail if the targetingInformation extension does not
134+
exist in the verified attribute certificate, but it will fail if the extension
135+
is present and the target does not appear in the list of targets.
136+
137+
=item B<-asserted-before>
138+
139+
Specifies whether the verified attribute certificate has been asserted once
140+
before. If provided, this causes verification of an attribute certificate to
141+
fail if the singleUse X.509v3 extension is present. This argument only takes
142+
effect if the B<acert> command is used with the B<-verify> option.
143+
124144
=item B<-AA> I<filename>|I<uri>
125145

126146
Specifies the Attribute Authority certificate to be used for signing with the

doc/man3/X509_attr_cert_verify.pod

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
=pod
2+
3+
=head1 NAME
4+
5+
X509_attr_cert_verify, X509_attr_cert_verify_ex, acert_crl
6+
- attribute certificate verification functions
7+
8+
=head1 SYNOPSIS
9+
10+
int X509_attr_cert_verify(X509_ACERT *acert, X509 *issuer);
11+
int X509_attr_cert_verify_ex(X509_ACERT *acert, X509 *issuer, X509 *holder,
12+
TARGET *tgt, int asserted_before);
13+
int acert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509_ACERT *x);
14+
15+
=head1 DESCRIPTION
16+
17+
X509_attr_cert_verify verifies that the attribute ceritifcate B<acert> is signed
18+
by the issuer B<issuer> and that the attribute certificate is valid with
19+
respect to its validity times and its extensions. This function does B<not>
20+
verify the B<issuer> certificate.
21+
22+
X509_attr_cert_verify_ex is the extended form of X509_attr_cert_verify, which
23+
takes an optional B<holder> argument, B<tgt> argument, and B<asserted_before>
24+
argument.
25+
26+
If not B<NULL>, the subject and subject alternative names are extracted from
27+
the B<holder> public key certificate and compared against the holder field of
28+
the asserted attribute certificate, B<acert>.
29+
30+
If not B<NULL>, the target is checked against the list of permitted targets
31+
within the targetingInformation X.509v3 extension, if the extension is present.
32+
33+
If set to a truthy value, B<asserted_before> causes attribute certificate
34+
verification to fail if the singleUse X.509v3 extension is present.
35+
36+
acert_crl returns 1 if the attribute certificate B<x> is not revoked in the
37+
certificate revocation list B<crl>, some other integer otherwise.
38+
39+
=head1 NOTES
40+
41+
These functions verify an X.509 attribute certificate to varying degrees. None
42+
of them verify the corresponding public key certificate, but the public key
43+
certificates can just be verified using the normal OpenSSL verification
44+
functions.
45+
46+
=head1 RETURN VALUES
47+
48+
Both X509_attr_cert_verify and X509_attr_cert_verify_ex return X509_V_OK (0) if
49+
the attribute certificate is valid with respect to the supplied verification
50+
parameters, or some other X509_V_ERR_ value otherwise. As stated above,
51+
acert_crl returns 1 if the attribute certificate is not revoked in the provided
52+
certificate revocation list, and some other integer otherwise.
53+
54+
=head1 COPYRIGHT
55+
56+
Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
57+
58+
Licensed under the Apache License 2.0 (the "License"). You may not use
59+
this file except in compliance with the License. You can obtain a copy
60+
in the file LICENSE in the source distribution or at
61+
L<https://www.openssl.org/source/license.html>.
62+
63+
=cut

0 commit comments

Comments
 (0)