Another stack.
[openssl.git] / apps / req.c
index dad1a50c4637208e4ac6822eb19309b44cd3a386..7459f7b7da99de20c0e5fa8d3195f2a3132fb692 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);
+static int add_attribute_object(STACK_OF(X509_ATTRIBUTE) *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);
 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 +127,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 +145,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 +252,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 +424,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 +657,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 +813,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;
@@ -916,7 +908,7 @@ start:              for (;;)
                                min,max))
                                goto err;
                        }
-               if (sk_num(ri->subject->entries) == 0)
+               if (sk_X509_NAME_ENTRY_num(ri->subject->entries) == 0)
                        {
                        BIO_printf(bio_err,"error, no objects specified in config file\n");
                        goto err;
@@ -977,14 +969,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 +1023,9 @@ 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_OF(X509_ATTRIBUTE) *n, char *text,
+                               char *def, char *value, int nid, int min,
+                               int max)
        {
        int i,z;
        X509_ATTRIBUTE *xa=NULL;
@@ -1088,7 +1069,7 @@ start:
        /* add object plus value */
        if ((xa=X509_ATTRIBUTE_new()) == NULL)
                goto err;
-       if ((xa->value.set=sk_new_null()) == NULL)
+       if ((xa->value.set=sk_ASN1_TYPE_new_null()) == NULL)
                goto err;
        xa->set=1;
 
@@ -1114,12 +1095,12 @@ start:
                { BIO_printf(bio_err,"Malloc failure\n"); goto err; }
 
        ASN1_TYPE_set(at,bs->type,(char *)bs);
-       sk_push(xa->value.set,(char *)at);
+       sk_ASN1_TYPE_push(xa->value.set,at);
        bs=NULL;
        at=NULL;
        /* only one item per attribute */
 
-       if (!sk_push(n,(char *)xa)) goto err;
+       if (!sk_X509_ATTRIBUTE_push(n,xa)) goto err;
        return(1);
 err:
        if (xa != NULL) X509_ATTRIBUTE_free(xa);
@@ -1128,10 +1109,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 +1124,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 +1157,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 +1168,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;