int noprompt = 0;
STACK *canames = NULL;
char *cpass = NULL, *mpass = NULL;
+ char *passargin = NULL, *passargout = NULL, *passarg = NULL;
char *passin = NULL, *passout = NULL;
+ char *inrand = NULL;
apps_startup();
badarg = 1;
}
} else badarg = 1;
+ } else if (!strcmp (*args, "-rand")) {
+ if (args[1]) {
+ args++;
+ inrand = *args;
+ } else badarg = 1;
} else if (!strcmp (*args, "-inkey")) {
if (args[1]) {
args++;
} else if (!strcmp(*args,"-passin")) {
if (args[1]) {
args++;
- passin = *args;
- } else badarg = 1;
- } else if (!strcmp(*args,"-envpassin")) {
- if (args[1]) {
- args++;
- if(!(passin= getenv(*args))) {
- BIO_printf(bio_err,
- "Can't read environment variable %s\n",
- *argv);
- badarg = 1;
- }
- } else badarg = 1;
- } else if (!strcmp(*args,"-envpassout")) {
- if (args[1]) {
- args++;
- if(!(passout= getenv(*args))) {
- BIO_printf(bio_err,
- "Can't read environment variable %s\n",
- *argv);
- badarg = 1;
- }
+ passargin = *args;
} else badarg = 1;
} else if (!strcmp(*args,"-passout")) {
if (args[1]) {
args++;
- passout = *args;
- } else badarg = 1;
- } else if (!strcmp (*args, "-envpass")) {
- if (args[1]) {
- args++;
- if(!(cpass = getenv(*args))) {
- BIO_printf(bio_err,
- "Can't read environment variable %s\n", *args);
- goto end;
- }
+ passargout = *args;
} else badarg = 1;
} else if (!strcmp (*args, "-password")) {
if (args[1]) {
args++;
- cpass = *args;
+ passarg = *args;
noprompt = 1;
} else badarg = 1;
} else badarg = 1;
BIO_printf (bio_err, "-keypbe alg specify private key PBE algorithm (default 3DES)\n");
BIO_printf (bio_err, "-keyex set MS key exchange type\n");
BIO_printf (bio_err, "-keysig set MS key signature type\n");
- BIO_printf (bio_err, "-password p set import/export password (NOT RECOMMENDED)\n");
- BIO_printf (bio_err, "-envpass p set import/export password from environment\n");
- BIO_printf (bio_err, "-passin p input file pass phrase\n");
- BIO_printf (bio_err, "-envpassin p environment variable containing input file pass phrase\n");
- BIO_printf (bio_err, "-passout p output file pass phrase\n");
- BIO_printf (bio_err, "-envpassout p environment variable containing output file pass phrase\n");
+ BIO_printf (bio_err, "-password p set import/export password source\n");
+ BIO_printf (bio_err, "-passin p input file pass phrase source\n");
+ BIO_printf (bio_err, "-passout p output file pass phrase source\n");
+ BIO_printf(bio_err, "-rand file:file:...\n");
+ BIO_printf(bio_err, " load the file (or the files in the directory) into\n");
+ BIO_printf(bio_err, " the random number generator\n");
goto end;
}
+ if(passarg) {
+ if(export_cert) passargout = passarg;
+ else passargin = passarg;
+ }
+
+ if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
+ BIO_printf(bio_err, "Error getting passwords\n");
+ goto end;
+ }
+
if(!cpass) {
if(export_cert) cpass = passout;
else cpass = passin;
mpass = macpass;
}
+ if(export_cert || inrand) {
+ app_RAND_load_file(NULL, bio_err, (inrand != NULL));
+ if (inrand != NULL)
+ BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
+ app_RAND_load_files(inrand));
+ }
ERR_load_crypto_strings();
#ifdef CRYPTO_MDEBUG
#ifdef CRYPTO_MDEBUG
CRYPTO_push_info("process -export_cert");
#endif
- key = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, PEM_cb, passin);
+ key = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL, passin);
if (!inkey) (void) BIO_reset(in);
else BIO_free(inkey);
if (!key) {
PKCS12_free(p12);
ret = 0;
end:
+ if(export_cert || inrand) app_RAND_write_file(NULL, bio_err);
#ifdef CRYPTO_MDEBUG
CRYPTO_remove_all_info();
#endif
BIO_free(in);
BIO_free(out);
+ if(passin) Free(passin);
+ if(passout) Free(passout);
EXIT(ret);
}
p8 = bag->value.keybag;
if (!(pkey = EVP_PKCS82PKEY (p8))) return 0;
print_attribs (out, p8->attributes, "Key Attributes");
- PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, PEM_cb, pempass);
+ PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, pempass);
EVP_PKEY_free(pkey);
break;
if (!(pkey = EVP_PKCS82PKEY (p8))) return 0;
print_attribs (out, p8->attributes, "Key Attributes");
PKCS8_PRIV_KEY_INFO_free(p8);
- PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, PEM_cb, pempass);
+ PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, pempass);
EVP_PKEY_free(pkey);
break;