Like MD_Init, MD now must include a NULL engine pointer in its definition.
[openssl.git] / apps / x509.c
index 5be90740c66e6a1fb01f621d5d98bc54a6d17a78..b2ea09d52fbfb48f099d028cdb2f98fee7698583 100644 (file)
@@ -73,7 +73,6 @@
 #include <openssl/x509v3.h>
 #include <openssl/objects.h>
 #include <openssl/pem.h>
-#include <openssl/engine.h>
 
 #undef PROG
 #define PROG x509_main
@@ -139,10 +138,10 @@ NULL
 
 static int MS_CALLBACK callb(int ok, X509_STORE_CTX *ctx);
 static int sign (X509 *x, EVP_PKEY *pkey,int days,int clrext, const EVP_MD *digest,
-                                               LHASH *conf, char *section);
+                                               CONF *conf, char *section);
 static int x509_certify (X509_STORE *ctx,char *CAfile,const EVP_MD *digest,
                         X509 *x,X509 *xca,EVP_PKEY *pkey,char *serial,
-                        int create,int days, int clrext, LHASH *conf, char *section,
+                        int create,int days, int clrext, CONF *conf, char *section,
                                                ASN1_INTEGER *sno);
 static int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt);
 static int reqfile=0;
@@ -179,7 +178,7 @@ int MAIN(int argc, char **argv)
        int fingerprint=0;
        char buf[256];
        const EVP_MD *md_alg,*digest=EVP_md5();
-       LHASH *extconf = NULL;
+       CONF *extconf = NULL;
        char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL;
        int need_rand = 0;
        int checkend=0,checkoffset=0;
@@ -448,23 +447,7 @@ bad:
                goto end;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if (need_rand)
                app_RAND_load_file(NULL, bio_err, 0);
@@ -495,7 +478,8 @@ bad:
                {
                long errorline;
                X509V3_CTX ctx2;
-               if (!(extconf=CONF_load(NULL,extfile,&errorline)))
+               extconf = NCONF_new(NULL);
+               if (!NCONF_load(extconf, extfile,&errorline))
                        {
                        if (errorline <= 0)
                                BIO_printf(bio_err,
@@ -509,7 +493,7 @@ bad:
                        }
                if (!extsect)
                        {
-                       extsect = CONF_get_string(extconf, "default", "extensions");
+                       extsect = NCONF_get_string(extconf, "default", "extensions");
                        if (!extsect)
                                {
                                ERR_clear_error();
@@ -517,8 +501,8 @@ bad:
                                }
                        }
                X509V3_set_ctx_test(&ctx2);
-               X509V3_set_conf_lhash(&ctx2, extconf);
-               if (!X509V3_EXT_add_conf(extconf, &ctx2, extsect, NULL))
+               X509V3_set_nconf(&ctx2, extconf);
+               if (!X509V3_EXT_add_nconf(extconf, &ctx2, extsect, NULL))
                        {
                        BIO_printf(bio_err,
                                "Error Loading extension section %s\n",
@@ -1011,7 +995,7 @@ end:
        if (need_rand)
                app_RAND_write_file(NULL, bio_err);
        OBJ_cleanup();
-       CONF_free(extconf);
+       NCONF_free(extconf);
        BIO_free_all(out);
        BIO_free_all(STDout);
        X509_STORE_free(ctx);
@@ -1025,6 +1009,7 @@ end:
        sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);
        sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);
        if (passin) OPENSSL_free(passin);
+       apps_shutdown();
        EXIT(ret);
        }
 
@@ -1131,7 +1116,7 @@ static ASN1_INTEGER *load_serial(char *CAfile, char *serialfile, int create)
 
 static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
             X509 *x, X509 *xca, EVP_PKEY *pkey, char *serialfile, int create,
-            int days, int clrext, LHASH *conf, char *section, ASN1_INTEGER *sno)
+            int days, int clrext, CONF *conf, char *section, ASN1_INTEGER *sno)
        {
        int ret=0;
        ASN1_INTEGER *bs=NULL;
@@ -1142,7 +1127,11 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
        EVP_PKEY_copy_parameters(upkey,pkey);
        EVP_PKEY_free(upkey);
 
-       X509_STORE_CTX_init(&xsc,ctx,x,NULL);
+       if(!X509_STORE_CTX_init(&xsc,ctx,x,NULL))
+               {
+               BIO_printf(bio_err,"Error initialising X509 store\n");
+               goto end;
+               }
        if (sno) bs = sno;
        else if (!(bs = load_serial(CAfile, serialfile, create)))
                goto end;
@@ -1181,8 +1170,8 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
                X509V3_CTX ctx2;
                X509_set_version(x,2); /* version 3 certificate */
                 X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);
-                X509V3_set_conf_lhash(&ctx2, conf);
-                if (!X509V3_EXT_add_conf(conf, &ctx2, section, x)) goto end;
+                X509V3_set_nconf(&ctx2, conf);
+                if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x)) goto end;
                }
 
        if (!X509_sign(x,pkey,digest)) goto end;
@@ -1228,7 +1217,7 @@ static int MS_CALLBACK callb(int ok, X509_STORE_CTX *ctx)
 
 /* self sign */
 static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest, 
-                                               LHASH *conf, char *section)
+                                               CONF *conf, char *section)
        {
 
        EVP_PKEY *pktmp;
@@ -1258,8 +1247,8 @@ static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *dig
                X509V3_CTX ctx;
                X509_set_version(x,2); /* version 3 certificate */
                 X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0);
-                X509V3_set_conf_lhash(&ctx, conf);
-                if (!X509V3_EXT_add_conf(conf, &ctx, section, x)) goto err;
+                X509V3_set_nconf(&ctx, conf);
+                if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err;
                }
        if (!X509_sign(x,pkey,digest)) goto err;
        return 1;