diff options
author | kris <kris@FreeBSD.org> | 2000-04-13 06:33:22 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2000-04-13 06:33:22 +0000 |
commit | 54c77f990d8a5f46f1d18b67cddb279f49176146 (patch) | |
tree | 85b9c007d5ac1d91a3895eef3fd18d6114b62cc4 /crypto/openssl/apps | |
parent | 7e4e44947b1aa16034c99654c268dc92300be719 (diff) | |
download | FreeBSD-src-54c77f990d8a5f46f1d18b67cddb279f49176146.zip FreeBSD-src-54c77f990d8a5f46f1d18b67cddb279f49176146.tar.gz |
Initial import of OpenSSL 0.9.5a
Diffstat (limited to 'crypto/openssl/apps')
52 files changed, 5419 insertions, 1243 deletions
diff --git a/crypto/openssl/apps/CA.pl b/crypto/openssl/apps/CA.pl index 7c023ae..4eef57e 100755 --- a/crypto/openssl/apps/CA.pl +++ b/crypto/openssl/apps/CA.pl @@ -41,6 +41,7 @@ $REQ="openssl req $SSLEAY_CONFIG"; $CA="openssl ca $SSLEAY_CONFIG"; $VERIFY="openssl verify"; $X509="openssl x509"; +$PKCS12="openssl pkcs12"; $CATOP="./demoCA"; $CAKEY="cakey.pem"; @@ -65,7 +66,7 @@ foreach (@ARGV) { $RET=$?; print "Request (and private key) is in newreq.pem\n"; } elsif (/^-newca$/) { - # if explictly asked for or it doesn't exist then setup the + # if explicitly asked for or it doesn't exist then setup the # directory structure that Eric likes to manage things $NEW="1"; if ( "$NEW" || ! -f "${CATOP}/serial" ) { @@ -99,6 +100,14 @@ foreach (@ARGV) { $RET=$?; } } + } elsif (/^-pkcs12$/) { + my $cname = $ARGV[1]; + $cname = "My Certificate" unless defined $cname; + system ("$PKCS12 -in newcert.pem -inkey newreq.pem " . + "-certfile ${CATOP}/$CACERT -out newcert.p12 " . + "-export -name \"$cname\""); + $RET=$?; + exit $RET; } elsif (/^-xsign$/) { system ("$CA -policy policy_anything -infiles newreq.pem"); $RET=$?; diff --git a/crypto/openssl/apps/CA.pl.in b/crypto/openssl/apps/CA.pl.in new file mode 100644 index 0000000..4eef57e --- /dev/null +++ b/crypto/openssl/apps/CA.pl.in @@ -0,0 +1,162 @@ +#!/usr/local/bin/perl +# +# CA - wrapper around ca to make it easier to use ... basically ca requires +# some setup stuff to be done before you can use it and this makes +# things easier between now and when Eric is convinced to fix it :-) +# +# CA -newca ... will setup the right stuff +# CA -newreq ... will generate a certificate request +# CA -sign ... will sign the generated request and output +# +# At the end of that grab newreq.pem and newcert.pem (one has the key +# and the other the certificate) and cat them together and that is what +# you want/need ... I'll make even this a little cleaner later. +# +# +# 12-Jan-96 tjh Added more things ... including CA -signcert which +# converts a certificate to a request and then signs it. +# 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG +# environment variable so this can be driven from +# a script. +# 25-Jul-96 eay Cleaned up filenames some more. +# 11-Jun-96 eay Fixed a few filename missmatches. +# 03-May-96 eay Modified to use 'ssleay cmd' instead of 'cmd'. +# 18-Apr-96 tjh Original hacking +# +# Tim Hudson +# tjh@cryptsoft.com +# + +# 27-Apr-98 snh Translation into perl, fix existing CA bug. +# +# +# Steve Henson +# shenson@bigfoot.com + +# default openssl.cnf file has setup as per the following +# demoCA ... where everything is stored + +$DAYS="-days 365"; +$REQ="openssl req $SSLEAY_CONFIG"; +$CA="openssl ca $SSLEAY_CONFIG"; +$VERIFY="openssl verify"; +$X509="openssl x509"; +$PKCS12="openssl pkcs12"; + +$CATOP="./demoCA"; +$CAKEY="cakey.pem"; +$CACERT="cacert.pem"; + +$DIRMODE = 0777; + +$RET = 0; + +foreach (@ARGV) { + if ( /^(-\?|-h|-help)$/ ) { + print STDERR "usage: CA -newcert|-newreq|-newca|-sign|-verify\n"; + exit 0; + } elsif (/^-newcert$/) { + # create a certificate + system ("$REQ -new -x509 -keyout newreq.pem -out newreq.pem $DAYS"); + $RET=$?; + print "Certificate (and private key) is in newreq.pem\n" + } elsif (/^-newreq$/) { + # create a certificate request + system ("$REQ -new -keyout newreq.pem -out newreq.pem $DAYS"); + $RET=$?; + print "Request (and private key) is in newreq.pem\n"; + } elsif (/^-newca$/) { + # if explicitly asked for or it doesn't exist then setup the + # directory structure that Eric likes to manage things + $NEW="1"; + if ( "$NEW" || ! -f "${CATOP}/serial" ) { + # create the directory hierarchy + mkdir $CATOP, $DIRMODE; + mkdir "${CATOP}/certs", $DIRMODE; + mkdir "${CATOP}/crl", $DIRMODE ; + mkdir "${CATOP}/newcerts", $DIRMODE; + mkdir "${CATOP}/private", $DIRMODE; + open OUT, ">${CATOP}/serial"; + print OUT "01\n"; + close OUT; + open OUT, ">${CATOP}/index.txt"; + close OUT; + } + if ( ! -f "${CATOP}/private/$CAKEY" ) { + print "CA certificate filename (or enter to create)\n"; + $FILE = <STDIN>; + + chop $FILE; + + # ask user for existing CA certificate + if ($FILE) { + cp_pem($FILE,"${CATOP}/private/$CAKEY", "PRIVATE"); + cp_pem($FILE,"${CATOP}/$CACERT", "CERTIFICATE"); + $RET=$?; + } else { + print "Making CA certificate ...\n"; + system ("$REQ -new -x509 -keyout " . + "${CATOP}/private/$CAKEY -out ${CATOP}/$CACERT $DAYS"); + $RET=$?; + } + } + } elsif (/^-pkcs12$/) { + my $cname = $ARGV[1]; + $cname = "My Certificate" unless defined $cname; + system ("$PKCS12 -in newcert.pem -inkey newreq.pem " . + "-certfile ${CATOP}/$CACERT -out newcert.p12 " . + "-export -name \"$cname\""); + $RET=$?; + exit $RET; + } elsif (/^-xsign$/) { + system ("$CA -policy policy_anything -infiles newreq.pem"); + $RET=$?; + } elsif (/^(-sign|-signreq)$/) { + system ("$CA -policy policy_anything -out newcert.pem " . + "-infiles newreq.pem"); + $RET=$?; + print "Signed certificate is in newcert.pem\n"; + } elsif (/^-signcert$/) { + system ("$X509 -x509toreq -in newreq.pem -signkey newreq.pem " . + "-out tmp.pem"); + system ("$CA -policy policy_anything -out newcert.pem " . + "-infiles tmp.pem"); + $RET = $?; + print "Signed certificate is in newcert.pem\n"; + } elsif (/^-verify$/) { + if (shift) { + foreach $j (@ARGV) { + system ("$VERIFY -CAfile $CATOP/$CACERT $j"); + $RET=$? if ($? != 0); + } + exit $RET; + } else { + system ("$VERIFY -CAfile $CATOP/$CACERT newcert.pem"); + $RET=$?; + exit 0; + } + } else { + print STDERR "Unknown arg $_\n"; + print STDERR "usage: CA -newcert|-newreq|-newca|-sign|-verify\n"; + exit 1; + } +} + +exit $RET; + +sub cp_pem { +my ($infile, $outfile, $bound) = @_; +open IN, $infile; +open OUT, ">$outfile"; +my $flag = 0; +while (<IN>) { + $flag = 1 if (/^-----BEGIN.*$bound/) ; + print OUT $_ if ($flag); + if (/^-----END.*$bound/) { + close IN; + close OUT; + return; + } +} +} + diff --git a/crypto/openssl/apps/CA.sh b/crypto/openssl/apps/CA.sh index 728f5bf..d9f3069 100644 --- a/crypto/openssl/apps/CA.sh +++ b/crypto/openssl/apps/CA.sh @@ -60,7 +60,7 @@ case $i in echo "Request (and private key) is in newreq.pem" ;; -newca) - # if explictly asked for or it doesn't exist then setup the directory + # if explicitly asked for or it doesn't exist then setup the directory # structure that Eric likes to manage things NEW="1" if [ "$NEW" -o ! -f ${CATOP}/serial ]; then diff --git a/crypto/openssl/apps/Makefile.save b/crypto/openssl/apps/Makefile.save new file mode 100644 index 0000000..b8d0b1b --- /dev/null +++ b/crypto/openssl/apps/Makefile.save @@ -0,0 +1,818 @@ +# +# apps/Makefile.ssl +# + +DIR= apps +TOP= .. +CC= cc +INCLUDES= -I../include +CFLAG= -g -static +INSTALL_PREFIX= +INSTALLTOP= /usr/local/ssl +OPENSSLDIR= /usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) +MAKEFILE= Makefile.ssl +PERL=/usr/local/bin/perl +RM= rm -f + +PEX_LIBS= +EX_LIBS= + +CFLAGS= -DMONOLITH $(INCLUDES) $(CFLAG) + +GENERAL=Makefile makeapps.com install.com + +DLIBCRYPTO=../libcrypto.a +DLIBSSL=../libssl.a +LIBCRYPTO=-L.. -lcrypto +LIBSSL=-L.. -lssl + +PROGRAM= openssl + +SCRIPTS=CA.sh CA.pl der_chop + +EXE= $(PROGRAM) + +E_EXE= verify asn1pars req dgst dh dhparam enc passwd gendh errstr \ + ca crl rsa dsa dsaparam \ + x509 genrsa gendsa s_server s_client speed \ + s_time version pkcs7 crl2pkcs7 sess_id ciphers nseq pkcs12 \ + pkcs8 spkac smime rand + +PROGS= $(PROGRAM).c + +A_OBJ=apps.o +A_SRC=apps.c +S_OBJ= s_cb.o s_socket.o +S_SRC= s_cb.c s_socket.c +RAND_OBJ=app_rand.o +RAND_SRC=app_rand.c + +E_OBJ= verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o \ + ca.o pkcs7.o crl2p7.o crl.o \ + 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) $(RAND_OBJ) version.o sess_id.o \ + ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o + +E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c passwd.c gendh.c errstr.c ca.c \ + pkcs7.c crl2p7.c crl.c \ + rsa.c dsa.c dsaparam.c \ + x509.c genrsa.c gendsa.c s_server.c s_client.c speed.c \ + s_time.c $(A_SRC) $(S_SRC) $(RAND_SRC) version.c sess_id.c \ + ciphers.c nseq.c pkcs12.c pkcs8.c spkac.c smime.c rand.c + +SRC=$(E_SRC) + +EXHEADER= +HEADER= apps.h progs.h s_apps.h \ + testdsa.h testrsa.h \ + $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + @(cd ..; $(MAKE) DIRS=$(DIR) all) + +all: exe + +exe: $(EXE) + +req: sreq.o $(A_OBJ) $(DLIBCRYPTO) + $(CC) -o req $(CFLAG) sreq.o $(A_OBJ) $(RAND_OBJ) $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) + +sreq.o: req.c + $(CC) -c $(INCLUDES) $(CFLAG) -o sreq.o req.c + +files: + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +install: + @for i in $(EXE); \ + do \ + (echo installing $$i; \ + cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i; \ + chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \ + done; + @for i in $(SCRIPTS); \ + do \ + (echo installing $$i; \ + cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i; \ + chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \ + done + @cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR); \ + chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf + +tags: + ctags $(SRC) + +tests: + +links: + @$(TOP)/util/point.sh Makefile.ssl Makefile + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(SRC) + +dclean: + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE) + rm -f req + +$(DLIBSSL): + (cd ../ssl; $(MAKE)) + +$(DLIBCRYPTO): + (cd ../crypto; $(MAKE)) + +$(PROGRAM): progs.h $(E_OBJ) $(PROGRAM).o $(DLIBCRYPTO) $(DLIBSSL) + $(RM) $(PROGRAM) + $(CC) -o $(PROGRAM) $(CFLAGS) $(PROGRAM).o $(E_OBJ) $(PEX_LIBS) $(LIBSSL) $(LIBCRYPTO) $(EX_LIBS) + @(cd ..; OPENSSL="`pwd`/apps/openssl"; export OPENSSL; sh tools/c_rehash certs) + +progs.h: progs.pl + $(PERL) progs.pl $(E_EXE) >progs.h + $(RM) $(PROGRAM).o + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +app_rand.o: ../include/openssl/asn1.h ../include/openssl/bio.h +app_rand.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +app_rand.o: ../include/openssl/buffer.h ../include/openssl/cast.h +app_rand.o: ../include/openssl/crypto.h ../include/openssl/des.h +app_rand.o: ../include/openssl/dh.h ../include/openssl/dsa.h +app_rand.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +app_rand.o: ../include/openssl/evp.h ../include/openssl/idea.h +app_rand.o: ../include/openssl/md2.h ../include/openssl/md5.h +app_rand.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +app_rand.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +app_rand.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h +app_rand.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +app_rand.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +app_rand.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +app_rand.o: ../include/openssl/sha.h ../include/openssl/stack.h +app_rand.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +apps.o: ../include/openssl/asn1.h ../include/openssl/bio.h +apps.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +apps.o: ../include/openssl/buffer.h ../include/openssl/cast.h +apps.o: ../include/openssl/crypto.h ../include/openssl/des.h +apps.o: ../include/openssl/dh.h ../include/openssl/dsa.h +apps.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +apps.o: ../include/openssl/evp.h ../include/openssl/idea.h +apps.o: ../include/openssl/md2.h ../include/openssl/md5.h +apps.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +apps.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +apps.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +apps.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +apps.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +apps.o: ../include/openssl/safestack.h ../include/openssl/sha.h +apps.o: ../include/openssl/stack.h ../include/openssl/x509.h +apps.o: ../include/openssl/x509_vfy.h apps.h +asn1pars.o: ../include/openssl/asn1.h ../include/openssl/bio.h +asn1pars.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +asn1pars.o: ../include/openssl/buffer.h ../include/openssl/cast.h +asn1pars.o: ../include/openssl/crypto.h ../include/openssl/des.h +asn1pars.o: ../include/openssl/dh.h ../include/openssl/dsa.h +asn1pars.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +asn1pars.o: ../include/openssl/err.h ../include/openssl/evp.h +asn1pars.o: ../include/openssl/idea.h ../include/openssl/md2.h +asn1pars.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +asn1pars.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +asn1pars.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +asn1pars.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +asn1pars.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +asn1pars.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +asn1pars.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +asn1pars.o: ../include/openssl/sha.h ../include/openssl/stack.h +asn1pars.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +ca.o: ../include/openssl/asn1.h ../include/openssl/bio.h +ca.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +ca.o: ../include/openssl/buffer.h ../include/openssl/cast.h +ca.o: ../include/openssl/conf.h ../include/openssl/crypto.h +ca.o: ../include/openssl/des.h ../include/openssl/dh.h ../include/openssl/dsa.h +ca.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +ca.o: ../include/openssl/err.h ../include/openssl/evp.h +ca.o: ../include/openssl/idea.h ../include/openssl/lhash.h +ca.o: ../include/openssl/md2.h ../include/openssl/md5.h +ca.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +ca.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +ca.o: ../include/openssl/pem.h ../include/openssl/pem2.h +ca.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +ca.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +ca.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +ca.o: ../include/openssl/safestack.h ../include/openssl/sha.h +ca.o: ../include/openssl/stack.h ../include/openssl/txt_db.h +ca.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +ca.o: ../include/openssl/x509v3.h apps.h +ciphers.o: ../include/openssl/asn1.h ../include/openssl/bio.h +ciphers.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +ciphers.o: ../include/openssl/buffer.h ../include/openssl/cast.h +ciphers.o: ../include/openssl/crypto.h ../include/openssl/des.h +ciphers.o: ../include/openssl/dh.h ../include/openssl/dsa.h +ciphers.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +ciphers.o: ../include/openssl/err.h ../include/openssl/evp.h +ciphers.o: ../include/openssl/idea.h ../include/openssl/lhash.h +ciphers.o: ../include/openssl/md2.h ../include/openssl/md5.h +ciphers.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +ciphers.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +ciphers.o: ../include/openssl/pem.h ../include/openssl/pem2.h +ciphers.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +ciphers.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +ciphers.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +ciphers.o: ../include/openssl/safestack.h ../include/openssl/sha.h +ciphers.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +ciphers.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +ciphers.o: ../include/openssl/stack.h ../include/openssl/tls1.h +ciphers.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +crl.o: ../include/openssl/asn1.h ../include/openssl/bio.h +crl.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +crl.o: ../include/openssl/buffer.h ../include/openssl/cast.h +crl.o: ../include/openssl/conf.h ../include/openssl/crypto.h +crl.o: ../include/openssl/des.h ../include/openssl/dh.h +crl.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +crl.o: ../include/openssl/e_os2.h ../include/openssl/err.h +crl.o: ../include/openssl/evp.h ../include/openssl/idea.h +crl.o: ../include/openssl/lhash.h ../include/openssl/md2.h +crl.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +crl.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +crl.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +crl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +crl.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +crl.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +crl.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +crl.o: ../include/openssl/sha.h ../include/openssl/stack.h +crl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +crl.o: ../include/openssl/x509v3.h apps.h +crl2p7.o: ../include/openssl/asn1.h ../include/openssl/bio.h +crl2p7.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +crl2p7.o: ../include/openssl/buffer.h ../include/openssl/cast.h +crl2p7.o: ../include/openssl/crypto.h ../include/openssl/des.h +crl2p7.o: ../include/openssl/dh.h ../include/openssl/dsa.h +crl2p7.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +crl2p7.o: ../include/openssl/err.h ../include/openssl/evp.h +crl2p7.o: ../include/openssl/idea.h ../include/openssl/md2.h +crl2p7.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +crl2p7.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +crl2p7.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +crl2p7.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +crl2p7.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +crl2p7.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +crl2p7.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +crl2p7.o: ../include/openssl/sha.h ../include/openssl/stack.h +crl2p7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +dgst.o: ../include/openssl/asn1.h ../include/openssl/bio.h +dgst.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +dgst.o: ../include/openssl/buffer.h ../include/openssl/cast.h +dgst.o: ../include/openssl/crypto.h ../include/openssl/des.h +dgst.o: ../include/openssl/dh.h ../include/openssl/dsa.h +dgst.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +dgst.o: ../include/openssl/err.h ../include/openssl/evp.h +dgst.o: ../include/openssl/idea.h ../include/openssl/md2.h +dgst.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +dgst.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +dgst.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +dgst.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +dgst.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +dgst.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +dgst.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +dgst.o: ../include/openssl/sha.h ../include/openssl/stack.h +dgst.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +dh.o: ../include/openssl/asn1.h ../include/openssl/bio.h +dh.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +dh.o: ../include/openssl/buffer.h ../include/openssl/cast.h +dh.o: ../include/openssl/crypto.h ../include/openssl/des.h +dh.o: ../include/openssl/dh.h ../include/openssl/dsa.h +dh.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +dh.o: ../include/openssl/err.h ../include/openssl/evp.h +dh.o: ../include/openssl/idea.h ../include/openssl/md2.h +dh.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +dh.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +dh.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +dh.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +dh.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +dh.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +dh.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +dh.o: ../include/openssl/sha.h ../include/openssl/stack.h +dh.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +dsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h +dsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +dsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h +dsa.o: ../include/openssl/crypto.h ../include/openssl/des.h +dsa.o: ../include/openssl/dh.h ../include/openssl/dsa.h +dsa.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +dsa.o: ../include/openssl/err.h ../include/openssl/evp.h +dsa.o: ../include/openssl/idea.h ../include/openssl/md2.h +dsa.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +dsa.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +dsa.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +dsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +dsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +dsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +dsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +dsa.o: ../include/openssl/sha.h ../include/openssl/stack.h +dsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +dsaparam.o: ../include/openssl/asn1.h ../include/openssl/bio.h +dsaparam.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +dsaparam.o: ../include/openssl/buffer.h ../include/openssl/cast.h +dsaparam.o: ../include/openssl/crypto.h ../include/openssl/des.h +dsaparam.o: ../include/openssl/dh.h ../include/openssl/dsa.h +dsaparam.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +dsaparam.o: ../include/openssl/err.h ../include/openssl/evp.h +dsaparam.o: ../include/openssl/idea.h ../include/openssl/md2.h +dsaparam.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +dsaparam.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +dsaparam.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +dsaparam.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +dsaparam.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +dsaparam.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +dsaparam.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +dsaparam.o: ../include/openssl/sha.h ../include/openssl/stack.h +dsaparam.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +enc.o: ../include/openssl/asn1.h ../include/openssl/bio.h +enc.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +enc.o: ../include/openssl/buffer.h ../include/openssl/cast.h +enc.o: ../include/openssl/crypto.h ../include/openssl/des.h +enc.o: ../include/openssl/dh.h ../include/openssl/dsa.h +enc.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +enc.o: ../include/openssl/err.h ../include/openssl/evp.h +enc.o: ../include/openssl/idea.h ../include/openssl/md2.h +enc.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +enc.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +enc.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +enc.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +enc.o: ../include/openssl/rand.h ../include/openssl/rc2.h +enc.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +enc.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +enc.o: ../include/openssl/safestack.h ../include/openssl/sha.h +enc.o: ../include/openssl/stack.h ../include/openssl/x509.h +enc.o: ../include/openssl/x509_vfy.h apps.h +errstr.o: ../include/openssl/asn1.h ../include/openssl/bio.h +errstr.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +errstr.o: ../include/openssl/buffer.h ../include/openssl/cast.h +errstr.o: ../include/openssl/crypto.h ../include/openssl/des.h +errstr.o: ../include/openssl/dh.h ../include/openssl/dsa.h +errstr.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +errstr.o: ../include/openssl/err.h ../include/openssl/evp.h +errstr.o: ../include/openssl/idea.h ../include/openssl/lhash.h +errstr.o: ../include/openssl/md2.h ../include/openssl/md5.h +errstr.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +errstr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +errstr.o: ../include/openssl/pem.h ../include/openssl/pem2.h +errstr.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +errstr.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +errstr.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +errstr.o: ../include/openssl/safestack.h ../include/openssl/sha.h +errstr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +errstr.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +errstr.o: ../include/openssl/stack.h ../include/openssl/tls1.h +errstr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +gendh.o: ../include/openssl/asn1.h ../include/openssl/bio.h +gendh.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +gendh.o: ../include/openssl/buffer.h ../include/openssl/cast.h +gendh.o: ../include/openssl/crypto.h ../include/openssl/des.h +gendh.o: ../include/openssl/dh.h ../include/openssl/dsa.h +gendh.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +gendh.o: ../include/openssl/err.h ../include/openssl/evp.h +gendh.o: ../include/openssl/idea.h ../include/openssl/md2.h +gendh.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +gendh.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +gendh.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +gendh.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +gendh.o: ../include/openssl/rand.h ../include/openssl/rc2.h +gendh.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +gendh.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +gendh.o: ../include/openssl/safestack.h ../include/openssl/sha.h +gendh.o: ../include/openssl/stack.h ../include/openssl/x509.h +gendh.o: ../include/openssl/x509_vfy.h apps.h +gendsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h +gendsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +gendsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h +gendsa.o: ../include/openssl/crypto.h ../include/openssl/des.h +gendsa.o: ../include/openssl/dh.h ../include/openssl/dsa.h +gendsa.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +gendsa.o: ../include/openssl/err.h ../include/openssl/evp.h +gendsa.o: ../include/openssl/idea.h ../include/openssl/md2.h +gendsa.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +gendsa.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +gendsa.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +gendsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +gendsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +gendsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +gendsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +gendsa.o: ../include/openssl/sha.h ../include/openssl/stack.h +gendsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +genrsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h +genrsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +genrsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h +genrsa.o: ../include/openssl/crypto.h ../include/openssl/des.h +genrsa.o: ../include/openssl/dh.h ../include/openssl/dsa.h +genrsa.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +genrsa.o: ../include/openssl/err.h ../include/openssl/evp.h +genrsa.o: ../include/openssl/idea.h ../include/openssl/md2.h +genrsa.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +genrsa.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +genrsa.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +genrsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +genrsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +genrsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +genrsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +genrsa.o: ../include/openssl/sha.h ../include/openssl/stack.h +genrsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +nseq.o: ../include/openssl/asn1.h ../include/openssl/bio.h +nseq.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +nseq.o: ../include/openssl/buffer.h ../include/openssl/cast.h +nseq.o: ../include/openssl/crypto.h ../include/openssl/des.h +nseq.o: ../include/openssl/dh.h ../include/openssl/dsa.h +nseq.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +nseq.o: ../include/openssl/err.h ../include/openssl/evp.h +nseq.o: ../include/openssl/idea.h ../include/openssl/md2.h +nseq.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +nseq.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +nseq.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +nseq.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +nseq.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +nseq.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +nseq.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +nseq.o: ../include/openssl/sha.h ../include/openssl/stack.h +nseq.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +openssl.o: ../include/openssl/asn1.h ../include/openssl/bio.h +openssl.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +openssl.o: ../include/openssl/buffer.h ../include/openssl/cast.h +openssl.o: ../include/openssl/conf.h ../include/openssl/crypto.h +openssl.o: ../include/openssl/des.h ../include/openssl/dh.h +openssl.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +openssl.o: ../include/openssl/e_os2.h ../include/openssl/err.h +openssl.o: ../include/openssl/evp.h ../include/openssl/idea.h +openssl.o: ../include/openssl/lhash.h ../include/openssl/md2.h +openssl.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +openssl.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +openssl.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +openssl.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +openssl.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +openssl.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +openssl.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +openssl.o: ../include/openssl/sha.h ../include/openssl/ssl.h +openssl.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h +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 +passwd.o: ../include/openssl/asn1.h ../include/openssl/bio.h +passwd.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +passwd.o: ../include/openssl/buffer.h ../include/openssl/cast.h +passwd.o: ../include/openssl/crypto.h ../include/openssl/des.h +passwd.o: ../include/openssl/dh.h ../include/openssl/dsa.h +passwd.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +passwd.o: ../include/openssl/err.h ../include/openssl/evp.h +passwd.o: ../include/openssl/idea.h ../include/openssl/md2.h +passwd.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +passwd.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +passwd.o: ../include/openssl/opensslv.h ../include/openssl/pkcs7.h +passwd.o: ../include/openssl/rand.h ../include/openssl/rc2.h +passwd.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +passwd.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +passwd.o: ../include/openssl/safestack.h ../include/openssl/sha.h +passwd.o: ../include/openssl/stack.h ../include/openssl/x509.h +passwd.o: ../include/openssl/x509_vfy.h apps.h +pkcs12.o: ../include/openssl/asn1.h ../include/openssl/bio.h +pkcs12.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +pkcs12.o: ../include/openssl/buffer.h ../include/openssl/cast.h +pkcs12.o: ../include/openssl/crypto.h ../include/openssl/des.h +pkcs12.o: ../include/openssl/dh.h ../include/openssl/dsa.h +pkcs12.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +pkcs12.o: ../include/openssl/err.h ../include/openssl/evp.h +pkcs12.o: ../include/openssl/idea.h ../include/openssl/md2.h +pkcs12.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +pkcs12.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +pkcs12.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +pkcs12.o: ../include/openssl/pem2.h ../include/openssl/pkcs12.h +pkcs12.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +pkcs12.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +pkcs12.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +pkcs12.o: ../include/openssl/safestack.h ../include/openssl/sha.h +pkcs12.o: ../include/openssl/stack.h ../include/openssl/x509.h +pkcs12.o: ../include/openssl/x509_vfy.h apps.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 +pkcs7.o: ../include/openssl/crypto.h ../include/openssl/des.h +pkcs7.o: ../include/openssl/dh.h ../include/openssl/dsa.h +pkcs7.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +pkcs7.o: ../include/openssl/err.h ../include/openssl/evp.h +pkcs7.o: ../include/openssl/idea.h ../include/openssl/md2.h +pkcs7.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +pkcs7.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +pkcs7.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +pkcs7.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +pkcs7.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +pkcs7.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +pkcs7.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +pkcs7.o: ../include/openssl/sha.h ../include/openssl/stack.h +pkcs7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +pkcs8.o: ../include/openssl/asn1.h ../include/openssl/bio.h +pkcs8.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +pkcs8.o: ../include/openssl/buffer.h ../include/openssl/cast.h +pkcs8.o: ../include/openssl/crypto.h ../include/openssl/des.h +pkcs8.o: ../include/openssl/dh.h ../include/openssl/dsa.h +pkcs8.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +pkcs8.o: ../include/openssl/err.h ../include/openssl/evp.h +pkcs8.o: ../include/openssl/idea.h ../include/openssl/md2.h +pkcs8.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +pkcs8.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +pkcs8.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +pkcs8.o: ../include/openssl/pem2.h ../include/openssl/pkcs12.h +pkcs8.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +pkcs8.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +pkcs8.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +pkcs8.o: ../include/openssl/safestack.h ../include/openssl/sha.h +pkcs8.o: ../include/openssl/stack.h ../include/openssl/x509.h +pkcs8.o: ../include/openssl/x509_vfy.h apps.h +rand.o: ../include/openssl/asn1.h ../include/openssl/bio.h +rand.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +rand.o: ../include/openssl/buffer.h ../include/openssl/cast.h +rand.o: ../include/openssl/crypto.h ../include/openssl/des.h +rand.o: ../include/openssl/dh.h ../include/openssl/dsa.h +rand.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +rand.o: ../include/openssl/err.h ../include/openssl/evp.h +rand.o: ../include/openssl/idea.h ../include/openssl/md2.h +rand.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +rand.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +rand.o: ../include/openssl/opensslv.h ../include/openssl/pkcs7.h +rand.o: ../include/openssl/rand.h ../include/openssl/rc2.h +rand.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +rand.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +rand.o: ../include/openssl/safestack.h ../include/openssl/sha.h +rand.o: ../include/openssl/stack.h ../include/openssl/x509.h +rand.o: ../include/openssl/x509_vfy.h apps.h +req.o: ../include/openssl/asn1.h ../include/openssl/bio.h +req.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +req.o: ../include/openssl/buffer.h ../include/openssl/cast.h +req.o: ../include/openssl/conf.h ../include/openssl/crypto.h +req.o: ../include/openssl/des.h ../include/openssl/dh.h +req.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +req.o: ../include/openssl/e_os2.h ../include/openssl/err.h +req.o: ../include/openssl/evp.h ../include/openssl/idea.h +req.o: ../include/openssl/lhash.h ../include/openssl/md2.h +req.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +req.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +req.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +req.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +req.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +req.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +req.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +req.o: ../include/openssl/sha.h ../include/openssl/stack.h +req.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +req.o: ../include/openssl/x509v3.h apps.h +rsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h +rsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +rsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h +rsa.o: ../include/openssl/crypto.h ../include/openssl/des.h +rsa.o: ../include/openssl/dh.h ../include/openssl/dsa.h +rsa.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +rsa.o: ../include/openssl/err.h ../include/openssl/evp.h +rsa.o: ../include/openssl/idea.h ../include/openssl/md2.h +rsa.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +rsa.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +rsa.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +rsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +rsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +rsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +rsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +rsa.o: ../include/openssl/sha.h ../include/openssl/stack.h +rsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +s_cb.o: ../include/openssl/asn1.h ../include/openssl/bio.h +s_cb.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +s_cb.o: ../include/openssl/buffer.h ../include/openssl/cast.h +s_cb.o: ../include/openssl/crypto.h ../include/openssl/des.h +s_cb.o: ../include/openssl/dh.h ../include/openssl/dsa.h +s_cb.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +s_cb.o: ../include/openssl/err.h ../include/openssl/evp.h +s_cb.o: ../include/openssl/idea.h ../include/openssl/lhash.h +s_cb.o: ../include/openssl/md2.h ../include/openssl/md5.h +s_cb.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +s_cb.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +s_cb.o: ../include/openssl/pem.h ../include/openssl/pem2.h +s_cb.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +s_cb.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +s_cb.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +s_cb.o: ../include/openssl/safestack.h ../include/openssl/sha.h +s_cb.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +s_cb.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +s_cb.o: ../include/openssl/stack.h ../include/openssl/tls1.h +s_cb.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h s_apps.h +s_client.o: ../include/openssl/asn1.h ../include/openssl/bio.h +s_client.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +s_client.o: ../include/openssl/buffer.h ../include/openssl/cast.h +s_client.o: ../include/openssl/crypto.h ../include/openssl/des.h +s_client.o: ../include/openssl/dh.h ../include/openssl/dsa.h +s_client.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +s_client.o: ../include/openssl/err.h ../include/openssl/evp.h +s_client.o: ../include/openssl/idea.h ../include/openssl/lhash.h +s_client.o: ../include/openssl/md2.h ../include/openssl/md5.h +s_client.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +s_client.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +s_client.o: ../include/openssl/pem.h ../include/openssl/pem2.h +s_client.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +s_client.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +s_client.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +s_client.o: ../include/openssl/safestack.h ../include/openssl/sha.h +s_client.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +s_client.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +s_client.o: ../include/openssl/stack.h ../include/openssl/tls1.h +s_client.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +s_client.o: s_apps.h +s_server.o: ../include/openssl/asn1.h ../include/openssl/bio.h +s_server.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +s_server.o: ../include/openssl/buffer.h ../include/openssl/cast.h +s_server.o: ../include/openssl/crypto.h ../include/openssl/des.h +s_server.o: ../include/openssl/dh.h ../include/openssl/dsa.h +s_server.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +s_server.o: ../include/openssl/err.h ../include/openssl/evp.h +s_server.o: ../include/openssl/idea.h ../include/openssl/lhash.h +s_server.o: ../include/openssl/md2.h ../include/openssl/md5.h +s_server.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +s_server.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +s_server.o: ../include/openssl/pem.h ../include/openssl/pem2.h +s_server.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +s_server.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +s_server.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +s_server.o: ../include/openssl/safestack.h ../include/openssl/sha.h +s_server.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +s_server.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +s_server.o: ../include/openssl/stack.h ../include/openssl/tls1.h +s_server.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +s_server.o: s_apps.h +s_socket.o: ../include/openssl/asn1.h ../include/openssl/bio.h +s_socket.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +s_socket.o: ../include/openssl/buffer.h ../include/openssl/cast.h +s_socket.o: ../include/openssl/crypto.h ../include/openssl/des.h +s_socket.o: ../include/openssl/dh.h ../include/openssl/dsa.h +s_socket.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +s_socket.o: ../include/openssl/evp.h ../include/openssl/idea.h +s_socket.o: ../include/openssl/lhash.h ../include/openssl/md2.h +s_socket.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +s_socket.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +s_socket.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +s_socket.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +s_socket.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +s_socket.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +s_socket.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +s_socket.o: ../include/openssl/sha.h ../include/openssl/ssl.h +s_socket.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h +s_socket.o: ../include/openssl/ssl3.h ../include/openssl/stack.h +s_socket.o: ../include/openssl/tls1.h ../include/openssl/x509.h +s_socket.o: ../include/openssl/x509_vfy.h apps.h s_apps.h +s_time.o: ../include/openssl/asn1.h ../include/openssl/bio.h +s_time.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +s_time.o: ../include/openssl/buffer.h ../include/openssl/cast.h +s_time.o: ../include/openssl/crypto.h ../include/openssl/des.h +s_time.o: ../include/openssl/dh.h ../include/openssl/dsa.h +s_time.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +s_time.o: ../include/openssl/err.h ../include/openssl/evp.h +s_time.o: ../include/openssl/idea.h ../include/openssl/lhash.h +s_time.o: ../include/openssl/md2.h ../include/openssl/md5.h +s_time.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +s_time.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +s_time.o: ../include/openssl/pem.h ../include/openssl/pem2.h +s_time.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +s_time.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +s_time.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +s_time.o: ../include/openssl/safestack.h ../include/openssl/sha.h +s_time.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +s_time.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +s_time.o: ../include/openssl/stack.h ../include/openssl/tls1.h +s_time.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +s_time.o: s_apps.h +sess_id.o: ../include/openssl/asn1.h ../include/openssl/bio.h +sess_id.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +sess_id.o: ../include/openssl/buffer.h ../include/openssl/cast.h +sess_id.o: ../include/openssl/crypto.h ../include/openssl/des.h +sess_id.o: ../include/openssl/dh.h ../include/openssl/dsa.h +sess_id.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +sess_id.o: ../include/openssl/err.h ../include/openssl/evp.h +sess_id.o: ../include/openssl/idea.h ../include/openssl/lhash.h +sess_id.o: ../include/openssl/md2.h ../include/openssl/md5.h +sess_id.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +sess_id.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +sess_id.o: ../include/openssl/pem.h ../include/openssl/pem2.h +sess_id.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +sess_id.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +sess_id.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +sess_id.o: ../include/openssl/safestack.h ../include/openssl/sha.h +sess_id.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h +sess_id.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h +sess_id.o: ../include/openssl/stack.h ../include/openssl/tls1.h +sess_id.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +smime.o: ../include/openssl/asn1.h ../include/openssl/bio.h +smime.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +smime.o: ../include/openssl/buffer.h ../include/openssl/cast.h +smime.o: ../include/openssl/crypto.h ../include/openssl/des.h +smime.o: ../include/openssl/dh.h ../include/openssl/dsa.h +smime.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +smime.o: ../include/openssl/err.h ../include/openssl/evp.h +smime.o: ../include/openssl/idea.h ../include/openssl/md2.h +smime.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +smime.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +smime.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +smime.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +smime.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +smime.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +smime.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +smime.o: ../include/openssl/sha.h ../include/openssl/stack.h +smime.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +speed.o: ../include/openssl/asn1.h ../include/openssl/bio.h +speed.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +speed.o: ../include/openssl/buffer.h ../include/openssl/cast.h +speed.o: ../include/openssl/crypto.h ../include/openssl/des.h +speed.o: ../include/openssl/dh.h ../include/openssl/dsa.h +speed.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +speed.o: ../include/openssl/err.h ../include/openssl/evp.h +speed.o: ../include/openssl/hmac.h ../include/openssl/idea.h +speed.o: ../include/openssl/md2.h ../include/openssl/md5.h +speed.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +speed.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +speed.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h +speed.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +speed.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +speed.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +speed.o: ../include/openssl/sha.h ../include/openssl/stack.h +speed.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ./testdsa.h +speed.o: ./testrsa.h apps.h +spkac.o: ../include/openssl/asn1.h ../include/openssl/bio.h +spkac.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +spkac.o: ../include/openssl/buffer.h ../include/openssl/cast.h +spkac.o: ../include/openssl/conf.h ../include/openssl/crypto.h +spkac.o: ../include/openssl/des.h ../include/openssl/dh.h +spkac.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +spkac.o: ../include/openssl/e_os2.h ../include/openssl/err.h +spkac.o: ../include/openssl/evp.h ../include/openssl/idea.h +spkac.o: ../include/openssl/lhash.h ../include/openssl/md2.h +spkac.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +spkac.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +spkac.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +spkac.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +spkac.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +spkac.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +spkac.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +spkac.o: ../include/openssl/sha.h ../include/openssl/stack.h +spkac.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +verify.o: ../include/openssl/asn1.h ../include/openssl/bio.h +verify.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +verify.o: ../include/openssl/buffer.h ../include/openssl/cast.h +verify.o: ../include/openssl/conf.h ../include/openssl/crypto.h +verify.o: ../include/openssl/des.h ../include/openssl/dh.h +verify.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +verify.o: ../include/openssl/e_os2.h ../include/openssl/err.h +verify.o: ../include/openssl/evp.h ../include/openssl/idea.h +verify.o: ../include/openssl/lhash.h ../include/openssl/md2.h +verify.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +verify.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +verify.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +verify.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +verify.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +verify.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +verify.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +verify.o: ../include/openssl/sha.h ../include/openssl/stack.h +verify.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +verify.o: ../include/openssl/x509v3.h apps.h +version.o: ../include/openssl/asn1.h ../include/openssl/bio.h +version.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +version.o: ../include/openssl/buffer.h ../include/openssl/cast.h +version.o: ../include/openssl/crypto.h ../include/openssl/des.h +version.o: ../include/openssl/dh.h ../include/openssl/dsa.h +version.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +version.o: ../include/openssl/evp.h ../include/openssl/idea.h +version.o: ../include/openssl/md2.h ../include/openssl/md5.h +version.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +version.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +version.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +version.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +version.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +version.o: ../include/openssl/safestack.h ../include/openssl/sha.h +version.o: ../include/openssl/stack.h ../include/openssl/x509.h +version.o: ../include/openssl/x509_vfy.h apps.h +x509.o: ../include/openssl/asn1.h ../include/openssl/bio.h +x509.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +x509.o: ../include/openssl/buffer.h ../include/openssl/cast.h +x509.o: ../include/openssl/conf.h ../include/openssl/crypto.h +x509.o: ../include/openssl/des.h ../include/openssl/dh.h +x509.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +x509.o: ../include/openssl/e_os2.h ../include/openssl/err.h +x509.o: ../include/openssl/evp.h ../include/openssl/idea.h +x509.o: ../include/openssl/lhash.h ../include/openssl/md2.h +x509.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +x509.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +x509.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +x509.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +x509.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +x509.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +x509.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +x509.o: ../include/openssl/sha.h ../include/openssl/stack.h +x509.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +x509.o: ../include/openssl/x509v3.h apps.h diff --git a/crypto/openssl/apps/Makefile.ssl b/crypto/openssl/apps/Makefile.ssl index 8363ec9..b8d0b1b 100644 --- a/crypto/openssl/apps/Makefile.ssl +++ b/crypto/openssl/apps/Makefile.ssl @@ -13,6 +13,7 @@ OPENSSLDIR= /usr/local/ssl MAKE= make -f Makefile.ssl MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl +PERL=/usr/local/bin/perl RM= rm -f PEX_LIBS= @@ -33,11 +34,11 @@ SCRIPTS=CA.sh CA.pl der_chop EXE= $(PROGRAM) -E_EXE= verify asn1pars req dgst dh enc gendh errstr ca crl \ - rsa dsa dsaparam \ +E_EXE= verify asn1pars req dgst dh dhparam enc passwd gendh errstr \ + ca crl rsa dsa dsaparam \ x509 genrsa gendsa s_server s_client speed \ s_time version pkcs7 crl2pkcs7 sess_id ciphers nseq pkcs12 \ - pkcs8 + pkcs8 spkac smime rand PROGS= $(PROGRAM).c @@ -45,24 +46,22 @@ A_OBJ=apps.o A_SRC=apps.c S_OBJ= s_cb.o s_socket.o S_SRC= s_cb.c s_socket.c +RAND_OBJ=app_rand.o +RAND_SRC=app_rand.c -E_OBJ= verify.o asn1pars.o req.o dgst.o dh.o enc.o gendh.o errstr.o ca.o \ - pkcs7.o crl2p7.o crl.o \ +E_OBJ= verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o \ + ca.o pkcs7.o crl2p7.o crl.o \ 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 pkcs8.o + s_time.o $(A_OBJ) $(S_OBJ) $(RAND_OBJ) version.o sess_id.o \ + ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o -# pem_mail.o - -E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c gendh.c errstr.c ca.c \ +E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c passwd.c gendh.c errstr.c ca.c \ pkcs7.c crl2p7.c crl.c \ rsa.c dsa.c dsaparam.c \ x509.c genrsa.c gendsa.c s_server.c s_client.c speed.c \ - s_time.c $(A_SRC) $(S_SRC) version.c sess_id.c \ - ciphers.c nseq.c pkcs12.c pkcs8.c - -# pem_mail.c + s_time.c $(A_SRC) $(S_SRC) $(RAND_SRC) version.c sess_id.c \ + ciphers.c nseq.c pkcs12.c pkcs8.c spkac.c smime.c rand.c SRC=$(E_SRC) @@ -81,7 +80,7 @@ all: exe exe: $(EXE) req: sreq.o $(A_OBJ) $(DLIBCRYPTO) - $(CC) -o req $(CFLAG) sreq.o $(A_OBJ) $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) + $(CC) -o req $(CFLAG) sreq.o $(A_OBJ) $(RAND_OBJ) $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS) sreq.o: req.c $(CC) -c $(INCLUDES) $(CFLAG) -o sreq.o req.c @@ -138,16 +137,44 @@ $(PROGRAM): progs.h $(E_OBJ) $(PROGRAM).o $(DLIBCRYPTO) $(DLIBSSL) $(CC) -o $(PROGRAM) $(CFLAGS) $(PROGRAM).o $(E_OBJ) $(PEX_LIBS) $(LIBSSL) $(LIBCRYPTO) $(EX_LIBS) @(cd ..; OPENSSL="`pwd`/apps/openssl"; export OPENSSL; sh tools/c_rehash certs) -progs.h: - $(PERL) ./progs.pl $(E_EXE) >progs.h +progs.h: progs.pl + $(PERL) progs.pl $(E_EXE) >progs.h $(RM) $(PROGRAM).o # DO NOT DELETE THIS LINE -- make depend depends on it. -apps.o: ../include/openssl/bio.h ../include/openssl/buffer.h -apps.o: ../include/openssl/crypto.h ../include/openssl/e_os.h -apps.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h -apps.o: ../include/openssl/opensslv.h ../include/openssl/stack.h apps.h progs.h +app_rand.o: ../include/openssl/asn1.h ../include/openssl/bio.h +app_rand.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +app_rand.o: ../include/openssl/buffer.h ../include/openssl/cast.h +app_rand.o: ../include/openssl/crypto.h ../include/openssl/des.h +app_rand.o: ../include/openssl/dh.h ../include/openssl/dsa.h +app_rand.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +app_rand.o: ../include/openssl/evp.h ../include/openssl/idea.h +app_rand.o: ../include/openssl/md2.h ../include/openssl/md5.h +app_rand.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +app_rand.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +app_rand.o: ../include/openssl/pkcs7.h ../include/openssl/rand.h +app_rand.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +app_rand.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +app_rand.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +app_rand.o: ../include/openssl/sha.h ../include/openssl/stack.h +app_rand.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h +apps.o: ../include/openssl/asn1.h ../include/openssl/bio.h +apps.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +apps.o: ../include/openssl/buffer.h ../include/openssl/cast.h +apps.o: ../include/openssl/crypto.h ../include/openssl/des.h +apps.o: ../include/openssl/dh.h ../include/openssl/dsa.h +apps.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +apps.o: ../include/openssl/evp.h ../include/openssl/idea.h +apps.o: ../include/openssl/md2.h ../include/openssl/md5.h +apps.o: ../include/openssl/mdc2.h ../include/openssl/objects.h +apps.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +apps.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +apps.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +apps.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +apps.o: ../include/openssl/safestack.h ../include/openssl/sha.h +apps.o: ../include/openssl/stack.h ../include/openssl/x509.h +apps.o: ../include/openssl/x509_vfy.h apps.h asn1pars.o: ../include/openssl/asn1.h ../include/openssl/bio.h asn1pars.o: ../include/openssl/blowfish.h ../include/openssl/bn.h asn1pars.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -165,7 +192,6 @@ asn1pars.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h asn1pars.o: ../include/openssl/rsa.h ../include/openssl/safestack.h asn1pars.o: ../include/openssl/sha.h ../include/openssl/stack.h asn1pars.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -asn1pars.o: progs.h ca.o: ../include/openssl/asn1.h ../include/openssl/bio.h ca.o: ../include/openssl/blowfish.h ../include/openssl/bn.h ca.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -184,7 +210,7 @@ ca.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h ca.o: ../include/openssl/safestack.h ../include/openssl/sha.h ca.o: ../include/openssl/stack.h ../include/openssl/txt_db.h ca.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h -ca.o: ../include/openssl/x509v3.h apps.h progs.h +ca.o: ../include/openssl/x509v3.h apps.h ciphers.o: ../include/openssl/asn1.h ../include/openssl/bio.h ciphers.o: ../include/openssl/blowfish.h ../include/openssl/bn.h ciphers.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -205,7 +231,6 @@ ciphers.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h ciphers.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h ciphers.o: ../include/openssl/stack.h ../include/openssl/tls1.h ciphers.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -ciphers.o: progs.h crl.o: ../include/openssl/asn1.h ../include/openssl/bio.h crl.o: ../include/openssl/blowfish.h ../include/openssl/bn.h crl.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -224,7 +249,7 @@ crl.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h crl.o: ../include/openssl/rsa.h ../include/openssl/safestack.h crl.o: ../include/openssl/sha.h ../include/openssl/stack.h crl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h -crl.o: ../include/openssl/x509v3.h apps.h progs.h +crl.o: ../include/openssl/x509v3.h apps.h crl2p7.o: ../include/openssl/asn1.h ../include/openssl/bio.h crl2p7.o: ../include/openssl/blowfish.h ../include/openssl/bn.h crl2p7.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -242,7 +267,6 @@ crl2p7.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h crl2p7.o: ../include/openssl/rsa.h ../include/openssl/safestack.h crl2p7.o: ../include/openssl/sha.h ../include/openssl/stack.h crl2p7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -crl2p7.o: progs.h dgst.o: ../include/openssl/asn1.h ../include/openssl/bio.h dgst.o: ../include/openssl/blowfish.h ../include/openssl/bn.h dgst.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -259,7 +283,7 @@ dgst.o: ../include/openssl/rc2.h ../include/openssl/rc4.h dgst.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h dgst.o: ../include/openssl/rsa.h ../include/openssl/safestack.h dgst.o: ../include/openssl/sha.h ../include/openssl/stack.h -dgst.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +dgst.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h dh.o: ../include/openssl/asn1.h ../include/openssl/bio.h dh.o: ../include/openssl/blowfish.h ../include/openssl/bn.h dh.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -276,7 +300,7 @@ dh.o: ../include/openssl/rc2.h ../include/openssl/rc4.h dh.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h dh.o: ../include/openssl/rsa.h ../include/openssl/safestack.h dh.o: ../include/openssl/sha.h ../include/openssl/stack.h -dh.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +dh.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h dsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h dsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h dsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -293,7 +317,7 @@ dsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h dsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h dsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h dsa.o: ../include/openssl/sha.h ../include/openssl/stack.h -dsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +dsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h dsaparam.o: ../include/openssl/asn1.h ../include/openssl/bio.h dsaparam.o: ../include/openssl/blowfish.h ../include/openssl/bn.h dsaparam.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -306,12 +330,11 @@ dsaparam.o: ../include/openssl/md5.h ../include/openssl/mdc2.h dsaparam.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h dsaparam.o: ../include/openssl/opensslv.h ../include/openssl/pem.h dsaparam.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h -dsaparam.o: ../include/openssl/rand.h ../include/openssl/rc2.h -dsaparam.o: ../include/openssl/rc4.h ../include/openssl/rc5.h -dsaparam.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h -dsaparam.o: ../include/openssl/safestack.h ../include/openssl/sha.h -dsaparam.o: ../include/openssl/stack.h ../include/openssl/x509.h -dsaparam.o: ../include/openssl/x509_vfy.h apps.h progs.h +dsaparam.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +dsaparam.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +dsaparam.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +dsaparam.o: ../include/openssl/sha.h ../include/openssl/stack.h +dsaparam.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h enc.o: ../include/openssl/asn1.h ../include/openssl/bio.h enc.o: ../include/openssl/blowfish.h ../include/openssl/bn.h enc.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -324,11 +347,12 @@ enc.o: ../include/openssl/md5.h ../include/openssl/mdc2.h enc.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h enc.o: ../include/openssl/opensslv.h ../include/openssl/pem.h enc.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h -enc.o: ../include/openssl/rc2.h ../include/openssl/rc4.h -enc.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h -enc.o: ../include/openssl/rsa.h ../include/openssl/safestack.h -enc.o: ../include/openssl/sha.h ../include/openssl/stack.h -enc.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +enc.o: ../include/openssl/rand.h ../include/openssl/rc2.h +enc.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +enc.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +enc.o: ../include/openssl/safestack.h ../include/openssl/sha.h +enc.o: ../include/openssl/stack.h ../include/openssl/x509.h +enc.o: ../include/openssl/x509_vfy.h apps.h errstr.o: ../include/openssl/asn1.h ../include/openssl/bio.h errstr.o: ../include/openssl/blowfish.h ../include/openssl/bn.h errstr.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -349,7 +373,6 @@ errstr.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h errstr.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h errstr.o: ../include/openssl/stack.h ../include/openssl/tls1.h errstr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -errstr.o: progs.h gendh.o: ../include/openssl/asn1.h ../include/openssl/bio.h gendh.o: ../include/openssl/blowfish.h ../include/openssl/bn.h gendh.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -367,7 +390,7 @@ gendh.o: ../include/openssl/rc4.h ../include/openssl/rc5.h gendh.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h gendh.o: ../include/openssl/safestack.h ../include/openssl/sha.h gendh.o: ../include/openssl/stack.h ../include/openssl/x509.h -gendh.o: ../include/openssl/x509_vfy.h apps.h progs.h +gendh.o: ../include/openssl/x509_vfy.h apps.h gendsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h gendsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h gendsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -380,12 +403,11 @@ gendsa.o: ../include/openssl/md5.h ../include/openssl/mdc2.h gendsa.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h gendsa.o: ../include/openssl/opensslv.h ../include/openssl/pem.h gendsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h -gendsa.o: ../include/openssl/rand.h ../include/openssl/rc2.h -gendsa.o: ../include/openssl/rc4.h ../include/openssl/rc5.h -gendsa.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h -gendsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h -gendsa.o: ../include/openssl/stack.h ../include/openssl/x509.h -gendsa.o: ../include/openssl/x509_vfy.h apps.h progs.h +gendsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +gendsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +gendsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +gendsa.o: ../include/openssl/sha.h ../include/openssl/stack.h +gendsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h genrsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h genrsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h genrsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -398,12 +420,11 @@ genrsa.o: ../include/openssl/md5.h ../include/openssl/mdc2.h genrsa.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h genrsa.o: ../include/openssl/opensslv.h ../include/openssl/pem.h genrsa.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h -genrsa.o: ../include/openssl/rand.h ../include/openssl/rc2.h -genrsa.o: ../include/openssl/rc4.h ../include/openssl/rc5.h -genrsa.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h -genrsa.o: ../include/openssl/safestack.h ../include/openssl/sha.h -genrsa.o: ../include/openssl/stack.h ../include/openssl/x509.h -genrsa.o: ../include/openssl/x509_vfy.h apps.h progs.h +genrsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +genrsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +genrsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +genrsa.o: ../include/openssl/sha.h ../include/openssl/stack.h +genrsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h nseq.o: ../include/openssl/asn1.h ../include/openssl/bio.h nseq.o: ../include/openssl/blowfish.h ../include/openssl/bn.h nseq.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -420,7 +441,7 @@ nseq.o: ../include/openssl/rc2.h ../include/openssl/rc4.h nseq.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h nseq.o: ../include/openssl/rsa.h ../include/openssl/safestack.h nseq.o: ../include/openssl/sha.h ../include/openssl/stack.h -nseq.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +nseq.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h openssl.o: ../include/openssl/asn1.h ../include/openssl/bio.h openssl.o: ../include/openssl/blowfish.h ../include/openssl/bn.h openssl.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -442,6 +463,23 @@ openssl.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h 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 +passwd.o: ../include/openssl/asn1.h ../include/openssl/bio.h +passwd.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +passwd.o: ../include/openssl/buffer.h ../include/openssl/cast.h +passwd.o: ../include/openssl/crypto.h ../include/openssl/des.h +passwd.o: ../include/openssl/dh.h ../include/openssl/dsa.h +passwd.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +passwd.o: ../include/openssl/err.h ../include/openssl/evp.h +passwd.o: ../include/openssl/idea.h ../include/openssl/md2.h +passwd.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +passwd.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +passwd.o: ../include/openssl/opensslv.h ../include/openssl/pkcs7.h +passwd.o: ../include/openssl/rand.h ../include/openssl/rc2.h +passwd.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +passwd.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +passwd.o: ../include/openssl/safestack.h ../include/openssl/sha.h +passwd.o: ../include/openssl/stack.h ../include/openssl/x509.h +passwd.o: ../include/openssl/x509_vfy.h apps.h pkcs12.o: ../include/openssl/asn1.h ../include/openssl/bio.h pkcs12.o: ../include/openssl/blowfish.h ../include/openssl/bn.h pkcs12.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -459,7 +497,7 @@ pkcs12.o: ../include/openssl/rc4.h ../include/openssl/rc5.h pkcs12.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h pkcs12.o: ../include/openssl/safestack.h ../include/openssl/sha.h pkcs12.o: ../include/openssl/stack.h ../include/openssl/x509.h -pkcs12.o: ../include/openssl/x509_vfy.h apps.h progs.h +pkcs12.o: ../include/openssl/x509_vfy.h apps.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 @@ -476,7 +514,7 @@ pkcs7.o: ../include/openssl/rc2.h ../include/openssl/rc4.h pkcs7.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h pkcs7.o: ../include/openssl/rsa.h ../include/openssl/safestack.h pkcs7.o: ../include/openssl/sha.h ../include/openssl/stack.h -pkcs7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +pkcs7.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h pkcs8.o: ../include/openssl/asn1.h ../include/openssl/bio.h pkcs8.o: ../include/openssl/blowfish.h ../include/openssl/bn.h pkcs8.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -494,7 +532,24 @@ pkcs8.o: ../include/openssl/rc4.h ../include/openssl/rc5.h pkcs8.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h pkcs8.o: ../include/openssl/safestack.h ../include/openssl/sha.h pkcs8.o: ../include/openssl/stack.h ../include/openssl/x509.h -pkcs8.o: ../include/openssl/x509_vfy.h apps.h progs.h +pkcs8.o: ../include/openssl/x509_vfy.h apps.h +rand.o: ../include/openssl/asn1.h ../include/openssl/bio.h +rand.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +rand.o: ../include/openssl/buffer.h ../include/openssl/cast.h +rand.o: ../include/openssl/crypto.h ../include/openssl/des.h +rand.o: ../include/openssl/dh.h ../include/openssl/dsa.h +rand.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +rand.o: ../include/openssl/err.h ../include/openssl/evp.h +rand.o: ../include/openssl/idea.h ../include/openssl/md2.h +rand.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +rand.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +rand.o: ../include/openssl/opensslv.h ../include/openssl/pkcs7.h +rand.o: ../include/openssl/rand.h ../include/openssl/rc2.h +rand.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +rand.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +rand.o: ../include/openssl/safestack.h ../include/openssl/sha.h +rand.o: ../include/openssl/stack.h ../include/openssl/x509.h +rand.o: ../include/openssl/x509_vfy.h apps.h req.o: ../include/openssl/asn1.h ../include/openssl/bio.h req.o: ../include/openssl/blowfish.h ../include/openssl/bn.h req.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -508,12 +563,12 @@ req.o: ../include/openssl/md5.h ../include/openssl/mdc2.h req.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h req.o: ../include/openssl/opensslv.h ../include/openssl/pem.h req.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h -req.o: ../include/openssl/rand.h ../include/openssl/rc2.h -req.o: ../include/openssl/rc4.h ../include/openssl/rc5.h -req.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h -req.o: ../include/openssl/safestack.h ../include/openssl/sha.h -req.o: ../include/openssl/stack.h ../include/openssl/x509.h -req.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h apps.h progs.h +req.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +req.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +req.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +req.o: ../include/openssl/sha.h ../include/openssl/stack.h +req.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +req.o: ../include/openssl/x509v3.h apps.h rsa.o: ../include/openssl/asn1.h ../include/openssl/bio.h rsa.o: ../include/openssl/blowfish.h ../include/openssl/bn.h rsa.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -530,7 +585,7 @@ rsa.o: ../include/openssl/rc2.h ../include/openssl/rc4.h rsa.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h rsa.o: ../include/openssl/rsa.h ../include/openssl/safestack.h rsa.o: ../include/openssl/sha.h ../include/openssl/stack.h -rsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h +rsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h s_cb.o: ../include/openssl/asn1.h ../include/openssl/bio.h s_cb.o: ../include/openssl/blowfish.h ../include/openssl/bn.h s_cb.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -550,8 +605,7 @@ s_cb.o: ../include/openssl/safestack.h ../include/openssl/sha.h s_cb.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h s_cb.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h s_cb.o: ../include/openssl/stack.h ../include/openssl/tls1.h -s_cb.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h progs.h -s_cb.o: s_apps.h +s_cb.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h s_apps.h s_client.o: ../include/openssl/asn1.h ../include/openssl/bio.h s_client.o: ../include/openssl/blowfish.h ../include/openssl/bn.h s_client.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -572,7 +626,7 @@ s_client.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h s_client.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h s_client.o: ../include/openssl/stack.h ../include/openssl/tls1.h s_client.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -s_client.o: progs.h s_apps.h +s_client.o: s_apps.h s_server.o: ../include/openssl/asn1.h ../include/openssl/bio.h s_server.o: ../include/openssl/blowfish.h ../include/openssl/bn.h s_server.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -593,7 +647,7 @@ s_server.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h s_server.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h s_server.o: ../include/openssl/stack.h ../include/openssl/tls1.h s_server.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -s_server.o: progs.h s_apps.h +s_server.o: s_apps.h s_socket.o: ../include/openssl/asn1.h ../include/openssl/bio.h s_socket.o: ../include/openssl/blowfish.h ../include/openssl/bn.h s_socket.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -613,7 +667,7 @@ s_socket.o: ../include/openssl/sha.h ../include/openssl/ssl.h s_socket.o: ../include/openssl/ssl2.h ../include/openssl/ssl23.h s_socket.o: ../include/openssl/ssl3.h ../include/openssl/stack.h s_socket.o: ../include/openssl/tls1.h ../include/openssl/x509.h -s_socket.o: ../include/openssl/x509_vfy.h apps.h progs.h s_apps.h +s_socket.o: ../include/openssl/x509_vfy.h apps.h s_apps.h s_time.o: ../include/openssl/asn1.h ../include/openssl/bio.h s_time.o: ../include/openssl/blowfish.h ../include/openssl/bn.h s_time.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -634,7 +688,7 @@ s_time.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h s_time.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h s_time.o: ../include/openssl/stack.h ../include/openssl/tls1.h s_time.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -s_time.o: progs.h s_apps.h +s_time.o: s_apps.h sess_id.o: ../include/openssl/asn1.h ../include/openssl/bio.h sess_id.o: ../include/openssl/blowfish.h ../include/openssl/bn.h sess_id.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -655,7 +709,23 @@ sess_id.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h sess_id.o: ../include/openssl/ssl23.h ../include/openssl/ssl3.h sess_id.o: ../include/openssl/stack.h ../include/openssl/tls1.h sess_id.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -sess_id.o: progs.h +smime.o: ../include/openssl/asn1.h ../include/openssl/bio.h +smime.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +smime.o: ../include/openssl/buffer.h ../include/openssl/cast.h +smime.o: ../include/openssl/crypto.h ../include/openssl/des.h +smime.o: ../include/openssl/dh.h ../include/openssl/dsa.h +smime.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +smime.o: ../include/openssl/err.h ../include/openssl/evp.h +smime.o: ../include/openssl/idea.h ../include/openssl/md2.h +smime.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +smime.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +smime.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +smime.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +smime.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +smime.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +smime.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +smime.o: ../include/openssl/sha.h ../include/openssl/stack.h +smime.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h speed.o: ../include/openssl/asn1.h ../include/openssl/bio.h speed.o: ../include/openssl/blowfish.h ../include/openssl/bn.h speed.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -673,15 +743,34 @@ speed.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h speed.o: ../include/openssl/rsa.h ../include/openssl/safestack.h speed.o: ../include/openssl/sha.h ../include/openssl/stack.h speed.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h ./testdsa.h -speed.o: ./testrsa.h apps.h progs.h +speed.o: ./testrsa.h apps.h +spkac.o: ../include/openssl/asn1.h ../include/openssl/bio.h +spkac.o: ../include/openssl/blowfish.h ../include/openssl/bn.h +spkac.o: ../include/openssl/buffer.h ../include/openssl/cast.h +spkac.o: ../include/openssl/conf.h ../include/openssl/crypto.h +spkac.o: ../include/openssl/des.h ../include/openssl/dh.h +spkac.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +spkac.o: ../include/openssl/e_os2.h ../include/openssl/err.h +spkac.o: ../include/openssl/evp.h ../include/openssl/idea.h +spkac.o: ../include/openssl/lhash.h ../include/openssl/md2.h +spkac.o: ../include/openssl/md5.h ../include/openssl/mdc2.h +spkac.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h +spkac.o: ../include/openssl/opensslv.h ../include/openssl/pem.h +spkac.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h +spkac.o: ../include/openssl/rc2.h ../include/openssl/rc4.h +spkac.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h +spkac.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +spkac.o: ../include/openssl/sha.h ../include/openssl/stack.h +spkac.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h verify.o: ../include/openssl/asn1.h ../include/openssl/bio.h verify.o: ../include/openssl/blowfish.h ../include/openssl/bn.h verify.o: ../include/openssl/buffer.h ../include/openssl/cast.h -verify.o: ../include/openssl/crypto.h ../include/openssl/des.h -verify.o: ../include/openssl/dh.h ../include/openssl/dsa.h -verify.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h -verify.o: ../include/openssl/err.h ../include/openssl/evp.h -verify.o: ../include/openssl/idea.h ../include/openssl/md2.h +verify.o: ../include/openssl/conf.h ../include/openssl/crypto.h +verify.o: ../include/openssl/des.h ../include/openssl/dh.h +verify.o: ../include/openssl/dsa.h ../include/openssl/e_os.h +verify.o: ../include/openssl/e_os2.h ../include/openssl/err.h +verify.o: ../include/openssl/evp.h ../include/openssl/idea.h +verify.o: ../include/openssl/lhash.h ../include/openssl/md2.h verify.o: ../include/openssl/md5.h ../include/openssl/mdc2.h verify.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h verify.o: ../include/openssl/opensslv.h ../include/openssl/pem.h @@ -690,8 +779,8 @@ verify.o: ../include/openssl/rc2.h ../include/openssl/rc4.h verify.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h verify.o: ../include/openssl/rsa.h ../include/openssl/safestack.h verify.o: ../include/openssl/sha.h ../include/openssl/stack.h -verify.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h apps.h -verify.o: progs.h +verify.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h +verify.o: ../include/openssl/x509v3.h apps.h version.o: ../include/openssl/asn1.h ../include/openssl/bio.h version.o: ../include/openssl/blowfish.h ../include/openssl/bn.h version.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -702,10 +791,12 @@ version.o: ../include/openssl/evp.h ../include/openssl/idea.h version.o: ../include/openssl/md2.h ../include/openssl/md5.h version.o: ../include/openssl/mdc2.h ../include/openssl/objects.h version.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h -version.o: ../include/openssl/rc2.h ../include/openssl/rc4.h -version.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h -version.o: ../include/openssl/rsa.h ../include/openssl/safestack.h -version.o: ../include/openssl/sha.h ../include/openssl/stack.h apps.h progs.h +version.o: ../include/openssl/pkcs7.h ../include/openssl/rc2.h +version.o: ../include/openssl/rc4.h ../include/openssl/rc5.h +version.o: ../include/openssl/ripemd.h ../include/openssl/rsa.h +version.o: ../include/openssl/safestack.h ../include/openssl/sha.h +version.o: ../include/openssl/stack.h ../include/openssl/x509.h +version.o: ../include/openssl/x509_vfy.h apps.h x509.o: ../include/openssl/asn1.h ../include/openssl/bio.h x509.o: ../include/openssl/blowfish.h ../include/openssl/bn.h x509.o: ../include/openssl/buffer.h ../include/openssl/cast.h @@ -724,4 +815,4 @@ x509.o: ../include/openssl/rc5.h ../include/openssl/ripemd.h x509.o: ../include/openssl/rsa.h ../include/openssl/safestack.h x509.o: ../include/openssl/sha.h ../include/openssl/stack.h x509.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h -x509.o: ../include/openssl/x509v3.h apps.h progs.h +x509.o: ../include/openssl/x509v3.h apps.h diff --git a/crypto/openssl/apps/app_rand.c b/crypto/openssl/apps/app_rand.c new file mode 100644 index 0000000..1146f9f --- /dev/null +++ b/crypto/openssl/apps/app_rand.c @@ -0,0 +1,213 @@ +/* apps/app_rand.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#define NON_MAIN +#include "apps.h" +#undef NON_MAIN +#include <openssl/bio.h> +#include <openssl/rand.h> + + +static int seeded = 0; +static int egdsocket = 0; + +int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn) + { + int consider_randfile = (file == NULL); + char buffer[200]; + +#ifdef WINDOWS + BIO_printf(bio_e,"Loading 'screen' into random state -"); + BIO_flush(bio_e); + RAND_screen(); + BIO_printf(bio_e," done\n"); +#endif + + if (file == NULL) + file = RAND_file_name(buffer, sizeof buffer); + else if (RAND_egd(file) > 0) + { + /* we try if the given filename is an EGD socket. + if it is, we don't write anything back to the file. */ + egdsocket = 1; + return 1; + } + if (file == NULL || !RAND_load_file(file, -1)) + { + if (RAND_status() == 0 && !dont_warn) + { + BIO_printf(bio_e,"unable to load 'random state'\n"); + BIO_printf(bio_e,"This means that the random number generator has not been seeded\n"); + BIO_printf(bio_e,"with much random data.\n"); + if (consider_randfile) /* explanation does not apply when a file is explicitly named */ + { + BIO_printf(bio_e,"Consider setting the RANDFILE environment variable to point at a file that\n"); + BIO_printf(bio_e,"'random' data can be kept in (the file will be overwritten).\n"); + } + } + return 0; + } + seeded = 1; + return 1; + } + +long app_RAND_load_files(char *name) + { + char *p,*n; + int last; + long tot=0; + int egd; + + for (;;) + { + last=0; + for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); + if (*p == '\0') last=1; + *p='\0'; + n=name; + name=p+1; + if (*n == '\0') break; + + egd=RAND_egd(n); + if (egd > 0) tot+=egd; + tot+=RAND_load_file(n,-1); + if (last) break; + } + if (tot > 512) + app_RAND_allow_write_file(); + return(tot); + } + +int app_RAND_write_file(const char *file, BIO *bio_e) + { + char buffer[200]; + + if (egdsocket || !seeded) + /* If we did not manage to read the seed file, + * we should not write a low-entropy seed file back -- + * it would suppress a crucial warning the next time + * we want to use it. */ + return 0; + + if (file == NULL) + file = RAND_file_name(buffer, sizeof buffer); + if (file == NULL || !RAND_write_file(file)) + { + BIO_printf(bio_e,"unable to write 'random state'\n"); + return 0; + } + return 1; + } + +void app_RAND_allow_write_file(void) + { + seeded = 1; + } diff --git a/crypto/openssl/apps/apps.c b/crypto/openssl/apps/apps.c index 8fb5e8a..a87d23b 100644 --- a/crypto/openssl/apps/apps.c +++ b/crypto/openssl/apps/apps.c @@ -324,3 +324,93 @@ int app_init(long mesgwin) return(1); } #endif + + +int dump_cert_text (BIO *out, X509 *x) +{ + char buf[256]; + X509_NAME_oneline(X509_get_subject_name(x),buf,256); + BIO_puts(out,"subject="); + BIO_puts(out,buf); + + X509_NAME_oneline(X509_get_issuer_name(x),buf,256); + BIO_puts(out,"\nissuer= "); + BIO_puts(out,buf); + BIO_puts(out,"\n"); + return 0; +} + +static char *app_get_pass(BIO *err, char *arg, int keepbio); + +int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2) +{ + int same; + if(!arg2 || !arg1 || strcmp(arg1, arg2)) same = 0; + else same = 1; + if(arg1) { + *pass1 = app_get_pass(err, arg1, same); + if(!*pass1) return 0; + } else if(pass1) *pass1 = NULL; + if(arg2) { + *pass2 = app_get_pass(err, arg2, same ? 2 : 0); + if(!*pass2) return 0; + } else if(pass2) *pass2 = NULL; + return 1; +} + +static char *app_get_pass(BIO *err, char *arg, int keepbio) +{ + char *tmp, tpass[APP_PASS_LEN]; + static BIO *pwdbio = NULL; + int i; + if(!strncmp(arg, "pass:", 5)) return BUF_strdup(arg + 5); + if(!strncmp(arg, "env:", 4)) { + tmp = getenv(arg + 4); + if(!tmp) { + BIO_printf(err, "Can't read environment variable %s\n", arg + 4); + return NULL; + } + return BUF_strdup(tmp); + } + if(!keepbio || !pwdbio) { + if(!strncmp(arg, "file:", 5)) { + pwdbio = BIO_new_file(arg + 5, "r"); + if(!pwdbio) { + BIO_printf(err, "Can't open file %s\n", arg + 5); + return NULL; + } + } else if(!strncmp(arg, "fd:", 3)) { + BIO *btmp; + i = atoi(arg + 3); + if(i >= 0) pwdbio = BIO_new_fd(i, BIO_NOCLOSE); + if((i < 0) || !pwdbio) { + BIO_printf(err, "Can't access file descriptor %s\n", arg + 3); + return NULL; + } + /* Can't do BIO_gets on an fd BIO so add a buffering BIO */ + btmp = BIO_new(BIO_f_buffer()); + pwdbio = BIO_push(btmp, pwdbio); + } else if(!strcmp(arg, "stdin")) { + pwdbio = BIO_new_fp(stdin, BIO_NOCLOSE); + if(!pwdbio) { + BIO_printf(err, "Can't open BIO for stdin\n"); + return NULL; + } + } else { + BIO_printf(err, "Invalid password argument \"%s\"\n", arg); + return NULL; + } + } + i = BIO_gets(pwdbio, tpass, APP_PASS_LEN); + if(keepbio != 1) { + BIO_free_all(pwdbio); + pwdbio = NULL; + } + if(i <= 0) { + BIO_printf(err, "Error reading password from BIO\n"); + return NULL; + } + tmp = strchr(tpass, '\n'); + if(tmp) *tmp = 0; + return BUF_strdup(tpass); +} diff --git a/crypto/openssl/apps/apps.h b/crypto/openssl/apps/apps.h index 063f9c6..2dcdb88 100644 --- a/crypto/openssl/apps/apps.h +++ b/crypto/openssl/apps/apps.h @@ -64,7 +64,17 @@ #include <openssl/buffer.h> #include <openssl/bio.h> #include <openssl/crypto.h> -#include "progs.h" +#include <openssl/x509.h> + +int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn); +int app_RAND_write_file(const char *file, BIO *bio_e); +/* When `file' is NULL, use defaults. + * `bio_e' is for error messages. */ +void app_RAND_allow_write_file(void); +long app_RAND_load_files(char *file); /* `file' is a list of files to read, + * separated by LIST_SEPARATOR_CHAR + * (see e_os.h). The string is + * destroyed! */ #ifdef NO_STDIO BIO_METHOD *BIO_s_file(); @@ -103,7 +113,7 @@ extern BIO *bio_err; #define do_pipe_sig() #endif -#if defined(MONOLITH) && !defined(SSLEAY) +#if defined(MONOLITH) && !defined(OPENSSL_C) # define apps_startup() do_pipe_sig() #else # if defined(MSDOS) || defined(WIN16) || defined(WIN32) @@ -132,10 +142,16 @@ int args_from_file(char *file, int *argc, char **argv[]); int str2fmt(char *s); void program_name(char *in,char *out,int size); int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]); +#ifdef HEADER_X509_H +int dump_cert_text(BIO *out, X509 *x); +#endif +int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2); #define FORMAT_UNDEF 0 #define FORMAT_ASN1 1 #define FORMAT_TEXT 2 #define FORMAT_PEM 3 #define FORMAT_NETSCAPE 4 +#define APP_PASS_LEN 1024 + #endif diff --git a/crypto/openssl/apps/asn1pars.c b/crypto/openssl/apps/asn1pars.c index 1b272b2..f104ebc 100644 --- a/crypto/openssl/apps/asn1pars.c +++ b/crypto/openssl/apps/asn1pars.c @@ -74,19 +74,21 @@ * -i - indent the details by depth * -offset - where in the file to start * -length - how many bytes to use - * -oid file - extra oid decription file + * -oid file - extra oid description file */ #undef PROG #define PROG asn1parse_main +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int i,badops=0,offset=0,ret=1,j; unsigned int length=0; long num,tmplen; BIO *in=NULL,*out=NULL,*b64=NULL, *derout = NULL; - int informat,indent=0; + int informat,indent=0, noout = 0; char *infile=NULL,*str=NULL,*prog,*oidfile=NULL, *derfile=NULL; unsigned char *tmpbuf; BUF_MEM *buf=NULL; @@ -130,6 +132,7 @@ int MAIN(int argc, char **argv) { indent=1; } + else if (strcmp(*argv,"-noout") == 0) noout = 1; else if (strcmp(*argv,"-oid") == 0) { if (--argc < 1) goto bad; @@ -168,8 +171,10 @@ bad: BIO_printf(bio_err,"where options are\n"); BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n"); BIO_printf(bio_err," -in arg input file\n"); + BIO_printf(bio_err," -out arg output file\n"); + BIO_printf(bio_err," -noout arg don't produce any output\n"); BIO_printf(bio_err," -offset arg offset into file\n"); - BIO_printf(bio_err," -length arg lenth of section in file\n"); + BIO_printf(bio_err," -length arg length of section in file\n"); BIO_printf(bio_err," -i indent entries\n"); BIO_printf(bio_err," -oid file file of extra oid definitions\n"); BIO_printf(bio_err," -strparse offset\n"); @@ -287,7 +292,8 @@ bad: goto end; } } - if (!ASN1_parse(out,(unsigned char *)&(str[offset]),length,indent)) + if (!noout && + !ASN1_parse(out,(unsigned char *)&(str[offset]),length,indent)) { ERR_print_errors(bio_err); goto end; diff --git a/crypto/openssl/apps/ca.c b/crypto/openssl/apps/ca.c index 9ed100d..73df13f 100644 --- a/crypto/openssl/apps/ca.c +++ b/crypto/openssl/apps/ca.c @@ -147,6 +147,8 @@ static char *ca_usage[]={ " -gencrl - Generate a new CRL\n", " -crldays days - Days is when the next CRL is due\n", " -crlhours hours - Hours is when the next CRL is due\n", +" -startdate YYMMDDHHMMSSZ - certificate validity notBefore\n", +" -enddate YYMMDDHHMMSSZ - certificate validity notAfter (overrides -days)\n", " -days arg - number of days to certify the certificate for\n", " -md arg - md to use, one of md2, md5, sha or sha1\n", " -policy arg - The CA 'policy' to support\n", @@ -163,6 +165,8 @@ static char *ca_usage[]={ " -batch - Don't ask questions\n", " -msie_hack - msie modifications to handle all those universal strings\n", " -revoke file - Revoke a certificate (given in file)\n", +" -extensions .. - Extension section (override value in config file)\n", +" -crlexts .. - CRL extension section (override value in config file)\n", NULL }; @@ -174,7 +178,6 @@ extern int EF_ALIGNMENT; static int add_oid_section(LHASH *conf); static void lookup_fail(char *name,char *tag); -static int MS_CALLBACK key_callback(char *buf,int len,int verify,void *u); static unsigned long index_serial_hash(char **a); static int index_serial_cmp(char **a, char **b); static unsigned long index_name_hash(char **a); @@ -197,22 +200,24 @@ static int certify_spkac(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509, char *enddate, int days, char *ext_sect,LHASH *conf, int verbose); static int fix_data(int nid, int *type); -static void write_new_certificate(BIO *bp, X509 *x, int output_der); +static void write_new_certificate(BIO *bp, X509 *x, int output_der, int notext); static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst, STACK_OF(CONF_VALUE) *policy, TXT_DB *db, BIGNUM *serial, char *startdate, char *enddate, int days, int batch, int verbose, X509_REQ *req, char *ext_sect, LHASH *conf); static int do_revoke(X509 *x509, TXT_DB *db); static int check_time_format(char *str); -static LHASH *conf; -static char *key=NULL; +static LHASH *conf=NULL; static char *section=NULL; static int preserve=0; static int msie_hack=0; +int MAIN(int, char **); + int MAIN(int argc, char **argv) { + char *key=NULL; int total=0; int total_done=0; int badops=0; @@ -244,6 +249,7 @@ int MAIN(int argc, char **argv) char *enddate=NULL; int days=0; int batch=0; + int notext=0; X509 *x509=NULL; X509 *x=NULL; BIO *in=NULL,*out=NULL,*Sout=NULL,*Cout=NULL; @@ -262,6 +268,7 @@ int MAIN(int argc, char **argv) #undef BSIZE #define BSIZE 256 MS_STATIC char buf[3][BSIZE]; + char *randfile=NULL; #ifdef EFENCE EF_PROTECT_FREE=1; @@ -271,9 +278,12 @@ EF_ALIGNMENT=0; apps_startup(); - X509V3_add_standard_extensions(); + conf = NULL; + key = NULL; + section = NULL; preserve=0; + msie_hack=0; if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); @@ -350,6 +360,8 @@ EF_ALIGNMENT=0; if (--argc < 1) goto bad; outdir= *(++argv); } + else if (strcmp(*argv,"-notext") == 0) + notext=1; else if (strcmp(*argv,"-batch") == 0) batch=1; else if (strcmp(*argv,"-preserveDN") == 0) @@ -393,6 +405,16 @@ EF_ALIGNMENT=0; infile= *(++argv); dorevoke=1; } + else if (strcmp(*argv,"-extensions") == 0) + { + if (--argc < 1) goto bad; + extensions= *(++argv); + } + else if (strcmp(*argv,"-crlexts") == 0) + { + if (--argc < 1) goto bad; + crl_ext= *(++argv); + } else { bad: @@ -476,12 +498,16 @@ bad: BIO_free(oid_bio); } } - } - if(!add_oid_section(conf)) { + if(!add_oid_section(conf)) + { ERR_print_errors(bio_err); goto err; + } } + randfile = CONF_get_string(conf, BASE_SECTION, "RANDFILE"); + app_RAND_load_file(randfile, bio_err, 0); + in=BIO_new(BIO_s_file()); out=BIO_new(BIO_s_file()); Sout=BIO_new(BIO_s_file()); @@ -493,7 +519,7 @@ bad: } /*****************************************************************/ - /* we definitly need an public key, so lets get it */ + /* we definitely need an public key, so lets get it */ if ((keyfile == NULL) && ((keyfile=CONF_get_string(conf, section,ENV_PRIVATE_KEY)) == NULL)) @@ -507,13 +533,8 @@ bad: BIO_printf(bio_err,"trying to load CA private key\n"); goto err; } - if (key == NULL) - pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL); - else - { - pkey=PEM_read_bio_PrivateKey(in,NULL,key_callback,NULL); - memset(key,0,strlen(key)); - } + pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,key); + if(key) memset(key,0,strlen(key)); if (pkey == NULL) { BIO_printf(bio_err,"unable to load CA private key\n"); @@ -566,14 +587,19 @@ bad: BIO_printf(bio_err,"there needs to be defined a directory for new certificate to be placed in\n"); goto err; } -#ifdef VMS - /* For technical reasons, VMS misbehaves with X_OK */ - if (access(outdir,R_OK|W_OK) != 0) -#else +#ifndef VMS /* outdir is a directory spec, but access() for VMS demands a + filename. In any case, stat(), below, will catch the problem + if outdir is not a directory spec, and the fopen() or open() + will catch an error if there is no write access. + + Presumably, this problem could also be solved by using the DEC + C routines to convert the directory syntax to Unixly, and give + that to access(). However, time's too short to do that just + now. + */ if (access(outdir,R_OK|W_OK|X_OK) != 0) -#endif { - BIO_printf(bio_err,"I am unable to acces the %s directory\n",outdir); + BIO_printf(bio_err,"I am unable to access the %s directory\n",outdir); perror(outdir); goto err; } @@ -584,12 +610,15 @@ bad: perror(outdir); goto err; } +#ifdef S_IFDIR if (!(sb.st_mode & S_IFDIR)) { BIO_printf(bio_err,"%s need to be a directory\n",outdir); perror(outdir); goto err; } +#endif +#endif } /*****************************************************************/ @@ -655,7 +684,7 @@ bad: TXT_DB_write(out,db); BIO_printf(bio_err,"%d entries loaded from the database\n", db->data->num); - BIO_printf(bio_err,"generating indexs\n"); + BIO_printf(bio_err,"generating index\n"); } if (!TXT_DB_create_index(db,DB_serial,NULL,index_serial_hash, @@ -720,8 +749,8 @@ bad: lookup_fail(section,ENV_SERIAL); goto err; } - - extensions=CONF_get_string(conf,section,ENV_EXTENSIONS); + if(!extensions) + extensions=CONF_get_string(conf,section,ENV_EXTENSIONS); if(extensions) { /* Check syntax of file */ X509V3_CTX ctx; @@ -966,8 +995,8 @@ bad: perror(buf[2]); goto err; } - write_new_certificate(Cout,x, 0); - write_new_certificate(Sout,x, output_der); + write_new_certificate(Cout,x, 0, notext); + write_new_certificate(Sout,x, output_der, notext); } if (sk_num(cert_sk)) @@ -987,14 +1016,14 @@ bad: out=NULL; if (rename(serialfile,buf[2]) < 0) { - BIO_printf(bio_err,"unabel to rename %s to %s\n", + BIO_printf(bio_err,"unable to rename %s to %s\n", serialfile,buf[2]); perror("reason"); goto err; } if (rename(buf[0],serialfile) < 0) { - BIO_printf(bio_err,"unabel to rename %s to %s\n", + BIO_printf(bio_err,"unable to rename %s to %s\n", buf[0],serialfile); perror("reason"); rename(buf[2],serialfile); @@ -1011,14 +1040,14 @@ bad: if (rename(dbfile,buf[2]) < 0) { - BIO_printf(bio_err,"unabel to rename %s to %s\n", + BIO_printf(bio_err,"unable to rename %s to %s\n", dbfile,buf[2]); perror("reason"); goto err; } if (rename(buf[1],dbfile) < 0) { - BIO_printf(bio_err,"unabel to rename %s to %s\n", + BIO_printf(bio_err,"unable to rename %s to %s\n", buf[1],dbfile); perror("reason"); rename(buf[2],dbfile); @@ -1031,7 +1060,7 @@ bad: /*****************************************************************/ if (gencrl) { - crl_ext=CONF_get_string(conf,section,ENV_CRLEXT); + if(!crl_ext) crl_ext=CONF_get_string(conf,section,ENV_CRLEXT); if(crl_ext) { /* Check syntax of file */ X509V3_CTX ctx; @@ -1143,13 +1172,6 @@ bad: /*****************************************************************/ if (dorevoke) { - in=BIO_new(BIO_s_file()); - out=BIO_new(BIO_s_file()); - if ((in == NULL) || (out == NULL)) - { - ERR_print_errors(bio_err); - goto err; - } if (infile == NULL) { BIO_printf(bio_err,"no input files\n"); @@ -1157,19 +1179,22 @@ bad: } else { + X509 *revcert; if (BIO_read_filename(in,infile) <= 0) { perror(infile); BIO_printf(bio_err,"error trying to load '%s' certificate\n",infile); goto err; } - x509=PEM_read_bio_X509(in,NULL,NULL,NULL); - if (x509 == NULL) + revcert=PEM_read_bio_X509(in,NULL,NULL,NULL); + if (revcert == NULL) { BIO_printf(bio_err,"unable to load '%s' certificate\n",infile); goto err; } - j=do_revoke(x509,db); + j=do_revoke(revcert,db); + if (j <= 0) goto err; + X509_free(revcert); strncpy(buf[0],dbfile,BSIZE-4); strcat(buf[0],".new"); @@ -1181,10 +1206,6 @@ bad: } j=TXT_DB_write(out,db); if (j <= 0) goto err; - BIO_free(in); - BIO_free(out); - in=NULL; - out=NULL; strncpy(buf[1],dbfile,BSIZE-4); strcat(buf[1],".old"); if (rename(dbfile,buf[1]) < 0) @@ -1215,13 +1236,13 @@ err: sk_pop_free(cert_sk,X509_free); if (ret) ERR_print_errors(bio_err); + app_RAND_write_file(randfile, bio_err); BN_free(serial); TXT_DB_free(db); EVP_PKEY_free(pkey); X509_free(x509); X509_CRL_free(crl); CONF_free(conf); - X509V3_EXT_cleanup(); OBJ_cleanup(); EXIT(ret); } @@ -1231,17 +1252,6 @@ static void lookup_fail(char *name, char *tag) BIO_printf(bio_err,"variable lookup failed for %s::%s\n",name,tag); } -static int MS_CALLBACK key_callback(char *buf, int len, int verify, void *u) - { - int i; - - if (key == NULL) return(0); - i=strlen(key); - i=(i > len)?len:i; - memcpy(buf,key,i); - return(i); - } - static unsigned long index_serial_hash(char **a) { char *n; @@ -1652,7 +1662,7 @@ again2: } if (j < 0) { - BIO_printf(bio_err,"The %s field needed to be the same in the\nCA certificate (%s) and the request (%s)\n",cv->name,((str == NULL)?"NULL":(char *)str->data),((str2 == NULL)?"NULL":(char *)str2->data)); + BIO_printf(bio_err,"The %s field needed to be the same in the\nCA certificate (%s) and the request (%s)\n",cv->name,((str2 == NULL)?"NULL":(char *)str2->data),((str == NULL)?"NULL":(char *)str->data)); goto err; } } @@ -1664,8 +1674,7 @@ again2: if (push != NULL) { - if (!X509_NAME_add_entry(subject,push, - X509_NAME_entry_count(subject),0)) + if (!X509_NAME_add_entry(subject,push, -1, 0)) { if (push != NULL) X509_NAME_ENTRY_free(push); @@ -1685,7 +1694,7 @@ again2: } if (verbose) - BIO_printf(bio_err,"The subject name apears to be ok, checking data base for clashes\n"); + BIO_printf(bio_err,"The subject name appears to be ok, checking data base for clashes\n"); row[DB_name]=X509_NAME_oneline(subject,NULL,0); row[DB_serial]=BN_bn2hex(serial); @@ -1742,7 +1751,7 @@ again2: goto err; } - /* We are now totaly happy, lets make and sign the certificate */ + /* We are now totally happy, lets make and sign the certificate */ if (verbose) BIO_printf(bio_err,"Everything appears to be ok, creating and signing the certificate\n"); @@ -1789,7 +1798,7 @@ again2: ASN1_INTEGER_set(ci->version,2); /* version 3 certificate */ /* Free the current entries if any, there should not - * be any I belive */ + * be any I believe */ if (ci->extensions != NULL) sk_X509_EXTENSION_pop_free(ci->extensions, X509_EXTENSION_free); @@ -1883,6 +1892,8 @@ err: X509_NAME_free(CAname); if (subject != NULL) X509_NAME_free(subject); + if (tmptm != NULL) + ASN1_UTCTIME_free(tmptm); if (ok <= 0) { if (ret != NULL) X509_free(ret); @@ -1893,17 +1904,16 @@ err: return(ok); } -static void write_new_certificate(BIO *bp, X509 *x, int output_der) +static void write_new_certificate(BIO *bp, X509 *x, int output_der, int notext) { - char *f; - char buf[256]; if (output_der) { (void)i2d_X509_bio(bp,x); return; } - +#if 0 + /* ??? Not needed since X509_print prints all this stuff anyway */ f=X509_NAME_oneline(X509_get_issuer_name(x),buf,256); BIO_printf(bp,"issuer :%s\n",f); @@ -1913,10 +1923,9 @@ static void write_new_certificate(BIO *bp, X509 *x, int output_der) BIO_puts(bp,"serial :"); i2a_ASN1_INTEGER(bp,x->cert_info->serialNumber); BIO_puts(bp,"\n\n"); - X509_print(bp,x); - BIO_puts(bp,"\n"); +#endif + if(!notext)X509_print(bp,x); PEM_write_bio_X509(bp,x); - BIO_puts(bp,"\n"); } static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, @@ -1929,7 +1938,6 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, X509_REQ *req=NULL; CONF_VALUE *cv=NULL; NETSCAPE_SPKI *spki = NULL; - unsigned char *spki_der = NULL,*p; X509_REQ_INFO *ri; char *type,*buf; EVP_PKEY *pktmp=NULL; @@ -1986,31 +1994,22 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, cv=sk_CONF_VALUE_value(sk,i); type=cv->name; - buf=cv->value; + /* Skip past any leading X. X: X, etc to allow for + * multiple instances + */ + for(buf = cv->name; *buf ; buf++) + if ((*buf == ':') || (*buf == ',') || (*buf == '.')) { + buf++; + if(*buf) type = buf; + break; + } + buf=cv->value; if ((nid=OBJ_txt2nid(type)) == NID_undef) { if (strcmp(type, "SPKAC") == 0) { - spki_der=(unsigned char *)Malloc( - strlen(cv->value)+1); - if (spki_der == NULL) - { - BIO_printf(bio_err,"Malloc failure\n"); - goto err; - } - j = EVP_DecodeBlock(spki_der, (unsigned char *)cv->value, - strlen(cv->value)); - if (j <= 0) - { - BIO_printf(bio_err, "Can't b64 decode SPKAC structure\n"); - goto err; - } - - p=spki_der; - spki = d2i_NETSCAPE_SPKI(&spki, &p, j); - Free(spki_der); - spki_der = NULL; + spki = NETSCAPE_SPKI_b64_decode(cv->value, -1); if (spki == NULL) { BIO_printf(bio_err,"unable to load Netscape SPKAC structure\n"); @@ -2034,8 +2033,7 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, strlen(buf))) == NULL) goto err; - if (!X509_NAME_add_entry(n,ne,X509_NAME_entry_count(n),0)) - goto err; + if (!X509_NAME_add_entry(n,ne,-1, 0)) goto err; } if (spki == NULL) { @@ -2050,7 +2048,7 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, BIO_printf(bio_err,"Check that the SPKAC request matches the signature\n"); - if ((pktmp=X509_PUBKEY_get(spki->spkac->pubkey)) == NULL) + if ((pktmp=NETSCAPE_SPKI_get_pubkey(spki)) == NULL) { BIO_printf(bio_err,"error unpacking SPKAC public key\n"); goto err; @@ -2071,7 +2069,6 @@ static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, err: if (req != NULL) X509_REQ_free(req); if (parms != NULL) CONF_free(parms); - if (spki_der != NULL) Free(spki_der); if (spki != NULL) NETSCAPE_SPKI_free(spki); if (ne != NULL) X509_NAME_ENTRY_free(ne); @@ -2127,20 +2124,26 @@ static int add_oid_section(LHASH *hconf) static int do_revoke(X509 *x509, TXT_DB *db) { - ASN1_UTCTIME *tm=NULL; + ASN1_UTCTIME *tm=NULL, *revtm=NULL; char *row[DB_NUMBER],**rrow,**irow; + BIGNUM *bn = NULL; int ok=-1,i; for (i=0; i<DB_NUMBER; i++) row[i]=NULL; - row[DB_name]=X509_NAME_oneline(x509->cert_info->subject,NULL,0); - row[DB_serial]=BN_bn2hex(ASN1_INTEGER_to_BN(x509->cert_info->serialNumber,NULL)); + row[DB_name]=X509_NAME_oneline(X509_get_subject_name(x509),NULL,0); + bn = ASN1_INTEGER_to_BN(X509_get_serialNumber(x509),NULL); + row[DB_serial]=BN_bn2hex(bn); + BN_free(bn); if ((row[DB_name] == NULL) || (row[DB_serial] == NULL)) { BIO_printf(bio_err,"Malloc failure\n"); goto err; } - rrow=TXT_DB_get_by_index(db,DB_name,row); + /* We have to lookup by serial number because name lookup + * skips revoked certs + */ + rrow=TXT_DB_get_by_index(db,DB_serial,row); if (rrow == NULL) { BIO_printf(bio_err,"Adding Entry to DB for %s\n", row[DB_name]); @@ -2191,16 +2194,15 @@ static int do_revoke(X509 *x509, TXT_DB *db) } /* Revoke Certificate */ - do_revoke(x509,db); + ok = do_revoke(x509,db); - ok=1; goto err; } - else if (index_serial_cmp(row,rrow)) + else if (index_name_cmp(row,rrow)) { - BIO_printf(bio_err,"ERROR:no same serial number %s\n", - row[DB_serial]); + BIO_printf(bio_err,"ERROR:name does not match %s\n", + row[DB_name]); goto err; } else if (rrow[DB_type][0]=='R') @@ -2212,12 +2214,14 @@ static int do_revoke(X509 *x509, TXT_DB *db) else { BIO_printf(bio_err,"Revoking Certificate %s.\n", rrow[DB_serial]); - tm=X509_gmtime_adj(tm,0); + revtm = ASN1_UTCTIME_new(); + revtm=X509_gmtime_adj(revtm,0); rrow[DB_type][0]='R'; rrow[DB_type][1]='\0'; - rrow[DB_rev_date]=(char *)Malloc(tm->length+1); - memcpy(rrow[DB_rev_date],tm->data,tm->length); - rrow[DB_rev_date][tm->length]='\0'; + rrow[DB_rev_date]=(char *)Malloc(revtm->length+1); + memcpy(rrow[DB_rev_date],revtm->data,revtm->length); + rrow[DB_rev_date][revtm->length]='\0'; + ASN1_UTCTIME_free(revtm); } ok=1; err: @@ -2226,7 +2230,6 @@ err: if (row[i] != NULL) Free(row[i]); } - ASN1_UTCTIME_free(tm); return(ok); } diff --git a/crypto/openssl/apps/ciphers.c b/crypto/openssl/apps/ciphers.c index 08e47be..f8e9e7b 100644 --- a/crypto/openssl/apps/ciphers.c +++ b/crypto/openssl/apps/ciphers.c @@ -66,10 +66,6 @@ #include <openssl/err.h> #include <openssl/ssl.h> -#if defined(NO_RSA) && !defined(NO_SSL2) -#define NO_SSL2 -#endif - #undef PROG #define PROG ciphers_main @@ -81,6 +77,8 @@ static char *ciphers_usage[]={ NULL }; +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int ret=1,i; @@ -145,12 +143,16 @@ int MAIN(int argc, char **argv) goto end; } - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); ctx=SSL_CTX_new(meth); if (ctx == NULL) goto err; - if (ciphers != NULL) - SSL_CTX_set_cipher_list(ctx,ciphers); + if (ciphers != NULL) { + if(!SSL_CTX_set_cipher_list(ctx,ciphers)) { + BIO_printf(bio_err, "Error in cipher list\n"); + goto err; + } + } ssl=SSL_new(ctx); if (ssl == NULL) goto err; diff --git a/crypto/openssl/apps/crl.c b/crypto/openssl/apps/crl.c index f7bdf76..338f46d 100644 --- a/crypto/openssl/apps/crl.c +++ b/crypto/openssl/apps/crl.c @@ -75,7 +75,7 @@ static char *crl_usage[]={ "usage: crl args\n", "\n", -" -inform arg - input format - default PEM (one of DER, TXT or PEM)\n", +" -inform arg - input format - default PEM (DER or PEM)\n", " -outform arg - output format - default PEM\n", " -text - print out a text format version\n", " -in arg - input file - default stdin\n", @@ -85,21 +85,32 @@ static char *crl_usage[]={ " -lastupdate - lastUpdate field\n", " -nextupdate - nextUpdate field\n", " -noout - no CRL output\n", +" -CAfile name - verify CRL using certificates in file \"name\"\n", +" -CApath dir - verify CRL using certificates in \"dir\"\n", NULL }; static X509_CRL *load_crl(char *file, int format); static BIO *bio_out=NULL; +int MAIN(int, char **); + int MAIN(int argc, char **argv) { X509_CRL *x=NULL; + char *CAfile = NULL, *CApath = NULL; int ret=1,i,num,badops=0; BIO *out=NULL; int informat,outformat; char *infile=NULL,*outfile=NULL; int hash=0,issuer=0,lastupdate=0,nextupdate=0,noout=0,text=0; char **pp,buf[256]; + X509_STORE *store = NULL; + X509_STORE_CTX ctx; + X509_LOOKUP *lookup = NULL; + X509_OBJECT xobj; + EVP_PKEY *pkey; + int do_ver = 0; apps_startup(); @@ -146,6 +157,20 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; outfile= *(++argv); } + else if (strcmp(*argv,"-CApath") == 0) + { + if (--argc < 1) goto bad; + CApath = *(++argv); + do_ver = 1; + } + else if (strcmp(*argv,"-CAfile") == 0) + { + if (--argc < 1) goto bad; + CAfile = *(++argv); + do_ver = 1; + } + else if (strcmp(*argv,"-verify") == 0) + do_ver = 1; else if (strcmp(*argv,"-text") == 0) text = 1; else if (strcmp(*argv,"-hash") == 0) @@ -177,36 +202,74 @@ bad: } ERR_load_crypto_strings(); - X509V3_add_standard_extensions(); x=load_crl(infile,informat); if (x == NULL) { goto end; } + if(do_ver) { + store = X509_STORE_new(); + lookup=X509_STORE_add_lookup(store,X509_LOOKUP_file()); + if (lookup == NULL) goto end; + if (!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) + X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT); + + lookup=X509_STORE_add_lookup(store,X509_LOOKUP_hash_dir()); + if (lookup == NULL) goto end; + if (!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) + X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT); + ERR_clear_error(); + + X509_STORE_CTX_init(&ctx, store, NULL, NULL); + + i = X509_STORE_get_by_subject(&ctx, X509_LU_X509, + X509_CRL_get_issuer(x), &xobj); + if(i <= 0) { + BIO_printf(bio_err, + "Error getting CRL issuer certificate\n"); + goto end; + } + pkey = X509_get_pubkey(xobj.data.x509); + X509_OBJECT_free_contents(&xobj); + if(!pkey) { + BIO_printf(bio_err, + "Error getting CRL issuer public key\n"); + goto end; + } + i = X509_CRL_verify(x, pkey); + EVP_PKEY_free(pkey); + if(i < 0) goto end; + if(i == 0) BIO_printf(bio_err, "verify failure\n"); + else BIO_printf(bio_err, "verify OK\n"); + } + if (num) { for (i=1; i<=num; i++) { if (issuer == i) { - X509_NAME_oneline(x->crl->issuer,buf,256); + X509_NAME_oneline(X509_CRL_get_issuer(x), + buf,256); BIO_printf(bio_out,"issuer= %s\n",buf); } if (hash == i) { BIO_printf(bio_out,"%08lx\n", - X509_NAME_hash(x->crl->issuer)); + X509_NAME_hash(X509_CRL_get_issuer(x))); } if (lastupdate == i) { BIO_printf(bio_out,"lastUpdate="); - ASN1_TIME_print(bio_out,x->crl->lastUpdate); + ASN1_TIME_print(bio_out, + X509_CRL_get_lastUpdate(x)); BIO_printf(bio_out,"\n"); } if (nextupdate == i) { BIO_printf(bio_out,"nextUpdate="); - if (x->crl->nextUpdate != NULL) - ASN1_TIME_print(bio_out,x->crl->nextUpdate); + if (X509_CRL_get_nextUpdate(x)) + ASN1_TIME_print(bio_out, + X509_CRL_get_nextUpdate(x)); else BIO_printf(bio_out,"NONE"); BIO_printf(bio_out,"\n"); @@ -250,8 +313,12 @@ bad: end: BIO_free(out); BIO_free(bio_out); + bio_out=NULL; X509_CRL_free(x); - X509V3_EXT_cleanup(); + if(store) { + X509_STORE_CTX_cleanup(&ctx); + X509_STORE_free(store); + } EXIT(ret); } diff --git a/crypto/openssl/apps/crl2p7.c b/crypto/openssl/apps/crl2p7.c index 8634e3a..4056591 100644 --- a/crypto/openssl/apps/crl2p7.c +++ b/crypto/openssl/apps/crl2p7.c @@ -76,12 +76,14 @@ static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile); #undef PROG #define PROG crl2pkcs7_main -/* -inform arg - input format - default PEM (one of DER, TXT or PEM) +/* -inform arg - input format - default PEM (DER or PEM) * -outform arg - output format - default PEM * -in arg - input file - default stdin * -out arg - output file - default stdout */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int i,badops=0; @@ -157,8 +159,8 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n"); + BIO_printf(bio_err," -inform arg input format - DER or PEM\n"); + BIO_printf(bio_err," -outform arg output format - DER or PEM\n"); BIO_printf(bio_err," -in arg input file\n"); BIO_printf(bio_err," -out arg output file\n"); BIO_printf(bio_err," -certfile arg certificates file of chain to a trusted CA\n"); diff --git a/crypto/openssl/apps/der_chop b/crypto/openssl/apps/der_chop index fbd2889..9070b03 100644 --- a/crypto/openssl/apps/der_chop +++ b/crypto/openssl/apps/der_chop @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl5 +#!/usr/local/bin/perl # # der_chop ... this is one total hack that Eric is really not proud of # so don't look at it and don't ask for support diff --git a/crypto/openssl/apps/dgst.c b/crypto/openssl/apps/dgst.c index 5f0506e..1b56d6e 100644 --- a/crypto/openssl/apps/dgst.c +++ b/crypto/openssl/apps/dgst.c @@ -74,6 +74,9 @@ #define PROG dgst_main void do_fp(unsigned char *buf,BIO *f,int sep); + +int MAIN(int, char **); + int MAIN(int argc, char **argv) { unsigned char *buf=NULL; diff --git a/crypto/openssl/apps/dh.c b/crypto/openssl/apps/dh.c index 9efdcd7..674963f 100644 --- a/crypto/openssl/apps/dh.c +++ b/crypto/openssl/apps/dh.c @@ -1,4 +1,5 @@ /* apps/dh.c */ +/* obsoleted by dhparam.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -72,7 +73,7 @@ #undef PROG #define PROG dh_main -/* -inform arg - input format - default PEM (one of DER, TXT or PEM) +/* -inform arg - input format - default PEM (DER or PEM) * -outform arg - output format - default PEM * -in arg - input file - default stdin * -out arg - output file - default stdout @@ -82,6 +83,8 @@ * -C */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { DH *dh=NULL; @@ -149,8 +152,8 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n"); + BIO_printf(bio_err," -inform arg input format - one of DER PEM\n"); + BIO_printf(bio_err," -outform arg output format - one of DER PEM\n"); BIO_printf(bio_err," -in arg input file\n"); BIO_printf(bio_err," -out arg output file\n"); BIO_printf(bio_err," -check check the DH parameters\n"); @@ -219,7 +222,7 @@ bad: BN_print(stdout,dh->g); printf("\n"); if (dh->length != 0) - printf("recomented private length=%ld\n",dh->length); + printf("recommended private length=%ld\n",dh->length); #endif } @@ -232,8 +235,8 @@ bad: } if (i & DH_CHECK_P_NOT_PRIME) printf("p value is not prime\n"); - if (i & DH_CHECK_P_NOT_STRONG_PRIME) - printf("p value is not a strong prime\n"); + if (i & DH_CHECK_P_NOT_SAFE_PRIME) + printf("p value is not a safe prime\n"); if (i & DH_UNABLE_TO_CHECK_GENERATOR) printf("unable to check the generator value\n"); if (i & DH_NOT_SUITABLE_GENERATOR) @@ -282,6 +285,7 @@ bad: printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n"); printf("\t\treturn(NULL);\n"); printf("\treturn(dh);\n\t}\n"); + Free(data); } @@ -297,7 +301,7 @@ bad: } if (!i) { - BIO_printf(bio_err,"unable to write DH paramaters\n"); + BIO_printf(bio_err,"unable to write DH parameters\n"); ERR_print_errors(bio_err); goto end; } diff --git a/crypto/openssl/apps/dhparam.c b/crypto/openssl/apps/dhparam.c new file mode 100644 index 0000000..709547f --- /dev/null +++ b/crypto/openssl/apps/dhparam.c @@ -0,0 +1,520 @@ +/* apps/dhparam.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef NO_DH +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <string.h> +#include "apps.h" +#include <openssl/bio.h> +#include <openssl/err.h> +#include <openssl/bn.h> +#include <openssl/dh.h> +#include <openssl/x509.h> +#include <openssl/pem.h> + +#ifndef NO_DSA +#include <openssl/dsa.h> +#endif + +#undef PROG +#define PROG dhparam_main + +#define DEFBITS 512 + +/* -inform arg - input format - default PEM (DER or PEM) + * -outform arg - output format - default PEM + * -in arg - input file - default stdin + * -out arg - output file - default stdout + * -dsaparam - read or generate DSA parameters, convert to DH + * -check - check the parameters are ok + * -noout + * -text + * -C + */ + +static void MS_CALLBACK dh_cb(int p, int n, void *arg); + +int MAIN(int, char **); + +int MAIN(int argc, char **argv) + { + DH *dh=NULL; + int i,badops=0,text=0; +#ifndef NO_DSA + int dsaparam=0; +#endif + BIO *in=NULL,*out=NULL; + int informat,outformat,check=0,noout=0,C=0,ret=1; + char *infile,*outfile,*prog; + char *inrand=NULL; + int num = 0, g = 0; + + apps_startup(); + + if (bio_err == NULL) + if ((bio_err=BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + + infile=NULL; + outfile=NULL; + informat=FORMAT_PEM; + outformat=FORMAT_PEM; + + prog=argv[0]; + argc--; + argv++; + while (argc >= 1) + { + if (strcmp(*argv,"-inform") == 0) + { + if (--argc < 1) goto bad; + informat=str2fmt(*(++argv)); + } + else if (strcmp(*argv,"-outform") == 0) + { + if (--argc < 1) goto bad; + outformat=str2fmt(*(++argv)); + } + else if (strcmp(*argv,"-in") == 0) + { + if (--argc < 1) goto bad; + infile= *(++argv); + } + else if (strcmp(*argv,"-out") == 0) + { + if (--argc < 1) goto bad; + outfile= *(++argv); + } + else if (strcmp(*argv,"-check") == 0) + check=1; + else if (strcmp(*argv,"-text") == 0) + text=1; +#ifndef NO_DSA + else if (strcmp(*argv,"-dsaparam") == 0) + dsaparam=1; +#endif + else if (strcmp(*argv,"-C") == 0) + C=1; + else if (strcmp(*argv,"-noout") == 0) + noout=1; + else if (strcmp(*argv,"-2") == 0) + g=2; + else if (strcmp(*argv,"-5") == 0) + g=5; + else if (strcmp(*argv,"-rand") == 0) + { + if (--argc < 1) goto bad; + inrand= *(++argv); + } + else if (((sscanf(*argv,"%d",&num) == 0) || (num <= 0))) + goto bad; + argv++; + argc--; + } + + if (badops) + { +bad: + BIO_printf(bio_err,"%s [options] [numbits]\n",prog); + BIO_printf(bio_err,"where options are\n"); + BIO_printf(bio_err," -inform arg input format - one of DER PEM\n"); + BIO_printf(bio_err," -outform arg output format - one of DER PEM\n"); + BIO_printf(bio_err," -in arg input file\n"); + BIO_printf(bio_err," -out arg output file\n"); +#ifndef NO_DSA + BIO_printf(bio_err," -dsaparam read or generate DSA parameters, convert to DH\n"); +#endif + BIO_printf(bio_err," -check check the DH parameters\n"); + BIO_printf(bio_err," -text print a text form of the DH parameters\n"); + BIO_printf(bio_err," -C Output C code\n"); + BIO_printf(bio_err," -2 generate parameters using 2 as the generator value\n"); + BIO_printf(bio_err," -5 generate parameters using 5 as the generator value\n"); + BIO_printf(bio_err," numbits number of bits in to generate (default 512)\n"); + BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); + BIO_printf(bio_err," the random number generator\n"); + BIO_printf(bio_err," -noout no output\n"); + goto end; + } + + ERR_load_crypto_strings(); + + if (g && !num) + num = DEFBITS; + +#ifndef NO_DSA + if (dsaparam) + { + if (g) + { + BIO_printf(bio_err, "generator may not be chosen for DSA parameters\n"); + goto end; + } + } + else +#endif + { + /* DH parameters */ + if (num && !g) + g = 2; + } + + if(num) { + + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) + { + BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); + } + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); + +#ifndef NO_DSA + if (dsaparam) + { + DSA *dsa; + + BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num); + dsa = DSA_generate_parameters(num, NULL, 0, NULL, NULL, dh_cb, bio_err); + if (dsa == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + + dh = DSA_dup_DH(dsa); + DSA_free(dsa); + if (dh == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + } + else +#endif + { + BIO_printf(bio_err,"Generating DH parameters, %d bit long safe prime, generator %d\n",num,g); + BIO_printf(bio_err,"This is going to take a long time\n"); + dh=DH_generate_parameters(num,g,dh_cb,bio_err); + + if (dh == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + } + + app_RAND_write_file(NULL, bio_err); + } else { + + in=BIO_new(BIO_s_file()); + if (in == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + if (infile == NULL) + BIO_set_fp(in,stdin,BIO_NOCLOSE); + else + { + if (BIO_read_filename(in,infile) <= 0) + { + perror(infile); + goto end; + } + } + + if (informat != FORMAT_ASN1 && informat != FORMAT_PEM) + { + BIO_printf(bio_err,"bad input format specified\n"); + goto end; + } + +#ifndef NO_DSA + if (dsaparam) + { + DSA *dsa; + + if (informat == FORMAT_ASN1) + dsa=d2i_DSAparams_bio(in,NULL); + else /* informat == FORMAT_PEM */ + dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL); + + if (dsa == NULL) + { + BIO_printf(bio_err,"unable to load DSA parameters\n"); + ERR_print_errors(bio_err); + goto end; + } + + dh = DSA_dup_DH(dsa); + DSA_free(dsa); + if (dh == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + } + else +#endif + { + if (informat == FORMAT_ASN1) + dh=d2i_DHparams_bio(in,NULL); + else /* informat == FORMAT_PEM */ + dh=PEM_read_bio_DHparams(in,NULL,NULL,NULL); + + if (dh == NULL) + { + BIO_printf(bio_err,"unable to load DH parameters\n"); + ERR_print_errors(bio_err); + goto end; + } + } + + /* dh != NULL */ + } + + out=BIO_new(BIO_s_file()); + if (out == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + if (outfile == NULL) + BIO_set_fp(out,stdout,BIO_NOCLOSE); + else + { + if (BIO_write_filename(out,outfile) <= 0) + { + perror(outfile); + goto end; + } + } + + + if (text) + { + DHparams_print(out,dh); + } + + if (check) + { + if (!DH_check(dh,&i)) + { + ERR_print_errors(bio_err); + goto end; + } + if (i & DH_CHECK_P_NOT_PRIME) + printf("p value is not prime\n"); + if (i & DH_CHECK_P_NOT_SAFE_PRIME) + printf("p value is not a safe prime\n"); + if (i & DH_UNABLE_TO_CHECK_GENERATOR) + printf("unable to check the generator value\n"); + if (i & DH_NOT_SUITABLE_GENERATOR) + printf("the g value is not a generator\n"); + if (i == 0) + printf("DH parameters appear to be ok.\n"); + } + if (C) + { + unsigned char *data; + int len,l,bits; + + len=BN_num_bytes(dh->p); + bits=BN_num_bits(dh->p); + data=(unsigned char *)Malloc(len); + if (data == NULL) + { + perror("Malloc"); + goto end; + } + printf("#ifndef HEADER_DH_H\n" + "#include <openssl/dh.h>\n" + "#endif\n"); + printf("DH *get_dh%d()\n\t{\n",bits); + + l=BN_bn2bin(dh->p,data); + printf("\tstatic unsigned char dh%d_p[]={",bits); + for (i=0; i<l; i++) + { + if ((i%12) == 0) printf("\n\t\t"); + printf("0x%02X,",data[i]); + } + printf("\n\t\t};\n"); + + l=BN_bn2bin(dh->g,data); + printf("\tstatic unsigned char dh%d_g[]={",bits); + for (i=0; i<l; i++) + { + if ((i%12) == 0) printf("\n\t\t"); + printf("0x%02X,",data[i]); + } + printf("\n\t\t};\n"); + + printf("\tDH *dh;\n\n"); + printf("\tif ((dh=DH_new()) == NULL) return(NULL);\n"); + printf("\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n", + bits,bits); + printf("\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n", + bits,bits); + printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n"); + printf("\t\t{ DH_free(dh); return(NULL); }\n"); + if (dh->length) + printf("\tdh->length = %d;\n", dh->length); + printf("\treturn(dh);\n\t}\n"); + Free(data); + } + + + if (!noout) + { + if (outformat == FORMAT_ASN1) + i=i2d_DHparams_bio(out,dh); + else if (outformat == FORMAT_PEM) + i=PEM_write_bio_DHparams(out,dh); + else { + BIO_printf(bio_err,"bad output format specified for outfile\n"); + goto end; + } + if (!i) + { + BIO_printf(bio_err,"unable to write DH parameters\n"); + ERR_print_errors(bio_err); + goto end; + } + } + ret=0; +end: + if (in != NULL) BIO_free(in); + if (out != NULL) BIO_free(out); + if (dh != NULL) DH_free(dh); + EXIT(ret); + } + +/* dh_cb is identical to dsa_cb in apps/dsaparam.c */ +static void MS_CALLBACK dh_cb(int p, int n, void *arg) + { + char c='*'; + + if (p == 0) c='.'; + if (p == 1) c='+'; + if (p == 2) c='*'; + if (p == 3) c='\n'; + BIO_write((BIO *)arg,&c,1); + (void)BIO_flush((BIO *)arg); +#ifdef LINT + p=n; +#endif + } + +#endif diff --git a/crypto/openssl/apps/dsa.c b/crypto/openssl/apps/dsa.c index fedecf2..4977671 100644 --- a/crypto/openssl/apps/dsa.c +++ b/crypto/openssl/apps/dsa.c @@ -83,6 +83,8 @@ * -modulus - print the DSA public key */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int ret=1; @@ -91,7 +93,10 @@ int MAIN(int argc, char **argv) const EVP_CIPHER *enc=NULL; BIO *in=NULL,*out=NULL; int informat,outformat,text=0,noout=0; + int pubin = 0, pubout = 0; char *infile,*outfile,*prog; + char *passargin = NULL, *passargout = NULL; + char *passin = NULL, *passout = NULL; int modulus=0; apps_startup(); @@ -130,12 +135,26 @@ 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,"-passout") == 0) + { + if (--argc < 1) goto bad; + passargout= *(++argv); + } else if (strcmp(*argv,"-noout") == 0) noout=1; else if (strcmp(*argv,"-text") == 0) text=1; else if (strcmp(*argv,"-modulus") == 0) modulus=1; + else if (strcmp(*argv,"-pubin") == 0) + pubin=1; + else if (strcmp(*argv,"-pubout") == 0) + pubout=1; else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL) { BIO_printf(bio_err,"unknown option %s\n",*argv); @@ -151,23 +170,30 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n"); - BIO_printf(bio_err," -in arg input file\n"); - BIO_printf(bio_err," -out arg output file\n"); - BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); - BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); + BIO_printf(bio_err," -inform arg input format - DER or PEM\n"); + BIO_printf(bio_err," -outform arg output format - DER or PEM\n"); + BIO_printf(bio_err," -in arg input file\n"); + BIO_printf(bio_err," -passin arg input file pass phrase source\n"); + BIO_printf(bio_err," -out arg output file\n"); + BIO_printf(bio_err," -passout arg output file pass phrase source\n"); + BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); + BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); #ifndef NO_IDEA - BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); + BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); #endif - BIO_printf(bio_err," -text print the key in text\n"); - BIO_printf(bio_err," -noout don't print key out\n"); - BIO_printf(bio_err," -modulus print the DSA public value\n"); + BIO_printf(bio_err," -text print the key in text\n"); + BIO_printf(bio_err," -noout don't print key out\n"); + BIO_printf(bio_err," -modulus print the DSA public value\n"); goto end; } ERR_load_crypto_strings(); + if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { + BIO_printf(bio_err, "Error getting passwords\n"); + goto end; + } + in=BIO_new(BIO_s_file()); out=BIO_new(BIO_s_file()); if ((in == NULL) || (out == NULL)) @@ -187,19 +213,21 @@ bad: } } - BIO_printf(bio_err,"read DSA private key\n"); - if (informat == FORMAT_ASN1) - dsa=d2i_DSAPrivateKey_bio(in,NULL); - else if (informat == FORMAT_PEM) - dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,NULL); - else + BIO_printf(bio_err,"read DSA key\n"); + if (informat == FORMAT_ASN1) { + if(pubin) dsa=d2i_DSA_PUBKEY_bio(in,NULL); + else dsa=d2i_DSAPrivateKey_bio(in,NULL); + } else if (informat == FORMAT_PEM) { + if(pubin) dsa=PEM_read_bio_DSA_PUBKEY(in,NULL, NULL, NULL); + else dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,passin); + } else { BIO_printf(bio_err,"bad input format specified for key\n"); goto end; } if (dsa == NULL) { - BIO_printf(bio_err,"unable to load Private Key\n"); + BIO_printf(bio_err,"unable to load Key\n"); ERR_print_errors(bio_err); goto end; } @@ -231,12 +259,16 @@ bad: } if (noout) goto end; - BIO_printf(bio_err,"writing DSA private key\n"); - if (outformat == FORMAT_ASN1) - i=i2d_DSAPrivateKey_bio(out,dsa); - else if (outformat == FORMAT_PEM) - i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL,NULL); - else { + BIO_printf(bio_err,"writing DSA key\n"); + if (outformat == FORMAT_ASN1) { + if(pubin || pubout) i=i2d_DSA_PUBKEY_bio(out,dsa); + else i=i2d_DSAPrivateKey_bio(out,dsa); + } else if (outformat == FORMAT_PEM) { + if(pubin || pubout) + i=PEM_write_bio_DSA_PUBKEY(out,dsa); + else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc, + NULL,0,NULL, passout); + } else { BIO_printf(bio_err,"bad output format specified for outfile\n"); goto end; } @@ -248,9 +280,11 @@ bad: else ret=0; end: - if (in != NULL) BIO_free(in); - if (out != NULL) BIO_free(out); - if (dsa != NULL) DSA_free(dsa); + if(in != NULL) BIO_free(in); + if(out != NULL) BIO_free(out); + if(dsa != NULL) DSA_free(dsa); + if(passin) Free(passin); + if(passout) Free(passout); EXIT(ret); } #endif diff --git a/crypto/openssl/apps/dsaparam.c b/crypto/openssl/apps/dsaparam.c index fb8d471..4d4e1ad 100644 --- a/crypto/openssl/apps/dsaparam.c +++ b/crypto/openssl/apps/dsaparam.c @@ -57,6 +57,7 @@ */ #ifndef NO_DSA +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -65,7 +66,6 @@ #include <openssl/bio.h> #include <openssl/err.h> #include <openssl/bn.h> -#include <openssl/rand.h> #include <openssl/dsa.h> #include <openssl/x509.h> #include <openssl/pem.h> @@ -73,7 +73,7 @@ #undef PROG #define PROG dsaparam_main -/* -inform arg - input format - default PEM (one of DER, TXT or PEM) +/* -inform arg - input format - default PEM (DER or PEM) * -outform arg - output format - default PEM * -in arg - input file - default stdin * -out arg - output file - default stdout @@ -84,7 +84,10 @@ * -genkey */ -static void MS_CALLBACK dsa_cb(int p, int n, char *arg); +static void MS_CALLBACK dsa_cb(int p, int n, void *arg); + +int MAIN(int, char **); + int MAIN(int argc, char **argv) { DSA *dsa=NULL; @@ -93,7 +96,7 @@ int MAIN(int argc, char **argv) int informat,outformat,noout=0,C=0,ret=1; char *infile,*outfile,*prog,*inrand=NULL; int numbits= -1,num,genkey=0; - char buffer[200],*randfile=NULL; + int need_rand=0; apps_startup(); @@ -136,11 +139,15 @@ int MAIN(int argc, char **argv) else if (strcmp(*argv,"-C") == 0) C=1; else if (strcmp(*argv,"-genkey") == 0) + { genkey=1; + need_rand=1; + } else if (strcmp(*argv,"-rand") == 0) { if (--argc < 1) goto bad; inrand= *(++argv); + need_rand=1; } else if (strcmp(*argv,"-noout") == 0) noout=1; @@ -148,6 +155,7 @@ int MAIN(int argc, char **argv) { /* generate a key */ numbits=num; + need_rand=1; } else { @@ -164,11 +172,11 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] [bits] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n"); + BIO_printf(bio_err," -inform arg input format - DER or PEM\n"); + BIO_printf(bio_err," -outform arg output format - DER or PEM\n"); BIO_printf(bio_err," -in arg input file\n"); BIO_printf(bio_err," -out arg output file\n"); - BIO_printf(bio_err," -text check the DSA parameters\n"); + BIO_printf(bio_err," -text print the key in text\n"); BIO_printf(bio_err," -C Output C code\n"); BIO_printf(bio_err," -noout no output\n"); BIO_printf(bio_err," -rand files to use for random number input\n"); @@ -207,15 +215,20 @@ bad: } } - if (numbits > 0) + if (need_rand) { - randfile=RAND_file_name(buffer,200); - RAND_load_file(randfile,1024L*1024L); + app_RAND_load_file(NULL, bio_err, (inrand != NULL)); + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); + } + if (numbits > 0) + { + assert(need_rand); BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num); BIO_printf(bio_err,"This could take some time\n"); - dsa=DSA_generate_parameters(num,NULL,0,NULL,NULL, - dsa_cb,(char *)bio_err); + dsa=DSA_generate_parameters(num,NULL,0,NULL,NULL, dsa_cb,bio_err); } else if (informat == FORMAT_ASN1) dsa=d2i_DSAparams_bio(in,NULL); @@ -307,7 +320,7 @@ bad: } if (!i) { - BIO_printf(bio_err,"unable to write DSA paramaters\n"); + BIO_printf(bio_err,"unable to write DSA parameters\n"); ERR_print_errors(bio_err); goto end; } @@ -316,6 +329,7 @@ bad: { DSA *dsakey; + assert(need_rand); if ((dsakey=DSAparams_dup(dsa)) == NULL) goto end; if (!DSA_generate_key(dsakey)) goto end; if (outformat == FORMAT_ASN1) @@ -328,6 +342,8 @@ bad: } DSA_free(dsakey); } + if (need_rand) + app_RAND_write_file(NULL, bio_err); ret=0; end: if (in != NULL) BIO_free(in); @@ -336,7 +352,7 @@ end: EXIT(ret); } -static void MS_CALLBACK dsa_cb(int p, int n, char *arg) +static void MS_CALLBACK dsa_cb(int p, int n, void *arg) { char c='*'; @@ -344,8 +360,8 @@ static void MS_CALLBACK dsa_cb(int p, int n, char *arg) if (p == 1) c='+'; if (p == 2) c='*'; if (p == 3) c='\n'; - BIO_write((BIO *)arg,&c,1); - (void)BIO_flush((BIO *)arg); + BIO_write(arg,&c,1); + (void)BIO_flush(arg); #ifdef LINT p=n; #endif diff --git a/crypto/openssl/apps/enc.c b/crypto/openssl/apps/enc.c index bce936a..6531c58 100644 --- a/crypto/openssl/apps/enc.c +++ b/crypto/openssl/apps/enc.c @@ -65,6 +65,7 @@ #include <openssl/evp.h> #include <openssl/objects.h> #include <openssl/x509.h> +#include <openssl/rand.h> #ifndef NO_MD5 #include <openssl/md5.h> #endif @@ -79,17 +80,22 @@ int set_hex(char *in,unsigned char *out,int size); #define BSIZE (8*1024) #define PROG enc_main +int MAIN(int, char **); + int MAIN(int argc, char **argv) { + static const char magic[]="Salted__"; + char mbuf[8]; /* should be 1 smaller than magic */ char *strbuf=NULL; unsigned char *buff=NULL,*bufsize=NULL; int bsize=BSIZE,verbose=0; int ret=1,inl; unsigned char key[24],iv[MD5_DIGEST_LENGTH]; - char *str=NULL; - char *hkey=NULL,*hiv=NULL; + unsigned char salt[PKCS5_SALT_LEN]; + char *str=NULL, *passarg = NULL, *pass = NULL; + char *hkey=NULL,*hiv=NULL,*hsalt = NULL; int enc=1,printkey=0,i,base64=0; - int debug=0,olb64=0; + int debug=0,olb64=0,nosalt=0; const EVP_CIPHER *cipher=NULL,*c; char *inf=NULL,*outf=NULL; BIO *in=NULL,*out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL; @@ -130,14 +136,22 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; outf= *(++argv); } + else if (strcmp(*argv,"-pass") == 0) + { + if (--argc < 1) goto bad; + passarg= *(++argv); + } else if (strcmp(*argv,"-d") == 0) enc=0; else if (strcmp(*argv,"-p") == 0) printkey=1; else if (strcmp(*argv,"-v") == 0) verbose=1; - else if ((strcmp(*argv,"-debug") == 0) || - (strcmp(*argv,"-d") == 0)) + else if (strcmp(*argv,"-salt") == 0) + nosalt=0; + else if (strcmp(*argv,"-nosalt") == 0) + nosalt=1; + else if (strcmp(*argv,"-debug") == 0) debug=1; else if (strcmp(*argv,"-P") == 0) printkey=2; @@ -194,6 +208,11 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; hkey= *(++argv); } + else if (strcmp(*argv,"-S") == 0) + { + if (--argc < 1) goto bad; + hsalt= *(++argv); + } else if (strcmp(*argv,"-iv") == 0) { if (--argc < 1) goto bad; @@ -212,7 +231,8 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"options are\n"); BIO_printf(bio_err,"%-14s input file\n","-in <file>"); - BIO_printf(bio_err,"%-14s output fileencrypt\n","-out <file>"); + BIO_printf(bio_err,"%-14s output file\n","-out <file>"); + BIO_printf(bio_err,"%-14s pass phrase source\n","-pass <arg>"); BIO_printf(bio_err,"%-14s encrypt\n","-e"); BIO_printf(bio_err,"%-14s decrypt\n","-d"); BIO_printf(bio_err,"%-14s base64 encode/decode, depending on encryption flag\n","-a/-base64"); @@ -233,7 +253,7 @@ bad: BIO_printf(bio_err,"rc2 :128 bit key RC2 encryption\n"); #endif #ifndef NO_BF - BIO_printf(bio_err,"bf :128 bit key BlowFish encryption\n"); + BIO_printf(bio_err,"bf :128 bit key Blowfish encryption\n"); #endif #ifndef NO_RC4 BIO_printf(bio_err," -%-5s :128 bit key RC4 encryption\n", @@ -357,6 +377,14 @@ bad: } } + if(!str && passarg) { + if(!app_passwd(bio_err, passarg, NULL, &pass, NULL)) { + BIO_printf(bio_err, "Error getting password\n"); + goto end; + } + str = pass; + } + if ((str == NULL) && (cipher != NULL) && (hkey == NULL)) { for (;;) @@ -386,11 +414,83 @@ bad: } } + + if (outf == NULL) + BIO_set_fp(out,stdout,BIO_NOCLOSE); + else + { + if (BIO_write_filename(out,outf) <= 0) + { + perror(outf); + goto end; + } + } + + rbio=in; + wbio=out; + + if (base64) + { + if ((b64=BIO_new(BIO_f_base64())) == NULL) + goto end; + if (debug) + { + BIO_set_callback(b64,BIO_debug_callback); + BIO_set_callback_arg(b64,bio_err); + } + if (olb64) + BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); + if (enc) + wbio=BIO_push(b64,wbio); + else + rbio=BIO_push(b64,rbio); + } + if (cipher != NULL) { if (str != NULL) { - EVP_BytesToKey(cipher,EVP_md5(),NULL, + /* Salt handling: if encrypting generate a salt and + * write to output BIO. If decrypting read salt from + * input BIO. + */ + unsigned char *sptr; + if(nosalt) sptr = NULL; + else { + if(enc) { + if(hsalt) { + if(!set_hex(hsalt,salt,PKCS5_SALT_LEN)) { + BIO_printf(bio_err, + "invalid hex salt value\n"); + goto end; + } + } else if (RAND_pseudo_bytes(salt, PKCS5_SALT_LEN) < 0) + goto end; + /* If -P option then don't bother writing */ + if((printkey != 2) + && (BIO_write(wbio,magic, + sizeof magic-1) != sizeof magic-1 + || BIO_write(wbio, + (char *)salt, + PKCS5_SALT_LEN) != PKCS5_SALT_LEN)) { + BIO_printf(bio_err,"error writing output file\n"); + goto end; + } + } else if(BIO_read(rbio,mbuf,sizeof mbuf) != sizeof mbuf + || BIO_read(rbio, + (unsigned char *)salt, + PKCS5_SALT_LEN) != PKCS5_SALT_LEN) { + BIO_printf(bio_err,"error reading input file\n"); + goto end; + } else if(memcmp(mbuf,magic,sizeof magic-1)) { + BIO_printf(bio_err,"bad magic number\n"); + goto end; + } + + sptr = salt; + } + + EVP_BytesToKey(cipher,EVP_md5(),sptr, (unsigned char *)str, strlen(str),1,key,iv); /* zero the complete buffer or the string @@ -424,6 +524,13 @@ bad: if (printkey) { + if (!nosalt) + { + printf("salt="); + for (i=0; i<PKCS5_SALT_LEN; i++) + printf("%02X",salt[i]); + printf("\n"); + } if (cipher->key_len > 0) { printf("key="); @@ -446,38 +553,6 @@ bad: } } - - if (outf == NULL) - BIO_set_fp(out,stdout,BIO_NOCLOSE); - else - { - if (BIO_write_filename(out,outf) <= 0) - { - perror(outf); - goto end; - } - } - - rbio=in; - wbio=out; - - if (base64) - { - if ((b64=BIO_new(BIO_f_base64())) == NULL) - goto end; - if (debug) - { - BIO_set_callback(b64,BIO_debug_callback); - BIO_set_callback_arg(b64,bio_err); - } - if (olb64) - BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); - if (enc) - wbio=BIO_push(b64,wbio); - else - rbio=BIO_push(b64,rbio); - } - /* Only encrypt/decrypt as we write the file */ if (benc != NULL) wbio=BIO_push(benc,wbio); @@ -505,12 +580,14 @@ bad: BIO_printf(bio_err,"bytes written:%8ld\n",BIO_number_written(out)); } end: + ERR_print_errors(bio_err); if (strbuf != NULL) Free(strbuf); if (buff != NULL) Free(buff); if (in != NULL) BIO_free(in); if (out != NULL) BIO_free(out); if (benc != NULL) BIO_free(benc); if (b64 != NULL) BIO_free(b64); + if(pass) Free(pass); EXIT(ret); } diff --git a/crypto/openssl/apps/errstr.c b/crypto/openssl/apps/errstr.c index c86b5d9..4650379 100644 --- a/crypto/openssl/apps/errstr.c +++ b/crypto/openssl/apps/errstr.c @@ -68,6 +68,8 @@ #undef PROG #define PROG errstr_main +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int i,ret=0; diff --git a/crypto/openssl/apps/gendh.c b/crypto/openssl/apps/gendh.c index 3d50948..caf5e8d 100644 --- a/crypto/openssl/apps/gendh.c +++ b/crypto/openssl/apps/gendh.c @@ -1,4 +1,5 @@ /* apps/gendh.c */ +/* obsoleted by dhparam.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -75,15 +76,16 @@ #define PROG gendh_main static void MS_CALLBACK dh_cb(int p, int n, void *arg); -static long dh_load_rand(char *names); + +int MAIN(int, char **); + int MAIN(int argc, char **argv) { - char buffer[200]; DH *dh=NULL; int ret=1,num=DEFBITS; int g=2; char *outfile=NULL; - char *inrand=NULL,*randfile; + char *inrand=NULL; BIO *out=NULL; apps_startup(); @@ -126,7 +128,7 @@ bad: BIO_printf(bio_err," -2 use 2 as the generator value\n"); /* BIO_printf(bio_err," -3 use 3 as the generator value\n"); */ BIO_printf(bio_err," -5 use 5 as the generator value\n"); - BIO_printf(bio_err," -rand file:file:...\n"); + BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); BIO_printf(bio_err," the random number generator\n"); goto end; @@ -150,28 +152,21 @@ bad: } } - randfile=RAND_file_name(buffer,200); - if ((randfile == NULL)|| !RAND_load_file(randfile,1024L*1024L)) - BIO_printf(bio_err,"unable to load 'random state'\n"); - - if (inrand == NULL) - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - else + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { - BIO_printf(bio_err,"%ld semi-random bytes loaded\n", - dh_load_rand(inrand)); + BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); } + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); - BIO_printf(bio_err,"Generating DH parameters, %d bit long strong prime, generator of %d\n",num,g); + BIO_printf(bio_err,"Generating DH parameters, %d bit long safe prime, generator %d\n",num,g); BIO_printf(bio_err,"This is going to take a long time\n"); dh=DH_generate_parameters(num,g,dh_cb,bio_err); if (dh == NULL) goto end; - if (randfile == NULL) - BIO_printf(bio_err,"unable to write 'random state'\n"); - else - RAND_write_file(randfile); + app_RAND_write_file(NULL, bio_err); if (!PEM_write_bio_DHparams(out,dh)) goto end; @@ -198,26 +193,4 @@ static void MS_CALLBACK dh_cb(int p, int n, void *arg) p=n; #endif } - -static long dh_load_rand(char *name) - { - char *p,*n; - int last; - long tot=0; - - for (;;) - { - last=0; - for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); - if (*p == '\0') last=1; - *p='\0'; - n=name; - name=p+1; - if (*n == '\0') break; - - tot+=RAND_load_file(n,1); - if (last) break; - } - return(tot); - } #endif diff --git a/crypto/openssl/apps/gendsa.c b/crypto/openssl/apps/gendsa.c index 5f00b89..b1a1c4f 100644 --- a/crypto/openssl/apps/gendsa.c +++ b/crypto/openssl/apps/gendsa.c @@ -63,7 +63,6 @@ #include <sys/stat.h> #include "apps.h" #include <openssl/bio.h> -#include <openssl/rand.h> #include <openssl/err.h> #include <openssl/bn.h> #include <openssl/dsa.h> @@ -74,14 +73,15 @@ #undef PROG #define PROG gendsa_main -static long dsa_load_rand(char *names); +int MAIN(int, char **); + int MAIN(int argc, char **argv) { - char buffer[200]; DSA *dsa=NULL; int ret=1; char *outfile=NULL; - char *inrand=NULL,*randfile,*dsaparams=NULL; + char *inrand=NULL,*dsaparams=NULL; + char *passargout = NULL, *passout = NULL; BIO *out=NULL,*in=NULL; EVP_CIPHER *enc=NULL; @@ -101,6 +101,11 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; outfile= *(++argv); } + else if (strcmp(*argv,"-passout") == 0) + { + if (--argc < 1) goto bad; + passargout= *(++argv); + } else if (strcmp(*argv,"-rand") == 0) { if (--argc < 1) goto bad; @@ -140,7 +145,7 @@ bad: #ifndef NO_IDEA BIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\n"); #endif - BIO_printf(bio_err," -rand file:file:...\n"); + BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); BIO_printf(bio_err," the random number generator\n"); BIO_printf(bio_err," dsaparam-file\n"); @@ -148,6 +153,12 @@ bad: goto end; } + if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { + BIO_printf(bio_err, "Error getting password\n"); + goto end; + } + + in=BIO_new(BIO_s_file()); if (!(BIO_read_filename(in,dsaparams))) { @@ -161,6 +172,7 @@ bad: goto end; } BIO_free(in); + in = NULL; out=BIO_new(BIO_s_file()); if (out == NULL) goto end; @@ -176,57 +188,30 @@ bad: } } - randfile=RAND_file_name(buffer,200); - if ((randfile == NULL)|| !RAND_load_file(randfile,1024L*1024L)) - BIO_printf(bio_err,"unable to load 'random state'\n"); - - if (inrand == NULL) - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - else + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { - BIO_printf(bio_err,"%ld semi-random bytes loaded\n", - dsa_load_rand(inrand)); + BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); } + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); BIO_printf(bio_err,"Generating DSA key, %d bits\n", BN_num_bits(dsa->p)); if (!DSA_generate_key(dsa)) goto end; - if (randfile == NULL) - BIO_printf(bio_err,"unable to write 'random state'\n"); - else - RAND_write_file(randfile); + app_RAND_write_file(NULL, bio_err); - if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL,NULL)) + if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL, passout)) goto end; ret=0; end: if (ret != 0) ERR_print_errors(bio_err); + if (in != NULL) BIO_free(in); if (out != NULL) BIO_free(out); if (dsa != NULL) DSA_free(dsa); + if(passout) Free(passout); EXIT(ret); } - -static long dsa_load_rand(char *name) - { - char *p,*n; - int last; - long tot=0; - - for (;;) - { - last=0; - for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); - if (*p == '\0') last=1; - *p='\0'; - n=name; - name=p+1; - if (*n == '\0') break; - - tot+=RAND_load_file(n,1); - if (last) break; - } - return(tot); - } #endif diff --git a/crypto/openssl/apps/genrsa.c b/crypto/openssl/apps/genrsa.c index 6738206..6fe578d 100644 --- a/crypto/openssl/apps/genrsa.c +++ b/crypto/openssl/apps/genrsa.c @@ -63,7 +63,6 @@ #include <sys/stat.h> #include "apps.h" #include <openssl/bio.h> -#include <openssl/rand.h> #include <openssl/err.h> #include <openssl/bn.h> #include <openssl/rsa.h> @@ -76,18 +75,20 @@ #define PROG genrsa_main static void MS_CALLBACK genrsa_cb(int p, int n, void *arg); -static long gr_load_rand(char *names); + +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int ret=1; - char buffer[200]; RSA *rsa=NULL; int i,num=DEFBITS; - long rnum=0,l; + long l; EVP_CIPHER *enc=NULL; unsigned long f4=RSA_F4; char *outfile=NULL; - char *inrand=NULL,*randfile; + char *passargout = NULL, *passout = NULL; + char *inrand=NULL; BIO *out=NULL; apps_startup(); @@ -97,7 +98,7 @@ int MAIN(int argc, char **argv) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if ((out=BIO_new(BIO_s_file())) == NULL) { - BIO_printf(bio_err,"unable to creat BIO for output\n"); + BIO_printf(bio_err,"unable to create BIO for output\n"); goto err; } @@ -130,6 +131,11 @@ int MAIN(int argc, char **argv) else if (strcmp(*argv,"-idea") == 0) enc=EVP_idea_cbc(); #endif + else if (strcmp(*argv,"-passout") == 0) + { + if (--argc < 1) goto bad; + passargout= *(++argv); + } else break; argv++; @@ -139,21 +145,28 @@ int MAIN(int argc, char **argv) { bad: BIO_printf(bio_err,"usage: genrsa [args] [numbits]\n"); - BIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode\n"); - BIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); + BIO_printf(bio_err," -des encrypt the generated key with DES in cbc mode\n"); + BIO_printf(bio_err," -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); #ifndef NO_IDEA - BIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\n"); + BIO_printf(bio_err," -idea encrypt the generated key with IDEA in cbc mode\n"); #endif - BIO_printf(bio_err," -out file - output the key to 'file\n"); - BIO_printf(bio_err," -f4 - use F4 (0x10001) for the E value\n"); - BIO_printf(bio_err," -3 - use 3 for the E value\n"); - BIO_printf(bio_err," -rand file:file:...\n"); - BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); - BIO_printf(bio_err," the random number generator\n"); + BIO_printf(bio_err," -out file output the key to 'file\n"); + BIO_printf(bio_err," -passout arg output file pass phrase source\n"); + BIO_printf(bio_err," -f4 use F4 (0x10001) for the E value\n"); + BIO_printf(bio_err," -3 use 3 for the E value\n"); + BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err," load the file (or the files in the directory) into\n"); + BIO_printf(bio_err," the random number generator\n"); goto err; } ERR_load_crypto_strings(); + + if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { + BIO_printf(bio_err, "Error getting password\n"); + goto err; + } + if (outfile == NULL) BIO_set_fp(out,stdout,BIO_NOCLOSE); else @@ -165,45 +178,23 @@ bad: } } -#ifdef WINDOWS - BIO_printf(bio_err,"Loading 'screen' into random state -"); - BIO_flush(bio_err); - RAND_screen(); - BIO_printf(bio_err," done\n"); -#endif - randfile=RAND_file_name(buffer,200); - if ((randfile == NULL) || - !(rnum=(long)RAND_load_file(randfile,1024L*1024L))) + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { - BIO_printf(bio_err,"unable to load 'random state'\n"); + BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); } - - if (inrand == NULL) - { - if (rnum == 0) - { - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - } - } - else - { - rnum+=gr_load_rand(inrand); - } - if (rnum != 0) - BIO_printf(bio_err,"%ld semi-random bytes loaded\n",rnum); + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n", num); rsa=RSA_generate_key(num,f4,genrsa_cb,bio_err); - if (randfile == NULL) - BIO_printf(bio_err,"unable to write 'random state'\n"); - else - RAND_write_file(randfile); + app_RAND_write_file(NULL, bio_err); if (rsa == NULL) goto err; - /* We need to do the folloing for when the base number size is < + /* We need to do the following for when the base number size is < * long, esp windows 3.1 :-(. */ l=0L; for (i=0; i<rsa->e->top; i++) @@ -215,13 +206,14 @@ bad: l+=rsa->e->d[i]; } BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l); - if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL,NULL)) + if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL, passout)) goto err; ret=0; err: if (rsa != NULL) RSA_free(rsa); if (out != NULL) BIO_free(out); + if(passout) Free(passout); if (ret != 0) ERR_print_errors(bio_err); EXIT(ret); @@ -241,26 +233,10 @@ static void MS_CALLBACK genrsa_cb(int p, int n, void *arg) p=n; #endif } +#else /* !NO_RSA */ -static long gr_load_rand(char *name) - { - char *p,*n; - int last; - long tot=0; - - for (;;) - { - last=0; - for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); - if (*p == '\0') last=1; - *p='\0'; - n=name; - name=p+1; - if (*n == '\0') break; +# if PEDANTIC +static void *dummy=&dummy; +# endif - tot+=RAND_load_file(n,1024L*1024L); - if (last) break; - } - return(tot); - } #endif diff --git a/crypto/openssl/apps/nseq.c b/crypto/openssl/apps/nseq.c index d9d0165..cc88d50 100644 --- a/crypto/openssl/apps/nseq.c +++ b/crypto/openssl/apps/nseq.c @@ -65,7 +65,7 @@ #undef PROG #define PROG nseq_main -static int dump_cert_text(BIO *out, X509 *x); +int MAIN(int, char **); int MAIN(int argc, char **argv) { @@ -158,17 +158,3 @@ end: EXIT(ret); } -static int dump_cert_text(BIO *out, X509 *x) -{ - char buf[256]; - X509_NAME_oneline(X509_get_subject_name(x),buf,256); - BIO_puts(out,"subject="); - BIO_puts(out,buf); - - X509_NAME_oneline(X509_get_issuer_name(x),buf,256); - BIO_puts(out,"\nissuer= "); - BIO_puts(out,buf); - BIO_puts(out,"\n"); - return 0; -} - diff --git a/crypto/openssl/apps/openssl.c b/crypto/openssl/apps/openssl.c index 9a337fb..a2a2630 100644 --- a/crypto/openssl/apps/openssl.c +++ b/crypto/openssl/apps/openssl.c @@ -56,13 +56,10 @@ * [including the GNU Public Licence.] */ -#ifndef DEBUG -#undef DEBUG -#endif - #include <stdio.h> #include <string.h> #include <stdlib.h> +#define OPENSSL_C /* tells apps.h to use complete apps_startup() */ #include <openssl/bio.h> #include <openssl/crypto.h> #include <openssl/lhash.h> @@ -70,19 +67,12 @@ #include <openssl/x509.h> #include <openssl/pem.h> #include <openssl/ssl.h> -#define SSLEAY /* turn off a few special case MONOLITH macros */ #define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */ -#define SSLEAY_SRC #include "apps.h" +#include "progs.h" #include "s_apps.h" #include <openssl/err.h> -/* -#ifdef WINDOWS -#include "bss_file.c" -#endif -*/ - static unsigned long MS_CALLBACK hash(FUNCTION *a); static int MS_CALLBACK cmp(FUNCTION *a,FUNCTION *b); static LHASH *prog_init(void ); @@ -90,15 +80,6 @@ static int do_cmd(LHASH *prog,int argc,char *argv[]); LHASH *config=NULL; char *default_config_file=NULL; -#ifdef DEBUG -static void sig_stop(int i) - { - char *a=NULL; - - *a='\0'; - } -#endif - /* Make sure there is only one when MONOLITH is defined */ #ifdef MONOLITH BIO *bio_err=NULL; @@ -120,24 +101,14 @@ int main(int Argc, char *Argv[]) arg.data=NULL; arg.count=0; - /* SSLeay_add_ssl_algorithms(); is called in apps_startup() */ - apps_startup(); + CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); -#if defined(DEBUG) && !defined(WINDOWS) && !defined(MSDOS) -#ifdef SIGBUS - signal(SIGBUS,sig_stop); -#endif -#ifdef SIGSEGV - signal(SIGSEGV,sig_stop); -#endif -#endif + apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - ERR_load_crypto_strings(); /* Lets load up our environment a little */ @@ -165,7 +136,7 @@ int main(int Argc, char *Argv[]) program_name(Argv[0],pname,PROG_NAME_SIZE); f.name=pname; - fp=(FUNCTION *)lh_retrieve(prog,(char *)&f); + fp=(FUNCTION *)lh_retrieve(prog,&f); if (fp != NULL) { Argv[0]=pname; @@ -235,7 +206,7 @@ end: EVP_cleanup(); ERR_free_strings(); - + CRYPTO_mem_leaks(bio_err); if (bio_err != NULL) { @@ -257,11 +228,23 @@ static int do_cmd(LHASH *prog, int argc, char *argv[]) if ((argc <= 0) || (argv[0] == NULL)) { ret=0; goto end; } f.name=argv[0]; - fp=(FUNCTION *)lh_retrieve(prog,(char *)&f); + fp=(FUNCTION *)lh_retrieve(prog,&f); if (fp != NULL) { ret=fp->func(argc,argv); } + else if ((strncmp(argv[0],"no-",3)) == 0) + { + BIO *bio_stdout = BIO_new_fp(stdout,BIO_NOCLOSE); + f.name=argv[0]+3; + ret = (lh_retrieve(prog,&f) != NULL); + if (!ret) + BIO_printf(bio_stdout, "%s\n", argv[0]); + else + BIO_printf(bio_stdout, "%s\n", argv[0]+3); + BIO_free(bio_stdout); + goto end; + } else if ((strcmp(argv[0],"quit") == 0) || (strcmp(argv[0],"q") == 0) || (strcmp(argv[0],"exit") == 0) || @@ -356,7 +339,7 @@ static LHASH *prog_init(void) if ((ret=lh_new(hash,cmp)) == NULL) return(NULL); for (f=functions; f->name != NULL; f++) - lh_insert(ret,(char *)f); + lh_insert(ret,f); return(ret); } @@ -369,5 +352,3 @@ static unsigned long MS_CALLBACK hash(FUNCTION *a) { return(lh_strhash(a->name)); } - -#undef SSLEAY diff --git a/crypto/openssl/apps/openssl.cnf b/crypto/openssl/apps/openssl.cnf index d70dd25..dbe8cbe 100644 --- a/crypto/openssl/apps/openssl.cnf +++ b/crypto/openssl/apps/openssl.cnf @@ -3,8 +3,13 @@ # This is mostly being used for generation of certificate requests. # +# This definition stops the following lines choking if HOME isn't +# defined. +HOME = . RANDFILE = $ENV::HOME/.rnd -oid_file = $ENV::HOME/.oid + +# Extra OBJECT IDENTIFIER info: +#oid_file = $ENV::HOME/.oid oid_section = new_oids # To use this configuration file with the "-extfile" option of the @@ -86,6 +91,22 @@ distinguished_name = req_distinguished_name attributes = req_attributes x509_extensions = v3_ca # The extentions to add to the self signed cert +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString. +# utf8only: only UTF8Strings. +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings +# so use this option with caution! +string_mask = nombstr + +# req_extensions = v3_req # The extensions to add to a certificate request + [ req_distinguished_name ] countryName = Country Name (2 letter code) countryName_default = AU @@ -170,8 +191,16 @@ authorityKeyIdentifier=keyid,issuer:always #nsCaPolicyUrl #nsSslServerName +[ v3_req ] + +# Extensions to add to a certificate request + +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment + [ v3_ca ] + # Extensions for a typical CA @@ -200,10 +229,11 @@ basicConstraints = CA:true # Copy issuer details # issuerAltName=issuer:copy -# RAW DER hex encoding of an extension: beware experts only! -# 1.2.3.5=RAW:02:03 +# DER hex encoding of an extension: beware experts only! +# obj=DER:02:03 +# Where 'obj' is a standard or added object # You can even override a supported extension: -# basicConstraints= critical, RAW:30:03:01:01:FF +# basicConstraints= critical, DER:30:03:01:01:FF [ crl_ext ] diff --git a/crypto/openssl/apps/passwd.c b/crypto/openssl/apps/passwd.c new file mode 100644 index 0000000..c7e21d2 --- /dev/null +++ b/crypto/openssl/apps/passwd.c @@ -0,0 +1,475 @@ +/* apps/passwd.c */ + +#if defined NO_MD5 || defined CHARSET_EBCDIC +# define NO_APR1 +#endif + +#if !defined(NO_DES) || !defined(NO_APR1) + +#include <assert.h> +#include <string.h> + +#include "apps.h" + +#include <openssl/bio.h> +#include <openssl/err.h> +#include <openssl/evp.h> +#include <openssl/rand.h> + +#ifndef NO_DES +# include <openssl/des.h> +#endif +#ifndef NO_APR1 +# include <openssl/md5.h> +#endif + + +#undef PROG +#define PROG passwd_main + + +static unsigned const char cov_2char[64]={ + /* from crypto/des/fcrypt.c */ + 0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35, + 0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44, + 0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C, + 0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54, + 0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62, + 0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A, + 0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72, + 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A +}; + +static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, + char *passwd, BIO *out, int quiet, int table, int reverse, + size_t pw_maxlen, int usecrypt, int useapr1); + +/* -crypt - standard Unix password algorithm (default, only choice) + * -apr1 - MD5-based password algorithm + * -salt string - salt + * -in file - read passwords from file + * -stdin - read passwords from stdin + * -quiet - no warnings + * -table - format output as table + * -reverse - switch table columns + */ + +int MAIN(int, char **); + +int MAIN(int argc, char **argv) + { + int ret = 1; + char *infile = NULL; + int in_stdin = 0; + char *salt = NULL, *passwd = NULL, **passwds = NULL; + char *salt_malloc = NULL, *passwd_malloc = NULL; + int pw_source_defined = 0; + BIO *in = NULL, *out = NULL; + int i, badopt, opt_done; + int passed_salt = 0, quiet = 0, table = 0, reverse = 0; + int usecrypt = 0, useapr1 = 0; + size_t pw_maxlen = 0; + + apps_startup(); + + if (bio_err == NULL) + if ((bio_err=BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + out = BIO_new(BIO_s_file()); + if (out == NULL) + goto err; + BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); + + badopt = 0, opt_done = 0; + i = 0; + while (!badopt && !opt_done && argv[++i] != NULL) + { + if (strcmp(argv[i], "-crypt") == 0) + usecrypt = 1; + else if (strcmp(argv[i], "-apr1") == 0) + useapr1 = 1; + else if (strcmp(argv[i], "-salt") == 0) + { + if ((argv[i+1] != NULL) && (salt == NULL)) + { + passed_salt = 1; + salt = argv[++i]; + } + else + badopt = 1; + } + else if (strcmp(argv[i], "-in") == 0) + { + if ((argv[i+1] != NULL) && !pw_source_defined) + { + pw_source_defined = 1; + infile = argv[++i]; + } + else + badopt = 1; + } + else if (strcmp(argv[i], "-stdin") == 0) + { + if (!pw_source_defined) + { + pw_source_defined = 1; + in_stdin = 1; + } + else + badopt = 1; + } + else if (strcmp(argv[i], "-quiet") == 0) + quiet = 1; + else if (strcmp(argv[i], "-table") == 0) + table = 1; + else if (strcmp(argv[i], "-reverse") == 0) + reverse = 1; + else if (argv[i][0] == '-') + badopt = 1; + else if (!pw_source_defined) + /* non-option arguments, use as passwords */ + { + pw_source_defined = 1; + passwds = &argv[i]; + opt_done = 1; + } + else + badopt = 1; + } + + if (!usecrypt && !useapr1) /* use default */ + usecrypt = 1; + if (usecrypt + useapr1 > 1) /* conflict */ + badopt = 1; + + /* reject unsupported algorithms */ +#ifdef NO_DES + if (usecrypt) badopt = 1; +#endif +#ifdef NO_APR1 + if (useapr1) badopt = 1; +#endif + + if (badopt) + { + BIO_printf(bio_err, "Usage: passwd [options] [passwords]\n"); + BIO_printf(bio_err, "where options are\n"); +#ifndef NO_DES + BIO_printf(bio_err, "-crypt standard Unix password algorithm (default)\n"); +#endif +#ifndef NO_APR1 + BIO_printf(bio_err, "-apr1 MD5-based password algorithm\n"); +#endif + BIO_printf(bio_err, "-salt string use provided salt\n"); + BIO_printf(bio_err, "-in file read passwords from file\n"); + BIO_printf(bio_err, "-stdin read passwords from stdin\n"); + BIO_printf(bio_err, "-quiet no warnings\n"); + BIO_printf(bio_err, "-table format output as table\n"); + BIO_printf(bio_err, "-reverse switch table columns\n"); + + goto err; + } + + if ((infile != NULL) || in_stdin) + { + in = BIO_new(BIO_s_file()); + if (in == NULL) + goto err; + if (infile != NULL) + { + assert(in_stdin == 0); + if (BIO_read_filename(in, infile) <= 0) + goto err; + } + else + { + assert(in_stdin); + BIO_set_fp(in, stdin, BIO_NOCLOSE); + } + } + + if (usecrypt) + pw_maxlen = 8; + else if (useapr1) + pw_maxlen = 256; /* arbitrary limit, should be enough for most passwords */ + + if (passwds == NULL) + { + /* no passwords on the command line */ + passwd = passwd_malloc = Malloc(pw_maxlen + 1); + if (passwd_malloc == NULL) + goto err; + } + + if ((in == NULL) && (passwds == NULL)) + { + /* build a null-terminated list */ + static char *passwds_static[2] = {NULL, NULL}; + + passwds = passwds_static; + if (in == NULL) + if (EVP_read_pw_string(passwd_malloc, pw_maxlen + 1, "Password: ", 0) != 0) + goto err; + passwds[0] = passwd_malloc; + } + + if (in == NULL) + { + assert(passwds != NULL); + assert(*passwds != NULL); + + do /* loop over list of passwords */ + { + passwd = *passwds++; + if (!do_passwd(passed_salt, &salt, &salt_malloc, passwd, out, + quiet, table, reverse, pw_maxlen, usecrypt, useapr1)) + goto err; + } + while (*passwds != NULL); + } + else + /* in != NULL */ + { + int done; + + assert (passwd != NULL); + do + { + int r = BIO_gets(in, passwd, pw_maxlen + 1); + if (r > 0) + { + char *c = (strchr(passwd, '\n')) ; + if (c != NULL) + *c = 0; /* truncate at newline */ + else + { + /* ignore rest of line */ + char trash[BUFSIZ]; + do + r = BIO_gets(in, trash, sizeof trash); + while ((r > 0) && (!strchr(trash, '\n'))); + } + + if (!do_passwd(passed_salt, &salt, &salt_malloc, passwd, out, + quiet, table, reverse, pw_maxlen, usecrypt, useapr1)) + goto err; + } + done = (r <= 0); + } + while (!done); + } + +err: + ERR_print_errors(bio_err); + if (salt_malloc) + Free(salt_malloc); + if (passwd_malloc) + Free(passwd_malloc); + if (in) + BIO_free(in); + if (out) + BIO_free(out); + EXIT(ret); + } + + +#ifndef NO_APR1 +/* MD5-based password algorithm compatible to the one found in Apache + * (should probably be available as a library function; + * then the static buffer would not be acceptable) */ +static char *apr1_crypt(const char *passwd, const char *salt) + { + static char out_buf[6 + 9 + 24 + 2]; /* "$apr1$..salt..$.......md5hash..........\0" */ + unsigned char buf[MD5_DIGEST_LENGTH]; + char *salt_out; + int n, i; + MD5_CTX md; + size_t passwd_len, salt_len; + + passwd_len = strlen(passwd); + strcpy(out_buf, "$apr1$"); + strncat(out_buf, salt, 8); + assert(strlen(out_buf) <= 6 + 8); /* "$apr1$..salt.." */ + salt_out = out_buf + 6; + salt_len = strlen(salt_out); + assert(salt_len <= 8); + + MD5_Init(&md); + MD5_Update(&md, passwd, passwd_len); + MD5_Update(&md, "$apr1$", 6); + MD5_Update(&md, salt_out, salt_len); + + { + MD5_CTX md2; + + MD5_Init(&md2); + MD5_Update(&md2, passwd, passwd_len); + MD5_Update(&md2, salt_out, salt_len); + MD5_Update(&md2, passwd, passwd_len); + MD5_Final(buf, &md2); + } + for (i = passwd_len; i > sizeof buf; i -= sizeof buf) + MD5_Update(&md, buf, sizeof buf); + MD5_Update(&md, buf, i); + + n = passwd_len; + while (n) + { + MD5_Update(&md, (n & 1) ? "\0" : passwd, 1); + n >>= 1; + } + MD5_Final(buf, &md); + + for (i = 0; i < 1000; i++) + { + MD5_CTX md2; + + MD5_Init(&md2); + MD5_Update(&md2, (i & 1) ? (unsigned char *) passwd : buf, + (i & 1) ? passwd_len : sizeof buf); + if (i % 3) + MD5_Update(&md2, salt_out, salt_len); + if (i % 7) + MD5_Update(&md2, passwd, passwd_len); + MD5_Update(&md2, (i & 1) ? buf : (unsigned char *) passwd, + (i & 1) ? sizeof buf : passwd_len); + MD5_Final(buf, &md2); + } + + { + /* transform buf into output string */ + + unsigned char buf_perm[sizeof buf]; + int dest, source; + char *output; + + /* silly output permutation */ + for (dest = 0, source = 0; dest < 14; dest++, source = (source + 6) % 17) + buf_perm[dest] = buf[source]; + buf_perm[14] = buf[5]; + buf_perm[15] = buf[11]; +#ifndef PEDANTIC /* Unfortunately, this generates a "no effect" warning */ + assert(16 == sizeof buf_perm); +#endif + + output = salt_out + salt_len; + assert(output == out_buf + strlen(out_buf)); + + *output++ = '$'; + + for (i = 0; i < 15; i += 3) + { + *output++ = cov_2char[buf_perm[i+2] & 0x3f]; + *output++ = cov_2char[((buf_perm[i+1] & 0xf) << 2) | + (buf_perm[i+2] >> 6)]; + *output++ = cov_2char[((buf_perm[i] & 3) << 4) | + (buf_perm[i+1] >> 4)]; + *output++ = cov_2char[buf_perm[i] >> 2]; + } + assert(i == 15); + *output++ = cov_2char[buf_perm[i] & 0x3f]; + *output++ = cov_2char[buf_perm[i] >> 6]; + *output = 0; + assert(strlen(out_buf) < sizeof(out_buf)); + } + + return out_buf; + } +#endif + + +static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, + char *passwd, BIO *out, int quiet, int table, int reverse, + size_t pw_maxlen, int usecrypt, int useapr1) + { + char *hash = NULL; + + assert(salt_p != NULL); + assert(salt_malloc_p != NULL); + + /* first make sure we have a salt */ + if (!passed_salt) + { +#ifndef NO_DES + if (usecrypt) + { + if (*salt_malloc_p == NULL) + { + *salt_p = *salt_malloc_p = Malloc(3); + if (*salt_malloc_p == NULL) + goto err; + } + if (RAND_pseudo_bytes((unsigned char *)*salt_p, 2) < 0) + goto err; + (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f]; /* 6 bits */ + (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f]; /* 6 bits */ + (*salt_p)[2] = 0; +#ifdef CHARSET_EBCDIC + ascii2ebcdic(*salt_p, *salt_p, 2); /* des_crypt will convert + * back to ASCII */ +#endif + } +#endif /* !NO_DES */ + +#ifndef NO_APR1 + if (useapr1) + { + int i; + + if (*salt_malloc_p == NULL) + { + *salt_p = *salt_malloc_p = Malloc(9); + if (*salt_malloc_p == NULL) + goto err; + } + if (RAND_pseudo_bytes((unsigned char *)*salt_p, 8) < 0) + goto err; + + for (i = 0; i < 8; i++) + (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f]; /* 6 bits */ + (*salt_p)[8] = 0; + } +#endif /* !NO_APR1 */ + } + + assert(*salt_p != NULL); + + /* truncate password if necessary */ + if ((strlen(passwd) > pw_maxlen)) + { + if (!quiet) + BIO_printf(bio_err, "Warning: truncating password to %u characters\n", pw_maxlen); + passwd[pw_maxlen] = 0; + } + assert(strlen(passwd) <= pw_maxlen); + + /* now compute password hash */ +#ifndef NO_DES + if (usecrypt) + hash = des_crypt(passwd, *salt_p); +#endif +#ifndef NO_APR1 + if (useapr1) + hash = apr1_crypt(passwd, *salt_p); +#endif + assert(hash != NULL); + + if (table && !reverse) + BIO_printf(out, "%s\t%s\n", passwd, hash); + else if (table && reverse) + BIO_printf(out, "%s\t%s\n", hash, passwd); + else + BIO_printf(out, "%s\n", hash); + return 1; + +err: + return 0; + } +#else + +int MAIN(int argc, char **argv) + { + fputs("Program not available.\n", stderr) + EXIT(1); + } +#endif diff --git a/crypto/openssl/apps/pkcs12.c b/crypto/openssl/apps/pkcs12.c index 5defdde..bf76864 100644 --- a/crypto/openssl/apps/pkcs12.c +++ b/crypto/openssl/apps/pkcs12.c @@ -61,12 +61,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <openssl/des.h> -#include <openssl/pem.h> +#include "apps.h" +#include <openssl/crypto.h> #include <openssl/err.h> +#include <openssl/pem.h> #include <openssl/pkcs12.h> -#include "apps.h" #define PROG pkcs12_main EVP_CIPHER *enc; @@ -79,14 +79,16 @@ EVP_CIPHER *enc; #define CACERTS 0x10 int get_cert_chain(X509 *cert, STACK_OF(X509) **chain); -int dump_cert_text (BIO *out, X509 *x); -int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int passlen, int options); -int dump_certs_pkeys_bags(BIO *out, STACK *bags, char *pass, int passlen, int options); -int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bags, char *pass, int passlen, int options); +int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int passlen, int options, char *pempass); +int dump_certs_pkeys_bags(BIO *out, STACK *bags, char *pass, int passlen, int options, char *pempass); +int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bags, char *pass, int passlen, int options, char *pempass); int print_attribs(BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst, char *name); void hex_prin(BIO *out, unsigned char *buf, int len); int alg_print(BIO *x, X509_ALGOR *alg); int cert_load(BIO *in, STACK_OF(X509) *sk); + +int MAIN(int, char **); + int MAIN(int argc, char **argv) { char *infile=NULL, *outfile=NULL, *keyname = NULL; @@ -101,15 +103,19 @@ int MAIN(int argc, char **argv) int chain = 0; int badarg = 0; int iter = PKCS12_DEFAULT_ITER; - int maciter = 1; + int maciter = PKCS12_DEFAULT_ITER; int twopass = 0; int keytype = 0; int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC; + int key_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC; int ret = 1; int macver = 1; int noprompt = 0; STACK *canames = NULL; char *cpass = NULL, *mpass = NULL; + char *passargin = NULL, *passargout = NULL, *passarg = NULL; + char *passin = NULL, *passout = NULL; + char *inrand = NULL; apps_startup(); @@ -143,8 +149,35 @@ int MAIN(int argc, char **argv) else if (!strcmp (*args, "-noiter")) iter = 1; else if (!strcmp (*args, "-maciter")) maciter = PKCS12_DEFAULT_ITER; + else if (!strcmp (*args, "-nomaciter")) + maciter = 1; else if (!strcmp (*args, "-nodes")) enc=NULL; - else if (!strcmp (*args, "-inkey")) { + else if (!strcmp (*args, "-certpbe")) { + if (args[1]) { + args++; + cert_pbe=OBJ_txt2nid(*args); + if(cert_pbe == NID_undef) { + BIO_printf(bio_err, + "Unknown PBE algorithm %s\n", *args); + badarg = 1; + } + } else badarg = 1; + } else if (!strcmp (*args, "-keypbe")) { + if (args[1]) { + args++; + key_pbe=OBJ_txt2nid(*args); + if(key_pbe == NID_undef) { + BIO_printf(bio_err, + "Unknown PBE algorithm %s\n", *args); + badarg = 1; + } + } else badarg = 1; + } else if (!strcmp (*args, "-rand")) { + if (args[1]) { + args++; + inrand = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-inkey")) { if (args[1]) { args++; keyname = *args; @@ -175,20 +208,20 @@ int MAIN(int argc, char **argv) args++; outfile = *args; } else badarg = 1; - } else if (!strcmp (*args, "-envpass")) { + } else if (!strcmp(*args,"-passin")) { if (args[1]) { args++; - if(!(cpass = getenv(*args))) { - BIO_printf(bio_err, - "Can't read environment variable %s\n", *args); - goto end; - } - noprompt = 1; + passargin = *args; + } else badarg = 1; + } else if (!strcmp(*args,"-passout")) { + if (args[1]) { + args++; + passargout = *args; } else badarg = 1; } else if (!strcmp (*args, "-password")) { if (args[1]) { args++; - cpass = *args; + passarg = *args; noprompt = 1; } else badarg = 1; } else badarg = 1; @@ -225,21 +258,54 @@ int MAIN(int argc, char **argv) BIO_printf (bio_err, "-maciter use MAC iteration\n"); BIO_printf (bio_err, "-twopass separate MAC, encryption passwords\n"); BIO_printf (bio_err, "-descert encrypt PKCS#12 certificates with triple DES (default RC2-40)\n"); + BIO_printf (bio_err, "-certpbe alg specify certificate PBE algorithm (default RC2-40)\n"); + BIO_printf (bio_err, "-keypbe alg specify private key PBE algorithm (default 3DES)\n"); BIO_printf (bio_err, "-keyex set MS key exchange type\n"); BIO_printf (bio_err, "-keysig set MS key signature type\n"); - BIO_printf (bio_err, "-password p set import/export password (NOT RECOMMENDED)\n"); - BIO_printf (bio_err, "-envpass p set import/export password from environment\n"); + BIO_printf (bio_err, "-password p set import/export password source\n"); + BIO_printf (bio_err, "-passin p input file pass phrase source\n"); + BIO_printf (bio_err, "-passout p output file pass phrase source\n"); + BIO_printf(bio_err, "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err, " load the file (or the files in the directory) into\n"); + BIO_printf(bio_err, " the random number generator\n"); goto end; } - if(cpass) mpass = cpass; - else { + if(passarg) { + if(export_cert) passargout = passarg; + else passargin = passarg; + } + + if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { + BIO_printf(bio_err, "Error getting passwords\n"); + goto end; + } + + if(!cpass) { + if(export_cert) cpass = passout; + else cpass = passin; + } + + if(cpass) { + mpass = cpass; + noprompt = 1; + } else { cpass = pass; mpass = macpass; } + if(export_cert || inrand) { + app_RAND_load_file(NULL, bio_err, (inrand != NULL)); + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); + } ERR_load_crypto_strings(); +#ifdef CRYPTO_MDEBUG + CRYPTO_push_info("read files"); +#endif + if (!infile) in = BIO_new_fp(stdin, BIO_NOCLOSE); else in = BIO_new_file(infile, "rb"); if (!in) { @@ -265,6 +331,11 @@ int MAIN(int argc, char **argv) } } +#ifdef CRYPTO_MDEBUG + CRYPTO_pop_info(); + CRYPTO_push_info("write files"); +#endif + if (!outfile) out = BIO_new_fp(stdout, BIO_NOCLOSE); else out = BIO_new_file(outfile, "wb"); if (!out) { @@ -274,27 +345,38 @@ int MAIN(int argc, char **argv) goto end; } if (twopass) { +#ifdef CRYPTO_MDEBUG + CRYPTO_push_info("read MAC password"); +#endif if(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert)) { BIO_printf (bio_err, "Can't read Password\n"); goto end; } +#ifdef CRYPTO_MDEBUG + CRYPTO_pop_info(); +#endif } -if (export_cert) { + if (export_cert) { EVP_PKEY *key; STACK *bags, *safes; PKCS12_SAFEBAG *bag; PKCS8_PRIV_KEY_INFO *p8; PKCS7 *authsafe; - X509 *cert = NULL, *ucert = NULL; - STACK_OF(X509) *certs; + X509 *ucert = NULL; + STACK_OF(X509) *certs=NULL; char *catmp; int i; unsigned char keyid[EVP_MAX_MD_SIZE]; unsigned int keyidlen = 0; - key = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL, NULL); + +#ifdef CRYPTO_MDEBUG + CRYPTO_push_info("process -export_cert"); +#endif + key = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL, passin); if (!inkey) (void) BIO_reset(in); + else BIO_free(inkey); if (!key) { BIO_printf (bio_err, "Error loading private key\n"); ERR_print_errors(bio_err); @@ -313,7 +395,7 @@ if (export_cert) { for(i = 0; i < sk_X509_num(certs); i++) { ucert = sk_X509_value(certs, i); if(X509_check_private_key(ucert, key)) { - X509_digest(cert, EVP_sha1(), keyid, &keyidlen); + X509_digest(ucert, EVP_sha1(), keyid, &keyidlen); break; } } @@ -354,6 +436,7 @@ if (export_cert) { /* We now have loads of certificates: include them all */ for(i = 0; i < sk_X509_num(certs); i++) { + X509 *cert = NULL; cert = sk_X509_value(certs, i); bag = M_PKCS12_x5092certbag(cert); /* If it matches private key set id */ @@ -364,7 +447,7 @@ if (export_cert) { PKCS12_add_friendlyname(bag, catmp, -1); sk_push(bags, (char *)bag); } - + sk_X509_pop_free(certs, X509_free); if (canames) sk_free(canames); if(!noprompt && @@ -390,8 +473,7 @@ if (export_cert) { p8 = EVP_PKEY2PKCS8 (key); EVP_PKEY_free(key); if(keytype) PKCS8_add_keyusage(p8, keytype); - bag = PKCS12_MAKE_SHKEYBAG(NID_pbe_WithSHA1And3_Key_TripleDES_CBC, - cpass, -1, NULL, 0, iter, p8); + bag = PKCS12_MAKE_SHKEYBAG(key_pbe, cpass, -1, NULL, 0, iter, p8); PKCS8_PRIV_KEY_INFO_free(p8); if (name) PKCS12_add_friendlyname (bag, name, -1); PKCS12_add_localkeyid (bag, keyid, keyidlen); @@ -415,6 +497,10 @@ if (export_cert) { PKCS12_free(p12); ret = 0; + +#ifdef CRYPTO_MDEBUG + CRYPTO_pop_info(); +#endif goto end; } @@ -424,50 +510,61 @@ if (export_cert) { goto end; } +#ifdef CRYPTO_MDEBUG + CRYPTO_push_info("read import password"); +#endif if(!noprompt && EVP_read_pw_string(pass, 50, "Enter Import Password:", 0)) { BIO_printf (bio_err, "Can't read Password\n"); goto end; } +#ifdef CRYPTO_MDEBUG + CRYPTO_pop_info(); +#endif if (!twopass) strcpy(macpass, pass); if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1); if(macver) { +#ifdef CRYPTO_MDEBUG + CRYPTO_push_info("verify MAC"); +#endif if (!PKCS12_verify_mac (p12, mpass, -1)) { - BIO_printf (bio_err, "Mac verify errror: invalid password?\n"); + BIO_printf (bio_err, "Mac verify error: invalid password?\n"); ERR_print_errors (bio_err); goto end; } else BIO_printf (bio_err, "MAC verified OK\n"); +#ifdef CRYPTO_MDEBUG + CRYPTO_pop_info(); +#endif } - if (!dump_certs_keys_p12 (out, p12, cpass, -1, options)) { +#ifdef CRYPTO_MDEBUG + CRYPTO_push_info("output keys and certificates"); +#endif + if (!dump_certs_keys_p12 (out, p12, cpass, -1, options, passout)) { BIO_printf(bio_err, "Error outputting keys and certificates\n"); ERR_print_errors (bio_err); goto end; } +#ifdef CRYPTO_MDEBUG + CRYPTO_pop_info(); +#endif PKCS12_free(p12); ret = 0; end: + if(export_cert || inrand) app_RAND_write_file(NULL, bio_err); +#ifdef CRYPTO_MDEBUG + CRYPTO_remove_all_info(); +#endif + BIO_free(in); BIO_free(out); + if(passin) Free(passin); + if(passout) Free(passout); EXIT(ret); } -int dump_cert_text (BIO *out, X509 *x) -{ - char buf[256]; - X509_NAME_oneline(X509_get_subject_name(x),buf,256); - BIO_puts(out,"subject="); - BIO_puts(out,buf); - - X509_NAME_oneline(X509_get_issuer_name(x),buf,256); - BIO_puts(out,"\nissuer= "); - BIO_puts(out,buf); - BIO_puts(out,"\n"); - return 0; -} - int dump_certs_keys_p12 (BIO *out, PKCS12 *p12, char *pass, - int passlen, int options) + int passlen, int options, char *pempass) { STACK *asafes, *bags; int i, bagnid; @@ -489,7 +586,7 @@ int dump_certs_keys_p12 (BIO *out, PKCS12 *p12, char *pass, } else continue; if (!bags) return 0; if (!dump_certs_pkeys_bags (out, bags, pass, passlen, - options)) { + options, pempass)) { sk_pop_free (bags, PKCS12_SAFEBAG_free); return 0; } @@ -500,19 +597,19 @@ int dump_certs_keys_p12 (BIO *out, PKCS12 *p12, char *pass, } int dump_certs_pkeys_bags (BIO *out, STACK *bags, char *pass, - int passlen, int options) + int passlen, int options, char *pempass) { int i; for (i = 0; i < sk_num (bags); i++) { if (!dump_certs_pkeys_bag (out, (PKCS12_SAFEBAG *)sk_value (bags, i), pass, passlen, - options)) return 0; + options, pempass)) return 0; } return 1; } int dump_certs_pkeys_bag (BIO *out, PKCS12_SAFEBAG *bag, char *pass, - int passlen, int options) + int passlen, int options, char *pempass) { EVP_PKEY *pkey; PKCS8_PRIV_KEY_INFO *p8; @@ -527,7 +624,7 @@ int dump_certs_pkeys_bag (BIO *out, PKCS12_SAFEBAG *bag, char *pass, p8 = bag->value.keybag; if (!(pkey = EVP_PKCS82PKEY (p8))) return 0; print_attribs (out, p8->attributes, "Key Attributes"); - PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, NULL); + PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, pempass); EVP_PKEY_free(pkey); break; @@ -543,7 +640,7 @@ int dump_certs_pkeys_bag (BIO *out, PKCS12_SAFEBAG *bag, char *pass, if (!(pkey = EVP_PKCS82PKEY (p8))) return 0; print_attribs (out, p8->attributes, "Key Attributes"); PKCS8_PRIV_KEY_INFO_free(p8); - PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, NULL); + PEM_write_bio_PrivateKey (out, pkey, enc, NULL, 0, NULL, pempass); EVP_PKEY_free(pkey); break; @@ -566,7 +663,7 @@ int dump_certs_pkeys_bag (BIO *out, PKCS12_SAFEBAG *bag, char *pass, if (options & INFO) BIO_printf (bio_err, "Safe Contents bag\n"); print_attribs (out, bag->attrib, "Bag Attributes"); return dump_certs_pkeys_bags (out, bag->value.safes, pass, - passlen, options); + passlen, options, pempass); default: BIO_printf (bio_err, "Warning unsupported bag type: "); @@ -588,7 +685,7 @@ int get_cert_chain (X509 *cert, STACK_OF(X509) **chain) X509_STORE_CTX store_ctx; STACK_OF(X509) *chn; int i; - X509 *x; + store = X509_STORE_new (); X509_STORE_set_default_paths (store); X509_STORE_CTX_init(&store_ctx, store, cert, NULL); @@ -596,11 +693,7 @@ int get_cert_chain (X509 *cert, STACK_OF(X509) **chain) i = X509_STORE_CTX_get_error (&store_ctx); goto err; } - chn = sk_X509_dup(X509_STORE_CTX_get_chain (&store_ctx)); - for (i = 0; i < sk_X509_num(chn); i++) { - x = sk_X509_value(chn, i); - CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); - } + chn = X509_STORE_CTX_get1_chain(&store_ctx); i = 0; *chain = chn; err: diff --git a/crypto/openssl/apps/pkcs7.c b/crypto/openssl/apps/pkcs7.c index 0e1427c..f471cc7 100644 --- a/crypto/openssl/apps/pkcs7.c +++ b/crypto/openssl/apps/pkcs7.c @@ -71,27 +71,23 @@ #undef PROG #define PROG pkcs7_main -/* -inform arg - input format - default PEM (one of DER, TXT or PEM) +/* -inform arg - input format - default PEM (DER or PEM) * -outform arg - output format - default PEM * -in arg - input file - default stdin * -out arg - output file - default stdout - * -des - encrypt output if PEM format with DES in cbc mode - * -des3 - encrypt output if PEM format - * -idea - encrypt output if PEM format * -print_certs */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { PKCS7 *p7=NULL; int i,badops=0; -#if !defined(NO_DES) || !defined(NO_IDEA) - EVP_CIPHER *enc=NULL; -#endif BIO *in=NULL,*out=NULL; int informat,outformat; - char *infile,*outfile,*prog,buf[256]; - int print_certs=0; + char *infile,*outfile,*prog; + int print_certs=0,text=0,noout=0; int ret=0; apps_startup(); @@ -130,18 +126,12 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; outfile= *(++argv); } + else if (strcmp(*argv,"-noout") == 0) + noout=1; + else if (strcmp(*argv,"-text") == 0) + text=1; else if (strcmp(*argv,"-print_certs") == 0) print_certs=1; -#ifndef NO_DES - else if (strcmp(*argv,"-des") == 0) - enc=EVP_des_cbc(); - else if (strcmp(*argv,"-des3") == 0) - enc=EVP_des_ede3_cbc(); -#endif -#ifndef NO_IDEA - else if (strcmp(*argv,"-idea") == 0) - enc=EVP_idea_cbc(); -#endif else { BIO_printf(bio_err,"unknown option %s\n",*argv); @@ -157,16 +147,13 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n"); + BIO_printf(bio_err," -inform arg input format - DER or PEM\n"); + BIO_printf(bio_err," -outform arg output format - DER or PEM\n"); BIO_printf(bio_err," -in arg input file\n"); BIO_printf(bio_err," -out arg output file\n"); BIO_printf(bio_err," -print_certs print any certs or crl in the input\n"); - BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); - BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); -#ifndef NO_IDEA - BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); -#endif + BIO_printf(bio_err," -text print full details of certificates\n"); + BIO_printf(bio_err," -noout don't output encoded data\n"); EXIT(1); } @@ -246,19 +233,10 @@ bad: for (i=0; i<sk_X509_num(certs); i++) { x=sk_X509_value(certs,i); + if(text) X509_print(out, x); + else dump_cert_text(out, x); - X509_NAME_oneline(X509_get_subject_name(x), - buf,256); - BIO_puts(out,"subject="); - BIO_puts(out,buf); - - X509_NAME_oneline(X509_get_issuer_name(x), - buf,256); - BIO_puts(out,"\nissuer= "); - BIO_puts(out,buf); - BIO_puts(out,"\n"); - - PEM_write_bio_X509(out,x); + if(!noout) PEM_write_bio_X509(out,x); BIO_puts(out,"\n"); } } @@ -270,17 +248,9 @@ bad: { crl=sk_X509_CRL_value(crls,i); - X509_NAME_oneline(crl->crl->issuer,buf,256); - BIO_puts(out,"issuer= "); - BIO_puts(out,buf); + X509_CRL_print(out, crl); - BIO_puts(out,"\nlast update="); - ASN1_TIME_print(out,crl->crl->lastUpdate); - BIO_puts(out,"\nnext update="); - ASN1_TIME_print(out,crl->crl->nextUpdate); - BIO_puts(out,"\n"); - - PEM_write_bio_X509_CRL(out,crl); + if(!noout)PEM_write_bio_X509_CRL(out,crl); BIO_puts(out,"\n"); } } @@ -289,21 +259,23 @@ bad: goto end; } - if (outformat == FORMAT_ASN1) - i=i2d_PKCS7_bio(out,p7); - else if (outformat == FORMAT_PEM) - i=PEM_write_bio_PKCS7(out,p7); - else { - BIO_printf(bio_err,"bad output format specified for outfile\n"); - goto end; - } + if(!noout) { + if (outformat == FORMAT_ASN1) + i=i2d_PKCS7_bio(out,p7); + else if (outformat == FORMAT_PEM) + i=PEM_write_bio_PKCS7(out,p7); + else { + BIO_printf(bio_err,"bad output format specified for outfile\n"); + goto end; + } - if (!i) - { - BIO_printf(bio_err,"unable to write pkcs7 object\n"); - ERR_print_errors(bio_err); - goto end; - } + if (!i) + { + BIO_printf(bio_err,"unable to write pkcs7 object\n"); + ERR_print_errors(bio_err); + goto end; + } + } ret=0; end: if (p7 != NULL) PKCS7_free(p7); diff --git a/crypto/openssl/apps/pkcs8.c b/crypto/openssl/apps/pkcs8.c index a053883..3e59b74 100644 --- a/crypto/openssl/apps/pkcs8.c +++ b/crypto/openssl/apps/pkcs8.c @@ -57,6 +57,7 @@ */ #include <stdio.h> #include <string.h> +#include "apps.h" #include <openssl/pem.h> #include <openssl/err.h> #include <openssl/evp.h> @@ -65,10 +66,12 @@ #include "apps.h" #define PROG pkcs8_main +int MAIN(int, char **); int MAIN(int argc, char **argv) { char **args, *infile = NULL, *outfile = NULL; + char *passargin = NULL, *passargout = NULL; BIO *in = NULL, *out = NULL; int topk8 = 0; int pbe_nid = -1; @@ -80,13 +83,13 @@ int MAIN(int argc, char **argv) X509_SIG *p8; PKCS8_PRIV_KEY_INFO *p8inf; EVP_PKEY *pkey; - char pass[50]; + char pass[50], *passin = NULL, *passout = NULL, *p8pass = NULL; int badarg = 0; if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE); informat=FORMAT_PEM; outformat=FORMAT_PEM; ERR_load_crypto_strings(); - SSLeay_add_all_algorithms(); + OpenSSL_add_all_algorithms(); args = argv + 1; while (!badarg && *args && *args[0] == '-') { if (!strcmp(*args,"-v2")) { @@ -99,6 +102,16 @@ int MAIN(int argc, char **argv) badarg = 1; } } else badarg = 1; + } else if (!strcmp(*args,"-v1")) { + if (args[1]) { + args++; + pbe_nid=OBJ_txt2nid(*args); + if(pbe_nid == NID_undef) { + BIO_printf(bio_err, + "Unknown PBE algorithm %s\n", *args); + badarg = 1; + } + } else badarg = 1; } else if (!strcmp(*args,"-inform")) { if (args[1]) { args++; @@ -113,6 +126,18 @@ int MAIN(int argc, char **argv) else if (!strcmp (*args, "-noiter")) iter = 1; else if (!strcmp (*args, "-nocrypt")) nocrypt = 1; else if (!strcmp (*args, "-nooct")) p8_broken = PKCS8_NO_OCTET; + else if (!strcmp (*args, "-nsdb")) p8_broken = PKCS8_NS_DB; + else if (!strcmp (*args, "-embed")) p8_broken = PKCS8_EMBEDDED_PARAM; + else if (!strcmp(*args,"-passin")) + { + if (!args[1]) goto bad; + passargin= *(++args); + } + else if (!strcmp(*args,"-passout")) + { + if (!args[1]) goto bad; + passargout= *(++args); + } else if (!strcmp (*args, "-in")) { if (args[1]) { args++; @@ -128,25 +153,36 @@ int MAIN(int argc, char **argv) } if (badarg) { - BIO_printf (bio_err, "Usage pkcs8 [options]\n"); - BIO_printf (bio_err, "where options are\n"); - BIO_printf (bio_err, "-in file input file\n"); - BIO_printf (bio_err, "-inform X input format (DER or PEM)\n"); - BIO_printf (bio_err, "-outform X output format (DER or PEM)\n"); - BIO_printf (bio_err, "-out file output file\n"); - BIO_printf (bio_err, "-topk8 output PKCS8 file\n"); - BIO_printf (bio_err, "-nooct use (broken) no octet form\n"); - BIO_printf (bio_err, "-noiter use 1 as iteration count\n"); - BIO_printf (bio_err, "-nocrypt use or expect unencrypted private key\n"); - BIO_printf (bio_err, "-v2 alg use PKCS#5 v2.0 and cipher \"alg\"\n"); + bad: + BIO_printf(bio_err, "Usage pkcs8 [options]\n"); + BIO_printf(bio_err, "where options are\n"); + BIO_printf(bio_err, "-in file input file\n"); + BIO_printf(bio_err, "-inform X input format (DER or PEM)\n"); + BIO_printf(bio_err, "-passin arg input file pass phrase source\n"); + BIO_printf(bio_err, "-outform X output format (DER or PEM)\n"); + BIO_printf(bio_err, "-out file output file\n"); + BIO_printf(bio_err, "-passout arg output file pass phrase source\n"); + BIO_printf(bio_err, "-topk8 output PKCS8 file\n"); + BIO_printf(bio_err, "-nooct use (nonstandard) no octet format\n"); + BIO_printf(bio_err, "-embed use (nonstandard) embedded DSA parameters format\n"); + BIO_printf(bio_err, "-nsdb use (nonstandard) DSA Netscape DB format\n"); + BIO_printf(bio_err, "-noiter use 1 as iteration count\n"); + BIO_printf(bio_err, "-nocrypt use or expect unencrypted private key\n"); + BIO_printf(bio_err, "-v2 alg use PKCS#5 v2.0 and cipher \"alg\"\n"); + BIO_printf(bio_err, "-v1 obj use PKCS#5 v1.5 and cipher \"alg\"\n"); + return (1); + } + + if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { + BIO_printf(bio_err, "Error getting passwords\n"); return (1); } if ((pbe_nid == -1) && !cipher) pbe_nid = NID_pbeWithMD5AndDES_CBC; if (infile) { - if (!(in = BIO_new_file (infile, "rb"))) { - BIO_printf (bio_err, + if (!(in = BIO_new_file(infile, "rb"))) { + BIO_printf(bio_err, "Can't open input file %s\n", infile); return (1); } @@ -154,25 +190,32 @@ int MAIN(int argc, char **argv) if (outfile) { if (!(out = BIO_new_file (outfile, "wb"))) { - BIO_printf (bio_err, + BIO_printf(bio_err, "Can't open output file %s\n", outfile); return (1); } } else out = BIO_new_fp (stdout, BIO_NOCLOSE); if (topk8) { - if (!(pkey = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL))) { - BIO_printf (bio_err, "Error reading key\n", outfile); + if(informat == FORMAT_PEM) + pkey = PEM_read_bio_PrivateKey(in, NULL, NULL, passin); + else if(informat == FORMAT_ASN1) + pkey = d2i_PrivateKey_bio(in, NULL); + else { + BIO_printf(bio_err, "Bad format specified for key\n"); + return (1); + } + if (!pkey) { + BIO_printf(bio_err, "Error reading key\n", outfile); ERR_print_errors(bio_err); return (1); } BIO_free(in); - if (!(p8inf = EVP_PKEY2PKCS8(pkey))) { - BIO_printf (bio_err, "Error converting key\n", outfile); + if (!(p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken))) { + BIO_printf(bio_err, "Error converting key\n", outfile); ERR_print_errors(bio_err); return (1); } - PKCS8_set_broken(p8inf, p8_broken); if(nocrypt) { if(outformat == FORMAT_PEM) PEM_write_bio_PKCS8_PRIV_KEY_INFO(out, p8inf); @@ -183,17 +226,23 @@ int MAIN(int argc, char **argv) return (1); } } else { - EVP_read_pw_string(pass, 50, "Enter Encryption Password:", 1); + if(passout) p8pass = passout; + else { + p8pass = pass; + EVP_read_pw_string(pass, 50, "Enter Encryption Password:", 1); + } + app_RAND_load_file(NULL, bio_err, 0); if (!(p8 = PKCS8_encrypt(pbe_nid, cipher, - pass, strlen(pass), + p8pass, strlen(p8pass), NULL, 0, iter, p8inf))) { - BIO_printf (bio_err, "Error encrypting key\n", + BIO_printf(bio_err, "Error encrypting key\n", outfile); ERR_print_errors(bio_err); return (1); } + app_RAND_write_file(NULL, bio_err); if(outformat == FORMAT_PEM) - PEM_write_bio_PKCS8 (out, p8); + PEM_write_bio_PKCS8(out, p8); else if(outformat == FORMAT_ASN1) i2d_PKCS8_bio(out, p8); else { @@ -205,6 +254,8 @@ int MAIN(int argc, char **argv) PKCS8_PRIV_KEY_INFO_free (p8inf); EVP_PKEY_free(pkey); BIO_free(out); + if(passin) Free(passin); + if(passout) Free(passout); return (0); } @@ -232,8 +283,12 @@ int MAIN(int argc, char **argv) ERR_print_errors(bio_err); return (1); } - EVP_read_pw_string(pass, 50, "Enter Password:", 0); - p8inf = M_PKCS8_decrypt(p8, pass, strlen(pass)); + if(passin) p8pass = passin; + else { + p8pass = pass; + EVP_read_pw_string(pass, 50, "Enter Password:", 0); + } + p8inf = M_PKCS8_decrypt(p8, p8pass, strlen(p8pass)); X509_SIG_free(p8); } @@ -253,7 +308,15 @@ int MAIN(int argc, char **argv) BIO_printf(bio_err, "Warning: broken key encoding: "); switch (p8inf->broken) { case PKCS8_NO_OCTET: - BIO_printf(bio_err, "No Octet String\n"); + BIO_printf(bio_err, "No Octet String in PrivateKey\n"); + break; + + case PKCS8_EMBEDDED_PARAM: + BIO_printf(bio_err, "DSA parameters included in PrivateKey\n"); + break; + + case PKCS8_NS_DB: + BIO_printf(bio_err, "DSA public key include in PrivateKey\n"); break; default: @@ -263,12 +326,20 @@ int MAIN(int argc, char **argv) } PKCS8_PRIV_KEY_INFO_free(p8inf); - - PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL, NULL); + if(outformat == FORMAT_PEM) + PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL, passout); + else if(outformat == FORMAT_ASN1) + i2d_PrivateKey_bio(out, pkey); + else { + BIO_printf(bio_err, "Bad format specified for key\n"); + return (1); + } EVP_PKEY_free(pkey); BIO_free(out); BIO_free(in); + if(passin) Free(passin); + if(passout) Free(passout); return (0); } diff --git a/crypto/openssl/apps/progs.h b/crypto/openssl/apps/progs.h index df06718..7d22384 100644 --- a/crypto/openssl/apps/progs.h +++ b/crypto/openssl/apps/progs.h @@ -1,11 +1,14 @@ -/* This file was generated by progs.pl. */ +/* apps/progs.h */ +/* automatically generated by progs.pl for openssl.c */ extern int verify_main(int argc,char *argv[]); extern int asn1parse_main(int argc,char *argv[]); extern int req_main(int argc,char *argv[]); extern int dgst_main(int argc,char *argv[]); extern int dh_main(int argc,char *argv[]); +extern int dhparam_main(int argc,char *argv[]); extern int enc_main(int argc,char *argv[]); +extern int passwd_main(int argc,char *argv[]); extern int gendh_main(int argc,char *argv[]); extern int errstr_main(int argc,char *argv[]); extern int ca_main(int argc,char *argv[]); @@ -28,8 +31,9 @@ extern int ciphers_main(int argc,char *argv[]); extern int nseq_main(int argc,char *argv[]); extern int pkcs12_main(int argc,char *argv[]); extern int pkcs8_main(int argc,char *argv[]); - -#ifdef SSLEAY_SRC /* Defined only in openssl.c. */ +extern int spkac_main(int argc,char *argv[]); +extern int smime_main(int argc,char *argv[]); +extern int rand_main(int argc,char *argv[]); #define FUNC_TYPE_GENERAL 1 #define FUNC_TYPE_MD 2 @@ -49,7 +53,11 @@ FUNCTION functions[] = { #ifndef NO_DH {FUNC_TYPE_GENERAL,"dh",dh_main}, #endif +#ifndef NO_DH + {FUNC_TYPE_GENERAL,"dhparam",dhparam_main}, +#endif {FUNC_TYPE_GENERAL,"enc",enc_main}, + {FUNC_TYPE_GENERAL,"passwd",passwd_main}, #ifndef NO_DH {FUNC_TYPE_GENERAL,"gendh",gendh_main}, #endif @@ -72,14 +80,14 @@ FUNCTION functions[] = { #ifndef NO_DSA {FUNC_TYPE_GENERAL,"gendsa",gendsa_main}, #endif -#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3)) +#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(NO_SSL3)) {FUNC_TYPE_GENERAL,"s_server",s_server_main}, #endif -#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3)) +#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(NO_SSL3)) {FUNC_TYPE_GENERAL,"s_client",s_client_main}, #endif {FUNC_TYPE_GENERAL,"speed",speed_main}, -#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3)) +#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(NO_SSL3)) {FUNC_TYPE_GENERAL,"s_time",s_time_main}, #endif {FUNC_TYPE_GENERAL,"version",version_main}, @@ -94,6 +102,9 @@ FUNCTION functions[] = { {FUNC_TYPE_GENERAL,"pkcs12",pkcs12_main}, #endif {FUNC_TYPE_GENERAL,"pkcs8",pkcs8_main}, + {FUNC_TYPE_GENERAL,"spkac",spkac_main}, + {FUNC_TYPE_GENERAL,"smime",smime_main}, + {FUNC_TYPE_GENERAL,"rand",rand_main}, {FUNC_TYPE_MD,"md2",dgst_main}, {FUNC_TYPE_MD,"md5",dgst_main}, {FUNC_TYPE_MD,"sha",dgst_main}, @@ -116,6 +127,9 @@ FUNCTION functions[] = { #ifndef NO_RC4 {FUNC_TYPE_CIPHER,"rc4",enc_main}, #endif +#ifndef NO_RC4 + {FUNC_TYPE_CIPHER,"rc4-40",enc_main}, +#endif #ifndef NO_RC2 {FUNC_TYPE_CIPHER,"rc2",enc_main}, #endif @@ -188,6 +202,12 @@ FUNCTION functions[] = { #ifndef NO_RC2 {FUNC_TYPE_CIPHER,"rc2-ofb",enc_main}, #endif +#ifndef NO_RC2 + {FUNC_TYPE_CIPHER,"rc2-64-cbc",enc_main}, +#endif +#ifndef NO_RC2 + {FUNC_TYPE_CIPHER,"rc2-40-cbc",enc_main}, +#endif #ifndef NO_BF {FUNC_TYPE_CIPHER,"bf-cbc",enc_main}, #endif @@ -229,5 +249,3 @@ FUNCTION functions[] = { #endif {0,NULL,NULL} }; -#endif - diff --git a/crypto/openssl/apps/progs.pl b/crypto/openssl/apps/progs.pl index 7a69fc7..9842d2a 100644 --- a/crypto/openssl/apps/progs.pl +++ b/crypto/openssl/apps/progs.pl @@ -1,6 +1,7 @@ #!/usr/local/bin/perl -print "/* This file was generated by progs.pl. */\n\n"; +print "/* apps/progs.h */\n"; +print "/* automatically generated by progs.pl for openssl.c */\n\n"; grep(s/^asn1pars$/asn1parse/,@ARGV); @@ -9,8 +10,6 @@ foreach (@ARGV) print <<'EOF'; -#ifdef SSLEAY_SRC /* Defined only in openssl.c. */ - #define FUNC_TYPE_GENERAL 1 #define FUNC_TYPE_MD 2 #define FUNC_TYPE_CIPHER 3 @@ -29,13 +28,15 @@ foreach (@ARGV) push(@files,$_); $str="\t{FUNC_TYPE_GENERAL,\"$_\",${_}_main},\n"; if (($_ =~ /^s_/) || ($_ =~ /^ciphers$/)) - { print "#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3))\n${str}#endif\n"; } + { print "#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(NO_SSL3))\n${str}#endif\n"; } elsif ( ($_ =~ /^rsa$/) || ($_ =~ /^genrsa$/) ) { print "#ifndef NO_RSA\n${str}#endif\n"; } elsif ( ($_ =~ /^dsa$/) || ($_ =~ /^gendsa$/) || ($_ =~ /^dsaparam$/)) { print "#ifndef NO_DSA\n${str}#endif\n"; } - elsif ( ($_ =~ /^dh$/) || ($_ =~ /^gendh$/)) + elsif ( ($_ =~ /^dh$/) || ($_ =~ /^gendh$/) || ($_ =~ /^dhparam$/)) { print "#ifndef NO_DH\n${str}#endif\n"; } + elsif ( ($_ =~ /^pkcs12$/)) + { print "#if !defined(NO_DES) && !defined(NO_SHA1)\n${str}#endif\n"; } else { print $str; } } @@ -48,13 +49,14 @@ foreach ("md2","md5","sha","sha1","mdc2","rmd160") foreach ( "base64", - "des", "des3", "desx", "idea", "rc4", "rc2","bf","cast","rc5", + "des", "des3", "desx", "idea", "rc4", "rc4-40", + "rc2", "bf", "cast", "rc5", "des-ecb", "des-ede", "des-ede3", "des-cbc", "des-ede-cbc","des-ede3-cbc", "des-cfb", "des-ede-cfb","des-ede3-cfb", "des-ofb", "des-ede-ofb","des-ede3-ofb", "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb", - "rc2-cbc", "rc2-ecb", "rc2-cfb", "rc2-ofb", + "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc", "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb", "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb", "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb") @@ -73,5 +75,3 @@ foreach ( } print "\t{0,NULL,NULL}\n\t};\n"; -print "#endif\n\n"; - diff --git a/crypto/openssl/apps/rand.c b/crypto/openssl/apps/rand.c new file mode 100644 index 0000000..cfbba30 --- /dev/null +++ b/crypto/openssl/apps/rand.c @@ -0,0 +1,140 @@ +/* apps/rand.c */ + +#include "apps.h" + +#include <ctype.h> +#include <stdio.h> +#include <string.h> + +#include <openssl/bio.h> +#include <openssl/err.h> +#include <openssl/rand.h> + +#undef PROG +#define PROG rand_main + +/* -out file - write to file + * -rand file:file - PRNG seed files + * -base64 - encode output + * num - write 'num' bytes + */ + +int MAIN(int, char **); + +int MAIN(int argc, char **argv) + { + int i, r, ret = 1; + int badopt; + char *outfile = NULL; + char *inrand = NULL; + int base64 = 0; + BIO *out = NULL; + int num = -1; + + apps_startup(); + + if (bio_err == NULL) + if ((bio_err = BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); + + badopt = 0; + i = 0; + while (!badopt && argv[++i] != NULL) + { + if (strcmp(argv[i], "-out") == 0) + { + if ((argv[i+1] != NULL) && (outfile == NULL)) + outfile = argv[++i]; + else + badopt = 1; + } + else if (strcmp(argv[i], "-rand") == 0) + { + if ((argv[i+1] != NULL) && (inrand == NULL)) + inrand = argv[++i]; + else + badopt = 1; + } + else if (strcmp(argv[i], "-base64") == 0) + { + if (!base64) + base64 = 1; + else + badopt = 1; + } + else if (isdigit(argv[i][0])) + { + if (num < 0) + { + r = sscanf(argv[i], "%d", &num); + if (r == 0 || num < 0) + badopt = 1; + } + else + badopt = 1; + } + else + badopt = 1; + } + + if (num < 0) + badopt = 1; + + if (badopt) + { + BIO_printf(bio_err, "Usage: rand [options] num\n"); + BIO_printf(bio_err, "where options are\n"); + BIO_printf(bio_err, "-out file - write to file\n"); + BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err, "-base64 - encode output\n"); + goto err; + } + + app_RAND_load_file(NULL, bio_err, (inrand != NULL)); + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); + + out = BIO_new(BIO_s_file()); + if (out == NULL) + goto err; + if (outfile != NULL) + r = BIO_write_filename(out, outfile); + else + r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); + if (r <= 0) + goto err; + + if (base64) + { + BIO *b64 = BIO_new(BIO_f_base64()); + if (b64 == NULL) + goto err; + out = BIO_push(b64, out); + } + + while (num > 0) + { + unsigned char buf[4096]; + int chunk; + + chunk = num; + if (chunk > sizeof buf) + chunk = sizeof buf; + r = RAND_bytes(buf, chunk); + if (r <= 0) + goto err; + BIO_write(out, buf, chunk); + num -= chunk; + } + BIO_flush(out); + + app_RAND_write_file(NULL, bio_err); + ret = 0; + +err: + ERR_print_errors(bio_err); + if (out) + BIO_free_all(out); + EXIT(ret); + } diff --git a/crypto/openssl/apps/req.c b/crypto/openssl/apps/req.c index 463ac15..eb338ee 100644 --- a/crypto/openssl/apps/req.c +++ b/crypto/openssl/apps/req.c @@ -66,7 +66,6 @@ #include "apps.h" #include <openssl/bio.h> #include <openssl/evp.h> -#include <openssl/rand.h> #include <openssl/conf.h> #include <openssl/err.h> #include <openssl/asn1.h> @@ -79,9 +78,12 @@ #define BITS "default_bits" #define KEYFILE "default_keyfile" +#define PROMPT "prompt" #define DISTINGUISHED_NAME "distinguished_name" #define ATTRIBUTES "attributes" #define V3_EXTENSIONS "x509_extensions" +#define REQ_EXTENSIONS "req_extensions" +#define STRING_MASK "string_mask" #define DEFAULT_KEY_LENGTH 512 #define MIN_KEY_LENGTH 384 @@ -89,7 +91,7 @@ #undef PROG #define PROG req_main -/* -inform arg - input format - default PEM (one of DER, TXT or PEM) +/* -inform arg - input format - default PEM (DER or PEM) * -outform arg - output format - default PEM * -in arg - input file - default stdin * -out arg - output file - default stdout @@ -108,13 +110,20 @@ */ static int make_REQ(X509_REQ *req,EVP_PKEY *pkey,int attribs); -static int add_attribute_object(STACK_OF(X509_ATTRIBUTE) *n, char *text, +static int prompt_info(X509_REQ *req, + STACK_OF(CONF_VALUE) *dn_sk, char *dn_sect, + STACK_OF(CONF_VALUE) *attr_sk, char *attr_sect, int attribs); +static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *sk, + STACK_OF(CONF_VALUE) *attr, int attribs); +static int add_attribute_object(X509_REQ *req, char *text, char *def, char *value, int nid, int min, int max); static int add_DN_object(X509_NAME *n, char *text, char *def, char *value, int nid,int min,int max); +#ifndef NO_RSA static void MS_CALLBACK req_cb(int p,int n,void *arg); -static int req_fix_data(int nid,int *type,int len,int min,int max); +#endif +static int req_check_len(int len,int min,int max); static int check_end(char *str, char *end); static int add_oid_section(LHASH *conf); #ifndef MONOLITH @@ -127,6 +136,8 @@ static LHASH *req_conf=NULL; #define TYPE_DSA 2 #define TYPE_DH 3 +int MAIN(int, char **); + int MAIN(int argc, char **argv) { #ifndef NO_DSA @@ -139,17 +150,21 @@ int MAIN(int argc, char **argv) int i,badops=0,newreq=0,newkey= -1,pkey_type=0; BIO *in=NULL,*out=NULL; int informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM; - int nodes=0,kludge=0; + int nodes=0,kludge=0,newhdr=0; char *infile,*outfile,*prog,*keyfile=NULL,*template=NULL,*keyout=NULL; char *extensions = NULL; + char *req_exts = NULL; EVP_CIPHER *cipher=NULL; int modulus=0; + char *passargin = NULL, *passargout = NULL; + char *passin = NULL, *passout = NULL; char *p; const EVP_MD *md_alg=NULL,*digest=EVP_md5(); #ifndef MONOLITH MS_STATIC char config_name[256]; #endif + req_conf = NULL; #ifndef NO_DES cipher=EVP_des_ede3_cbc(); #endif @@ -214,6 +229,16 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; keyout= *(++argv); } + else if (strcmp(*argv,"-passin") == 0) + { + if (--argc < 1) goto bad; + passargin= *(++argv); + } + else if (strcmp(*argv,"-passout") == 0) + { + if (--argc < 1) goto bad; + passargout= *(++argv); + } else if (strcmp(*argv,"-newkey") == 0) { int is_numeric; @@ -281,6 +306,8 @@ int MAIN(int argc, char **argv) newreq=1; } + else if (strcmp(*argv,"-newhdr") == 0) + newhdr=1; else if (strcmp(*argv,"-modulus") == 0) modulus=1; else if (strcmp(*argv,"-verify") == 0) @@ -308,8 +335,17 @@ int MAIN(int argc, char **argv) /* ok */ digest=md_alg; } + else if (strcmp(*argv,"-extensions") == 0) + { + if (--argc < 1) goto bad; + extensions = *(++argv); + } + else if (strcmp(*argv,"-reqexts") == 0) + { + if (--argc < 1) goto bad; + req_exts = *(++argv); + } else - { BIO_printf(bio_err,"unknown option %s\n",*argv); badops=1; @@ -324,8 +360,8 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n"); + BIO_printf(bio_err," -inform arg input format - DER or PEM\n"); + BIO_printf(bio_err," -outform arg output format - DER or PEM\n"); BIO_printf(bio_err," -in arg input file\n"); BIO_printf(bio_err," -out arg output file\n"); BIO_printf(bio_err," -text text form of request\n"); @@ -344,16 +380,21 @@ bad: BIO_printf(bio_err," -new new request.\n"); BIO_printf(bio_err," -x509 output a x509 structure instead of a cert. req.\n"); BIO_printf(bio_err," -days number of days a x509 generated by -x509 is valid for.\n"); + BIO_printf(bio_err," -newhdr output \"NEW\" in the header lines\n"); BIO_printf(bio_err," -asn1-kludge Output the 'request' in a format that is wrong but some CA's\n"); BIO_printf(bio_err," have been reported as requiring\n"); - BIO_printf(bio_err," [ It is now always turned on but can be turned off with -no-asn1-kludge ]\n"); + 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"); goto end; } ERR_load_crypto_strings(); - X509V3_add_standard_extensions(); + if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { + BIO_printf(bio_err, "Error getting passwords\n"); + goto end; + } -#ifndef MONOLITH +#ifndef MONOLITH /* else this has happened in openssl.c (global `config') */ /* Lets load up our environment a little */ p=getenv("OPENSSL_CONF"); if (p == NULL) @@ -367,7 +408,7 @@ bad: strcat(config_name,OPENSSL_CONF); p=config_name; } - default_config_file=p; + default_config_file=p; config=CONF_load(config,p,NULL); #endif @@ -425,7 +466,8 @@ bad: digest=md_alg; } - extensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS); + if(!extensions) + extensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS); if(extensions) { /* Check syntax of file */ X509V3_CTX ctx; @@ -438,6 +480,34 @@ bad: } } + if(!passin) + passin = CONF_get_string(req_conf, SECTION, "input_password"); + + if(!passout) + passout = CONF_get_string(req_conf, SECTION, "output_password"); + + p = CONF_get_string(req_conf, SECTION, STRING_MASK); + + if(p && !ASN1_STRING_set_default_mask_asc(p)) { + BIO_printf(bio_err, "Invalid global string mask setting %s\n", p); + goto end; + } + + if(!req_exts) + req_exts = CONF_get_string(req_conf, SECTION, REQ_EXTENSIONS); + if(req_exts) { + /* Check syntax of file */ + X509V3_CTX ctx; + X509V3_set_ctx_test(&ctx); + X509V3_set_conf_lhash(&ctx, req_conf); + if(!X509V3_EXT_add_conf(req_conf, &ctx, req_exts, NULL)) { + BIO_printf(bio_err, + "Error Loading request extension section %s\n", + req_exts); + goto end; + } + } + in=BIO_new(BIO_s_file()); out=BIO_new(BIO_s_file()); if ((in == NULL) || (out == NULL)) @@ -451,11 +521,12 @@ bad: goto end; } -/* if (keyform == FORMAT_ASN1) - rsa=d2i_RSAPrivateKey_bio(in,NULL); - else */ - if (keyform == FORMAT_PEM) - pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL); + if (keyform == FORMAT_ASN1) + pkey=d2i_PrivateKey_bio(in,NULL); + else if (keyform == FORMAT_PEM) + { + pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,passin); + } else { BIO_printf(bio_err,"bad input format specified for X509 request\n"); @@ -471,25 +542,9 @@ bad: if (newreq && (pkey == NULL)) { - char *randfile; - char buffer[200]; - - if ((randfile=CONF_get_string(req_conf,SECTION,"RANDFILE")) == NULL) - randfile=RAND_file_name(buffer,200); -#ifdef WINDOWS - BIO_printf(bio_err,"Loading 'screen' into random state -"); - BIO_flush(bio_err); - RAND_screen(); - BIO_printf(bio_err," done\n"); -#endif - if ((randfile == NULL) || !RAND_load_file(randfile,1024L*1024L)) - { - BIO_printf(bio_err,"unable to load 'random state'\n"); - BIO_printf(bio_err,"What this means is that the random number generator has not been seeded\n"); - BIO_printf(bio_err,"with much random data.\n"); - BIO_printf(bio_err,"Consider setting the RANDFILE environment variable to point at a file that\n"); - BIO_printf(bio_err,"'random' data can be kept in.\n"); - } + char *randfile = CONF_get_string(req_conf,SECTION,"RANDFILE"); + app_RAND_load_file(randfile, bio_err, 0); + if (newkey <= 0) { newkey=(int)CONF_get_number(req_conf,SECTION,BITS); @@ -527,8 +582,7 @@ bad: } #endif - if ((randfile == NULL) || (RAND_write_file(randfile) == 0)) - BIO_printf(bio_err,"unable to write 'random state'\n"); + app_RAND_write_file(randfile, bio_err); if (pkey == NULL) goto end; @@ -560,7 +614,7 @@ bad: i=0; loop: if (!PEM_write_bio_PrivateKey(out,pkey,cipher, - NULL,0,NULL,NULL)) + NULL,0,NULL,passout)) { if ((ERR_GET_REASON(ERR_peek_error()) == PEM_R_PROBLEMS_GETTING_PASSWORD) && (i < 3)) @@ -677,6 +731,22 @@ loop: } else { + X509V3_CTX ext_ctx; + + /* Set up V3 context struct */ + + X509V3_set_ctx(&ext_ctx, NULL, NULL, req, NULL, 0); + X509V3_set_conf_lhash(&ext_ctx, req_conf); + + /* Add extensions */ + if(req_exts && !X509V3_EXT_REQ_add_conf(req_conf, + &ext_ctx, req_exts, req)) + { + BIO_printf(bio_err, + "Error Loading extension section %s\n", + req_exts); + goto end; + } if (!(i=X509_REQ_sign(req,pkey,digest))) goto end; } @@ -767,9 +837,10 @@ loop: { if (outformat == FORMAT_ASN1) i=i2d_X509_REQ_bio(out,req); - else if (outformat == FORMAT_PEM) - i=PEM_write_bio_X509_REQ(out,req); - else { + else if (outformat == FORMAT_PEM) { + if(newhdr) i=PEM_write_bio_X509_REQ_NEW(out,req); + else i=PEM_write_bio_X509_REQ(out,req); + } else { BIO_printf(bio_err,"bad output format specified for outfile\n"); goto end; } @@ -807,7 +878,8 @@ end: EVP_PKEY_free(pkey); X509_REQ_free(req); X509_free(x509ss); - X509V3_EXT_cleanup(); + if(passargin && passin) Free(passin); + if(passargout && passout) Free(passout); OBJ_cleanup(); #ifndef NO_DSA if (dsa_params != NULL) DSA_free(dsa_params); @@ -818,43 +890,67 @@ end: static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs) { int ret=0,i; - char *p,*q; - X509_REQ_INFO *ri; - char buf[100]; - int nid,min,max; - char *type,*def,*tmp,*value,*tmp_attr; - STACK_OF(CONF_VALUE) *sk, *attr=NULL; - CONF_VALUE *v; - - tmp=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME); - if (tmp == NULL) + char no_prompt = 0; + STACK_OF(CONF_VALUE) *dn_sk, *attr_sk = NULL; + char *tmp, *dn_sect,*attr_sect; + + tmp=CONF_get_string(req_conf,SECTION,PROMPT); + if((tmp != NULL) && !strcmp(tmp, "no")) no_prompt = 1; + + dn_sect=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME); + if (dn_sect == NULL) { BIO_printf(bio_err,"unable to find '%s' in config\n", DISTINGUISHED_NAME); goto err; } - sk=CONF_get_section(req_conf,tmp); - if (sk == NULL) + dn_sk=CONF_get_section(req_conf,dn_sect); + if (dn_sk == NULL) { - BIO_printf(bio_err,"unable to get '%s' section\n",tmp); + BIO_printf(bio_err,"unable to get '%s' section\n",dn_sect); goto err; } - tmp_attr=CONF_get_string(req_conf,SECTION,ATTRIBUTES); - if (tmp_attr == NULL) - attr=NULL; + attr_sect=CONF_get_string(req_conf,SECTION,ATTRIBUTES); + if (attr_sect == NULL) + attr_sk=NULL; else { - attr=CONF_get_section(req_conf,tmp_attr); - if (attr == NULL) + attr_sk=CONF_get_section(req_conf,attr_sect); + if (attr_sk == NULL) { - BIO_printf(bio_err,"unable to get '%s' section\n",tmp_attr); + BIO_printf(bio_err,"unable to get '%s' section\n",attr_sect); goto err; } } - ri=req->req_info; + /* setup version number */ + if (!X509_REQ_set_version(req,0L)) goto err; /* version 1 */ + + if(no_prompt) i = auto_info(req, dn_sk, attr_sk, attribs); + else i = prompt_info(req, dn_sk, dn_sect, attr_sk, attr_sect, attribs); + if(!i) goto err; + + X509_REQ_set_pubkey(req,pkey); + ret=1; +err: + return(ret); + } + + +static int prompt_info(X509_REQ *req, + STACK_OF(CONF_VALUE) *dn_sk, char *dn_sect, + STACK_OF(CONF_VALUE) *attr_sk, char *attr_sect, int attribs) + { + int i; + char *p,*q; + char buf[100]; + int nid,min,max; + char *type,*def,*value; + CONF_VALUE *v; + X509_NAME *subj; + subj = X509_REQ_get_subject_name(req); BIO_printf(bio_err,"You are about to be asked to enter information that will be incorporated\n"); BIO_printf(bio_err,"into your certificate request.\n"); BIO_printf(bio_err,"What you are about to enter is what is called a Distinguished Name or a DN.\n"); @@ -863,18 +959,16 @@ static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs) BIO_printf(bio_err,"If you enter '.', the field will be left blank.\n"); BIO_printf(bio_err,"-----\n"); - /* setup version number */ - if (!ASN1_INTEGER_set(ri->version,0L)) goto err; /* version 1 */ - if (sk_CONF_VALUE_num(sk)) + if (sk_CONF_VALUE_num(dn_sk)) { i= -1; start: for (;;) { i++; - if (sk_CONF_VALUE_num(sk) <= i) break; + if (sk_CONF_VALUE_num(dn_sk) <= i) break; - v=sk_CONF_VALUE_value(sk,i); + v=sk_CONF_VALUE_value(dn_sk,i); p=q=NULL; type=v->name; if(!check_end(type,"_min") || !check_end(type,"_max") || @@ -893,32 +987,32 @@ start: for (;;) /* If OBJ not recognised ignore it */ if ((nid=OBJ_txt2nid(type)) == NID_undef) goto start; sprintf(buf,"%s_default",v->name); - if ((def=CONF_get_string(req_conf,tmp,buf)) == NULL) + if ((def=CONF_get_string(req_conf,dn_sect,buf)) == NULL) def=""; sprintf(buf,"%s_value",v->name); - if ((value=CONF_get_string(req_conf,tmp,buf)) == NULL) + if ((value=CONF_get_string(req_conf,dn_sect,buf)) == NULL) value=NULL; sprintf(buf,"%s_min",v->name); - min=(int)CONF_get_number(req_conf,tmp,buf); + min=(int)CONF_get_number(req_conf,dn_sect,buf); sprintf(buf,"%s_max",v->name); - max=(int)CONF_get_number(req_conf,tmp,buf); + max=(int)CONF_get_number(req_conf,dn_sect,buf); - if (!add_DN_object(ri->subject,v->value,def,value,nid, + if (!add_DN_object(subj,v->value,def,value,nid, min,max)) - goto err; + return 0; } - if (sk_X509_NAME_ENTRY_num(ri->subject->entries) == 0) + if (X509_NAME_entry_count(subj) == 0) { BIO_printf(bio_err,"error, no objects specified in config file\n"); - goto err; + return 0; } if (attribs) { - if ((attr != NULL) && (sk_CONF_VALUE_num(attr) > 0)) + if ((attr_sk != NULL) && (sk_CONF_VALUE_num(attr_sk) > 0)) { BIO_printf(bio_err,"\nPlease enter the following 'extra' attributes\n"); BIO_printf(bio_err,"to be sent with your certificate request\n"); @@ -928,57 +1022,101 @@ start: for (;;) start2: for (;;) { i++; - if ((attr == NULL) || - (sk_CONF_VALUE_num(attr) <= i)) + if ((attr_sk == NULL) || + (sk_CONF_VALUE_num(attr_sk) <= i)) break; - v=sk_CONF_VALUE_value(attr,i); + v=sk_CONF_VALUE_value(attr_sk,i); type=v->name; if ((nid=OBJ_txt2nid(type)) == NID_undef) goto start2; sprintf(buf,"%s_default",type); - if ((def=CONF_get_string(req_conf,tmp_attr,buf)) + if ((def=CONF_get_string(req_conf,attr_sect,buf)) == NULL) def=""; sprintf(buf,"%s_value",type); - if ((value=CONF_get_string(req_conf,tmp_attr,buf)) + if ((value=CONF_get_string(req_conf,attr_sect,buf)) == NULL) value=NULL; sprintf(buf,"%s_min",type); - min=(int)CONF_get_number(req_conf,tmp_attr,buf); + min=(int)CONF_get_number(req_conf,attr_sect,buf); sprintf(buf,"%s_max",type); - max=(int)CONF_get_number(req_conf,tmp_attr,buf); + max=(int)CONF_get_number(req_conf,attr_sect,buf); - if (!add_attribute_object(ri->attributes, + if (!add_attribute_object(req, v->value,def,value,nid,min,max)) - goto err; + return 0; } } } else { BIO_printf(bio_err,"No template, please set one up.\n"); - goto err; + return 0; } - X509_REQ_set_pubkey(req,pkey); + return 1; - ret=1; -err: - return(ret); } +static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *dn_sk, + STACK_OF(CONF_VALUE) *attr_sk, int attribs) + { + int i; + char *p,*q; + char *type; + CONF_VALUE *v; + X509_NAME *subj; + + subj = X509_REQ_get_subject_name(req); + + for (i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) + { + v=sk_CONF_VALUE_value(dn_sk,i); + p=q=NULL; + type=v->name; + /* Skip past any leading X. X: X, etc to allow for + * multiple instances + */ + for(p = v->name; *p ; p++) + if ((*p == ':') || (*p == ',') || (*p == '.')) { + p++; + if(*p) type = p; + break; + } + if (!X509_NAME_add_entry_by_txt(subj,type, MBSTRING_ASC, + (unsigned char *) v->value,-1,-1,0)) return 0; + + } + + if (!X509_NAME_entry_count(subj)) + { + BIO_printf(bio_err,"error, no objects specified in config file\n"); + return 0; + } + if (attribs) + { + for (i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) + { + v=sk_CONF_VALUE_value(attr_sk,i); + if(!X509_REQ_add1_attr_by_txt(req, v->name, MBSTRING_ASC, + (unsigned char *)v->value, -1)) return 0; + } + } + return 1; + } + + static int add_DN_object(X509_NAME *n, char *text, char *def, char *value, int nid, int min, int max) { - int i,j,ret=0; - X509_NAME_ENTRY *ne=NULL; + int i,ret=0; MS_STATIC char buf[1024]; - +start: BIO_printf(bio_err,"%s [%s]:",text,def); (void)BIO_flush(bio_err); if (value != NULL) @@ -1011,33 +1149,23 @@ static int add_DN_object(X509_NAME *n, char *text, char *def, char *value, } buf[--i]='\0'; - j=ASN1_PRINTABLE_type((unsigned char *)buf,-1); - if (req_fix_data(nid,&j,i,min,max) == 0) - goto err; #ifdef CHARSET_EBCDIC ebcdic2ascii(buf, buf, i); #endif - if ((ne=X509_NAME_ENTRY_create_by_NID(NULL,nid,j,(unsigned char *)buf, - strlen(buf))) - == NULL) goto err; - if (!X509_NAME_add_entry(n,ne,X509_NAME_entry_count(n),0)) - goto err; - + if(!req_check_len(i, min, max)) goto start; + if (!X509_NAME_add_entry_by_NID(n,nid, MBSTRING_ASC, + (unsigned char *) buf, -1,-1,0)) goto err; ret=1; err: - if (ne != NULL) X509_NAME_ENTRY_free(ne); return(ret); } -static int add_attribute_object(STACK_OF(X509_ATTRIBUTE) *n, char *text, +static int add_attribute_object(X509_REQ *req, char *text, char *def, char *value, int nid, int min, int max) { - int i,z; - X509_ATTRIBUTE *xa=NULL; + int i; static char buf[1024]; - ASN1_BIT_STRING *bs=NULL; - ASN1_TYPE *at=NULL; start: BIO_printf(bio_err,"%s [%s]:",text,def); @@ -1071,50 +1199,21 @@ start: return(0); } buf[--i]='\0'; + if(!req_check_len(i, min, max)) goto start; - /* add object plus value */ - if ((xa=X509_ATTRIBUTE_new()) == NULL) - goto err; - if ((xa->value.set=sk_ASN1_TYPE_new_null()) == NULL) + if(!X509_REQ_add1_attr_by_NID(req, nid, MBSTRING_ASC, + (unsigned char *)buf, -1)) { + BIO_printf(bio_err, "Error adding attribute\n"); + ERR_print_errors(bio_err); goto err; - xa->set=1; - - if (xa->object != NULL) ASN1_OBJECT_free(xa->object); - xa->object=OBJ_nid2obj(nid); - - if ((bs=ASN1_BIT_STRING_new()) == NULL) goto err; - - bs->type=ASN1_PRINTABLE_type((unsigned char *)buf,-1); - - z=req_fix_data(nid,&bs->type,i,min,max); - if (z == 0) - { - if (value == NULL) - goto start; - else goto err; - } - - if (!ASN1_STRING_set(bs,(unsigned char *)buf,i+1)) - { BIO_printf(bio_err,"Malloc failure\n"); goto err; } - - if ((at=ASN1_TYPE_new()) == NULL) - { BIO_printf(bio_err,"Malloc failure\n"); goto err; } - - ASN1_TYPE_set(at,bs->type,(char *)bs); - sk_ASN1_TYPE_push(xa->value.set,at); - bs=NULL; - at=NULL; - /* only one item per attribute */ + } - if (!sk_X509_ATTRIBUTE_push(n,xa)) goto err; return(1); err: - if (xa != NULL) X509_ATTRIBUTE_free(xa); - if (at != NULL) ASN1_TYPE_free(at); - if (bs != NULL) ASN1_BIT_STRING_free(bs); return(0); } +#ifndef NO_RSA static void MS_CALLBACK req_cb(int p, int n, void *arg) { char c='*'; @@ -1129,26 +1228,10 @@ static void MS_CALLBACK req_cb(int p, int n, void *arg) p=n; #endif } +#endif -static int req_fix_data(int nid, int *type, int len, int min, int max) +static int req_check_len(int len, int min, int max) { - if (nid == NID_pkcs9_emailAddress) - *type=V_ASN1_IA5STRING; - if ((nid == NID_commonName) && (*type == V_ASN1_IA5STRING)) - *type=V_ASN1_T61STRING; - if ((nid == NID_pkcs9_challengePassword) && - (*type == V_ASN1_IA5STRING)) - *type=V_ASN1_T61STRING; - - if ((nid == NID_pkcs9_unstructuredName) && - (*type == V_ASN1_T61STRING)) - { - BIO_printf(bio_err,"invalid characters in string, please re-enter the string\n"); - return(0); - } - if (nid == NID_pkcs9_unstructuredName) - *type=V_ASN1_IA5STRING; - if (len < min) { BIO_printf(bio_err,"string is too short, it needs to be at least %d bytes long\n",min); diff --git a/crypto/openssl/apps/rsa.c b/crypto/openssl/apps/rsa.c index 9b723ee..9d4c2e6 100644 --- a/crypto/openssl/apps/rsa.c +++ b/crypto/openssl/apps/rsa.c @@ -82,8 +82,12 @@ * -text - print a text version * -modulus - print the RSA key modulus * -check - verify key consistency + * -pubin - Expect a public key in input file. + * -pubout - Output a public key. */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int ret=1; @@ -92,7 +96,10 @@ int MAIN(int argc, char **argv) const EVP_CIPHER *enc=NULL; BIO *in=NULL,*out=NULL; int informat,outformat,text=0,check=0,noout=0; + int pubin = 0, pubout = 0; char *infile,*outfile,*prog; + char *passargin = NULL, *passargout = NULL; + char *passin = NULL, *passout = NULL; int modulus=0; apps_startup(); @@ -131,6 +138,20 @@ 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,"-passout") == 0) + { + if (--argc < 1) goto bad; + passargout= *(++argv); + } + else if (strcmp(*argv,"-pubin") == 0) + pubin=1; + else if (strcmp(*argv,"-pubout") == 0) + pubout=1; else if (strcmp(*argv,"-noout") == 0) noout=1; else if (strcmp(*argv,"-text") == 0) @@ -154,24 +175,38 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); BIO_printf(bio_err,"where options are\n"); - BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n"); - BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n"); - BIO_printf(bio_err," -in arg input file\n"); - BIO_printf(bio_err," -out arg output file\n"); - BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); - BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); + BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n"); + BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n"); + BIO_printf(bio_err," -in arg input file\n"); + BIO_printf(bio_err," -passin arg input file pass phrase source\n"); + BIO_printf(bio_err," -out arg output file\n"); + BIO_printf(bio_err," -passout arg output file pass phrase source\n"); + BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); + BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); #ifndef NO_IDEA - BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); + BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); #endif - BIO_printf(bio_err," -text print the key in text\n"); - BIO_printf(bio_err," -noout don't print key out\n"); - BIO_printf(bio_err," -modulus print the RSA key modulus\n"); - BIO_printf(bio_err," -check verify key consistency\n"); + BIO_printf(bio_err," -text print the key in text\n"); + BIO_printf(bio_err," -noout don't print key out\n"); + BIO_printf(bio_err," -modulus print the RSA key modulus\n"); + BIO_printf(bio_err," -check verify key consistency\n"); + BIO_printf(bio_err," -pubin expect a public key in input file\n"); + BIO_printf(bio_err," -pubout output a public key\n"); goto end; } ERR_load_crypto_strings(); + if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { + BIO_printf(bio_err, "Error getting passwords\n"); + goto end; + } + + if(check && pubin) { + BIO_printf(bio_err, "Only private keys can be checked\n"); + goto end; + } + in=BIO_new(BIO_s_file()); out=BIO_new(BIO_s_file()); if ((in == NULL) || (out == NULL)) @@ -191,9 +226,11 @@ bad: } } - BIO_printf(bio_err,"read RSA private key\n"); - if (informat == FORMAT_ASN1) - rsa=d2i_RSAPrivateKey_bio(in,NULL); + BIO_printf(bio_err,"read RSA key\n"); + if (informat == FORMAT_ASN1) { + if (pubin) rsa=d2i_RSA_PUBKEY_bio(in,NULL); + else rsa=d2i_RSAPrivateKey_bio(in,NULL); + } #ifndef NO_RC4 else if (informat == FORMAT_NETSCAPE) { @@ -217,12 +254,14 @@ bad: } } p=(unsigned char *)buf->data; - rsa=(RSA *)d2i_Netscape_RSA(NULL,&p,(long)size,NULL); + rsa=d2i_Netscape_RSA(NULL,&p,(long)size,NULL); BUF_MEM_free(buf); } #endif - else if (informat == FORMAT_PEM) - rsa=PEM_read_bio_RSAPrivateKey(in,NULL,NULL,NULL); + else if (informat == FORMAT_PEM) { + if(pubin) rsa=PEM_read_bio_RSA_PUBKEY(in,NULL,NULL,NULL); + else rsa=PEM_read_bio_RSAPrivateKey(in,NULL, NULL,passin); + } else { BIO_printf(bio_err,"bad input format specified for key\n"); @@ -230,7 +269,7 @@ bad: } if (rsa == NULL) { - BIO_printf(bio_err,"unable to load Private Key\n"); + BIO_printf(bio_err,"unable to load key\n"); ERR_print_errors(bio_err); goto end; } @@ -256,9 +295,9 @@ bad: if (modulus) { - fprintf(stdout,"Modulus="); + BIO_printf(out,"Modulus="); BN_print(out,rsa->n); - fprintf(stdout,"\n"); + BIO_printf(out,"\n"); } if (check) @@ -288,10 +327,16 @@ bad: } } - if (noout) goto end; - BIO_printf(bio_err,"writing RSA private key\n"); - if (outformat == FORMAT_ASN1) - i=i2d_RSAPrivateKey_bio(out,rsa); + if (noout) + { + ret = 0; + goto end; + } + BIO_printf(bio_err,"writing RSA key\n"); + if (outformat == FORMAT_ASN1) { + if(pubout || pubin) i=i2d_RSA_PUBKEY_bio(out,rsa); + else i=i2d_RSAPrivateKey_bio(out,rsa); + } #ifndef NO_RC4 else if (outformat == FORMAT_NETSCAPE) { @@ -311,23 +356,34 @@ bad: Free(pp); } #endif - else if (outformat == FORMAT_PEM) - i=PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL,NULL); - else { + else if (outformat == FORMAT_PEM) { + if(pubout || pubin) + i=PEM_write_bio_RSA_PUBKEY(out,rsa); + else i=PEM_write_bio_RSAPrivateKey(out,rsa, + enc,NULL,0,NULL,passout); + } else { BIO_printf(bio_err,"bad output format specified for outfile\n"); goto end; } if (!i) { - BIO_printf(bio_err,"unable to write private key\n"); + BIO_printf(bio_err,"unable to write key\n"); ERR_print_errors(bio_err); } else ret=0; end: - if (in != NULL) BIO_free(in); - if (out != NULL) BIO_free(out); - if (rsa != NULL) RSA_free(rsa); + if(in != NULL) BIO_free(in); + if(out != NULL) BIO_free(out); + if(rsa != NULL) RSA_free(rsa); + if(passin) Free(passin); + if(passout) Free(passout); EXIT(ret); } +#else /* !NO_RSA */ + +# if PEDANTIC +static void *dummy=&dummy; +# endif + #endif diff --git a/crypto/openssl/apps/s_apps.h b/crypto/openssl/apps/s_apps.h index 1a0e9f9..57af7c0 100644 --- a/crypto/openssl/apps/s_apps.h +++ b/crypto/openssl/apps/s_apps.h @@ -84,7 +84,6 @@ typedef fd_mask fd_set; #define PORT_STR "4433" #define PROTOCOL "tcp" -int do_accept(int acc_sock, int *sock, char **host); int do_server(int port, int *ret, int (*cb) (), char *context); #ifdef HEADER_X509_H int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx); @@ -97,17 +96,9 @@ int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file); int set_cert_stuff(char *ctx, char *cert_file, char *key_file); #endif int init_client(int *sock, char *server, int port); -int init_client_ip(int *sock,unsigned char ip[4], int port); -int nbio_init_client_ip(int *sock,unsigned char ip[4], int port); -int nbio_sock_error(int sock); -int spawn(int argc, char **argv, int *in, int *out); -int init_server(int *sock, int port); -int init_server_long(int *sock, int port,char *ip); int should_retry(int i); -void sock_cleanup(void ); int extract_port(char *str, short *port_ptr); int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p); -int host_ip(char *str, unsigned char ip[4]); long MS_CALLBACK bio_dump_cb(BIO *bio, int cmd, const char *argp, int argi, long argl, long ret); diff --git a/crypto/openssl/apps/s_cb.c b/crypto/openssl/apps/s_cb.c index fdb11a1..fd62259 100644 --- a/crypto/openssl/apps/s_cb.c +++ b/crypto/openssl/apps/s_cb.c @@ -1,4 +1,4 @@ -/* apps/s_cb.c */ +/* apps/s_cb.c - callback functions used by s_client, s_server, and s_time */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * diff --git a/crypto/openssl/apps/s_client.c b/crypto/openssl/apps/s_client.c index b0610413..e629f8e 100644 --- a/crypto/openssl/apps/s_client.c +++ b/crypto/openssl/apps/s_client.c @@ -56,9 +56,7 @@ * [including the GNU Public Licence.] */ -#ifdef APPS_CRLF -# include <assert.h> -#endif +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -83,15 +81,16 @@ typedef unsigned int u_int; #include <openssl/pem.h> #include "s_apps.h" +#ifdef WINDOWS +#include <conio.h> +#endif + + #if (defined(VMS) && __VMS_VER < 70000000) /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ #undef FIONBIO #endif -#if defined(NO_RSA) && !defined(NO_SSL2) -#define NO_SSL2 -#endif - #undef PROG #define PROG s_client_main @@ -118,6 +117,7 @@ static void sc_usage(void); static void print_stuff(BIO *berr,SSL *con,int full); static BIO *bio_c_out=NULL; static int c_quiet=0; +static int c_ign_eof=0; static void sc_usage(void) { @@ -142,20 +142,21 @@ static void sc_usage(void) #ifdef FIONBIO BIO_printf(bio_err," -nbio - Run with non-blocking IO\n"); #endif -#ifdef APPS_CRLF /* won't be #ifdef'd in next release */ BIO_printf(bio_err," -crlf - convert LF from terminal into CRLF\n"); -#endif BIO_printf(bio_err," -quiet - no s_client output\n"); + BIO_printf(bio_err," -ign_eof - ignore input eof (default when -quiet)\n"); BIO_printf(bio_err," -ssl2 - just use SSLv2\n"); BIO_printf(bio_err," -ssl3 - just use SSLv3\n"); BIO_printf(bio_err," -tls1 - just use TLSv1\n"); BIO_printf(bio_err," -no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol\n"); BIO_printf(bio_err," -bugs - Switch on all SSL implementation bug workarounds\n"); - BIO_printf(bio_err," -cipher - prefered cipher to use, use the 'openssl ciphers'\n"); + BIO_printf(bio_err," -cipher - preferred cipher to use, use the 'openssl ciphers'\n"); BIO_printf(bio_err," command to see what is available\n"); } +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int off=0; @@ -171,15 +172,16 @@ int MAIN(int argc, char **argv) char *cert_file=NULL,*key_file=NULL; char *CApath=NULL,*CAfile=NULL,*cipher=NULL; int reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0; -#ifdef APPS_CRLF int crlf=0; -#endif int write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending; SSL_CTX *ctx=NULL; int ret=1,in_init=1,i,nbio_test=0; + int prexit = 0; SSL_METHOD *meth=NULL; BIO *sbio; - /*static struct timeval timeout={10,0};*/ +#ifdef WINDOWS + struct timeval tv; +#endif #if !defined(NO_SSL2) && !defined(NO_SSL3) meth=SSLv23_client_method(); @@ -192,6 +194,7 @@ int MAIN(int argc, char **argv) apps_startup(); c_Pause=0; c_quiet=0; + c_ign_eof=0; c_debug=0; c_showcerts=0; @@ -244,12 +247,17 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; cert_file= *(++argv); } -#ifdef APPS_CRLF + else if (strcmp(*argv,"-prexit") == 0) + prexit=1; else if (strcmp(*argv,"-crlf") == 0) crlf=1; -#endif else if (strcmp(*argv,"-quiet") == 0) + { c_quiet=1; + c_ign_eof=1; + } + else if (strcmp(*argv,"-ign_eof") == 0) + c_ign_eof=1; else if (strcmp(*argv,"-pause") == 0) c_Pause=1; else if (strcmp(*argv,"-debug") == 0) @@ -324,6 +332,8 @@ bad: goto end; } + app_RAND_load_file(NULL, bio_err, 0); + if (bio_c_out == NULL) { if (c_quiet) @@ -337,7 +347,8 @@ bad: } } - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); + SSL_load_error_strings(); ctx=SSL_CTX_new(meth); if (ctx == NULL) { @@ -352,7 +363,11 @@ bad: if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback); if (cipher != NULL) - SSL_CTX_set_cipher_list(ctx,cipher); + if(!SSL_CTX_set_cipher_list(ctx,cipher)) { + BIO_printf(bio_err,"error setting cipher list\n"); + ERR_print_errors(bio_err); + goto end; + } #if 0 else SSL_CTX_set_cipher_list(ctx,getenv("SSL_CIPHER")); @@ -365,14 +380,13 @@ bad: if ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) || (!SSL_CTX_set_default_verify_paths(ctx))) { - /* BIO_printf(bio_err,"error seting default verify locations\n"); */ + /* BIO_printf(bio_err,"error setting default verify locations\n"); */ ERR_print_errors(bio_err); /* goto end; */ } - SSL_load_error_strings(); - con=(SSL *)SSL_new(ctx); + con=SSL_new(ctx); /* SSL_set_cipher_list(con,"RC4-MD5"); */ re_start: @@ -473,12 +487,18 @@ re_start: if (read_tty) FD_SET(fileno(stdin),&readfds); if (write_tty) FD_SET(fileno(stdout),&writefds); } -#endif if (read_ssl) FD_SET(SSL_get_fd(con),&readfds); if (write_ssl) FD_SET(SSL_get_fd(con),&writefds); - +#else + if(!tty_on || !write_tty) { + if (read_ssl) + FD_SET(SSL_get_fd(con),&readfds); + if (write_ssl) + FD_SET(SSL_get_fd(con),&writefds); + } +#endif /* printf("mode tty(%d %d%d) ssl(%d%d)\n", tty_on,read_tty,write_tty,read_ssl,write_ssl);*/ @@ -488,8 +508,29 @@ re_start: * will choke the compiler: if you do have a cast then * you can either go for (int *) or (void *). */ +#ifdef WINDOWS + /* Under Windows we make the assumption that we can + * always write to the tty: therefore if we need to + * write to the tty we just fall through. Otherwise + * we timeout the select every second and see if there + * are any keypresses. Note: this is a hack, in a proper + * Windows application we wouldn't do this. + */ + i=0; + if(!write_tty) { + if(read_tty) { + tv.tv_sec = 1; + tv.tv_usec = 0; + i=select(width,(void *)&readfds,(void *)&writefds, + NULL,&tv); + if(!i && (!_kbhit() || !read_tty) ) continue; + } else i=select(width,(void *)&readfds,(void *)&writefds, + NULL,NULL); + } +#else i=select(width,(void *)&readfds,(void *)&writefds, NULL,NULL); +#endif if ( i < 0) { BIO_printf(bio_err,"bad select %d\n", @@ -566,8 +607,12 @@ re_start: goto shut; } } -#ifndef WINDOWS +#ifdef WINDOWS + /* Assume Windows can always write */ + else if (!ssl_pending && write_tty) +#else else if (!ssl_pending && FD_ISSET(fileno(stdout),&writefds)) +#endif { #ifdef CHARSET_EBCDIC ascii2ebcdic(&(sbuf[sbuf_off]),&(sbuf[sbuf_off]),sbuf_len); @@ -589,7 +634,6 @@ re_start: write_tty=0; } } -#endif else if (ssl_pending || FD_ISSET(SSL_get_fd(con),&readfds)) { #ifdef RENEG @@ -644,10 +688,12 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240 } } -#ifndef WINDOWS +#ifdef WINDOWS + else if (_kbhit()) +#else else if (FD_ISSET(fileno(stdin),&readfds)) +#endif { -#ifdef APPS_CRLF if (crlf) { int j, lf_num; @@ -671,16 +717,15 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240 assert(lf_num == 0); } else -#endif i=read(fileno(stdin),cbuf,BUFSIZZ); - if ((!c_quiet) && ((i <= 0) || (cbuf[0] == 'Q'))) + if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == 'Q'))) { BIO_printf(bio_err,"DONE\n"); goto shut; } - if ((!c_quiet) && (cbuf[0] == 'R')) + if ((!c_ign_eof) && (cbuf[0] == 'R')) { BIO_printf(bio_err,"RENEGOTIATING\n"); SSL_renegotiate(con); @@ -698,13 +743,13 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240 write_ssl=1; read_tty=0; } -#endif } shut: SSL_shutdown(con); SHUTDOWN(SSL_get_fd(con)); ret=0; end: + if(prexit) print_stuff(bio_c_out,con,1); if (con != NULL) SSL_free(con); if (con2 != NULL) SSL_free(con2); if (ctx != NULL) SSL_CTX_free(ctx); diff --git a/crypto/openssl/apps/s_server.c b/crypto/openssl/apps/s_server.c index 9a81418..af19b89 100644 --- a/crypto/openssl/apps/s_server.c +++ b/crypto/openssl/apps/s_server.c @@ -56,9 +56,7 @@ * [including the GNU Public Licence.] */ -#ifdef APPS_CRLF -# include <assert.h> -#endif +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -87,15 +85,15 @@ typedef unsigned int u_int; #include <openssl/ssl.h> #include "s_apps.h" +#ifdef WINDOWS +#include <conio.h> +#endif + #if (defined(VMS) && __VMS_VER < 70000000) /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ #undef FIONBIO #endif -#if defined(NO_RSA) && !defined(NO_SSL2) -#define NO_SSL2 -#endif - #ifndef NO_RSA static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength); #endif @@ -106,10 +104,12 @@ static void sv_usage(void); static int init_ssl_connection(SSL *s); static void print_stats(BIO *bp,SSL_CTX *ctx); #ifndef NO_DH -static DH *load_dh_param(void ); +static DH *load_dh_param(char *dhfile); static DH *get_dh512(void); #endif -/* static void s_server_init(void);*/ +#ifdef MONOLITH +static void s_server_init(void); +#endif #ifndef S_ISDIR # if defined(_S_IFMT) && defined(_S_IFDIR) @@ -149,15 +149,13 @@ static DH *get_dh512(void) #undef BUFSIZZ #define BUFSIZZ 16*1024 -static int bufsize=32; +static int bufsize=BUFSIZZ; static int accept_socket= -1; #define TEST_CERT "server.pem" #undef PROG #define PROG s_server_main -#define DH_PARAM "server.pem" - extern int verify_depth; static char *cipher=NULL; @@ -169,9 +167,7 @@ static char *s_dcert_file=NULL,*s_dkey_file=NULL; static int s_nbio=0; #endif static int s_nbio_test=0; -#ifdef APPS_CRLF /* won't be #ifdef'd in next release */ int s_crlf=0; -#endif static SSL_CTX *ctx=NULL; static int www=0; @@ -179,9 +175,12 @@ static BIO *bio_s_out=NULL; static int s_debug=0; static int s_quiet=0; -#if 0 +static int hack=0; + +#ifdef MONOLITH static void s_server_init(void) { + accept_socket=-1; cipher=NULL; s_server_verify=SSL_VERIFY_NONE; s_dcert_file=NULL; @@ -198,6 +197,7 @@ static void s_server_init(void) bio_s_out=NULL; s_debug=0; s_quiet=0; + hack=0; } #endif @@ -211,17 +211,17 @@ static void sv_usage(void) BIO_printf(bio_err," -Verify arg - turn on peer certificate verification, must have a cert.\n"); BIO_printf(bio_err," -cert arg - certificate file to use, PEM format assumed\n"); BIO_printf(bio_err," (default is %s)\n",TEST_CERT); - BIO_printf(bio_err," -key arg - RSA file to use, PEM format assumed, in cert file if\n"); + BIO_printf(bio_err," -key arg - Private Key file to use, PEM format assumed, in cert file if\n"); BIO_printf(bio_err," not specified (default is %s)\n",TEST_CERT); BIO_printf(bio_err," -dcert arg - second certificate file to use (usually for DSA)\n"); BIO_printf(bio_err," -dkey arg - second private key file to use (usually for DSA)\n"); + BIO_printf(bio_err," -dhparam arg - DH parameter file to use, in cert file if not specified\n"); + BIO_printf(bio_err," or a default set of parameters is used\n"); #ifdef FIONBIO BIO_printf(bio_err," -nbio - Run with non-blocking IO\n"); #endif BIO_printf(bio_err," -nbio_test - test with the non-blocking test bio\n"); -#ifdef APPS_CRLF BIO_printf(bio_err," -crlf - convert LF from terminal into CRLF\n"); -#endif BIO_printf(bio_err," -debug - Print more output\n"); BIO_printf(bio_err," -state - Print the SSL states\n"); BIO_printf(bio_err," -CApath arg - PEM format directory of CA's\n"); @@ -239,14 +239,13 @@ static void sv_usage(void) #ifndef NO_DH BIO_printf(bio_err," -no_dhe - Disable ephemeral DH\n"); #endif - BIO_printf(bio_err," -bugs - Turn on SSL bug compatability\n"); + BIO_printf(bio_err," -bugs - Turn on SSL bug compatibility\n"); BIO_printf(bio_err," -www - Respond to a 'GET /' with a status page\n"); BIO_printf(bio_err," -WWW - Respond to a 'GET /<path> HTTP/1.0' with file ./<path>\n"); } static int local_argc=0; static char **local_argv; -static int hack=0; #ifdef CHARSET_EBCDIC static int ebcdic_new(BIO *bi); @@ -337,7 +336,7 @@ static int ebcdic_write(BIO *b, char *in, int inl) num = num + num; /* double the size */ if (num < inl) num = inl; - Free((char*)wbuf); + Free(wbuf); wbuf=(EBCDIC_OUTBUFF *)Malloc(sizeof(EBCDIC_OUTBUFF) + num); wbuf->alloced = num; @@ -398,11 +397,14 @@ static int ebcdic_puts(BIO *bp, char *str) } #endif +int MAIN(int, char **); + int MAIN(int argc, char *argv[]) { short port=PORT; char *CApath=NULL,*CAfile=NULL; char *context = NULL; + char *dhfile = NULL; int badop=0,bugs=0; int ret=1; int off=0; @@ -425,8 +427,9 @@ int MAIN(int argc, char *argv[]) local_argv=argv; apps_startup(); - s_quiet=0; - s_debug=0; +#ifdef MONOLITH + s_server_init(); +#endif if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); @@ -479,6 +482,11 @@ int MAIN(int argc, char *argv[]) if (--argc < 1) goto bad; s_key_file= *(++argv); } + else if (strcmp(*argv,"-dhparam") == 0) + { + if (--argc < 1) goto bad; + dhfile = *(++argv); + } else if (strcmp(*argv,"-dcert") == 0) { if (--argc < 1) goto bad; @@ -525,10 +533,8 @@ int MAIN(int argc, char *argv[]) { hack=1; } else if (strcmp(*argv,"-state") == 0) { state=1; } -#ifdef APPS_CRLF else if (strcmp(*argv,"-crlf") == 0) { s_crlf=1; } -#endif else if (strcmp(*argv,"-quiet") == 0) { s_quiet=1; } else if (strcmp(*argv,"-bugs") == 0) @@ -575,6 +581,8 @@ bad: goto end; } + app_RAND_load_file(NULL, bio_err, 0); + if (bio_s_out == NULL) { if (s_quiet && !s_debug) @@ -599,7 +607,7 @@ bad: } SSL_load_error_strings(); - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); ctx=SSL_CTX_new(meth); if (ctx == NULL) @@ -641,8 +649,7 @@ bad: #ifndef NO_DH if (!no_dhe) { - /* EAY EAY EAY evil hack */ - dh=load_dh_param(); + dh=load_dh_param(dhfile ? dhfile : s_cert_file); if (dh != NULL) { BIO_printf(bio_s_out,"Setting temp DH parameters\n"); @@ -692,12 +699,17 @@ bad: #endif if (cipher != NULL) - SSL_CTX_set_cipher_list(ctx,cipher); + if(!SSL_CTX_set_cipher_list(ctx,cipher)) { + BIO_printf(bio_err,"error setting cipher list\n"); + ERR_print_errors(bio_err); + goto end; + } SSL_CTX_set_verify(ctx,s_server_verify,verify_callback); SSL_CTX_set_session_id_context(ctx,(void*)&s_server_session_id_context, sizeof s_server_session_id_context); - SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile)); + if (CAfile != NULL) + SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile)); BIO_printf(bio_s_out,"ACCEPT\n"); if (www) @@ -750,6 +762,9 @@ static int sv_body(char *hostname, int s, unsigned char *context) unsigned long l; SSL *con=NULL; BIO *sbio; +#ifdef WINDOWS + struct timeval tv; +#endif if ((buf=Malloc(bufsize)) == NULL) { @@ -769,7 +784,7 @@ static int sv_body(char *hostname, int s, unsigned char *context) #endif if (con == NULL) { - con=(SSL *)SSL_new(ctx); + con=SSL_new(ctx); if(context) SSL_set_session_id_context(con, context, strlen((char *)context)); @@ -798,22 +813,48 @@ static int sv_body(char *hostname, int s, unsigned char *context) width=s+1; for (;;) { - FD_ZERO(&readfds); + int read_from_terminal; + int read_from_sslcon; + + read_from_terminal = 0; + read_from_sslcon = SSL_pending(con); + + if (!read_from_sslcon) + { + FD_ZERO(&readfds); #ifndef WINDOWS - FD_SET(fileno(stdin),&readfds); + FD_SET(fileno(stdin),&readfds); #endif - FD_SET(s,&readfds); - /* Note: under VMS with SOCKETSHR the second parameter is - * currently of type (int *) whereas under other systems - * it is (void *) if you don't have a cast it will choke - * the compiler: if you do have a cast then you can either - * go for (int *) or (void *). - */ - i=select(width,(void *)&readfds,NULL,NULL,NULL); - if (i <= 0) continue; - if (FD_ISSET(fileno(stdin),&readfds)) + FD_SET(s,&readfds); + /* Note: under VMS with SOCKETSHR the second parameter is + * currently of type (int *) whereas under other systems + * it is (void *) if you don't have a cast it will choke + * the compiler: if you do have a cast then you can either + * go for (int *) or (void *). + */ +#ifdef WINDOWS + /* Under Windows we can't select on stdin: only + * on sockets. As a workaround we timeout the select every + * second and check for any keypress. In a proper Windows + * application we wouldn't do this because it is inefficient. + */ + tv.tv_sec = 1; + tv.tv_usec = 0; + i=select(width,(void *)&readfds,NULL,NULL,&tv); + if((i < 0) || (!i && !_kbhit() ) )continue; + if(_kbhit()) + read_from_terminal = 1; +#else + i=select(width,(void *)&readfds,NULL,NULL,NULL); + if (i <= 0) continue; + if (FD_ISSET(fileno(stdin),&readfds)) + read_from_terminal = 1; +#endif + if (FD_ISSET(s,&readfds)) + read_from_sslcon = 1; + } + if (read_from_terminal) { -#ifdef APPS_CRLF if (s_crlf) { int j, lf_num; @@ -837,7 +878,6 @@ static int sv_body(char *hostname, int s, unsigned char *context) assert(lf_num == 0); } else -#endif i=read(fileno(stdin),buf,bufsize); if (!s_quiet) { @@ -926,7 +966,7 @@ static int sv_body(char *hostname, int s, unsigned char *context) if (i <= 0) break; } } - if (FD_ISSET(s,&readfds)) + if (read_from_sslcon) { if (!SSL_is_init_finished(con)) { @@ -1059,12 +1099,12 @@ static int init_ssl_connection(SSL *con) } #ifndef NO_DH -static DH *load_dh_param(void) +static DH *load_dh_param(char *dhfile) { DH *ret=NULL; BIO *bio; - if ((bio=BIO_new_file(DH_PARAM,"r")) == NULL) + if ((bio=BIO_new_file(dhfile,"r")) == NULL) goto err; ret=PEM_read_bio_DHparams(bio,NULL,NULL,NULL); err: @@ -1126,7 +1166,7 @@ static int www_body(char *hostname, int s, unsigned char *context) /* lets make the output buffer a reasonable size */ if (!BIO_set_write_buffer_size(io,bufsize)) goto err; - if ((con=(SSL *)SSL_new(ctx)) == NULL) goto err; + if ((con=SSL_new(ctx)) == NULL) goto err; if(context) SSL_set_session_id_context(con, context, strlen((char *)context)); @@ -1424,7 +1464,7 @@ end: /* make sure we re-use sessions */ SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); #else - /* This kills performace */ + /* This kills performance */ /* SSL_shutdown(con); A shutdown gets sent in the * BIO_free_all(io) procession */ #endif diff --git a/crypto/openssl/apps/s_socket.c b/crypto/openssl/apps/s_socket.c index 888b66d..081b1a5 100644 --- a/crypto/openssl/apps/s_socket.c +++ b/crypto/openssl/apps/s_socket.c @@ -1,4 +1,4 @@ -/* apps/s_socket.c */ +/* apps/s_socket.c - socket-related functions used by s_client and s_server */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -79,16 +79,17 @@ typedef unsigned int u_int; #include "s_apps.h" #include <openssl/ssl.h> -#ifdef VMS -#if (__VMS_VER < 70000000) /* FIONBIO used as a switch to enable ioctl, - and that isn't in VMS < 7.0 */ -#undef FIONBIO -#endif -#include <processes.h> /* for vfork() */ +static struct hostent *GetHostByName(char *name); +#ifdef WINDOWS +static void sock_cleanup(void); #endif +static int sock_init(void); +static int init_client_ip(int *sock,unsigned char ip[4], int port); +static int init_server(int *sock, int port); +static int init_server_long(int *sock, int port,char *ip); +static int do_accept(int acc_sock, int *sock, char **host); +static int host_ip(char *str, unsigned char ip[4]); -static struct hostent *GetHostByName(char *name); -int sock_init(void ); #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ #else @@ -131,19 +132,19 @@ static BOOL CALLBACK enumproc(HWND hwnd,LPARAM lParam) #endif /* WIN32 */ #endif /* WINDOWS */ -void sock_cleanup(void) - { #ifdef WINDOWS +static void sock_cleanup(void) + { if (wsa_init_done) { wsa_init_done=0; WSACancelBlockingCall(); WSACleanup(); } -#endif } +#endif -int sock_init(void) +static int sock_init(void) { #ifdef WINDOWS if (!wsa_init_done) @@ -187,7 +188,7 @@ int init_client(int *sock, char *host, int port) return(init_client_ip(sock,ip,port)); } -int init_client_ip(int *sock, unsigned char ip[4], int port) +static int init_client_ip(int *sock, unsigned char ip[4], int port) { unsigned long addr; struct sockaddr_in them; @@ -218,75 +219,6 @@ int init_client_ip(int *sock, unsigned char ip[4], int port) return(1); } -int nbio_sock_error(int sock) - { - int j,i; - int size; - - size=sizeof(int); - /* Note: under VMS with SOCKETSHR the third parameter is currently - * of type (int *) whereas under other systems it is (void *) if - * you don't have a cast it will choke the compiler: if you do - * have a cast then you can either go for (int *) or (void *). - */ - i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,(void *)&size); - if (i < 0) - return(1); - else - return(j); - } - -int nbio_init_client_ip(int *sock, unsigned char ip[4], int port) - { - unsigned long addr; - struct sockaddr_in them; - int s,i; - - if (!sock_init()) return(0); - - memset((char *)&them,0,sizeof(them)); - them.sin_family=AF_INET; - them.sin_port=htons((unsigned short)port); - addr= (unsigned long) - ((unsigned long)ip[0]<<24L)| - ((unsigned long)ip[1]<<16L)| - ((unsigned long)ip[2]<< 8L)| - ((unsigned long)ip[3]); - them.sin_addr.s_addr=htonl(addr); - - if (*sock <= 0) - { -#ifdef FIONBIO - unsigned long l=1; -#endif - - s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); - if (s == INVALID_SOCKET) { perror("socket"); return(0); } - - i=0; - i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); - if (i < 0) { perror("keepalive"); return(0); } - *sock=s; - -#ifdef FIONBIO - BIO_socket_ioctl(s,FIONBIO,&l); -#endif - } - else - s= *sock; - - i=connect(s,(struct sockaddr *)&them,sizeof(them)); - if (i == INVALID_SOCKET) - { - if (BIO_sock_should_retry(i)) - return(-1); - else - return(0); - } - else - return(1); - } - int do_server(int port, int *ret, int (*cb)(), char *context) { int sock; @@ -319,7 +251,7 @@ int do_server(int port, int *ret, int (*cb)(), char *context) } } -int init_server_long(int *sock, int port, char *ip) +static int init_server_long(int *sock, int port, char *ip) { int ret=0; struct sockaddr_in server; @@ -369,12 +301,12 @@ err: return(ret); } -int init_server(int *sock, int port) +static int init_server(int *sock, int port) { return(init_server_long(sock, port, NULL)); } -int do_accept(int acc_sock, int *sock, char **host) +static int do_accept(int acc_sock, int *sock, char **host) { int ret,i; struct hostent *h1,*h2; @@ -490,7 +422,7 @@ err: return(0); } -int host_ip(char *str, unsigned char ip[4]) +static int host_ip(char *str, unsigned char ip[4]) { unsigned int in[4]; int i; @@ -606,69 +538,3 @@ static struct hostent *GetHostByName(char *name) return(ret); } } - -#ifndef MSDOS -int spawn(int argc, char **argv, int *in, int *out) - { - int pid; -#define CHILD_READ p1[0] -#define CHILD_WRITE p2[1] -#define PARENT_READ p2[0] -#define PARENT_WRITE p1[1] - int p1[2],p2[2]; - - if ((pipe(p1) < 0) || (pipe(p2) < 0)) return(-1); - -#ifdef VMS - if ((pid=vfork()) == 0) -#else - if ((pid=fork()) == 0) -#endif - { /* child */ - if (dup2(CHILD_WRITE,fileno(stdout)) < 0) - perror("dup2"); - if (dup2(CHILD_WRITE,fileno(stderr)) < 0) - perror("dup2"); - if (dup2(CHILD_READ,fileno(stdin)) < 0) - perror("dup2"); - close(CHILD_READ); - close(CHILD_WRITE); - - close(PARENT_READ); - close(PARENT_WRITE); - execvp(argv[0],argv); - perror("child"); - exit(1); - } - - /* parent */ - *in= PARENT_READ; - *out=PARENT_WRITE; - close(CHILD_READ); - close(CHILD_WRITE); - return(pid); - } -#endif /* MSDOS */ - - -#ifdef undef - /* Turn on synchronous sockets so that we can do a WaitForMultipleObjects - * on sockets */ - { - SOCKET s; - int optionValue = SO_SYNCHRONOUS_NONALERT; - int err; - - err = setsockopt( - INVALID_SOCKET, - SOL_SOCKET, - SO_OPENTYPE, - (char *)&optionValue, - sizeof(optionValue)); - if (err != NO_ERROR) { - /* failed for some reason... */ - BIO_printf(bio_err, "failed to setsockopt(SO_OPENTYPE, SO_SYNCHRONOUS_ALERT) - %d\n", - WSAGetLastError()); - } - } -#endif diff --git a/crypto/openssl/apps/s_time.c b/crypto/openssl/apps/s_time.c index a529e2a..39fd3b8 100644 --- a/crypto/openssl/apps/s_time.c +++ b/crypto/openssl/apps/s_time.c @@ -67,10 +67,6 @@ #include <stdlib.h> #include <string.h> -#if defined(NO_RSA) && !defined(NO_SSL2) -#define NO_SSL2 -#endif - #ifdef NO_STDIO #define APPS_WIN16 #endif @@ -220,7 +216,7 @@ static void s_time_usage(void) file if not specified by this option\n\ -CApath arg - PEM format directory of CA's\n\ -CAfile arg - PEM format file of CA's\n\ --cipher - prefered cipher to use, play with 'openssl ciphers'\n\n"; +-cipher - preferred cipher to use, play with 'openssl ciphers'\n\n"; printf( "usage: s_time <args>\n\n" ); @@ -229,7 +225,7 @@ static void s_time_usage(void) printf("-nbio - Run with non-blocking IO\n"); printf("-ssl2 - Just use SSLv2\n"); printf("-ssl3 - Just use SSLv3\n"); - printf("-bugs - Turn on SSL bug compatability\n"); + printf("-bugs - Turn on SSL bug compatibility\n"); printf("-new - Just time new connections\n"); printf("-reuse - Just time connection reuse\n"); printf("-www page - Retrieve 'page' from the site\n"); @@ -248,15 +244,6 @@ static int parseArgs(int argc, char **argv) verify_depth=0; verify_error=X509_V_OK; -#ifdef FIONBIO - t_nbio=0; -#endif - - apps_startup(); - s_time_init(); - - if (bio_err == NULL) - bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); argc--; argv++; @@ -401,6 +388,8 @@ static double tm_Time_F(int s) * MAIN - main processing area for client * real name depends on MONOLITH */ +int MAIN(int, char **); + int MAIN(int argc, char **argv) { double totalTime = 0.0; @@ -411,6 +400,12 @@ int MAIN(int argc, char **argv) MS_STATIC char buf[1024*8]; int ver; + apps_startup(); + s_time_init(); + + if (bio_err == NULL) + bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + #if !defined(NO_SSL2) && !defined(NO_SSL3) s_time_meth=SSLv23_client_method(); #elif !defined(NO_SSL3) @@ -423,7 +418,7 @@ int MAIN(int argc, char **argv) if( parseArgs( argc, argv ) < 0 ) goto end; - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1); SSL_CTX_set_quiet_shutdown(tm_ctx,1); @@ -438,7 +433,7 @@ int MAIN(int argc, char **argv) if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) || (!SSL_CTX_set_default_verify_paths(tm_ctx))) { - /* BIO_printf(bio_err,"error seting default verify locations\n"); */ + /* BIO_printf(bio_err,"error setting default verify locations\n"); */ ERR_print_errors(bio_err); /* goto end; */ } @@ -639,7 +634,7 @@ static SSL *doConnection(SSL *scon) BIO_set_conn_hostname(conn,host); if (scon == NULL) - serverCon=(SSL *)SSL_new(tm_ctx); + serverCon=SSL_new(tm_ctx); else { serverCon=scon; diff --git a/crypto/openssl/apps/sess_id.c b/crypto/openssl/apps/sess_id.c index 8ac118d..71d5aa0 100644 --- a/crypto/openssl/apps/sess_id.c +++ b/crypto/openssl/apps/sess_id.c @@ -72,7 +72,7 @@ static char *sess_id_usage[]={ "usage: sess_id args\n", "\n", -" -inform arg - input format - default PEM (one of DER, TXT or PEM)\n", +" -inform arg - input format - default PEM (DER or PEM)\n", " -outform arg - output format - default PEM\n", " -in arg - input file - default stdin\n", " -out arg - output file - default stdout\n", @@ -84,6 +84,9 @@ NULL }; static SSL_SESSION *load_sess_id(char *file, int format); + +int MAIN(int, char **); + int MAIN(int argc, char **argv) { SSL_SESSION *x=NULL; diff --git a/crypto/openssl/apps/smime.c b/crypto/openssl/apps/smime.c new file mode 100644 index 0000000..7dc66d6 --- /dev/null +++ b/crypto/openssl/apps/smime.c @@ -0,0 +1,535 @@ +/* smime.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* S/MIME utility function */ + +#include <stdio.h> +#include <string.h> +#include "apps.h" +#include <openssl/crypto.h> +#include <openssl/pem.h> +#include <openssl/err.h> + +#undef PROG +#define PROG smime_main +static X509 *load_cert(char *file); +static EVP_PKEY *load_key(char *file, char *pass); +static STACK_OF(X509) *load_certs(char *file); +static X509_STORE *setup_verify(char *CAfile, char *CApath); +static int save_certs(char *signerfile, STACK_OF(X509) *signers); + +#define SMIME_OP 0x10 +#define SMIME_ENCRYPT (1 | SMIME_OP) +#define SMIME_DECRYPT 2 +#define SMIME_SIGN (3 | SMIME_OP) +#define SMIME_VERIFY 4 +#define SMIME_PK7OUT 5 + +int MAIN(int, char **); + +int MAIN(int argc, char **argv) +{ + int operation = 0; + int ret = 0; + char **args; + char *inmode = "r", *outmode = "w"; + char *infile = NULL, *outfile = NULL; + char *signerfile = NULL, *recipfile = NULL; + char *certfile = NULL, *keyfile = NULL; + EVP_CIPHER *cipher = NULL; + PKCS7 *p7 = NULL; + X509_STORE *store = NULL; + X509 *cert = NULL, *recip = NULL, *signer = NULL; + EVP_PKEY *key = NULL; + STACK_OF(X509) *encerts = NULL, *other = NULL; + BIO *in = NULL, *out = NULL, *indata = NULL; + int badarg = 0; + int flags = PKCS7_DETACHED; + char *to = NULL, *from = NULL, *subject = NULL; + char *CAfile = NULL, *CApath = NULL; + char *passargin = NULL, *passin = NULL; + char *inrand = NULL; + int need_rand = 0; + args = argv + 1; + + ret = 1; + + while (!badarg && *args && *args[0] == '-') { + if (!strcmp (*args, "-encrypt")) operation = SMIME_ENCRYPT; + else if (!strcmp (*args, "-decrypt")) operation = SMIME_DECRYPT; + else if (!strcmp (*args, "-sign")) operation = SMIME_SIGN; + else if (!strcmp (*args, "-verify")) operation = SMIME_VERIFY; + else if (!strcmp (*args, "-pk7out")) operation = SMIME_PK7OUT; +#ifndef NO_DES + else if (!strcmp (*args, "-des3")) + cipher = EVP_des_ede3_cbc(); + else if (!strcmp (*args, "-des")) + cipher = EVP_des_cbc(); +#endif +#ifndef NO_RC2 + else if (!strcmp (*args, "-rc2-40")) + cipher = EVP_rc2_40_cbc(); + else if (!strcmp (*args, "-rc2-128")) + cipher = EVP_rc2_cbc(); + else if (!strcmp (*args, "-rc2-64")) + cipher = EVP_rc2_64_cbc(); +#endif + else if (!strcmp (*args, "-text")) + flags |= PKCS7_TEXT; + else if (!strcmp (*args, "-nointern")) + flags |= PKCS7_NOINTERN; + else if (!strcmp (*args, "-noverify")) + flags |= PKCS7_NOVERIFY; + else if (!strcmp (*args, "-nochain")) + flags |= PKCS7_NOCHAIN; + else if (!strcmp (*args, "-nocerts")) + flags |= PKCS7_NOCERTS; + else if (!strcmp (*args, "-noattr")) + flags |= PKCS7_NOATTR; + else if (!strcmp (*args, "-nodetach")) + flags &= ~PKCS7_DETACHED; + else if (!strcmp (*args, "-binary")) + flags |= PKCS7_BINARY; + else if (!strcmp (*args, "-nosigs")) + flags |= PKCS7_NOSIGS; + else if (!strcmp(*args,"-rand")) { + if (args[1]) { + args++; + inrand = *args; + } else badarg = 1; + need_rand = 1; + } else if (!strcmp(*args,"-passin")) { + if (args[1]) { + args++; + passargin = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-to")) { + if (args[1]) { + args++; + to = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-from")) { + if (args[1]) { + args++; + from = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-subject")) { + if (args[1]) { + args++; + subject = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-signer")) { + if (args[1]) { + args++; + signerfile = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-recip")) { + if (args[1]) { + args++; + recipfile = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-inkey")) { + if (args[1]) { + args++; + keyfile = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-certfile")) { + if (args[1]) { + args++; + certfile = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-CAfile")) { + if (args[1]) { + args++; + CAfile = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-CApath")) { + if (args[1]) { + args++; + CApath = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-in")) { + if (args[1]) { + args++; + infile = *args; + } else badarg = 1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + args++; + outfile = *args; + } else badarg = 1; + } else badarg = 1; + args++; + } + + if(operation == SMIME_SIGN) { + if(!signerfile) { + BIO_printf(bio_err, "No signer certificate specified\n"); + badarg = 1; + } + need_rand = 1; + } else if(operation == SMIME_DECRYPT) { + if(!recipfile) { + BIO_printf(bio_err, "No recipient certificate and key specified\n"); + badarg = 1; + } + } else if(operation == SMIME_ENCRYPT) { + if(!*args) { + BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n"); + badarg = 1; + } + need_rand = 1; + } else if(!operation) badarg = 1; + + if (badarg) { + BIO_printf (bio_err, "Usage smime [options] cert.pem ...\n"); + BIO_printf (bio_err, "where options are\n"); + BIO_printf (bio_err, "-encrypt encrypt message\n"); + BIO_printf (bio_err, "-decrypt decrypt encrypted message\n"); + BIO_printf (bio_err, "-sign sign message\n"); + BIO_printf (bio_err, "-verify verify signed message\n"); + BIO_printf (bio_err, "-pk7out output PKCS#7 structure\n"); +#ifndef NO_DES + BIO_printf (bio_err, "-des3 encrypt with triple DES\n"); + BIO_printf (bio_err, "-des encrypt with DES\n"); +#endif +#ifndef NO_RC2 + BIO_printf (bio_err, "-rc2-40 encrypt with RC2-40 (default)\n"); + BIO_printf (bio_err, "-rc2-64 encrypt with RC2-64\n"); + BIO_printf (bio_err, "-rc2-128 encrypt with RC2-128\n"); +#endif + BIO_printf (bio_err, "-nointern don't search certificates in message for signer\n"); + BIO_printf (bio_err, "-nosigs don't verify message signature\n"); + BIO_printf (bio_err, "-noverify don't verify signers certificate\n"); + BIO_printf (bio_err, "-nocerts don't include signers certificate when signing\n"); + BIO_printf (bio_err, "-nodetach use opaque signing\n"); + BIO_printf (bio_err, "-noattr don't include any signed attributes\n"); + BIO_printf (bio_err, "-binary don't translate message to text\n"); + BIO_printf (bio_err, "-certfile file other certificates file\n"); + BIO_printf (bio_err, "-signer file signer certificate file\n"); + BIO_printf (bio_err, "-recip file recipient certificate file for decryption\n"); + BIO_printf (bio_err, "-in file input file\n"); + BIO_printf (bio_err, "-inkey file input private key (if not signer or recipient)\n"); + BIO_printf (bio_err, "-out file output file\n"); + BIO_printf (bio_err, "-to addr to address\n"); + BIO_printf (bio_err, "-from ad from address\n"); + BIO_printf (bio_err, "-subject s subject\n"); + BIO_printf (bio_err, "-text include or delete text MIME headers\n"); + BIO_printf (bio_err, "-CApath dir trusted certificates directory\n"); + BIO_printf (bio_err, "-CAfile file trusted certificates file\n"); + BIO_printf(bio_err, "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err, " load the file (or the files in the directory) into\n"); + BIO_printf(bio_err, " the random number generator\n"); + BIO_printf (bio_err, "cert.pem recipient certificate(s) for encryption\n"); + goto end; + } + + if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) { + BIO_printf(bio_err, "Error getting password\n"); + goto end; + } + + if (need_rand) { + app_RAND_load_file(NULL, bio_err, (inrand != NULL)); + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); + } + + ret = 2; + + if(operation != SMIME_SIGN) flags &= ~PKCS7_DETACHED; + + if(flags & PKCS7_BINARY) { + if(operation & SMIME_OP) inmode = "rb"; + else outmode = "rb"; + } + + if(operation == SMIME_ENCRYPT) { + if (!cipher) { +#ifndef NO_RC2 + cipher = EVP_rc2_40_cbc(); +#else + BIO_printf(bio_err, "No cipher selected\n"); + goto end; +#endif + } + encerts = sk_X509_new_null(); + while (*args) { + if(!(cert = load_cert(*args))) { + BIO_printf(bio_err, "Can't read recipient certificate file %s\n", *args); + goto end; + } + sk_X509_push(encerts, cert); + cert = NULL; + args++; + } + } + + if(signerfile && (operation == SMIME_SIGN)) { + if(!(signer = load_cert(signerfile))) { + BIO_printf(bio_err, "Can't read signer certificate file %s\n", signerfile); + goto end; + } + } + + if(certfile) { + if(!(other = load_certs(certfile))) { + BIO_printf(bio_err, "Can't read certificate file %s\n", certfile); + ERR_print_errors(bio_err); + goto end; + } + } + + if(recipfile && (operation == SMIME_DECRYPT)) { + if(!(recip = load_cert(recipfile))) { + BIO_printf(bio_err, "Can't read recipient certificate file %s\n", recipfile); + ERR_print_errors(bio_err); + goto end; + } + } + + if(operation == SMIME_DECRYPT) { + if(!keyfile) keyfile = recipfile; + } else if(operation == SMIME_SIGN) { + if(!keyfile) keyfile = signerfile; + } else keyfile = NULL; + + if(keyfile) { + if(!(key = load_key(keyfile, passin))) { + BIO_printf(bio_err, "Can't read recipient certificate file %s\n", keyfile); + ERR_print_errors(bio_err); + goto end; + } + } + + if (infile) { + if (!(in = BIO_new_file(infile, inmode))) { + BIO_printf (bio_err, + "Can't open input file %s\n", infile); + goto end; + } + } else in = BIO_new_fp(stdin, BIO_NOCLOSE); + + if (outfile) { + if (!(out = BIO_new_file(outfile, outmode))) { + BIO_printf (bio_err, + "Can't open output file %s\n", outfile); + goto end; + } + } else out = BIO_new_fp(stdout, BIO_NOCLOSE); + + if(operation == SMIME_VERIFY) { + if(!(store = setup_verify(CAfile, CApath))) goto end; + } + + ret = 3; + + if(operation == SMIME_ENCRYPT) { + p7 = PKCS7_encrypt(encerts, in, cipher, flags); + } else if(operation == SMIME_SIGN) { + p7 = PKCS7_sign(signer, key, other, in, flags); + BIO_reset(in); + } else { + if(!(p7 = SMIME_read_PKCS7(in, &indata))) { + BIO_printf(bio_err, "Error reading S/MIME message\n"); + goto end; + } + } + + if(!p7) { + BIO_printf(bio_err, "Error creating PKCS#7 structure\n"); + goto end; + } + + ret = 4; + if(operation == SMIME_DECRYPT) { + if(!PKCS7_decrypt(p7, key, recip, out, flags)) { + BIO_printf(bio_err, "Error decrypting PKCS#7 structure\n"); + goto end; + } + } else if(operation == SMIME_VERIFY) { + STACK_OF(X509) *signers; + if(PKCS7_verify(p7, other, store, indata, out, flags)) { + BIO_printf(bio_err, "Verification Successful\n"); + } else { + BIO_printf(bio_err, "Verification Failure\n"); + goto end; + } + signers = PKCS7_get0_signers(p7, other, flags); + if(!save_certs(signerfile, signers)) { + BIO_printf(bio_err, "Error writing signers to %s\n", + signerfile); + ret = 5; + goto end; + } + sk_X509_free(signers); + } else if(operation == SMIME_PK7OUT) { + PEM_write_bio_PKCS7(out, p7); + } else { + if(to) BIO_printf(out, "To: %s\n", to); + if(from) BIO_printf(out, "From: %s\n", from); + if(subject) BIO_printf(out, "Subject: %s\n", subject); + SMIME_write_PKCS7(out, p7, in, flags); + } + ret = 0; +end: + if (need_rand) + app_RAND_write_file(NULL, bio_err); + if(ret) ERR_print_errors(bio_err); + sk_X509_pop_free(encerts, X509_free); + sk_X509_pop_free(other, X509_free); + X509_STORE_free(store); + X509_free(cert); + X509_free(recip); + X509_free(signer); + EVP_PKEY_free(key); + PKCS7_free(p7); + BIO_free(in); + BIO_free(indata); + BIO_free(out); + if(passin) Free(passin); + return (ret); +} + +static X509 *load_cert(char *file) +{ + BIO *in; + X509 *cert; + if(!(in = BIO_new_file(file, "r"))) return NULL; + cert = PEM_read_bio_X509(in, NULL, NULL,NULL); + BIO_free(in); + return cert; +} + +static EVP_PKEY *load_key(char *file, char *pass) +{ + BIO *in; + EVP_PKEY *key; + if(!(in = BIO_new_file(file, "r"))) return NULL; + key = PEM_read_bio_PrivateKey(in, NULL,NULL,pass); + BIO_free(in); + return key; +} + +static STACK_OF(X509) *load_certs(char *file) +{ + BIO *in; + int i; + STACK_OF(X509) *othercerts; + STACK_OF(X509_INFO) *allcerts; + X509_INFO *xi; + if(!(in = BIO_new_file(file, "r"))) return NULL; + othercerts = sk_X509_new(NULL); + if(!othercerts) return NULL; + allcerts = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); + for(i = 0; i < sk_X509_INFO_num(allcerts); i++) { + xi = sk_X509_INFO_value (allcerts, i); + if (xi->x509) { + sk_X509_push(othercerts, xi->x509); + xi->x509 = NULL; + } + } + sk_X509_INFO_pop_free(allcerts, X509_INFO_free); + BIO_free(in); + return othercerts; +} + +static X509_STORE *setup_verify(char *CAfile, char *CApath) +{ + X509_STORE *store; + X509_LOOKUP *lookup; + if(!(store = X509_STORE_new())) goto end; + lookup=X509_STORE_add_lookup(store,X509_LOOKUP_file()); + if (lookup == NULL) goto end; + if (CAfile) { + if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) { + BIO_printf(bio_err, "Error loading file %s\n", CAfile); + goto end; + } + } else X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT); + + lookup=X509_STORE_add_lookup(store,X509_LOOKUP_hash_dir()); + if (lookup == NULL) goto end; + if (CApath) { + if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) { + BIO_printf(bio_err, "Error loading directory %s\n", CApath); + goto end; + } + } else X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT); + + ERR_clear_error(); + return store; + end: + X509_STORE_free(store); + return NULL; +} + +static int save_certs(char *signerfile, STACK_OF(X509) *signers) +{ + int i; + BIO *tmp; + if(!signerfile) return 1; + tmp = BIO_new_file(signerfile, "w"); + if(!tmp) return 0; + for(i = 0; i < sk_X509_num(signers); i++) + PEM_write_bio_X509(tmp, sk_X509_value(signers, i)); + BIO_free(tmp); + return 1; +} + diff --git a/crypto/openssl/apps/speed.c b/crypto/openssl/apps/speed.c index 3cfb4db..f7a8e00 100644 --- a/crypto/openssl/apps/speed.c +++ b/crypto/openssl/apps/speed.c @@ -238,16 +238,19 @@ static double Time_F(int s) #endif } +int MAIN(int, char **); + int MAIN(int argc, char **argv) { unsigned char *buf=NULL,*buf2=NULL; - int ret=1; + int mret=1; #define ALGOR_NUM 14 #define SIZE_NUM 5 #define RSA_NUM 4 #define DSA_NUM 3 long count,rsa_count; - int i,j,k,rsa_num,rsa_num2; + int i,j,k; + unsigned rsa_num,rsa_num2; #ifndef NO_MD2 unsigned char md2[MD2_DIGEST_LENGTH]; #endif @@ -344,6 +347,7 @@ int MAIN(int argc, char **argv) int pr_header=0; apps_startup(); + memset(results, 0, sizeof(results)); #ifndef NO_DSA memset(dsa_key,0,sizeof(dsa_key)); #endif @@ -421,7 +425,7 @@ int MAIN(int argc, char **argv) if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1; else #endif -#ifndef NO_DEF +#ifndef NO_DES if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1; else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1; else @@ -435,12 +439,14 @@ int MAIN(int argc, char **argv) } else #endif +#ifndef RSA_NULL if (strcmp(*argv,"openssl") == 0) { RSA_set_default_method(RSA_PKCS1_SSLeay()); j--; } else +#endif #endif /* !NO_RSA */ if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2; else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2; @@ -586,9 +592,9 @@ int MAIN(int argc, char **argv) #endif #ifndef NO_DES - des_set_key(&key,sch); - des_set_key(&key2,sch2); - des_set_key(&key3,sch3); + des_set_key_unchecked(&key,sch); + des_set_key_unchecked(&key2,sch2); + des_set_key_unchecked(&key3,sch3); #endif #ifndef NO_IDEA idea_set_encrypt_key(key16,&idea_ks); @@ -612,6 +618,7 @@ int MAIN(int argc, char **argv) memset(rsa_c,0,sizeof(rsa_c)); #endif #ifndef SIGALRM +#ifndef NO_DES BIO_printf(bio_err,"First we calculate the approximate speed ...\n"); count=10; do { @@ -703,10 +710,14 @@ int MAIN(int argc, char **argv) #define COND(d) (count < (d)) #define COUNT(d) (d) #else +/* not worth fixing */ +# error "You cannot disable DES on systems without SIGALRM." +#endif /* NO_DES */ +#else #define COND(c) (run) #define COUNT(d) (count) signal(SIGALRM,sig_done); -#endif +#endif /* SIGALRM */ #ifndef NO_MD2 if (doit[D_MD2]) @@ -956,22 +967,22 @@ int MAIN(int argc, char **argv) } #endif - RAND_bytes(buf,30); + RAND_pseudo_bytes(buf,36); #ifndef NO_RSA for (j=0; j<RSA_NUM; j++) { + int ret; if (!rsa_doit[j]) continue; - rsa_num=RSA_private_encrypt(30,buf,buf2,rsa_key[j], - RSA_PKCS1_PADDING); + ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]); pkey_print_message("private","rsa",rsa_c[j][0],rsa_bits[j], RSA_SECONDS); /* RSA_blinding_on(rsa_key[j],NULL); */ Time_F(START); for (count=0,run=1; COND(rsa_c[j][0]); count++) { - rsa_num=RSA_private_encrypt(30,buf,buf2,rsa_key[j], - RSA_PKCS1_PADDING); - if (rsa_num <= 0) + ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, + rsa_key[j]); + if (ret <= 0) { BIO_printf(bio_err,"RSA private encrypt failure\n"); ERR_print_errors(bio_err); @@ -986,18 +997,17 @@ int MAIN(int argc, char **argv) rsa_count=count; #if 1 - rsa_num2=RSA_public_decrypt(rsa_num,buf2,buf,rsa_key[j], - RSA_PKCS1_PADDING); + ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]); pkey_print_message("public","rsa",rsa_c[j][1],rsa_bits[j], RSA_SECONDS); Time_F(START); for (count=0,run=1; COND(rsa_c[j][1]); count++) { - rsa_num2=RSA_public_decrypt(rsa_num,buf2,buf,rsa_key[j], - RSA_PKCS1_PADDING); - if (rsa_num2 <= 0) + ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, + rsa_key[j]); + if (ret <= 0) { - BIO_printf(bio_err,"RSA public encrypt failure\n"); + BIO_printf(bio_err,"RSA verify failure\n"); ERR_print_errors(bio_err); count=1; break; @@ -1018,8 +1028,13 @@ int MAIN(int argc, char **argv) } #endif - RAND_bytes(buf,20); + RAND_pseudo_bytes(buf,20); #ifndef NO_DSA + if (RAND_status() != 1) + { + RAND_seed(rnd_seed, sizeof rnd_seed); + rnd_fake = 1; + } for (j=0; j<DSA_NUM; j++) { unsigned int kk; @@ -1036,7 +1051,7 @@ int MAIN(int argc, char **argv) { rsa_num=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, &kk,dsa_key[j]); - if (rsa_num <= 0) + if (rsa_num == 0) { BIO_printf(bio_err,"DSA sign failure\n"); ERR_print_errors(bio_err); @@ -1059,7 +1074,7 @@ int MAIN(int argc, char **argv) { rsa_num2=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, kk,dsa_key[j]); - if (rsa_num2 <= 0) + if (rsa_num2 == 0) { BIO_printf(bio_err,"DSA verify failure\n"); ERR_print_errors(bio_err); @@ -1079,6 +1094,7 @@ int MAIN(int argc, char **argv) dsa_doit[j]=0; } } + if (rnd_fake) RAND_cleanup(); #endif fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION)); @@ -1155,7 +1171,7 @@ int MAIN(int argc, char **argv) fprintf(stdout,"\n"); } #endif - ret=0; + mret=0; end: if (buf != NULL) Free(buf); if (buf2 != NULL) Free(buf2); @@ -1169,7 +1185,7 @@ end: if (dsa_key[i] != NULL) DSA_free(dsa_key[i]); #endif - EXIT(ret); + EXIT(mret); } static void print_message(char *s, long num, int length) diff --git a/crypto/openssl/apps/spkac.c b/crypto/openssl/apps/spkac.c new file mode 100644 index 0000000..f3ee7e3 --- /dev/null +++ b/crypto/openssl/apps/spkac.c @@ -0,0 +1,276 @@ +/* apps/spkac.c */ + +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. Based on an original idea by Massimiliano Pala + * (madwolf@openca.org). + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include "apps.h" +#include <openssl/bio.h> +#include <openssl/conf.h> +#include <openssl/err.h> +#include <openssl/evp.h> +#include <openssl/lhash.h> +#include <openssl/x509.h> +#include <openssl/pem.h> + +#undef PROG +#define PROG spkac_main + +/* -in arg - input file - default stdin + * -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; + NETSCAPE_SPKI *spki = NULL; + EVP_PKEY *pkey = NULL; + + apps_startup(); + + if (!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); + + prog=argv[0]; + argc--; + argv++; + while (argc >= 1) + { + if (strcmp(*argv,"-in") == 0) + { + if (--argc < 1) goto bad; + infile= *(++argv); + } + else if (strcmp(*argv,"-out") == 0) + { + 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; + keyfile= *(++argv); + } + else if (strcmp(*argv,"-challenge") == 0) + { + if (--argc < 1) goto bad; + challenge= *(++argv); + } + else if (strcmp(*argv,"-spkac") == 0) + { + if (--argc < 1) goto bad; + spkac= *(++argv); + } + else if (strcmp(*argv,"-spksect") == 0) + { + if (--argc < 1) goto bad; + spksect= *(++argv); + } + else if (strcmp(*argv,"-noout") == 0) + noout=1; + else if (strcmp(*argv,"-pubkey") == 0) + pubkey=1; + else if (strcmp(*argv,"-verify") == 0) + verify=1; + else badops = 1; + argc--; + argv++; + } + + if (badops) + { +bad: + BIO_printf(bio_err,"%s [options]\n",prog); + BIO_printf(bio_err,"where options are\n"); + 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"); + BIO_printf(bio_err," -pubkey output public key\n"); + BIO_printf(bio_err," -verify verify SPKAC signature\n"); + goto end; + } + + 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"); + 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); + if(!pkey) { + BIO_printf(bio_err, "Error reading private key\n"); + ERR_print_errors(bio_err); + goto end; + } + spki = NETSCAPE_SPKI_new(); + if(challenge) ASN1_STRING_set(spki->spkac->challenge, + challenge, strlen(challenge)); + NETSCAPE_SPKI_set_pubkey(spki, pkey); + NETSCAPE_SPKI_sign(spki, pkey, EVP_md5()); + spkstr = NETSCAPE_SPKI_b64_encode(spki); + + if (outfile) out = BIO_new_file(outfile, "w"); + else out = BIO_new_fp(stdout, BIO_NOCLOSE); + + if(!out) { + BIO_printf(bio_err, "Error opening output file\n"); + ERR_print_errors(bio_err); + goto end; + } + BIO_printf(out, "SPKAC=%s\n", spkstr); + Free(spkstr); + ret = 0; + goto end; + } + + + + if (infile) in = BIO_new_file(infile, "r"); + else in = BIO_new_fp(stdin, BIO_NOCLOSE); + + if(!in) { + BIO_printf(bio_err, "Error opening input file\n"); + ERR_print_errors(bio_err); + goto end; + } + + conf = CONF_load_bio(NULL, in, NULL); + + if(!conf) { + BIO_printf(bio_err, "Error parsing config file\n"); + ERR_print_errors(bio_err); + goto end; + } + + spkstr = CONF_get_string(conf, spksect, spkac); + + if(!spkstr) { + BIO_printf(bio_err, "Can't find SPKAC called \"%s\"\n", spkac); + ERR_print_errors(bio_err); + goto end; + } + + spki = NETSCAPE_SPKI_b64_decode(spkstr, -1); + + if(!spki) { + BIO_printf(bio_err, "Error loading SPKAC\n"); + ERR_print_errors(bio_err); + goto end; + } + + if (outfile) out = BIO_new_file(outfile, "w"); + else out = BIO_new_fp(stdout, BIO_NOCLOSE); + + if(!out) { + BIO_printf(bio_err, "Error opening output file\n"); + ERR_print_errors(bio_err); + goto end; + } + + if(!noout) NETSCAPE_SPKI_print(out, spki); + pkey = NETSCAPE_SPKI_get_pubkey(spki); + if(verify) { + i = NETSCAPE_SPKI_verify(spki, pkey); + if(i) BIO_printf(bio_err, "Signature OK\n"); + else { + BIO_printf(bio_err, "Signature Failure\n"); + ERR_print_errors(bio_err); + goto end; + } + } + if(pubkey) PEM_write_bio_PUBKEY(out, pkey); + + ret = 0; + +end: + CONF_free(conf); + NETSCAPE_SPKI_free(spki); + BIO_free(in); + BIO_free(out); + BIO_free(key); + EVP_PKEY_free(pkey); + if(passin) Free(passin); + EXIT(ret); + } diff --git a/crypto/openssl/apps/testdsa.h b/crypto/openssl/apps/testdsa.h index a322978..f0bfbb1 100644 --- a/crypto/openssl/apps/testdsa.h +++ b/crypto/openssl/apps/testdsa.h @@ -1,4 +1,5 @@ /* NOCW */ +/* used by apps/speed.c */ DSA *get_dsa512(void ); DSA *get_dsa1024(void ); DSA *get_dsa2048(void ); @@ -146,3 +147,5 @@ DSA *get_dsa2048() return(dsa); } +static const char rnd_seed[] = "string to make the random number generator think it has entropy"; +static int rnd_fake = 0; diff --git a/crypto/openssl/apps/testrsa.h b/crypto/openssl/apps/testrsa.h index 9a0e811..3007d79 100644 --- a/crypto/openssl/apps/testrsa.h +++ b/crypto/openssl/apps/testrsa.h @@ -1,4 +1,5 @@ /* apps/testrsa.h */ +/* used by apps/speed.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * diff --git a/crypto/openssl/apps/verify.c b/crypto/openssl/apps/verify.c index 093fe09..267ee4e 100644 --- a/crypto/openssl/apps/verify.c +++ b/crypto/openssl/apps/verify.c @@ -63,19 +63,26 @@ #include <openssl/bio.h> #include <openssl/err.h> #include <openssl/x509.h> +#include <openssl/x509v3.h> #include <openssl/pem.h> #undef PROG #define PROG verify_main static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx); -static int check(X509_STORE *ctx,char *file); +static int check(X509_STORE *ctx,char *file, STACK_OF(X509)*other, int purpose); +static STACK_OF(X509) *load_untrusted(char *file); static int v_verbose=0; +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int i,ret=1; + int purpose = -1; char *CApath=NULL,*CAfile=NULL; + char *untfile = NULL; + STACK_OF(X509) *untrusted = NULL; X509_STORE *cert_ctx=NULL; X509_LOOKUP *lookup=NULL; @@ -107,6 +114,24 @@ int MAIN(int argc, char **argv) if (argc-- < 1) goto end; CAfile= *(++argv); } + else if (strcmp(*argv,"-purpose") == 0) + { + X509_PURPOSE *xptmp; + if (argc-- < 1) goto end; + i = X509_PURPOSE_get_by_sname(*(++argv)); + if(i < 0) + { + BIO_printf(bio_err, "unrecognized purpose\n"); + goto end; + } + xptmp = X509_PURPOSE_get0(i); + purpose = X509_PURPOSE_get_id(xptmp); + } + else if (strcmp(*argv,"-untrusted") == 0) + { + if (argc-- < 1) goto end; + untfile= *(++argv); + } else if (strcmp(*argv,"-help") == 0) goto end; else if (strcmp(*argv,"-verbose") == 0) @@ -124,34 +149,63 @@ int MAIN(int argc, char **argv) lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file()); if (lookup == NULL) abort(); - if (!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) - X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT); + if (CAfile) { + i=X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM); + if(!i) { + BIO_printf(bio_err, "Error loading file %s\n", CAfile); + ERR_print_errors(bio_err); + goto end; + } + } else X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT); lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_hash_dir()); if (lookup == NULL) abort(); - if (!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) - X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT); - + if (CApath) { + i=X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM); + if(!i) { + BIO_printf(bio_err, "Error loading directory %s\n", CApath); + ERR_print_errors(bio_err); + goto end; + } + } else X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT); ERR_clear_error(); - if (argc < 1) check(cert_ctx,NULL); + + if(untfile) { + if(!(untrusted = load_untrusted(untfile))) { + BIO_printf(bio_err, "Error loading untrusted file %s\n", untfile); + ERR_print_errors(bio_err); + goto end; + } + } + + if (argc < 1) check(cert_ctx, NULL, untrusted, purpose); else for (i=0; i<argc; i++) - check(cert_ctx,argv[i]); + check(cert_ctx,argv[i], untrusted, purpose); ret=0; end: - if (ret == 1) + if (ret == 1) { BIO_printf(bio_err,"usage: verify [-verbose] [-CApath path] [-CAfile file] cert1 cert2 ...\n"); + BIO_printf(bio_err,"recognized usages:\n"); + for(i = 0; i < X509_PURPOSE_get_count(); i++) { + X509_PURPOSE *ptmp; + ptmp = X509_PURPOSE_get0(i); + BIO_printf(bio_err, "\t%-10s\t%s\n", X509_PURPOSE_get0_sname(ptmp), + X509_PURPOSE_get0_name(ptmp)); + } + } if (cert_ctx != NULL) X509_STORE_free(cert_ctx); + sk_X509_pop_free(untrusted, X509_free); EXIT(ret); } -static int check(X509_STORE *ctx, char *file) +static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, int purpose) { X509 *x=NULL; BIO *in=NULL; int i=0,ret=0; - X509_STORE_CTX csc; + X509_STORE_CTX *csc; in=BIO_new(BIO_s_file()); if (in == NULL) @@ -181,9 +235,16 @@ static int check(X509_STORE *ctx, char *file) } fprintf(stdout,"%s: ",(file == NULL)?"stdin":file); - X509_STORE_CTX_init(&csc,ctx,x,NULL); - i=X509_verify_cert(&csc); - X509_STORE_CTX_cleanup(&csc); + csc = X509_STORE_CTX_new(); + if (csc == NULL) + { + ERR_print_errors(bio_err); + goto end; + } + X509_STORE_CTX_init(csc,ctx,x,uchain); + if(purpose >= 0) X509_STORE_CTX_set_purpose(csc, purpose); + i=X509_verify_cert(csc); + X509_STORE_CTX_free(csc); ret=0; end: @@ -200,27 +261,75 @@ end: return(ret); } +static STACK_OF(X509) *load_untrusted(char *certfile) +{ + STACK_OF(X509_INFO) *sk=NULL; + STACK_OF(X509) *stack=NULL, *ret=NULL; + BIO *in=NULL; + X509_INFO *xi; + + if(!(stack = sk_X509_new_null())) { + BIO_printf(bio_err,"memory allocation failure\n"); + goto end; + } + + if(!(in=BIO_new_file(certfile, "r"))) { + BIO_printf(bio_err,"error opening the file, %s\n",certfile); + goto end; + } + + /* This loads from a file, a stack of x509/crl/pkey sets */ + if(!(sk=PEM_X509_INFO_read_bio(in,NULL,NULL,NULL))) { + BIO_printf(bio_err,"error reading the file, %s\n",certfile); + goto end; + } + + /* scan over it and pull out the certs */ + while (sk_X509_INFO_num(sk)) + { + xi=sk_X509_INFO_shift(sk); + if (xi->x509 != NULL) + { + sk_X509_push(stack,xi->x509); + xi->x509=NULL; + } + X509_INFO_free(xi); + } + if(!sk_X509_num(stack)) { + BIO_printf(bio_err,"no certificates in file, %s\n",certfile); + sk_X509_free(stack); + goto end; + } + ret=stack; +end: + BIO_free(in); + sk_X509_INFO_free(sk); + return(ret); + } + static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx) { char buf[256]; if (!ok) { - /* since we are just checking the certificates, it is - * ok if they are self signed. */ - if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) - ok=1; - else - { - X509_NAME_oneline( + X509_NAME_oneline( X509_get_subject_name(ctx->current_cert),buf,256); - printf("%s\n",buf); - printf("error %d at %d depth lookup:%s\n",ctx->error, - ctx->error_depth, - X509_verify_cert_error_string(ctx->error)); - if (ctx->error == X509_V_ERR_CERT_HAS_EXPIRED) - ok=1; - } + printf("%s\n",buf); + printf("error %d at %d depth lookup:%s\n",ctx->error, + ctx->error_depth, + X509_verify_cert_error_string(ctx->error)); + if (ctx->error == X509_V_ERR_CERT_HAS_EXPIRED) ok=1; + /* since we are just checking the certificates, it is + * ok if they are self signed. But we should still warn + * the user. + */ + if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ok=1; + /* Continue after extension errors too */ + if (ctx->error == X509_V_ERR_INVALID_CA) ok=1; + if (ctx->error == X509_V_ERR_PATH_LENGTH_EXCEEDED) ok=1; + if (ctx->error == X509_V_ERR_INVALID_PURPOSE) ok=1; + if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ok=1; } if (!v_verbose) ERR_clear_error(); diff --git a/crypto/openssl/apps/version.c b/crypto/openssl/apps/version.c index a567f34..f5c9adc 100644 --- a/crypto/openssl/apps/version.c +++ b/crypto/openssl/apps/version.c @@ -66,6 +66,8 @@ #undef PROG #define PROG version_main +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int i,ret=0; diff --git a/crypto/openssl/apps/winrand.c b/crypto/openssl/apps/winrand.c new file mode 100644 index 0000000..d042258 --- /dev/null +++ b/crypto/openssl/apps/winrand.c @@ -0,0 +1,149 @@ +/* apps/winrand.c */ +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* Usage: winrand [filename] + * + * Collects entropy from mouse movements and other events and writes + * random data to filename or .rnd + */ + +#include <windows.h> +#include <openssl/opensslv.h> +#include <openssl/rand.h> + +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +const char *filename; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + PSTR cmdline, int iCmdShow) + { + static char appname[] = "OpenSSL"; + HWND hwnd; + MSG msg; + WNDCLASSEX wndclass; + char buffer[200]; + + if (cmdline[0] == '\0') + filename = RAND_file_name(buffer, sizeof buffer); + else + filename = cmdline; + + RAND_load_file(filename, -1); + + wndclass.cbSize = sizeof(wndclass); + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = appname; + wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + RegisterClassEx(&wndclass); + + hwnd = CreateWindow(appname, OPENSSL_VERSION_TEXT, + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); + + ShowWindow(hwnd, iCmdShow); + UpdateWindow(hwnd); + + + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return msg.wParam; + } + +LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) + { + HDC hdc; + PAINTSTRUCT ps; + RECT rect; + char buffer[200]; + static int seeded = 0; + + switch (iMsg) + { + case WM_PAINT: + hdc = BeginPaint(hwnd, &ps); + GetClientRect(hwnd, &rect); + DrawText(hdc, "Seeding the PRNG. Please move the mouse!", -1, + &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + EndPaint(hwnd, &ps); + return 0; + + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + + if (RAND_event(iMsg, wParam, lParam) == 1 && seeded == 0) + { + seeded = 1; + if (RAND_write_file(filename) <= 0) + MessageBox(hwnd, "Couldn't write random file!", + "OpenSSL", MB_OK | MB_ICONERROR); + PostQuitMessage(0); + } + + return DefWindowProc(hwnd, iMsg, wParam, lParam); + } diff --git a/crypto/openssl/apps/x509.c b/crypto/openssl/apps/x509.c index 2e2d18b..2d63841 100644 --- a/crypto/openssl/apps/x509.c +++ b/crypto/openssl/apps/x509.c @@ -56,6 +56,7 @@ * [including the GNU Public Licence.] */ +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -91,59 +92,78 @@ static char *x509_usage[]={ " -CAkeyform arg - CA key format - default PEM\n", " -in arg - input file - default stdin\n", " -out arg - output file - default stdout\n", +" -passin arg - private key password source\n", " -serial - print serial number value\n", " -hash - print hash value\n", " -subject - print subject DN\n", " -issuer - print issuer DN\n", " -startdate - notBefore field\n", " -enddate - notAfter field\n", +" -purpose - print out certificate purposes\n", " -dates - both Before and After dates\n", " -modulus - print the RSA key modulus\n", +" -pubkey - output the public key\n", " -fingerprint - print the certificate fingerprint\n", +" -alias - output certificate alias\n", " -noout - no certificate output\n", - +" -trustout - output a \"trusted\" certificate\n", +" -clrtrust - clear all trusted purposes\n", +" -clrreject - clear all rejected purposes\n", +" -addtrust arg - trust certificate for a given purpose\n", +" -addreject arg - reject certificate for a given purpose\n", +" -setalias arg - set certificate alias\n", " -days arg - How long till expiry of a signed certificate - def 30 days\n", " -signkey arg - self sign cert with arg\n", " -x509toreq - output a certification request object\n", " -req - input is a certificate request, sign and output.\n", " -CA arg - set the CA certificate, must be PEM format.\n", " -CAkey arg - set the CA key, must be PEM format\n", -" missing, it is asssumed to be in the CA file.\n", +" missing, it is assumed to be in the CA file.\n", " -CAcreateserial - create serial number file if it does not exist\n", " -CAserial - serial file\n", " -text - print the certificate in text form\n", " -C - print out C code forms\n", -" -md2/-md5/-sha1/-mdc2 - digest to do an RSA sign with\n", +" -md2/-md5/-sha1/-mdc2 - digest to use\n", " -extfile - configuration file with X509V3 extensions to add\n", +" -extensions - section from config file with X509V3 extensions to add\n", +" -clrext - delete extensions before signing and input certificate\n", NULL }; static int MS_CALLBACK callb(int ok, X509_STORE_CTX *ctx); -static EVP_PKEY *load_key(char *file, int format); +static EVP_PKEY *load_key(char *file, int format, char *passin); static X509 *load_cert(char *file, int format); -static int sign (X509 *x, EVP_PKEY *pkey,int days,const EVP_MD *digest, +static int sign (X509 *x, EVP_PKEY *pkey,int days,int clrext, const EVP_MD *digest, LHASH *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, LHASH *conf, char *section); + int create,int days, int clrext, LHASH *conf, char *section); +static int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt); static int reqfile=0; +int MAIN(int, char **); + int MAIN(int argc, char **argv) { int ret=1; X509_REQ *req=NULL; X509 *x=NULL,*xca=NULL; + ASN1_OBJECT *objtmp; EVP_PKEY *Upkey=NULL,*CApkey=NULL; int i,num,badops=0; BIO *out=NULL; BIO *STDout=NULL; + STACK_OF(ASN1_OBJECT) *trust = NULL, *reject = NULL; int informat,outformat,keyformat,CAformat,CAkeyformat; char *infile=NULL,*outfile=NULL,*keyfile=NULL,*CAfile=NULL; char *CAkeyfile=NULL,*CAserial=NULL; + char *alias=NULL; int text=0,serial=0,hash=0,subject=0,issuer=0,startdate=0,enddate=0; int noout=0,sign_flag=0,CA_flag=0,CA_createserial=0; + int trustout=0,clrtrust=0,clrreject=0,aliasout=0,clrext=0; int C=0; - int x509req=0,days=DEF_DAYS,modulus=0; + int x509req=0,days=DEF_DAYS,modulus=0,pubkey=0; + int pprint = 0; char **pp; X509_STORE *ctx=NULL; X509_REQ *rq=NULL; @@ -151,7 +171,8 @@ int MAIN(int argc, char **argv) char buf[256]; const EVP_MD *md_alg,*digest=EVP_md5(); LHASH *extconf = NULL; - char *extsect = NULL, *extfile = NULL; + char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL; + int need_rand = 0; reqfile=0; @@ -192,7 +213,10 @@ int MAIN(int argc, char **argv) keyformat=str2fmt(*(++argv)); } else if (strcmp(*argv,"-req") == 0) + { reqfile=1; + need_rand = 1; + } else if (strcmp(*argv,"-CAform") == 0) { if (--argc < 1) goto bad; @@ -213,11 +237,21 @@ int MAIN(int argc, char **argv) goto bad; } } + else if (strcmp(*argv,"-passin") == 0) + { + if (--argc < 1) goto bad; + passargin= *(++argv); + } else if (strcmp(*argv,"-extfile") == 0) { if (--argc < 1) goto bad; extfile= *(++argv); } + else if (strcmp(*argv,"-extensions") == 0) + { + if (--argc < 1) goto bad; + extsect= *(++argv); + } else if (strcmp(*argv,"-in") == 0) { if (--argc < 1) goto bad; @@ -233,12 +267,14 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; keyfile= *(++argv); sign_flag= ++num; + need_rand = 1; } else if (strcmp(*argv,"-CA") == 0) { if (--argc < 1) goto bad; CAfile= *(++argv); CA_flag= ++num; + need_rand = 1; } else if (strcmp(*argv,"-CAkey") == 0) { @@ -250,12 +286,50 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; CAserial= *(++argv); } + else if (strcmp(*argv,"-addtrust") == 0) + { + if (--argc < 1) goto bad; + if(!(objtmp = OBJ_txt2obj(*(++argv), 0))) { + BIO_printf(bio_err, + "Invalid trust object value %s\n", *argv); + goto bad; + } + if(!trust) trust = sk_ASN1_OBJECT_new_null(); + sk_ASN1_OBJECT_push(trust, objtmp); + trustout = 1; + } + else if (strcmp(*argv,"-addreject") == 0) + { + if (--argc < 1) goto bad; + if(!(objtmp = OBJ_txt2obj(*(++argv), 0))) { + BIO_printf(bio_err, + "Invalid reject object value %s\n", *argv); + goto bad; + } + if(!reject) reject = sk_ASN1_OBJECT_new_null(); + sk_ASN1_OBJECT_push(reject, objtmp); + trustout = 1; + } + else if (strcmp(*argv,"-setalias") == 0) + { + if (--argc < 1) goto bad; + alias= *(++argv); + trustout = 1; + } + else if (strcmp(*argv,"-setalias") == 0) + { + if (--argc < 1) goto bad; + alias= *(++argv); + trustout = 1; + } else if (strcmp(*argv,"-C") == 0) C= ++num; else if (strcmp(*argv,"-serial") == 0) serial= ++num; else if (strcmp(*argv,"-modulus") == 0) modulus= ++num; + else if (strcmp(*argv,"-pubkey") == 0) + pubkey= ++num; else if (strcmp(*argv,"-x509toreq") == 0) x509req= ++num; else if (strcmp(*argv,"-text") == 0) @@ -273,15 +347,34 @@ int MAIN(int argc, char **argv) startdate= ++num; enddate= ++num; } + else if (strcmp(*argv,"-purpose") == 0) + pprint= ++num; else if (strcmp(*argv,"-startdate") == 0) startdate= ++num; else if (strcmp(*argv,"-enddate") == 0) enddate= ++num; else if (strcmp(*argv,"-noout") == 0) noout= ++num; + else if (strcmp(*argv,"-trustout") == 0) + trustout= 1; + else if (strcmp(*argv,"-clrtrust") == 0) + clrtrust= ++num; + else if (strcmp(*argv,"-clrreject") == 0) + clrreject= ++num; + else if (strcmp(*argv,"-alias") == 0) + aliasout= ++num; else if (strcmp(*argv,"-CAcreateserial") == 0) CA_createserial= ++num; - else if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL) + else if (strcmp(*argv,"-clrext") == 0) + clrext = 1; +#if 1 /* stay backwards-compatible with 0.9.5; this should go away soon */ + else if (strcmp(*argv,"-crlext") == 0) + { + BIO_printf(bio_err,"use -clrext instead of -crlext\n"); + clrext = 1; + } +#endif + else if ((md_alg=EVP_get_digestbyname(*argv + 1))) { /* ok */ digest=md_alg; @@ -304,8 +397,15 @@ bad: goto end; } + if (need_rand) + app_RAND_load_file(NULL, bio_err, 0); + ERR_load_crypto_strings(); - X509V3_add_standard_extensions(); + + if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) { + BIO_printf(bio_err, "Error getting password\n"); + goto end; + } if (!X509_STORE_set_default_paths(ctx)) { @@ -335,7 +435,7 @@ bad: ,errorline,extfile); goto end; } - if(!(extsect = CONF_get_string(extconf, "default", + if(!extsect && !(extsect = CONF_get_string(extconf, "default", "extensions"))) extsect = "default"; X509V3_set_ctx_test(&ctx2); X509V3_set_conf_lhash(&ctx2, extconf); @@ -425,15 +525,9 @@ bad: X509_gmtime_adj(X509_get_notBefore(x),0); X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days); -#if 0 - X509_PUBKEY_free(ci->key); - ci->key=req->req_info->pubkey; - req->req_info->pubkey=NULL; -#else pkey = X509_REQ_get_pubkey(req); X509_set_pubkey(x,pkey); EVP_PKEY_free(pkey); -#endif } else x=load_cert(infile,informat); @@ -468,6 +562,25 @@ bad: } } + if(alias) X509_alias_set1(x, (unsigned char *)alias, -1); + + if(clrtrust) X509_trust_clear(x); + if(clrreject) X509_reject_clear(x); + + if(trust) { + for(i = 0; i < sk_ASN1_OBJECT_num(trust); i++) { + objtmp = sk_ASN1_OBJECT_value(trust, i); + X509_add1_trust_object(x, objtmp); + } + } + + if(reject) { + for(i = 0; i < sk_ASN1_OBJECT_num(reject); i++) { + objtmp = sk_ASN1_OBJECT_value(reject, i); + X509_add1_reject_object(x, objtmp); + } + } + if (num) { for (i=1; i<=num; i++) @@ -490,10 +603,28 @@ bad: i2a_ASN1_INTEGER(STDout,x->cert_info->serialNumber); BIO_printf(STDout,"\n"); } + else if (aliasout == i) + { + unsigned char *alstr; + alstr = X509_alias_get0(x, NULL); + if(alstr) BIO_printf(STDout,"%s\n", alstr); + else BIO_puts(STDout,"<No Alias>\n"); + } else if (hash == i) { BIO_printf(STDout,"%08lx\n",X509_subject_name_hash(x)); } + else if (pprint == i) + { + X509_PURPOSE *ptmp; + int j; + BIO_printf(STDout, "Certificate purposes:\n"); + for(j = 0; j < X509_PURPOSE_get_count(); j++) + { + ptmp = X509_PURPOSE_get0(j); + purpose_print(STDout, x, ptmp); + } + } else if (modulus == i) { @@ -522,6 +653,21 @@ bad: EVP_PKEY_free(pkey); } else + if (pubkey == i) + { + EVP_PKEY *pkey; + + pkey=X509_get_pubkey(x); + if (pkey == NULL) + { + BIO_printf(bio_err,"Error getting public key\n"); + ERR_print_errors(bio_err); + goto end; + } + PEM_write_bio_PUBKEY(STDout, pkey); + EVP_PKEY_free(pkey); + } + else if (C == i) { unsigned char *d; @@ -598,12 +744,13 @@ bad: unsigned int n; unsigned char md[EVP_MAX_MD_SIZE]; - if (!X509_digest(x,EVP_md5(),md,&n)) + if (!X509_digest(x,digest,md,&n)) { BIO_printf(bio_err,"out of memory\n"); goto end; } - BIO_printf(STDout,"MD5 Fingerprint="); + BIO_printf(STDout,"%s Fingerprint=", + OBJ_nid2sn(EVP_MD_type(digest))); for (j=0; j<(int)n; j++) { BIO_printf(STDout,"%02X%c",md[j], @@ -618,7 +765,7 @@ bad: BIO_printf(bio_err,"Getting Private key\n"); if (Upkey == NULL) { - Upkey=load_key(keyfile,keyformat); + Upkey=load_key(keyfile,keyformat, passin); if (Upkey == NULL) goto end; } #ifndef NO_DSA @@ -626,7 +773,8 @@ bad: digest=EVP_dss1(); #endif - if (!sign(x,Upkey,days,digest, + assert(need_rand); + if (!sign(x,Upkey,days,clrext,digest, extconf, extsect)) goto end; } else if (CA_flag == i) @@ -634,7 +782,7 @@ bad: BIO_printf(bio_err,"Getting CA Private Key\n"); if (CAkeyfile != NULL) { - CApkey=load_key(CAkeyfile,CAkeyformat); + CApkey=load_key(CAkeyfile,CAkeyformat, passin); if (CApkey == NULL) goto end; } #ifndef NO_DSA @@ -642,8 +790,9 @@ bad: digest=EVP_dss1(); #endif + assert(need_rand); if (!x509_certify(ctx,CAfile,digest,x,xca, - CApkey, CAserial,CA_createserial,days, + CApkey, CAserial,CA_createserial,days, clrext, extconf, extsect)) goto end; } @@ -659,13 +808,16 @@ bad: } else { - pk=load_key(keyfile,FORMAT_PEM); + pk=load_key(keyfile,FORMAT_PEM, passin); if (pk == NULL) goto end; } BIO_printf(bio_err,"Generating certificate request\n"); - rq=X509_to_X509_REQ(x,pk,EVP_md5()); + if (pk->type == EVP_PKEY_DSA) + digest=EVP_dss1(); + + rq=X509_to_X509_REQ(x,pk,digest); EVP_PKEY_free(pk); if (rq == NULL) { @@ -690,9 +842,10 @@ bad: if (outformat == FORMAT_ASN1) i=i2d_X509_bio(out,x); - else if (outformat == FORMAT_PEM) - i=PEM_write_bio_X509(out,x); - else if (outformat == FORMAT_NETSCAPE) + else if (outformat == FORMAT_PEM) { + if(trustout) i=PEM_write_bio_X509_AUX(out,x); + else i=PEM_write_bio_X509(out,x); + } else if (outformat == FORMAT_NETSCAPE) { ASN1_HEADER ah; ASN1_OCTET_STRING os; @@ -717,6 +870,8 @@ bad: } ret=0; end: + if (need_rand) + app_RAND_write_file(NULL, bio_err); OBJ_cleanup(); CONF_free(extconf); BIO_free(out); @@ -728,13 +883,15 @@ end: EVP_PKEY_free(Upkey); EVP_PKEY_free(CApkey); X509_REQ_free(rq); - X509V3_EXT_cleanup(); + sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free); + sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free); + if(passin) Free(passin); EXIT(ret); } 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, LHASH *conf, char *section) + int days, int clrext, LHASH *conf, char *section) { int ret=0; BIO *io=NULL; @@ -750,7 +907,7 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, EVP_PKEY_free(upkey); X509_STORE_CTX_init(&xsc,ctx,x,NULL); - buf=(char *)Malloc(EVP_PKEY_size(pkey)*2+ + buf=Malloc(EVP_PKEY_size(pkey)*2+ ((serialfile == NULL) ?(strlen(CAfile)+strlen(POSTFIX)+1) :(strlen(serialfile)))+1); @@ -792,8 +949,8 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, } else { - ASN1_INTEGER_set(bs,0); - BN_zero(serial); + ASN1_INTEGER_set(bs,1); + BN_one(serial); } } else @@ -855,6 +1012,10 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL) goto end; + if(clrext) { + while(X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); + } + if(conf) { X509V3_CTX ctx2; X509_set_version(x,2); /* version 3 certificate */ @@ -909,7 +1070,7 @@ static int MS_CALLBACK callb(int ok, X509_STORE_CTX *ctx) } } -static EVP_PKEY *load_key(char *file, int format) +static EVP_PKEY *load_key(char *file, int format, char *passin) { BIO *key=NULL; EVP_PKEY *pkey=NULL; @@ -930,25 +1091,13 @@ static EVP_PKEY *load_key(char *file, int format) perror(file); goto end; } -#ifndef NO_RSA - if (format == FORMAT_ASN1) + if (format == FORMAT_ASN1) { - RSA *rsa; - - rsa=d2i_RSAPrivateKey_bio(key,NULL); - if (rsa != NULL) - { - if ((pkey=EVP_PKEY_new()) != NULL) - EVP_PKEY_assign_RSA(pkey,rsa); - else - RSA_free(rsa); - } + pkey=d2i_PrivateKey_bio(key, NULL); } - else -#endif - if (format == FORMAT_PEM) + else if (format == FORMAT_PEM) { - pkey=PEM_read_bio_PrivateKey(key,NULL,NULL,NULL); + pkey=PEM_read_bio_PrivateKey(key,NULL,NULL,passin); } else { @@ -1031,7 +1180,7 @@ static X509 *load_cert(char *file, int format) ah->data=NULL; } else if (format == FORMAT_PEM) - x=PEM_read_bio_X509(cert,NULL,NULL,NULL); + x=PEM_read_bio_X509_AUX(cert,NULL,NULL,NULL); else { BIO_printf(bio_err,"bad input format specified for input cert\n"); goto end; @@ -1049,7 +1198,7 @@ end: } /* self sign */ -static int sign(X509 *x, EVP_PKEY *pkey, int days, const EVP_MD *digest, +static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest, LHASH *conf, char *section) { @@ -1071,6 +1220,9 @@ static int sign(X509 *x, EVP_PKEY *pkey, int days, const EVP_MD *digest, goto err; if (!X509_set_pubkey(x,pkey)) goto err; + if(clrext) { + while(X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); + } if(conf) { X509V3_CTX ctx; X509_set_version(x,2); /* version 3 certificate */ @@ -1084,3 +1236,22 @@ err: ERR_print_errors(bio_err); return(0); } + +static int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt) +{ + int id, i, idret; + char *pname; + id = X509_PURPOSE_get_id(pt); + pname = X509_PURPOSE_get0_name(pt); + for(i = 0; i < 2; i++) { + idret = X509_check_purpose(cert, id, i); + BIO_printf(bio, "%s%s : ", pname, i ? " CA" : ""); + if(idret == 1) BIO_printf(bio, "Yes\n"); + else if (idret == 0) BIO_printf(bio, "No\n"); + else BIO_printf(bio, "Yes (WARNING code=%d)\n", idret); + } + return 1; +} + + + |