summaryrefslogtreecommitdiff
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
commit8b80ab5a6950ce6515f477624794defd7531642a (patch)
treeaa8303f3806c5615fbeafc4dc82febe3cd7c24dc /src/libstrongswan
parentdb67c87db3c9089ea8d2e14f617bf3d9e2af261f (diff)
downloadvyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.tar.gz
vyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.8)
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/Makefile.am15
-rw-r--r--src/libstrongswan/Makefile.in69
-rw-r--r--src/libstrongswan/asn1/oid.h2
-rw-r--r--src/libstrongswan/asn1/oid.pl2
-rw-r--r--src/libstrongswan/chunk.c22
-rw-r--r--src/libstrongswan/chunk.h7
-rw-r--r--src/libstrongswan/credentials/builder.c12
-rw-r--r--src/libstrongswan/credentials/builder.h17
-rw-r--r--src/libstrongswan/credentials/credential_factory.c161
-rw-r--r--src/libstrongswan/credentials/credential_factory.h15
-rw-r--r--src/libstrongswan/crypto/crypto_factory.c281
-rw-r--r--src/libstrongswan/crypto/crypto_factory.h35
-rw-r--r--src/libstrongswan/database/database.h20
-rw-r--r--src/libstrongswan/fips/Makefile.am19
-rw-r--r--src/libstrongswan/fips/Makefile.in475
-rw-r--r--src/libstrongswan/fips/fips_signer.c10
-rw-r--r--src/libstrongswan/library.c4
-rw-r--r--src/libstrongswan/library.h7
-rw-r--r--src/libstrongswan/plugins/aes/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/agent/Makefile.am12
-rw-r--r--src/libstrongswan/plugins/agent/Makefile.in499
-rw-r--r--src/libstrongswan/plugins/agent/agent_plugin.c59
-rw-r--r--src/libstrongswan/plugins/agent/agent_plugin.h47
-rw-r--r--src/libstrongswan/plugins/agent/agent_private_key.c590
-rw-r--r--src/libstrongswan/plugins/agent/agent_private_key.h48
-rw-r--r--src/libstrongswan/plugins/curl/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/des/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/des/des_plugin.c6
-rw-r--r--src/libstrongswan/plugins/fips_prf/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/gmp/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c26
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_plugin.c12
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c55
-rw-r--r--src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c47
-rw-r--r--src/libstrongswan/plugins/hmac/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/hmac/hmac_plugin.c10
-rw-r--r--src/libstrongswan/plugins/ldap/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/md5/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/mysql/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/mysql/mysql_database.c11
-rw-r--r--src/libstrongswan/plugins/openssl/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_ec_private_key.c39
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_ec_public_key.c37
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_plugin.c42
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c51
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c37
-rw-r--r--src/libstrongswan/plugins/padlock/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/plugin_loader.c37
-rw-r--r--src/libstrongswan/plugins/pubkey/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/pubkey/pubkey_cert.c56
-rw-r--r--src/libstrongswan/plugins/pubkey/pubkey_public_key.c75
-rw-r--r--src/libstrongswan/plugins/random/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/random/random_rng.c3
-rw-r--r--src/libstrongswan/plugins/sha1/Makefile.am3
-rw-r--r--src/libstrongswan/plugins/sha1/Makefile.in10
-rw-r--r--src/libstrongswan/plugins/sha1/sha1_hasher.c115
-rw-r--r--src/libstrongswan/plugins/sha1/sha1_hasher.h21
-rw-r--r--src/libstrongswan/plugins/sha1/sha1_plugin.c7
-rw-r--r--src/libstrongswan/plugins/sha1/sha1_prf.c152
-rw-r--r--src/libstrongswan/plugins/sha1/sha1_prf.h47
-rw-r--r--src/libstrongswan/plugins/sha2/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/sqlite/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/sqlite/sqlite_database.c43
-rw-r--r--src/libstrongswan/plugins/x509/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/x509/x509_ac.c27
-rw-r--r--src/libstrongswan/plugins/x509/x509_cert.c15
-rw-r--r--src/libstrongswan/plugins/x509/x509_crl.c47
-rw-r--r--src/libstrongswan/plugins/x509/x509_ocsp_request.c33
-rw-r--r--src/libstrongswan/plugins/x509/x509_ocsp_response.c42
-rw-r--r--src/libstrongswan/plugins/xcbc/Makefile.in2
-rw-r--r--src/libstrongswan/settings.c43
-rw-r--r--src/libstrongswan/settings.h11
-rw-r--r--src/libstrongswan/utils.c53
-rw-r--r--src/libstrongswan/utils.h25
-rw-r--r--src/libstrongswan/utils/enumerator.c141
-rw-r--r--src/libstrongswan/utils/enumerator.h15
-rw-r--r--src/libstrongswan/utils/identification.c6
-rw-r--r--src/libstrongswan/utils/identification.h18
-rw-r--r--src/libstrongswan/utils/leak_detective.c5
79 files changed, 3110 insertions, 775 deletions
diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am
index 869f9677b..08409d503 100644
--- a/src/libstrongswan/Makefile.am
+++ b/src/libstrongswan/Makefile.am
@@ -156,15 +156,10 @@ if USE_OPENSSL
SUBDIRS += plugins/openssl
endif
-if USE_INTEGRITY_TEST
- noinst_PROGRAMS = fips_signer
- fips_signer_SOURCES = fips/fips_signer.c
- fips_signer_LDADD = libstrongswan.la
-
- BUILT_SOURCES += fips_signature.h
- CLEANFILES = fips_signature.h fips_signer
- AM_CFLAGS += -DSTRONGSWAN_CONF=\"${strongswan_conf}\"
+if USE_AGENT
+ SUBDIRS += plugins/agent
+endif
-fips_signature.h : fips_signer
- ./fips_signer
+if USE_INTEGRITY_TEST
+ SUBDIRS += fips
endif
diff --git a/src/libstrongswan/Makefile.in b/src/libstrongswan/Makefile.in
index fc6e40229..e73411aa6 100644
--- a/src/libstrongswan/Makefile.in
+++ b/src/libstrongswan/Makefile.in
@@ -14,7 +14,6 @@
@SET_MAKE@
-
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -53,9 +52,8 @@ host_triplet = @host@
@USE_SQLITE_TRUE@am__append_18 = plugins/sqlite
@USE_PADLOCK_TRUE@am__append_19 = plugins/padlock
@USE_OPENSSL_TRUE@am__append_20 = plugins/openssl
-@USE_INTEGRITY_TEST_TRUE@noinst_PROGRAMS = fips_signer$(EXEEXT)
-@USE_INTEGRITY_TEST_TRUE@am__append_21 = fips_signature.h
-@USE_INTEGRITY_TEST_TRUE@am__append_22 = -DSTRONGSWAN_CONF=\"${strongswan_conf}\"
+@USE_AGENT_TRUE@am__append_21 = plugins/agent
+@USE_INTEGRITY_TEST_TRUE@am__append_22 = fips
subdir = src/libstrongswan
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -150,12 +148,6 @@ am__libstrongswan_la_SOURCES_DIST = library.c library.h chunk.c \
@USE_INTEGRITY_TEST_TRUE@ plugin_loader.lo $(am__objects_1) \
@USE_INTEGRITY_TEST_TRUE@ fips_canister_end.lo
libstrongswan_la_OBJECTS = $(am_libstrongswan_la_OBJECTS)
-PROGRAMS = $(noinst_PROGRAMS)
-am__fips_signer_SOURCES_DIST = fips/fips_signer.c
-@USE_INTEGRITY_TEST_TRUE@am_fips_signer_OBJECTS = \
-@USE_INTEGRITY_TEST_TRUE@ fips_signer.$(OBJEXT)
-fips_signer_OBJECTS = $(am_fips_signer_OBJECTS)
-@USE_INTEGRITY_TEST_TRUE@fips_signer_DEPENDENCIES = libstrongswan.la
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -168,9 +160,8 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
-SOURCES = $(libstrongswan_la_SOURCES) $(fips_signer_SOURCES)
-DIST_SOURCES = $(am__libstrongswan_la_SOURCES_DIST) \
- $(am__fips_signer_SOURCES_DIST)
+SOURCES = $(libstrongswan_la_SOURCES)
+DIST_SOURCES = $(am__libstrongswan_la_SOURCES_DIST)
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-dvi-recursive install-exec-recursive \
@@ -186,7 +177,7 @@ DIST_SUBDIRS = . plugins/aes plugins/des plugins/md5 plugins/sha1 \
plugins/sha2 plugins/fips_prf plugins/gmp plugins/random \
plugins/hmac plugins/xcbc plugins/x509 plugins/pubkey \
plugins/curl plugins/ldap plugins/mysql plugins/sqlite \
- plugins/padlock plugins/openssl
+ plugins/padlock plugins/openssl plugins/agent fips
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
@@ -303,6 +294,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
@@ -451,10 +444,9 @@ lib_LTLIBRARIES = libstrongswan.la
libstrongswan_la_LIBADD = -lpthread -ldl
INCLUDES = -I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = -DIPSEC_DIR=\"${ipsecdir}\" \
- -DIPSEC_PLUGINDIR=\"${plugindir}\" $(am__append_1) \
- $(am__append_22)
+ -DIPSEC_PLUGINDIR=\"${plugindir}\" $(am__append_1)
EXTRA_DIST = asn1/oid.txt asn1/oid.pl
-BUILT_SOURCES = asn1/oid.c asn1/oid.h $(am__append_21)
+BUILT_SOURCES = asn1/oid.c asn1/oid.h
MAINTAINERCLEANFILES = asn1/oid.c asn1/oid.h
# build plugins with their own Makefile
@@ -464,10 +456,8 @@ SUBDIRS = . $(am__append_3) $(am__append_4) $(am__append_5) \
$(am__append_9) $(am__append_10) $(am__append_11) \
$(am__append_12) $(am__append_13) $(am__append_14) \
$(am__append_15) $(am__append_16) $(am__append_17) \
- $(am__append_18) $(am__append_19) $(am__append_20)
-@USE_INTEGRITY_TEST_TRUE@fips_signer_SOURCES = fips/fips_signer.c
-@USE_INTEGRITY_TEST_TRUE@fips_signer_LDADD = libstrongswan.la
-@USE_INTEGRITY_TEST_TRUE@CLEANFILES = fips_signature.h fips_signer
+ $(am__append_18) $(am__append_19) $(am__append_20) \
+ $(am__append_21) $(am__append_22)
all: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) all-recursive
@@ -532,16 +522,6 @@ clean-libLTLIBRARIES:
libstrongswan.la: $(libstrongswan_la_OBJECTS) $(libstrongswan_la_DEPENDENCIES)
$(LINK) -rpath $(libdir) $(libstrongswan_la_OBJECTS) $(libstrongswan_la_LIBADD) $(LIBS)
-clean-noinstPROGRAMS:
- @list='$(noinst_PROGRAMS)'; for p in $$list; do \
- f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
- echo " rm -f $$p $$f"; \
- rm -f $$p $$f ; \
- done
-fips_signer$(EXEEXT): $(fips_signer_OBJECTS) $(fips_signer_DEPENDENCIES)
- @rm -f fips_signer$(EXEEXT)
- $(LINK) $(fips_signer_OBJECTS) $(fips_signer_LDADD) $(LIBS)
-
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -566,7 +546,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fips.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fips_canister_end.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fips_canister_start.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fips_signer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hasher.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/host.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/identification.Plo@am__quote@
@@ -866,20 +845,6 @@ fips_canister_end.lo: fips/fips_canister_end.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o fips_canister_end.lo `test -f 'fips/fips_canister_end.c' || echo '$(srcdir)/'`fips/fips_canister_end.c
-fips_signer.o: fips/fips_signer.c
-@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT fips_signer.o -MD -MP -MF $(DEPDIR)/fips_signer.Tpo -c -o fips_signer.o `test -f 'fips/fips_signer.c' || echo '$(srcdir)/'`fips/fips_signer.c
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/fips_signer.Tpo $(DEPDIR)/fips_signer.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='fips/fips_signer.c' object='fips_signer.o' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o fips_signer.o `test -f 'fips/fips_signer.c' || echo '$(srcdir)/'`fips/fips_signer.c
-
-fips_signer.obj: fips/fips_signer.c
-@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT fips_signer.obj -MD -MP -MF $(DEPDIR)/fips_signer.Tpo -c -o fips_signer.obj `if test -f 'fips/fips_signer.c'; then $(CYGPATH_W) 'fips/fips_signer.c'; else $(CYGPATH_W) '$(srcdir)/fips/fips_signer.c'; fi`
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/fips_signer.Tpo $(DEPDIR)/fips_signer.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='fips/fips_signer.c' object='fips_signer.obj' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o fips_signer.obj `if test -f 'fips/fips_signer.c'; then $(CYGPATH_W) 'fips/fips_signer.c'; else $(CYGPATH_W) '$(srcdir)/fips/fips_signer.c'; fi`
-
mostlyclean-libtool:
-rm -f *.lo
@@ -1062,7 +1027,7 @@ distdir: $(DISTFILES)
check-am: all-am
check: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) check-recursive
-all-am: Makefile $(LTLIBRARIES) $(PROGRAMS)
+all-am: Makefile $(LTLIBRARIES)
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(libdir)"; do \
@@ -1086,7 +1051,6 @@ install-strip:
mostlyclean-generic:
clean-generic:
- -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
@@ -1099,7 +1063,7 @@ maintainer-clean-generic:
clean: clean-recursive
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
- clean-noinstPROGRAMS mostlyclean-am
+ mostlyclean-am
distclean: distclean-recursive
-rm -rf ./$(DEPDIR)
@@ -1160,8 +1124,8 @@ uninstall-am: uninstall-libLTLIBRARIES
.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
all all-am check check-am clean clean-generic \
- clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS ctags \
- ctags-recursive distclean distclean-compile distclean-generic \
+ clean-libLTLIBRARIES clean-libtool ctags ctags-recursive \
+ distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
@@ -1180,9 +1144,6 @@ asn1/oid.c : asn1/oid.txt asn1/oid.pl
asn1/oid.h : asn1/oid.txt asn1/oid.pl
cd asn1 && $(PERL) oid.pl
-
-@USE_INTEGRITY_TEST_TRUE@fips_signature.h : fips_signer
-@USE_INTEGRITY_TEST_TRUE@ ./fips_signer
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/src/libstrongswan/asn1/oid.h b/src/libstrongswan/asn1/oid.h
index a0fb95f18..72049259a 100644
--- a/src/libstrongswan/asn1/oid.h
+++ b/src/libstrongswan/asn1/oid.h
@@ -1,4 +1,4 @@
-/* Object identifiers (OIDs) used by FreeS/WAN
+/* Object identifiers (OIDs) used by strongSwan
* Copyright (C) 2003-2008 Andreas Steffen, Hochschule fuer Technik Rapperswil
*
* This file has been automatically generated by the script oid.pl
diff --git a/src/libstrongswan/asn1/oid.pl b/src/libstrongswan/asn1/oid.pl
index 04030d3ee..373101cc0 100644
--- a/src/libstrongswan/asn1/oid.pl
+++ b/src/libstrongswan/asn1/oid.pl
@@ -26,7 +26,7 @@ print "oid.pl generating oid.h and oid.c\n";
open(OID_H, ">oid.h")
or die "could not open 'oid.h': $!";
-print OID_H "/* Object identifiers (OIDs) used by FreeS/WAN\n",
+print OID_H "/* Object identifiers (OIDs) used by strongSwan\n",
" * ", $copyright, "\n",
" * \n",
" * ", $automatic, "\n",
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c
index 7e7a7c69d..565f48fb0 100644
--- a/src/libstrongswan/chunk.c
+++ b/src/libstrongswan/chunk.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: chunk.c 3868 2008-04-24 13:26:22Z martin $
+ * $Id: chunk.c 4276 2008-08-22 10:44:51Z martin $
*/
#include <stdio.h>
@@ -298,16 +298,28 @@ static char hex2bin(char hex)
chunk_t chunk_from_hex(chunk_t hex, char *buf)
{
int i, len;
+ bool odd = FALSE;
- len = hex.len / 2;
+ len = (hex.len / 2);
+ if (hex.len % 2)
+ {
+ odd = TRUE;
+ len++;
+ }
if (!buf)
{
buf = malloc(len);
}
- for (i = 0; i < len; i++)
+ /* buffer is filled from the right */
+ memset(buf, 0, len);
+ hex.ptr += hex.len;
+ for (i = len - 1; i >= 0; i--)
{
- buf[i] = hex2bin(*hex.ptr++) << 4;
- buf[i] |= hex2bin(*hex.ptr++);
+ buf[i] = hex2bin(*(--hex.ptr));
+ if (i > 0 || !odd)
+ {
+ buf[i] |= hex2bin(*(--hex.ptr)) << 4;
+ }
}
return chunk_create(buf, len);
}
diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h
index 146b175d6..7e70a2a2d 100644
--- a/src/libstrongswan/chunk.h
+++ b/src/libstrongswan/chunk.h
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: chunk.h 3868 2008-04-24 13:26:22Z martin $
+ * $Id: chunk.h 4276 2008-08-22 10:44:51Z martin $
*/
/**
@@ -100,7 +100,8 @@ chunk_t chunk_to_hex(chunk_t chunk, char *buf, bool uppercase);
/**
* Convert a hex encoded in a binary chunk.
*
- * If buf is supplied, it must hold at least (hex.len / 2).
+ * If buf is supplied, it must hold at least (hex.len / 2) + (hex.len % 2)
+ * bytes. It is filled by the right to give correct values for short inputs.
*
* @param hex hex encoded input data
* @param buf buffer to write decoded data, NULL to malloc
@@ -164,7 +165,7 @@ void chunk_clear(chunk_t *chunk);
/**
* Clone a chunk on heap
*/
-#define chunk_clone(chunk) chunk_create_clone(malloc(chunk.len), chunk)
+#define chunk_clone(chunk) chunk_create_clone((chunk).len ? malloc(chunk.len) : NULL, chunk)
/**
* Clone a chunk on stack
diff --git a/src/libstrongswan/credentials/builder.c b/src/libstrongswan/credentials/builder.c
index c13a8a860..4295b3094 100644
--- a/src/libstrongswan/credentials/builder.c
+++ b/src/libstrongswan/credentials/builder.c
@@ -15,8 +15,9 @@
#include "builder.h"
-ENUM(builder_part_names, BUILD_BLOB_ASN1_DER, BUILD_END,
+ENUM(builder_part_names, BUILD_FROM_FILE, BUILD_END,
"BUILD_FROM_FILE",
+ "BUILD_AGENT_SOCKET",
"BUILD_BLOB_ASN1_DER",
"BUILD_BLOB_ASN1_PEM",
"BUILD_KEY_SIZE",
@@ -36,3 +37,12 @@ ENUM(builder_part_names, BUILD_BLOB_ASN1_DER, BUILD_END,
"BUILD_X509_FLAG",
"BUILD_END",
);
+
+/**
+ * See header.
+ */
+void* builder_free(builder_t *this)
+{
+ free(this);
+ return NULL;
+}
diff --git a/src/libstrongswan/credentials/builder.h b/src/libstrongswan/credentials/builder.h
index 22c106b7a..cd75236ba 100644
--- a/src/libstrongswan/credentials/builder.h
+++ b/src/libstrongswan/credentials/builder.h
@@ -40,6 +40,8 @@ typedef builder_t* (*builder_constructor_t)(int subtype);
enum builder_part_t {
/** path to a file containing an ASN1 blob, char* */
BUILD_FROM_FILE,
+ /** unix socket of a ssh/pgp agent, char* */
+ BUILD_AGENT_SOCKET,
/** DER encoded ASN1 blob, chunk_t */
BUILD_BLOB_ASN1_DER,
/** PEM encoded ASN1 blob, null terminated char* */
@@ -94,8 +96,8 @@ struct builder_t {
/**
* Add a part to the construct.
*
- * Any added parts get owned by the builder/construct, so clone/refcount
- * them if needed.
+ * Any added parts are cloned/refcounted by the builder implementation, a
+ * caller may need to free the passed ressources themself.
*
* @param part kind of part
* @param ... part specific variable argument
@@ -112,4 +114,15 @@ struct builder_t {
void* (*build)(builder_t *this);
};
+/**
+ * Helper macro to cancel a build in a builder
+ */
+#define builder_cancel(builder) { (builder)->add = (void*)nop; \
+ (builder)->build = (void*)builder_free; }
+
+/**
+ * Helper function for a cancelled build.
+ */
+void* builder_free(builder_t *this);
+
#endif /* BUILDER_H_ @}*/
diff --git a/src/libstrongswan/credentials/credential_factory.c b/src/libstrongswan/credentials/credential_factory.c
index 52ee2060d..203317fa4 100644
--- a/src/libstrongswan/credentials/credential_factory.c
+++ b/src/libstrongswan/credentials/credential_factory.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: credential_factory.c 4059 2008-06-11 14:10:02Z martin $
+ * $Id: credential_factory.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "credential_factory.h"
@@ -62,31 +62,36 @@ struct entry_t {
};
/**
- * Implementation of credential_factory_t.create_builder.
+ * type/subtype filter function for builder_enumerator
*/
-static builder_t* create_builder(private_credential_factory_t *this,
- credential_type_t type, int subtype)
+static bool builder_filter(entry_t *data, entry_t **in, builder_t **out)
{
- enumerator_t *enumerator;
- entry_t *entry;
- builder_t *builder = NULL;
-
- this->mutex->lock(this->mutex);
- enumerator = this->constructors->create_enumerator(this->constructors);
- while (enumerator->enumerate(enumerator, &entry))
+ if (data->type == (*in)->type &&
+ data->subtype == (*in)->subtype)
{
- if (entry->type == type && entry->subtype == subtype)
- {
- builder = entry->constructor(subtype);
- if (builder)
- {
- break;
- }
- }
+ *out = (*in)->constructor(data->subtype);
+ return TRUE;
}
- enumerator->destroy(enumerator);
- this->mutex->unlock(this->mutex);
- return builder;
+ return FALSE;
+}
+
+/**
+ * Implementation of credential_factory_t.create_builder_enumerator.
+ */
+static enumerator_t* create_builder_enumerator(
+ private_credential_factory_t *this, credential_type_t type, int subtype)
+{
+ entry_t *data = malloc_thing(entry_t);
+
+ data->type = type;
+ data->subtype = subtype;
+
+ this->mutex->lock(this->mutex);
+ return enumerator_create_cleaner(
+ enumerator_create_filter(
+ this->constructors->create_enumerator(this->constructors),
+ (void*)builder_filter, data, free),
+ (void*)this->mutex->unlock, this->mutex);
}
/**
@@ -135,18 +140,19 @@ static void remove_builder(private_credential_factory_t *this,
static void* create(private_credential_factory_t *this, credential_type_t type,
int subtype, ...)
{
+ enumerator_t *enumerator;
builder_t *builder;
builder_part_t part;
va_list args;
+ void* construct = NULL;
- builder = create_builder(this, type, subtype);
- if (builder)
+ enumerator = create_builder_enumerator(this, type, subtype);
+ while (enumerator->enumerate(enumerator, &builder))
{
va_start(args, subtype);
while (TRUE)
{
part = va_arg(args, builder_part_t);
-
switch (part)
{
case BUILD_END:
@@ -167,6 +173,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type,
continue;
case BUILD_BLOB_ASN1_PEM:
case BUILD_FROM_FILE:
+ case BUILD_AGENT_SOCKET:
case BUILD_SIGNING_KEY:
case BUILD_PUBLIC_KEY:
case BUILD_SUBJECT:
@@ -179,105 +186,25 @@ static void* create(private_credential_factory_t *this, credential_type_t type,
case BUILD_IETF_GROUP_ATTR:
builder->add(builder, part, va_arg(args, void*));
continue;
- default:
- DBG1("builder part %N not supported by factory",
- builder_part_names, part);
- break;
+ /* no default to get a compiler warning */
}
break;
}
va_end(args);
-
- return builder->build(builder);
- }
- else
- {
- DBG1("failed to create a builder for credential type %N,"
- " subtype (%d)", credential_type_names, type, subtype);
- }
-
- /** shredder all data on failure */
- va_start(args, subtype);
- while (TRUE)
- {
- part = va_arg(args, builder_part_t);
- switch (part)
+ construct = builder->build(builder);
+ if (construct)
{
- case BUILD_END:
- break;
- case BUILD_BLOB_ASN1_DER:
- {
- chunk_t chunk = va_arg(args, chunk_t);
- free(chunk.ptr);
- continue;
- }
- case BUILD_SERIAL:
- {
- va_arg(args, chunk_t);
- continue;
- }
- case BUILD_X509_FLAG:
- {
- va_arg(args, x509_flag_t);
- continue;
- }
- case BUILD_KEY_SIZE:
- {
- va_arg(args, u_int);
- continue;
- }
- case BUILD_NOT_BEFORE_TIME:
- case BUILD_NOT_AFTER_TIME:
- {
- va_arg(args, time_t);
- continue;
- }
- case BUILD_SIGNING_KEY:
- {
- private_key_t *private = va_arg(args, private_key_t*);
- private->destroy(private);
- continue;
- }
- case BUILD_PUBLIC_KEY:
- {
- public_key_t *public = va_arg(args, public_key_t*);
- public->destroy(public);
- continue;
- }
- case BUILD_SUBJECT:
- case BUILD_SUBJECT_ALTNAME:
- case BUILD_ISSUER:
- case BUILD_ISSUER_ALTNAME:
- {
- identification_t *id = va_arg(args, identification_t*);
- id->destroy(id);
- continue;
- }
- case BUILD_SIGNING_CERT:
- case BUILD_CA_CERT:
- case BUILD_CERT:
- {
- certificate_t *cert = va_arg(args, certificate_t*);
- cert->destroy(cert);
- continue;
- }
- case BUILD_BLOB_ASN1_PEM:
- case BUILD_FROM_FILE:
- case BUILD_IETF_GROUP_ATTR:
- {
- va_arg(args, void*);
- continue;
- }
- default:
- DBG1("builder part %N not supported by factory",
- builder_part_names, part);
- continue;
+ break;
}
- break;
}
- va_end(args);
- return NULL;
+ enumerator->destroy(enumerator);
+ if (!construct)
+ {
+ DBG1("failed to create a builder for credential type %N,"
+ " subtype (%d)", credential_type_names, type, subtype);
+ }
+ return construct;
}
/**
@@ -298,7 +225,7 @@ credential_factory_t *credential_factory_create()
private_credential_factory_t *this = malloc_thing(private_credential_factory_t);
this->public.create = (void*(*)(credential_factory_t*, credential_type_t type, int subtype, ...))create;
- this->public.create_builder = (builder_t*(*)(credential_factory_t*, credential_type_t type, int subtype))create_builder;
+ this->public.create_builder_enumerator = (enumerator_t*(*)(credential_factory_t*, credential_type_t type, int subtype))create_builder_enumerator;
this->public.add_builder = (void(*)(credential_factory_t*,credential_type_t type, int subtype, builder_constructor_t constructor))add_builder;
this->public.remove_builder = (void(*)(credential_factory_t*,builder_constructor_t constructor))remove_builder;
this->public.destroy = (void(*)(credential_factory_t*))destroy;
diff --git a/src/libstrongswan/credentials/credential_factory.h b/src/libstrongswan/credentials/credential_factory.h
index 873cf8ab2..dc4d62679 100644
--- a/src/libstrongswan/credentials/credential_factory.h
+++ b/src/libstrongswan/credentials/credential_factory.h
@@ -56,6 +56,9 @@ struct credential_factory_t {
*
* The variable argument list takes builder_part_t types followed
* by the type specific value. The list must be terminated using BUILD_END.
+ * All passed parts get cloned/refcounted by the builder implementations,
+ * so free up allocated ressources after successful and unsuccessful
+ * invocations.
*
* @param type credential type to build
* @param subtype subtype specific for type of the credential
@@ -66,14 +69,18 @@ struct credential_factory_t {
int subtype, ...);
/**
- * Create a builder instance to build credentials.
+ * Create an enumerator for a builder type.
+ *
+ * The build() method has to be called on each enumerated builder to
+ * cleanup associated ressources.
*
* @param type type of credentials the builder creates
* @param subtype type specific subtype, such as certificate_type_t
- * @return builder instance
+ * @return enumerator over builder_t
*/
- builder_t* (*create_builder)(credential_factory_t *this,
- credential_type_t type, int subtype);
+ enumerator_t* (*create_builder_enumerator)(credential_factory_t *this,
+ credential_type_t type, int subtype);
+
/**
* Register a builder_t constructor function.
*
diff --git a/src/libstrongswan/crypto/crypto_factory.c b/src/libstrongswan/crypto/crypto_factory.c
index 46fa983b2..9836ed468 100644
--- a/src/libstrongswan/crypto/crypto_factory.c
+++ b/src/libstrongswan/crypto/crypto_factory.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: crypto_factory.c 3806 2008-04-15 05:56:35Z martin $
+ * $Id: crypto_factory.c 4307 2008-08-28 09:24:42Z martin $
*/
#include "crypto_factory.h"
@@ -20,52 +20,19 @@
#include <utils/linked_list.h>
#include <utils/mutex.h>
-typedef struct crypter_entry_t crypter_entry_t;
-struct crypter_entry_t {
- /** encryption algorithm */
- encryption_algorithm_t algo;
- /** associated constructor */
- crypter_constructor_t create;
-};
-
-typedef struct signer_entry_t signer_entry_t;
-struct signer_entry_t {
- /** integrity algorithm */
- integrity_algorithm_t algo;
- /** associated constructor */
- signer_constructor_t create;
-};
-
-typedef struct hasher_entry_t hasher_entry_t;
-struct hasher_entry_t {
- /** hash algorithm */
- hash_algorithm_t algo;
- /** associated constructor */
- hasher_constructor_t create;
-};
-
-typedef struct prf_entry_t prf_entry_t;
-struct prf_entry_t {
- /** hash algorithm */
- pseudo_random_function_t algo;
- /** associated constructor */
- prf_constructor_t create;
-};
-
-typedef struct rng_entry_t rng_entry_t;
-struct rng_entry_t {
- /** quality of randomness */
- rng_quality_t quality;
- /** associated constructor */
- rng_constructor_t create;
-};
-
-typedef struct dh_entry_t dh_entry_t;
-struct dh_entry_t {
- /** hash algorithm */
- diffie_hellman_group_t group;
- /** associated constructor */
- dh_constructor_t create;
+typedef struct entry_t entry_t;
+struct entry_t {
+ /** algorithm */
+ u_int algo;
+ /* constructor */
+ union {
+ crypter_constructor_t create_crypter;
+ signer_constructor_t create_signer;
+ hasher_constructor_t create_hasher;
+ prf_constructor_t create_prf;
+ rng_constructor_t create_rng;
+ dh_constructor_t create_dh;
+ };
};
typedef struct private_crypto_factory_t private_crypto_factory_t;
@@ -81,32 +48,32 @@ struct private_crypto_factory_t {
crypto_factory_t public;
/**
- * registered crypters, as crypter_entry_t
+ * registered crypters, as entry_t
*/
linked_list_t *crypters;
/**
- * registered signers, as signer_entry_t
+ * registered signers, as entry_t
*/
linked_list_t *signers;
/**
- * registered hashers, as hasher_entry_t
+ * registered hashers, as entry_t
*/
linked_list_t *hashers;
/**
- * registered prfs, as prf_entry_t
+ * registered prfs, as entry_t
*/
linked_list_t *prfs;
/**
- * registered rngs, as rng_entry_t
+ * registered rngs, as entry_t
*/
linked_list_t *rngs;
/**
- * registered diffie hellman, as dh_entry_t
+ * registered diffie hellman, as entry_t
*/
linked_list_t *dhs;
@@ -123,7 +90,7 @@ static crypter_t* create_crypter(private_crypto_factory_t *this,
encryption_algorithm_t algo, size_t key_size)
{
enumerator_t *enumerator;
- crypter_entry_t *entry;
+ entry_t *entry;
crypter_t *crypter = NULL;
this->mutex->lock(this->mutex);
@@ -132,7 +99,7 @@ static crypter_t* create_crypter(private_crypto_factory_t *this,
{
if (entry->algo == algo)
{
- crypter = entry->create(algo, key_size);
+ crypter = entry->create_crypter(algo, key_size);
if (crypter)
{
break;
@@ -151,7 +118,7 @@ static signer_t* create_signer(private_crypto_factory_t *this,
integrity_algorithm_t algo)
{
enumerator_t *enumerator;
- signer_entry_t *entry;
+ entry_t *entry;
signer_t *signer = NULL;
this->mutex->lock(this->mutex);
@@ -160,7 +127,7 @@ static signer_t* create_signer(private_crypto_factory_t *this,
{
if (entry->algo == algo)
{
- signer = entry->create(algo);
+ signer = entry->create_signer(algo);
if (signer)
{
break;
@@ -180,7 +147,7 @@ static hasher_t* create_hasher(private_crypto_factory_t *this,
hash_algorithm_t algo)
{
enumerator_t *enumerator;
- hasher_entry_t *entry;
+ entry_t *entry;
hasher_t *hasher = NULL;
this->mutex->lock(this->mutex);
@@ -189,7 +156,7 @@ static hasher_t* create_hasher(private_crypto_factory_t *this,
{
if (algo == HASH_PREFERRED || entry->algo == algo)
{
- hasher = entry->create(entry->algo);
+ hasher = entry->create_hasher(entry->algo);
if (hasher)
{
break;
@@ -208,7 +175,7 @@ static prf_t* create_prf(private_crypto_factory_t *this,
pseudo_random_function_t algo)
{
enumerator_t *enumerator;
- prf_entry_t *entry;
+ entry_t *entry;
prf_t *prf = NULL;
this->mutex->lock(this->mutex);
@@ -217,7 +184,7 @@ static prf_t* create_prf(private_crypto_factory_t *this,
{
if (entry->algo == algo)
{
- prf = entry->create(algo);
+ prf = entry->create_prf(algo);
if (prf)
{
break;
@@ -235,7 +202,7 @@ static prf_t* create_prf(private_crypto_factory_t *this,
static rng_t* create_rng(private_crypto_factory_t *this, rng_quality_t quality)
{
enumerator_t *enumerator;
- rng_entry_t *entry;
+ entry_t *entry;
u_int diff = ~0;
rng_constructor_t constr = NULL;
@@ -243,10 +210,10 @@ static rng_t* create_rng(private_crypto_factory_t *this, rng_quality_t quality)
enumerator = this->rngs->create_enumerator(this->rngs);
while (enumerator->enumerate(enumerator, &entry))
{ /* find the best matching quality, but at least as good as requested */
- if (entry->quality >= quality && diff > entry->quality - quality)
+ if (entry->algo >= quality && diff > entry->algo - quality)
{
- diff = entry->quality - quality;
- constr = entry->create;
+ diff = entry->algo - quality;
+ constr = entry->create_rng;
if (diff == 0)
{ /* perfect match, won't get better */
break;
@@ -269,16 +236,16 @@ static diffie_hellman_t* create_dh(private_crypto_factory_t *this,
diffie_hellman_group_t group)
{
enumerator_t *enumerator;
- dh_entry_t *entry;
+ entry_t *entry;
diffie_hellman_t *diffie_hellman = NULL;
this->mutex->lock(this->mutex);
enumerator = this->dhs->create_enumerator(this->dhs);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->group == group)
+ if (entry->algo == group)
{
- diffie_hellman = entry->create(group);
+ diffie_hellman = entry->create_dh(group);
if (diffie_hellman)
{
break;
@@ -297,10 +264,10 @@ static void add_crypter(private_crypto_factory_t *this,
encryption_algorithm_t algo,
crypter_constructor_t create)
{
- crypter_entry_t *entry = malloc_thing(crypter_entry_t);
+ entry_t *entry = malloc_thing(entry_t);
entry->algo = algo;
- entry->create = create;
+ entry->create_crypter = create;
this->mutex->lock(this->mutex);
this->crypters->insert_last(this->crypters, entry);
this->mutex->unlock(this->mutex);
@@ -312,14 +279,14 @@ static void add_crypter(private_crypto_factory_t *this,
static void remove_crypter(private_crypto_factory_t *this,
crypter_constructor_t create)
{
- crypter_entry_t *entry;
+ entry_t *entry;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->crypters->create_enumerator(this->crypters);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->create == create)
+ if (entry->create_crypter == create)
{
this->crypters->remove_at(this->crypters, enumerator);
free(entry);
@@ -335,10 +302,10 @@ static void remove_crypter(private_crypto_factory_t *this,
static void add_signer(private_crypto_factory_t *this,
integrity_algorithm_t algo, signer_constructor_t create)
{
- signer_entry_t *entry = malloc_thing(signer_entry_t);
+ entry_t *entry = malloc_thing(entry_t);
entry->algo = algo;
- entry->create = create;
+ entry->create_signer = create;
this->mutex->lock(this->mutex);
this->signers->insert_last(this->signers, entry);
this->mutex->unlock(this->mutex);
@@ -350,14 +317,14 @@ static void add_signer(private_crypto_factory_t *this,
static void remove_signer(private_crypto_factory_t *this,
signer_constructor_t create)
{
- signer_entry_t *entry;
+ entry_t *entry;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->signers->create_enumerator(this->signers);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->create == create)
+ if (entry->create_signer == create)
{
this->signers->remove_at(this->signers, enumerator);
free(entry);
@@ -373,10 +340,10 @@ static void remove_signer(private_crypto_factory_t *this,
static void add_hasher(private_crypto_factory_t *this, hash_algorithm_t algo,
hasher_constructor_t create)
{
- hasher_entry_t *entry = malloc_thing(hasher_entry_t);
+ entry_t *entry = malloc_thing(entry_t);
entry->algo = algo;
- entry->create = create;
+ entry->create_hasher = create;
this->mutex->lock(this->mutex);
this->hashers->insert_last(this->hashers, entry);
this->mutex->unlock(this->mutex);
@@ -388,14 +355,14 @@ static void add_hasher(private_crypto_factory_t *this, hash_algorithm_t algo,
static void remove_hasher(private_crypto_factory_t *this,
hasher_constructor_t create)
{
- hasher_entry_t *entry;
+ entry_t *entry;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->hashers->create_enumerator(this->hashers);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->create == create)
+ if (entry->create_hasher == create)
{
this->hashers->remove_at(this->hashers, enumerator);
free(entry);
@@ -411,10 +378,10 @@ static void remove_hasher(private_crypto_factory_t *this,
static void add_prf(private_crypto_factory_t *this,
pseudo_random_function_t algo, prf_constructor_t create)
{
- prf_entry_t *entry = malloc_thing(prf_entry_t);
+ entry_t *entry = malloc_thing(entry_t);
entry->algo = algo;
- entry->create = create;
+ entry->create_prf = create;
this->mutex->lock(this->mutex);
this->prfs->insert_last(this->prfs, entry);
this->mutex->unlock(this->mutex);
@@ -425,14 +392,14 @@ static void add_prf(private_crypto_factory_t *this,
*/
static void remove_prf(private_crypto_factory_t *this, prf_constructor_t create)
{
- prf_entry_t *entry;
+ entry_t *entry;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->prfs->create_enumerator(this->prfs);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->create == create)
+ if (entry->create_prf == create)
{
this->prfs->remove_at(this->prfs, enumerator);
free(entry);
@@ -448,10 +415,10 @@ static void remove_prf(private_crypto_factory_t *this, prf_constructor_t create)
static void add_rng(private_crypto_factory_t *this, rng_quality_t quality,
rng_constructor_t create)
{
- rng_entry_t *entry = malloc_thing(rng_entry_t);
+ entry_t *entry = malloc_thing(entry_t);
- entry->quality = quality;
- entry->create = create;
+ entry->algo = quality;
+ entry->create_rng = create;
this->mutex->lock(this->mutex);
this->rngs->insert_last(this->rngs, entry);
this->mutex->unlock(this->mutex);
@@ -462,14 +429,14 @@ static void add_rng(private_crypto_factory_t *this, rng_quality_t quality,
*/
static void remove_rng(private_crypto_factory_t *this, rng_constructor_t create)
{
- rng_entry_t *entry;
+ entry_t *entry;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->rngs->create_enumerator(this->rngs);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->create == create)
+ if (entry->create_rng == create)
{
this->rngs->remove_at(this->rngs, enumerator);
free(entry);
@@ -485,10 +452,10 @@ static void remove_rng(private_crypto_factory_t *this, rng_constructor_t create)
static void add_dh(private_crypto_factory_t *this, diffie_hellman_group_t group,
dh_constructor_t create)
{
- dh_entry_t *entry = malloc_thing(dh_entry_t);
+ entry_t *entry = malloc_thing(entry_t);
- entry->group = group;
- entry->create = create;
+ entry->algo = group;
+ entry->create_dh = create;
this->mutex->lock(this->mutex);
this->dhs->insert_last(this->dhs, entry);
this->mutex->unlock(this->mutex);
@@ -499,14 +466,14 @@ static void add_dh(private_crypto_factory_t *this, diffie_hellman_group_t group,
*/
static void remove_dh(private_crypto_factory_t *this, dh_constructor_t create)
{
- dh_entry_t *entry;
+ entry_t *entry;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->dhs->create_enumerator(this->dhs);
while (enumerator->enumerate(enumerator, &entry))
{
- if (entry->create == create)
+ if (entry->create_dh == create)
{
this->dhs->remove_at(this->dhs, enumerator);
free(entry);
@@ -517,6 +484,127 @@ static void remove_dh(private_crypto_factory_t *this, dh_constructor_t create)
}
/**
+ * match algorithms of an entry?
+ */
+static bool entry_match(entry_t *a, entry_t *b)
+{
+ return a->algo == b->algo;
+}
+
+/**
+ * check for uniqueness of an entry
+ */
+static bool unique_check(linked_list_t *list, entry_t **in, entry_t **out)
+{
+ if (list->find_first(list, (void*)entry_match, NULL, *in) == SUCCESS)
+ {
+ return FALSE;
+ }
+ *out = *in;
+ list->insert_last(list, *in);
+ return TRUE;
+}
+
+/**
+ * create an enumerator over entry->algo in list with locking and unique check
+ */
+static enumerator_t *create_enumerator(private_crypto_factory_t *this,
+ linked_list_t *list, void *filter)
+{
+ this->mutex->lock(this->mutex);
+ return enumerator_create_filter(
+ enumerator_create_filter(
+ list->create_enumerator(list), (void*)unique_check,
+ linked_list_create(), (void*)list->destroy),
+ filter, this->mutex, (void*)this->mutex->unlock);
+}
+
+/**
+ * Filter function to enumerate algorithm, not entry
+ */
+static bool crypter_filter(void *n, entry_t **entry, encryption_algorithm_t *algo)
+{
+ *algo = (*entry)->algo;
+ return TRUE;
+}
+
+/**
+ * Implementation of crypto_factory_t.create_crypter_enumerator
+ */
+static enumerator_t* create_crypter_enumerator(private_crypto_factory_t *this)
+{
+ return create_enumerator(this, this->crypters, crypter_filter);
+}
+
+/**
+ * Filter function to enumerate algorithm, not entry
+ */
+static bool signer_filter(void *n, entry_t **entry, integrity_algorithm_t *algo)
+{
+ *algo = (*entry)->algo;
+ return TRUE;
+}
+
+/**
+ * Implementation of crypto_factory_t.create_signer_enumerator
+ */
+static enumerator_t* create_signer_enumerator(private_crypto_factory_t *this)
+{
+ return create_enumerator(this, this->signers, signer_filter);
+}
+
+/**
+ * Filter function to enumerate algorithm, not entry
+ */
+static bool hasher_filter(void *n, entry_t **entry, hash_algorithm_t *algo)
+{
+ *algo = (*entry)->algo;
+ return TRUE;
+}
+
+/**
+ * Implementation of crypto_factory_t.create_hasher_enumerator
+ */
+static enumerator_t* create_hasher_enumerator(private_crypto_factory_t *this)
+{
+ return create_enumerator(this, this->hashers, hasher_filter);
+}
+
+/**
+ * Filter function to enumerate algorithm, not entry
+ */
+static bool prf_filter(void *n, entry_t **entry, pseudo_random_function_t *algo)
+{
+ *algo = (*entry)->algo;
+ return TRUE;
+}
+
+/**
+ * Implementation of crypto_factory_t.create_prf_enumerator
+ */
+static enumerator_t* create_prf_enumerator(private_crypto_factory_t *this)
+{
+ return create_enumerator(this, this->prfs, prf_filter);
+}
+
+/**
+ * Filter function to enumerate algorithm, not entry
+ */
+static bool dh_filter(void *n, entry_t **entry, diffie_hellman_group_t *group)
+{
+ *group = (*entry)->algo;
+ return TRUE;
+}
+
+/**
+ * Implementation of crypto_factory_t.create_dh_enumerator
+ */
+static enumerator_t* create_dh_enumerator(private_crypto_factory_t *this)
+{
+ return create_enumerator(this, this->dhs, dh_filter);
+}
+
+/**
* Implementation of crypto_factory_t.destroy
*/
static void destroy(private_crypto_factory_t *this)
@@ -556,6 +644,11 @@ crypto_factory_t *crypto_factory_create()
this->public.remove_rng = (void(*)(crypto_factory_t*, rng_constructor_t create))remove_rng;
this->public.add_dh = (void(*)(crypto_factory_t*, diffie_hellman_group_t algo, dh_constructor_t create))add_dh;
this->public.remove_dh = (void(*)(crypto_factory_t*, dh_constructor_t create))remove_dh;
+ this->public.create_crypter_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_crypter_enumerator;
+ this->public.create_signer_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_signer_enumerator;
+ this->public.create_hasher_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_hasher_enumerator;
+ this->public.create_prf_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_prf_enumerator;
+ this->public.create_dh_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_dh_enumerator;
this->public.destroy = (void(*)(crypto_factory_t*))destroy;
this->crypters = linked_list_create();
diff --git a/src/libstrongswan/crypto/crypto_factory.h b/src/libstrongswan/crypto/crypto_factory.h
index 6bf070c31..cdb9b47ba 100644
--- a/src/libstrongswan/crypto/crypto_factory.h
+++ b/src/libstrongswan/crypto/crypto_factory.h
@@ -222,6 +222,41 @@ struct crypto_factory_t {
void (*remove_dh)(crypto_factory_t *this, dh_constructor_t create);
/**
+ * Create an enumerator over all registered crypter algorithms.
+ *
+ * @return enumerator over encryption_algorithm_t
+ */
+ enumerator_t* (*create_crypter_enumerator)(crypto_factory_t *this);
+
+ /**
+ * Create an enumerator over all registered signer algorithms.
+ *
+ * @return enumerator over integrity_algorithm_t
+ */
+ enumerator_t* (*create_signer_enumerator)(crypto_factory_t *this);
+
+ /**
+ * Create an enumerator over all registered hasher algorithms.
+ *
+ * @return enumerator over hash_algorithm_t
+ */
+ enumerator_t* (*create_hasher_enumerator)(crypto_factory_t *this);
+
+ /**
+ * Create an enumerator over all registered PRFs.
+ *
+ * @return enumerator over pseudo_random_function_t
+ */
+ enumerator_t* (*create_prf_enumerator)(crypto_factory_t *this);
+
+ /**
+ * Create an enumerator over all registered diffie hellman groups.
+ *
+ * @return enumerator over diffie_hellman_group_t
+ */
+ enumerator_t* (*create_dh_enumerator)(crypto_factory_t *this);
+
+ /**
* Destroy a crypto_factory instance.
*/
void (*destroy)(crypto_factory_t *this);
diff --git a/src/libstrongswan/database/database.h b/src/libstrongswan/database/database.h
index 1cf5c2542..39f909cd7 100644
--- a/src/libstrongswan/database/database.h
+++ b/src/libstrongswan/database/database.h
@@ -22,6 +22,7 @@
#define DATABASE_H_
typedef enum db_type_t db_type_t;
+typedef enum db_driver_t db_driver_t;
typedef struct database_t database_t;
#include <utils/enumerator.h>
@@ -44,6 +45,15 @@ enum db_type_t {
DB_NULL,
};
+/**
+ * Database implementation type.
+ */
+enum db_driver_t {
+ /** SQLite database */
+ DB_SQLITE,
+ /** MySQL database */
+ DB_MYSQL,
+};
/**
* Interface for a database implementation.
@@ -95,6 +105,16 @@ struct database_t {
int (*execute)(database_t *this, int *rowid, char *sql, ...);
/**
+ * Get the database implementation type.
+ *
+ * To allow driver specific SQL or performance optimizations each database
+ * implementations can be queried for its type.
+ *
+ * @return database implementation type
+ */
+ db_driver_t (*get_driver)(database_t *this);
+
+ /**
* Destroy a database connection.
*/
void (*destroy)(database_t *this);
diff --git a/src/libstrongswan/fips/Makefile.am b/src/libstrongswan/fips/Makefile.am
new file mode 100644
index 000000000..22a35701b
--- /dev/null
+++ b/src/libstrongswan/fips/Makefile.am
@@ -0,0 +1,19 @@
+noinst_PROGRAMS = fips_signer
+fips_signer_SOURCES = fips_signer.c
+fips_signer_LDADD = ../libstrongswan.la
+
+BUILT_SOURCES = fips_signature.h
+CLEANFILES = fips_signature.h fips_signer
+INCLUDES = -I$(top_srcdir)/src/libstrongswan
+AM_CFLAGS = -DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
+ -DPLUGINDIR=\"${top_srcdir}/src/libstrongswan/plugins\"
+if USE_SHA1
+ AM_CFLAGS += -DUSE_SHA1
+endif
+
+if USE_OPENSSL
+ AM_CFLAGS += -DUSE_OPENSSL
+endif
+
+fips_signature.h : fips_signer
+ ./fips_signer
diff --git a/src/libstrongswan/fips/Makefile.in b/src/libstrongswan/fips/Makefile.in
new file mode 100644
index 000000000..9814d631f
--- /dev/null
+++ b/src/libstrongswan/fips/Makefile.in
@@ -0,0 +1,475 @@
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+noinst_PROGRAMS = fips_signer$(EXEEXT)
+@USE_SHA1_TRUE@am__append_1 = -DUSE_SHA1
+@USE_OPENSSL_TRUE@am__append_2 = -DUSE_OPENSSL
+subdir = src/libstrongswan/fips
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+PROGRAMS = $(noinst_PROGRAMS)
+am_fips_signer_OBJECTS = fips_signer.$(OBJEXT)
+fips_signer_OBJECTS = $(am_fips_signer_OBJECTS)
+fips_signer_DEPENDENCIES = ../libstrongswan.la
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(fips_signer_SOURCES)
+DIST_SOURCES = $(fips_signer_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GPERF = @GPERF@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IPSEC_ROUTING_TABLE = @IPSEC_ROUTING_TABLE@
+IPSEC_ROUTING_TABLE_PRIO = @IPSEC_ROUTING_TABLE_PRIO@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LINUX_HEADERS = @LINUX_HEADERS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NMEDIT = @NMEDIT@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PERL = @PERL@
+PKG_CONFIG = @PKG_CONFIG@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+YACC = @YACC@
+YFLAGS = @YFLAGS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+confdir = @confdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+gtk_CFLAGS = @gtk_CFLAGS@
+gtk_LIBS = @gtk_LIBS@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+ipsecdir = @ipsecdir@
+ipsecgroup = @ipsecgroup@
+ipsecuser = @ipsecuser@
+libdir = @libdir@
+libexecdir = @libexecdir@
+libstrongswan_plugins = @libstrongswan_plugins@
+linuxdir = @linuxdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+piddir = @piddir@
+plugindir = @plugindir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+resolv_conf = @resolv_conf@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+simreader = @simreader@
+srcdir = @srcdir@
+strongswan_conf = @strongswan_conf@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+xml_CFLAGS = @xml_CFLAGS@
+xml_LIBS = @xml_LIBS@
+fips_signer_SOURCES = fips_signer.c
+fips_signer_LDADD = ../libstrongswan.la
+BUILT_SOURCES = fips_signature.h
+CLEANFILES = fips_signature.h fips_signer
+INCLUDES = -I$(top_srcdir)/src/libstrongswan
+AM_CFLAGS = -DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
+ -DPLUGINDIR=\"${top_srcdir}/src/libstrongswan/plugins\" \
+ $(am__append_1) $(am__append_2)
+all: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libstrongswan/fips/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src/libstrongswan/fips/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+clean-noinstPROGRAMS:
+ @list='$(noinst_PROGRAMS)'; for p in $$list; do \
+ f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f $$p $$f"; \
+ rm -f $$p $$f ; \
+ done
+fips_signer$(EXEEXT): $(fips_signer_OBJECTS) $(fips_signer_DEPENDENCIES)
+ @rm -f fips_signer$(EXEEXT)
+ $(LINK) $(fips_signer_OBJECTS) $(fips_signer_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fips_signer.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+install: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+ -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-noinstPROGRAMS ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags uninstall uninstall-am
+
+
+fips_signature.h : fips_signer
+ ./fips_signer
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/libstrongswan/fips/fips_signer.c b/src/libstrongswan/fips/fips_signer.c
index 81a5874f7..4bf8b38dd 100644
--- a/src/libstrongswan/fips/fips_signer.c
+++ b/src/libstrongswan/fips/fips_signer.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: fips_signer.c 3964 2008-05-15 14:01:26Z martin $
+ * $Id: fips_signer.c 4258 2008-08-19 18:51:30Z andreas $
*/
#include <stdio.h>
@@ -28,7 +28,13 @@ int main(int argc, char* argv[])
/* initialize library */
library_init(STRONGSWAN_CONF);
- lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "sha1 hmac");
+#ifdef USE_SHA1
+ lib->plugins->load(lib->plugins, PLUGINDIR "/sha1/.libs", "sha1");
+#endif
+#ifdef USE_OPENSSL
+ lib->plugins->load(lib->plugins, PLUGINDIR "/openssl/.libs", "openssl");
+#endif
+ lib->plugins->load(lib->plugins, PLUGINDIR "/hmac/.libs", "hmac");
if (!fips_compute_hmac_signature(hmac_key, hmac_signature))
{
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c
index cc3ee6bd6..07d08fa51 100644
--- a/src/libstrongswan/library.c
+++ b/src/libstrongswan/library.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: library.c 3750 2008-04-04 11:38:16Z martin $
+ * $Id: library.c 4311 2008-08-28 16:27:48Z martin $
*/
#include "library.h"
@@ -86,6 +86,8 @@ void library_init(char *settings)
private_library_t *this = malloc_thing(private_library_t);
lib = &this->public;
+ lib->leak_detective = FALSE;
+
#ifdef LEAK_DETECTIVE
this->detective = leak_detective_create();
#endif /* LEAK_DETECTIVE */
diff --git a/src/libstrongswan/library.h b/src/libstrongswan/library.h
index 6cb57ef20..34a981054 100644
--- a/src/libstrongswan/library.h
+++ b/src/libstrongswan/library.h
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: library.h 3589 2008-03-13 14:14:44Z martin $
+ * $Id: library.h 4311 2008-08-28 16:27:48Z martin $
*/
/**
@@ -108,6 +108,11 @@ struct library_t {
* various settings loaded from settings file
*/
settings_t *settings;
+
+ /**
+ * is leak detective running?
+ */
+ bool leak_detective;
};
/**
diff --git a/src/libstrongswan/plugins/aes/Makefile.in b/src/libstrongswan/plugins/aes/Makefile.in
index ed3dfb621..55faa07f0 100644
--- a/src/libstrongswan/plugins/aes/Makefile.in
+++ b/src/libstrongswan/plugins/aes/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/agent/Makefile.am b/src/libstrongswan/plugins/agent/Makefile.am
new file mode 100644
index 000000000..bc022aa26
--- /dev/null
+++ b/src/libstrongswan/plugins/agent/Makefile.am
@@ -0,0 +1,12 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan
+
+AM_CFLAGS = -rdynamic
+
+plugin_LTLIBRARIES = libstrongswan-agent.la
+
+libstrongswan_agent_la_SOURCES = agent_plugin.h agent_plugin.c \
+ agent_private_key.c agent_private_key.h
+
+libstrongswan_agent_la_LDFLAGS = -module
+
diff --git a/src/libstrongswan/plugins/agent/Makefile.in b/src/libstrongswan/plugins/agent/Makefile.in
new file mode 100644
index 000000000..eb38b537a
--- /dev/null
+++ b/src/libstrongswan/plugins/agent/Makefile.in
@@ -0,0 +1,499 @@
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src/libstrongswan/plugins/agent
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(plugindir)"
+pluginLTLIBRARIES_INSTALL = $(INSTALL)
+LTLIBRARIES = $(plugin_LTLIBRARIES)
+libstrongswan_agent_la_LIBADD =
+am_libstrongswan_agent_la_OBJECTS = agent_plugin.lo \
+ agent_private_key.lo
+libstrongswan_agent_la_OBJECTS = $(am_libstrongswan_agent_la_OBJECTS)
+libstrongswan_agent_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(libstrongswan_agent_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libstrongswan_agent_la_SOURCES)
+DIST_SOURCES = $(libstrongswan_agent_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GPERF = @GPERF@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IPSEC_ROUTING_TABLE = @IPSEC_ROUTING_TABLE@
+IPSEC_ROUTING_TABLE_PRIO = @IPSEC_ROUTING_TABLE_PRIO@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LINUX_HEADERS = @LINUX_HEADERS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NMEDIT = @NMEDIT@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PERL = @PERL@
+PKG_CONFIG = @PKG_CONFIG@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+YACC = @YACC@
+YFLAGS = @YFLAGS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+confdir = @confdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+gtk_CFLAGS = @gtk_CFLAGS@
+gtk_LIBS = @gtk_LIBS@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+ipsecdir = @ipsecdir@
+ipsecgroup = @ipsecgroup@
+ipsecuser = @ipsecuser@
+libdir = @libdir@
+libexecdir = @libexecdir@
+libstrongswan_plugins = @libstrongswan_plugins@
+linuxdir = @linuxdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+piddir = @piddir@
+plugindir = @plugindir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+resolv_conf = @resolv_conf@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+simreader = @simreader@
+srcdir = @srcdir@
+strongswan_conf = @strongswan_conf@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+xml_CFLAGS = @xml_CFLAGS@
+xml_LIBS = @xml_LIBS@
+INCLUDES = -I$(top_srcdir)/src/libstrongswan
+AM_CFLAGS = -rdynamic
+plugin_LTLIBRARIES = libstrongswan-agent.la
+libstrongswan_agent_la_SOURCES = agent_plugin.h agent_plugin.c \
+ agent_private_key.c agent_private_key.h
+
+libstrongswan_agent_la_LDFLAGS = -module
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libstrongswan/plugins/agent/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src/libstrongswan/plugins/agent/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(plugindir)" || $(MKDIR_P) "$(DESTDIR)$(plugindir)"
+ @list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+ if test -f $$p; then \
+ f=$(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(pluginLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(plugindir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(pluginLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(plugindir)/$$f"; \
+ else :; fi; \
+ done
+
+uninstall-pluginLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+ p=$(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(plugindir)/$$p'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(plugindir)/$$p"; \
+ done
+
+clean-pluginLTLIBRARIES:
+ -test -z "$(plugin_LTLIBRARIES)" || rm -f $(plugin_LTLIBRARIES)
+ @list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libstrongswan-agent.la: $(libstrongswan_agent_la_OBJECTS) $(libstrongswan_agent_la_DEPENDENCIES)
+ $(libstrongswan_agent_la_LINK) -rpath $(plugindir) $(libstrongswan_agent_la_OBJECTS) $(libstrongswan_agent_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/agent_plugin.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/agent_private_key.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(plugindir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-pluginLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am: install-pluginLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pluginLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-pluginLTLIBRARIES ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-pluginLTLIBRARIES \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-pluginLTLIBRARIES
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/libstrongswan/plugins/agent/agent_plugin.c b/src/libstrongswan/plugins/agent/agent_plugin.c
new file mode 100644
index 000000000..474171ad1
--- /dev/null
+++ b/src/libstrongswan/plugins/agent/agent_plugin.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * $Id$
+ */
+
+#include "agent_plugin.h"
+
+#include <library.h>
+#include "agent_private_key.h"
+
+typedef struct private_agent_plugin_t private_agent_plugin_t;
+
+/**
+ * private data of agent_plugin
+ */
+struct private_agent_plugin_t {
+
+ /**
+ * public functions
+ */
+ agent_plugin_t public;
+};
+
+/**
+ * Implementation of agent_plugin_t.agenttroy
+ */
+static void destroy(private_agent_plugin_t *this)
+{
+ lib->creds->remove_builder(lib->creds,
+ (builder_constructor_t)agent_private_key_builder);
+ free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *plugin_create()
+{
+ private_agent_plugin_t *this = malloc_thing(private_agent_plugin_t);
+
+ this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+
+ lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
+ (builder_constructor_t)agent_private_key_builder);
+ return &this->public.plugin;
+}
+
diff --git a/src/libstrongswan/plugins/agent/agent_plugin.h b/src/libstrongswan/plugins/agent/agent_plugin.h
new file mode 100644
index 000000000..d12dd44ac
--- /dev/null
+++ b/src/libstrongswan/plugins/agent/agent_plugin.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup agent_p agent
+ * @ingroup plugins
+ *
+ * @defgroup agent_plugin agent_plugin
+ * @{ @ingroup agent_p
+ */
+
+#ifndef AGENT_PLUGIN_H_
+#define AGENT_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct agent_plugin_t agent_plugin_t;
+
+/**
+ * Plugin to use private keys loaded in a ssh-agent.
+ */
+struct agent_plugin_t {
+
+ /**
+ * implements plugin interface
+ */
+ plugin_t plugin;
+};
+
+/**
+ * Create a agent_plugin instance.
+ */
+plugin_t *plugin_create();
+
+#endif /* AGENT_PLUGIN_H_ @}*/
diff --git a/src/libstrongswan/plugins/agent/agent_private_key.c b/src/libstrongswan/plugins/agent/agent_private_key.c
new file mode 100644
index 000000000..a3b8eebf3
--- /dev/null
+++ b/src/libstrongswan/plugins/agent/agent_private_key.c
@@ -0,0 +1,590 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * $Id$
+ */
+
+#include "agent_private_key.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <arpa/inet.h>
+#include <errno.h>
+
+#include <library.h>
+#include <chunk.h>
+#include <debug.h>
+#include <asn1/asn1.h>
+#include <asn1/oid.h>
+
+#ifndef UNIX_PATH_MAX
+#define UNIX_PATH_MAX 108
+#endif /* UNIX_PATH_MAX */
+
+typedef struct private_agent_private_key_t private_agent_private_key_t;
+typedef enum agent_msg_type_t agent_msg_type_t;
+
+/**
+ * Private data of a agent_private_key_t object.
+ */
+struct private_agent_private_key_t {
+ /**
+ * Public interface for this signer.
+ */
+ agent_private_key_t public;
+
+ /**
+ * ssh-agent unix socket connection
+ */
+ int socket;
+
+ /**
+ * key identity blob in ssh format
+ */
+ chunk_t key;
+
+ /**
+ * keysize in bytes
+ */
+ size_t key_size;
+
+ /**
+ * Keyid formed as a SHA-1 hash of a publicKey object
+ */
+ identification_t* keyid;
+
+ /**
+ * Keyid formed as a SHA-1 hash of a publicKeyInfo object
+ */
+ identification_t* keyid_info;
+
+ /**
+ * reference count
+ */
+ refcount_t ref;
+};
+
+/**
+ * Message types for ssh-agent protocol
+ */
+enum agent_msg_type_t {
+ SSH_AGENT_FAILURE = 5,
+ SSH_AGENT_SUCCESS = 6,
+ SSH_AGENT_ID_REQUEST = 11,
+ SSH_AGENT_ID_RESPONSE = 12,
+ SSH_AGENT_SIGN_REQUEST = 13,
+ SSH_AGENT_SIGN_RESPONSE = 14,
+};
+
+/**
+ * read a byte from a blob
+ */
+static u_char read_byte(chunk_t *blob)
+{
+ u_char val;
+
+ if (blob->len < sizeof(u_char))
+ {
+ return 0;
+ }
+ val = *(blob->ptr);
+ *blob = chunk_skip(*blob, sizeof(u_char));
+ return val;
+}
+
+/**
+ * read a u_int32_t from a blob
+ */
+static u_int32_t read_uint32(chunk_t *blob)
+{
+ u_int32_t val;
+
+ if (blob->len < sizeof(u_int32_t))
+ {
+ return 0;
+ }
+ val = ntohl(*(u_int32_t*)blob->ptr);
+ *blob = chunk_skip(*blob, sizeof(u_int32_t));
+ return val;
+}
+
+/**
+ * read a ssh-agent "string" length/value from a blob
+ */
+static chunk_t read_string(chunk_t *blob)
+{
+ int len;
+ chunk_t str;
+
+ len = read_uint32(blob);
+ if (len > blob->len)
+ {
+ return chunk_empty;
+ }
+ str = chunk_create(blob->ptr, len);
+ *blob = chunk_skip(*blob, + len);
+ return str;
+}
+
+/**
+ * open socket connection to the ssh-agent
+ */
+static int open_connection(char *path)
+{
+ struct sockaddr_un addr;
+ int s;
+
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s == -1)
+ {
+ DBG1("opening ssh-agent socket %s failed: %s:", path, strerror(errno));
+ return -1;
+ }
+
+ addr.sun_family = AF_UNIX;
+ addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
+ strncpy(addr.sun_path, path, UNIX_PATH_MAX - 1);
+
+ if (connect(s, (struct sockaddr*)&addr, SUN_LEN(&addr)) != 0)
+ {
+ DBG1("connecting to ssh-agent socket failed: %s", strerror(errno));
+ close(s);
+ return -1;
+ }
+ return s;
+}
+
+/**
+ * check if the ssh agent key blob matches to our public key
+ */
+static bool matches_pubkey(chunk_t key, public_key_t *pubkey)
+{
+ chunk_t pubkeydata, hash, n, e;
+ hasher_t *hasher;
+ identification_t *id;
+ bool match;
+
+ if (!pubkey)
+ {
+ return TRUE;
+ }
+ read_string(&key);
+ e = read_string(&key);
+ n = read_string(&key);
+ hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
+ if (hasher == NULL)
+ {
+ return FALSE;
+ }
+ pubkeydata = asn1_wrap(ASN1_SEQUENCE, "mm",
+ asn1_wrap(ASN1_INTEGER, "c", n),
+ asn1_wrap(ASN1_INTEGER, "c", e));
+ hasher->allocate_hash(hasher, pubkeydata, &hash);
+ free(pubkeydata.ptr);
+ id = pubkey->get_id(pubkey, ID_PUBKEY_SHA1);
+ if (!id)
+ {
+ return FALSE;
+ }
+ match = chunk_equals(id->get_encoding(id), hash);
+ free(hash.ptr);
+ return match;
+}
+
+/**
+ * Get the first usable key from the agent
+ */
+static bool read_key(private_agent_private_key_t *this, public_key_t *pubkey)
+{
+ int len, count;
+ char buf[2048];
+ chunk_t blob = chunk_from_buf(buf), key, type, tmp;
+
+ len = htonl(1);
+ write(this->socket, &len, sizeof(len));
+ buf[0] = SSH_AGENT_ID_REQUEST;
+ write(this->socket, &buf, 1);
+
+ blob.len = read(this->socket, blob.ptr, blob.len);
+
+ if (blob.len < sizeof(u_int32_t) + sizeof(u_char) ||
+ read_uint32(&blob) != blob.len ||
+ read_byte(&blob) != SSH_AGENT_ID_RESPONSE)
+ {
+ DBG1("received invalid ssh-agent identity response");
+ return FALSE;
+ }
+ count = read_uint32(&blob);
+
+ while (blob.len)
+ {
+ key = read_string(&blob);
+ if (key.len)
+ {
+ tmp = key;
+ type = read_string(&tmp);
+ read_string(&tmp);
+ tmp = read_string(&tmp);
+ if (type.len && strneq("ssh-rsa", type.ptr, type.len) &&
+ tmp.len >= 512/8 && matches_pubkey(key, pubkey))
+ {
+ this->key = chunk_clone(key);
+ this->key_size = tmp.len;
+ if (tmp.ptr[0] == 0)
+ {
+ this->key_size--;
+ }
+ return TRUE;
+ }
+ continue;
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/**
+ * Implementation of agent_private_key.destroy.
+ */
+static bool sign(private_agent_private_key_t *this, signature_scheme_t scheme,
+ chunk_t data, chunk_t *signature)
+{
+ u_int32_t len, flags;
+ char buf[2048];
+ chunk_t blob = chunk_from_buf(buf);
+
+ if (scheme != SIGN_DEFAULT && scheme != SIGN_RSA_EMSA_PKCS1_SHA1)
+ {
+ DBG1("signature scheme %N not supported by ssh-agent",
+ signature_scheme_names, scheme);
+ return FALSE;
+ }
+
+ len = htonl(1 + sizeof(u_int32_t) * 3 + this->key.len + data.len);
+ write(this->socket, &len, sizeof(len));
+ buf[0] = SSH_AGENT_SIGN_REQUEST;
+ write(this->socket, &buf, 1);
+
+ len = htonl(this->key.len);
+ write(this->socket, &len, sizeof(len));
+ write(this->socket, this->key.ptr, this->key.len);
+
+ len = htonl(data.len);
+ write(this->socket, &len, sizeof(len));
+ write(this->socket, data.ptr, data.len);
+
+ flags = htonl(0);
+ write(this->socket, &flags, sizeof(flags));
+
+ blob.len = read(this->socket, blob.ptr, blob.len);
+ if (blob.len < sizeof(u_int32_t) + sizeof(u_char) ||
+ read_uint32(&blob) != blob.len ||
+ read_byte(&blob) != SSH_AGENT_SIGN_RESPONSE)
+ {
+ DBG1("received invalid ssh-agent signature response");
+ return FALSE;
+ }
+ /* parse length */
+ blob = read_string(&blob);
+ /* skip sig type */
+ read_string(&blob);
+ /* parse length */
+ blob = read_string(&blob);
+ if (!blob.len)
+ {
+ DBG1("received invalid ssh-agent signature response");
+ return FALSE;
+ }
+ *signature = chunk_clone(blob);
+ return TRUE;
+}
+
+/**
+ * Implementation of agent_private_key.destroy.
+ */
+static key_type_t get_type(private_agent_private_key_t *this)
+{
+ return KEY_RSA;
+}
+
+/**
+ * Implementation of agent_private_key.destroy.
+ */
+static bool decrypt(private_agent_private_key_t *this,
+ chunk_t crypto, chunk_t *plain)
+{
+ DBG1("private key decryption not supported by ssh-agent");
+ return FALSE;
+}
+
+/**
+ * Implementation of agent_private_key.destroy.
+ */
+static size_t get_keysize(private_agent_private_key_t *this)
+{
+ return this->key_size;
+}
+
+/**
+ * Implementation of agent_private_key.destroy.
+ */
+static identification_t* get_id(private_agent_private_key_t *this,
+ id_type_t type)
+{
+ switch (type)
+ {
+ case ID_PUBKEY_INFO_SHA1:
+ return this->keyid_info;
+ case ID_PUBKEY_SHA1:
+ return this->keyid;
+ default:
+ return NULL;
+ }
+}
+
+/**
+ * Implementation of agent_private_key.get_public_key.
+ */
+static public_key_t* get_public_key(private_agent_private_key_t *this)
+{
+ chunk_t key, n, e, encoded;
+ public_key_t *public;
+
+ key = this->key;
+ read_string(&key);
+ e = read_string(&key);
+ n = read_string(&key);
+ encoded = asn1_wrap(ASN1_SEQUENCE, "mm",
+ asn1_wrap(ASN1_INTEGER, "c", n),
+ asn1_wrap(ASN1_INTEGER, "c", e));
+
+ public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
+ BUILD_BLOB_ASN1_DER, encoded, BUILD_END);
+ free(encoded.ptr);
+ return public;
+}
+
+/**
+ * Implementation of agent_private_key.belongs_to.
+ */
+static bool belongs_to(private_agent_private_key_t *this, public_key_t *public)
+{
+ identification_t *keyid;
+
+ if (public->get_type(public) != KEY_RSA)
+ {
+ return FALSE;
+ }
+ keyid = public->get_id(public, ID_PUBKEY_SHA1);
+ if (keyid && keyid->equals(keyid, this->keyid))
+ {
+ return TRUE;
+ }
+ keyid = public->get_id(public, ID_PUBKEY_INFO_SHA1);
+ if (keyid && keyid->equals(keyid, this->keyid_info))
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * Build the RSA key identifier from n and e using SHA1 hashed publicKey(Info).
+ */
+static bool build_ids(private_agent_private_key_t *this)
+{
+ chunk_t publicKeyInfo, publicKey, hash, key, n, e;
+ hasher_t *hasher;
+
+ key = this->key;
+ read_string(&key);
+ e = read_string(&key);
+ n = read_string(&key);
+
+ hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
+ if (hasher == NULL)
+ {
+ DBG1("SHA1 hash algorithm not supported, unable to use RSA");
+ return FALSE;
+ }
+ publicKey = asn1_wrap(ASN1_SEQUENCE, "mm",
+ asn1_wrap(ASN1_INTEGER, "c", n),
+ asn1_wrap(ASN1_INTEGER, "c", e));
+ hasher->allocate_hash(hasher, publicKey, &hash);
+ this->keyid = identification_create_from_encoding(ID_PUBKEY_SHA1, hash);
+ chunk_free(&hash);
+
+ publicKeyInfo = asn1_wrap(ASN1_SEQUENCE, "cm",
+ asn1_algorithmIdentifier(OID_RSA_ENCRYPTION),
+ asn1_bitstring("m", publicKey));
+ hasher->allocate_hash(hasher, publicKeyInfo, &hash);
+ this->keyid_info = identification_create_from_encoding(ID_PUBKEY_INFO_SHA1, hash);
+ chunk_free(&hash);
+
+ hasher->destroy(hasher);
+ chunk_free(&publicKeyInfo);
+ return TRUE;
+}
+
+/**
+ * Implementation of private_key_t.get_encoding.
+ */
+static chunk_t get_encoding(private_agent_private_key_t *this)
+{
+ return chunk_empty;
+}
+
+/**
+ * Implementation of agent_private_key.get_ref.
+ */
+static private_agent_private_key_t* get_ref(private_agent_private_key_t *this)
+{
+ ref_get(&this->ref);
+ return this;
+}
+
+/**
+ * Implementation of agent_private_key.destroy.
+ */
+static void destroy(private_agent_private_key_t *this)
+{
+ if (ref_put(&this->ref))
+ {
+ close(this->socket);
+ DESTROY_IF(this->keyid);
+ DESTROY_IF(this->keyid_info);
+ free(this->key.ptr);
+ free(this);
+ }
+}
+
+/**
+ * Internal constructor
+ */
+static agent_private_key_t *agent_private_key_create(char *path,
+ public_key_t *pubkey)
+{
+ private_agent_private_key_t *this = malloc_thing(private_agent_private_key_t);
+
+ this->public.interface.get_type = (key_type_t (*)(private_key_t *this))get_type;
+ this->public.interface.sign = (bool (*)(private_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t *signature))sign;
+ this->public.interface.decrypt = (bool (*)(private_key_t *this, chunk_t crypto, chunk_t *plain))decrypt;
+ this->public.interface.get_keysize = (size_t (*) (private_key_t *this))get_keysize;
+ this->public.interface.get_id = (identification_t* (*) (private_key_t *this,id_type_t))get_id;
+ this->public.interface.get_public_key = (public_key_t* (*)(private_key_t *this))get_public_key;
+ this->public.interface.belongs_to = (bool (*) (private_key_t *this, public_key_t *public))belongs_to;
+ this->public.interface.get_encoding = (chunk_t(*)(private_key_t*))get_encoding;
+ this->public.interface.get_ref = (private_key_t* (*)(private_key_t *this))get_ref;
+ this->public.interface.destroy = (void (*)(private_key_t *this))destroy;
+
+ this->socket = open_connection(path);
+ if (this->socket < 0)
+ {
+ free(this);
+ return NULL;
+ }
+ this->key = chunk_empty;
+ this->keyid = NULL;
+ this->keyid_info = NULL;
+ this->ref = 1;
+ if (!read_key(this, pubkey) || !build_ids(this))
+ {
+ destroy(this);
+ return NULL;
+ }
+ return &this->public;
+}
+
+typedef struct private_builder_t private_builder_t;
+/**
+ * Builder implementation for key loading/generation
+ */
+struct private_builder_t {
+ /** implements the builder interface */
+ builder_t public;
+ /** agent unix socket */
+ char *socket;
+ /** matching public key */
+ public_key_t *pubkey;
+};
+
+/**
+ * Implementation of builder_t.build
+ */
+static agent_private_key_t *build(private_builder_t *this)
+{
+ agent_private_key_t *key = NULL;
+
+ if (this->socket)
+ {
+ key = agent_private_key_create(this->socket, this->pubkey);
+ }
+ free(this);
+ return key;
+}
+
+/**
+ * Implementation of builder_t.add
+ */
+static void add(private_builder_t *this, builder_part_t part, ...)
+{
+ va_list args;
+
+ switch (part)
+ {
+ case BUILD_AGENT_SOCKET:
+ {
+ va_start(args, part);
+ this->socket = va_arg(args, char*);
+ va_end(args);
+ return;
+ }
+ case BUILD_PUBLIC_KEY:
+ {
+ va_start(args, part);
+ this->pubkey = va_arg(args, public_key_t*);
+ va_end(args);
+ return;
+ }
+ default:
+ break;
+ }
+ builder_cancel(&this->public);
+}
+
+/**
+ * Builder construction function
+ */
+builder_t *agent_private_key_builder(key_type_t type)
+{
+ private_builder_t *this;
+
+ if (type != KEY_RSA)
+ {
+ return NULL;
+ }
+
+ this = malloc_thing(private_builder_t);
+
+ this->pubkey = NULL;
+ this->socket = NULL;
+ this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
+ this->public.build = (void*(*)(builder_t *this))build;
+
+ return &this->public;
+}
+
diff --git a/src/libstrongswan/plugins/agent/agent_private_key.h b/src/libstrongswan/plugins/agent/agent_private_key.h
new file mode 100644
index 000000000..4d678dd08
--- /dev/null
+++ b/src/libstrongswan/plugins/agent/agent_private_key.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup agent_private_key agent_private_key
+ * @{ @ingroup agent_p
+ */
+
+#ifndef AGENT_PRIVATE_KEY_H_
+#define AGENT_PRIVATE_KEY_H_
+
+#include <credentials/keys/private_key.h>
+
+typedef struct agent_private_key_t agent_private_key_t;
+
+/**
+ * private_key_t implementation using an ssh-agent.
+ */
+struct agent_private_key_t {
+
+ /**
+ * Implements private_key_t interface
+ */
+ private_key_t interface;
+};
+
+/**
+ * Create the builder for a private key.
+ *
+ * @param type type of the key
+ * @return builder instance
+ */
+builder_t *agent_private_key_builder(key_type_t type);
+
+#endif /*AGENT_PRIVATE_KEY_H_ @}*/
+
diff --git a/src/libstrongswan/plugins/curl/Makefile.in b/src/libstrongswan/plugins/curl/Makefile.in
index d3f7b443d..cb44a4ffe 100644
--- a/src/libstrongswan/plugins/curl/Makefile.in
+++ b/src/libstrongswan/plugins/curl/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/des/Makefile.in b/src/libstrongswan/plugins/des/Makefile.in
index 5072a2cab..8824bd238 100644
--- a/src/libstrongswan/plugins/des/Makefile.in
+++ b/src/libstrongswan/plugins/des/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/des/des_plugin.c b/src/libstrongswan/plugins/des/des_plugin.c
index c32096ad0..538138d8a 100644
--- a/src/libstrongswan/plugins/des/des_plugin.c
+++ b/src/libstrongswan/plugins/des/des_plugin.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: des_plugin.c 3488 2008-02-21 15:10:02Z martin $
+ * $Id: des_plugin.c 4309 2008-08-28 11:07:57Z martin $
*/
#include "des_plugin.h"
@@ -52,10 +52,10 @@ plugin_t *plugin_create()
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
- lib->crypto->add_crypter(lib->crypto, ENCR_DES,
- (crypter_constructor_t)des_crypter_create);
lib->crypto->add_crypter(lib->crypto, ENCR_3DES,
(crypter_constructor_t)des_crypter_create);
+ lib->crypto->add_crypter(lib->crypto, ENCR_DES,
+ (crypter_constructor_t)des_crypter_create);
return &this->public.plugin;
}
diff --git a/src/libstrongswan/plugins/fips_prf/Makefile.in b/src/libstrongswan/plugins/fips_prf/Makefile.in
index fa51b0db5..48a6c9b28 100644
--- a/src/libstrongswan/plugins/fips_prf/Makefile.in
+++ b/src/libstrongswan/plugins/fips_prf/Makefile.in
@@ -189,6 +189,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/gmp/Makefile.in b/src/libstrongswan/plugins/gmp/Makefile.in
index 1d9bfb88e..56642b7c9 100644
--- a/src/libstrongswan/plugins/gmp/Makefile.in
+++ b/src/libstrongswan/plugins/gmp/Makefile.in
@@ -188,6 +188,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c b/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
index 3d9856b63..40e83fc4c 100644
--- a/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
+++ b/src/libstrongswan/plugins/gmp/gmp_diffie_hellman.c
@@ -15,7 +15,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_diffie_hellman.c 3806 2008-04-15 05:56:35Z martin $
+ * $Id: gmp_diffie_hellman.c 4346 2008-09-17 09:02:30Z martin $
*/
#include <gmp.h>
@@ -343,7 +343,7 @@ struct private_gmp_diffie_hellman_t {
* Generator value.
*/
mpz_t g;
-
+
/**
* My private value.
*/
@@ -353,7 +353,7 @@ struct private_gmp_diffie_hellman_t {
* My public value.
*/
mpz_t ya;
-
+
/**
* Other public value.
*/
@@ -373,7 +373,7 @@ struct private_gmp_diffie_hellman_t {
* Modulus length.
*/
size_t p_len;
-
+
/**
* True if shared secret is computed and stored in my_public_value.
*/
@@ -395,7 +395,7 @@ static void set_other_public_value(private_gmp_diffie_hellman_t *this, chunk_t v
/* check public value:
* 1. 0 or 1 is invalid as 0^a = 0 and 1^a = 1
* 2. a public value larger or equal the modulus is invalid */
- if (mpz_cmp_ui(this->yb, 1) > 0 ||
+ if (mpz_cmp_ui(this->yb, 1) > 0 &&
mpz_cmp(this->yb, p_min_1) < 0)
{
#ifdef EXTENDED_DH_TEST
@@ -440,7 +440,11 @@ static status_t get_other_public_value(private_gmp_diffie_hellman_t *this,
return FAILED;
}
value->len = this->p_len;
- value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb);
+ value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb);
+ if (value->ptr == NULL)
+ {
+ return FAILED;
+ }
return SUCCESS;
}
@@ -451,6 +455,10 @@ static void get_my_public_value(private_gmp_diffie_hellman_t *this,chunk_t *valu
{
value->len = this->p_len;
value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->ya);
+ if (value->ptr == NULL)
+ {
+ value->len = 0;
+ }
}
/**
@@ -463,7 +471,11 @@ static status_t get_shared_secret(private_gmp_diffie_hellman_t *this, chunk_t *s
return FAILED;
}
secret->len = this->p_len;
- secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz);
+ secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz);
+ if (secret->ptr == NULL)
+ {
+ return FAILED;
+ }
return SUCCESS;
}
diff --git a/src/libstrongswan/plugins/gmp/gmp_plugin.c b/src/libstrongswan/plugins/gmp/gmp_plugin.c
index 56fb0ddd8..7711b6d34 100644
--- a/src/libstrongswan/plugins/gmp/gmp_plugin.c
+++ b/src/libstrongswan/plugins/gmp/gmp_plugin.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_plugin.c 3962 2008-05-15 12:39:35Z tobias $
+ * $Id: gmp_plugin.c 4309 2008-08-28 11:07:57Z martin $
*/
#include "gmp_plugin.h"
@@ -58,14 +58,10 @@ plugin_t *plugin_create()
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
- lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
- (dh_constructor_t)gmp_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
+ lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
- (dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
@@ -74,6 +70,10 @@ plugin_t *plugin_create()
(dh_constructor_t)gmp_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
(dh_constructor_t)gmp_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
+ (dh_constructor_t)gmp_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
+ (dh_constructor_t)gmp_diffie_hellman_create);
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
(builder_constructor_t)gmp_rsa_private_key_builder);
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
index cd951f0e4..e445dd670 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_rsa_private_key.c 4014 2008-05-23 19:23:04Z andreas $
+ * $Id: gmp_rsa_private_key.c 4345 2008-09-17 08:10:48Z martin $
*/
#include <gmp.h>
@@ -191,6 +191,10 @@ static chunk_t rsadp(private_gmp_rsa_private_key_t *this, chunk_t data)
decrypted.len = this->k;
decrypted.ptr = mpz_export(NULL, NULL, 1, decrypted.len, 1, 0, t1);
+ if (decrypted.ptr == NULL)
+ {
+ decrypted.len = 0;
+ }
mpz_clear_randomized(t1);
mpz_clear_randomized(t2);
@@ -789,34 +793,37 @@ static gmp_rsa_private_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
- }
- case BUILD_KEY_SIZE:
- {
- va_start(args, part);
- this->key = generate(va_arg(args, u_int));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ case BUILD_KEY_SIZE:
+ {
+ va_start(args, part);
+ this->key = generate(va_arg(args, u_int));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_gmp_rsa_private_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
index e4f898ecc..8a89849cd 100644
--- a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
+++ b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: gmp_rsa_public_key.c 3988 2008-05-21 13:01:58Z martin $
+ * $Id: gmp_rsa_public_key.c 4345 2008-09-17 08:10:48Z martin $
*/
#include <gmp.h>
@@ -93,11 +93,15 @@ static chunk_t rsaep(private_gmp_rsa_public_key_t *this, chunk_t data)
mpz_powm(c, m, this->e, this->n);
- encrypted.len = this->k;
- encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c);
+ encrypted.len = this->k;
+ encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c);
+ if (encrypted.ptr == NULL)
+ {
+ encrypted.len = 0;
+ }
mpz_clear(c);
- mpz_clear(m);
+ mpz_clear(m);
return encrypted;
}
@@ -541,27 +545,30 @@ static gmp_rsa_public_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_gmp_rsa_public_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/hmac/Makefile.in b/src/libstrongswan/plugins/hmac/Makefile.in
index b6e851cd4..ded48fbf2 100644
--- a/src/libstrongswan/plugins/hmac/Makefile.in
+++ b/src/libstrongswan/plugins/hmac/Makefile.in
@@ -188,6 +188,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/hmac/hmac_plugin.c b/src/libstrongswan/plugins/hmac/hmac_plugin.c
index bfa2df35f..a0afc2a85 100644
--- a/src/libstrongswan/plugins/hmac/hmac_plugin.c
+++ b/src/libstrongswan/plugins/hmac/hmac_plugin.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: hmac_plugin.c 3488 2008-02-21 15:10:02Z martin $
+ * $Id: hmac_plugin.c 4309 2008-08-28 11:07:57Z martin $
*/
#include "hmac_plugin.h"
@@ -55,25 +55,25 @@ plugin_t *plugin_create()
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
- lib->crypto->add_prf(lib->crypto, PRF_HMAC_MD5,
+ lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_256,
(prf_constructor_t)hmac_prf_create);
lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA1,
(prf_constructor_t)hmac_prf_create);
- lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_256,
+ lib->crypto->add_prf(lib->crypto, PRF_HMAC_MD5,
(prf_constructor_t)hmac_prf_create);
lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_384,
(prf_constructor_t)hmac_prf_create);
lib->crypto->add_prf(lib->crypto, PRF_HMAC_SHA2_512,
(prf_constructor_t)hmac_prf_create);
- lib->crypto->add_signer(lib->crypto, AUTH_HMAC_MD5_96,
- (signer_constructor_t)hmac_signer_create);
lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_96,
(signer_constructor_t)hmac_signer_create);
lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA1_128,
(signer_constructor_t)hmac_signer_create);
lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_256_128,
(signer_constructor_t)hmac_signer_create);
+ lib->crypto->add_signer(lib->crypto, AUTH_HMAC_MD5_96,
+ (signer_constructor_t)hmac_signer_create);
lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_384_192,
(signer_constructor_t)hmac_signer_create);
lib->crypto->add_signer(lib->crypto, AUTH_HMAC_SHA2_512_256,
diff --git a/src/libstrongswan/plugins/ldap/Makefile.in b/src/libstrongswan/plugins/ldap/Makefile.in
index 8c28f1307..e828fbd44 100644
--- a/src/libstrongswan/plugins/ldap/Makefile.in
+++ b/src/libstrongswan/plugins/ldap/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/md5/Makefile.in b/src/libstrongswan/plugins/md5/Makefile.in
index 6a4b2a78b..43b921e63 100644
--- a/src/libstrongswan/plugins/md5/Makefile.in
+++ b/src/libstrongswan/plugins/md5/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/mysql/Makefile.in b/src/libstrongswan/plugins/mysql/Makefile.in
index 6de9dc13d..96dc33fe5 100644
--- a/src/libstrongswan/plugins/mysql/Makefile.in
+++ b/src/libstrongswan/plugins/mysql/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/mysql/mysql_database.c b/src/libstrongswan/plugins/mysql/mysql_database.c
index 58202c5ae..01f604fef 100644
--- a/src/libstrongswan/plugins/mysql/mysql_database.c
+++ b/src/libstrongswan/plugins/mysql/mysql_database.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: mysql_database.c 4111 2008-06-26 07:31:52Z martin $
+ * $Id: mysql_database.c 4193 2008-07-21 11:13:06Z martin $
*/
#define _GNU_SOURCE
@@ -592,6 +592,14 @@ static int execute(private_mysql_database_t *this, int *rowid, char *sql, ...)
conn_release(conn);
return affected;
}
+
+/**
+ * Implementation of database_t.get_driver
+ */
+static db_driver_t get_driver(private_mysql_database_t *this)
+{
+ return DB_MYSQL;
+}
/**
* Implementation of database_t.destroy
@@ -672,6 +680,7 @@ mysql_database_t *mysql_database_create(char *uri)
this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
+ this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
this->public.db.destroy = (void(*)(database_t*))destroy;
if (!parse_uri(this, uri))
diff --git a/src/libstrongswan/plugins/openssl/Makefile.in b/src/libstrongswan/plugins/openssl/Makefile.in
index f83b0ce38..746b5cf4b 100644
--- a/src/libstrongswan/plugins/openssl/Makefile.in
+++ b/src/libstrongswan/plugins/openssl/Makefile.in
@@ -192,6 +192,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/openssl/openssl_ec_private_key.c b/src/libstrongswan/plugins/openssl/openssl_ec_private_key.c
index 9f7df4bca..aeab15f26 100644
--- a/src/libstrongswan/plugins/openssl/openssl_ec_private_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_ec_private_key.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: openssl_ec_private_key.c 4051 2008-06-10 09:08:27Z tobias $
+ * $Id: openssl_ec_private_key.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "openssl_ec_private_key.h"
@@ -399,27 +399,30 @@ static openssl_ec_private_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
- {
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
-
- switch (part)
+ if (!this->key)
{
- case BUILD_BLOB_ASN1_DER:
+ va_list args;
+ chunk_t chunk;
+
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_openssl_ec_private_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c b/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c
index 2056575ba..923df3938 100644
--- a/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_ec_public_key.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: openssl_ec_public_key.c 4051 2008-06-10 09:08:27Z tobias $
+ * $Id: openssl_ec_public_key.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "openssl_ec_public_key.h"
@@ -401,27 +401,30 @@ static openssl_ec_public_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_openssl_ec_public_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/openssl/openssl_plugin.c b/src/libstrongswan/plugins/openssl/openssl_plugin.c
index 7fdd7c224..82c54a95e 100644
--- a/src/libstrongswan/plugins/openssl/openssl_plugin.c
+++ b/src/libstrongswan/plugins/openssl/openssl_plugin.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: openssl_plugin.c 4107 2008-06-25 12:39:32Z tobias $
+ * $Id: openssl_plugin.c 4309 2008-08-28 11:07:57Z martin $
*/
#include <openssl/evp.h>
@@ -87,7 +87,7 @@ plugin_t *plugin_create()
ENGINE_register_all_complete();
/* crypter */
- lib->crypto->add_crypter(lib->crypto, ENCR_DES,
+ lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
(crypter_constructor_t)openssl_crypter_create);
lib->crypto->add_crypter(lib->crypto, ENCR_3DES,
(crypter_constructor_t)openssl_crypter_create);
@@ -99,9 +99,9 @@ plugin_t *plugin_create()
(crypter_constructor_t)openssl_crypter_create);
lib->crypto->add_crypter(lib->crypto, ENCR_BLOWFISH,
(crypter_constructor_t)openssl_crypter_create);
- lib->crypto->add_crypter(lib->crypto, ENCR_NULL,
+ lib->crypto->add_crypter(lib->crypto, ENCR_DES,
(crypter_constructor_t)openssl_crypter_create);
- lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
+ lib->crypto->add_crypter(lib->crypto, ENCR_NULL,
(crypter_constructor_t)openssl_crypter_create);
/* hasher */
@@ -118,15 +118,23 @@ plugin_t *plugin_create()
lib->crypto->add_hasher(lib->crypto, HASH_SHA512,
(hasher_constructor_t)openssl_hasher_create);
+ /* ec diffie hellman */
+ lib->crypto->add_dh(lib->crypto, ECP_192_BIT,
+ (dh_constructor_t)openssl_ec_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, ECP_224_BIT,
+ (dh_constructor_t)openssl_ec_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, ECP_256_BIT,
+ (dh_constructor_t)openssl_ec_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, ECP_384_BIT,
+ (dh_constructor_t)openssl_ec_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, ECP_521_BIT,
+ (dh_constructor_t)openssl_ec_diffie_hellman_create);
+
/* diffie hellman */
- lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
- (dh_constructor_t)openssl_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
+ lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
(dh_constructor_t)openssl_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
(dh_constructor_t)openssl_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
- (dh_constructor_t)openssl_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
(dh_constructor_t)openssl_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
@@ -135,18 +143,10 @@ plugin_t *plugin_create()
(dh_constructor_t)openssl_diffie_hellman_create);
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
(dh_constructor_t)openssl_diffie_hellman_create);
-
- /* ec diffie hellman */
- lib->crypto->add_dh(lib->crypto, ECP_192_BIT,
- (dh_constructor_t)openssl_ec_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, ECP_224_BIT,
- (dh_constructor_t)openssl_ec_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, ECP_256_BIT,
- (dh_constructor_t)openssl_ec_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, ECP_384_BIT,
- (dh_constructor_t)openssl_ec_diffie_hellman_create);
- lib->crypto->add_dh(lib->crypto, ECP_521_BIT,
- (dh_constructor_t)openssl_ec_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
+ (dh_constructor_t)openssl_diffie_hellman_create);
+ lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
+ (dh_constructor_t)openssl_diffie_hellman_create);
/* rsa */
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c
index 7595eed3a..8ad75215a 100644
--- a/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: openssl_rsa_private_key.c 3963 2008-05-15 12:41:06Z tobias $
+ * $Id: openssl_rsa_private_key.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "openssl_rsa_private_key.h"
@@ -369,34 +369,37 @@ static openssl_rsa_private_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
- {
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
- }
- case BUILD_KEY_SIZE:
+ switch (part)
{
- va_start(args, part);
- this->key = generate(va_arg(args, u_int));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ case BUILD_KEY_SIZE:
+ {
+ va_start(args, part);
+ this->key = generate(va_arg(args, u_int));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_openssl_rsa_private_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
index 755b86e96..61b5b9b64 100644
--- a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: openssl_rsa_public_key.c 3963 2008-05-15 12:41:06Z tobias $
+ * $Id: openssl_rsa_public_key.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "openssl_rsa_public_key.h"
@@ -387,27 +387,30 @@ static openssl_rsa_public_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->key = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_openssl_rsa_public_key_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/padlock/Makefile.in b/src/libstrongswan/plugins/padlock/Makefile.in
index d96b2cf6d..1b032e3d4 100644
--- a/src/libstrongswan/plugins/padlock/Makefile.in
+++ b/src/libstrongswan/plugins/padlock/Makefile.in
@@ -189,6 +189,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c
index 4c5095e4a..6480a2760 100644
--- a/src/libstrongswan/plugins/plugin_loader.c
+++ b/src/libstrongswan/plugins/plugin_loader.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: plugin_loader.c 4108 2008-06-25 14:53:49Z martin $
+ * $Id: plugin_loader.c 4144 2008-07-02 08:19:43Z martin $
*/
#define _GNU_SOURCE
@@ -96,43 +96,22 @@ static plugin_t* load_plugin(private_plugin_loader_t *this,
static int load(private_plugin_loader_t *this, char *path, char *list)
{
plugin_t *plugin;
- char *pos;
+ enumerator_t *enumerator;
+ char *token;
int count = 0;
- list = strdupa(list);
- while (TRUE)
+ enumerator = enumerator_create_token(list, " ", " ");
+ while (enumerator->enumerate(enumerator, &token))
{
- /* eat any whitespace in front */
- while (*list == ' ')
- {
- list++;
- }
- /* have we reached the end of the list? */
- if (!*list)
- {
- break;
- }
- pos = strchr(list, ' ');
- if (pos)
- {
- *pos++ = '\0';
- }
- plugin = load_plugin(this, path, list);
+ plugin = load_plugin(this, path, token);
if (plugin)
{ /* insert in front to destroy them in reverse order */
this->plugins->insert_last(this->plugins, plugin);
- this->names->insert_last(this->names, strdup(list));
+ this->names->insert_last(this->names, strdup(token));
count++;
}
- if (pos)
- {
- list = pos;
- }
- else
- {
- break;
- }
}
+ enumerator->destroy(enumerator);
return count;
}
diff --git a/src/libstrongswan/plugins/pubkey/Makefile.in b/src/libstrongswan/plugins/pubkey/Makefile.in
index ced339d15..ef1004672 100644
--- a/src/libstrongswan/plugins/pubkey/Makefile.in
+++ b/src/libstrongswan/plugins/pubkey/Makefile.in
@@ -189,6 +189,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/pubkey/pubkey_cert.c b/src/libstrongswan/plugins/pubkey/pubkey_cert.c
index 63dffb47b..762557094 100644
--- a/src/libstrongswan/plugins/pubkey/pubkey_cert.c
+++ b/src/libstrongswan/plugins/pubkey/pubkey_cert.c
@@ -19,6 +19,11 @@
#include <debug.h>
+/**
+ * defined in pubkey_public_key.c
+ */
+extern public_key_t *pubkey_public_key_load(chunk_t blob);
+
typedef struct private_pubkey_cert_t private_pubkey_cert_t;
/**
@@ -60,7 +65,7 @@ static certificate_type_t get_type(private_pubkey_cert_t *this)
*/
static identification_t* get_subject(private_pubkey_cert_t *this)
{
- return this->key->get_id(this->key, ID_PUBKEY_SHA1);
+ return this->key->get_id(this->key, ID_PUBKEY_INFO_SHA1);
}
/**
@@ -109,7 +114,7 @@ static bool equals(private_pubkey_cert_t *this, certificate_t *other)
{
return FALSE;
}
- return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_SHA1));
+ return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_INFO_SHA1));
}
/**
@@ -211,6 +216,13 @@ static pubkey_cert_t *pubkey_cert_create(public_key_t *key)
return &this->public;
}
+static pubkey_cert_t *pubkey_cert_create_from_chunk(chunk_t blob)
+{
+ public_key_t *key = pubkey_public_key_load(chunk_clone(blob));
+
+ return (key)? pubkey_cert_create(key) : NULL;
+}
+
typedef struct private_builder_t private_builder_t;
/**
* Builder implementation for key loading
@@ -238,27 +250,35 @@ static pubkey_cert_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
- switch (part)
- {
- case BUILD_PUBLIC_KEY:
+ switch (part)
{
- va_start(args, part);
- this->key = pubkey_cert_create(va_arg(args, public_key_t*));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ this->key = pubkey_cert_create_from_chunk(va_arg(args, chunk_t));
+ va_end(args);
+ return;
+ }
+ case BUILD_PUBLIC_KEY:
+ {
+ va_start(args, part);
+ this->key = pubkey_cert_create(va_arg(args, public_key_t*));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_pubkey_cert_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/pubkey/pubkey_public_key.c b/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
index 0527ed758..4b5f4aac2 100644
--- a/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
+++ b/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
@@ -14,7 +14,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: pubkey_public_key.c 4059 2008-06-11 14:10:02Z martin $
+ * $Id: pubkey_public_key.c 4379 2008-10-08 01:19:26Z andreas $
*/
#include "pubkey_public_key.h"
@@ -39,9 +39,10 @@ static const asn1Object_t pkinfoObjects[] = {
/**
- * Load a public key from an ASN1 encoded blob
+ * Load a public key from an ASN.1 encoded blob
+ * Also used by pubkey_cert.c
*/
-static public_key_t *load(chunk_t blob)
+public_key_t *pubkey_public_key_load(chunk_t blob)
{
asn1_parser_t *parser;
chunk_t object;
@@ -67,9 +68,8 @@ static public_key_t *load(chunk_t blob)
else if (oid == OID_EC_PUBLICKEY)
{
/* we need the whole subjectPublicKeyInfo for EC public keys */
- key = lib->creds->create(lib->creds,
- CRED_PUBLIC_KEY, KEY_ECDSA, BUILD_BLOB_ASN1_DER,
- chunk_clone(blob), BUILD_END);
+ key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY,
+ KEY_ECDSA, BUILD_BLOB_ASN1_DER, blob, BUILD_END);
goto end;
}
else
@@ -86,8 +86,7 @@ static public_key_t *load(chunk_t blob)
object = chunk_skip(object, 1);
}
key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, type,
- BUILD_BLOB_ASN1_DER, chunk_clone(object),
- BUILD_END);
+ BUILD_BLOB_ASN1_DER, object, BUILD_END);
break;
}
}
@@ -125,41 +124,43 @@ static public_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
- {
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
- va_start(args, part);
- switch (part)
+ if (!this->key)
{
- case BUILD_BLOB_ASN1_DER:
+ va_list args;
+ chunk_t blob;
+
+ switch (part)
{
- this->key = load(va_arg(args, chunk_t));
- break;
- }
- case BUILD_BLOB_ASN1_PEM:
- {
- bool pgp;
- char *pem;
- chunk_t blob;
-
- pem = va_arg(args, char *);
- blob = chunk_clone(chunk_create(pem, strlen(pem)));
- if (pem_to_bin(&blob, &chunk_empty, &pgp))
+ case BUILD_BLOB_ASN1_DER:
{
- this->key = load(chunk_clone(blob));
+ va_start(args, part);
+ blob = va_arg(args, chunk_t);
+ this->key = pubkey_public_key_load(chunk_clone(blob));
+ va_end(args);
+ return;
}
- free(blob.ptr);
- break;
+ case BUILD_BLOB_ASN1_PEM:
+ {
+ bool pgp;
+ char *pem;
+
+ va_start(args, part);
+ pem = va_arg(args, char *);
+ blob = chunk_clone(chunk_create(pem, strlen(pem)));
+ if (pem_to_bin(&blob, &chunk_empty, &pgp))
+ {
+ this->key = pubkey_public_key_load(chunk_clone(blob));
+ }
+ free(blob.ptr);
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
- va_end(args);
+ DESTROY_IF(this->key);
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/random/Makefile.in b/src/libstrongswan/plugins/random/Makefile.in
index c4baa04b3..90b319520 100644
--- a/src/libstrongswan/plugins/random/Makefile.in
+++ b/src/libstrongswan/plugins/random/Makefile.in
@@ -188,6 +188,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/random/random_rng.c b/src/libstrongswan/plugins/random/random_rng.c
index 1aadc88bd..45a1b5138 100644
--- a/src/libstrongswan/plugins/random/random_rng.c
+++ b/src/libstrongswan/plugins/random/random_rng.c
@@ -63,7 +63,8 @@ struct private_random_rng_t {
static void get_bytes(private_random_rng_t *this, size_t bytes,
u_int8_t *buffer)
{
- size_t done, got;
+ size_t done;
+ ssize_t got;
done = 0;
diff --git a/src/libstrongswan/plugins/sha1/Makefile.am b/src/libstrongswan/plugins/sha1/Makefile.am
index 299e85083..5de45e4e8 100644
--- a/src/libstrongswan/plugins/sha1/Makefile.am
+++ b/src/libstrongswan/plugins/sha1/Makefile.am
@@ -5,6 +5,7 @@ AM_CFLAGS = -rdynamic
plugin_LTLIBRARIES = libstrongswan-sha1.la
-libstrongswan_sha1_la_SOURCES = sha1_plugin.h sha1_plugin.c sha1_hasher.c sha1_hasher.h
+libstrongswan_sha1_la_SOURCES = sha1_plugin.h sha1_plugin.c \
+ sha1_hasher.c sha1_hasher.h sha1_prf.c sha1_prf.h
libstrongswan_sha1_la_LDFLAGS = -module
diff --git a/src/libstrongswan/plugins/sha1/Makefile.in b/src/libstrongswan/plugins/sha1/Makefile.in
index b57c46aee..df6845b43 100644
--- a/src/libstrongswan/plugins/sha1/Makefile.in
+++ b/src/libstrongswan/plugins/sha1/Makefile.in
@@ -50,7 +50,8 @@ am__installdirs = "$(DESTDIR)$(plugindir)"
pluginLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(plugin_LTLIBRARIES)
libstrongswan_sha1_la_LIBADD =
-am_libstrongswan_sha1_la_OBJECTS = sha1_plugin.lo sha1_hasher.lo
+am_libstrongswan_sha1_la_OBJECTS = sha1_plugin.lo sha1_hasher.lo \
+ sha1_prf.lo
libstrongswan_sha1_la_OBJECTS = $(am_libstrongswan_sha1_la_OBJECTS)
libstrongswan_sha1_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@@ -187,6 +188,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
@@ -209,7 +212,9 @@ xml_LIBS = @xml_LIBS@
INCLUDES = -I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = -rdynamic
plugin_LTLIBRARIES = libstrongswan-sha1.la
-libstrongswan_sha1_la_SOURCES = sha1_plugin.h sha1_plugin.c sha1_hasher.c sha1_hasher.h
+libstrongswan_sha1_la_SOURCES = sha1_plugin.h sha1_plugin.c \
+ sha1_hasher.c sha1_hasher.h sha1_prf.c sha1_prf.h
+
libstrongswan_sha1_la_LDFLAGS = -module
all: all-am
@@ -282,6 +287,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1_hasher.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1_plugin.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1_prf.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/libstrongswan/plugins/sha1/sha1_hasher.c b/src/libstrongswan/plugins/sha1/sha1_hasher.c
index c496be8f4..ea0882cb5 100644
--- a/src/libstrongswan/plugins/sha1/sha1_hasher.c
+++ b/src/libstrongswan/plugins/sha1/sha1_hasher.c
@@ -16,7 +16,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: sha1_hasher.c 3619 2008-03-19 14:02:52Z martin $
+ * $Id: sha1_hasher.c 4308 2008-08-28 10:57:24Z martin $
*/
#include <string.h>
@@ -47,7 +47,6 @@
typedef struct private_sha1_hasher_t private_sha1_hasher_t;
-typedef struct private_sha1_keyed_prf_t private_sha1_keyed_prf_t;
/**
* Private data structure with hasing context.
@@ -59,28 +58,13 @@ struct private_sha1_hasher_t {
sha1_hasher_t public;
/*
- * State of the hasher.
+ * State of the hasher. Shared with sha1_prf.c, do not change it!!!
*/
u_int32_t state[5];
u_int32_t count[2];
u_int8_t buffer[64];
};
-/**
- * Private data structure with keyed prf context.
- */
-struct private_sha1_keyed_prf_t {
- /**
- * public prf interface
- */
- sha1_keyed_prf_t public;
-
- /**
- * internal used hasher
- */
- private_sha1_hasher_t *hasher;
-};
-
/*
* Hash a single 512-bit block. This is the core of the algorithm. *
*/
@@ -132,10 +116,10 @@ static void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
memset(block, '\0', sizeof(block));
}
-/*
- * Run your data through this.
+/**
+ * Run your data through this. Also used in sha1_prf.
*/
-static void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
+void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
{
u_int32_t i;
u_int32_t j;
@@ -275,92 +259,3 @@ sha1_hasher_t *sha1_hasher_create(hash_algorithm_t algo)
return &(this->public);
}
-/**
- * Implementation of prf_t.get_bytes.
- */
-static void get_bytes(private_sha1_keyed_prf_t *this, chunk_t seed, u_int8_t *bytes)
-{
- u_int32_t *hash = (u_int32_t*)bytes;
-
- SHA1Update(this->hasher, seed.ptr, seed.len);
-
- hash[0] = htonl(this->hasher->state[0]);
- hash[1] = htonl(this->hasher->state[1]);
- hash[2] = htonl(this->hasher->state[2]);
- hash[3] = htonl(this->hasher->state[3]);
- hash[4] = htonl(this->hasher->state[4]);
-}
-
-/**
- * Implementation of prf_t.get_block_size.
- */
-static size_t get_block_size(private_sha1_keyed_prf_t *this)
-{
- return HASH_SIZE_SHA1;
-}
-
-/**
- * Implementation of prf_t.allocate_bytes.
- */
-static void allocate_bytes(private_sha1_keyed_prf_t *this, chunk_t seed, chunk_t *chunk)
-{
- *chunk = chunk_alloc(HASH_SIZE_SHA1);
- get_bytes(this, seed, chunk->ptr);
-}
-
-/**
- * Implementation of prf_t.get_key_size.
- */
-static size_t get_key_size(private_sha1_keyed_prf_t *this)
-{
- return sizeof(this->hasher->state);
-}
-
-/**
- * Implementation of prf_t.set_key.
- */
-static void set_key(private_sha1_keyed_prf_t *this, chunk_t key)
-{
- int i, rounds;
- u_int32_t *iv = (u_int32_t*)key.ptr;
-
- reset(this->hasher);
- rounds = min(key.len/sizeof(u_int32_t), sizeof(this->hasher->state));
- for (i = 0; i < rounds; i++)
- {
- this->hasher->state[i] ^= htonl(iv[i]);
- }
-}
-
-/**
- * Implementation of prf_t.destroy.
- */
-static void destroy_p(private_sha1_keyed_prf_t *this)
-{
- destroy(this->hasher);
- free(this);
-}
-
-/**
- * see header
- */
-sha1_keyed_prf_t *sha1_keyed_prf_create(pseudo_random_function_t algo)
-{
- private_sha1_keyed_prf_t *this;
- if (algo != PRF_KEYED_SHA1)
- {
- return NULL;
- }
- this = malloc_thing(private_sha1_keyed_prf_t);
- this->public.prf_interface.get_bytes = (void (*) (prf_t *,chunk_t,u_int8_t*))get_bytes;
- this->public.prf_interface.allocate_bytes = (void (*) (prf_t*,chunk_t,chunk_t*))allocate_bytes;
- this->public.prf_interface.get_block_size = (size_t (*) (prf_t*))get_block_size;
- this->public.prf_interface.get_key_size = (size_t (*) (prf_t*))get_key_size;
- this->public.prf_interface.set_key = (void (*) (prf_t *,chunk_t))set_key;
- this->public.prf_interface.destroy = (void (*) (prf_t *))destroy_p;
-
- this->hasher = (private_sha1_hasher_t*)sha1_hasher_create(HASH_SHA1);
-
- return &(this->public);
-}
-
diff --git a/src/libstrongswan/plugins/sha1/sha1_hasher.h b/src/libstrongswan/plugins/sha1/sha1_hasher.h
index 2e44797d8..7dcb0b8b3 100644
--- a/src/libstrongswan/plugins/sha1/sha1_hasher.h
+++ b/src/libstrongswan/plugins/sha1/sha1_hasher.h
@@ -23,10 +23,8 @@
#define SHA1_HASHER_H_
typedef struct sha1_hasher_t sha1_hasher_t;
-typedef struct sha1_keyed_prf_t sha1_keyed_prf_t;
#include <crypto/hashers/hasher.h>
-#include <crypto/prfs/prf.h>
/**
* Implementation of hasher_t interface using the SHA1 algorithm.
@@ -40,17 +38,6 @@ struct sha1_hasher_t {
};
/**
- * Implementation of prf_t interface using keyed SHA1 algorithm (used for EAP-AKA).
- */
-struct sha1_keyed_prf_t {
-
- /**
- * Implements prf_t interface.
- */
- prf_t prf_interface;
-};
-
-/**
* Creates a new sha1_hasher_t.
*
* @param algo algorithm, must be HASH_SHA1
@@ -58,12 +45,4 @@ struct sha1_keyed_prf_t {
*/
sha1_hasher_t *sha1_hasher_create(hash_algorithm_t algo);
-/**
- * Creates a new sha1_keyed_prf_t.
- *
- * @param algo algorithm, must be PRF_KEYED_SHA1
- * @return sha1_keyed_prf_tobject
- */
-sha1_keyed_prf_t *sha1_keyed_prf_create(pseudo_random_function_t algo);
-
#endif /*SHA1_HASHER_H_ @}*/
diff --git a/src/libstrongswan/plugins/sha1/sha1_plugin.c b/src/libstrongswan/plugins/sha1/sha1_plugin.c
index e8da99e6c..58f0faf56 100644
--- a/src/libstrongswan/plugins/sha1/sha1_plugin.c
+++ b/src/libstrongswan/plugins/sha1/sha1_plugin.c
@@ -12,13 +12,14 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: sha1_plugin.c 3619 2008-03-19 14:02:52Z martin $
+ * $Id: sha1_plugin.c 4308 2008-08-28 10:57:24Z martin $
*/
#include "sha1_plugin.h"
#include <library.h>
#include "sha1_hasher.h"
+#include "sha1_prf.h"
typedef struct private_sha1_plugin_t private_sha1_plugin_t;
@@ -41,7 +42,7 @@ static void destroy(private_sha1_plugin_t *this)
lib->crypto->remove_hasher(lib->crypto,
(hasher_constructor_t)sha1_hasher_create);
lib->crypto->remove_prf(lib->crypto,
- (prf_constructor_t)sha1_keyed_prf_create);
+ (prf_constructor_t)sha1_prf_create);
free(this);
}
@@ -57,7 +58,7 @@ plugin_t *plugin_create()
lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
(hasher_constructor_t)sha1_hasher_create);
lib->crypto->add_prf(lib->crypto, PRF_KEYED_SHA1,
- (prf_constructor_t)sha1_keyed_prf_create);
+ (prf_constructor_t)sha1_prf_create);
return &this->public.plugin;
}
diff --git a/src/libstrongswan/plugins/sha1/sha1_prf.c b/src/libstrongswan/plugins/sha1/sha1_prf.c
new file mode 100644
index 000000000..668801caf
--- /dev/null
+++ b/src/libstrongswan/plugins/sha1/sha1_prf.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * $Id$
+ */
+
+#include "sha1_prf.h"
+#include "sha1_hasher.h"
+
+#include <arpa/inet.h>
+
+typedef struct private_sha1_prf_t private_sha1_prf_t;
+typedef struct private_sha1_hasher_t private_sha1_hasher_t;
+
+/**
+ * Private data structure with hasing context.
+ */
+struct private_sha1_hasher_t {
+ /**
+ * Public interface for this hasher.
+ */
+ sha1_hasher_t public;
+
+ /*
+ * State of the hasher. From sha1_hasher.c, do not change it!
+ */
+ u_int32_t state[5];
+ u_int32_t count[2];
+ u_int8_t buffer[64];
+};
+
+/**
+ * Private data structure with keyed prf context.
+ */
+struct private_sha1_prf_t {
+
+ /**
+ * public prf interface
+ */
+ sha1_prf_t public;
+
+ /**
+ * internal used hasher
+ */
+ private_sha1_hasher_t *hasher;
+};
+
+/**
+ * From sha1_hasher.c
+ */
+extern void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len);
+
+/**
+ * Implementation of prf_t.get_bytes.
+ */
+static void get_bytes(private_sha1_prf_t *this, chunk_t seed, u_int8_t *bytes)
+{
+ u_int32_t *hash = (u_int32_t*)bytes;
+
+ SHA1Update(this->hasher, seed.ptr, seed.len);
+
+ hash[0] = htonl(this->hasher->state[0]);
+ hash[1] = htonl(this->hasher->state[1]);
+ hash[2] = htonl(this->hasher->state[2]);
+ hash[3] = htonl(this->hasher->state[3]);
+ hash[4] = htonl(this->hasher->state[4]);
+}
+
+/**
+ * Implementation of prf_t.get_block_size.
+ */
+static size_t get_block_size(private_sha1_prf_t *this)
+{
+ return HASH_SIZE_SHA1;
+}
+
+/**
+ * Implementation of prf_t.allocate_bytes.
+ */
+static void allocate_bytes(private_sha1_prf_t *this, chunk_t seed, chunk_t *chunk)
+{
+ *chunk = chunk_alloc(HASH_SIZE_SHA1);
+ get_bytes(this, seed, chunk->ptr);
+}
+
+/**
+ * Implementation of prf_t.get_key_size.
+ */
+static size_t get_key_size(private_sha1_prf_t *this)
+{
+ return sizeof(this->hasher->state);
+}
+
+/**
+ * Implementation of prf_t.set_key.
+ */
+static void set_key(private_sha1_prf_t *this, chunk_t key)
+{
+ int i, rounds;
+ u_int32_t *iv = (u_int32_t*)key.ptr;
+
+ this->hasher->public.hasher_interface.reset(&this->hasher->public.hasher_interface);
+ rounds = min(key.len/sizeof(u_int32_t), sizeof(this->hasher->state));
+ for (i = 0; i < rounds; i++)
+ {
+ this->hasher->state[i] ^= htonl(iv[i]);
+ }
+}
+
+/**
+ * Implementation of prf_t.destroy.
+ */
+static void destroy(private_sha1_prf_t *this)
+{
+ this->hasher->public.hasher_interface.destroy(&this->hasher->public.hasher_interface);
+ free(this);
+}
+
+/**
+ * see header
+ */
+sha1_prf_t *sha1_prf_create(pseudo_random_function_t algo)
+{
+ private_sha1_prf_t *this;
+ if (algo != PRF_KEYED_SHA1)
+ {
+ return NULL;
+ }
+ this = malloc_thing(private_sha1_prf_t);
+ this->public.prf_interface.get_bytes = (void (*) (prf_t *,chunk_t,u_int8_t*))get_bytes;
+ this->public.prf_interface.allocate_bytes = (void (*) (prf_t*,chunk_t,chunk_t*))allocate_bytes;
+ this->public.prf_interface.get_block_size = (size_t (*) (prf_t*))get_block_size;
+ this->public.prf_interface.get_key_size = (size_t (*) (prf_t*))get_key_size;
+ this->public.prf_interface.set_key = (void (*) (prf_t *,chunk_t))set_key;
+ this->public.prf_interface.destroy = (void (*) (prf_t *))destroy;
+
+ this->hasher = (private_sha1_hasher_t*)sha1_hasher_create(HASH_SHA1);
+
+ return &this->public;
+}
+
diff --git a/src/libstrongswan/plugins/sha1/sha1_prf.h b/src/libstrongswan/plugins/sha1/sha1_prf.h
new file mode 100644
index 000000000..a0f56b681
--- /dev/null
+++ b/src/libstrongswan/plugins/sha1/sha1_prf.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup sha1_prf sha1_prf
+ * @{ @ingroup sha1_p
+ */
+
+#ifndef SHA1_PRF_H_
+#define SHA1_PRF_H_
+
+typedef struct sha1_prf_t sha1_prf_t;
+
+#include <crypto/prfs/prf.h>
+
+/**
+ * Implementation of prf_t interface using keyed SHA1 algorithm (used for EAP-AKA).
+ */
+struct sha1_prf_t {
+
+ /**
+ * Implements prf_t interface.
+ */
+ prf_t prf_interface;
+};
+
+/**
+ * Creates a new sha1_prf_t.
+ *
+ * @param algo algorithm, must be PRF_KEYED_SHA1
+ * @return sha1_keyed_prf_tobject
+ */
+sha1_prf_t *sha1_prf_create(pseudo_random_function_t algo);
+
+#endif /*SHA1_PRF_H_ @}*/
diff --git a/src/libstrongswan/plugins/sha2/Makefile.in b/src/libstrongswan/plugins/sha2/Makefile.in
index ec0e45248..ea5610671 100644
--- a/src/libstrongswan/plugins/sha2/Makefile.in
+++ b/src/libstrongswan/plugins/sha2/Makefile.in
@@ -187,6 +187,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/sqlite/Makefile.in b/src/libstrongswan/plugins/sqlite/Makefile.in
index 3a73829dc..21773de32 100644
--- a/src/libstrongswan/plugins/sqlite/Makefile.in
+++ b/src/libstrongswan/plugins/sqlite/Makefile.in
@@ -189,6 +189,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/sqlite/sqlite_database.c b/src/libstrongswan/plugins/sqlite/sqlite_database.c
index d5a03894d..c8d9e5beb 100644
--- a/src/libstrongswan/plugins/sqlite/sqlite_database.c
+++ b/src/libstrongswan/plugins/sqlite/sqlite_database.c
@@ -12,12 +12,13 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: sqlite_database.c 3911 2008-05-07 14:41:13Z martin $
+ * $Id: sqlite_database.c 4268 2008-08-21 11:58:58Z andreas $
*/
#include "sqlite_database.h"
#include <sqlite3.h>
+#include <unistd.h>
#include <library.h>
#include <debug.h>
#include <utils/mutex.h>
@@ -131,8 +132,8 @@ typedef struct {
int count;
/** column types */
db_type_t *columns;
- /** reference to db connection */
- sqlite3 *db;
+ /** back reference to parent */
+ private_sqlite_database_t *database;
} sqlite_enumerator_t;
/**
@@ -141,6 +142,9 @@ typedef struct {
static void sqlite_enumerator_destroy(sqlite_enumerator_t *this)
{
sqlite3_finalize(this->stmt);
+#if SQLITE_VERSION_NUMBER < 3005000
+ this->database->mutex->unlock(this->database->mutex);
+#endif
free(this->columns);
free(this);
}
@@ -158,7 +162,8 @@ static bool sqlite_enumerator_enumerate(sqlite_enumerator_t *this, ...)
case SQLITE_ROW:
break;
default:
- DBG1("stepping sqlite statement failed: %s", sqlite3_errmsg(this->db));
+ DBG1("stepping sqlite statement failed: %s",
+ sqlite3_errmsg(this->database->db));
/* fall */
case SQLITE_DONE:
return FALSE;
@@ -218,6 +223,10 @@ static enumerator_t* query(private_sqlite_database_t *this, char *sql, ...)
sqlite_enumerator_t *enumerator = NULL;
int i;
+#if SQLITE_VERSION_NUMBER < 3005000
+ /* sqlite connections prior to 3.5 may be used by a single thread only, */
+ this->mutex->lock(this->mutex);
+#endif
va_start(args, sql);
stmt = run(this, sql, &args);
@@ -229,7 +238,7 @@ static enumerator_t* query(private_sqlite_database_t *this, char *sql, ...)
enumerator->stmt = stmt;
enumerator->count = sqlite3_column_count(stmt);
enumerator->columns = malloc(sizeof(db_type_t) * enumerator->count);
- enumerator->db = this->db;
+ enumerator->database = this;
for (i = 0; i < enumerator->count; i++)
{
enumerator->columns[i] = va_arg(args, db_type_t);
@@ -274,6 +283,25 @@ static int execute(private_sqlite_database_t *this, int *rowid, char *sql, ...)
}
/**
+ * Implementation of database_t.get_driver
+ */
+static db_driver_t get_driver(private_sqlite_database_t *this)
+{
+ return DB_SQLITE;
+}
+
+/**
+ * Busy handler implementation
+ */
+static int busy_handler(private_sqlite_database_t *this, int count)
+{
+ /* add a backoff time, quadratically increasing with every try */
+ usleep(count * count * 1000);
+ /* always retry */
+ return 1;
+}
+
+/**
* Implementation of database_t.destroy
*/
static void destroy(private_sqlite_database_t *this)
@@ -304,9 +332,10 @@ sqlite_database_t *sqlite_database_create(char *uri)
this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
+ this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
this->public.db.destroy = (void(*)(database_t*))destroy;
- this->mutex = mutex_create(MUTEX_DEFAULT);
+ this->mutex = mutex_create(MUTEX_RECURSIVE);
if (sqlite3_open(file, &this->db) != SQLITE_OK)
{
@@ -316,6 +345,8 @@ sqlite_database_t *sqlite_database_create(char *uri)
return NULL;
}
+ sqlite3_busy_handler(this->db, (void*)busy_handler, this);
+
return &this->public;
}
diff --git a/src/libstrongswan/plugins/x509/Makefile.in b/src/libstrongswan/plugins/x509/Makefile.in
index 9178d6c8c..01093e862 100644
--- a/src/libstrongswan/plugins/x509/Makefile.in
+++ b/src/libstrongswan/plugins/x509/Makefile.in
@@ -189,6 +189,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/x509/x509_ac.c b/src/libstrongswan/plugins/x509/x509_ac.c
index cfa38c66b..caae5e08d 100644
--- a/src/libstrongswan/plugins/x509/x509_ac.c
+++ b/src/libstrongswan/plugins/x509/x509_ac.c
@@ -1054,6 +1054,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
{
va_list args;
certificate_t *cert;
+ chunk_t chunk;
va_start(args, part);
switch (part)
@@ -1070,7 +1071,8 @@ static void add(private_builder_t *this, builder_part_t part, ...)
{
destroy(this->ac);
}
- this->ac = create_from_chunk(va_arg(args, chunk_t));
+ chunk = va_arg(args, chunk_t);
+ this->ac = create_from_chunk(chunk_clone(chunk));
break;
case BUILD_NOT_BEFORE_TIME:
this->ac->notBefore = va_arg(args, time_t);
@@ -1079,7 +1081,8 @@ static void add(private_builder_t *this, builder_part_t part, ...)
this->ac->notAfter = va_arg(args, time_t);
break;
case BUILD_SERIAL:
- this->ac->serialNumber = va_arg(args, chunk_t);
+ chunk = va_arg(args, chunk_t);
+ this->ac->serialNumber = chunk_clone(chunk);
break;
case BUILD_IETF_GROUP_ATTR:
ietfAttr_list_create_from_string(va_arg(args, char*),
@@ -1089,29 +1092,27 @@ static void add(private_builder_t *this, builder_part_t part, ...)
cert = va_arg(args, certificate_t*);
if (cert->get_type(cert) == CERT_X509)
{
- this->ac->holderCert = cert;
- }
- else
- {
- cert->destroy(cert);
+ this->ac->holderCert = cert->get_ref(cert);
}
break;
case BUILD_SIGNING_CERT:
cert = va_arg(args, certificate_t*);
if (cert->get_type(cert) == CERT_X509)
{
- this->ac->signerCert = cert;
- }
- else
- {
- cert->destroy(cert);
+ this->ac->signerCert = cert->get_ref(cert);
}
break;
case BUILD_SIGNING_KEY:
this->ac->signerKey = va_arg(args, private_key_t*);
+ this->ac->signerKey->get_ref(this->ac->signerKey);
break;
default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
+ /* abort if unsupported option */
+ if (this->ac)
+ {
+ destroy(this->ac);
+ }
+ builder_cancel(&this->public);
break;
}
va_end(args);
diff --git a/src/libstrongswan/plugins/x509/x509_cert.c b/src/libstrongswan/plugins/x509/x509_cert.c
index 714258865..c82d14a17 100644
--- a/src/libstrongswan/plugins/x509/x509_cert.c
+++ b/src/libstrongswan/plugins/x509/x509_cert.c
@@ -17,7 +17,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: x509_cert.c 4051 2008-06-10 09:08:27Z tobias $
+ * $Id: x509_cert.c 4317 2008-09-02 11:00:13Z martin $
*/
#define _GNU_SOURCE
@@ -722,7 +722,7 @@ static bool parse_certificate(private_x509_cert_t *this)
break;
case X509_OBJ_SUBJECT_PUBLIC_KEY_INFO:
this->public_key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY,
- KEY_ANY, BUILD_BLOB_ASN1_DER, chunk_clone(object), BUILD_END);
+ KEY_ANY, BUILD_BLOB_ASN1_DER, object, BUILD_END);
if (this->public_key == NULL)
{
DBG1("could not create public key");
@@ -1251,6 +1251,7 @@ static private_x509_cert_t *build(private_builder_t *this)
static void add(private_builder_t *this, builder_part_t part, ...)
{
va_list args;
+ chunk_t chunk;
va_start(args, part);
switch (part)
@@ -1259,13 +1260,19 @@ static void add(private_builder_t *this, builder_part_t part, ...)
this->cert = create_from_file(va_arg(args, char*));
break;
case BUILD_BLOB_ASN1_DER:
- this->cert = create_from_chunk(va_arg(args, chunk_t));
+ chunk = va_arg(args, chunk_t);
+ this->cert = create_from_chunk(chunk_clone(chunk));
break;
case BUILD_X509_FLAG:
this->flags = va_arg(args, x509_flag_t);
break;
default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
+ /* abort if unsupported option */
+ if (this->cert)
+ {
+ destroy(this->cert);
+ }
+ builder_cancel(&this->public);
break;
}
va_end(args);
diff --git a/src/libstrongswan/plugins/x509/x509_crl.c b/src/libstrongswan/plugins/x509/x509_crl.c
index 3bdda1701..eb9bfe903 100644
--- a/src/libstrongswan/plugins/x509/x509_crl.c
+++ b/src/libstrongswan/plugins/x509/x509_crl.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: x509_crl.c 4091 2008-06-22 17:41:07Z andreas $
+ * $Id: x509_crl.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "x509_crl.h"
@@ -693,30 +693,37 @@ static private_x509_crl_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->crl)
+ if (!this->crl)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
+ chunk_t chunk;
- va_start(args, part);
- switch (part)
- {
- case BUILD_FROM_FILE:
- this->crl = create_from_file(va_arg(args, char*));
- break;
- case BUILD_BLOB_ASN1_DER:
+ switch (part)
{
- this->crl = create_from_chunk(va_arg(args, chunk_t));
- break;
+ case BUILD_FROM_FILE:
+ {
+ va_start(args, part);
+ this->crl = create_from_file(va_arg(args, char*));
+ va_end(args);
+ return;
+ }
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->crl = create_from_chunk(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
- va_end(args);
+ if (this->crl)
+ {
+ destroy(this->crl);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/x509/x509_ocsp_request.c b/src/libstrongswan/plugins/x509/x509_ocsp_request.c
index 590a974f7..7b97b990d 100644
--- a/src/libstrongswan/plugins/x509/x509_ocsp_request.c
+++ b/src/libstrongswan/plugins/x509/x509_ocsp_request.c
@@ -14,7 +14,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: x509_ocsp_request.c 4091 2008-06-22 17:41:07Z andreas $
+ * $Id: x509_ocsp_request.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "x509_ocsp_request.h"
@@ -547,6 +547,8 @@ static void add(private_builder_t *this, builder_part_t part, ...)
{
va_list args;
certificate_t *cert;
+ identification_t *subject;
+ private_key_t *private;
va_start(args, part);
switch (part)
@@ -555,35 +557,36 @@ static void add(private_builder_t *this, builder_part_t part, ...)
cert = va_arg(args, certificate_t*);
if (cert->get_type(cert) == CERT_X509)
{
- this->req->ca = (x509_t*)cert;
- }
- else
- {
- cert->destroy(cert);
+ this->req->ca = (x509_t*)cert->get_ref(cert);
}
break;
case BUILD_CERT:
cert = va_arg(args, certificate_t*);
if (cert->get_type(cert) == CERT_X509)
{
- this->req->candidates->insert_last(this->req->candidates, cert);
- }
- else
- {
- cert->destroy(cert);
+ this->req->candidates->insert_last(this->req->candidates,
+ cert->get_ref(cert));
}
break;
case BUILD_SIGNING_CERT:
- this->req->cert = va_arg(args, certificate_t*);
+ cert = va_arg(args, certificate_t*);
+ this->req->cert = cert->get_ref(cert);
break;
case BUILD_SIGNING_KEY:
- this->req->key = va_arg(args, private_key_t*);
+ private = va_arg(args, private_key_t*);
+ this->req->key = private->get_ref(private);
break;
case BUILD_SUBJECT:
- this->req->requestor = va_arg(args, identification_t*);
+ subject = va_arg(args, identification_t*);
+ this->req->requestor = subject->clone(subject);
break;
default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
+ /* cancel if option not supported */
+ if (this->req)
+ {
+ destroy(this->req);
+ }
+ builder_cancel(&this->public);
break;
}
va_end(args);
diff --git a/src/libstrongswan/plugins/x509/x509_ocsp_response.c b/src/libstrongswan/plugins/x509/x509_ocsp_response.c
index 33cf73cd2..01f35864d 100644
--- a/src/libstrongswan/plugins/x509/x509_ocsp_response.c
+++ b/src/libstrongswan/plugins/x509/x509_ocsp_response.c
@@ -14,7 +14,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: x509_ocsp_response.c 4091 2008-06-22 17:41:07Z andreas $
+ * $Id: x509_ocsp_response.c 4317 2008-09-02 11:00:13Z martin $
*/
#include "x509_ocsp_response.h"
@@ -560,8 +560,7 @@ static bool parse_basicOCSPResponse(private_x509_ocsp_response_t *this,
case BASIC_RESPONSE_CERTIFICATE:
{
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE,CERT_X509,
- BUILD_BLOB_ASN1_DER,
- chunk_clone(object),
+ BUILD_BLOB_ASN1_DER, object,
BUILD_END);
if (cert)
{
@@ -944,27 +943,30 @@ static x509_ocsp_response_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->res)
- {
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
-
- switch (part)
+ if (!this->res)
{
- case BUILD_BLOB_ASN1_DER:
+ va_list args;
+ chunk_t chunk;
+
+ switch (part)
{
- va_start(args, part);
- this->res = load(va_arg(args, chunk_t));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ chunk = va_arg(args, chunk_t);
+ this->res = load(chunk_clone(chunk));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->res)
+ {
+ destroy((private_x509_ocsp_response_t*)this->res);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/xcbc/Makefile.in b/src/libstrongswan/plugins/xcbc/Makefile.in
index 3fdf46955..898142582 100644
--- a/src/libstrongswan/plugins/xcbc/Makefile.in
+++ b/src/libstrongswan/plugins/xcbc/Makefile.in
@@ -188,6 +188,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c
index 7c87dccd8..6f9e40395 100644
--- a/src/libstrongswan/settings.c
+++ b/src/libstrongswan/settings.c
@@ -203,8 +203,44 @@ static int get_int(private_settings_t *this, char *key, int def)
}
/**
- * destry a section
-*/
+ * Implementation of settings_t.get_time.
+ */
+static u_int32_t get_time(private_settings_t *this, char *key, u_int32_t def)
+{
+ char *value, *endptr;
+ u_int32_t timeval;
+
+ value = find(this->top, key);
+ if (value)
+ {
+ errno = 0;
+ timeval = strtol(value, &endptr, 10);
+ if (errno == 0 && timeval >= 0)
+ {
+ switch (*endptr)
+ {
+ case 'd': /* time in days */
+ timeval *= 24 * 3600;
+ break;
+ case 'h': /* time in hours */
+ timeval *= 3600;
+ break;
+ case 'm': /* time in minutes */
+ timeval *= 60;
+ break;
+ case 's': /* time in seconds */
+ default:
+ break;
+ }
+ return timeval;
+ }
+ }
+ return def;
+}
+
+/**
+ * destroy a section
+ */
static void section_destroy(section_t *this)
{
this->kv->destroy_function(this->kv, free);
@@ -365,7 +401,8 @@ settings_t *settings_create(char *file)
private_settings_t *this = malloc_thing(private_settings_t);
this->public.get_str = (char*(*)(settings_t*, char *key, char* def))get_str;
- this->public.get_int = (int(*)(settings_t*, char *key, bool def))get_int;
+ this->public.get_int = (int(*)(settings_t*, char *key, int def))get_int;
+ this->public.get_time = (u_int32_t(*)(settings_t*, char *key, u_int32_t def))get_time;
this->public.get_bool = (bool(*)(settings_t*, char *key, bool def))get_bool;
this->public.destroy = (void(*)(settings_t*))destroy;
diff --git a/src/libstrongswan/settings.h b/src/libstrongswan/settings.h
index 91770973b..451c2a583 100644
--- a/src/libstrongswan/settings.h
+++ b/src/libstrongswan/settings.h
@@ -80,9 +80,18 @@ struct settings_t {
* @param def default value to return if key not found
* @return value of the key
*/
- int (*get_int)(settings_t *this, char *key, bool def);
+ int (*get_int)(settings_t *this, char *key, int def);
/**
+ * Get a time value.
+ *
+ * @param key key including sections
+ * @param def default value to return if key not found
+ * @return value of the key
+ */
+ u_int32_t (*get_time)(settings_t *this, char *key, u_int32_t def);
+
+ /**
* Destroy a settings instance.
*/
void (*destroy)(settings_t *this);
diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c
index bd13b7c4d..b2134dfc7 100644
--- a/src/libstrongswan/utils.c
+++ b/src/libstrongswan/utils.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2005-2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -12,16 +13,20 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: utils.c 3820 2008-04-17 11:22:37Z martin $
+ * $Id: utils.c 4305 2008-08-28 07:47:55Z tobias $
*/
#include "utils.h"
+#include <sys/stat.h>
#include <string.h>
#include <pthread.h>
#include <stdio.h>
+#include <unistd.h>
+#include <dirent.h>
#include <enum.h>
+#include <debug.h>
ENUM(status_names, SUCCESS, DESTROY_ME,
"SUCCESS",
@@ -64,6 +69,52 @@ void memxor(u_int8_t dest[], u_int8_t src[], size_t n)
}
/**
+ * Described in header.
+ */
+bool mkdir_p(const char *path, mode_t mode)
+{
+ size_t len;
+ char *pos, full[PATH_MAX];
+ pos = full;
+ if (!path || *path == '\0')
+ {
+ return TRUE;
+ }
+ len = snprintf(full, sizeof(full)-1, "%s", path);
+ if (len < 0 || len >= sizeof(full)-1)
+ {
+ DBG1("path string %s too long", path);
+ return FALSE;
+ }
+ /* ensure that the path ends with a '/' */
+ if (full[len-1] != '/')
+ {
+ full[len++] = '/';
+ full[len] = '\0';
+ }
+ /* skip '/' at the beginning */
+ while (*pos == '/')
+ {
+ pos++;
+ }
+ while ((pos = strchr(pos, '/')))
+ {
+ *pos = '\0';
+ if (access(full, F_OK) < 0)
+ {
+ if (mkdir(full, mode) < 0)
+ {
+ DBG1("failed to create directory %s", full);
+ return FALSE;
+ }
+ }
+ *pos = '/';
+ pos++;
+ }
+ return TRUE;
+}
+
+/**
* return null
*/
void *return_null()
diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h
index ee3ebbd41..4af7df9ad 100644
--- a/src/libstrongswan/utils.h
+++ b/src/libstrongswan/utils.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -12,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: utils.h 3820 2008-04-17 11:22:37Z martin $
+ * $Id: utils.h 4305 2008-08-28 07:47:55Z tobias $
*/
/**
@@ -90,6 +91,11 @@
#define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
/**
+ * Get the number of elements in an array
+ */
+#define countof(array) (sizeof(array)/sizeof(array[0]))
+
+/**
* Assign a function as a class method
*/
#define ASSIGN(method, function) (method = (typeof(method))function)
@@ -103,8 +109,12 @@
* General purpose boolean type.
*/
typedef int bool;
-#define FALSE 0
-#define TRUE 1
+#ifndef FALSE
+# define FALSE 0
+#endif /* FALSE */
+#ifndef TRUE
+# define TRUE 1
+#endif /* TRUE */
typedef enum status_t status_t;
@@ -210,6 +220,15 @@ void *clalloc(void *pointer, size_t size);
void memxor(u_int8_t dest[], u_int8_t src[], size_t n);
/**
+ * Creates a directory and all required parent directories.
+ *
+ * @param path path to the new directory
+ * @param mode permissions of the new directory/directories
+ * @return TRUE on success
+ */
+bool mkdir_p(const char *path, mode_t mode);
+
+/**
* returns null
*/
void *return_null();
diff --git a/src/libstrongswan/utils/enumerator.c b/src/libstrongswan/utils/enumerator.c
index cac5d73fa..4ebc2e097 100644
--- a/src/libstrongswan/utils/enumerator.c
+++ b/src/libstrongswan/utils/enumerator.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: enumerator.c 3589 2008-03-13 14:14:44Z martin $
+ * $Id: enumerator.c 4142 2008-07-02 08:09:07Z martin $
*/
#include "enumerator.h"
@@ -154,6 +154,145 @@ enumerator_t* enumerator_create_directory(char *path)
}
/**
+ * Enumerator implementation for directory enumerator
+ */
+typedef struct {
+ /** implements enumerator_t */
+ enumerator_t public;
+ /** string to parse */
+ char *string;
+ /** current position */
+ char *pos;
+ /** separater chars */
+ char *sep;
+ /** trim chars */
+ char *trim;
+} token_enum_t;
+
+/**
+ * Implementation of enumerator_create_token().destroy
+ */
+static void destroy_token_enum(token_enum_t *this)
+{
+ free(this->string);
+ free(this);
+}
+
+/**
+ * Implementation of enumerator_create_token().enumerate
+ */
+static bool enumerate_token_enum(token_enum_t *this, char **token)
+{
+ char *pos = NULL, *tmp, *sep, *trim;
+ bool last = FALSE;
+
+ /* trim leading characters/separators */
+ while (*this->pos)
+ {
+ trim = this->trim;
+ while (*trim)
+ {
+ if (*trim == *this->pos)
+ {
+ this->pos++;
+ break;
+ }
+ trim++;
+ }
+ sep = this->sep;
+ while (*sep)
+ {
+ if (*sep == *this->pos)
+ {
+ this->pos++;
+ break;
+ }
+ sep++;
+ }
+ if (!*trim && !*sep)
+ {
+ break;
+ }
+ }
+
+ /* find separators */
+ sep = this->sep;
+ while (*sep)
+ {
+ tmp = strchr(this->pos, *sep);
+ if (tmp && (pos == NULL || tmp < pos))
+ {
+ pos = tmp;
+ }
+ sep++;
+ }
+ *token = this->pos;
+ if (pos)
+ {
+ *pos = '\0';
+ this->pos = pos + 1;
+ }
+ else
+ {
+ last = TRUE;
+ pos = this->pos = strchr(this->pos, '\0');
+ }
+
+ /* trim trailing characters/separators */
+ pos--;
+ while (pos >= *token)
+ {
+ trim = this->trim;
+ while (*trim)
+ {
+ if (*trim == *pos)
+ {
+ *(pos--) = '\0';
+ break;
+ }
+ trim++;
+ }
+ sep = this->sep;
+ while (*sep)
+ {
+ if (*sep == *pos)
+ {
+ *(pos--) = '\0';
+ break;
+ }
+ sep++;
+ }
+ if (!*trim && !*sep)
+ {
+ break;
+ }
+ }
+
+ if (!last || pos > *token)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * See header
+ */
+enumerator_t* enumerator_create_token(char *string, char *sep, char *trim)
+{
+ token_enum_t *enumerator = malloc_thing(token_enum_t);
+
+ enumerator->public.enumerate = (void*)enumerate_token_enum;
+ enumerator->public.destroy = (void*)destroy_token_enum;
+ enumerator->string = strdup(string);
+ enumerator->pos = enumerator->string;
+ enumerator->sep = sep;
+ enumerator->trim = trim;
+
+ return &enumerator->public;
+}
+
+/**
* enumerator for nested enumerations
*/
typedef struct {
diff --git a/src/libstrongswan/utils/enumerator.h b/src/libstrongswan/utils/enumerator.h
index 6b91fee72..d82f650db 100644
--- a/src/libstrongswan/utils/enumerator.h
+++ b/src/libstrongswan/utils/enumerator.h
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: enumerator.h 3589 2008-03-13 14:14:44Z martin $
+ * $Id: enumerator.h 4142 2008-07-02 08:09:07Z martin $
*/
/**
@@ -98,6 +98,19 @@ enumerator_t *enumerator_create_single(void *item, void (*cleanup)(void *item));
enumerator_t* enumerator_create_directory(char *path);
/**
+ * Create an enumerator over tokens of a string.
+ *
+ * Tokens are separated by one of the characters in sep and trimmed by the
+ * characters in trim.
+ *
+ * @param string string to parse
+ * @param sep separator characters
+ * @param trim characters to trim from tokens
+ * @return enumerator over char* tokens
+ */
+enumerator_t* enumerator_create_token(char *string, char *sep, char *trim);
+
+/**
* Creates an enumerator which enumerates over enumerated enumerators :-).
*
* The variable argument list of enumeration values is limit to 5.
diff --git a/src/libstrongswan/utils/identification.c b/src/libstrongswan/utils/identification.c
index 39d49bf6c..db442e9ab 100644
--- a/src/libstrongswan/utils/identification.c
+++ b/src/libstrongswan/utils/identification.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: identification.c 4064 2008-06-13 15:10:01Z martin $
+ * $Id: identification.c 4344 2008-09-17 02:17:01Z andreas $
*/
#define _GNU_SOURCE
@@ -915,6 +915,8 @@ static int print(FILE *stream, const struct printf_info *info,
case ID_FQDN:
case ID_RFC822_ADDR:
case ID_DER_ASN1_GN_URI:
+ case ID_EAP:
+ case ID_IETF_ATTR_STRING:
proper = sanitize_chunk(this->encoded);
snprintf(buf, sizeof(buf), "%.*s", proper.len, proper.ptr);
chunk_free(&proper);
@@ -1169,6 +1171,8 @@ identification_t *identification_create_from_encoding(id_type_t type, chunk_t en
case ID_PUBKEY_INFO_SHA1:
case ID_PUBKEY_SHA1:
case ID_CERT_DER_SHA1:
+ case ID_EAP:
+ case ID_IETF_ATTR_STRING:
default:
break;
}
diff --git a/src/libstrongswan/utils/identification.h b/src/libstrongswan/utils/identification.h
index 591909411..3b895961d 100644
--- a/src/libstrongswan/utils/identification.h
+++ b/src/libstrongswan/utils/identification.h
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: identification.h 3838 2008-04-18 11:24:45Z tobias $
+ * $Id: identification.h 4344 2008-09-17 02:17:01Z andreas $
*/
/**
@@ -131,17 +131,27 @@ enum id_type_t {
/**
* SHA1 hash over PKCS#1 subjectPublicKeyInfo
*/
- ID_PUBKEY_INFO_SHA1,
+ ID_PUBKEY_INFO_SHA1 = 202,
/**
* SHA1 hash over PKCS#1 subjectPublicKey
*/
- ID_PUBKEY_SHA1,
+ ID_PUBKEY_SHA1 = 203,
/**
* SHA1 hash of the binary DER encoding of a certificate
*/
- ID_CERT_DER_SHA1,
+ ID_CERT_DER_SHA1 = 204,
+
+ /**
+ * Generic EAP identity
+ */
+ ID_EAP = 205,
+
+ /**
+ * IETF Attribute Syntax String (RFC 3281)
+ */
+ ID_IETF_ATTR_STRING = 206,
};
/**
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c
index cff5a1c81..bc7f56ebd 100644
--- a/src/libstrongswan/utils/leak_detective.c
+++ b/src/libstrongswan/utils/leak_detective.c
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: leak_detective.c 4044 2008-06-06 15:05:54Z martin $
+ * $Id: leak_detective.c 4311 2008-08-28 16:27:48Z martin $
*/
#ifdef HAVE_DLADDR
@@ -262,6 +262,7 @@ char *whitelist[] = {
/* ignore dlopen, as we do not dlclose to get proper leak reports */
"dlopen",
"dlerror",
+ "dlclose",
/* mysql functions */
"mysql_init_character_set",
"init_client_errs",
@@ -277,6 +278,7 @@ char *whitelist[] = {
/* OpenSSL */
"RSA_new_method",
"DH_new_method",
+ "ENGINE_load_builtin_engines",
};
/**
@@ -558,6 +560,7 @@ leak_detective_t *leak_detective_create()
if (getenv("LEAK_DETECTIVE_DISABLE") == NULL)
{
+ lib->leak_detective = TRUE;
install_hooks();
}
return &this->public;