Skip to content

Commit

Permalink
* Added new files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker committed Sep 21, 2004
0 parents commit d6d6dba
Show file tree
Hide file tree
Showing 51 changed files with 9,905 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Makefile
config.h
config.status
24 changes: 24 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Jun 29, 2004

* MODIFIED: use true/false for boolean options.

Jun 28, 2004

* FIXED: (JW) release of config structure

* FIXED: (JW) Order of closing connection.

* FIXED: (JW) pass length for certificate in callback.

* ADDED: (JW) https.pl demoing a simple HTTPS server

Jun 24, 2004

* MODIFIED: Role of SSL and sockets. The primary socket of a server
or client is kept in the SSL structure.

* FIXED: close socket on ssl_exit/1 on server site.

* ADDED: ssl_thread_setup() to allow for multi-threaded apps.

* Started
144 changes: 144 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
################################################################
# Makefile template for SWI-Prolog SSL interface
#
# This template is used by configure to create Makefile. See
# the file INSTALL for further installation instructions.
#
# License: LGPL
#
# Author: Jan Wielemaker ([email protected])
# Jan van der Steen
################################################################

.SUFFIXES: .tex .dvi .doc .pl

PL=@PL@
PLBASE=@PLBASE@
PLARCH=@PLARCH@
PLINCL=@PLINCL@
PKGDOC=$(PLBASE)/doc/packages
PCEHOME=$(PLBASE)/xpce
EXDIR=$(PKGDOC)/examples/ssl

CC=@CC@
COFLAGS=@COFLAGS@
CWFLAGS=@CWFLAGS@
CMFLAGS=@CMFLAGS@
CIFLAGS=-I.
DEFS=@DEFS@ -DSERVER_CERT_REQUIRED=TRUE -DCLIENT_CERT_REQUIRED=TRUE
CFLAGS=$(COFLAGS) $(CWFLAGS) $(CMFLAGS) $(CIFLAGS) $(DEFS)
LIBS=@LIBS@
NETLIBS=@NETLIBS@

DOCTOTEX=$(PCEHOME)/bin/doc2tex
PLTOTEX=$(PCEHOME)/bin/pl2tex
DOC=ssl
TEX=$(DOC).tex
DVI=$(DOC).dvi
PDF=$(DOC).pdf
RUNTEX=@RUNTEX@

LD=@LD@
LDFLAGS=@LDSOFLAGS@

INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

LIBPL= @PLTARGETS@
TARGETS= @TARGETS@
EXAMPLES= client.pl server.pl https.pl

SSLOBJ= ssl4pl.o ssllib.o ../clib/nonblockio.o ../clib/error.o

all: $(TARGETS)

ssl4pl.@SO@: $(SSLOBJ)
$(LD) $(LDFLAGS) -o $@ $(SSLOBJ) $(LIBS)

install: $(TARGETS) $(LIBPL)
mkdir -p $(PLBASE)/lib/$(PLARCH)
for f in $(TARGETS); do \
$(INSTALL) -m 755 $$f $(PLBASE)/lib/$(PLARCH); \
done
for f in $(LIBPL); do \
$(INSTALL) -m 644 $$f $(PLBASE)/library; \
done
$(PL) -f none -g make -t halt

rpm-install: install

html-install: install-examples
mkdir -p $(PKGDOC)
$(INSTALL) -m 644 $(DOC).html $(PKGDOC)

pdf-install: install-examples
mkdir -p $(PKGDOC)
$(INSTALL) -m 644 $(DOC).pdf $(PKGDOC)

install-examples::
mkdir -p $(EXDIR)
$(INSTALL_DATA) $(EXAMPLES) $(EXDIR)
cp -r etc $(EXDIR)

uninstall::
(cd $(PLBASE)/lib/$(PLARCH) && rm -f $(TARGETS))
(cd $(PLBASE)/library && rm -f $(LIBPL))
rm -r $(EXDIR)
$(PL) -f none -g make -t halt

################################################################
# SSL Certificate stuff
################################################################

servercert:
openssl x509 -inform PEM -text -noout -in etc/server/server-cert.pem

clientcert:
openssl x509 -inform PEM -text -noout -in etc/client/client-cert.pem


################################################################
# Documentation
################################################################

pdf: $(PDF)

$(DVI): $(TEX)
$(RUNTEX) $(DOC)

$(PDF): $(TEX)
$(RUNTEX) --pdf $(DOC)

html: $(TEX)
latex2html $(DOC)
mv html/index.html $(DOC).html
rm -r html

$(TEX): $(DOCTOTEX)

.doc.tex:
$(DOCTOTEX) $*.doc > $*.tex
.pl.tex:
$(PLTOTEX) $*.pl > $*.tex

################################################################
# Check
################################################################

check::
$(PL) -q -f ssl_test.pl -F none -g test,halt -t 'halt(1)'

################################################################
# Clean
################################################################

clean:
rm -f $(OBJ) *~ *.o *% a.out core config.log ssl.tex
$(RUNTEX) --clean ssl

distclean: clean
rm -f $(TARGETS) config.cache config.h config.status Makefile
rm -f $(DOC).aux $(DOC).log $(DOC).out $(DOC).toc
rm -rf html
rm -rf autom4te.cache
71 changes: 71 additions & 0 deletions Makefile.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
################################################################
# Build the SWI-Prolog SSL package for MS-Windows
#
# Author: Jan Wielemaker
#
# Use:
# nmake /f Makefile.mak
# nmake /f Makefile.mak install
################################################################

PLHOME=..\..
!include ..\..\src\rules.mk
PKGDLL=ssl4pl
EXDIR= $(PKGDOC)\examples\ssl
CFLAGS= -D__SWI_PROLOG__ $(CFLAGS)

