version 1.10, 2022/11/11 17:07:38 |
version 1.11, 2023/03/06 14:32:05 |
|
|
int nocrl; |
int nocrl; |
char *outfile; |
char *outfile; |
int outformat; |
int outformat; |
} crl2p7_config; |
} cfg; |
|
|
static int |
static int |
crl2p7_opt_certfile(char *arg) |
crl2p7_opt_certfile(char *arg) |
{ |
{ |
if (crl2p7_config.certflst == NULL) |
if (cfg.certflst == NULL) |
crl2p7_config.certflst = sk_OPENSSL_STRING_new_null(); |
cfg.certflst = sk_OPENSSL_STRING_new_null(); |
if (crl2p7_config.certflst == NULL) { |
if (cfg.certflst == NULL) { |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
return (1); |
return (1); |
} |
} |
if (!sk_OPENSSL_STRING_push(crl2p7_config.certflst, arg)) { |
if (!sk_OPENSSL_STRING_push(cfg.certflst, arg)) { |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
return (1); |
return (1); |
} |
} |
|
|
.argname = "file", |
.argname = "file", |
.desc = "Input file (default stdin)", |
.desc = "Input file (default stdin)", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &crl2p7_config.infile, |
.opt.arg = &cfg.infile, |
}, |
}, |
{ |
{ |
.name = "inform", |
.name = "inform", |
.argname = "format", |
.argname = "format", |
.desc = "Input format (DER or PEM (default))", |
.desc = "Input format (DER or PEM (default))", |
.type = OPTION_ARG_FORMAT, |
.type = OPTION_ARG_FORMAT, |
.opt.value = &crl2p7_config.informat, |
.opt.value = &cfg.informat, |
}, |
}, |
{ |
{ |
.name = "nocrl", |
.name = "nocrl", |
.desc = "Do not read CRL from input or include CRL in output", |
.desc = "Do not read CRL from input or include CRL in output", |
.type = OPTION_FLAG, |
.type = OPTION_FLAG, |
.opt.flag = &crl2p7_config.nocrl, |
.opt.flag = &cfg.nocrl, |
}, |
}, |
{ |
{ |
.name = "out", |
.name = "out", |
.argname = "file", |
.argname = "file", |
.desc = "Output file (default stdout)", |
.desc = "Output file (default stdout)", |
.type = OPTION_ARG, |
.type = OPTION_ARG, |
.opt.arg = &crl2p7_config.outfile, |
.opt.arg = &cfg.outfile, |
}, |
}, |
{ |
{ |
.name = "outform", |
.name = "outform", |
.argname = "format", |
.argname = "format", |
.desc = "Output format (DER or PEM (default))", |
.desc = "Output format (DER or PEM (default))", |
.type = OPTION_ARG_FORMAT, |
.type = OPTION_ARG_FORMAT, |
.opt.value = &crl2p7_config.outformat, |
.opt.value = &cfg.outformat, |
}, |
}, |
{ NULL }, |
{ NULL }, |
}; |
}; |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
memset(&crl2p7_config, 0, sizeof(crl2p7_config)); |
memset(&cfg, 0, sizeof(cfg)); |
|
|
crl2p7_config.informat = FORMAT_PEM; |
cfg.informat = FORMAT_PEM; |
crl2p7_config.outformat = FORMAT_PEM; |
cfg.outformat = FORMAT_PEM; |
|
|
if (options_parse(argc, argv, crl2p7_options, NULL, NULL) != 0) { |
if (options_parse(argc, argv, crl2p7_options, NULL, NULL) != 0) { |
crl2p7_usage(); |
crl2p7_usage(); |
|
|
ERR_print_errors(bio_err); |
ERR_print_errors(bio_err); |
goto end; |
goto end; |
} |
} |
if (!crl2p7_config.nocrl) { |
if (!cfg.nocrl) { |
if (crl2p7_config.infile == NULL) |
if (cfg.infile == NULL) |
BIO_set_fp(in, stdin, BIO_NOCLOSE); |
BIO_set_fp(in, stdin, BIO_NOCLOSE); |
else { |
else { |
if (BIO_read_filename(in, crl2p7_config.infile) <= 0) { |
if (BIO_read_filename(in, cfg.infile) <= 0) { |
perror(crl2p7_config.infile); |
perror(cfg.infile); |
goto end; |
goto end; |
} |
} |
} |
} |
|
|
if (crl2p7_config.informat == FORMAT_ASN1) |
if (cfg.informat == FORMAT_ASN1) |
crl = d2i_X509_CRL_bio(in, NULL); |
crl = d2i_X509_CRL_bio(in, NULL); |
else if (crl2p7_config.informat == FORMAT_PEM) |
else if (cfg.informat == FORMAT_PEM) |
crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); |
crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); |
else { |
else { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |
|
|
goto end; |
goto end; |
p7s->cert = cert_stack; |
p7s->cert = cert_stack; |
|
|
if (crl2p7_config.certflst) { |
if (cfg.certflst) { |
for (i = 0; i < sk_OPENSSL_STRING_num(crl2p7_config.certflst); i++) { |
for (i = 0; i < sk_OPENSSL_STRING_num(cfg.certflst); i++) { |
certfile = sk_OPENSSL_STRING_value(crl2p7_config.certflst, i); |
certfile = sk_OPENSSL_STRING_value(cfg.certflst, i); |
if (add_certs_from_file(cert_stack, certfile) < 0) { |
if (add_certs_from_file(cert_stack, certfile) < 0) { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |
"error loading certificates\n"); |
"error loading certificates\n"); |
|
|
} |
} |
} |
} |
|
|
sk_OPENSSL_STRING_free(crl2p7_config.certflst); |
sk_OPENSSL_STRING_free(cfg.certflst); |
|
|
if (crl2p7_config.outfile == NULL) { |
if (cfg.outfile == NULL) { |
BIO_set_fp(out, stdout, BIO_NOCLOSE); |
BIO_set_fp(out, stdout, BIO_NOCLOSE); |
} else { |
} else { |
if (BIO_write_filename(out, crl2p7_config.outfile) <= 0) { |
if (BIO_write_filename(out, cfg.outfile) <= 0) { |
perror(crl2p7_config.outfile); |
perror(cfg.outfile); |
goto end; |
goto end; |
} |
} |
} |
} |
|
|
if (crl2p7_config.outformat == FORMAT_ASN1) |
if (cfg.outformat == FORMAT_ASN1) |
i = i2d_PKCS7_bio(out, p7); |
i = i2d_PKCS7_bio(out, p7); |
else if (crl2p7_config.outformat == FORMAT_PEM) |
else if (cfg.outformat == FORMAT_PEM) |
i = PEM_write_bio_PKCS7(out, p7); |
i = PEM_write_bio_PKCS7(out, p7); |
else { |
else { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |