60 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_SHA1)
71 #define PROG pkcs12_main
85 int passlen,
int options,
char *pempass);
91 static int set_pbe(
BIO *err,
int *ppbe,
const char *str);
93 int MAIN(
int,
char **);
95 int MAIN(
int argc,
char **argv)
98 char *infile=NULL, *outfile=NULL, *keyname = NULL;
100 BIO *in=NULL, *out = NULL;
103 char *csp_name = NULL;
106 char pass[50], macpass[50];
121 char *cpass = NULL, *mpass = NULL;
122 char *passargin = NULL, *passargout = NULL, *passarg = NULL;
123 char *passin = NULL, *passout = NULL;
126 char *CApath = NULL, *CAfile = NULL;
127 #ifndef OPENSSL_NO_ENGINE
143 if (*args[0] ==
'-') {
144 if (!strcmp (*args,
"-nokeys")) options |=
NOKEYS;
145 else if (!strcmp (*args,
"-keyex")) keytype =
KEY_EX;
146 else if (!strcmp (*args,
"-keysig")) keytype =
KEY_SIG;
147 else if (!strcmp (*args,
"-nocerts")) options |=
NOCERTS;
148 else if (!strcmp (*args,
"-clcerts")) options |=
CLCERTS;
149 else if (!strcmp (*args,
"-cacerts")) options |=
CACERTS;
150 else if (!strcmp (*args,
"-noout")) options |= (
NOKEYS|
NOCERTS);
151 else if (!strcmp (*args,
"-info")) options |=
INFO;
152 else if (!strcmp (*args,
"-chain")) chain = 1;
153 else if (!strcmp (*args,
"-twopass")) twopass = 1;
154 else if (!strcmp (*args,
"-nomacver")) macver = 0;
155 else if (!strcmp (*args,
"-descert"))
157 else if (!strcmp (*args,
"-export")) export_cert = 1;
158 else if (!strcmp (*args,
"-des")) enc=
EVP_des_cbc();
160 #ifndef OPENSSL_NO_IDEA
163 #ifndef OPENSSL_NO_SEED
166 #ifndef OPENSSL_NO_AES
171 #ifndef OPENSSL_NO_CAMELLIA
176 else if (!strcmp (*args,
"-noiter")) iter = 1;
177 else if (!strcmp (*args,
"-maciter"))
179 else if (!strcmp (*args,
"-nomaciter"))
181 else if (!strcmp (*args,
"-nomac"))
183 else if (!strcmp (*args,
"-macalg"))
188 else if (!strcmp (*args,
"-nodes")) enc=NULL;
189 else if (!strcmp (*args,
"-certpbe")) {
190 if (!set_pbe(
bio_err, &cert_pbe, *++args))
192 }
else if (!strcmp (*args,
"-keypbe")) {
193 if (!set_pbe(
bio_err, &key_pbe, *++args))
195 }
else if (!strcmp (*args,
"-rand")) {
200 }
else if (!strcmp (*args,
"-inkey")) {
205 }
else if (!strcmp (*args,
"-certfile")) {
210 }
else if (!strcmp (*args,
"-name")) {
215 }
else if (!strcmp (*args,
"-LMK"))
217 else if (!strcmp (*args,
"-CSP")) {
222 }
else if (!strcmp (*args,
"-caname")) {
228 }
else if (!strcmp (*args,
"-in")) {
233 }
else if (!strcmp (*args,
"-out")) {
238 }
else if (!strcmp(*args,
"-passin")) {
243 }
else if (!strcmp(*args,
"-passout")) {
248 }
else if (!strcmp (*args,
"-password")) {
254 }
else if (!strcmp(*args,
"-CApath")) {
259 }
else if (!strcmp(*args,
"-CAfile")) {
264 #ifndef OPENSSL_NO_ENGINE
265 }
else if (!strcmp(*args,
"-engine")) {
287 BIO_printf (
bio_err,
"-caname \"nm\" use nm as CA friendly name (can be used more than once).\n");
299 #ifndef OPENSSL_NO_IDEA
302 #ifndef OPENSSL_NO_SEED
305 #ifndef OPENSSL_NO_AES
309 #ifndef OPENSSL_NO_CAMELLIA
319 BIO_printf (
bio_err,
"-descert encrypt PKCS#12 certificates with triple DES (default RC2-40)\n");
320 BIO_printf (
bio_err,
"-certpbe alg specify certificate PBE algorithm (default RC2-40)\n");
321 BIO_printf (
bio_err,
"-keypbe alg specify private key PBE algorithm (default 3DES)\n");
322 BIO_printf (
bio_err,
"-macalg alg digest algorithm used in MAC (default SHA1)\n");
328 #ifndef OPENSSL_NO_ENGINE
339 #ifndef OPENSSL_NO_ENGINE
344 if(export_cert) passargout = passarg;
345 else passargin = passarg;
354 if(export_cert) cpass = passout;
366 if(export_cert || inrand) {
382 infile ? infile :
"<stdin>");
394 #ifdef OPENSSL_SYS_VMS
403 outfile ? outfile :
"<stdout>");
423 X509 *ucert = NULL, *x = NULL;
425 const EVP_MD *macmd = NULL;
426 unsigned char *catmp = NULL;
456 if(!(options & NOCERTS))
500 "certificates from certfile")))
576 if (!twopass)
BUF_strlcpy(macpass, pass,
sizeof macpass);
584 key_pbe, cert_pbe, iter, -1, keytype);
623 if (ucert) X509_free(ucert);
648 if (!twopass)
BUF_strlcpy(macpass, pass,
sizeof macpass);
658 if(!twopass) cpass = NULL;
683 if (p12) PKCS12_free(p12);
698 int passlen,
int options,
char *pempass)
706 if (!( asafes = PKCS12_unpack_authsafes(p12)))
return 0;
711 bags = PKCS12_unpack_p7data(p7);
714 if (options & INFO) {
719 bags = PKCS12_unpack_p7encdata(p7, pass, passlen);
740 char *pass,
int passlen,
int options,
char *pempass)
754 int passlen,
int options,
char *pempass)
764 if (options & NOKEYS)
return 1;
774 if (options & INFO) {
778 if (options & NOKEYS)
return 1;
783 PKCS8_PRIV_KEY_INFO_free(p8);
787 PKCS8_PRIV_KEY_INFO_free(p8);
794 if (options & NOCERTS)
return 1;
796 if (options &
CACERTS)
return 1;
797 }
else if (options &
CLCERTS)
return 1;
803 PEM_write_bio_X509 (out, x509);
811 passlen, options, pempass);
846 chn = X509_STORE_CTX_get1_chain(&store_ctx);
857 const unsigned char *
p;
879 while((cert = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
905 BIO_printf(out,
"%s: <No Attributes>\n", name);
909 BIO_printf(out,
"%s: <Empty Attributes>\n", name);
959 static int set_pbe(
BIO *err,
int *ppbe,
const char *str)
963 if (!strcmp(str,
"NONE"))