gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (c5945b0 -> 8805d19)


From: gnunet
Subject: [taler-anastasis] branch master updated (c5945b0 -> 8805d19)
Date: Tue, 24 Nov 2020 11:18:59 +0100

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

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from c5945b0  fix truths initialization
     new 4b38cd2  worked on truth upload
     new 56af39d  worked on truth upload
     new 8805d19  fix cleanup

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/cli/Makefile.am                            |   3 +-
 src/cli/test_anastasis_reducer_enter_secret.sh | 121 ++++++++++++
 src/include/anastasis_redux.h                  |   4 +-
 src/lib/Makefile.am                            |   4 +-
 src/lib/anastasis_api_backup_redux.c           | 261 ++++++++++++++++++-------
 5 files changed, 316 insertions(+), 77 deletions(-)
 create mode 100755 src/cli/test_anastasis_reducer_enter_secret.sh

diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index fa3f1e2..f9525e2 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -16,7 +16,8 @@ check_SCRIPTS = \
   test_anastasis_reducer_enter_user_attributes.sh \
   test_anastasis_reducer_add_authentication.sh \
   test_anastasis_reducer_done_authentication.sh \
-  test_anastasis_reducer_done_policy_review.sh
+  test_anastasis_reducer_done_policy_review.sh \
+  test_anastasis_reducer_enter_secret.sh
 
 
 AM_TESTS_ENVIRONMENT=export 
ANASTASIS_PREFIX=$${ANASTASIS_PREFIX:-@libdir@};export 
PATH=$${ANASTASIS_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset 
XDG_CONFIG_HOME;
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
new file mode 100755
index 0000000..63f9c6b
--- /dev/null
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+set -eu
+
+# Exit, with status code "skip" (no 'real' failure)
+function exit_skip() {
+    echo $1
+    exit 77
+}
+
+# Exit, with error message (hard failure)
+function exit_fail() {
+    echo $1
+    exit 1
+}
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+    for n in `jobs -p`
+    do
+        kill $n 2> /dev/null || true
+    done
+    rm -f $SFILE $TFILE $CONF_1 $CONF_2 $CONF_3 $CONF_4 
+    wait
+}
+
+# Install cleanup handler (except for kill -9)
+CONF_1=`mktemp test_reducerXXXXXX_1.conf`
+CONF_2=`mktemp test_reducerXXXXXX_2.conf`
+CONF_3=`mktemp test_reducerXXXXXX_3.conf`
+CONF_4=`mktemp test_reducerXXXXXX_4.conf`
+SFILE=test_reducer_stateSESTATE
+TFILE=`mktemp test_reducer_stateXXXXXX`
+
+trap cleanup EXIT
+
+# Check we can actually run
+echo -n "Testing for jq"
+jq -h > /dev/null || exit_skip "jq required"
+echo " FOUND"
+
+echo -n "Testing for anastasis-httpd"
+anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
+echo " FOUND"
+
+# Name of the Postgres database we will use for the script.
+# Will be dropped, do NOT use anything that might be used
+# elsewhere
+TARGET_DB=anastasischeck
+
+# Configuration file will be edited, so we create one
+# from the template.
+cp test_anastasis_reducer.conf $CONF_1
+cp test_anastasis_reducer_1.conf $CONF_2
+cp test_anastasis_reducer_2.conf $CONF_3
+cp test_anastasis_reducer_3.conf $CONF_4
+
+# reset database
+dropdb $TARGET_DB >/dev/null 2>/dev/null || true
+createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB"
+
+# Launch services
+echo "Launching anastasis service"
+anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log &
+anastasis-httpd -c $CONF_2 2> anastasis-httpd_2.log &
+anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log &
+anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log &
+
+# Wait for anastasis service to be available
+for n in `seq 1 50`
+do
+    echo -n "."
+    sleep 0.1
+    OK=0
+    # anastasis_01
+    wget http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    # anastasis_02
+    wget http://localhost:8087/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    # anastasis_03
+    wget http://localhost:8088/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    # anastasis_04
+    wget http://localhost:8089/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    OK=1
+    break
+done
+
+if [ 1 != $OK ]
+then
+    exit_skip "Failed to launch anastasis services"
+fi
+
+echo " ANASTASIS SETUP DONE"
+echo " "
+echo " "
+echo " "
+echo "Beginning with actual reducer test"
+
+# Test enter secret in a backup state
+echo " "
+echo "Test enter secret in a backup state"
+./anastasis-reducer -a \
+  '{"secret": "veryhardtoguesssecret",
+    "type": "password"}' \
+  enter_secret $SFILE $TFILE
+
+wait
+
+STATE=`jq -r -e .backup_state < $TFILE`
+if test "$STATE" != "BACKUP_FINISHED"
+then
+    exit_fail "Expected new state to be BACKUP_FINISHED, got $STATE"
+fi
+
+ARRAY_LENGTH=`jq -r -e '.truth_uploads | length' < $TFILE`
+if test $ARRAY_LENGTH -lt 3
+then
+    exit_fail "Expected truth_uploads array length to be >= 3, got 
$ARRAY_LENGTH"
+fi
+
+exit 0
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 143c967..c7129b8 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -52,7 +52,7 @@ enum ANASTASIS_GenericState
   REDUX_STATE (POLICIES_REVIEWING)   \
   REDUX_STATE (SECRET_EDITING) \
   REDUX_STATE (POLICIES_PAYING) \
