> I have a patch for the openssl app that enables some command-line options
> to make openssl completely non-interactive. I've found this to be of
> value.
I've been told this mailing list is the right place for it, so here it is:
diff -u --recursive --new-file old/openssl-0.9.3a/apps/MagicPassword.c
new/openssl-0.9.3a/apps/MagicPassword.c
--- old/openssl-0.9.3a/apps/MagicPassword.c Wed Dec 31 16:00:00 1969
+++ new/openssl-0.9.3a/apps/MagicPassword.c Fri Jun 18 03:57:26 1999
@@ -0,0 +1,75 @@
+/* MagicPassword.c */
+
+#include <openssl/MagicPassword.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* global password: */
+
+char *MagicPassword__Password = 0;
+
+/* interface: */
+
+int MagicPassword__set (char *cP)
+{
+ int len;
+
+ /* clean up old password: */
+ if (MagicPassword__Password) { free (MagicPassword__Password); }
+
+ /* allocate memory */
+ len = strlen(cP);
+ if (len > MAGICPASSWORD_MAXLEN) { return 0; }
+ MagicPassword__Password = (char*)malloc (len + 1);
+ if (!MagicPassword__Password) { return 0; }
+
+ /* save a copy of the password */
+ strcpy (MagicPassword__Password, cP);
+
+ return 1; /* success */
+}
+
+char *MagicPassword__get (void)
+{
+ return MagicPassword__Password;
+}
+
+/* hackargs
+ *
+ * hackargs goes through the arguement list, rips out a -pw <password>
+ * option, and recreates Argv so that the app never knows the difference.
+ * I'm so lazy, eh?
+ */
+int MagicPassword__hackargs(int Argc, char *Argv[])
+{
+ int i,j;
+ char *cP;
+
+ for (i = 0; i < Argc; i++)
+ {
+ cP = Argv[i];
+ if (strncmp(cP, "-pw", 20) == 0 && ( (i+1) < Argc ))
+ {
+ /* ah ha! here's a password! */
+ MagicPassword__set( Argv[ i+1 ] );
+
+ /* should I free the memory used by -pw password? */
+ /* I'm afraid to. :-( It's not a big deal anywho */
+
+ /* now fix the arguement stack: */
+ for (j = i+2; j < Argc; j++)
+ {
+ Argv[j-2] = Argv[j];
+ }
+
+ /* now bail: */
+ return (Argc-2);
+ }
+ }
+
+ /* no password found. Bleah! */
+ return Argc;
+}
+
+/* eof */
+
diff -u --recursive --new-file old/openssl-0.9.3a/apps/Makefile
new/openssl-0.9.3a/apps/Makefile
--- old/openssl-0.9.3a/apps/Makefile Sun May 23 05:36:09 1999
+++ new/openssl-0.9.3a/apps/Makefile Fri Jun 18 03:59:18 1999
@@ -50,7 +50,8 @@
rsa.o dsa.o dsaparam.o \
x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o \
s_time.o $(A_OBJ) $(S_OBJ) version.o sess_id.o \
- ciphers.o nseq.o pkcs12.o
+ ciphers.o nseq.o pkcs12.o \
+ MagicPassword.o
# pem_mail.o
@@ -440,6 +441,8 @@
openssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
openssl.o: ../include/openssl/tls1.h ../include/openssl/x509.h
openssl.o: ../include/openssl/x509_vfy.h apps.h progs.h s_apps.h
+openssl.o: ../include/openssl/MagicPassword.h
+MagicPassword.o: ../include/openssl/MagicPassword.h
pkcs7.o: ../include/openssl/asn1.h ../include/openssl/bio.h
pkcs7.o: ../include/openssl/blowfish.h ../include/openssl/bn.h
pkcs7.o: ../include/openssl/buffer.h ../include/openssl/cast.h
diff -u --recursive --new-file old/openssl-0.9.3a/apps/Makefile.ssl
new/openssl-0.9.3a/apps/Makefile.ssl
--- old/openssl-0.9.3a/apps/Makefile.ssl Sun May 23 05:36:09 1999
+++ new/openssl-0.9.3a/apps/Makefile.ssl Fri Jun 18 03:59:18 1999
@@ -50,7 +50,8 @@
rsa.o dsa.o dsaparam.o \
x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o \
s_time.o $(A_OBJ) $(S_OBJ) version.o sess_id.o \
- ciphers.o nseq.o pkcs12.o
+ ciphers.o nseq.o pkcs12.o \
+ MagicPassword.o
# pem_mail.o
@@ -440,6 +441,8 @@
openssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
openssl.o: ../include/openssl/tls1.h ../include/openssl/x509.h
openssl.o: ../include/openssl/x509_vfy.h apps.h progs.h s_apps.h
+openssl.o: ../include/openssl/MagicPassword.h
+MagicPassword.o: ../include/openssl/MagicPassword.h
pkcs7.o: ../include/openssl/asn1.h ../include/openssl/bio.h
pkcs7.o: ../include/openssl/blowfish.h ../include/openssl/bn.h
pkcs7.o: ../include/openssl/buffer.h ../include/openssl/cast.h
diff -u --recursive --new-file old/openssl-0.9.3a/apps/openssl.c
new/openssl-0.9.3a/apps/openssl.c
--- old/openssl-0.9.3a/apps/openssl.c Thu May 13 04:36:27 1999
+++ new/openssl-0.9.3a/apps/openssl.c Fri Jun 18 03:57:50 1999
@@ -76,6 +76,7 @@
#include "apps.h"
#include "s_apps.h"
#include <openssl/err.h>
+#include <openssl/MagicPassword.h>
/*
#ifdef WINDOWS
@@ -116,6 +117,9 @@
char **argv,*p;
LHASH *prog=NULL;
long errline;
+
+ /* MagicPassword hack at the arguement stack: */
+ Argc = MagicPassword__hackargs(Argc, Argv); /* rock and roll */
arg.data=NULL;
arg.count=0;
diff -u --recursive --new-file old/openssl-0.9.3a/crypto/des/Makefile
new/openssl-0.9.3a/crypto/des/Makefile
--- old/openssl-0.9.3a/crypto/des/Makefile Sat May 29 07:13:56 1999
+++ new/openssl-0.9.3a/crypto/des/Makefile Fri Jun 18 03:59:10 1999
@@ -32,7 +32,8 @@
qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \
des_enc.c fcrypt_b.c read2pwd.c \
fcrypt.c xcbc_enc.c \
- str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c
+ str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c \
+ ../../apps/MagicPassword.c
LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
@@ -40,7 +41,8 @@
ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
${DES_ENC} read2pwd.o \
fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o \
- ede_cbcm_enc.o
+ ede_cbcm_enc.o \
+ ../../apps/MagicPassword.o
SRC= $(LIBSRC)
@@ -193,6 +195,8 @@
read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
read_pwd.o: ../cryptlib.h des_locl.h
+read_pwd.o: ../../include/openssl/MagicPassword.h
+../../apps/MagicPassword.o: ../../include/openssl/MagicPassword.h
rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h
set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
diff -u --recursive --new-file old/openssl-0.9.3a/crypto/des/Makefile.ssl
new/openssl-0.9.3a/crypto/des/Makefile.ssl
--- old/openssl-0.9.3a/crypto/des/Makefile.ssl Sat May 29 07:13:56 1999
+++ new/openssl-0.9.3a/crypto/des/Makefile.ssl Fri Jun 18 03:59:10 1999
@@ -32,7 +32,8 @@
qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \
des_enc.c fcrypt_b.c read2pwd.c \
fcrypt.c xcbc_enc.c \
- str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c
+ str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c \
+ ../../apps/MagicPassword.c
LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
@@ -40,7 +41,8 @@
ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
${DES_ENC} read2pwd.o \
fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o \
- ede_cbcm_enc.o
+ ede_cbcm_enc.o \
+ ../../apps/MagicPassword.o
SRC= $(LIBSRC)
@@ -193,6 +195,8 @@
read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
read_pwd.o: ../cryptlib.h des_locl.h
+read_pwd.o: ../../include/openssl/MagicPassword.h
+../../apps/MagicPassword.o: ../../include/openssl/MagicPassword.h
rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h
set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
diff -u --recursive --new-file old/openssl-0.9.3a/crypto/des/read_pwd.c
new/openssl-0.9.3a/crypto/des/read_pwd.c
--- old/openssl-0.9.3a/crypto/des/read_pwd.c Sat May 29 07:13:56 1999
+++ new/openssl-0.9.3a/crypto/des/read_pwd.c Fri Jun 18 03:59:03 1999
@@ -87,6 +87,9 @@
#include <setjmp.h>
#include <errno.h>
+/* 18-Jun-99 Jonathan Mayer Support MagicPassword */
+#include <openssl/MagicPassword.h>
+
#ifdef VMS /* prototypes for sys$whatever */
#include <starlet.h>
#ifdef __DECC
@@ -242,6 +245,16 @@
int is_a_tty;
static FILE *tty;
char *p;
+
+ /* check for the Maaaagic password: */
+ char *magicpw;
+ magicpw = MagicPassword__get();
+ if (magicpw) {
+ /* I have the password! skip everything else! */
+ strncpy (buf, magicpw, size);
+ return 0;
+ /* whew! */
+ }
if (setjmp(save))
{
diff -u --recursive --new-file old/openssl-0.9.3a/include/openssl/MagicPassword.h
new/openssl-0.9.3a/include/openssl/MagicPassword.h
--- old/openssl-0.9.3a/include/openssl/MagicPassword.h Wed Dec 31 16:00:00 1969
+++ new/openssl-0.9.3a/include/openssl/MagicPassword.h Fri Jun 18 03:58:15 1999
@@ -0,0 +1,14 @@
+/* MagicPassword.h */
+
+/* global password: */
+#define MAGICPASSWORD_MAXLEN 512
+extern char *MagicPassword__Password ;
+
+/* interface: */
+
+int MagicPassword__set (char *);
+char *MagicPassword__get (void);
+int MagicPassword__hackargs(int Argc, char *Argv[]);
+
+/* eof */
+
diff -u --recursive --new-file old/openssl-0.9.3a/apps/req.c openssl-0.9.3a/apps/req.c
--- old/openssl-0.9.3a/apps/req.c Thu May 13 04:36:27 1999
+++ new/openssl-0.9.3a/apps/req.c Mon Jun 21 23:38:48 1999
@@ -123,6 +123,9 @@
#endif
static LHASH *req_conf=NULL;
+/* for the -defaults option, non-interactive use */
+static int hack_use_defaults=0;
+
#define TYPE_RSA 1
#define TYPE_DSA 2
#define TYPE_DH 3
@@ -163,6 +166,7 @@
outfile=NULL;
informat=FORMAT_PEM;
outformat=FORMAT_PEM;
+ hack_use_defaults = 0; /* default is to not use defaults :-) */
prog=argv[0];
argc--;
@@ -174,6 +178,11 @@
if (--argc < 1) goto bad;
informat=str2fmt(*(++argv));
}
+ else if (strcmp(*argv,"-defaults") == 0)
+ {
+ /* run non-interactively */
+ hack_use_defaults = 1;
+ }
else if (strcmp(*argv,"-outform") == 0)
{
if (--argc < 1) goto bad;
@@ -989,7 +998,12 @@
else
{
buf[0]='\0';
- fgets(buf,1024,stdin);
+ if (hack_use_defaults) {
+ BIO_printf(bio_err,"\n");
+ buf[0]='\n'; buf[1]='\0';
+ } else {
+ fgets(buf,1024,stdin);
+ }
}
if (buf[0] == '\0') return(0);
@@ -1047,7 +1061,12 @@
else
{
buf[0]='\0';
- fgets(buf,1024,stdin);
+ if (hack_use_defaults) {
+ BIO_printf(bio_err,"\n");
+ buf[0]='\n'; buf[1]='\0';
+ } else {
+ fgets(buf,1024,stdin);
+ }
}
if (buf[0] == '\0') return(0);
--------------------- [EMAIL PROTECTED] -----------------------
"What I say is that, if a fellow really likes potatoes, he must be
a pretty decent sort of fellow." - A. A. Milne
------------------------------------------------------------------
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]