Added eap-dynamic plugin which can proxy any other EAP method
authorTobias Brunner <tobias@strongswan.org>
Thu, 23 Aug 2012 12:42:23 +0000 (14:42 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 31 Aug 2012 09:42:01 +0000 (11:42 +0200)
configure.in
src/libcharon/Makefile.am
src/libcharon/plugins/eap_dynamic/Makefile.am [new file with mode: 0644]
src/libcharon/plugins/eap_dynamic/eap_dynamic.c [new file with mode: 0644]
src/libcharon/plugins/eap_dynamic/eap_dynamic.h [new file with mode: 0644]
src/libcharon/plugins/eap_dynamic/eap_dynamic_plugin.c [new file with mode: 0644]
src/libcharon/plugins/eap_dynamic/eap_dynamic_plugin.h [new file with mode: 0644]
src/libstrongswan/eap/eap.c
src/libstrongswan/eap/eap.h

index 2ab96e0..a1c777a 100644 (file)
@@ -154,6 +154,7 @@ ARG_ENABL_SET([eap-tls],        [enable EAP TLS authentication module.])
 ARG_ENABL_SET([eap-ttls],       [enable EAP TTLS authentication module.])
 ARG_ENABL_SET([eap-peap],       [enable EAP PEAP authentication module.])
 ARG_ENABL_SET([eap-tnc],        [enable EAP TNC trusted network connect module.])
+ARG_ENABL_SET([eap-dynamic],    [enable dynamic EAP proxy module.])
 ARG_ENABL_SET([eap-radius],     [enable RADIUS proxy authentication module.])
 ARG_DISBL_SET([xauth-generic],  [disable generic XAuth backend.])
 ARG_ENABL_SET([xauth-eap],      [enable XAuth backend using EAP methods to verify passwords.])
@@ -922,6 +923,7 @@ ADD_PLUGIN([eap-simaka-reauth],    [c charon])
 ADD_PLUGIN([eap-md5],              [c charon nm])
 ADD_PLUGIN([eap-gtc],              [c charon nm])
 ADD_PLUGIN([eap-mschapv2],         [c charon nm])
+ADD_PLUGIN([eap-dynamic],          [c charon])
 ADD_PLUGIN([eap-radius],           [c charon])
 ADD_PLUGIN([eap-tls],              [c charon nm])
 ADD_PLUGIN([eap-ttls],             [c charon nm])
@@ -1055,6 +1057,7 @@ AM_CONDITIONAL(USE_EAP_TLS, test x$eap_tls = xtrue)
 AM_CONDITIONAL(USE_EAP_TTLS, test x$eap_ttls = xtrue)
 AM_CONDITIONAL(USE_EAP_PEAP, test x$eap_peap = xtrue)
 AM_CONDITIONAL(USE_EAP_TNC, test x$eap_tnc = xtrue)
+AM_CONDITIONAL(USE_EAP_DYNAMIC, test x$eap_dynamic = xtrue)
 AM_CONDITIONAL(USE_EAP_RADIUS, test x$eap_radius = xtrue)
 AM_CONDITIONAL(USE_XAUTH_GENERIC, test x$xauth_generic = xtrue)
 AM_CONDITIONAL(USE_XAUTH_EAP, test x$xauth_eap = xtrue)
@@ -1222,6 +1225,7 @@ AC_OUTPUT(
        src/libcharon/Makefile
        src/libcharon/plugins/eap_aka/Makefile
        src/libcharon/plugins/eap_aka_3gpp2/Makefile
+       src/libcharon/plugins/eap_dynamic/Makefile
        src/libcharon/plugins/eap_identity/Makefile
        src/libcharon/plugins/eap_md5/Makefile
        src/libcharon/plugins/eap_gtc/Makefile
index eada68b..3869066 100644 (file)
@@ -316,6 +316,13 @@ if MONOLITHIC
 endif
 endif
 
+if USE_EAP_DYNAMIC
+  SUBDIRS += plugins/eap_dynamic
+if MONOLITHIC
+  libcharon_la_LIBADD += plugins/eap_dynamic/libstrongswan-eap-dynamic.la
+endif
+endif
+
 if USE_EAP_RADIUS
   SUBDIRS += plugins/eap_radius
 if MONOLITHIC
diff --git a/src/libcharon/plugins/eap_dynamic/Makefile.am b/src/libcharon/plugins/eap_dynamic/Makefile.am
new file mode 100644 (file)
index 0000000..0d07fbf
--- /dev/null
@@ -0,0 +1,16 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+       -I$(top_srcdir)/src/libcharon
+
+AM_CFLAGS = -rdynamic
+
+if MONOLITHIC
+noinst_LTLIBRARIES = libstrongswan-eap-dynamic.la
+else
+plugin_LTLIBRARIES = libstrongswan-eap-dynamic.la
+endif
+
+libstrongswan_eap_dynamic_la_SOURCES = \
+       eap_dynamic_plugin.h eap_dynamic_plugin.c eap_dynamic.h eap_dynamic.c
+
+libstrongswan_eap_dynamic_la_LDFLAGS = -module -avoid-version
diff --git a/src/libcharon/plugins/eap_dynamic/eap_dynamic.c b/src/libcharon/plugins/eap_dynamic/eap_dynamic.c
new file mode 100644 (file)
index 0000000..a75f458
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * 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.
+ */
+
+#include "eap_dynamic.h"
+
+#include <daemon.h>
+#include <library.h>
+
+typedef struct private_eap_dynamic_t private_eap_dynamic_t;
+
+/**
+ * Private data of an eap_dynamic_t object.
+ */
+struct private_eap_dynamic_t {
+
+       /**
+        * Public authenticator_t interface.
+        */
+       eap_dynamic_t public;
+
+       /**
+        * ID of the server
+        */
+       identification_t *server;
+
+       /**
+        * ID of the peer
+        */
+       identification_t *peer;
+
+       /**
+        * The proxied EAP method
+        */
+       eap_method_t *method;
+};
+
+METHOD(eap_method_t, initiate, status_t,
+       private_eap_dynamic_t *this, eap_payload_t **out)
+{
+       return FAILED;
+}
+
+METHOD(eap_method_t, process, status_t,
+       private_eap_dynamic_t *this, eap_payload_t *in, eap_payload_t **out)
+{
+       return FAILED;
+}
+
+METHOD(eap_method_t, get_type, eap_type_t,
+       private_eap_dynamic_t *this, u_int32_t *vendor)
+{
+       if (this->method)
+       {
+               return this->method->get_type(this->method, vendor);
+       }
+       *vendor = 0;
+       return EAP_DYNAMIC;
+}
+
+METHOD(eap_method_t, get_msk, status_t,
+       private_eap_dynamic_t *this, chunk_t *msk)
+{
+       if (this->method)
+       {
+               return this->method->get_msk(this->method, msk);
+       }
+       return FAILED;
+}
+
+METHOD(eap_method_t, get_identifier, u_int8_t,
+       private_eap_dynamic_t *this)
+{
+       if (this->method)
+       {
+               return this->method->get_identifier(this->method);
+       }
+       return 0;
+}
+
+METHOD(eap_method_t, set_identifier, void,
+       private_eap_dynamic_t *this, u_int8_t identifier)
+{
+       if (this->method)
+       {
+               this->method->set_identifier(this->method, identifier);
+       }
+}
+
+METHOD(eap_method_t, is_mutual, bool,
+       private_eap_dynamic_t *this)
+{
+       if (this->method)
+       {
+               return this->method->is_mutual(this->method);
+       }
+       return FALSE;
+}
+
+METHOD(eap_method_t, destroy, void,
+       private_eap_dynamic_t *this)
+{
+       DESTROY_IF(this->method);
+       this->server->destroy(this->server);
+       this->peer->destroy(this->peer);
+       free(this);
+}
+
+/*
+ * Defined in header
+ */
+eap_dynamic_t *eap_dynamic_create(identification_t *server,
+                                                                 identification_t *peer)
+{
+       private_eap_dynamic_t *this;
+
+       INIT(this,
+               .public = {
+                       .interface = {
+                               .initiate = _initiate,
+                               .process = _process,
+                               .get_type = _get_type,
+                               .is_mutual = _is_mutual,
+                               .get_msk = _get_msk,
+                               .get_identifier = _get_identifier,
+                               .set_identifier = _set_identifier,
+                               .destroy = _destroy,
+                       },
+               },
+               .peer = peer->clone(peer),
+               .server = server->clone(server),
+       );
+
+       return &this->public;
+}
diff --git a/src/libcharon/plugins/eap_dynamic/eap_dynamic.h b/src/libcharon/plugins/eap_dynamic/eap_dynamic.h
new file mode 100644 (file)
index 0000000..35db4fa
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * 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 eap_dynamic_i eap_dynamic
+ * @{ @ingroup eap_dynamic
+ */
+
+#ifndef EAP_DYNAMIC_H_
+#define EAP_DYNAMIC_H_
+
+typedef struct eap_dynamic_t eap_dynamic_t;
+
+#include <sa/eap/eap_method.h>
+
+/**
+ * Implementation of the eap_method_t interface for a virtual EAP method that
+ * proxies other EAP methods and supports the selection of the actual method
+ * by the client.
+ */
+struct eap_dynamic_t {
+
+       /**
+        * Implemented eap_method_t interface
+        */
+       eap_method_t interface;
+};
+
+/**
+ * Create a dynamic EAP proxy serving any supported real method which is also
+ * supported (or selected) by the client.
+ *
+ * @param server       ID of the EAP server
+ * @param peer         ID of the EAP client
+ * @return                     eap_dynamic_t object
+ */
+eap_dynamic_t *eap_dynamic_create(identification_t *server,
+                                                                 identification_t *peer);
+
+#endif /** EAP_DYNAMIC_H_ @}*/
diff --git a/src/libcharon/plugins/eap_dynamic/eap_dynamic_plugin.c b/src/libcharon/plugins/eap_dynamic/eap_dynamic_plugin.c
new file mode 100644 (file)
index 0000000..d6f38b6
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * 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.
+ */
+
+#include "eap_dynamic_plugin.h"
+
+#include "eap_dynamic.h"
+
+#include <daemon.h>
+
+METHOD(plugin_t, get_name, char*,
+       eap_dynamic_plugin_t *this)
+{
+       return "eap-dynamic";
+}
+
+METHOD(plugin_t, get_features, int,
+       eap_dynamic_plugin_t *this, plugin_feature_t *features[])
+{
+       static plugin_feature_t f[] = {
+               PLUGIN_CALLBACK(eap_method_register, eap_dynamic_create),
+                       PLUGIN_PROVIDE(EAP_SERVER, EAP_DYNAMIC),
+       };
+       *features = f;
+       return countof(f);
+}
+
+METHOD(plugin_t, destroy, void,
+       eap_dynamic_plugin_t *this)
+{
+       free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *eap_dynamic_plugin_create()
+{
+       eap_dynamic_plugin_t *this;
+
+       INIT(this,
+               .plugin = {
+                       .get_name = _get_name,
+                       .get_features = _get_features,
+                       .destroy = _destroy,
+               },
+       );
+
+       return &this->plugin;
+}
+
diff --git a/src/libcharon/plugins/eap_dynamic/eap_dynamic_plugin.h b/src/libcharon/plugins/eap_dynamic/eap_dynamic_plugin.h
new file mode 100644 (file)
index 0000000..9b124d8
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * 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 eap_dynamic eap_dynamic
+ * @ingroup cplugins
+ *
+ * @defgroup eap_dynamic_plugin eap_dynamic_plugin
+ * @{ @ingroup eap_dynamic
+ */
+
+#ifndef EAP_DYNAMIC_PLUGIN_H_
+#define EAP_DYNAMIC_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct eap_dynamic_plugin_t eap_dynamic_plugin_t;
+
+/**
+ * EAP plugin that can use any supported EAP method the client supports or
+ * prefers to use.
+ */
+struct eap_dynamic_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       plugin_t plugin;
+};
+
+#endif /** EAP_DYNAMIC_PLUGIN_H_ @}*/
index 2cc4883..1e4cf11 100644 (file)
@@ -114,6 +114,7 @@ eap_type_t eap_type_from_string(char *name)
                {"peap",                EAP_PEAP},
                {"mschapv2",    EAP_MSCHAPV2},
                {"tnc",                 EAP_TNC},
+               {"dynamic",             EAP_DYNAMIC},
                {"radius",              EAP_RADIUS},
        };
 
index d824783..0e144b1 100644 (file)
@@ -71,7 +71,7 @@ enum eap_type_t {
        EAP_EXPERIMENTAL = 255,
        /** not a method, but an implementation providing different methods */
        EAP_RADIUS = 256,
-       /** not a method, select actual method dynamically based on e.g. the ID */
+       /** not a method, select method dynamically based on client selection */
        EAP_DYNAMIC = 257,
 };