make update
[openssl.git] / apps / spkac.c
index 5ac9b14c54b2035c56cb1989d240ff0272ea53b9..d43dc9f3b9b480b47f58e1209248a99d26a83ae6 100644 (file)
@@ -84,13 +84,13 @@ int MAIN(int argc, char **argv)
        {
        ENGINE *e = NULL;
        int i,badops=0, ret = 1;
-       BIO *in = NULL,*out = NULL, *key = NULL;
+       BIO *in = NULL,*out = NULL;
        int verify=0,noout=0,pubkey=0;
        char *infile = NULL,*outfile = NULL,*prog;
        char *passargin = NULL, *passin = NULL;
        char *spkac = "SPKAC", *spksect = "default", *spkstr = NULL;
        char *challenge = NULL, *keyfile = NULL;
-       LHASH *conf = NULL;
+       CONF *conf = NULL;
        NETSCAPE_SPKI *spki = NULL;
        EVP_PKEY *pkey = NULL;
        char *engine=NULL;
@@ -179,36 +179,13 @@ 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(keyfile) {
-               if(strcmp(keyfile, "-")) key = BIO_new_file(keyfile, "r");
-               else key = BIO_new_fp(stdin, BIO_NOCLOSE);
-               if(!key) {
-                       BIO_printf(bio_err, "Error opening key file\n");
-                       ERR_print_errors(bio_err);
-                       goto end;
-               }
-               pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, passin);
+               pkey = load_key(bio_err,
+                               strcmp(keyfile, "-") ? keyfile : NULL,
+                               FORMAT_PEM, passin, e, "private key");
                if(!pkey) {
-                       BIO_printf(bio_err, "Error reading private key\n");
-                       ERR_print_errors(bio_err);
                        goto end;
                }
                spki = NETSCAPE_SPKI_new();
@@ -251,15 +228,16 @@ bad:
                goto end;
        }
 
-       conf = CONF_load_bio(NULL, in, NULL);
+       conf = NCONF_new(NULL);
+       i = NCONF_load_bio(conf, in, NULL);
 
-       if(!conf) {
+       if(!i) {
                BIO_printf(bio_err, "Error parsing config file\n");
                ERR_print_errors(bio_err);
                goto end;
        }
 
-       spkstr = CONF_get_string(conf, spksect, spkac);
+       spkstr = NCONF_get_string(conf, spksect, spkac);
                
        if(!spkstr) {
                BIO_printf(bio_err, "Can't find SPKAC called \"%s\"\n", spkac);
@@ -308,12 +286,12 @@ bad:
        ret = 0;
 
 end:
-       CONF_free(conf);
+       NCONF_free(conf);
        NETSCAPE_SPKI_free(spki);
        BIO_free(in);
        BIO_free_all(out);
-       BIO_free(key);
        EVP_PKEY_free(pkey);
        if(passin) OPENSSL_free(passin);
+       apps_shutdown();
        EXIT(ret);
        }