static int save_certs(char *signerfile, STACK_OF(X509) * signers);
static int cms_cb(int ok, X509_STORE_CTX * ctx);
static void receipt_request_print(BIO * out, CMS_ContentInfo * cms);
-static CMS_ReceiptRequest *
- make_receipt_request(STACK_OF(OPENSSL_STRING) * rr_to,
- int rr_allorfirst,
+static CMS_ReceiptRequest * make_receipt_request(
+ STACK_OF(OPENSSL_STRING) * rr_to, int rr_allorfirst,
STACK_OF(OPENSSL_STRING) * rr_from);
#define SMIME_OP 0x10
if (signerfile) {
if (!sksigners)
- sksigners = sk_OPENSSL_STRING_new_null();
+ sksigners =
+ sk_OPENSSL_STRING_new_null();
sk_OPENSSL_STRING_push(sksigners, signerfile);
if (!keyfile)
keyfile = signerfile;
/* If previous -inkey arument add signer to list */
if (keyfile) {
if (!signerfile) {
- BIO_puts(bio_err, "Illegal -inkey without -signer\n");
+ BIO_puts(bio_err,
+ "Illegal -inkey without -signer\n");
goto argerr;
}
if (!sksigners)
- sksigners = sk_OPENSSL_STRING_new_null();
+ sksigners =
+ sk_OPENSSL_STRING_new_null();
sk_OPENSSL_STRING_push(sksigners, signerfile);
signerfile = NULL;
if (!skkeys)
sk_OPENSSL_STRING_push(skkeys, keyfile);
}
if (!sksigners) {
- BIO_printf(bio_err, "No signer certificate specified\n");
+ BIO_printf(bio_err,
+ "No signer certificate specified\n");
badarg = 1;
}
signerfile = NULL;
keyfile = NULL;
} else if (operation == SMIME_DECRYPT) {
if (!recipfile && !keyfile && !secret_key && !pwri_pass) {
- BIO_printf(bio_err, "No recipient certificate or key specified\n");
+ BIO_printf(bio_err,
+ "No recipient certificate or key specified\n");
badarg = 1;
}
} else if (operation == SMIME_ENCRYPT) {
if (!*args && !secret_key && !pwri_pass) {
- BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n");
+ BIO_printf(bio_err,
+ "No recipient(s) certificate(s) specified\n");
badarg = 1;
}
} else if (!operation)
encerts = sk_X509_new_null();
while (*args) {
if (!(cert = load_cert(bio_err, *args, FORMAT_PEM,
- NULL, e, "recipient certificate file")))
+ NULL, e, "recipient certificate file")))
goto end;
sk_X509_push(encerts, cert);
cert = NULL;
}
if (certfile) {
if (!(other = load_certs(bio_err, certfile, FORMAT_PEM, NULL,
- e, "certificate file"))) {
+ e, "certificate file"))) {
ERR_print_errors(bio_err);
goto end;
}
}
if (recipfile && (operation == SMIME_DECRYPT)) {
if (!(recip = load_cert(bio_err, recipfile, FORMAT_PEM, NULL,
- e, "recipient certificate file"))) {
+ e, "recipient certificate file"))) {
ERR_print_errors(bio_err);
goto end;
}
}
if (operation == SMIME_SIGN_RECEIPT) {
if (!(signer = load_cert(bio_err, signerfile, FORMAT_PEM, NULL,
- e, "receipt signer certificate file"))) {
+ e, "receipt signer certificate file"))) {
ERR_print_errors(bio_err);
goto end;
}
if (operation == SMIME_DECRYPT) {
if (!keyfile)
keyfile = recipfile;
- } else if ((operation == SMIME_SIGN) || (operation == SMIME_SIGN_RECEIPT)) {
+ } else if ((operation == SMIME_SIGN) ||
+ (operation == SMIME_SIGN_RECEIPT)) {
if (!keyfile)
keyfile = signerfile;
} else
if (contfile) {
BIO_free(indata);
if (!(indata = BIO_new_file(contfile, "rb"))) {
- BIO_printf(bio_err, "Can't read content file %s\n", contfile);
+ BIO_printf(bio_err,
+ "Can't read content file %s\n", contfile);
goto end;
}
}
out = BIO_new_fp(stdout, BIO_NOCLOSE);
}
- if ((operation == SMIME_VERIFY) || (operation == SMIME_VERIFY_RECEIPT)) {
+ if ((operation == SMIME_VERIFY) ||
+ (operation == SMIME_VERIFY_RECEIPT)) {
if (!(store = setup_verify(bio_err, CAfile, CApath)))
goto end;
X509_STORE_set_verify_cb(store, cms_cb);
if (!cms)
goto end;
if (secret_key) {
- if (!CMS_add0_recipient_key(cms, NID_undef,
- secret_key, secret_keylen,
- secret_keyid, secret_keyidlen,
- NULL, NULL, NULL))
+ if (!CMS_add0_recipient_key(cms, NID_undef, secret_key,
+ secret_keylen, secret_keyid, secret_keyidlen,
+ NULL, NULL, NULL))
goto end;
/* NULL these because call absorbs them */
secret_key = NULL;
secret_keyid = NULL;
}
if (pwri_pass) {
- pwri_tmp = (unsigned char *) BUF_strdup((char *) pwri_pass);
+ pwri_tmp =
+ (unsigned char *)BUF_strdup((char *)pwri_pass);
if (!pwri_tmp)
goto end;
- if (!CMS_add0_recipient_password(cms,
- -1, NID_undef, NID_undef,
- pwri_tmp, -1, NULL))
+ if (!CMS_add0_recipient_password(cms, -1, NID_undef,
+ NID_undef, pwri_tmp, -1, NULL))
goto end;
pwri_tmp = NULL;
}
goto end;
}
} else if (operation == SMIME_ENCRYPTED_ENCRYPT) {
- cms = CMS_EncryptedData_encrypt(in, cipher,
- secret_key, secret_keylen,
- flags);
+ cms = CMS_EncryptedData_encrypt(in, cipher, secret_key,
+ secret_keylen, flags);
} else if (operation == SMIME_SIGN_RECEIPT) {
CMS_ContentInfo *srcms = NULL;
CMS_SignerInfo *si;
signerfile = sk_OPENSSL_STRING_value(sksigners, i);
keyfile = sk_OPENSSL_STRING_value(skkeys, i);
- signer = load_cert(bio_err, signerfile, FORMAT_PEM, NULL,
- e, "signer certificate");
+ signer = load_cert(bio_err, signerfile, FORMAT_PEM,
+ NULL, e, "signer certificate");
if (!signer)
goto end;
key = load_key(bio_err, keyfile, keyform, 0, passin, e,
CMS_decrypt(cms, NULL, NULL, NULL, NULL, flags);
if (secret_key) {
- if (!CMS_decrypt_set1_key(cms,
- secret_key, secret_keylen,
- secret_keyid, secret_keyidlen)) {
+ if (!CMS_decrypt_set1_key(cms, secret_key,
+ secret_keylen, secret_keyid, secret_keyidlen)) {
BIO_puts(bio_err,
"Error decrypting CMS using secret key\n");
goto end;
}
} else if (operation == SMIME_ENCRYPTED_DECRYPT) {
if (!CMS_EncryptedData_decrypt(cms, secret_key, secret_keylen,
- indata, out, flags))
+ indata, out, flags))
goto end;
} else if (operation == SMIME_VERIFY) {
if (CMS_verify(cms, other, store, indata, out, flags) > 0)
}
}
ret = 0;
+
end:
if (ret)
ERR_print_errors(bio_err);
{
int i;
BIO *tmp;
+
if (!signerfile)
return 1;
tmp = BIO_new_file(signerfile, "w");
return 1;
}
-
/* Minimal callback just to output policy info (if any) */
static int
STACK_OF(GENERAL_NAME) * gens;
GENERAL_NAME *gen;
int i, j;
+
for (i = 0; i < sk_GENERAL_NAMES_num(gns); i++) {
gens = sk_GENERAL_NAMES_value(gns, i);
for (j = 0; j < sk_GENERAL_NAME_num(gens); j++) {
STACK_OF(GENERAL_NAMES) * rto, *rlist;
ASN1_STRING *scid;
int i, rv;
+
sis = CMS_get0_SignerInfos(cms);
for (i = 0; i < sk_CMS_SignerInfo_num(sis); i++) {
si = sk_CMS_SignerInfo_value(sis, i);
}
}
-static
-STACK_OF(GENERAL_NAMES) *
+static STACK_OF(GENERAL_NAMES) *
make_names_stack(STACK_OF(OPENSSL_STRING) * ns)
{
int i;
{
STACK_OF(GENERAL_NAMES) * rct_to, *rct_from;
CMS_ReceiptRequest *rr;
+
rct_to = make_names_stack(rr_to);
if (!rct_to)
goto err;
int informat, outformat;
char *infile = NULL, *outfile = NULL;
int hash = 0, issuer = 0, lastupdate = 0, nextupdate = 0, noout = 0,
- text = 0;
+ text = 0;
#ifndef OPENSSL_NO_MD5
int hash_old = 0;
#endif
if (lookup == NULL)
goto end;
if (!X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM))
- X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
+ X509_LOOKUP_load_file(lookup, NULL,
+ X509_FILETYPE_DEFAULT);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
if (lookup == NULL)
goto end;
if (!X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM))
- X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
+ X509_LOOKUP_add_dir(lookup, NULL,
+ X509_FILETYPE_DEFAULT);
ERR_clear_error();
if (!X509_STORE_CTX_init(&ctx, store, NULL, NULL)) {
if (num) {
for (i = 1; i <= num; i++) {
if (issuer == i) {
- print_name(bio_out, "issuer=", X509_CRL_get_issuer(x), nmflag);
+ print_name(bio_out, "issuer=",
+ X509_CRL_get_issuer(x), nmflag);
}
if (crlnumber == i) {
ASN1_INTEGER *crlnum;
- crlnum = X509_CRL_get_ext_d2i(x, NID_crl_number,
- NULL, NULL);
+ crlnum = X509_CRL_get_ext_d2i(x,
+ NID_crl_number, NULL, NULL);
BIO_printf(bio_out, "crlNumber=");
if (crlnum) {
i2a_ASN1_INTEGER(bio_out, crlnum);
#ifndef OPENSSL_NO_MD5
if (hash_old == i) {
BIO_printf(bio_out, "%08lx\n",
- X509_NAME_hash_old(
- X509_CRL_get_issuer(x)));
+ X509_NAME_hash_old(X509_CRL_get_issuer(x)));
}
#endif
if (lastupdate == i) {
OBJ_nid2sn(EVP_MD_type(digest)));
for (j = 0; j < (int) n; j++) {
BIO_printf(bio_out, "%02X%c", md[j],
- (j + 1 == (int) n) ? '\n' : ':');
+ (j + 1 == (int)n) ? '\n' : ':');
}
}
}
else if (outformat == FORMAT_PEM)
i = PEM_write_bio_X509_CRL(out, x);
else {
- BIO_printf(bio_err, "bad output format specified for outfile\n");
+ BIO_printf(bio_err,
+ "bad output format specified for outfile\n");
goto end;
}
if (!i) {
else if (format == FORMAT_PEM)
x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
else {
- BIO_printf(bio_err, "bad input format specified for input crl\n");
+ BIO_printf(bio_err,
+ "bad input format specified for input crl\n");
goto end;
}
if (x == NULL) {
ERR_print_errors(bio_err);
goto end;
}
+
end:
BIO_free(in);
return (x);