use SHA-1 as the default digest for the apps/openssl commands
[openssl.git] / apps / req.c
index c5becc9d4dd19401873f5c3b673b7e55788c78d9..f43c477f75b746b6b63cd28581c831ef86cd5fcc 100644 (file)
@@ -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;
@@ -1321,34 +1330,34 @@ start:          for (;;)
                                mval = 0;
                        /* If OBJ not recognised ignore it */
                        if ((nid=OBJ_txt2nid(type)) == NID_undef) goto start;
-
-                       if(strlen(v->name) > sizeof buf-9)
+                       if (BIO_snprintf(buf,sizeof buf,"%s_default",v->name)
+                               >= (int)sizeof(buf))
                           {
                           BIO_printf(bio_err,"Name '%s' too long\n",v->name);
                           return 0;
                           }
 
-                       sprintf(buf,"%s_default",v->name);
                        if ((def=NCONF_get_string(req_conf,dn_sect,buf)) == NULL)
                                {
                                ERR_clear_error();
                                def="";
                                }
-                       sprintf(buf,"%s_value",v->name);
+                               
+                       BIO_snprintf(buf,sizeof buf,"%s_value",v->name);
                        if ((value=NCONF_get_string(req_conf,dn_sect,buf)) == NULL)
                                {
                                ERR_clear_error();
                                value=NULL;
                                }
 
-                       sprintf(buf,"%s_min",v->name);
+                       BIO_snprintf(buf,sizeof buf,"%s_min",v->name);
                        if (!NCONF_get_number(req_conf,dn_sect,buf, &n_min))
                                {
                                ERR_clear_error();
                                n_min = -1;
                                }
 
-                       sprintf(buf,"%s_max",v->name);
+                       BIO_snprintf(buf,sizeof buf,"%s_max",v->name);
                        if (!NCONF_get_number(req_conf,dn_sect,buf, &n_max))
                                {
                                ERR_clear_error();
@@ -1386,13 +1395,13 @@ start2:                 for (;;)
                                if ((nid=OBJ_txt2nid(type)) == NID_undef)
                                        goto start2;
 
-                               if(strlen(v->name) > sizeof buf-9)
+                               if (BIO_snprintf(buf,sizeof buf,"%s_default",type)
+                                       >= (int)sizeof(buf))
                                   {
                                   BIO_printf(bio_err,"Name '%s' too long\n",v->name);
                                   return 0;
                                   }
 
-                               sprintf(buf,"%s_default",type);
                                if ((def=NCONF_get_string(req_conf,attr_sect,buf))
                                        == NULL)
                                        {
@@ -1401,7 +1410,7 @@ start2:                   for (;;)
                                        }
                                
                                
-                               sprintf(buf,"%s_value",type);
+                               BIO_snprintf(buf,sizeof buf,"%s_value",type);
                                if ((value=NCONF_get_string(req_conf,attr_sect,buf))
                                        == NULL)
                                        {
@@ -1409,11 +1418,11 @@ start2:                 for (;;)
                                        value=NULL;
                                        }
 
-                               sprintf(buf,"%s_min",type);
+                               BIO_snprintf(buf,sizeof buf,"%s_min",type);
                                if (!NCONF_get_number(req_conf,attr_sect,buf, &n_min))
                                        n_min = -1;
 
-                               sprintf(buf,"%s_max",type);
+                               BIO_snprintf(buf,sizeof buf,"%s_max",type);
                                if (!NCONF_get_number(req_conf,attr_sect,buf, &n_max))
                                        n_max = -1;
 
@@ -1507,9 +1516,8 @@ start:
        (void)BIO_flush(bio_err);
        if(value != NULL)
                {
-               OPENSSL_assert(strlen(value) < sizeof buf-2);
-               strcpy(buf,value);
-               strcat(buf,"\n");
+               BUF_strlcpy(buf,value,sizeof buf);
+               BUF_strlcat(buf,"\n",sizeof buf);
                BIO_printf(bio_err,"%s\n",value);
                }
        else
@@ -1531,8 +1539,8 @@ start:
                {
                if ((def == NULL) || (def[0] == '\0'))
                        return(1);
-               strcpy(buf,def);
-               strcat(buf,"\n");
+               BUF_strlcpy(buf,def,sizeof buf);
+               BUF_strlcat(buf,"\n",sizeof buf);
                }
        else if ((buf[0] == '.') && (buf[1] == '\n')) return(1);
 
@@ -1566,9 +1574,8 @@ start:
        (void)BIO_flush(bio_err);
        if (value != NULL)
                {
-               OPENSSL_assert(strlen(value) < sizeof buf-2);
-               strcpy(buf,value);
-               strcat(buf,"\n");
+               BUF_strlcpy(buf,value,sizeof buf);
+               BUF_strlcat(buf,"\n",sizeof buf);
                BIO_printf(bio_err,"%s\n",value);
                }
        else
@@ -1590,8 +1597,8 @@ start:
                {
                if ((def == NULL) || (def[0] == '\0'))
                        return(1);
-               strcpy(buf,def);
-               strcat(buf,"\n");
+               BUF_strlcpy(buf,def,sizeof buf);
+               BUF_strlcat(buf,"\n",sizeof buf);
                }
        else if ((buf[0] == '.') && (buf[1] == '\n')) return(1);