const fixes
[openssl.git] / apps / req.c
index 5df8f89fcd03f7223e56f2b4b9184400eece5991..db70dc22755c2caaa22aae264dc5d1ebec820df7 100644 (file)
@@ -130,16 +130,16 @@ static int prompt_info(X509_REQ *req,
 static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *sk,
                                STACK_OF(CONF_VALUE) *attr, int attribs,
                                unsigned long chtype);
-static int add_attribute_object(X509_REQ *req, char *text,
-                               char *def, char *value, int nid, int n_min,
+static int add_attribute_object(X509_REQ *req, char *text, const char *def,
+                               char *value, int nid, int n_min,
                                int n_max, unsigned long chtype);
-static int add_DN_object(X509_NAME *n, char *text, char *def, char *value,
+static int add_DN_object(X509_NAME *n, char *text, const char *def, char *value,
        int nid,int n_min,int n_max, unsigned long chtype, int mval);
 #ifndef OPENSSL_NO_RSA
 static int MS_CALLBACK req_cb(int p, int n, BN_GENCB *cb);
 #endif
 static int req_check_len(int len,int n_min,int n_max);
-static int check_end(char *str, char *end);
+static int check_end(const char *str, const char *end);
 #ifndef MONOLITH
 static char *default_config_file=NULL;
 #endif
@@ -187,7 +187,7 @@ int MAIN(int argc, char **argv)
        char *p;
        char *subj = NULL;
        int multirdn = 0;
-       const EVP_MD *md_alg=NULL,*digest=EVP_md5();
+       const EVP_MD *md_alg=NULL,*digest=EVP_sha1();
        unsigned long chtype = MBSTRING_ASC;
 #ifndef MONOLITH
        char *to_free;
@@ -567,13 +567,16 @@ bad:
        else
                {
                req_conf=config;
-               if( verbose )
-                       BIO_printf(bio_err,"Using configuration from %s\n",
-                       default_config_file);
+
                if (req_conf == NULL)
                        {
-                       BIO_printf(bio_err,"Unable to load config info\n");
+                       BIO_printf(bio_err,"Unable to load config info from %s\n", default_config_file);
+                       if (newreq)
+                               goto end;
                        }
+               else if( verbose )
+                       BIO_printf(bio_err,"Using configuration from %s\n",
+                       default_config_file);
                }
 
        if (req_conf != NULL)
@@ -748,12 +751,16 @@ bad:
                if (pkey_type == TYPE_RSA)
                        {
                        RSA *rsa = RSA_new();
-                       if(!rsa || !RSA_generate_key_ex(rsa, newkey, 0x10001, &cb) ||
+                       BIGNUM *bn = BN_new();
+                       if(!bn || !rsa || !BN_set_word(bn, 0x10001) ||
+                                       !RSA_generate_key_ex(rsa, newkey, bn, &cb) ||
                                        !EVP_PKEY_assign_RSA(pkey, rsa))
                                {
+                               if(bn) BN_free(bn);
                                if(rsa) RSA_free(rsa);
                                goto end;
                                }
+                       BN_free(bn);
                        }
                else
 #endif
@@ -919,7 +926,9 @@ loop:
                                }
                        else
                                {
-                               if (!ASN1_INTEGER_set(X509_get_serialNumber(x509ss),0L)) goto end;
+                               if (!rand_serial(NULL,
+                                       X509_get_serialNumber(x509ss)))
+                                               goto end;
                                }
 
                        if (!X509_set_issuer_name(x509ss, X509_REQ_get_subject_name(req))) goto end;
@@ -1271,7 +1280,8 @@ static int prompt_info(X509_REQ *req,
        char buf[100];
        int nid, mval;
        long n_min,n_max;
-       char *type,*def,*value;
+       char *type, *value;
+       const char *def;
        CONF_VALUE *v;
        X509_NAME *subj;
        subj = X509_REQ_get_subject_name(req);
@@ -1497,7 +1507,7 @@ static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *dn_sk,
        }
 
 
-static int add_DN_object(X509_NAME *n, char *text, char *def, char *value,
+static int add_DN_object(X509_NAME *n, char *text, const char *def, char *value,
             int nid, int n_min, int n_max, unsigned long chtype, int mval)
        {
        int i,ret=0;
@@ -1553,8 +1563,8 @@ err:
        return(ret);
        }
 
-static int add_attribute_object(X509_REQ *req, char *text,
-                               char *def, char *value, int nid, int n_min,
+static int add_attribute_object(X509_REQ *req, char *text, const char *def,
+                               char *value, int nid, int n_min,
                                int n_max, unsigned long chtype)
        {
        int i;
@@ -1651,10 +1661,10 @@ static int req_check_len(int len, int n_min, int n_max)
        }
 
 /* Check if the end of a string matches 'end' */
-static int check_end(char *str, char *end)
+static int check_end(const char *str, const char *end)
 {
        int elen, slen; 
-       char *tmp;
+       const char *tmp;
        elen = strlen(end);
        slen = strlen(str);
        if(elen > slen) return 1;