[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: plugin backend
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: plugin backend |
Date: |
Fri, 23 Oct 2020 17:32:06 +0200 |
This is an automated email from the git hooks/post-receive script.
ds-meister pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 9cb20b6 plugin backend
new 6b44740 merge
9cb20b6 is described below
commit 9cb20b6ef01931861d0c14840538a8b0511dc773
Author: Dominik Meister <dominik.meister@hotmail.ch>
AuthorDate: Fri Oct 23 17:28:54 2020 +0200
plugin backend
---
src/backend/Makefile.am | 12 ++
src/backend/anastasis-httpd_truth.c | 104 ++----------
src/backend/anastasis_authorization_plugin.c | 196 ++++++++++++++++++++++
src/backend/anastasis_authorization_plugin_file.c | 50 +++++-
src/include/Makefile.am | 1 +
src/include/anastasis_authorization_lib.h | 56 +++++++
src/stasis/plugin_anastasis_postgres.c | 6 +-
7 files changed, 329 insertions(+), 96 deletions(-)
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 18a94a2..b56aa13 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -9,6 +9,17 @@ if USE_COVERAGE
XLIB = -lgcov
endif
+lib_LTLIBRARIES = \
+ libanastasisauthorization.la
+
+libanastasisauthorization_la_SOURCES = \
+ anastasis_authorization_plugin.c
+libanastasisauthorization_la_LIBADD = \
+ $(LTLIBINTL)
+libanastasisauthorization_la_LDFLAGS = \
+ -talerutil \
+ -lgnunetutil
+
plugin_LTLIBRARIES = \
libanastasis_plugin_authorization_file.la
libanastasis_plugin_authorization_file_la_SOURCES = \
@@ -42,6 +53,7 @@ anastasis_httpd_SOURCES = \
anastasis_httpd_LDADD = \
$(top_builddir)/src/util/libanastasisutil.la \
$(top_builddir)/src/stasis/libanastasisdb.la \
+ libanastasisauthorization.la \
-lmicrohttpd \
-ljansson \
-ltalermerchant \
diff --git a/src/backend/anastasis-httpd_truth.c
b/src/backend/anastasis-httpd_truth.c
index 689306f..3e93c87 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -27,29 +27,10 @@
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_rest_lib.h>
#include "anastasis_authorization_plugin.h"
+#include "anastasis_authorization_lib.h"
#include <taler/taler_merchant_service.h>
#include <taler/taler_json_lib.h>
-/**
- * Authentication plugin which is used to verify code based authentication
- * like SMS, E-Mail.
- */
-struct AuthPlugin
-{
- struct AuthPlugin *next;
- struct AuthPlugin *prev;
-
- struct ANASTASIS_AuthorizationPlugin *authorization;
-
- /**
- * I.e. "sms", "phone".
- */
- char *name;
-
- char *lib_name;
-};
-
-
struct GetContext
{
/**
@@ -124,18 +105,16 @@ struct GetContext
};
+/**
+ * Linked list over all authorization processes
+ */
static struct GetContext *gc_head;
static struct GetContext *gc_tail;
-static struct AuthPlugin *ap_head;
-static struct AuthPlugin *ap_tail;
-
-
void
AH_truth_shutdown (void)
{
- struct AuthPlugin *ap;
struct GetContext *gc;
while (NULL != (gc = gc_head))
@@ -148,60 +127,7 @@ AH_truth_shutdown (void)
gc->as = NULL;
MHD_resume_connection (gc->connection);
}
- while (NULL != (ap = ap_head))
- {
- GNUNET_CONTAINER_DLL_remove (ap_head,
- ap_tail,
- ap);
- GNUNET_PLUGIN_unload (ap->lib_name,
- ap);
- GNUNET_free (ap->lib_name);
- GNUNET_free (ap->name);
- GNUNET_free (ap);
- }
-}
-
-
-/**
- * Load authorization plugin.
- * TODO: likely make these plugin-specific functions into
anastasis-http_plugin.h
- * to be used elsewhere!
- *
- * @param method name of the method to load
- * @return #GNUNET_OK on success
- */
-static struct ANASTASIS_AuthorizationPlugin *
-auth_plugin_load (const char *method)
-{
- struct ANASTASIS_AuthorizationPlugin *authorization;
- char *lib_name;
- struct AuthPlugin *ap;
-
- for (ap = ap_head; NULL != ap; ap = ap->next)
- if (0 == strcmp (method,
- ap->name))
- return ap->authorization;
- (void) GNUNET_asprintf (&lib_name,
- "libanastasis_plugin_authorization_%s",
- method);
- authorization = GNUNET_PLUGIN_load (lib_name,
- (void *) AH_cfg);
- if (NULL == authorization)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Authentication method `%s' not supported\n",
- method);
- GNUNET_free (lib_name);
- return NULL;
- }
- ap = GNUNET_new (struct AuthPlugin);
- ap->name = GNUNET_strdup (method);
- ap->lib_name = lib_name;
- ap->authorization = authorization;
- GNUNET_CONTAINER_DLL_insert (ap_head,
- ap_tail,
- ap);
- return authorization;
+ ANASTASIS_authorization_plugin_shutdown ();
}
@@ -827,20 +753,26 @@ AH_handler_truth_get (struct MHD_Connection *connection,
struct ANASTASIS_AuthorizationPlugin *authorization;
enum GNUNET_GenericReturnValue ret;
struct ANASTASIS_AUTHORIZATION_State *as;
- uint64_t code;
+ uint64_t code = 42;
enum ANASTASIS_AUTHORIZATION_Result aret;
enum ANASTASIS_DB_QueryStatus qs;
- authorization = auth_plugin_load (method);
+ struct GNUNET_TIME_Relative challenge_expiration;
+ challenge_expiration = GNUNET_TIME_UNIT_HOURS;
+
+ authorization = ANASTASIS_authorization_plugin_load (method);
if (NULL == authorization)
{
- // FIXME: queue PROPER reply...
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Plugin not found: %s",method);
GNUNET_free (decrypted_truth);
return MHD_NO;
}
+
ret = authorization->validate (authorization->cls,
connection,
decrypted_truth,
decrypted_truth_size);
+
switch (ret)
{
case GNUNET_OK:
@@ -856,16 +788,14 @@ AH_handler_truth_get (struct MHD_Connection *connection,
return MHD_NO;
}
// FIXME:
- code = 42; // RANDOM! -- or from DB if recent one in DB!
+ // RANDOM! -- or from DB if recent one in DB!
// FIXME TIME where to put this?
// FIXME retry counter where to put it?
-
qs = db->store_challenge_code (authorization->cls,
&truth_public_key,
code,
- GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_HOURS, 2),
+ challenge_expiration,
3);
switch (qs)
{
@@ -896,6 +826,8 @@ AH_handler_truth_get (struct MHD_Connection *connection,
GNUNET_free (decrypted_truth);
if (NULL == as)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ ("AUTHORIZATION START FAILED"));
// FIXME: queue PROPER reply...
return MHD_NO;
}
diff --git a/src/backend/anastasis_authorization_plugin.c
b/src/backend/anastasis_authorization_plugin.c
new file mode 100644
index 0000000..35f768d
--- /dev/null
+++ b/src/backend/anastasis_authorization_plugin.c
@@ -0,0 +1,196 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2015, 2016 GNUnet e.V. and INRIA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Lesser General Public License as published by the Free
Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER 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.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file anastasis_authorization_plugin.c
+ * @brief Logic to load database plugin
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ */
+#include "platform.h"
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis_authorization_plugin.h"
+#include <ltdl.h>
+
+
+/**
+ *Linked list for all loaded plugins
+ */
+static struct AuthPlugin *ap_head;
+static struct AuthPlugin *ap_tail;
+
+/**
+ * Authentication plugin which is used to verify code based authentication
+ * like SMS, E-Mail.
+ */
+struct AuthPlugin
+{
+ struct AuthPlugin *next;
+ struct AuthPlugin *prev;
+
+ struct ANASTASIS_AuthorizationPlugin *authorization;
+
+ /**
+ * I.e. "sms", "phone".
+ */
+ char *name;
+
+ char *lib_name;
+};
+
+/**
+ * Load authorization plugin.
+ *
+ * @param method name of the method to load
+ * @return #GNUNET_OK on success
+ */
+struct ANASTASIS_AuthorizationPlugin *
+ANASTASIS_authorization_plugin_load (
+ const char *method,
+ const struct GNUNET_CONFIGURATION_Handle *AH_cfg)
+{
+ struct ANASTASIS_AuthorizationPlugin *authorization;
+ char *lib_name;
+ struct AuthPlugin *ap;
+
+ for (ap = ap_head; NULL != ap; ap = ap->next)
+ if (0 == strcmp (method,
+ ap->name))
+ return ap->authorization;
+ (void) GNUNET_asprintf (&lib_name,
+ "libanastasis_plugin_authorization_%s",
+ method);
+ authorization = GNUNET_PLUGIN_load (lib_name,
+ (void *) AH_cfg);
+ if (NULL == authorization)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Authentication method `%s' not supported\n",
+ method);
+ GNUNET_free (lib_name);
+ return NULL;
+ }
+ ap = GNUNET_new (struct AuthPlugin);
+ ap->name = GNUNET_strdup (method);
+ ap->lib_name = lib_name;
+ ap->authorization = authorization;
+ GNUNET_CONTAINER_DLL_insert (ap_head,
+ ap_tail,
+ ap);
+ return authorization;
+}
+
+/**
+ * Shutdown the plugin.
+ *
+ * @param plugin the plugin to unload
+ */
+void
+ANASTASIS_authorization_plugin_unload
+ (struct ANASTASIS_AuthorizationPlugin *plugin)
+{
+ char *lib_name;
+
+ if (NULL == plugin)
+ return;
+ lib_name = plugin->library_name;
+ GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
+ plugin));
+ GNUNET_free (lib_name);
+ lib_name = NULL;
+}
+
+
+void
+ANASTASIS_authorization_plugin_shutdown (void)
+{
+ struct AuthPlugin *ap;
+ while (NULL != (ap = ap_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (ap_head,
+ ap_tail,
+ ap);
+ GNUNET_PLUGIN_unload (ap->lib_name,
+ ap);
+ GNUNET_free (ap->lib_name);
+ GNUNET_free (ap->name);
+ GNUNET_free (ap);
+ }
+}
+
+/**
+ * Libtool search path before we started.
+ */
+static char *old_dlsearchpath;
+
+
+/**
+ * Setup libtool paths.
+ */
+void __attribute__ ((constructor))
+plugin_init ()
+{
+ int err;
+ const char *opath;
+ char *path;
+ char *cpath;
+
+ err = lt_dlinit ();
+ if (err > 0)
+ {
+ fprintf (stderr,
+ _ ("Initialization of plugin mechanism failed: %s!\n"),
+ lt_dlerror ());
+ return;
+ }
+ opath = lt_dlgetsearchpath ();
+ if (NULL != opath)
+ old_dlsearchpath = GNUNET_strdup (opath);
+ path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
+ if (NULL != path)
+ {
+ if (NULL != opath)
+ {
+ GNUNET_asprintf (&cpath, "%s:%s", opath, path);
+ lt_dlsetsearchpath (cpath);
+ GNUNET_free (path);
+ GNUNET_free (cpath);
+ }
+ else
+ {
+ lt_dlsetsearchpath (path);
+ GNUNET_free (path);
+ }
+ }
+}
+
+
+/**
+ * Shutdown libtool.
+ */
+void __attribute__ ((destructor))
+plugin_fini ()
+{
+ lt_dlsetsearchpath (old_dlsearchpath);
+ if (NULL != old_dlsearchpath)
+ {
+ GNUNET_free (old_dlsearchpath);
+ old_dlsearchpath = NULL;
+ }
+ lt_dlexit ();
+}
+
+/* end of anastasis_authorization_plugin.c */
diff --git a/src/backend/anastasis_authorization_plugin_file.c
b/src/backend/anastasis_authorization_plugin_file.c
index 127fc10..b5583c6 100644
--- a/src/backend/anastasis_authorization_plugin_file.c
+++ b/src/backend/anastasis_authorization_plugin_file.c
@@ -21,6 +21,7 @@
#include "platform.h"
#include "anastasis_authorization_plugin.h"
+
/**
* Saves the State of a authorization process
*/
@@ -68,11 +69,31 @@ file_validate (void *cls,
const char *data,
size_t data_length)
{
- if (data != NULL)
+ char *data_string;
+
+ if (data == NULL)
+ {
+ return GNUNET_NO;
+ }
+
+ data_string = GNUNET_STRINGS_data_to_string_alloc (data,
+ data_length);
+ int i = 0;
+ int flag = 0;
+ for (i = 0; i<strlen (data_string); i++)
{
- return GNUNET_OK;
+ if ((data_string[i] == ' ')|| (data_string[i] == '/'))
+ {
+ flag = 1;
+ break;
+ }
}
- return GNUNET_NO;
+ if (flag == 1)
+ {
+ return GNUNET_NO;
+ }
+ GNUNET_free (data_string);
+ return GNUNET_OK;
}
@@ -119,7 +140,7 @@ static enum ANASTASIS_AUTHORIZATION_Result
file_process (struct ANASTASIS_AUTHORIZATION_State *as,
struct MHD_Connection *connection)
{
- FILE *f = fopen ("challenge.txt", "w");
+ FILE *f = fopen (as->data, "w");
if (f == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -128,7 +149,11 @@ file_process (struct ANASTASIS_AUTHORIZATION_State *as,
}
/* print challenge code to file */
- fprintf (f, "%lu", as->code);
+ if (0 >= fprintf (f, "%lu", as->code))
+ {
+ fclose (f);
+ return ANASTASIS_AUTHORIZATION_RES_FAILED;
+ }
fclose (f);
return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
@@ -142,6 +167,7 @@ file_process (struct ANASTASIS_AUTHORIZATION_State *as,
static void
file_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
{
+ GNUNET_free (as->data);
GNUNET_free (as);
}
@@ -165,3 +191,17 @@ libanastasis_plugin_authorization_file_init (void *cls)
plugin->cleanup = &file_cleanup;
return plugin;
}
+
+/**
+ * Unload authorization plugin
+ *
+ * @param cls a `struct ANASTASIS_AuthorizationPlugin`
+ * @return NULL (always)
+ */
+void *
+libanastasis_plugin_authorization_file_done (void *cls)
+{
+ struct ANASTASIS_AuthorizationPlugin *plugin = cls;
+ GNUNET_free (plugin);
+ return NULL;
+}
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index c9dfab0..d48c611 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -13,4 +13,5 @@ anastasisinclude_HEADERS = \
anastasis_crypto_lib.h \
anastasis_redux.h \
anastasis_authorization_plugin.h \
+ anastasis_authorization_lib.h \
anastasis.h
diff --git a/src/include/anastasis_authorization_lib.h
b/src/include/anastasis_authorization_lib.h
new file mode 100644
index 0000000..6314fa9
--- /dev/null
+++ b/src/include/anastasis_authorization_lib.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of Anastasis
+ Copyright (C) 2019 Taler Systems SA
+
+ Anastasis is free software; you can redistribute it and/or modify it under
the
+ terms of the GNU Lesser General Public License as published by the Free
Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Anastasis 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.
+
+ You should have received a copy of the GNU General Public License along with
+ Anastasis; see the file COPYING.GPL. If not, see
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file include/anastasis_authorization_lib.h
+ * @brief database plugin loader
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ * @author Christian Grothoff
+ */
+#ifndef ANASTASIS_AUTHORIZATION_LIB_H
+#define ANASTASIS_AUTHORIZATION_LIB_H
+
+#include <taler/taler_util.h>
+#include "anastasis_authorization_plugin.h"
+
+/**
+ * Initialize the plugin.
+ *
+ * @param cfg configuration to use
+ * @return NULL on failure
+ */
+struct ANASTASIS_AuthorizationPlugin *
+ANASTASIS_authorization_plugin_load (const char *method);
+
+
+/**
+ * unload a plugin.
+ *
+ * @param plugin plugin to unload
+ */
+void
+ANASTASIS_authorization_plugin_unload (struct ANASTASIS_DatabasePlugin
*plugin);
+
+/**
+ * shutdown all loaded plugins.
+ *
+ * @param void
+ */
+void
+ANASTASIS_authorization_plugin_shutdown (void);
+
+#endif
+/* end of anastasis_authorization_lib.h */
diff --git a/src/stasis/plugin_anastasis_postgres.c
b/src/stasis/plugin_anastasis_postgres.c
index 8a68c96..1f21dfe 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -1825,7 +1825,7 @@ postgres_store_challenge_code (void *cls,
GNUNET_TIME_round_abs (&creation_date);
expiration_date = GNUNET_TIME_absolute_add (creation_date,
expiration_time);
-
+ GNUNET_TIME_round_abs (&expiration_date);
/*Check if there is already a valid code */
/*FIXME maybe put this in a function code reusage*/
uint64_t server_code;
@@ -1841,7 +1841,6 @@ postgres_store_challenge_code (void *cls,
GNUNET_PQ_result_spec_end
};
- check_connection (pg);
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"challengecode_select",
params,
@@ -1862,7 +1861,6 @@ postgres_store_challenge_code (void *cls,
return ANASTASIS_DB_STATUS_HARD_ERROR;
}
}
-
check_connection (pg);
if (GNUNET_OK != begin_transaction (pg,
"store_challenge_code"))
@@ -1880,7 +1878,6 @@ postgres_store_challenge_code (void *cls,
GNUNET_PQ_query_param_uint32 (&retry_counter),
GNUNET_PQ_query_param_end
};
-
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
"challengecode_insert",
params);
@@ -1894,7 +1891,6 @@ postgres_store_challenge_code (void *cls,
rollback (pg);
return ANASTASIS_DB_STATUS_SOFT_ERROR;
case ANASTASIS_DB_STATUS_NO_RESULTS:
- GNUNET_break (0);
rollback (pg);
return ANASTASIS_DB_STATUS_SOFT_ERROR;
case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: plugin backend,
gnunet <=