-#ifdef CRYPTO_MDEBUG
- CRYPTO_pop_info();
- CRYPTO_push_info("building bags");
-#endif
-
- /* We now have loads of certificates: include them all */
- for(i = 0; i < sk_X509_num(certs); i++) {
- X509 *cert = NULL;
- cert = sk_X509_value(certs, i);
- bag = PKCS12_x5092certbag(cert);
- /* If it matches private key set id */
- if(cert == ucert) {
- if(name) PKCS12_add_friendlyname(bag, name, -1);
- PKCS12_add_localkeyid(bag, keyid, keyidlen);
- } else if((catmp = sk_shift(canames)))
- PKCS12_add_friendlyname(bag, catmp, -1);
- sk_PKCS12_SAFEBAG_push(bags, bag);
- }
- sk_X509_pop_free(certs, X509_free);
- certs = NULL;
- /* ucert is part of certs so it is already freed */
- ucert = NULL;
-
-#ifdef CRYPTO_MDEBUG
- CRYPTO_pop_info();
- CRYPTO_push_info("encrypting bags");
-#endif
-
- if(!noprompt &&
- EVP_read_pw_string(pass, 50, "Enter Export Password:", 1)) {
- BIO_printf (bio_err, "Can't read Password\n");
- goto export_end;
- }
- if (!twopass) strcpy(macpass, pass);
- /* Turn certbags into encrypted authsafe */
- authsafe = PKCS12_pack_p7encdata(cert_pbe, cpass, -1, NULL, 0,
- iter, bags);
- sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
- bags = NULL;
-
- if (!authsafe) {
- ERR_print_errors (bio_err);
- goto export_end;
- }
-
- safes = sk_PKCS7_new_null ();
- sk_PKCS7_push (safes, authsafe);