2 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
59 #include <openssl/opensslconf.h>
60 #if !defined(OPENSSL_NO_DES)
66 # include <openssl/crypto.h>
67 # include <openssl/err.h>
68 # include <openssl/pem.h>
69 # include <openssl/pkcs12.h>
77 static int get_cert_chain(X509 *cert, X509_STORE *store,
78 STACK_OF(X509) **chain);
79 int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int passlen,
80 int options, char *pempass, const EVP_CIPHER *enc);
81 int dump_certs_pkeys_bags(BIO *out, STACK_OF(PKCS12_SAFEBAG) *bags,
82 char *pass, int passlen, int options, char *pempass,
83 const EVP_CIPHER *enc);
84 int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bags, char *pass,
85 int passlen, int options, char *pempass,
86 const EVP_CIPHER *enc);
87 int print_attribs(BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst,
89 void hex_prin(BIO *out, unsigned char *buf, int len);
90 static int alg_print(X509_ALGOR *alg);
91 int cert_load(BIO *in, STACK_OF(X509) *sk);
92 static int set_pbe(int *ppbe, const char *str);
94 typedef enum OPTION_choice {
95 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
96 OPT_CIPHER, OPT_NOKEYS, OPT_KEYEX, OPT_KEYSIG, OPT_NOCERTS, OPT_CLCERTS,
97 OPT_CACERTS, OPT_NOOUT, OPT_INFO, OPT_CHAIN, OPT_TWOPASS, OPT_NOMACVER,
98 OPT_DESCERT, OPT_EXPORT, OPT_NOITER, OPT_MACITER, OPT_NOMACITER,
99 OPT_NOMAC, OPT_LMK, OPT_NODES, OPT_MACALG, OPT_CERTPBE, OPT_KEYPBE,
100 OPT_RAND, OPT_INKEY, OPT_CERTFILE, OPT_NAME, OPT_CSP, OPT_CANAME,
101 OPT_IN, OPT_OUT, OPT_PASSIN, OPT_PASSOUT, OPT_PASSWORD, OPT_CAPATH,
102 OPT_CAFILE, OPT_NOCAPATH, OPT_NOCAFILE, OPT_ENGINE
105 OPTIONS pkcs12_options[] = {
106 {"help", OPT_HELP, '-', "Display this summary"},
107 {"nokeys", OPT_NOKEYS, '-', "Don't output private keys"},
108 {"keyex", OPT_KEYEX, '-', "Set MS key exchange type"},
109 {"keysig", OPT_KEYSIG, '-', "Set MS key signature type"},
110 {"nocerts", OPT_NOCERTS, '-', "Don't output certificates"},
111 {"clcerts", OPT_CLCERTS, '-', "Only output client certificates"},
112 {"cacerts", OPT_CACERTS, '-', "Only output CA certificates"},
113 {"noout", OPT_NOOUT, '-', "Don't output anything, just verify"},
114 {"info", OPT_INFO, '-', "Print info about PKCS#12 structure"},
115 {"chain", OPT_CHAIN, '-', "Add certificate chain"},
116 {"twopass", OPT_TWOPASS, '-', "Separate MAC, encryption passwords"},
117 {"nomacver", OPT_NOMACVER, '-', "Don't verify MAC"},
118 # ifndef OPENSSL_NO_RC2
119 {"descert", OPT_DESCERT, '-',
120 "Encrypt output with 3DES (default RC2-40)"},
121 {"certpbe", OPT_CERTPBE, 's',
122 "Certificate PBE algorithm (default RC2-40)"},
124 {"descert", OPT_DESCERT, '-', "Encrypt output with 3DES (the default)"},
125 {"certpbe", OPT_CERTPBE, 's', "Certificate PBE algorithm (default 3DES)"},
127 {"export", OPT_EXPORT, '-', "Output PKCS12 file"},
128 {"noiter", OPT_NOITER, '-', "Don't use encryption iteration"},
129 {"maciter", OPT_MACITER, '-', "Use MAC iteration"},
130 {"nomaciter", OPT_NOMACITER, '-', "Don't use MAC iteration"},
131 {"nomac", OPT_NOMAC, '-', "Don't generate MAC"},
132 {"LMK", OPT_LMK, '-',
133 "Add local machine keyset attribute to private key"},
134 {"nodes", OPT_NODES, '-', "Don't encrypt private keys"},
135 {"macalg", OPT_MACALG, 's',
136 "Digest algorithm used in MAC (default SHA1)"},
137 {"keypbe", OPT_KEYPBE, 's', "Private key PBE algorithm (default 3DES)"},
138 {"rand", OPT_RAND, 's',
139 "Load the file(s) into the random number generator"},
140 {"inkey", OPT_INKEY, '<', "Private key if not infile"},
141 {"certfile", OPT_CERTFILE, '<', "Load certs from file"},
142 {"name", OPT_NAME, 's', "Use name as friendly name"},
143 {"CSP", OPT_CSP, 's', "Microsoft CSP name"},
144 {"caname", OPT_CANAME, 's',
145 "Use name as CA friendly name (can be repeated)"},
146 {"in", OPT_IN, '<', "Input filename"},
147 {"out", OPT_OUT, '>', "Output filename"},
148 {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
149 {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
150 {"password", OPT_PASSWORD, 's', "Set import/export password source"},
151 {"CApath", OPT_CAPATH, '/', "PEM-format directory of CA's"},
152 {"CAfile", OPT_CAFILE, '<', "PEM-format file of CA's"},
153 {"no-CAfile", OPT_NOCAFILE, '-',
154 "Do not load the default certificates file"},
155 {"no-CApath", OPT_NOCAPATH, '-',
156 "Do not load certificates from the default certificates directory"},
157 {"", OPT_CIPHER, '-', "Any supported cipher"},
158 # ifndef OPENSSL_NO_ENGINE
159 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
164 int pkcs12_main(int argc, char **argv)
166 char *infile = NULL, *outfile = NULL, *keyname = NULL, *certfile = NULL;
167 char *name = NULL, *csp_name = NULL;
168 char pass[2048], macpass[2048];
169 int export_cert = 0, options = 0, chain = 0, twopass = 0, keytype = 0;
170 int iter = PKCS12_DEFAULT_ITER, maciter = PKCS12_DEFAULT_ITER;
171 # ifndef OPENSSL_NO_RC2
172 int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
174 int cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
176 int key_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
177 int ret = 1, macver = 1, noprompt = 0, add_lmk = 0, private = 0;
178 char *passinarg = NULL, *passoutarg = NULL, *passarg = NULL;
179 char *passin = NULL, *passout = NULL, *inrand = NULL, *macalg = NULL;
180 char *cpass = NULL, *mpass = NULL, *CApath = NULL, *CAfile = NULL;
182 int noCApath = 0, noCAfile = 0;
184 BIO *in = NULL, *out = NULL;
186 STACK_OF(OPENSSL_STRING) *canames = NULL;
187 const EVP_CIPHER *enc = EVP_des_ede3_cbc();
190 prog = opt_init(argc, argv, pkcs12_options);
191 while ((o = opt_next()) != OPT_EOF) {
196 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
199 opt_help(pkcs12_options);
221 options |= (NOKEYS | NOCERTS);
236 cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
242 if (!opt_cipher(opt_unknown(), &enc))
249 maciter = PKCS12_DEFAULT_ITER;
264 if (!set_pbe(&cert_pbe, opt_arg()))
268 if (!set_pbe(&key_pbe, opt_arg()))
278 certfile = opt_arg();
287 csp_name = opt_arg();
291 && (canames = sk_OPENSSL_STRING_new_null()) == NULL)
293 sk_OPENSSL_STRING_push(canames, opt_arg());
302 passinarg = opt_arg();
305 passoutarg = opt_arg();
323 e = setup_engine(opt_arg(), 0);
327 argc = opt_num_rest();
333 passoutarg = passarg;
338 if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
339 BIO_printf(bio_err, "Error getting passwords\n");
358 if (export_cert || inrand) {
359 app_RAND_load_file(NULL, (inrand != NULL));
361 BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
362 app_RAND_load_files(inrand));
366 if (EVP_read_pw_string
367 (macpass, sizeof macpass, "Enter MAC Password:", export_cert)) {
368 BIO_printf(bio_err, "Can't read Password\n");
374 EVP_PKEY *key = NULL;
375 X509 *ucert = NULL, *x = NULL;
376 STACK_OF(X509) *certs = NULL;
377 const EVP_MD *macmd = NULL;
378 unsigned char *catmp = NULL;
381 if ((options & (NOCERTS | NOKEYS)) == (NOCERTS | NOKEYS)) {
382 BIO_printf(bio_err, "Nothing to do!\n");
386 if (options & NOCERTS)
389 if (!(options & NOKEYS)) {
390 key = load_key(keyname ? keyname : infile,
391 FORMAT_PEM, 1, passin, e, "private key");
396 /* Load in all certs in input file */
397 if (!(options & NOCERTS)) {
398 if (!load_certs(infile, &certs, FORMAT_PEM, NULL, e,
403 /* Look for matching private key */
404 for (i = 0; i < sk_X509_num(certs); i++) {
405 x = sk_X509_value(certs, i);
406 if (X509_check_private_key(x, key)) {
408 /* Zero keyid and alias */
409 X509_keyid_set1(ucert, NULL, 0);
410 X509_alias_set1(ucert, NULL, 0);
411 /* Remove from list */
412 (void)sk_X509_delete(certs, i);
418 "No certificate matches private key\n");
425 /* Add any more certificates asked for */
427 if (!load_certs(certfile, &certs, FORMAT_PEM, NULL, e,
428 "certificates from certfile"))
432 /* If chaining get chain from user cert */
435 STACK_OF(X509) *chain2;
437 if ((store = setup_verify(CAfile, CApath, noCAfile, noCApath))
441 vret = get_cert_chain(ucert, store, &chain2);
442 X509_STORE_free(store);
444 if (vret == X509_V_OK) {
445 /* Exclude verified certificate */
446 for (i = 1; i < sk_X509_num(chain2); i++)
447 sk_X509_push(certs, sk_X509_value(chain2, i));
448 /* Free first certificate */
449 X509_free(sk_X509_value(chain2, 0));
450 sk_X509_free(chain2);
452 if (vret != X509_V_ERR_UNSPECIFIED)
453 BIO_printf(bio_err, "Error %s getting chain.\n",
454 X509_verify_cert_error_string(vret));
456 ERR_print_errors(bio_err);
461 /* Add any CA names */
463 for (i = 0; i < sk_OPENSSL_STRING_num(canames); i++) {
464 catmp = (unsigned char *)sk_OPENSSL_STRING_value(canames, i);
465 X509_alias_set1(sk_X509_value(certs, i), catmp, -1);
469 EVP_PKEY_add1_attr_by_NID(key, NID_ms_csp_name,
470 MBSTRING_ASC, (unsigned char *)csp_name,
474 EVP_PKEY_add1_attr_by_NID(key, NID_LocalKeySet, 0, NULL, -1);
477 EVP_read_pw_string(pass, sizeof pass, "Enter Export Password:",
479 BIO_printf(bio_err, "Can't read Password\n");
483 OPENSSL_strlcpy(macpass, pass, sizeof macpass);
485 p12 = PKCS12_create(cpass, name, key, ucert, certs,
486 key_pbe, cert_pbe, iter, -1, keytype);
489 ERR_print_errors(bio_err);
494 if (!opt_md(macalg, &macmd))
499 PKCS12_set_mac(p12, mpass, -1, NULL, 0, maciter, macmd);
503 out = bio_open_owner(outfile, FORMAT_PKCS12, private);
507 i2d_PKCS12_bio(out, p12);
514 sk_X509_pop_free(certs, X509_free);
521 in = bio_open_default(infile, 'r', FORMAT_PKCS12);
524 out = bio_open_owner(outfile, FORMAT_PEM, private);
528 if ((p12 = d2i_PKCS12_bio(in, NULL)) == NULL) {
529 ERR_print_errors(bio_err);
534 && EVP_read_pw_string(pass, sizeof pass, "Enter Import Password:",
536 BIO_printf(bio_err, "Can't read Password\n");
541 OPENSSL_strlcpy(macpass, pass, sizeof macpass);
543 if ((options & INFO) && p12->mac)
544 BIO_printf(bio_err, "MAC Iteration %ld\n",
545 p12->mac->iter ? ASN1_INTEGER_get(p12->mac->iter) : 1);
547 /* If we enter empty password try no password first */
548 if (!mpass[0] && PKCS12_verify_mac(p12, NULL, 0)) {
549 /* If mac and crypto pass the same set it to NULL too */
552 } else if (!PKCS12_verify_mac(p12, mpass, -1)) {
553 BIO_printf(bio_err, "Mac verify error: invalid password?\n");
554 ERR_print_errors(bio_err);
560 if (!dump_certs_keys_p12(out, p12, cpass, -1, options, passout, enc)) {
561 BIO_printf(bio_err, "Error outputting keys and certificates\n");
562 ERR_print_errors(bio_err);
568 if (export_cert || inrand)
569 app_RAND_write_file(NULL);
572 sk_OPENSSL_STRING_free(canames);
573 OPENSSL_free(passin);
574 OPENSSL_free(passout);
578 int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass,
579 int passlen, int options, char *pempass,
580 const EVP_CIPHER *enc)
582 STACK_OF(PKCS7) *asafes = NULL;
583 STACK_OF(PKCS12_SAFEBAG) *bags;
588 if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL)
590 for (i = 0; i < sk_PKCS7_num(asafes); i++) {
591 p7 = sk_PKCS7_value(asafes, i);
592 bagnid = OBJ_obj2nid(p7->type);
593 if (bagnid == NID_pkcs7_data) {
594 bags = PKCS12_unpack_p7data(p7);
596 BIO_printf(bio_err, "PKCS7 Data\n");
597 } else if (bagnid == NID_pkcs7_encrypted) {
598 if (options & INFO) {
599 BIO_printf(bio_err, "PKCS7 Encrypted data: ");
600 alg_print(p7->d.encrypted->enc_data->algorithm);
602 bags = PKCS12_unpack_p7encdata(p7, pass, passlen);
607 if (!dump_certs_pkeys_bags(out, bags, pass, passlen,
608 options, pempass, enc)) {
609 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
612 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
618 sk_PKCS7_pop_free(asafes, PKCS7_free);
622 int dump_certs_pkeys_bags(BIO *out, STACK_OF(PKCS12_SAFEBAG) *bags,
623 char *pass, int passlen, int options, char *pempass,
624 const EVP_CIPHER *enc)
627 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
628 if (!dump_certs_pkeys_bag(out,
629 sk_PKCS12_SAFEBAG_value(bags, i),
630 pass, passlen, options, pempass, enc))
636 int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass,
637 int passlen, int options, char *pempass,
638 const EVP_CIPHER *enc)
641 PKCS8_PRIV_KEY_INFO *p8;
644 switch (M_PKCS12_bag_type(bag)) {
647 BIO_printf(bio_err, "Key bag\n");
648 if (options & NOKEYS)
650 print_attribs(out, bag->attrib, "Bag Attributes");
651 p8 = bag->value.keybag;
652 if ((pkey = EVP_PKCS82PKEY(p8)) == NULL)
654 print_attribs(out, p8->attributes, "Key Attributes");
655 PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, pempass);
659 case NID_pkcs8ShroudedKeyBag:
660 if (options & INFO) {
661 BIO_printf(bio_err, "Shrouded Keybag: ");
662 alg_print(bag->value.shkeybag->algor);
664 if (options & NOKEYS)
666 print_attribs(out, bag->attrib, "Bag Attributes");
667 if ((p8 = PKCS12_decrypt_skey(bag, pass, passlen)) == NULL)
669 if ((pkey = EVP_PKCS82PKEY(p8)) == NULL) {
670 PKCS8_PRIV_KEY_INFO_free(p8);
673 print_attribs(out, p8->attributes, "Key Attributes");
674 PKCS8_PRIV_KEY_INFO_free(p8);
675 PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, pempass);
681 BIO_printf(bio_err, "Certificate bag\n");
682 if (options & NOCERTS)
684 if (PKCS12_get_attr(bag, NID_localKeyID)) {
685 if (options & CACERTS)
687 } else if (options & CLCERTS)
689 print_attribs(out, bag->attrib, "Bag Attributes");
690 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate)
692 if ((x509 = PKCS12_certbag2x509(bag)) == NULL)
694 dump_cert_text(out, x509);
695 PEM_write_bio_X509(out, x509);
699 case NID_safeContentsBag:
701 BIO_printf(bio_err, "Safe Contents bag\n");
702 print_attribs(out, bag->attrib, "Bag Attributes");
703 return dump_certs_pkeys_bags(out, bag->value.safes, pass,
704 passlen, options, pempass, enc);
707 BIO_printf(bio_err, "Warning unsupported bag type: ");
708 i2a_ASN1_OBJECT(bio_err, bag->type);
709 BIO_printf(bio_err, "\n");
715 /* Given a single certificate return a verified chain or NULL if error */
717 static int get_cert_chain(X509 *cert, X509_STORE *store,
718 STACK_OF(X509) **chain)
720 X509_STORE_CTX store_ctx;
721 STACK_OF(X509) *chn = NULL;
724 if (!X509_STORE_CTX_init(&store_ctx, store, cert, NULL)) {
726 return X509_V_ERR_UNSPECIFIED;
729 if (X509_verify_cert(&store_ctx) > 0)
730 chn = X509_STORE_CTX_get1_chain(&store_ctx);
731 else if ((i = X509_STORE_CTX_get_error(&store_ctx)) == 0)
732 i = X509_V_ERR_UNSPECIFIED;
734 X509_STORE_CTX_cleanup(&store_ctx);
739 static int alg_print(X509_ALGOR *alg)
742 const unsigned char *p = alg->parameter->value.sequence->data;
744 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
747 BIO_printf(bio_err, "%s, Iteration %ld\n",
748 OBJ_nid2ln(OBJ_obj2nid(alg->algorithm)),
749 ASN1_INTEGER_get(pbe->iter));
754 /* Load all certificates from a given file */
756 int cert_load(BIO *in, STACK_OF(X509) *sk)
761 while ((cert = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
763 sk_X509_push(sk, cert);
770 /* Generalised attribute print: handle PKCS#8 and bag attributes */
772 int print_attribs(BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst,
775 X509_ATTRIBUTE *attr;
780 BIO_printf(out, "%s: <No Attributes>\n", name);
783 if (!sk_X509_ATTRIBUTE_num(attrlst)) {
784 BIO_printf(out, "%s: <Empty Attributes>\n", name);
787 BIO_printf(out, "%s\n", name);
788 for (i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
789 ASN1_OBJECT *attr_obj;
790 attr = sk_X509_ATTRIBUTE_value(attrlst, i);
791 attr_obj = X509_ATTRIBUTE_get0_object(attr);
792 attr_nid = OBJ_obj2nid(attr_obj);
793 BIO_printf(out, " ");
794 if (attr_nid == NID_undef) {
795 i2a_ASN1_OBJECT(out, attr_obj);
796 BIO_printf(out, ": ");
798 BIO_printf(out, "%s: ", OBJ_nid2ln(attr_nid));
800 if (X509_ATTRIBUTE_count(attr)) {
801 av = X509_ATTRIBUTE_get0_type(attr, 0);
803 case V_ASN1_BMPSTRING:
804 value = OPENSSL_uni2asc(av->value.bmpstring->data,
805 av->value.bmpstring->length);
806 BIO_printf(out, "%s\n", value);
810 case V_ASN1_OCTET_STRING:
811 hex_prin(out, av->value.octet_string->data,
812 av->value.octet_string->length);
813 BIO_printf(out, "\n");
816 case V_ASN1_BIT_STRING:
817 hex_prin(out, av->value.bit_string->data,
818 av->value.bit_string->length);
819 BIO_printf(out, "\n");
823 BIO_printf(out, "<Unsupported tag %d>\n", av->type);
827 BIO_printf(out, "<No Values>\n");
832 void hex_prin(BIO *out, unsigned char *buf, int len)
835 for (i = 0; i < len; i++)
836 BIO_printf(out, "%02X ", buf[i]);
839 static int set_pbe(int *ppbe, const char *str)
843 if (strcmp(str, "NONE") == 0) {
847 *ppbe = OBJ_txt2nid(str);
848 if (*ppbe == NID_undef) {
849 BIO_printf(bio_err, "Unknown PBE algorithm %s\n", str);