#
# Constants below are defined in rules.mk
#
LIB=$(LIB);$(OPENSSLLIBDIR)
INCLUDE=$(INCLUDE);$(OPENSSLINCDIR)

EXAMPLES= client.pl server.pl https.pl

OBJ= ssl4pl.obj ssllib.obj ..\clib\nonblockio.obj ..\clib\error.obj

all: $(PKGDLL).dll

$(PKGDLL).dll: $(OBJ)
$(LD) /dll /out:$@ $(LDFLAGS) $(OBJ) $(PLLIB) $(LIBS) \
ssleay32.lib libeay32.lib

!IF "$(CFG)" == "rt"
install: all idll
!ELSE
install: all idll ilib
!ENDIF

idll::
copy $(PKGDLL).dll "$(BINDIR)"
!IF "$(PDB)" == "true"
copy $(PKGDLL).pdb "$(BINDIR)"
!ENDIF

ilib::
copy ssl.pl "$(PLBASE)\library"
$(MAKEINDEX)

xpce-install::

html-install: install-examples
copy ssl.html "$(PKGDOC)"

install-examples::
if not exist "$(EXDIR)/$(NULL)" $(MKDIR) "$(EXDIR)"
@for %f in ($(EXAMPLES)) do @copy %f "$(EXDIR)"
xcopy /Q /S /I /Y etc "$(EXDIR)\etc"
if exist "$(EXDIR)\etc\README.TXT" del "$(EXDIR)\etc\README.TXT"
ren "$(EXDIR)\etc\README" "README.TXT"

uninstall::
del "$(PLBASE)\bin\$(PKGDLL).dll"
del "$(PLBASE)\library\ssl.pl"
$(MAKEINDEX)

clean::
-del *.obj *~ 2>nul

distclean: clean
-del *.dll *.lib *.exe *.pdb *.ilk 2>nul

31 changes: 31 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Server/client implementatie van een SSL socket verbinding
gebouwd bovenop openssl.

* De etc/demoCA is de locale CA die gebruikt is voor het tekenen
van de server en client certificates.
* De certificates zijn aangemaakt met CA.pl.
* Zie etc/README.txt voor een verslag hiervan.
* Client certificate is optioneel en momenteel compile time
in te stellen.
* Server certificate is verplicht.
* De locale etc/demoCA wordt gebruikt om certificates te verifieren.
* De certificates zijn opgeslagen in de etc directory.
* De API en het voorstel aan de klanten van Jan Wielemaker is
te vinden in doc/PROPOSAL.txt
* Het stappenplan is beschreven in doc/PLAN.txt
* Hoewel de laatste openssl library source geinstalleerd is in:
$(HOME)/src/openssl-0.9.7d worden de standaard debian paketten
gebruikt voor administratie en development:
libssl-dev 0.9.6c-2.woody SSL development libraries, header files and
libssl0.9.6 0.9.6c-2.woody SSL shared libraries
openssl 0.9.6c-2.woody Secure Socket Layer (SSL) binary and related
* Test de software met:
$ make veryclean
$ make depend
$ make all
$ ./server &
$ ./client

Jan van der Steen
Tue Jun 1 12:30:29 CEST 2004
11 changes: 11 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* Check out BIO_new() and change X509_NAME_oneline() to X509_NAME_print_ex()
or change it to X509_NAME_print_ex_fp()
+ Get rid of get_peer_cert
+ Callback handler for cert_verify
+ name resolving

Windows environment

1. OpenSSL in rules.mk analoog aan PTHREADLIBDIR?
2. ssl4pl analoog aan socket.dll?
3. ssl package directory met proloog server/client tests en ssl.pl?
82 changes: 82 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**********************************************************************
* Filename: client.c
* Purpose: Implementation of SSL client
* Method: OpenSSL
* Author: [email protected]
* Date: Thu May 27 11:11:06 CEST 2004
**********************************************************************/

#include "ssllib.h"
#include "util.h"


int
main()
{
PL_SSL *config = NULL;
PL_SSL_INSTANCE *instance = NULL;
int sock_inst = -1;

/*
* Initialize ssllib
*/
(void) ssl_lib_init();

/*
* SSL preliminaries, creating context and handle for this session.
*/
if ((config = ssl_init(FALSE)) == NULL) {
exit(EXIT_FAILURE);
}

/*
* Set some more parameters
*/
ssl_set_cacert (config, CACERT);
ssl_set_certf (config, CLIENT_CERTF);
ssl_set_keyf (config, CLIENT_KEYF);
ssl_set_password (config, CLIENT_PASSWD);
ssl_set_cert (config, CLIENT_CERT_REQUIRED);
#if 0
ssl_set_peer_cert (config, SERVER_CERT_REQUIRED);
#endif

#if 1
/*
* Install some callback's
*/
ssl_set_cb_cert_verify(config, util_cb_cert_verify, NULL);
#endif

/*
* Establish TCP layer with SSL layer on top of it
*/
ssl_set_host (config, TEST_HOST);
ssl_set_port (config, TEST_PORT);
if ((config->sock = ssl_socket(config)) < 0) {
exit(EXIT_FAILURE);
}

/*
* Start up the client
*/
if ((sock_inst = ssl_connect(config)) < 0) {
exit(EXIT_FAILURE);
}
if ((instance = ssl_ssl(config, sock_inst)) == NULL) {
exit(EXIT_FAILURE);
}
util_run_test(instance);

/*
* Close down SSL, TCP and free all resources
*/
ssl_close(instance);

/*
* Close down SSL, TCP and free all resources
*/
ssl_exit(config);

exit(EXIT_SUCCESS);
}
Loading

0 comments on commit d6d6dba

Please sign in to comment.