return BUF_strdup(tpass);
}
-X509 *load_cert(char *file, int format)
+int add_oid_section(BIO *err, LHASH *conf)
+{
+ char *p;
+ STACK_OF(CONF_VALUE) *sktmp;
+ CONF_VALUE *cnf;
+ int i;
+ if(!(p=CONF_get_string(conf,NULL,"oid_section"))) return 1;
+ if(!(sktmp = CONF_get_section(conf, p))) {
+ BIO_printf(err, "problem loading oid section %s\n", p);
+ return 0;
+ }
+ for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
+ cnf = sk_CONF_VALUE_value(sktmp, i);
+ if(OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) {
+ BIO_printf(err, "problem creating object %s=%s\n",
+ cnf->name, cnf->value);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+X509 *load_cert(BIO *err, char *file, int format)
{
ASN1_HEADER *ah=NULL;
BUF_MEM *buf=NULL;
if ((cert=BIO_new(BIO_s_file())) == NULL)
{
- ERR_print_errors(bio_err);
+ ERR_print_errors(err);
goto end;
}
(strncmp(NETSCAPE_CERT_HDR,(char *)ah->header->data,
ah->header->length) != 0))
{
- BIO_printf(bio_err,"Error reading header on certificate\n");
+ BIO_printf(err,"Error reading header on certificate\n");
goto end;
}
/* header is ok, so now read the object */
p12 = NULL;
}
else {
- BIO_printf(bio_err,"bad input format specified for input cert\n");
+ BIO_printf(err,"bad input format specified for input cert\n");
goto end;
}
end:
if (x == NULL)
{
- BIO_printf(bio_err,"unable to load certificate\n");
- ERR_print_errors(bio_err);
+ BIO_printf(err,"unable to load certificate\n");
+ ERR_print_errors(err);
}
if (ah != NULL) ASN1_HEADER_free(ah);
if (cert != NULL) BIO_free(cert);
return(x);
}
-EVP_PKEY *load_key(char *file, int format, char *pass)
+EVP_PKEY *load_key(BIO *err, char *file, int format, char *pass)
{
BIO *key=NULL;
EVP_PKEY *pkey=NULL;
if (file == NULL)
{
- BIO_printf(bio_err,"no keyfile specified\n");
+ BIO_printf(err,"no keyfile specified\n");
goto end;
}
key=BIO_new(BIO_s_file());
if (key == NULL)
{
- ERR_print_errors(bio_err);
+ ERR_print_errors(err);
goto end;
}
if (BIO_read_filename(key,file) <= 0)
}
else
{
- BIO_printf(bio_err,"bad input format specified for key\n");
+ BIO_printf(err,"bad input format specified for key\n");
goto end;
}
end:
if (key != NULL) BIO_free(key);
if (pkey == NULL)
- BIO_printf(bio_err,"unable to load Private Key\n");
+ BIO_printf(err,"unable to load Private Key\n");
return(pkey);
}
-STACK_OF(X509) *load_certs(char *file, int format)
+STACK_OF(X509) *load_certs(BIO *err, char *file, int format)
{
BIO *certs;
int i;
if((certs = BIO_new(BIO_s_file())) == NULL)
{
- ERR_print_errors(bio_err);
+ ERR_print_errors(err);
goto end;
}
goto end;
}
else {
- BIO_printf(bio_err,"bad input format specified for input cert\n");
+ BIO_printf(err,"bad input format specified for input cert\n");
goto end;
}
end:
if (othercerts == NULL)
{
- BIO_printf(bio_err,"unable to load certificates\n");
- ERR_print_errors(bio_err);
+ BIO_printf(err,"unable to load certificates\n");
+ ERR_print_errors(err);
}
if (allcerts) sk_X509_INFO_pop_free(allcerts, X509_INFO_free);
if (certs != NULL) BIO_free(certs);
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
+#include <openssl/lhash.h>
int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
int app_RAND_write_file(const char *file, BIO *bio_e);
int dump_cert_text(BIO *out, X509 *x);
#endif
int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
-X509 *load_cert(char *file, int format);
-EVP_PKEY *load_key(char *file, int format, char *pass);
-STACK_OF(X509) *load_certs(char *file, int format);
+int add_oid_section(BIO *err, LHASH *conf);
+X509 *load_cert(BIO *err, char *file, int format);
+EVP_PKEY *load_key(BIO *err, char *file, int format, char *pass);
+STACK_OF(X509) *load_certs(BIO *err, char *file, int format);
#define FORMAT_UNDEF 0
#define FORMAT_ASN1 1
extern int EF_ALIGNMENT;
#endif
-static int add_oid_section(LHASH *conf);
static void lookup_fail(char *name,char *tag);
static unsigned long index_serial_hash(char **a);
static int index_serial_cmp(char **a, char **b);
BIO_free(oid_bio);
}
}
- if(!add_oid_section(conf))
+ if(!add_oid_section(bio_err,conf))
{
ERR_print_errors(bio_err);
goto err;
return(ASN1_UTCTIME_check(&tm));
}
-static int add_oid_section(LHASH *hconf)
-{
- char *p;
- STACK_OF(CONF_VALUE) *sktmp;
- CONF_VALUE *cnf;
- int i;
- if(!(p=CONF_get_string(hconf,NULL,"oid_section"))) return 1;
- if(!(sktmp = CONF_get_section(hconf, p))) {
- BIO_printf(bio_err, "problem loading oid section %s\n", p);
- return 0;
- }
- for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
- cnf = sk_CONF_VALUE_value(sktmp, i);
- if(OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) {
- BIO_printf(bio_err, "problem creating object %s=%s\n",
- cnf->name, cnf->value);
- return 0;
- }
- }
- return 1;
-}
-
static int do_revoke(X509 *x509, TXT_DB *db)
{
ASN1_UTCTIME *tm=NULL, *revtm=NULL;
#endif
static int req_check_len(int len,int min,int max);
static int check_end(char *str, char *end);
-static int add_oid_section(LHASH *conf);
#ifndef MONOLITH
static char *default_config_file=NULL;
static LHASH *config=NULL;
}
}
}
- if(!add_oid_section(req_conf)) goto end;
+ if(!add_oid_section(bio_err, req_conf)) goto end;
if ((md_alg == NULL) &&
((p=CONF_get_string(req_conf,SECTION,"default_md")) != NULL))
tmp = str + slen - elen;
return strcmp(tmp, end);
}
-
-static int add_oid_section(LHASH *conf)
-{
- char *p;
- STACK_OF(CONF_VALUE) *sktmp;
- CONF_VALUE *cnf;
- int i;
- if(!(p=CONF_get_string(conf,NULL,"oid_section"))) return 1;
- if(!(sktmp = CONF_get_section(conf, p))) {
- BIO_printf(bio_err, "problem loading oid section %s\n", p);
- return 0;
- }
- for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
- cnf = sk_CONF_VALUE_value(sktmp, i);
- if(OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) {
- BIO_printf(bio_err, "problem creating object %s=%s\n",
- cnf->name, cnf->value);
- return 0;
- }
- }
- return 1;
-}
}
encerts = sk_X509_new_null();
while (*args) {
- if(!(cert = load_cert(*args,FORMAT_PEM))) {
+ if(!(cert = load_cert(bio_err,*args,FORMAT_PEM))) {
BIO_printf(bio_err, "Can't read recipient certificate file %s\n", *args);
goto end;
}
}
if(signerfile && (operation == SMIME_SIGN)) {
- if(!(signer = load_cert(signerfile,FORMAT_PEM))) {
+ if(!(signer = load_cert(bio_err,signerfile,FORMAT_PEM))) {
BIO_printf(bio_err, "Can't read signer certificate file %s\n", signerfile);
goto end;
}
}
if(certfile) {
- if(!(other = load_certs(certfile,FORMAT_PEM))) {
+ if(!(other = load_certs(bio_err,certfile,FORMAT_PEM))) {
BIO_printf(bio_err, "Can't read certificate file %s\n", certfile);
ERR_print_errors(bio_err);
goto end;
}
if(recipfile && (operation == SMIME_DECRYPT)) {
- if(!(recip = load_cert(recipfile,FORMAT_PEM))) {
+ if(!(recip = load_cert(bio_err,recipfile,FORMAT_PEM))) {
BIO_printf(bio_err, "Can't read recipient certificate file %s\n", recipfile);
ERR_print_errors(bio_err);
goto end;
} else keyfile = NULL;
if(keyfile) {
- if(!(key = load_key(keyfile, FORMAT_PEM, passin))) {
+ if(!(key = load_key(bio_err,keyfile, FORMAT_PEM, passin))) {
BIO_printf(bio_err, "Can't read recipient certificate file %s\n", keyfile);
ERR_print_errors(bio_err);
goto end;
EVP_PKEY_free(pkey);
}
else
- x=load_cert(infile,informat);
+ x=load_cert(bio_err,infile,informat);
if (x == NULL) goto end;
if (CA_flag)
{
- xca=load_cert(CAfile,CAformat);
+ xca=load_cert(bio_err,CAfile,CAformat);
if (xca == NULL) goto end;
}
BIO_printf(bio_err,"Getting Private key\n");
if (Upkey == NULL)
{
- Upkey=load_key(keyfile,keyformat, passin);
+ Upkey=load_key(bio_err,
+ keyfile,keyformat, passin);
if (Upkey == NULL) goto end;
}
#ifndef NO_DSA
BIO_printf(bio_err,"Getting CA Private Key\n");
if (CAkeyfile != NULL)
{
- CApkey=load_key(CAkeyfile,CAkeyformat, passin);
+ CApkey=load_key(bio_err,
+ CAkeyfile,CAkeyformat, passin);
if (CApkey == NULL) goto end;
}
#ifndef NO_DSA
}
else
{
- pk=load_key(keyfile,FORMAT_PEM, passin);
+ pk=load_key(bio_err,
+ keyfile,FORMAT_PEM, passin);
if (pk == NULL) goto end;
}