#include <openssl/x509v3.h>
#include <openssl/objects.h>
#include <openssl/pem.h>
+#include <openssl/engine.h>
#define SECTION "req"
* -nodes - no des encryption
* -config file - Load configuration file.
* -key file - make a request using key in file (or use it for verification).
- * -keyform - key file format.
+ * -keyform arg - key file format.
* -rand file(s) - load the file(s) into the PRNG.
* -newkey - make a key and a request.
* -modulus - print RSA modulus.
int MAIN(int argc, char **argv)
{
+ ENGINE *e = NULL;
#ifndef NO_DSA
DSA *dsa_params=NULL;
#endif
X509 *x509ss=NULL;
X509_REQ *req=NULL;
EVP_PKEY *pkey=NULL;
- int i,badops=0,newreq=0,newkey= -1,pkey_type=0;
+ int i,badops=0,newreq=0,newkey= -1,pkey_type=TYPE_RSA;
BIO *in=NULL,*out=NULL;
int informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;
int nodes=0,kludge=0,newhdr=0,subject=0;
char *infile,*outfile,*prog,*keyfile=NULL,*template=NULL,*keyout=NULL;
+ char *engine=NULL;
char *extensions = NULL;
char *req_exts = NULL;
EVP_CIPHER *cipher=NULL;
if (--argc < 1) goto bad;
outformat=str2fmt(*(++argv));
}
+ else if (strcmp(*argv,"-engine") == 0)
+ {
+ if (--argc < 1) goto bad;
+ engine= *(++argv);
+ }
else if (strcmp(*argv,"-key") == 0)
{
if (--argc < 1) goto bad;
}
else if (strcmp(*argv,"-new") == 0)
{
- pkey_type=TYPE_RSA;
newreq=1;
}
else if (strcmp(*argv,"-config") == 0)
BIO_printf(bio_err," -verify verify signature on REQ\n");
BIO_printf(bio_err," -modulus RSA modulus\n");
BIO_printf(bio_err," -nodes don't encrypt the output key\n");
+ BIO_printf(bio_err," -engine e use engine e, possibly a hardware device.\n");
BIO_printf(bio_err," -key file use the private key contained in file\n");
BIO_printf(bio_err," -keyform arg key file format\n");
BIO_printf(bio_err," -keyout arg file to send the key to\n");
if (req_conf != NULL)
{
p=CONF_get_string(req_conf,NULL,"oid_file");
+ if (p == NULL)
+ ERR_clear_error();
if (p != NULL)
{
BIO *oid_bio;
}
}
}
- if(!add_oid_section(bio_err, 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))
+ if (md_alg == NULL)
{
- if ((md_alg=EVP_get_digestbyname(p)) != NULL)
- digest=md_alg;
+ p=CONF_get_string(req_conf,SECTION,"default_md");
+ if (p == NULL)
+ ERR_clear_error();
+ if (p != NULL)
+ {
+ if ((md_alg=EVP_get_digestbyname(p)) != NULL)
+ digest=md_alg;
+ }
}
- if(!extensions)
+ if (!extensions)
+ {
extensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS);
- if(extensions) {
+ if (!extensions)
+ ERR_clear_error();
+ }
+ if (extensions) {
/* Check syntax of file */
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
}
if(!passin)
+ {
passin = CONF_get_string(req_conf, SECTION, "input_password");
-
+ if (!passin)
+ ERR_clear_error();
+ }
+
if(!passout)
+ {
passout = CONF_get_string(req_conf, SECTION, "output_password");
+ if (!passout)
+ ERR_clear_error();
+ }
p = CONF_get_string(req_conf, SECTION, STRING_MASK);
+ if (!p)
+ ERR_clear_error();
if(p && !ASN1_STRING_set_default_mask_asc(p)) {
BIO_printf(bio_err, "Invalid global string mask setting %s\n", p);
}
if(!req_exts)
+ {
req_exts = CONF_get_string(req_conf, SECTION, REQ_EXTENSIONS);
+ if (!req_exts)
+ ERR_clear_error();
+ }
if(req_exts) {
/* Check syntax of file */
X509V3_CTX ctx;
if ((in == NULL) || (out == NULL))
goto end;
- if (keyfile != NULL)
+ if (engine != NULL)
{
- if (BIO_read_filename(in,keyfile) <= 0)
+ if((e = ENGINE_by_id(engine)) == NULL)
{
- perror(keyfile);
+ BIO_printf(bio_err,"invalid engine \"%s\"\n",
+ engine);
goto end;
}
+ if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
+ {
+ BIO_printf(bio_err,"can't use that engine\n");
+ goto end;
+ }
+ BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
+ /* Free our "structural" reference. */
+ ENGINE_free(e);
+ }
- if (keyform == FORMAT_ASN1)
- pkey=d2i_PrivateKey_bio(in,NULL);
- else if (keyform == FORMAT_PEM)
+ if (keyfile != NULL)
+ {
+ if (keyform == FORMAT_ENGINE)
{
- pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,passin);
+ if (!e)
+ {
+ BIO_printf(bio_err,"no engine specified\n");
+ goto end;
+ }
+ pkey = ENGINE_load_private_key(e, keyfile, NULL);
}
else
{
- BIO_printf(bio_err,"bad input format specified for X509 request\n");
- goto end;
+ if (BIO_read_filename(in,keyfile) <= 0)
+ {
+ perror(keyfile);
+ goto end;
+ }
+
+ if (keyform == FORMAT_ASN1)
+ pkey=d2i_PrivateKey_bio(in,NULL);
+ else if (keyform == FORMAT_PEM)
+ {
+ pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,
+ passin);
+ }
+ else
+ {
+ BIO_printf(bio_err,"bad input format specified for X509 request\n");
+ goto end;
+ }
}
if (pkey == NULL)
if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA)
{
char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE");
+ if (randfile == NULL)
+ ERR_clear_error();
app_RAND_load_file(randfile, bio_err, 0);
}
}
if (newreq && (pkey == NULL))
{
char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE");
+ if (randfile == NULL)
+ ERR_clear_error();
app_RAND_load_file(randfile, bio_err, 0);
if (inrand)
app_RAND_load_files(inrand);
if (pkey == NULL) goto end;
if (keyout == NULL)
+ {
keyout=CONF_get_string(req_conf,SECTION,KEYFILE);
-
+ if (keyout == NULL)
+ ERR_clear_error();
+ }
+
if (keyout == NULL)
{
BIO_printf(bio_err,"writing new private key to stdout\n");
p=CONF_get_string(req_conf,SECTION,"encrypt_rsa_key");
if (p == NULL)
+ {
+ ERR_clear_error();
p=CONF_get_string(req_conf,SECTION,"encrypt_key");
+ if (p == NULL)
+ ERR_clear_error();
+ }
if ((p != NULL) && (strcmp(p,"no") == 0))
cipher=NULL;
if (nodes) cipher=NULL;
}
i=make_REQ(req,pkey,!x509);
- if (kludge >= 0)
- req->req_info->req_kludge=kludge;
+ if ((kludge > 0) && !sk_X509_ATTRIBUTE_num(req->req_info->attributes))
+ {
+ sk_X509_ATTRIBUTE_free(req->req_info->attributes);
+ req->req_info->attributes = NULL;
+ }
if (!i)
{
BIO_printf(bio_err,"problems making Certificate Request\n");
char *tmp, *dn_sect,*attr_sect;
tmp=CONF_get_string(req_conf,SECTION,PROMPT);
+ if (tmp == NULL)
+ ERR_clear_error();
if((tmp != NULL) && !strcmp(tmp, "no")) no_prompt = 1;
dn_sect=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME);
attr_sect=CONF_get_string(req_conf,SECTION,ATTRIBUTES);
if (attr_sect == NULL)
+ {
+ ERR_clear_error();
attr_sk=NULL;
+ }
else
{
attr_sk=CONF_get_section(req_conf,attr_sect);
if ((nid=OBJ_txt2nid(type)) == NID_undef) goto start;
sprintf(buf,"%s_default",v->name);
if ((def=CONF_get_string(req_conf,dn_sect,buf)) == NULL)
+ {
+ ERR_clear_error();
def="";
+ }
sprintf(buf,"%s_value",v->name);
if ((value=CONF_get_string(req_conf,dn_sect,buf)) == NULL)
+ {
+ ERR_clear_error();
value=NULL;
+ }
sprintf(buf,"%s_min",v->name);
min=(int)CONF_get_number(req_conf,dn_sect,buf);
sprintf(buf,"%s_default",type);
if ((def=CONF_get_string(req_conf,attr_sect,buf))
== NULL)
+ {
+ ERR_clear_error();
def="";
+ }
+
sprintf(buf,"%s_value",type);
if ((value=CONF_get_string(req_conf,attr_sect,buf))
== NULL)
+ {
+ ERR_clear_error();
value=NULL;
+ }
sprintf(buf,"%s_min",type);
min=(int)CONF_get_number(req_conf,attr_sect,buf);