renamed med_db plugin to medsrv, as we will introduce an additional medcli client...
authorMartin Willi <martin@strongswan.org>
Thu, 8 May 2008 12:11:30 +0000 (12:11 -0000)
committerMartin Willi <martin@strongswan.org>
Thu, 8 May 2008 12:11:30 +0000 (12:11 -0000)
24 files changed:
configure.in
src/charon/Makefile.am
src/charon/plugins/med_db/Makefile.am [deleted file]
src/charon/plugins/med_db/med_db_config.c [deleted file]
src/charon/plugins/med_db/med_db_config.h [deleted file]
src/charon/plugins/med_db/med_db_creds.c [deleted file]
src/charon/plugins/med_db/med_db_creds.h [deleted file]
src/charon/plugins/med_db/med_db_plugin.c [deleted file]
src/charon/plugins/med_db/med_db_plugin.h [deleted file]
src/charon/plugins/med_db/med_db_pubkey.c [deleted file]
src/charon/plugins/med_db/med_db_pubkey.h [deleted file]
src/charon/plugins/med_db/mysql.sql [deleted file]
src/charon/plugins/med_db/test.sql [deleted file]
src/charon/plugins/medsrv/Makefile.am [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_config.c [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_config.h [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_creds.c [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_creds.h [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_plugin.c [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_plugin.h [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_pubkey.c [new file with mode: 0644]
src/charon/plugins/medsrv/medsrv_pubkey.h [new file with mode: 0644]
src/charon/plugins/medsrv/mysql.sql [new file with mode: 0644]
src/charon/plugins/medsrv/test.sql [new file with mode: 0644]

index b29ce3a..d03f2fb 100644 (file)
@@ -304,10 +304,10 @@ AC_ARG_ENABLE(
 )
 
 AC_ARG_ENABLE(
-       [med-db],
-       AS_HELP_STRING([--enable-med-db],[enable MySQL mediation database plugin (default is NO).]),
+       [medsrv],
+       AS_HELP_STRING([--enable-medsrv],[enable mediation server configuration database plugin (default is NO).]),
        [if test x$enableval = xyes; then
-               med_db=true
+               medsrv=true
        fi]
 )
 
@@ -665,7 +665,7 @@ AM_CONDITIONAL(USE_XCBC, test x$xcbc = xtrue)
 AM_CONDITIONAL(USE_MYSQL, test x$mysql = xtrue)
 AM_CONDITIONAL(USE_SQLITE, test x$sqlite = xtrue)
 AM_CONDITIONAL(USE_STROKE, test x$stroke = xtrue)
-AM_CONDITIONAL(USE_MED_DB, test x$med_db = xtrue)
+AM_CONDITIONAL(USE_MEDSRV, test x$medsrv = xtrue)
 AM_CONDITIONAL(USE_SMP, test x$smp = xtrue)
 AM_CONDITIONAL(USE_SQL, test x$sql = xtrue)
 AM_CONDITIONAL(USE_SMARTCARD, test x$smartcard = xtrue)
@@ -739,7 +739,7 @@ AC_OUTPUT(
        src/charon/plugins/eap_sim/Makefile
        src/charon/plugins/smp/Makefile
        src/charon/plugins/sql/Makefile
-       src/charon/plugins/med_db/Makefile
+       src/charon/plugins/medsrv/Makefile
        src/charon/plugins/stroke/Makefile
        src/charon/plugins/unit_tester/Makefile
        src/stroke/Makefile
index b7bf4c4..c1306ce 100644 (file)
@@ -162,7 +162,7 @@ if USE_EAP_AKA
   SUBDIRS += plugins/eap_aka
 endif
 
-if USE_MED_DB
-  SUBDIRS += plugins/med_db
+if USE_MEDSRV
+  SUBDIRS += plugins/medsrv
 endif
 
diff --git a/src/charon/plugins/med_db/Makefile.am b/src/charon/plugins/med_db/Makefile.am
deleted file mode 100644 (file)
index 3e06078..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/charon
-
-AM_CFLAGS = -rdynamic
-
-plugin_LTLIBRARIES = libcharon-med-db.la
-libcharon_med_db_la_SOURCES = med_db_plugin.h med_db_plugin.c \
-                             med_db_creds.h med_db_creds.c \
-                             med_db_config.h med_db_config.c \
-                             med_db_pubkey.h med_db_pubkey.c
-libcharon_med_db_la_LDFLAGS = -module
-
diff --git a/src/charon/plugins/med_db/med_db_config.c b/src/charon/plugins/med_db/med_db_config.c
deleted file mode 100644 (file)
index d129cbe..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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 <string.h>
-
-#include "med_db_config.h"
-
-#include <daemon.h>
-
-typedef struct private_med_db_config_t private_med_db_config_t;
-
-/**
- * Private data of an med_db_config_t object
- */
-struct private_med_db_config_t {
-
-       /**
-        * Public part
-        */
-       med_db_config_t public;
-       
-       /**
-        * database connection
-        */
-       database_t *db;
-       
-       /**
-        * rekey time
-        */
-       int rekey;
-       
-       /**
-        * dpd delay
-        */
-       int dpd;
-       
-       /**
-        * default ike config
-        */
-       ike_cfg_t *ike;
-};
-
-/**
- * implements backend_t.get_peer_cfg_by_name.
- */
-static peer_cfg_t *get_peer_cfg_by_name(private_med_db_config_t *this, char *name)
-{
-       return NULL;
-}
-
-/**
- * Implementation of backend_t.create_ike_cfg_enumerator.
- */
-static enumerator_t* create_ike_cfg_enumerator(private_med_db_config_t *this,
-                                                                                          host_t *me, host_t *other)
-{
-       return enumerator_create_single(this->ike, NULL);
-}
-
-/**
- * Implementation of backend_t.create_peer_cfg_enumerator.
- */
-static enumerator_t* create_peer_cfg_enumerator(private_med_db_config_t *this,
-                                                                                               identification_t *me,
-                                                                                               identification_t *other)
-{
-       enumerator_t *e;
-       
-       if (!me || !other || other->get_type(other) != ID_KEY_ID)
-       {
-               return NULL;
-       }
-       e = this->db->query(this->db,
-                       "SELECT CONCAT(Peer.Alias, CONCAT('@', User.Login)) FROM "
-                       "Peer JOIN User ON Peer.IdUser = User.IdUser "
-                       "WHERE Peer.KeyID = ?", DB_BLOB, other->get_encoding(other),
-                       DB_TEXT);
-       if (e)
-       {
-               peer_cfg_t *peer_cfg;
-               char *name;
-               
-               if (e->enumerate(e, &name))
-               {
-                       peer_cfg = peer_cfg_create(
-                               name, 2, this->ike->get_ref(this->ike),
-                               me->clone(me), other->clone(other),
-                               CERT_NEVER_SEND, UNIQUE_REPLACE, AUTH_RSA,
-                               0, 0,                                                   /* EAP method, vendor */
-                               1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
-                               this->rekey*5, this->rekey*3,   /* jitter, overtime */
-                               TRUE, this->dpd,                                /* mobike, dpddelay */
-                               NULL, NULL,                                     /* vip, pool */
-                               TRUE, NULL, NULL);                              /* mediation, med by, peer id */
-                       e->destroy(e);
-                       return enumerator_create_single(peer_cfg, (void*)peer_cfg->destroy);
-               }
-               e->destroy(e);
-       }
-       return NULL;
-}
-
-/**
- * Implementation of med_db_config_t.destroy.
- */
-static void destroy(private_med_db_config_t *this)
-{
-       this->ike->destroy(this->ike);
-       free(this);
-}
-
-/**
- * Described in header.
- */
-med_db_config_t *med_db_config_create(database_t *db)
-{
-       private_med_db_config_t *this = malloc_thing(private_med_db_config_t);
-
-       this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
-       this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
-       this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
-       this->public.destroy = (void(*)(med_db_config_t*))destroy;
-       
-       this->db = db;
-       this->rekey = lib->settings->get_int(lib->settings,
-                                                                                "medmanager.rekey", 20) * 60;
-       this->dpd = lib->settings->get_int(lib->settings, "medmanager.dpd", 300);
-       this->ike = ike_cfg_create(FALSE, FALSE, host_create_any(AF_INET),
-                                                          host_create_any(AF_INET));
-       this->ike->add_proposal(this->ike, proposal_create_default(PROTO_IKE));
-       
-       return &this->public;
-}
-
diff --git a/src/charon/plugins/med_db/med_db_config.h b/src/charon/plugins/med_db/med_db_config.h
deleted file mode 100644 (file)
index aa9fd0b..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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$
- */
-
-/**
- * @defgroup med_db_config_i med_db_config
- * @{ @ingroup med_db
- */
-
-#ifndef MED_DB_CONFIG_H_
-#define MED_DB_CONFIG_H_
-
-#include <config/backend.h>
-#include <database/database.h>
-
-typedef struct med_db_config_t med_db_config_t;
-
-/**
- * Mediation server configuration backend.
- */
-struct med_db_config_t {
-
-       /**
-        * Implements backend_t interface
-        */
-       backend_t backend;
-       
-       /**
-        * Destroy the backend.
-        */
-       void (*destroy)(med_db_config_t *this); 
-};
-
-/**
- * Create a med_db_config backend instance.
- *
- * @param db           underlying database
- * @return                     backend instance
- */
-med_db_config_t *med_db_config_create(database_t *db);
-
-#endif /* MED_DB_CONFIG_H_ @}*/
diff --git a/src/charon/plugins/med_db/med_db_creds.c b/src/charon/plugins/med_db/med_db_creds.c
deleted file mode 100644 (file)
index 0f55ec1..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * 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 "med_db_creds.h"
-#include "med_db_pubkey.h"
-
-#include <daemon.h>
-#include <library.h>
-#include <utils/enumerator.h>
-
-typedef struct private_med_db_creds_t private_med_db_creds_t;
-
-/**
- * Private data of an med_db_creds_t object
- */
-struct private_med_db_creds_t {
-
-       /**
-        * Public part
-        */
-       med_db_creds_t public;
-       
-       /**
-        * underlying database handle
-        */
-       database_t *db;
-};
-
-/**
- * enumerator over certificates
- */
-typedef struct {
-       /** implements enumerator */
-       enumerator_t public;
-       /** inner SQL enumerator */
-       enumerator_t *inner;
-       /** currently enumerated cert */
-       certificate_t *current;
-       /** type of requested key */
-       key_type_t type;
-} cert_enumerator_t;
-
-/**
- * Implementation of cert_enumerator_t.public.enumerate
- */
-static bool cert_enumerator_enumerate(cert_enumerator_t *this,
-                                                                         certificate_t **cert)
-{
-       public_key_t *public;
-       chunk_t chunk;
-
-       DESTROY_IF(this->current);
-       while (this->inner->enumerate(this->inner, &chunk))
-       {
-               public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
-                                                                       BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
-                                                                       BUILD_END);
-               if (public)
-               {
-                       if (this->type == KEY_ANY || this->type == public->get_type(public))
-                       {
-                               *cert = this->current = (certificate_t*)med_db_pubkey_create(public);
-                               return TRUE;
-                       }
-                       public->destroy(public);
-               }
-       }
-       this->current = NULL;
-       return FALSE;
-}
-
-/**
- * Implementation of cert_enumerator_t.public.destroy
- */
-static void cert_enumerator_destroy(cert_enumerator_t *this)
-{
-       DESTROY_IF(this->current);
-       this->inner->destroy(this->inner);
-       free(this);
-}
-
-/**
- * Implementation of credential_set_t.create_cert_enumerator.
- */
-static enumerator_t* create_cert_enumerator(private_med_db_creds_t *this,
-                                                                               certificate_type_t cert, key_type_t key,
-                                                                               identification_t *id, bool trusted)
-{
-       cert_enumerator_t *e;
-       
-       if ((cert != CERT_TRUSTED_PUBKEY && cert != CERT_ANY) ||
-               id == NULL || id->get_type(id) != ID_KEY_ID)
-       {
-               return NULL;
-       }
-       
-       e = malloc_thing(cert_enumerator_t);
-       e->current = NULL;
-       e->type = key;
-       e->public.enumerate = (void*)cert_enumerator_enumerate;
-       e->public.destroy = (void*)cert_enumerator_destroy;
-       e->inner = this->db->query(this->db,
-                                                          "SELECT PublicKey FROM Peer WHERE KeyId = ?",
-                                                          DB_BLOB, id->get_encoding(id),
-                                                          DB_BLOB);
-       if (!e->inner)
-       {
-               free(e);
-               return NULL;
-       }
-       return &e->public;
-}
-
-/**
- * Implementation of backend_t.destroy.
- */
-static void destroy(private_med_db_creds_t *this)
-{
-    free(this);
-}
-
-/**
- * Described in header.
- */
-med_db_creds_t *med_db_creds_create(database_t *db)
-{
-       private_med_db_creds_t *this = malloc_thing(private_med_db_creds_t);
-
-       this->public.set.create_private_enumerator = (void*)return_null;
-       this->public.set.create_cert_enumerator = (void*)create_cert_enumerator;
-       this->public.set.create_shared_enumerator = (void*)return_null;
-       this->public.set.create_cdp_enumerator = (void*)return_null;
-       this->public.set.cache_cert = (void*)nop;
-
-       this->public.destroy = (void (*)(med_db_creds_t*))destroy;
-       
-       this->db = db;
-       
-       return &this->public;
-}
-
diff --git a/src/charon/plugins/med_db/med_db_creds.h b/src/charon/plugins/med_db/med_db_creds.h
deleted file mode 100644 (file)
index 69379ed..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2007-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$
- */
-
-/**
- * @defgroup med_db_creds_i med_db_creds
- * @{ @ingroup med_db
- */
-
-#ifndef MED_DB_CREDS_H_
-#define MED_DB_CREDS_H_
-
-#include <credentials/credential_set.h>
-#include <database/database.h>
-
-typedef struct med_db_creds_t med_db_creds_t;
-
-/**
- * Mediation credentials database.
- */
-struct med_db_creds_t {
-
-       /**
-        * Implements credential_set_t interface
-        */
-       credential_set_t set;
-       
-       /**
-        * Destroy the credentials databse.
-        */
-       void (*destroy)(med_db_creds_t *this);  
-};
-
-/**
- * Create the med_db credentials db.
- *
- * @param database             underlying database
- * @return                             credential set implementation on that database
- */
-med_db_creds_t *med_db_creds_create(database_t *database);
-
-#endif /* MED_DB_CREDS_H_ @}*/
diff --git a/src/charon/plugins/med_db/med_db_plugin.c b/src/charon/plugins/med_db/med_db_plugin.c
deleted file mode 100644 (file)
index 23da0eb..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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 "med_db_plugin.h"
-
-#include "med_db_creds.h"
-#include "med_db_config.h"
-
-#include <daemon.h>
-
-typedef struct private_med_db_plugin_t private_med_db_plugin_t;
-
-/**
- * private data of med_db plugin
- */
-struct private_med_db_plugin_t {
-
-       /**
-        * implements plugin interface
-        */
-       med_db_plugin_t public;
-       
-       /**
-        * database connection instance
-        */
-       database_t *db;
-       
-       /**
-        * med_db credential set instance
-        */
-       med_db_creds_t *creds;
-       
-       /**
-        * med_db config database
-        */
-       med_db_config_t *config;
-};
-
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_med_db_plugin_t *this)
-{
-       charon->backends->remove_backend(charon->backends, &this->config->backend);
-       charon->credentials->remove_set(charon->credentials, &this->creds->set);
-       this->config->destroy(this->config);
-       this->creds->destroy(this->creds);
-       this->db->destroy(this->db);
-       free(this);
-}
-
-/*
- * see header file
- */
-plugin_t *plugin_create()
-{
-       char *uri;
-       private_med_db_plugin_t *this = malloc_thing(private_med_db_plugin_t);
-       
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-       
-       uri = lib->settings->get_str(lib->settings,
-                                                                "medmanager.database", NULL);
-       if (!uri)
-       {
-               DBG1(DBG_CFG, "mediation database URI not defined, skipped");
-               free(this);
-               return NULL;
-       }
-       
-       this->db = lib->db->create(lib->db, uri);
-       if (this->db == NULL)
-       {
-               DBG1(DBG_CFG, "opening mediation server database failed");
-               free(this);
-               return NULL;
-       }
-       
-       this->creds = med_db_creds_create(this->db);
-       this->config = med_db_config_create(this->db);
-       
-       charon->credentials->add_set(charon->credentials, &this->creds->set);
-       charon->backends->add_backend(charon->backends, &this->config->backend);
-       
-       return &this->public.plugin;
-}
-
diff --git a/src/charon/plugins/med_db/med_db_plugin.h b/src/charon/plugins/med_db/med_db_plugin.h
deleted file mode 100644 (file)
index 42d55ad..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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$
- */
-
-/**
- * @defgroup med_db med_db
- * @ingroup cplugins
- *
- * @defgroup med_db_plugin med_db_plugin
- * @{ @ingroup med_db
- */
-
-#ifndef MED_DB_PLUGIN_H_
-#define MED_DB_PLUGIN_H_
-
-#include <plugins/plugin.h>
-
-typedef struct med_db_plugin_t med_db_plugin_t;
-
-/**
- * Mediation server database plugin.
- */
-struct med_db_plugin_t {
-
-       /**
-        * implements plugin interface
-        */
-       plugin_t plugin;
-};
-
-/**
- * Create a med_db_plugin instance.
- */
-plugin_t *plugin_create();
-
-#endif /* MED_DB_PLUGIN_H_ @}*/
diff --git a/src/charon/plugins/med_db/med_db_pubkey.c b/src/charon/plugins/med_db/med_db_pubkey.c
deleted file mode 100644 (file)
index d0dc41f..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * 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 "med_db_pubkey.h"
-
-typedef struct private_med_db_pubkey_t private_med_db_pubkey_t;
-
-/**
- * private data of med_db_pubkey
- */
-struct private_med_db_pubkey_t {
-
-       /**
-        * public functions
-        */
-       med_db_pubkey_t public;
-       
-       /**
-        * wrapped public key
-        */
-       public_key_t *key;
-       
-       /**
-        * dummy issuer id, ID_ANY
-        */
-       identification_t *issuer;
-       
-       /**
-        * reference count
-        */
-       refcount_t ref;
-};
-
-/**
- * Implementation of certificate_t.get_type
- */
-static certificate_type_t get_type(private_med_db_pubkey_t *this)
-{
-       return CERT_TRUSTED_PUBKEY;
-}
-
-/**
- * Implementation of certificate_t.get_subject
- */
-static identification_t* get_subject(private_med_db_pubkey_t *this)
-{
-       return this->key->get_id(this->key, ID_PUBKEY_SHA1);
-}
-
-/**
- * Implementation of certificate_t.get_issuer
- */
-static identification_t* get_issuer(private_med_db_pubkey_t *this)
-{
-       return this->issuer;
-}
-
-/**
- * Implementation of certificate_t.has_subject.
- */
-static id_match_t has_subject(private_med_db_pubkey_t *this,
-                                                         identification_t *subject)
-{
-       identification_t *id;
-       
-       id = this->key->get_id(this->key, subject->get_type(subject));
-       if (id)
-       {
-               return id->matches(id, subject);
-       }
-       return ID_MATCH_NONE;   
-}
-
-/**
- * Implementation of certificate_t.has_subject.
- */
-static id_match_t has_issuer(private_med_db_pubkey_t *this,
-                                                        identification_t *issuer)
-{
-       return ID_MATCH_NONE;
-}
-
-/**
- * Implementation of certificate_t.equals.
- */
-static bool equals(private_med_db_pubkey_t *this, certificate_t *other)
-{
-       if (this == (private_med_db_pubkey_t*)other)
-       {
-               return TRUE;
-       }
-       if (other->get_type(other) != CERT_TRUSTED_PUBKEY)
-       {
-               return FALSE;
-       }
-       return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_SHA1));
-}
-
-/**
- * Implementation of certificate_t.issued_by
- */
-static bool issued_by(private_med_db_pubkey_t *this, certificate_t *issuer)
-{
-       return equals(this, issuer);
-}
-
-/**
- * Implementation of certificate_t.get_public_key
- */
-static public_key_t* get_public_key(private_med_db_pubkey_t *this)
-{
-       this->key->get_ref(this->key);
-       return this->key;
-}
-/**
- * Implementation of certificate_t.get_validity.
- */
-static bool get_validity(private_med_db_pubkey_t *this, time_t *when,
-                                                time_t *not_before, time_t *not_after)
-{
-       if (not_before)
-       {
-               *not_before = 0;
-       }
-       if (not_after)
-       {
-               *not_after = ~0;
-       }
-       return TRUE;
-}
-
-/**
- * Implementation of certificate_t.is_newer.
- */
-static bool is_newer(certificate_t *this, certificate_t *that)
-{
-       return FALSE;
-}
-       
-/**
- * Implementation of certificate_t.get_encoding.
- */
-static chunk_t get_encoding(private_med_db_pubkey_t *this)
-{
-       return this->key->get_encoding(this->key);
-}
-
-/**
- * Implementation of certificate_t.get_ref
- */
-static private_med_db_pubkey_t* get_ref(private_med_db_pubkey_t *this)
-{
-       ref_get(&this->ref);
-       return this;
-}
-
-/**
- * Implementation of med_db_pubkey_t.destroy
- */
-static void destroy(private_med_db_pubkey_t *this)
-{
-       if (ref_put(&this->ref))
-       {
-               this->issuer->destroy(this->issuer);
-               this->key->destroy(this->key);
-               free(this);
-       }
-}
-
-/*
- * see header file
- */
-med_db_pubkey_t *med_db_pubkey_create(public_key_t *key)
-{
-       private_med_db_pubkey_t *this = malloc_thing(private_med_db_pubkey_t);
-       
-       this->public.interface.get_type = (certificate_type_t (*)(certificate_t *this))get_type;
-       this->public.interface.get_subject = (identification_t* (*)(certificate_t *this))get_subject;
-       this->public.interface.get_issuer = (identification_t* (*)(certificate_t *this))get_issuer;
-       this->public.interface.has_subject = (id_match_t (*)(certificate_t*, identification_t *subject))has_subject;
-       this->public.interface.has_issuer = (id_match_t (*)(certificate_t*, identification_t *issuer))has_issuer;
-       this->public.interface.issued_by = (bool (*)(certificate_t *this, certificate_t *issuer))issued_by;
-       this->public.interface.get_public_key = (public_key_t* (*)(certificate_t *this))get_public_key;
-       this->public.interface.get_validity = (bool (*)(certificate_t*, time_t *when, time_t *, time_t*))get_validity;
-       this->public.interface.is_newer = (bool (*)(certificate_t*,certificate_t*))is_newer;
-       this->public.interface.get_encoding = (chunk_t (*)(certificate_t*))get_encoding;
-       this->public.interface.equals = (bool (*)(certificate_t*, certificate_t *other))equals;
-       this->public.interface.get_ref = (certificate_t* (*)(certificate_t *this))get_ref;
-       this->public.interface.destroy = (void (*)(certificate_t *this))destroy;
-       
-       this->ref = 1;
-       this->key = key;
-       this->issuer = identification_create_from_encoding(ID_ANY, chunk_empty);
-       
-       return &this->public;
-}
-
diff --git a/src/charon/plugins/med_db/med_db_pubkey.h b/src/charon/plugins/med_db/med_db_pubkey.h
deleted file mode 100644 (file)
index f61f97b..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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$
- */
-
-/**
- * @defgroup med_db_pubkey med_db_pubkey
- * @{ @ingroup med_db
- */
-
-#ifndef MED_DB_PUBKEY_H_
-#define MED_DB_PUBKEY_H_
-
-#include <credentials/keys/public_key.h>
-#include <credentials/certificates/certificate.h>
-
-typedef struct med_db_pubkey_t med_db_pubkey_t;
-
-/**
- * A trusted public key wrapped into certificate of type CERT_TRUSTED_PUBKEY.
- */
-struct med_db_pubkey_t {
-
-       /**
-        * Implements certificate_t.
-        */
-       certificate_t interface;
-};
-
-/**
- * Create a wrapped public key instance using a public_key.
- *
- * The certifcate uses the public_key ID as subject.
- *
- * @param key          public key to wrap
- * @return                     public key implementing certificate interface
- */
-med_db_pubkey_t *med_db_pubkey_create(public_key_t *key);
-
-#endif /* MED_DB_PUBKEY_H_ @}*/
diff --git a/src/charon/plugins/med_db/mysql.sql b/src/charon/plugins/med_db/mysql.sql
deleted file mode 100644 (file)
index 0fb60db..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-CREATE TABLE IF NOT EXISTS `Peer` (
-  `IdPeer` int(10) unsigned NOT NULL auto_increment,
-  `IdUser` int(10) unsigned NOT NULL,
-  `Alias` varchar(30) collate utf8_unicode_ci NOT NULL,
-  `KeyId` varbinary(20) NOT NULL,
-  `PublicKey` blob NOT NULL,
-  PRIMARY KEY  (`IdPeer`),
-  KEY `KeyId` (`KeyId`),
-  KEY `IdUser` (`IdUser`)
-) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-
diff --git a/src/charon/plugins/med_db/test.sql b/src/charon/plugins/med_db/test.sql
deleted file mode 100644 (file)
index 8ba3364..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-
-INSERT INTO `Peer` (
-       `IdPeer`, `IdUser`, `Alias`, `KeyId`, `PublicKey`
-) VALUES (
-       1, 0, 'sidv150', 
-       X'ed90e64feca21f4b6897992422e0de21b9d62629',
-       X'30820122300d06092a864886f70d01010105000382010f003082010a0282010100cd946c229f7d52b21da1cb5384e7dcaf6529f760534a56355efd49e87a9c6f1ddd5ff303bd7eb49c23de03adc487456f41eb5f92947bdc8ff8dbe443f8d112e0da2c98145e7c4d1cd15cddd08577f4d4f3d0a2e1da3c08c94cd819758751931e7a9724cc43d73a11b8e176a268b4cdbbf3995cb09723abc9bfc477c25e714a4661a84c078be7404d8986be55f20437e3a6b278a3cc89aec085941f1a1aafaf4b22ae146fe4684d5567dc30658a32087d01b98515070cb1653311cb6102f82a83c638c2a79985dbb9600752e9cbc272014a5c547b4ab59130c3a948658bff794b6f202cf95939ffa73b10521f05c060cecb15f8597ed95d72b9e405ee31f1b5d90203010001'
-);
-
diff --git a/src/charon/plugins/medsrv/Makefile.am b/src/charon/plugins/medsrv/Makefile.am
new file mode 100644 (file)
index 0000000..afff076
--- /dev/null
@@ -0,0 +1,12 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/charon
+
+AM_CFLAGS = -rdynamic
+
+plugin_LTLIBRARIES = libcharon-medsrv.la
+libcharon_medsrv_la_SOURCES = medsrv_plugin.h medsrv_plugin.c \
+                             medsrv_creds.h medsrv_creds.c \
+                             medsrv_config.h medsrv_config.c \
+                             medsrv_pubkey.h medsrv_pubkey.c
+libcharon_medsrv_la_LDFLAGS = -module
+
diff --git a/src/charon/plugins/medsrv/medsrv_config.c b/src/charon/plugins/medsrv/medsrv_config.c
new file mode 100644 (file)
index 0000000..8439c20
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * 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 <string.h>
+
+#include "medsrv_config.h"
+
+#include <daemon.h>
+
+typedef struct private_medsrv_config_t private_medsrv_config_t;
+
+/**
+ * Private data of an medsrv_config_t object
+ */
+struct private_medsrv_config_t {
+
+       /**
+        * Public part
+        */
+       medsrv_config_t public;
+       
+       /**
+        * database connection
+        */
+       database_t *db;
+       
+       /**
+        * rekey time
+        */
+       int rekey;
+       
+       /**
+        * dpd delay
+        */
+       int dpd;
+       
+       /**
+        * default ike config
+        */
+       ike_cfg_t *ike;
+};
+
+/**
+ * implements backend_t.get_peer_cfg_by_name.
+ */
+static peer_cfg_t *get_peer_cfg_by_name(private_medsrv_config_t *this, char *name)
+{
+       return NULL;
+}
+
+/**
+ * Implementation of backend_t.create_ike_cfg_enumerator.
+ */
+static enumerator_t* create_ike_cfg_enumerator(private_medsrv_config_t *this,
+                                                                                          host_t *me, host_t *other)
+{
+       return enumerator_create_single(this->ike, NULL);
+}
+
+/**
+ * Implementation of backend_t.create_peer_cfg_enumerator.
+ */
+static enumerator_t* create_peer_cfg_enumerator(private_medsrv_config_t *this,
+                                                                                               identification_t *me,
+                                                                                               identification_t *other)
+{
+       enumerator_t *e;
+       
+       if (!me || !other || other->get_type(other) != ID_KEY_ID)
+       {
+               return NULL;
+       }
+       e = this->db->query(this->db,
+                       "SELECT CONCAT(Peer.Alias, CONCAT('@', User.Login)) FROM "
+                       "Peer JOIN User ON Peer.IdUser = User.IdUser "
+                       "WHERE Peer.KeyID = ?", DB_BLOB, other->get_encoding(other),
+                       DB_TEXT);
+       if (e)
+       {
+               peer_cfg_t *peer_cfg;
+               char *name;
+               
+               if (e->enumerate(e, &name))
+               {
+                       peer_cfg = peer_cfg_create(
+                               name, 2, this->ike->get_ref(this->ike),
+                               me->clone(me), other->clone(other),
+                               CERT_NEVER_SEND, UNIQUE_REPLACE, AUTH_RSA,
+                               0, 0,                                                   /* EAP method, vendor */
+                               1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
+                               this->rekey*5, this->rekey*3,   /* jitter, overtime */
+                               TRUE, this->dpd,                                /* mobike, dpddelay */
+                               NULL, NULL,                                     /* vip, pool */
+                               TRUE, NULL, NULL);                              /* mediation, med by, peer id */
+                       e->destroy(e);
+                       return enumerator_create_single(peer_cfg, (void*)peer_cfg->destroy);
+               }
+               e->destroy(e);
+       }
+       return NULL;
+}
+
+/**
+ * Implementation of medsrv_config_t.destroy.
+ */
+static void destroy(private_medsrv_config_t *this)
+{
+       this->ike->destroy(this->ike);
+       free(this);
+}
+
+/**
+ * Described in header.
+ */
+medsrv_config_t *medsrv_config_create(database_t *db)
+{
+       private_medsrv_config_t *this = malloc_thing(private_medsrv_config_t);
+
+       this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
+       this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
+       this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
+       this->public.destroy = (void(*)(medsrv_config_t*))destroy;
+       
+       this->db = db;
+       this->rekey = lib->settings->get_int(lib->settings,
+                                                                                "medmanager.rekey", 20) * 60;
+       this->dpd = lib->settings->get_int(lib->settings, "medmanager.dpd", 300);
+       this->ike = ike_cfg_create(FALSE, FALSE, host_create_any(AF_INET),
+                                                          host_create_any(AF_INET));
+       this->ike->add_proposal(this->ike, proposal_create_default(PROTO_IKE));
+       
+       return &this->public;
+}
+
diff --git a/src/charon/plugins/medsrv/medsrv_config.h b/src/charon/plugins/medsrv/medsrv_config.h
new file mode 100644 (file)
index 0000000..ebb6203
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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$
+ */
+
+/**
+ * @defgroup medsrv_config_i medsrv_config
+ * @{ @ingroup medsrv
+ */
+
+#ifndef MEDSRV_CONFIG_H_
+#define MEDSRV_CONFIG_H_
+
+#include <config/backend.h>
+#include <database/database.h>
+
+typedef struct medsrv_config_t medsrv_config_t;
+
+/**
+ * Mediation server configuration backend.
+ */
+struct medsrv_config_t {
+
+       /**
+        * Implements backend_t interface
+        */
+       backend_t backend;
+       
+       /**
+        * Destroy the backend.
+        */
+       void (*destroy)(medsrv_config_t *this); 
+};
+
+/**
+ * Create a medsrv_config backend instance.
+ *
+ * @param db           underlying database
+ * @return                     backend instance
+ */
+medsrv_config_t *medsrv_config_create(database_t *db);
+
+#endif /* MEDSRV_CONFIG_H_ @}*/
diff --git a/src/charon/plugins/medsrv/medsrv_creds.c b/src/charon/plugins/medsrv/medsrv_creds.c
new file mode 100644 (file)
index 0000000..b87ef06
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * 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 "medsrv_creds.h"
+#include "medsrv_pubkey.h"
+
+#include <daemon.h>
+#include <library.h>
+#include <utils/enumerator.h>
+
+typedef struct private_medsrv_creds_t private_medsrv_creds_t;
+
+/**
+ * Private data of an medsrv_creds_t object
+ */
+struct private_medsrv_creds_t {
+
+       /**
+        * Public part
+        */
+       medsrv_creds_t public;
+       
+       /**
+        * underlying database handle
+        */
+       database_t *db;
+};
+
+/**
+ * enumerator over certificates
+ */
+typedef struct {
+       /** implements enumerator */
+       enumerator_t public;
+       /** inner SQL enumerator */
+       enumerator_t *inner;
+       /** currently enumerated cert */
+       certificate_t *current;
+       /** type of requested key */
+       key_type_t type;
+} cert_enumerator_t;
+
+/**
+ * Implementation of cert_enumerator_t.public.enumerate
+ */
+static bool cert_enumerator_enumerate(cert_enumerator_t *this,
+                                                                         certificate_t **cert)
+{
+       public_key_t *public;
+       chunk_t chunk;
+
+       DESTROY_IF(this->current);
+       while (this->inner->enumerate(this->inner, &chunk))
+       {
+               public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
+                                                                       BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
+                                                                       BUILD_END);
+               if (public)
+               {
+                       if (this->type == KEY_ANY || this->type == public->get_type(public))
+                       {
+                               *cert = this->current = (certificate_t*)medsrv_pubkey_create(public);
+                               return TRUE;
+                       }
+                       public->destroy(public);
+               }
+       }
+       this->current = NULL;
+       return FALSE;
+}
+
+/**
+ * Implementation of cert_enumerator_t.public.destroy
+ */
+static void cert_enumerator_destroy(cert_enumerator_t *this)
+{
+       DESTROY_IF(this->current);
+       this->inner->destroy(this->inner);
+       free(this);
+}
+
+/**
+ * Implementation of credential_set_t.create_cert_enumerator.
+ */
+static enumerator_t* create_cert_enumerator(private_medsrv_creds_t *this,
+                                                                               certificate_type_t cert, key_type_t key,
+                                                                               identification_t *id, bool trusted)
+{
+       cert_enumerator_t *e;
+       
+       if ((cert != CERT_TRUSTED_PUBKEY && cert != CERT_ANY) ||
+               id == NULL || id->get_type(id) != ID_KEY_ID)
+       {
+               return NULL;
+       }
+       
+       e = malloc_thing(cert_enumerator_t);
+       e->current = NULL;
+       e->type = key;
+       e->public.enumerate = (void*)cert_enumerator_enumerate;
+       e->public.destroy = (void*)cert_enumerator_destroy;
+       e->inner = this->db->query(this->db,
+                                                          "SELECT PublicKey FROM Peer WHERE KeyId = ?",
+                                                          DB_BLOB, id->get_encoding(id),
+                                                          DB_BLOB);
+       if (!e->inner)
+       {
+               free(e);
+               return NULL;
+       }
+       return &e->public;
+}
+
+/**
+ * Implementation of backend_t.destroy.
+ */
+static void destroy(private_medsrv_creds_t *this)
+{
+    free(this);
+}
+
+/**
+ * Described in header.
+ */
+medsrv_creds_t *medsrv_creds_create(database_t *db)
+{
+       private_medsrv_creds_t *this = malloc_thing(private_medsrv_creds_t);
+
+       this->public.set.create_private_enumerator = (void*)return_null;
+       this->public.set.create_cert_enumerator = (void*)create_cert_enumerator;
+       this->public.set.create_shared_enumerator = (void*)return_null;
+       this->public.set.create_cdp_enumerator = (void*)return_null;
+       this->public.set.cache_cert = (void*)nop;
+
+       this->public.destroy = (void (*)(medsrv_creds_t*))destroy;
+       
+       this->db = db;
+       
+       return &this->public;
+}
+
diff --git a/src/charon/plugins/medsrv/medsrv_creds.h b/src/charon/plugins/medsrv/medsrv_creds.h
new file mode 100644 (file)
index 0000000..5884006
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2007-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$
+ */
+
+/**
+ * @defgroup medsrv_creds_i medsrv_creds
+ * @{ @ingroup medsrv
+ */
+
+#ifndef MEDSRV_CREDS_H_
+#define MEDSRV_CREDS_H_
+
+#include <credentials/credential_set.h>
+#include <database/database.h>
+
+typedef struct medsrv_creds_t medsrv_creds_t;
+
+/**
+ * Mediation credentials database.
+ */
+struct medsrv_creds_t {
+
+       /**
+        * Implements credential_set_t interface
+        */
+       credential_set_t set;
+       
+       /**
+        * Destroy the credentials databse.
+        */
+       void (*destroy)(medsrv_creds_t *this);  
+};
+
+/**
+ * Create the medsrv credentials db.
+ *
+ * @param database             underlying database
+ * @return                             credential set implementation on that database
+ */
+medsrv_creds_t *medsrv_creds_create(database_t *database);
+
+#endif /* MEDSRV_CREDS_H_ @}*/
diff --git a/src/charon/plugins/medsrv/medsrv_plugin.c b/src/charon/plugins/medsrv/medsrv_plugin.c
new file mode 100644 (file)
index 0000000..23b36a5
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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 "medsrv_plugin.h"
+
+#include "medsrv_creds.h"
+#include "medsrv_config.h"
+
+#include <daemon.h>
+
+typedef struct private_medsrv_plugin_t private_medsrv_plugin_t;
+
+/**
+ * private data of medsrv plugin
+ */
+struct private_medsrv_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       medsrv_plugin_t public;
+       
+       /**
+        * database connection instance
+        */
+       database_t *db;
+       
+       /**
+        * medsrv credential set instance
+        */
+       medsrv_creds_t *creds;
+       
+       /**
+        * medsrv config database
+        */
+       medsrv_config_t *config;
+};
+
+/**
+ * Implementation of plugin_t.destroy
+ */
+static void destroy(private_medsrv_plugin_t *this)
+{
+       charon->backends->remove_backend(charon->backends, &this->config->backend);
+       charon->credentials->remove_set(charon->credentials, &this->creds->set);
+       this->config->destroy(this->config);
+       this->creds->destroy(this->creds);
+       this->db->destroy(this->db);
+       free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *plugin_create()
+{
+       char *uri;
+       private_medsrv_plugin_t *this = malloc_thing(private_medsrv_plugin_t);
+       
+       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       
+       uri = lib->settings->get_str(lib->settings,
+                                                                "medmanager.database", NULL);
+       if (!uri)
+       {
+               DBG1(DBG_CFG, "mediation database URI not defined, skipped");
+               free(this);
+               return NULL;
+       }
+       
+       this->db = lib->db->create(lib->db, uri);
+       if (this->db == NULL)
+       {
+               DBG1(DBG_CFG, "opening mediation server database failed");
+               free(this);
+               return NULL;
+       }
+       
+       this->creds = medsrv_creds_create(this->db);
+       this->config = medsrv_config_create(this->db);
+       
+       charon->credentials->add_set(charon->credentials, &this->creds->set);
+       charon->backends->add_backend(charon->backends, &this->config->backend);
+       
+       return &this->public.plugin;
+}
+
diff --git a/src/charon/plugins/medsrv/medsrv_plugin.h b/src/charon/plugins/medsrv/medsrv_plugin.h
new file mode 100644 (file)
index 0000000..cb7d205
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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$
+ */
+
+/**
+ * @defgroup medsrv medsrv
+ * @ingroup cplugins
+ *
+ * @defgroup medsrv_plugin medsrv_plugin
+ * @{ @ingroup medsrv
+ */
+
+#ifndef MEDSRV_PLUGIN_H_
+#define MEDSRV_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct medsrv_plugin_t medsrv_plugin_t;
+
+/**
+ * Mediation server database plugin.
+ */
+struct medsrv_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       plugin_t plugin;
+};
+
+/**
+ * Create a medsrv_plugin instance.
+ */
+plugin_t *plugin_create();
+
+#endif /* MEDSRV_PLUGIN_H_ @}*/
diff --git a/src/charon/plugins/medsrv/medsrv_pubkey.c b/src/charon/plugins/medsrv/medsrv_pubkey.c
new file mode 100644 (file)
index 0000000..26a9647
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * 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 "medsrv_pubkey.h"
+
+typedef struct private_medsrv_pubkey_t private_medsrv_pubkey_t;
+
+/**
+ * private data of medsrv_pubkey
+ */
+struct private_medsrv_pubkey_t {
+
+       /**
+        * public functions
+        */
+       medsrv_pubkey_t public;
+       
+       /**
+        * wrapped public key
+        */
+       public_key_t *key;
+       
+       /**
+        * dummy issuer id, ID_ANY
+        */
+       identification_t *issuer;
+       
+       /**
+        * reference count
+        */
+       refcount_t ref;
+};
+
+/**
+ * Implementation of certificate_t.get_type
+ */
+static certificate_type_t get_type(private_medsrv_pubkey_t *this)
+{
+       return CERT_TRUSTED_PUBKEY;
+}
+
+/**
+ * Implementation of certificate_t.get_subject
+ */
+static identification_t* get_subject(private_medsrv_pubkey_t *this)
+{
+       return this->key->get_id(this->key, ID_PUBKEY_SHA1);
+}
+
+/**
+ * Implementation of certificate_t.get_issuer
+ */
+static identification_t* get_issuer(private_medsrv_pubkey_t *this)
+{
+       return this->issuer;
+}
+
+/**
+ * Implementation of certificate_t.has_subject.
+ */
+static id_match_t has_subject(private_medsrv_pubkey_t *this,
+                                                         identification_t *subject)
+{
+       identification_t *id;
+       
+       id = this->key->get_id(this->key, subject->get_type(subject));
+       if (id)
+       {
+               return id->matches(id, subject);
+       }
+       return ID_MATCH_NONE;   
+}
+
+/**
+ * Implementation of certificate_t.has_subject.
+ */
+static id_match_t has_issuer(private_medsrv_pubkey_t *this,
+                                                        identification_t *issuer)
+{
+       return ID_MATCH_NONE;
+}
+
+/**
+ * Implementation of certificate_t.equals.
+ */
+static bool equals(private_medsrv_pubkey_t *this, certificate_t *other)
+{
+       if (this == (private_medsrv_pubkey_t*)other)
+       {
+               return TRUE;
+       }
+       if (other->get_type(other) != CERT_TRUSTED_PUBKEY)
+       {
+               return FALSE;
+       }
+       return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_SHA1));
+}
+
+/**
+ * Implementation of certificate_t.issued_by
+ */
+static bool issued_by(private_medsrv_pubkey_t *this, certificate_t *issuer)
+{
+       return equals(this, issuer);
+}
+
+/**
+ * Implementation of certificate_t.get_public_key
+ */
+static public_key_t* get_public_key(private_medsrv_pubkey_t *this)
+{
+       this->key->get_ref(this->key);
+       return this->key;
+}
+/**
+ * Implementation of certificate_t.get_validity.
+ */
+static bool get_validity(private_medsrv_pubkey_t *this, time_t *when,
+                                                time_t *not_before, time_t *not_after)
+{
+       if (not_before)
+       {
+               *not_before = 0;
+       }
+       if (not_after)
+       {
+               *not_after = ~0;
+       }
+       return TRUE;
+}
+
+/**
+ * Implementation of certificate_t.is_newer.
+ */
+static bool is_newer(certificate_t *this, certificate_t *that)
+{
+       return FALSE;
+}
+       
+/**
+ * Implementation of certificate_t.get_encoding.
+ */
+static chunk_t get_encoding(private_medsrv_pubkey_t *this)
+{
+       return this->key->get_encoding(this->key);
+}
+
+/**
+ * Implementation of certificate_t.get_ref
+ */
+static private_medsrv_pubkey_t* get_ref(private_medsrv_pubkey_t *this)
+{
+       ref_get(&this->ref);
+       return this;
+}
+
+/**
+ * Implementation of medsrv_pubkey_t.destroy
+ */
+static void destroy(private_medsrv_pubkey_t *this)
+{
+       if (ref_put(&this->ref))
+       {
+               this->issuer->destroy(this->issuer);
+               this->key->destroy(this->key);
+               free(this);
+       }
+}
+
+/*
+ * see header file
+ */
+medsrv_pubkey_t *medsrv_pubkey_create(public_key_t *key)
+{
+       private_medsrv_pubkey_t *this = malloc_thing(private_medsrv_pubkey_t);
+       
+       this->public.interface.get_type = (certificate_type_t (*)(certificate_t *this))get_type;
+       this->public.interface.get_subject = (identification_t* (*)(certificate_t *this))get_subject;
+       this->public.interface.get_issuer = (identification_t* (*)(certificate_t *this))get_issuer;
+       this->public.interface.has_subject = (id_match_t (*)(certificate_t*, identification_t *subject))has_subject;
+       this->public.interface.has_issuer = (id_match_t (*)(certificate_t*, identification_t *issuer))has_issuer;
+       this->public.interface.issued_by = (bool (*)(certificate_t *this, certificate_t *issuer))issued_by;
+       this->public.interface.get_public_key = (public_key_t* (*)(certificate_t *this))get_public_key;
+       this->public.interface.get_validity = (bool (*)(certificate_t*, time_t *when, time_t *, time_t*))get_validity;
+       this->public.interface.is_newer = (bool (*)(certificate_t*,certificate_t*))is_newer;
+       this->public.interface.get_encoding = (chunk_t (*)(certificate_t*))get_encoding;
+       this->public.interface.equals = (bool (*)(certificate_t*, certificate_t *other))equals;
+       this->public.interface.get_ref = (certificate_t* (*)(certificate_t *this))get_ref;
+       this->public.interface.destroy = (void (*)(certificate_t *this))destroy;
+       
+       this->ref = 1;
+       this->key = key;
+       this->issuer = identification_create_from_encoding(ID_ANY, chunk_empty);
+       
+       return &this->public;
+}
+
diff --git a/src/charon/plugins/medsrv/medsrv_pubkey.h b/src/charon/plugins/medsrv/medsrv_pubkey.h
new file mode 100644 (file)
index 0000000..fb831f3
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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$
+ */
+
+/**
+ * @defgroup medsrv_pubkey medsrv_pubkey
+ * @{ @ingroup medsrv
+ */
+
+#ifndef MEDSRV_PUBKEY_H_
+#define MEDSRV_PUBKEY_H_
+
+#include <credentials/keys/public_key.h>
+#include <credentials/certificates/certificate.h>
+
+typedef struct medsrv_pubkey_t medsrv_pubkey_t;
+
+/**
+ * A trusted public key wrapped into certificate of type CERT_TRUSTED_PUBKEY.
+ */
+struct medsrv_pubkey_t {
+
+       /**
+        * Implements certificate_t.
+        */
+       certificate_t interface;
+};
+
+/**
+ * Create a wrapped public key instance using a public_key.
+ *
+ * The certifcate uses the public_key ID as subject.
+ *
+ * @param key          public key to wrap
+ * @return                     public key implementing certificate interface
+ */
+medsrv_pubkey_t *medsrv_pubkey_create(public_key_t *key);
+
+#endif /* MEDSRV_PUBKEY_H_ @}*/
diff --git a/src/charon/plugins/medsrv/mysql.sql b/src/charon/plugins/medsrv/mysql.sql
new file mode 100644 (file)
index 0000000..0fb60db
--- /dev/null
@@ -0,0 +1,12 @@
+
+CREATE TABLE IF NOT EXISTS `Peer` (
+  `IdPeer` int(10) unsigned NOT NULL auto_increment,
+  `IdUser` int(10) unsigned NOT NULL,
+  `Alias` varchar(30) collate utf8_unicode_ci NOT NULL,
+  `KeyId` varbinary(20) NOT NULL,
+  `PublicKey` blob NOT NULL,
+  PRIMARY KEY  (`IdPeer`),
+  KEY `KeyId` (`KeyId`),
+  KEY `IdUser` (`IdUser`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
diff --git a/src/charon/plugins/medsrv/test.sql b/src/charon/plugins/medsrv/test.sql
new file mode 100644 (file)
index 0000000..8ba3364
--- /dev/null
@@ -0,0 +1,9 @@
+
+INSERT INTO `Peer` (
+       `IdPeer`, `IdUser`, `Alias`, `KeyId`, `PublicKey`
+) VALUES (
+       1, 0, 'sidv150', 
+       X'ed90e64feca21f4b6897992422e0de21b9d62629',
+       X'30820122300d06092a864886f70d01010105000382010f003082010a0282010100cd946c229f7d52b21da1cb5384e7dcaf6529f760534a56355efd49e87a9c6f1ddd5ff303bd7eb49c23de03adc487456f41eb5f92947bdc8ff8dbe443f8d112e0da2c98145e7c4d1cd15cddd08577f4d4f3d0a2e1da3c08c94cd819758751931e7a9724cc43d73a11b8e176a268b4cdbbf3995cb09723abc9bfc477c25e714a4661a84c078be7404d8986be55f20437e3a6b278a3cc89aec085941f1a1aafaf4b22ae146fe4684d5567dc30658a32087d01b98515070cb1653311cb6102f82a83c638c2a79985dbb9600752e9cbc272014a5c547b4ab59130c3a948658bff794b6f202cf95939ffa73b10521f05c060cecb15f8597ed95d72b9e405ee31f1b5d90203010001'
+);
+