gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: add files


From: gnunet
Subject: [taler-anastasis] branch master updated: add files
Date: Thu, 10 Sep 2020 11:08:44 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 3aaa133  add files
3aaa133 is described below

commit 3aaa133280f282a3f3f1095b4234317189610fd9
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Sep 10 11:08:36 2020 +0200

    add files
---
 src/include/anastasis_authorization_plugin.h | 142 +++++++++++++++++++++++++++
 src/include/anastasis_redux.h                | 106 ++++++++++++++++++++
 src/lib/redux.c                              | 116 ++++++++++++++++++++++
 3 files changed, 364 insertions(+)

diff --git a/src/include/anastasis_authorization_plugin.h 
b/src/include/anastasis_authorization_plugin.h
new file mode 100644
index 0000000..b9d3732
--- /dev/null
+++ b/src/include/anastasis_authorization_plugin.h
@@ -0,0 +1,142 @@
+/*
+  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_plugin.h
+ * @brief authorization access for Anastasis
+ * @author Christian Grothoff
+ */
+#ifndef ANASTASIS_AUTHORIZATION_PLUGIN_H
+#define ANASTASIS_AUTHORIZATION_PLUGIN_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <anastasis_error_codes.h>
+#include "anastasis_service.h"
+#include <jansson.h>
+#include <taler/taler_util.h>
+
+
+/**
+ * Plugin-specific state for an authorization operation.
+ */
+struct ANASTASIS_AUTHORIZATION_State;
+
+
+enum ANASTASIS_AUTHORIZATION_Result
+{
+  ANASTASIS_AUTHORIZATION_RES_SUCCESS,
+  ANASTASIS_AUTHORIZATION_RES_FAILED,
+  ANASTASIS_AUTHORIZATION_RES_SUSPENDED,
+  ANASTASIS_AUTHORIZATION_RES_REPLY_FAILED
+};
+
+
+/**
+ * Handle to interact with a authorization backend.
+ */
+struct ANASTASIS_AuthorizationPlugin
+{
+
+  /**
+   * Closure for all callbacks.
+   */
+  void *cls;
+
+  /**
+   * Name of the library which generated this plugin.  Set by the
+   * plugin loader.
+   */
+  char *library_name;
+
+  /**
+   * How long should a generated challenge be valid for this type of method.
+   */
+  struct GNUNET_TIME_Relative code_validity_period;
+
+  /**
+   * How long before we should rotate a challenge for this type of method.
+   */
+  struct GNUNET_TIME_Relative code_rotation_period;
+
+  /**
+   * How long before we should retransmit a code.
+   */
+  struct GNUNET_TIME_Relative code_retransmission_frequency;
+
+  /**
+   * Validate @a data is a well-formed input into the challenge method,
+   * i.e. @a data is a well-formed phone number for sending an SMS, or
+   * a well-formed e-mail address for sending an e-mail. Not expected to
+   * check that the phone number or e-mail account actually exists.
+   *
+   * To be possibly used before issuing a 402 payment required to the client.
+   *
+   * @param cls closure
+   * @param connection HTTP client request (for queuing response)
+   * @param data input to validate (i.e. is it a valid phone number, etc.)
+   * @param data_length number of bytes in @a data
+   * @return #GNUNET_OK if @a data is valid,
+   *         #GNUNET_NO if @a data is invalid and a reply was successfully 
queued on @a connection
+   *         #GNUNET_SYSERR if @a data invalid but we failed to queue a reply 
on @a connection
+   */
+  enum GNUNET_GenericReturnValue
+  (*validate)(void *cls,
+              struct MHD_Connection *connection,
+              const char *data,
+              size_t data_length);
+
+  /**
+   * Begin issuing authentication challenge to user based on @a data.
+   * I.e. start to send SMS or e-mail or launch video identification.
+   *
+   * @param cls closure
+   * @param truth_public_key Identifier of the challenge, to be (if possible) 
included in the
+   *             interaction with the user
+   * @param code secret code that the user has to provide back to satisfy the 
challenge in
+   *             the main anastasis protocol
+   * @param data input to validate (i.e. is it a valid phone number, etc.)
+   * @param data_length number of bytes in @a data
+   * @return state to track progress on the authorization operation, NULL on 
failure
+   */
+  struct ANASTASIS_AUTHORIZATION_State *
+  (*start)(void *cls,
+           const struct ANASTASIS_CRYPTO_TruthPublicKeyP *truth_public_key,
+           uint64_t code,
+           const void *data,
+           size_t data_length);
+
+  /**
+   * Begin issuing authentication challenge to user based on @a data.
+   * I.e. start to send SMS or e-mail or launch video identification.
+   *
+   * @param as authorization state
+   * @param connection HTTP client request (for queuing response, such as 
redirection to video portal)
+   * @return state of the request
+   */
+  enum ANASTASIS_AUTHORIZATION_Result
+  (*process)(struct ANASTASIS_AUTHORIZATION_State *as,
+             struct MHD_Connection *connection);
+
+
+  /**
+   * Free internal state associated with @a as.
+   *
+   * @param as state to clean up
+   */
+  void
+  (*cleanup)(struct ANASTASIS_AUTHORIZATION_State *as);
+
+};
+#endif
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
new file mode 100644
index 0000000..7d978a9
--- /dev/null
+++ b/src/include/anastasis_redux.h
@@ -0,0 +1,106 @@
+/*
+  This file is part of Anastasis
+  Copyright (C) 2020 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 lib/anastasis_redux.h
+ * @brief anastasis reducer api
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ */
+#ifndef ANASTASIS_REDUX_H
+#define ANASTASIS_REDUX_H
+
+#include <jansson.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis_error_codes.h"
+
+
+/**
+ * Returns an initial ANASTASIS backup state.
+ *
+ * @return NULL on failure
+ */
+json_t *
+ANASTASIS_backup_start (void);
+
+
+/**
+ * Returns an initial ANASTASIS recovery state.
+ *
+ * @return NULL on failure
+ */
+json_t *
+ANASTASIS_recovery_start (void);
+
+
+/**
+ * Signature of the callback passed to #ANASTASIS_backup_action and
+ * #ANASTASIS_recover_action.
+ *
+ * @param cls closure
+ * @param error error code, #TALER_EC_NONE if @a new_bs is the new successful 
state
+ * @param new_state the new state of the operation (client should 
json_incref() to keep an alias)
+ * @param error error code
+ */
+typedef void
+(*ANASTASIS_ActionCallback)(
+  void *cls,
+  enum ANASTASIS_ErrorCode error,
+  json_t *new_state);
+
+
+/**
+ * Operates on a backup state depending on given #ANASTASIS_BackupState
+ * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned
+ * by a callback function.
+ * This function can do network access to talk to anastasis service providers.
+ *
+ * @param state input state
+ * @param action what action to perform
+ * @param arguments data for the @a action
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return failure state or new state
+ */
+void
+ANASTASIS_backup_action (const json_t *state,
+                         const char *action,
+                         const json_t *arguments,
+                         ANASTASIS_ActionCallback cb,
+                         void *cb_cls);
+
+
+/**
+ * Operates on a backup state depending on given #ANASTASIS_BackupState
+ * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned
+ * by a callback function.
+ * This function can do network access to talk to anastasis service providers.
+ *
+ * @param state input state
+ * @param action what action to perform
+ * @param arguments data for the @a action
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ */
+void
+ANASTASIS_recovery_action (const json_t *state,
+                           const char *action,
+                           const json_t *arguments,
+                           ANASTASIS_ActionCallback cb,
+                           void *cb_cls);
+
+
+#endif  /* _ANASTASIS_JSON_H */
diff --git a/src/lib/redux.c b/src/lib/redux.c
new file mode 100644
index 0000000..f8db250
--- /dev/null
+++ b/src/lib/redux.c
@@ -0,0 +1,116 @@
+typedef void
+(*DispatchHandler)(const json_t *state,
+                   const jons_t *arguments,
+                   ANASTASIS_ActionCallback cb,
+                   void *cb_cls);
+
+/**
+ * Returns an initial ANASTASIS backup state.
+ *
+ * @return NULL on failure
+ */
+json_t *
+ANASTASIS_backup_start (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  json_t *initial_state;
+
+
+  initial_state = json_object_pack ("{s:s, s:o}",
+                                    "backup-state", "ReduxInitialBackupState",
+                                    "continents", FIXME);
+  return initial_state;
+}
+
+
+static void
+select_continent (const json_t *state,
+                  const json_t *arguments,
+                  ANASTASIS_ActionCallback cb,
+                  void *cb_cls)
+{
+  json_t *new_state;
+  const char *continent = json_string_value (json_object_get (arguments,
+                                                              "continent"));
+  if (NULL == s)
+  {
+    GNUNET_break (0);
+    cb (cb_cls,
+        error);
+  }
+  if (continent - not - in - array)
+  {
+    GNUNET_break (0);
+    cb (cb_cls,
+        error);
+  }
+  new_state = json_deep_copy (state);
+  // FIXME: get list of countries for 'continent'
+  json_object_set_new (new_state,
+                       "countries",
+                       countries);
+  // optional:
+  json_object_set_new (new_state,
+                       "continent",
+                       json_string (continent));
+  cb (cb_cls,
+      TALER_EC_NONE,
+      new_state);
+  json_decref (new_state);
+}
+
+
+/**
+ * Operates on a backup state depending on given #ANASTASIS_BackupState
+ * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned
+ * by a callback function.
+ * This function can do network access to talk to anastasis service providers.
+ *
+ * @param state input state
+ * @param action what action to perform
+ * @param arguments data for the @a action
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return failure state or new state
+ */
+void
+ANASTASIS_backup_action (const json_t *state,
+                         const char *action,
+                         const json_t *arguments,
+                         ANASTASIS_ActionCallback cb,
+                         void *cb_cls)
+{
+  struct Dispatcher
+  {
+    const char *backup_state;
+    const char *backup_action;
+    DispatchHandler fun;
+  } dispatchers[] = {
+    {
+      "ReduxInitialBackupState",
+      "selection_continent",
+      &select_continent
+    },
+    { NULL, NULL, NULL }
+  };
+  const char *s = json_string_value (json_object_get (state,
+                                                      "backup-state"));
+  if (NULL == s)
+  {
+    GNUNET_break (0);
+    cb (cb_cls,
+        error);
+  }
+  for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
+  {
+    if ( (0 == strcmp (s, dispatchers[i].backup_state)) &&
+         (0 == strcmp (action, dispatchers[i].backup_action)) )
+    {
+      dispatchers[i].fun (state, arguments, cb, cb_cls);
+      return;
+    }
+  }
+  GNUNET_break (0);
+  cb (cb_cls,
+      error);
+
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]