@@ -64,7 +64,8 @@ typedef enum OPTION_choice {
64
64
OPT_DAYS , OPT_SET_SERIAL , OPT_STARTDATE , OPT_ENDDATE ,
65
65
OPT_ADDEXT , OPT_ACERTEXTS ,
66
66
OPT_SECTION ,
67
- OPT_PROV_ENUM , OPT_MD
67
+ OPT_PROV_ENUM , OPT_MD ,
68
+ OPT_ASSERTED_BEFORE , OPT_TARGET_CERT
68
69
} OPTION_CHOICE ;
69
70
70
71
const OPTIONS acert_options [] = {
@@ -104,6 +105,10 @@ const OPTIONS acert_options[] = {
104
105
"Additional cert extension key=value pair (may be given more than once)" },
105
106
{"acertexts" , OPT_ACERTEXTS , 's' ,
106
107
"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" },
107
112
108
113
OPT_SECTION ("Signing" ),
109
114
{"sigopt" , OPT_SIGOPT , 's' , "Signature parameter in n:v form" },
@@ -189,21 +194,25 @@ int acert_main(int argc, char **argv)
189
194
EVP_PKEY_CTX * genctx = NULL ;
190
195
STACK_OF (OPENSSL_STRING ) * pkeyopts = NULL , * sigopts = NULL ;
191
196
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 ;
193
202
X509_ACERT * acert = NULL ;
194
203
BIO * addext_bio = NULL ;
195
204
const char * infile = NULL , * AAfile = NULL , * AAkeyfile = NULL ;
196
- const char * holderfile = NULL ;
205
+ const char * holderfile = NULL , * targetfile = NULL ;
197
206
int hldr_basecertid = 0 , hldr_entity = 0 ;
198
207
char * outfile = NULL , * digest = NULL ;
199
208
char * keyalgstr = NULL , * p , * prog ;
200
209
char * passin = NULL , * passinarg = NULL ;
201
210
char * acert_exts = NULL ;
202
- X509_NAME * fsubj = NULL ;
211
+ X509_NAME * fsubj = NULL , * target_subj = NULL ;
203
212
char * template = default_config_file ;
204
213
OPTION_CHOICE o ;
205
214
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 ;
207
216
int informat = FORMAT_PEM , outformat = FORMAT_PEM , keyform = FORMAT_UNDEF ;
208
217
int verify = 0 , noout = 0 , text = 0 ;
209
218
unsigned long chtype = MBSTRING_ASC , certflag = 0 ;
@@ -310,6 +319,12 @@ int acert_main(int argc, char **argv)
310
319
case OPT_ENDDATE :
311
320
enddate = opt_arg ();
312
321
break ;
322
+ case OPT_ASSERTED_BEFORE :
323
+ asserted_before = 1 ;
324
+ break ;
325
+ case OPT_TARGET_CERT :
326
+ targetfile = opt_arg ();
327
+ break ;
313
328
case OPT_DAYS :
314
329
days = atoi (opt_arg ());
315
330
if (days < -1 ) {
@@ -559,15 +574,29 @@ int acert_main(int argc, char **argv)
559
574
}
560
575
561
576
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 ;
569
598
}
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 );
571
600
if (ret != X509_V_OK ) {
572
601
BIO_printf (bio_err , "Attribute certificate is invalid.\n" );
573
602
goto end ;
0 commit comments