Update ocsp usage message and docs.
[oweals/openssl.git] / apps / req.c
index 4dca798e4a7bb1225daf18e4c92fe8f5c56df1bf..5f6ec3d33914072978595169d5f0ba880d5e5c2a 100644 (file)
  * [including the GNU Public Licence.]
  */
 
-/* Until the key-gen callbacks are modified to use newer prototypes, we allow
- * deprecated functions for openssl-internal code */
-#ifdef OPENSSL_NO_DEPRECATED
-#undef OPENSSL_NO_DEPRECATED
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
@@ -141,7 +135,6 @@ static int req_check_len(int len,int n_min,int n_max);
 static int check_end(char *str, char *end);
 #ifndef MONOLITH
 static char *default_config_file=NULL;
-static CONF *config=NULL;
 #endif
 static CONF *req_conf=NULL;
 static int batch=0;
@@ -149,7 +142,6 @@ static int batch=0;
 #define TYPE_RSA       1
 #define TYPE_DSA       2
 #define TYPE_DH                3
-#define TYPE_EC                4
 
 int MAIN(int, char **);
 
@@ -158,9 +150,6 @@ int MAIN(int argc, char **argv)
        ENGINE *e = NULL;
 #ifndef OPENSSL_NO_DSA
        DSA *dsa_params=NULL;
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       EC_KEY *ec_params = NULL;
 #endif
        unsigned long nmflag = 0, reqflag = 0;
        int ex=1,x509=0,days=30;
@@ -173,7 +162,9 @@ int MAIN(int argc, char **argv)
        int informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;
        int nodes=0,kludge=0,newhdr=0,subject=0,pubkey=0;
        char *infile,*outfile,*prog,*keyfile=NULL,*template=NULL,*keyout=NULL;
+#ifndef OPENSSL_NO_ENGINE
        char *engine=NULL;
+#endif
        char *extensions = NULL;
        char *req_exts = NULL;
        const EVP_CIPHER *cipher=NULL;
@@ -221,11 +212,13 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        outformat=str2fmt(*(++argv));
                        }
+#ifndef OPENSSL_NO_ENGINE
                else if (strcmp(*argv,"-engine") == 0)
                        {
                        if (--argc < 1) goto bad;
                        engine= *(++argv);
                        }
+#endif
                else if (strcmp(*argv,"-key") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -329,58 +322,10 @@ int MAIN(int argc, char **argv)
                                                }
                                        }
                                BIO_free(in);
-                               in=NULL;
                                newkey=BN_num_bits(dsa_params->p);
-                               }
-                       else 
-#endif
-#ifndef OPENSSL_NO_ECDSA
-                               if (strncmp("ec:",p,3) == 0)
-                               {
-                               X509 *xtmp=NULL;
-                               EVP_PKEY *dtmp;
-
-                               pkey_type=TYPE_EC;
-                               p+=3;
-                               if ((in=BIO_new_file(p,"r")) == NULL)
-                                       {
-                                       perror(p);
-                                       goto end;
-                                       }
-                               if ((ec_params = EC_KEY_new()) == NULL)
-                                       goto end;
-                               if ((ec_params->group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL)) == NULL)
-                                       {
-                                       if (ec_params)
-                                               EC_KEY_free(ec_params);
-                                       ERR_clear_error();
-                                       (void)BIO_reset(in);
-                                       if ((xtmp=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL)
-                                               {       
-                                               BIO_printf(bio_err,"unable to load EC parameters from file\n");
-                                               goto end;
-                                               }
-
-                                       if ((dtmp=X509_get_pubkey(xtmp))==NULL)
-                                               goto end;
-                                       if (dtmp->type == EVP_PKEY_EC)
-                                               ec_params = ECParameters_dup(dtmp->pkey.eckey);
-                                       EVP_PKEY_free(dtmp);
-                                       X509_free(xtmp);
-                                       if (ec_params == NULL)
-                                               {
-                                               BIO_printf(bio_err,"Certificate does not contain EC parameters\n");
-                                               goto end;
-                                               }
-                                       }
-
-                               BIO_free(in);
                                in=NULL;
-                               
-                               newkey = EC_GROUP_get_degree(ec_params->group);
-
                                }
-                       else
+                       else 
 #endif
 #ifndef OPENSSL_NO_DH
                                if (strncmp("dh:",p,4) == 0)
@@ -390,9 +335,7 @@ int MAIN(int argc, char **argv)
                                }
                        else
 #endif
-                               {
-                               goto bad;
-                               }
+                               pkey_type=TYPE_RSA;
 
                        newreq=1;
                        }
@@ -489,7 +432,9 @@ bad:
                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");
+#ifndef OPENSSL_NO_ENGINE
                BIO_printf(bio_err," -engine e      use engine e, possibly a hardware device\n");
