version 1.11, 2019/11/04 15:31:08 |
version 1.12, 2019/11/04 15:33:48 |
|
|
|
|
#include <openssl/cms.h> |
#include <openssl/cms.h> |
|
|
static int save_certs(char *signerfile, STACK_OF(X509) * signers); |
static int save_certs(char *signerfile, STACK_OF(X509) *signers); |
static int cms_cb(int ok, X509_STORE_CTX * ctx); |
static int cms_cb(int ok, X509_STORE_CTX *ctx); |
static void receipt_request_print(BIO * out, CMS_ContentInfo * cms); |
static void receipt_request_print(BIO *out, CMS_ContentInfo *cms); |
static CMS_ReceiptRequest * make_receipt_request( |
static CMS_ReceiptRequest *make_receipt_request( |
STACK_OF(OPENSSL_STRING) * rr_to, int rr_allorfirst, |
STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst, |
STACK_OF(OPENSSL_STRING) * rr_from); |
STACK_OF(OPENSSL_STRING) *rr_from); |
|
|
#define SMIME_OP 0x10 |
#define SMIME_OP 0x10 |
#define SMIME_IP 0x20 |
#define SMIME_IP 0x20 |
|
|
const char *inmode = "r", *outmode = "w"; |
const char *inmode = "r", *outmode = "w"; |
char *infile = NULL, *outfile = NULL, *rctfile = NULL; |
char *infile = NULL, *outfile = NULL, *rctfile = NULL; |
char *signerfile = NULL, *recipfile = NULL; |
char *signerfile = NULL, *recipfile = NULL; |
STACK_OF(OPENSSL_STRING) * sksigners = NULL, *skkeys = NULL; |
STACK_OF(OPENSSL_STRING) *sksigners = NULL, *skkeys = NULL; |
char *certfile = NULL, *keyfile = NULL, *contfile = NULL; |
char *certfile = NULL, *keyfile = NULL, *contfile = NULL; |
char *certsoutfile = NULL; |
char *certsoutfile = NULL; |
const EVP_CIPHER *cipher = NULL; |
const EVP_CIPHER *cipher = NULL; |
|
|
X509_STORE *store = NULL; |
X509_STORE *store = NULL; |
X509 *cert = NULL, *recip = NULL, *signer = NULL; |
X509 *cert = NULL, *recip = NULL, *signer = NULL; |
EVP_PKEY *key = NULL; |
EVP_PKEY *key = NULL; |
STACK_OF(X509) * encerts = NULL, *other = NULL; |
STACK_OF(X509) *encerts = NULL, *other = NULL; |
BIO *in = NULL, *out = NULL, *indata = NULL, *rctin = NULL; |
BIO *in = NULL, *out = NULL, *indata = NULL, *rctin = NULL; |
int badarg = 0; |
int badarg = 0; |
int flags = CMS_DETACHED, noout = 0, print = 0; |
int flags = CMS_DETACHED, noout = 0, print = 0; |
int verify_retcode = 0; |
int verify_retcode = 0; |
int rr_print = 0, rr_allorfirst = -1; |
int rr_print = 0, rr_allorfirst = -1; |
STACK_OF(OPENSSL_STRING) * rr_to = NULL, *rr_from = NULL; |
STACK_OF(OPENSSL_STRING) *rr_to = NULL, *rr_from = NULL; |
CMS_ReceiptRequest *rr = NULL; |
CMS_ReceiptRequest *rr = NULL; |
char *to = NULL, *from = NULL, *subject = NULL; |
char *to = NULL, *from = NULL, *subject = NULL; |
char *CAfile = NULL, *CApath = NULL; |
char *CAfile = NULL, *CApath = NULL; |
|
|
} |
} |
} |
} |
if (certsoutfile) { |
if (certsoutfile) { |
STACK_OF(X509) * allcerts; |
STACK_OF(X509) *allcerts; |
allcerts = CMS_get1_certs(cms); |
allcerts = CMS_get1_certs(cms); |
if (!save_certs(certsoutfile, allcerts)) { |
if (!save_certs(certsoutfile, allcerts)) { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |
|
|
|
|
} else if (operation == SMIME_SIGN_RECEIPT) { |
} else if (operation == SMIME_SIGN_RECEIPT) { |
CMS_ContentInfo *srcms = NULL; |
CMS_ContentInfo *srcms = NULL; |
STACK_OF(CMS_SignerInfo) * sis; |
STACK_OF(CMS_SignerInfo) *sis; |
CMS_SignerInfo *si; |
CMS_SignerInfo *si; |
sis = CMS_get0_SignerInfos(cms); |
sis = CMS_get0_SignerInfos(cms); |
if (!sis) |
if (!sis) |
|
|
goto end; |
goto end; |
} |
} |
if (signerfile) { |
if (signerfile) { |
STACK_OF(X509) * signers; |
STACK_OF(X509) *signers; |
signers = CMS_get0_signers(cms); |
signers = CMS_get0_signers(cms); |
if (!save_certs(signerfile, signers)) { |
if (!save_certs(signerfile, signers)) { |
BIO_printf(bio_err, |
BIO_printf(bio_err, |
|
|
} |
} |
|
|
static int |
static int |
save_certs(char *signerfile, STACK_OF(X509) * signers) |
save_certs(char *signerfile, STACK_OF(X509) *signers) |
{ |
{ |
int i; |
int i; |
BIO *tmp; |
BIO *tmp; |
|
|
/* Minimal callback just to output policy info (if any) */ |
/* Minimal callback just to output policy info (if any) */ |
|
|
static int |
static int |
cms_cb(int ok, X509_STORE_CTX * ctx) |
cms_cb(int ok, X509_STORE_CTX *ctx) |
{ |
{ |
int error; |
int error; |
|
|
|
|
} |
} |
|
|
static void |
static void |
gnames_stack_print(BIO * out, STACK_OF(GENERAL_NAMES) * gns) |
gnames_stack_print(BIO *out, STACK_OF(GENERAL_NAMES) *gns) |
{ |
{ |
STACK_OF(GENERAL_NAME) * gens; |
STACK_OF(GENERAL_NAME) *gens; |
GENERAL_NAME *gen; |
GENERAL_NAME *gen; |
int i, j; |
int i, j; |
|
|
|
|
} |
} |
|
|
static void |
static void |
receipt_request_print(BIO * out, CMS_ContentInfo * cms) |
receipt_request_print(BIO *out, CMS_ContentInfo *cms) |
{ |
{ |
STACK_OF(CMS_SignerInfo) * sis; |
STACK_OF(CMS_SignerInfo) *sis; |
CMS_SignerInfo *si; |
CMS_SignerInfo *si; |
CMS_ReceiptRequest *rr; |
CMS_ReceiptRequest *rr; |
int allorfirst; |
int allorfirst; |
STACK_OF(GENERAL_NAMES) * rto, *rlist; |
STACK_OF(GENERAL_NAMES) *rto, *rlist; |
ASN1_STRING *scid; |
ASN1_STRING *scid; |
int i, rv; |
int i, rv; |
|
|
|
|
} |
} |
|
|
static STACK_OF(GENERAL_NAMES) * |
static STACK_OF(GENERAL_NAMES) * |
make_names_stack(STACK_OF(OPENSSL_STRING) * ns) |
make_names_stack(STACK_OF(OPENSSL_STRING) *ns) |
{ |
{ |
int i; |
int i; |
STACK_OF(GENERAL_NAMES) * ret; |
STACK_OF(GENERAL_NAMES) *ret; |
GENERAL_NAMES *gens = NULL; |
GENERAL_NAMES *gens = NULL; |
GENERAL_NAME *gen = NULL; |
GENERAL_NAME *gen = NULL; |
ret = sk_GENERAL_NAMES_new_null(); |
ret = sk_GENERAL_NAMES_new_null(); |
|
|
|
|
|
|
static CMS_ReceiptRequest * |
static CMS_ReceiptRequest * |
make_receipt_request(STACK_OF(OPENSSL_STRING) * rr_to, int rr_allorfirst, |
make_receipt_request(STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst, |
STACK_OF(OPENSSL_STRING) * rr_from) |
STACK_OF(OPENSSL_STRING) *rr_from) |
{ |
{ |
STACK_OF(GENERAL_NAMES) * rct_to, *rct_from; |
STACK_OF(GENERAL_NAMES) *rct_to, *rct_from; |
CMS_ReceiptRequest *rr; |
CMS_ReceiptRequest *rr; |
|
|
rct_to = make_names_stack(rr_to); |
rct_to = make_names_stack(rr_to); |