Support INSTALL_PREFIX for packagers.
[openssl.git] / apps / req.c
index dad1a50c4637208e4ac6822eb19309b44cd3a386..5678b707f8514974af1886400a773d0abcc9b8b2 100644 (file)
 #define APPS_WIN16
 #endif
 #include "apps.h"
-#include "bio.h"
-#include "evp.h"
-#include "rand.h"
-#include "conf.h"
-#include "err.h"
-#include "asn1.h"
-#include "x509.h"
-#include "x509v3.h"
-#include "objects.h"
-#include "pem.h"
+#include <openssl/bio.h>
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+#include <openssl/conf.h>
+#include <openssl/err.h>
+#include <openssl/asn1.h>
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+#include <openssl/objects.h>
+#include <openssl/pem.h>
 
 #define SECTION                "req"
 
  *               require.  This format is wrong
  */
 
-#ifndef NOPROTO
 static int make_REQ(X509_REQ *req,EVP_PKEY *pkey,int attribs);
 static int add_attribute_object(STACK *n, char *text, char *def, 
        char *value, int nid,int min,int max);
@@ -117,16 +116,6 @@ static void MS_CALLBACK req_cb(int p,int n,char *arg);
 static int req_fix_data(int nid,int *type,int len,int min,int max);
 static int check_end(char *str, char *end);
 static int add_oid_section(LHASH *conf);
-#else
-static int make_REQ();
-static int add_attribute_object();
-static int add_DN_object();
-static void MS_CALLBACK req_cb();
-static int req_fix_data();
-static int check_end();
-static int add_oid_section();
-#endif
-
 #ifndef MONOLITH
 static char *default_config_file=NULL;
 static LHASH *config=NULL;
@@ -137,9 +126,7 @@ static LHASH *req_conf=NULL;
 #define TYPE_DSA       2
 #define TYPE_DH                3
 
-int MAIN(argc, argv)
-int argc;
-char **argv;
+int MAIN(int argc, char **argv)
        {
 #ifndef NO_DSA
        DSA *dsa_params=NULL;
@@ -157,7 +144,7 @@ char **argv;
        EVP_CIPHER *cipher=NULL;
        int modulus=0;
        char *p;
-       EVP_MD *md_alg=NULL,*digest=EVP_md5();
+       const EVP_MD *md_alg=NULL,*digest=EVP_md5();
 #ifndef MONOLITH
        MS_STATIC char config_name[256];
 #endif
@@ -264,11 +251,10 @@ char **argv;
                                                goto end;
                                                }
 
-                                       /* This will 'disapear'
-                                        * when we free xtmp */
                                        dtmp=X509_get_pubkey(xtmp);
                                        if (dtmp->type == EVP_PKEY_DSA)
                                                dsa_params=DSAparams_dup(dtmp->pkey.dsa);
+                                       EVP_PKEY_free(dtmp);
                                        X509_free(xtmp);
                                        if (dsa_params == NULL)
                                                {
@@ -437,6 +423,17 @@ bad:
                }
 
        extensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS);
+       if(extensions) {
+               /* Check syntax of file */
+               X509V3_CTX ctx;
+               X509V3_set_ctx_test(&ctx);
+               X509V3_set_conf_lhash(&ctx, req_conf);
+               if(!X509V3_EXT_add_conf(req_conf, &ctx, extensions, NULL)) {
+                       BIO_printf(bio_err,
+                        "Error Loading extension section %s\n", extensions);
+                       goto end;
+               }
+       }
 
        in=BIO_new(BIO_s_file());
        out=BIO_new(BIO_s_file());
@@ -659,11 +656,8 @@ loop:
 
                        /* Set up V3 context struct */
 
-                       ext_ctx.issuer_cert = x509ss;
-                       ext_ctx.subject_cert = x509ss;
-                       ext_ctx.subject_req = NULL;
-                       ext_ctx.crl = NULL;
-                       ext_ctx.flags = 0;
+                       X509V3_set_ctx(&ext_ctx, x509ss, x509ss, NULL, NULL, 0);
+                       X509V3_set_conf_lhash(&ext_ctx, req_conf);
 
                        /* Add extensions */
                        if(extensions && !X509V3_EXT_add_conf(req_conf, 
@@ -818,13 +812,10 @@ end:
        EXIT(ex);
        }
 
-static int make_REQ(req,pkey,attribs)
-X509_REQ *req;
-EVP_PKEY *pkey;
-int attribs;
+static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs)
        {
        int ret=0,i;
-       unsigned char *p,*q;
+       char *p,*q;
        X509_REQ_INFO *ri;
        char buf[100];
        int nid,min,max;
@@ -977,14 +968,8 @@ err:
        return(ret);
        }
 
-static int add_DN_object(n,text,def,value,nid,min,max)
-X509_NAME *n;
-char *text;
-char *def;
-char *value;
-int nid;
-int min;
-int max;
+static int add_DN_object(X509_NAME *n, char *text, char *def, char *value,
+            int nid, int min, int max)
        {
        int i,j,ret=0;
        X509_NAME_ENTRY *ne=NULL;
@@ -1037,14 +1022,8 @@ err:
        return(ret);
        }
 
-static int add_attribute_object(n,text,def,value,nid,min,max)
-STACK *n;
-char *text;
-char *def;
-char *value;
-int nid;
-int min;
-int max;
+static int add_attribute_object(STACK *n, char *text, char *def, char *value,
+            int nid, int min, int max)
        {
        int i,z;
        X509_ATTRIBUTE *xa=NULL;
@@ -1128,10 +1107,7 @@ err:
        return(0);
        }
 
-static void MS_CALLBACK req_cb(p,n,arg)
-int p;
-int n;
-char *arg;
+static void MS_CALLBACK req_cb(int p, int n, char *arg)
        {
        char c='*';
 
@@ -1146,10 +1122,7 @@ char *arg;
 #endif
        }
 
-static int req_fix_data(nid,type,len,min,max)
-int nid;
-int *type;
-int len,min,max;
+static int req_fix_data(int nid, int *type, int len, int min, int max)
        {
        if (nid == NID_pkcs9_emailAddress)
                *type=V_ASN1_IA5STRING;
@@ -1182,9 +1155,7 @@ int len,min,max;
        }
 
 /* Check if the end of a string matches 'end' */
-static int check_end(str, end)
-char *str;
-char *end;
+static int check_end(char *str, char *end)
 {
        int elen, slen; 
        char *tmp;
@@ -1195,8 +1166,7 @@ char *end;
        return strcmp(tmp, end);
 }
 
-static int add_oid_section(conf)
-LHASH *conf;
+static int add_oid_section(LHASH *conf)
 {      
        char *p;
        STACK *sktmp;