+#endif
                BIO_printf(bio_err," -subject       output the request's subject\n");
                BIO_printf(bio_err," -passin        private key password source\n");
                BIO_printf(bio_err," -key file      use the private key contained in file\n");
@@ -500,9 +445,6 @@ bad:
                BIO_printf(bio_err,"                the random number generator\n");
                BIO_printf(bio_err," -newkey rsa:bits generate a new RSA key of 'bits' in size\n");
                BIO_printf(bio_err," -newkey dsa:file generate a new DSA key, parameters taken from CA in 'file'\n");
-#ifndef OPENSSL_NO_ECDSA
-               BIO_printf(bio_err," -newkey ec:file generate a new EC key, parameters taken from CA in 'file'\n");
-#endif
                BIO_printf(bio_err," -[digest]      Digest to sign with (md5, sha1, md2, mdc2, md4)\n");
                BIO_printf(bio_err," -config file   request template file.\n");
                BIO_printf(bio_err," -subj arg      set or modify request subject\n");
@@ -517,7 +459,7 @@ bad:
                BIO_printf(bio_err," -extensions .. specify certificate extension section (override value in config file)\n");
                BIO_printf(bio_err," -reqexts ..    specify request extension section (override value in config file)\n");
                BIO_printf(bio_err," -utf8          input characters are UTF8 (default ASCII)\n");
-               BIO_printf(bio_err," -nameopt arg   - various certificate name options\n");
+               BIO_printf(bio_err," -nameopt arg    - various certificate name options\n");
                BIO_printf(bio_err," -reqopt arg    - various request text options\n\n");
                goto end;
                }
@@ -681,7 +623,9 @@ bad:
        if ((in == NULL) || (out == NULL))
                goto end;
 
+#ifndef OPENSSL_NO_ENGINE
         e = setup_engine(bio_err, engine, 0);
+#endif
 
        if (keyfile != NULL)
                {
@@ -693,8 +637,7 @@ bad:
                           message */
                        goto end;
                        }
-               if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA || 
-                       EVP_PKEY_type(pkey->type) == EVP_PKEY_EC)
+               if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA)
                        {
                        char *randfile = NCONF_get_string(req_conf,SECTION,"RANDFILE");
                        if (randfile == NULL)
@@ -718,15 +661,14 @@ bad:
                                newkey=DEFAULT_KEY_LENGTH;
                        }
 
-               if (newkey < MIN_KEY_LENGTH && (pkey_type == TYPE_RSA || pkey_type == TYPE_DSA))
+               if (newkey < MIN_KEY_LENGTH)
                        {
                        BIO_printf(bio_err,"private key length is too short,\n");
                        BIO_printf(bio_err,"it needs to be at least %d bits, not %d\n",MIN_KEY_LENGTH,newkey);
                        goto end;
                        }
                BIO_printf(bio_err,"Generating a %d bit %s private key\n",
-                       newkey,(pkey_type == TYPE_RSA)?"RSA":
-                       (pkey_type == TYPE_DSA)?"DSA":"EC");
+                       newkey,(pkey_type == TYPE_RSA)?"RSA":"DSA");
 
                if ((pkey=EVP_PKEY_new()) == NULL) goto end;
 
@@ -748,15 +690,6 @@ bad:
                        dsa_params=NULL;
                        }
 #endif
-#ifndef OPENSSL_NO_ECDSA
-                       if (pkey_type == TYPE_EC)
-                       {
-                       if (!EC_KEY_generate_key(ec_params)) goto end;
-                       if (!EVP_PKEY_assign_EC_KEY(pkey, ec_params)) 
-                               goto end;
-                       ec_params = NULL;
-                       }
-#endif
 
                app_RAND_write_file(randfile, bio_err);
 
@@ -862,10 +795,6 @@ loop:
 #ifndef OPENSSL_NO_DSA
                if (pkey->type == EVP_PKEY_DSA)
                        digest=EVP_dss1();
-#endif
-#ifndef OPENSSL_NO_ECDSA
-               if (pkey->type == EVP_PKEY_EC)
-                       digest=EVP_ecdsa();
 #endif
                if (req == NULL)
                        {
@@ -1151,9 +1080,6 @@ end:
        OBJ_cleanup();
 #ifndef OPENSSL_NO_DSA
        if (dsa_params != NULL) DSA_free(dsa_params);
-#endif
-#ifndef OPENSSL_NO_ECDSA
-       if (ec_params != NULL) EC_KEY_free(ec_params);
 #endif
        apps_shutdown();
        OPENSSL_EXIT(ex);
@@ -1319,11 +1245,17 @@ start:          for (;;)
 
                        sprintf(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);
                        if (!NCONF_get_number(req_conf,dn_sect,buf, &n_max))
+                               {
+                               ERR_clear_error();
                                n_max = -1;
+                               }
 
                        if (!add_DN_object(subj,v->value,def,value,nid,
                                n_min,n_max, chtype))