Add an #include.
[openssl.git] / apps / spkac.c
index 34b0026e01078e90b8defd5319af47a022f893d7..f69dc5c2612a66e5960a1b37aede5ca704228671 100644 (file)
@@ -65,6 +65,7 @@
 #include <openssl/bio.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
+#include <openssl/lhash.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
 
  * -out arg    - output file - default stdout
  */
 
+int MAIN(int, char **);
+
 int MAIN(int argc, char **argv)
        {
        int i,badops=0, ret = 1;
        BIO *in = NULL,*out = NULL, *key = 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;
@@ -106,6 +110,11 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        outfile= *(++argv);
                        }
+               else if (strcmp(*argv,"-passin") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       passargin= *(++argv);
+                       }
                else if (strcmp(*argv,"-key") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -145,6 +154,7 @@ bad:
                BIO_printf(bio_err," -in arg        input file\n");
                BIO_printf(bio_err," -out arg       output file\n");
                BIO_printf(bio_err," -key arg       create SPKAC using private key\n");
+               BIO_printf(bio_err," -passin arg    input file pass phrase source\n");
                BIO_printf(bio_err," -challenge arg challenge string\n");
                BIO_printf(bio_err," -spkac arg     alternative SPKAC name\n");
                BIO_printf(bio_err," -noout         don't print SPKAC\n");
@@ -154,6 +164,10 @@ bad:
                }
 
        ERR_load_crypto_strings();
+       if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
+               BIO_printf(bio_err, "Error getting password\n");
+               goto end;
+       }
 
        if(keyfile) {
                if(strcmp(keyfile, "-")) key = BIO_new_file(keyfile, "r");
@@ -163,7 +177,7 @@ bad:
                        ERR_print_errors(bio_err);
                        goto end;
                }
-               pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, NULL);
+               pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, passin);
                if(!pkey) {
                        BIO_printf(bio_err, "Error reading private key\n");
                        ERR_print_errors(bio_err);
@@ -256,5 +270,6 @@ end:
        BIO_free(out);
        BIO_free(key);
        EVP_PKEY_free(pkey);
+       if(passin) Free(passin);
        EXIT(ret);
        }