-  REDUX_STATE (FINISHED)
+  REDUX_STATE (BACKUP_FINISHED)
 
 #define GENERATE_BACKUP_ENUM(ENUM) ANASTASIS_BACKUP_STATE_ ## ENUM,
 
@@ -68,7 +68,7 @@ enum ANASTASIS_BackupState
   REDUX_STATE (CHALLENGE_SELECTING)  \
   REDUX_STATE (CHALLENGE_PAYING)   \
   REDUX_STATE (CHALLENGE_SOLVING)  \
-  REDUX_STATE (FINISHED)
+  REDUX_STATE (RECOVERY_FINISHED)
 
 #define GENERATE_RECOVERY_ENUM(ENUM) ANASTASIS_RECOVERY_STATE_ ## ENUM,
 
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 0756609..15f448e 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -108,13 +108,15 @@ libanastasisredux_la_SOURCES = \
   anastasis_api_recovery_redux.c \
   anastasis_api_backup_redux.c
 libanastasisredux_la_LIBADD = \
+  $(top_builddir)/src/lib/libanastasisrest.la \
+  $(top_builddir)/src/lib/libanastasis.la \
+  $(top_builddir)/src/util/libanastasisutil.la \
   -lgnunetjson \
   -lgnunetcurl \
   -lgnunetutil \
   -ltalermhd \
   -ltalerutil \
   -ltalerjson \
-  -lanastasisrest \
   -ljansson \
   $(XLIB)
 
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index ad9022c..e08736e 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -115,17 +115,43 @@ struct TruthUploadState
   struct ANASTASIS_TruthUpload *tuo;
 
   /**
-   * closure for the payment callback
+   * Action callback.
    */
-  void *tpc_cls;
+  ANASTASIS_ActionCallback cb;
 
   /**
-   * Truth object
+   * Closure for action callback.
+   */
+  void *cb_cls;
+
+  /**
+   * Truth object.
    */
   struct ANASTASIS_Truth *truth;
+
+  /**
+   * Truth index.
+   */
+  unsigned int index;
+
+  /**
+   * Redux json state.
+   */
+  json_t *state;
 };
 
 
+/**
+ * Array of truth upload states.
+ */
+static struct TruthUploadState *tus_arr;
+
+/**
+ * The length of the #tus_arr array.
+ */
+static unsigned int tus_arr_length;
+
+
 /**
  * Callback function FIXME: Description.
  *
@@ -1024,6 +1050,34 @@ done_policy_review (json_t *state,
 }
 
 
+/**
+ * Check if all uploads passed (status code 204).
+ *
+ * @param uploads json array representing uploads (truth, recovery document)
+ * @return true if all uploads passed, else false
+ */
+static bool
+check_uploads (json_t *uploads)
+{
+  GNUNET_assert (json_is_array (uploads));
+  size_t index;
+  json_t *upload;
+  bool pass = true;
+
+  json_array_foreach (uploads, index, upload)
+  {
+    int status = json_integer_value (json_object_get (upload,
+                                                      "status"));
+    if (status != 204)
+    {
+      pass = false;
+      break;
+    }
+  }
+  return pass;
+}
+
+
 /**
 * Upload information
 * caller MUST free 't' using ANASTASIS_truth_free()
@@ -1040,10 +1094,34 @@ truth_upload_cb (void *cls,
 
   if (NULL == t)
   {
-    GNUNET_break (0);
+    ANASTASIS_redux_fail (tus->cb,
+                          tus->cb_cls,
+                          TALER_EC_ANASTASIS_REDUCER_ACTION_INVALID, // FIXME: 
Error Code
+                          "enter_secret or pay");
     return;
   }
+  json_t *uploads = json_object_get (tus->state,
+                                     "truth_uploads");
+  json_t *truth_upload = json_array_get (uploads,
+                                         tus->index);
+  GNUNET_assert (NULL != truth_upload);
+  GNUNET_assert (0 ==
+                 json_object_set (truth_upload,
+                                  "status",
+                                  json_integer ((json_int_t) 204)));
   tus->truth = t;
+
+
+  if (check_uploads (uploads))
+  {
+    set_state (tus->state,
+               ANASTASIS_backup_state_to_string (
+                 ANASTASIS_BACKUP_STATE_BACKUP_FINISHED));
+  }
+
+  tus->cb (tus->cb_cls,
+           ANASTASIS_EC_NONE,
+           tus->state);
 }
 
 
@@ -1061,8 +1139,35 @@ truth_payment_cb (void *cls,
 {
   struct TruthUploadState *tus = cls;
   tus->tuo = NULL;
+
+  if (! ec)
+  {
+    json_t *truth_upload = json_array_get (
+      json_object_get (tus->state,
+                       "truth_uploads"),
+      tus->index);
+    GNUNET_assert (NULL != truth_upload);
+    GNUNET_assert (0 ==
+                   json_object_set (truth_upload,
+                                    "status",
+                                    json_integer ((json_int_t) 402)));
+    GNUNET_assert (0 ==
+                   json_object_set (truth_upload,
+                                    "pay_url",
+                                    json_string (taler_pay_url)));
+    set_state (tus->state,
+               ANASTASIS_backup_state_to_string (
+                 ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
+    tus->cb (tus->cb_cls,
+             ANASTASIS_EC_NONE,
+             tus->state);
+    return;
+  }
+  ANASTASIS_redux_fail (tus->cb,
+                        tus->cb_cls,
+                        ec,
+                        "enter_secret or pay");
   // FIXME: Payment handling
-  return;
 }
 
 
@@ -1116,75 +1221,85 @@ enter_secret (json_t *state,
   GNUNET_assert (0 ==
                  json_object_set (state,
                                   "core_secret",
-                                  arguments));
-  // {
-  //   // upload truths
-  //   size_t truth_index;
-  //   json_t *truth;
-  //   json_t *truths = initialize_truths (state);
-
-  //   GNUNET_assert (json_is_array (truths));
-  //   json_array_foreach (truths, truth_index, truth)
-  //   {
-  //     struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
-  //     struct ANASTASIS_CRYPTO_PowSalt backend_salt;
-  //     struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
-  //     const char *backend_url = json_string_value (json_object_get (truth,
-  //                                                                   
"backend_url"));
-
-  //     tus->method = json_string_value (json_object_get (truth,
-  //                                                       "method"));
-  //     tus->instructions = json_string_value (json_object_get (truth,
-  //                                                             
"instructions"));
-  //     tus->mime_type = json_string_value (json_object_get (truth,
-  //                                                          "mime_type"));
-  //     const char *salt_str = json_string_value (json_object_get (truth,
-  //                                                                
"backen_salt"));
-  //     GNUNET_STRINGS_string_to_data (salt_str,
-  //                                    strlen (salt_str),
-  //                                    &backend_salt,
-  //                                    sizeof (struct 
ANASTASIS_CRYPTO_PowSalt));
-
-  //     tus->id_data = json_object_get (state,
-  //                                     "identity_attributes");
-
-  //     if (0 == strcmp ("question", tus->method))
-  //     {
-  //       json_t *truth_data = json_object_get (truth,
-  //                                             "truth_data");
-  //       // FIXME: hash secure question or salt into truth_data?
-  //       tus->truth_data = json_string_value (json_object_get (truth_data,
-  //                                                             "answer"));
-  //       tus->truth_data_size = strlen (tus->truth_data);
-  //     }
-  //     // FIXME: other method types
-
-  //     ANASTASIS_CRYPTO_user_identifier_derive (tus->id_data,
-  //                                              &backend_salt,
-  //                                              &user_id);
-  //     tus->tuo = ANASTASIS_truth_upload (ctx,
-  //                                        &user_id,
-  //                                        backend_url,
-  //                                        tus->method,
-  //                                        tus->mime_type,
-  //                                        &backend_salt,
-  //                                        tus->truth_data,
-  //                                        tus->truth_data_size,
-  //                                        &truth_payment_cb,
-  //                                        tus->tpc_cls,
-  //                                        &truth_upload_cb,
-  //                                        tus);
-  //   }
-  // }
+                                  json_deep_copy (arguments)));
+  {
+    // upload truths
+    size_t truth_index;
+    json_t *truth;
+    json_t *truths = json_object_get (state,
+                                      "truths");
+
+    GNUNET_assert (json_is_array (truths));
+    GNUNET_assert (0 ==
+                   json_object_set_new (state,
+                                        "truth_uploads",
+                                        json_array ()));
+    json_array_foreach (truths, truth_index, truth)
+    {
+      struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
+      struct ANASTASIS_CRYPTO_PowSalt backend_salt;
+      struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
+      const char *backend_url = json_string_value (json_object_get (truth,
+                                                                    
"backend_url"));
+      tus->state = json_incref (state);
+      tus->method = json_string_value (json_object_get (truth,
+                                                        "method"));
+      tus->instructions = json_string_value (json_object_get (truth,
+                                                              "instructions"));
+      tus->mime_type = json_string_value (json_object_get (truth,
+                                                           "mime_type"));
+      const char *salt_str = json_string_value (json_object_get (truth,
+                                                                 
"backend_salt"));
+      GNUNET_STRINGS_string_to_data (salt_str,
+                                     strlen (salt_str),
+                                     &backend_salt,
+                                     sizeof (struct ANASTASIS_CRYPTO_PowSalt));
+      tus->id_data = json_object_get (state,
+                                      "identity_attributes");
+      tus->index = truth_index;
+      tus->cb = cb;
+      tus->cb_cls = cb_cls;
+
+      if (0 == strcmp ("question", tus->method))
+      {
+        json_t *truth_data = json_object_get (truth,
+                                              "truth_data");
+        // FIXME: hash secure question or salt into truth_data?
+        tus->truth_data = json_string_value (json_object_get (truth_data,
+                                                              "answer"));
+        tus->truth_data_size = strlen (tus->truth_data);
+      }
+      // FIXME: other method types
+
+      json_t *truth_upload = json_pack ("{s:I}",
+                                        "status", 0);
+      GNUNET_assert (0 ==
+                     json_array_append_new (json_object_get (state,
+                                                             "truth_uploads"),
+                                            truth_upload));
+      ANASTASIS_CRYPTO_user_identifier_derive (tus->id_data,
+                                               &backend_salt,
+                                               &user_id);
+      GNUNET_array_append (tus_arr,
+                           tus_arr_length,
+                           *tus);
+      tus->tuo = ANASTASIS_truth_upload (ctx,
+                                         &user_id,
+                                         backend_url,
+                                         tus->method,
+                                         tus->instructions,
+                                         tus->mime_type,
+                                         &backend_salt,
+                                         tus->truth_data,
+                                         tus->truth_data_size,
+                                         &truth_payment_cb,
+                                         tus,
+                                         &truth_upload_cb,
+                                         tus);
+    }
+  }
 
   // try uploading recovery document
-  set_state (state,
-             ANASTASIS_backup_state_to_string (
-               ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
-
-  cb (cb_cls,
-      ANASTASIS_EC_NONE,
-      state);
   return NULL;
 }
 
@@ -1343,7 +1458,7 @@ ANASTASIS_backup_action_ (struct GNUNET_CURL_Context *ctx,
       &pay_policy
     },
     {
-      ANASTASIS_BACKUP_STATE_FINISHED,
+      ANASTASIS_BACKUP_STATE_BACKUP_FINISHED,
       "back",
       &back_finished
     },

-- 
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]