gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 04/15: worked on reducer


From: gnunet
Subject: [taler-anastasis] 04/15: worked on reducer
Date: Sun, 31 Jan 2021 17:06:10 +0100

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

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

commit 40e79dcf80167737738ab19bcac612ed2e82a914
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Sun Jan 17 15:47:14 2021 +0100

    worked on reducer
---
 contrib/Makefile.am                                |   3 +-
 contrib/test_resources/test_reducer_stateUACSTATE  | 116 -----------
 src/cli/Makefile.am                                |   5 +-
 ...stasis_reducer_backup_enter_user_attributes.sh} |   2 +-
 ...tasis_reducer_recovery_enter_user_attributes.sh | 141 +++++++++++++
 src/include/anastasis.h                            |  11 +-
 src/lib/anastasis.c                                | 221 +++++++++++----------
 src/lib/anastasis_api_redux.c                      | 139 ++++++-------
 8 files changed, 340 insertions(+), 298 deletions(-)

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 1736a77..cf4e7de 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -17,7 +17,8 @@ pkgdata_DATA = \
   provider-list.json \
   test_resources/test_reducer_stateBFSTATE \
   test_resources/test_reducer_statePPSTATE \
-  test_resources/test_reducer_stateUACSTATE \
+  test_resources/test_reducer_backup_stateUACSTATE \
+  test_resources/test_reducer_recovery_stateUACSTATE \
   test_resources/test_reducer_stateSESTATE \
   test_resources/test_reducer_statePRSTATE \
   test_resources/test_reducer_stateAESTATE \
diff --git a/contrib/test_resources/test_reducer_stateUACSTATE 
b/contrib/test_resources/test_reducer_stateUACSTATE
deleted file mode 100644
index f4a43a7..0000000
--- a/contrib/test_resources/test_reducer_stateUACSTATE
+++ /dev/null
@@ -1,116 +0,0 @@
-{
-  "backup_state": "USER_ATTRIBUTES_COLLECTING",
-  "continents": [
-    "Europe",
-    "North_America"
-  ],
-  "selected_continent": "Europe",
-  "countries": [
-    {
-      "code": "ch",
-      "name": "Switzerland",
-      "continent": "Europe",
-      "name_i18n": {
-        "de_DE": "Schweiz",
-        "de_CH": "Schwiiz",
-        "fr": "Suisse",
-        "en": "Swiss"
-      },
-      "currency": "TESTKUDOS"
-    },
-    {
-      "code": "de",
-      "name": "Germany",
-      "continent": "Europe",
-      "continent_i18n": {
-        "de": "Europa"
-      },
-      "name_i18n": {
-        "de_DE": "Deutschland",
-        "de_CH": "Deutschland",
-        "fr": "Allemagne",
-        "en": "Germany"
-      },
-      "currency": "TESTKUDOS"
-    }
-  ],
-  "selected_country": "ch",
-  "currency": "TESTKUDOS",
-  "required_attributes": [
-    {
-      "type": "string",
-      "name": "full_name",
-      "label": "Full name",
-      "label_i18n": {
-        "de_DE": "Vollstaendiger Name",
-        "de_CH": "Vollstaendiger Name"
-      },
-      "widget": "anastasis_gtk_ia_full_name"
-    },
-    {
-      "type": "date",
-      "name": "birthdate",
-      "label": "Birthdate",
-      "label_i18n": {
-        "de_CH": "Geburtsdatum"
-      },
-      "widget": "anastasis_gtk_ia_birthdate"
-    },
-    {
-      "type": "string",
-      "name": "ahv_number",
-      "label": "AHV number",
-      "label_i18n": {
-        "de_DE": "AHV-Nummer",
-        "de_CH": "AHV-Nummer"
-      },
-      "widget": "anastasis_gtk_ia_ahv",
-      "validation-regex": "^(756).[0-9]{4}.[0-9]{4}.[0-9]{2}|(756)[0-9]{10}$",
-      "validation-logic": "CH_AVH_check"
-    }
-  ],
-  "authentication_providers": {
-    "question": [
-      {
-        "anastasis_04": {
-          "method_cost": "TESTKUDOS:0",
-          "annual_cost": "TESTKUDOS:0",
-          "insurance": "TESTKUDOS:1",
-          "provider_url": "localhost:8089/",
-          "provider_name": "Anastasis 4",
-          "provider_salt": "8HAPCKSH9D3MYJTS9536RHJHCW"
-        }
-      },
-      {
-        "anastasis_03": {
-          "method_cost": "TESTKUDOS:0",
-          "annual_cost": "TESTKUDOS:4.99",
-          "insurance": "TESTKUDOS:1",
-          "provider_url": "localhost:8088/",
-          "provider_name": "Anastasis 3",
-          "provider_salt": "8DAPCKSH9D3MYJTS9536RHJHCW"
-        }
-      },
-      {
-        "anastasis_02": {
-          "method_cost": "TESTKUDOS:0",
-          "annual_cost": "TESTKUDOS:1.99",
-          "insurance": "TESTKUDOS:1",
-          "provider_url": "localhost:8087/",
-          "provider_name": "Anastasis 2",
-          "provider_salt": "89APCKSH9D3MYJTS9536RHJHCW"
-        }
-      },
-      {
-        "anastasis_01": {
-          "method_cost": "TESTKUDOS:0",
-          "annual_cost": "TESTKUDOS:4.99",
-          "insurance": "TESTKUDOS:1",
-          "provider_url": "localhost:8086/",
-          "provider_name": "Anastasis 1",
-          "provider_salt": "85APCKSH9D3MYJTS9536RHJHCW"
-        }
-      }
-    ]
-  }
-}
\ No newline at end of file
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 5973356..b8efb10 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -13,11 +13,12 @@ check_SCRIPTS = \
   test_anastasis_reducer_initialize_state.sh \
   test_anastasis_reducer_select_continent.sh \
   test_anastasis_reducer_select_country.sh \
-  test_anastasis_reducer_enter_user_attributes.sh \
+  test_anastasis_reducer_backup_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_enter_secret.sh
+  test_anastasis_reducer_enter_secret.sh \
+  test_anastasis_reducer_recovery_enter_user_attributes.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_user_attributes.sh 
b/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
similarity index 96%
rename from src/cli/test_anastasis_reducer_enter_user_attributes.sh
rename to src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
index 756cd1c..a4116b5 100755
--- a/src/cli/test_anastasis_reducer_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
@@ -29,7 +29,7 @@ function cleanup()
 AFN=`which anastasis-reducer`
 ADN=`dirname $AFN`
 RESOURCES=$ADN/../share/anastasis
-SFILE=$RESOURCES/test_reducer_stateUACSTATE
+SFILE=$RESOURCES/test_reducer_backup_stateUACSTATE
 TFILE=`mktemp test_reducer_stateXXXXXX`
 
 trap cleanup EXIT
diff --git a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh 
b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
new file mode 100755
index 0000000..32f5f43
--- /dev/null
+++ b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
@@ -0,0 +1,141 @@
+#!/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 $CONF $CONF_1 $CONF_2 $CONF_3 $CONF_4
+    #rm -f $TFILE
+    wait
+}
+
+# Install cleanup handler (except for kill -9)
+AFN=`which anastasis-reducer`
+ADN=`dirname $AFN`
+RESOURCES=$ADN/../share/anastasis
+SFILE=$RESOURCES/test_reducer_recovery_stateUACSTATE
+TFILE=`mktemp test_reducer_stateXXXXXX`
+CONF=`mktemp test_reducerXXXXXX.conf`
+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`
+
+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
+ANASTASIS_DB=anastasischeck
+ANASTASIS_DB_1=anastasischeck1
+ANASTASIS_DB_2=anastasischeck2
+ANASTASIS_DB_3=anastasischeck3
+
+# Configuration file will be edited, so we create one
+# from the template.
+cp test_reducer.conf $CONF
+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
+
+# Clean up
+DATA_DIR=`taler-config -f -c $CONF -s PATHS -o TALER_HOME`
+rm -rf $DATA_DIR || true
+
+# reset database
+# dropdb $TALER_DB >/dev/null 2>/dev/null || true
+# createdb $TALER_DB || exit_skip "Could not create database $TALER_DB"
+# dropdb $ANASTASIS_DB >/dev/null 2>/dev/null || true
+# createdb $ANASTASIS_DB || exit_skip "Could not create database $ANASTASIS_DB"
+# dropdb $ANASTASIS_DB_1 >/dev/null 2>/dev/null || true
+# createdb $ANASTASIS_DB_1 || exit_skip "Could not create database 
$ANASTASIS_DB_1"
+# dropdb $ANASTASIS_DB_2 >/dev/null 2>/dev/null || true
+# createdb $ANASTASIS_DB_2 || exit_skip "Could not create database 
$ANASTASIS_DB_2"
+# dropdb $ANASTASIS_DB_3 >/dev/null 2>/dev/null || true
+# createdb $ANASTASIS_DB_3 || exit_skip "Could not create database 
$ANASTASIS_DB_3"
+
+echo "Launching anastasis service"
+valgrind anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log &
+valgrind anastasis-httpd -c $CONF_2 2> anastasis-httpd_2.log &
+valgrind anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log &
+valgrind anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log &
+
+# Wait for anastasis services 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 " "
+echo "Beginning with actual reducer test"
+
+# Test user attributes collection in a recovery state
+echo " "
+echo "Test user attributes collection in a recovery state"
+./anastasis-reducer -a \
+  '{"identity_attributes": {
+    "full_name": "Max Musterman",
+    "ahv_number": "756.9217.0769.85",
+    "birth_year": 2000 ,
+    "birth_month": 1, 
+    "birth_day": 1}}' \
+  enter_user_attributes $SFILE $TFILE
+
+STATE=`jq -r -e .recovery_state < $TFILE`
+if test "$STATE" != "AUTHENTICATIONS_EDITING"
+then
+    exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+fi
+
+SELECTED_COUNTRY=`jq -r -e .selected_country < $TFILE`
+if test "$SELECTED_COUNTRY" != "ch"
+then
+    exit_fail "Expected selected country to be ch, got $SELECTED_COUNTRY"
+fi
+
+exit 0
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index cafad61..237d240 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -74,7 +74,6 @@ struct ANASTASIS_DecryptionPolicy
  */
 struct ANASTASIS_RecoveryInformation
 {
-
   struct ANASTASIS_DecryptionPolicy *dps;
 
   unsigned int dps_len;
@@ -200,6 +199,16 @@ typedef void
 struct ANASTASIS_ChallengeInformation *
 ANASTASIS_get_challenge (struct ANASTASIS_Challenge *challenge);
 
+/**
+ * Returns JSON-encoded challenge information.
+ *
+ * @param ci object to return JSON encoding for
+ * @return JSON encoding of @a r
+ */
+json_t *
+ANASTASIS_challenge_information_to_json (const struct
+                                         ANASTASIS_ChallengeInformation *ci);
+
 /**
  * Defines a Callback for the payment of an escrow challenge. Sends back a 
payment link
  * and a status code.
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index a074048..a780ab1 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -280,105 +280,97 @@ struct ANASTASIS_ChallengeAnswerOperation
 };
 
 
-// json_t *
-// ANASTASIS_recovery_to_json (const struct ANASTASIS_Recovery *r)
-// {
-//   return json_pack 
("{s:o,s:s,s:o,s:s,s:o,s:o,s:o,s:o,s:o,s:I,s:I,s:o,s:o,s:o,s:I,s:o}",
-//                     "pc",
-//                     GNUNET_JSON_from_data_auto (&r->pc),
-//                     "pc_cls",
-//                     r->pc_cls,
-//                     "csc",
-//                     GNUNET_JSON_from_data_auto (&r->csc),
-//                     "csc_cls",
-//                     r->csc_cls,
-//                     "id",
-//                     GNUNET_JSON_from_data_auto (&r->id),
-//                     "pub_key",
-//                     GNUNET_JSON_from_data_auto (&r->pub_key),
-//                     "ctx",
-//                     GNUNET_JSON_from_data_auto (r->ctx),
-//                     "plo",
-//                     GNUNET_JSON_from_data_auto (r->plo),
-//                     "encrypted_recovery_document",
-//                     GNUNET_JSON_from_data (r->encrypted_recovery_document,
-//                                            r->enc_rec_doc_size),
-//                     "http_status",
-//                     r->http_status,
-//                     "response_code",
-//                     r->response_code,
-//                     "enc_core_secret",
-//                     GNUNET_JSON_from_data (r->enc_core_secret,
-//                                            r->enc_core_secret_size),
-//                     "policy_salt",
-//                     GNUNET_JSON_from_data_auto (&r->policy_salt),
-//                     "solved_challenges",
-//                     GNUNET_JSON_from_data_auto (r->solved_challenges),
-//                     "solved_challenge_pos",
-//                     r->solved_challenge_pos,
-//                     "ri",
-//                     GNUNET_JSON_from_data_auto (r->ri));
-// }
-
-
-// struct ANASTASIS_Recovery *
-// ANASTASIS_recovery_from_json (const json_t *json)
-// {
-//   struct ANASTASIS_Recovery *r = GNUNET_new (struct ANASTASIS_Recovery);
-//   struct GNUNET_JSON_Specification spec[] = {
-//     GNUNET_JSON_spec_fixed_auto ("pc",
-//                                  &r->pc),
-//     GNUNET_JSON_spec_string ("pc_cls",
-//                              &r->pc_cls),
-//     GNUNET_JSON_spec_fixed_auto ("csc",
-//                                  &r->csc),
-//     GNUNET_JSON_spec_string ("csc_cls",
-//                              &r->csc_cls),
-//     GNUNET_JSON_spec_fixed_auto ("id",
-//                                  &r->id),
-//     GNUNET_JSON_spec_fixed_auto ("pub_key",
-//                                  &r->pub_key),
-//     GNUNET_JSON_spec_fixed_auto ("ctx",
-//                                  &r->ctx),
-//     GNUNET_JSON_spec_fixed_auto ("plo",
-//                                  &r->plo),
-//     GNUNET_JSON_spec_fixed ("encrypted_recovery_document",
-//                             &r->encrypted_recovery_document,
-//                             &r->enc_rec_doc_size),
-//     GNUNET_JSON_spec_uint32 ("http_status",
-//                              &r->http_status),
-//     GNUNET_JSON_spec_uint32 ("response_code",
-//                              &r->response_code),
-//     GNUNET_JSON_spec_fixed ("enc_core_secret",
-//                             &r->enc_core_secret,
-//                             &r->enc_core_secret_size),
-//     GNUNET_JSON_spec_fixed_auto ("policy_salt",
-//                                  &r->policy_salt),
-//     GNUNET_JSON_spec_fixed_auto ("solved_challenges",
-//                                  &r->solved_challenges),
-//     GNUNET_JSON_spec_uint32 ("solved_challenge_pos",
-//                              &r->solved_challenge_pos),
-//     GNUNET_JSON_spec_fixed_auto ("ri",
-//                                  &r->ri),
-//     GNUNET_JSON_spec_end ()
-//   };
-//   const char *err_name;
-//   unsigned int err_line;
-
-//   if (GNUNET_OK !=
-//       GNUNET_JSON_parse (json,
-//                          spec,
-//                          &err_name,
-//                          &err_line))
-//   {
-//     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-//                 "Failed to parse recovery in line %u (%s)\n",
-//                 err_line,
-//                 err_name);
-//     return NULL;
-//   }
-//   return r;
-// }
+json_t *
+ANASTASIS_recovery_to_json (const struct ANASTASIS_Recovery *r)
+{
+  return json_pack 
("{s:o,s:s,s:o,s:s,s:o,s:o,s:o,s:I,s:I,s:o,s:o,s:o,s:I,s:o}",
+                    "pc",
+                    GNUNET_JSON_from_data_auto (&r->pc),
+                    "pc_cls",
+                    r->pc_cls,
+                    "csc",
+                    GNUNET_JSON_from_data_auto (&r->csc),
+                    "csc_cls",
+                    r->csc_cls,
+                    "id",
+                    GNUNET_JSON_from_data_auto (&r->id),
+                    "pub_key",
+                    GNUNET_JSON_from_data_auto (&r->pub_key),
+                    "encrypted_recovery_document",
+                    GNUNET_JSON_from_data (r->encrypted_recovery_document,
+                                           r->enc_rec_doc_size),
+                    "http_status",
+                    r->http_status,
+                    "response_code",
+                    r->response_code,
+                    "enc_core_secret",
+                    GNUNET_JSON_from_data (r->enc_core_secret,
+                                           r->enc_core_secret_size),
+                    "policy_salt",
+                    GNUNET_JSON_from_data_auto (&r->policy_salt),
+                    "solved_challenges",
+                    GNUNET_JSON_from_data_auto (r->solved_challenges),
+                    "solved_challenge_pos",
+                    r->solved_challenge_pos,
+                    "ri",
+                    GNUNET_JSON_from_data_auto (r->ri));
+}
+
+
+struct ANASTASIS_Recovery *
+ANASTASIS_recovery_from_json (const json_t *json)
+{
+  struct ANASTASIS_Recovery *r = GNUNET_new (struct ANASTASIS_Recovery);
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_fixed_auto ("pc",
+                                 &r->pc),
+    // GNUNET_JSON_spec_string ("pc_cls",
+    //                          &r->pc_cls),
+    GNUNET_JSON_spec_fixed_auto ("csc",
+                                 &r->csc),
+    // GNUNET_JSON_spec_string ("csc_cls",
+    //                          &r->csc_cls),
+    GNUNET_JSON_spec_fixed_auto ("id",
+                                 &r->id),
+    GNUNET_JSON_spec_fixed_auto ("pub_key",
+                                 &r->pub_key),
+    GNUNET_JSON_spec_fixed ("encrypted_recovery_document",
+                            &r->encrypted_recovery_document,
+                            r->enc_rec_doc_size),
+    GNUNET_JSON_spec_uint32 ("http_status",
+                             &r->http_status),
+    GNUNET_JSON_spec_uint32 ("response_code",
+                             &r->response_code),
+    GNUNET_JSON_spec_fixed ("enc_core_secret",
+                            &r->enc_core_secret,
+                            r->enc_core_secret_size),
+    GNUNET_JSON_spec_fixed_auto ("policy_salt",
+                                 &r->policy_salt),
+    GNUNET_JSON_spec_fixed_auto ("solved_challenges",
+                                 &r->solved_challenges),
+    GNUNET_JSON_spec_uint32 ("solved_challenge_pos",
+                             &r->solved_challenge_pos),
+    GNUNET_JSON_spec_fixed_auto ("ri",
+                                 &r->ri),
+    GNUNET_JSON_spec_end ()
+  };
+  const char *err_name;
+  unsigned int err_line;
+
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (json,
+                         spec,
+                         &err_name,
+                         &err_line))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to parse recovery in line %u (%s)\n",
+                err_line,
+                err_name);
+    return NULL;
+  }
+  return r;
+}
 
 
 /**
@@ -621,6 +613,29 @@ ANASTASIS_get_challenge (struct ANASTASIS_Challenge 
*challenge)
   ci->instructions = challenge->instructions;
   ci->solved = challenge->solved;
   ci->challenge = challenge;
+
+  return ci;
+}
+
+json_t *
+ANASTASIS_challenge_information_to_json (const struct
+                                         ANASTASIS_ChallengeInformation *ci)
+{
+  return json_pack ("{s:o,s:s,s:s,s:o,s:s:s:I,s:o}",
+                    "truth_public_key",
+                    GNUNET_JSON_from_data_auto (ci->truth_public_key),
+                    "method",
+                    ci->method,
+                    "url",
+                    ci->url,
+                    "nonce",
+                    GNUNET_JSON_from_data_auto (ci->nonce),
+                    "instructions",
+                    ci->instructions,
+                    "solved",
+                    (json_int_t) ci->solved,
+                    "challenge",
+                    GNUNET_JSON_from_data_auto (ci->challenge));
 }
 
 
@@ -923,18 +938,18 @@ policy_lookup_cb (void *cls,
 
     for (int a = 0; a < r->ri->dps[j].nonces_length; a++)
     {
-      char buf[53];
+      char buf[52];
 
       GNUNET_strlcpy (buf,
-                      nonces + a * 52,
+                      nonces + a * 51,
                       52);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "At %s:%d buf is %s\n", __FILE__, __LINE__,
                   buf);
       GNUNET_STRINGS_string_to_data (buf,
-                                     sizeof(buf),
+                                     sizeof (buf),
                                      &r->ri->dps[j].nonces[a],
-                                     sizeof(struct ANASTASIS_CRYPTO_NonceP));
+                                     sizeof (struct ANASTASIS_CRYPTO_NonceP));
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "At %s:%d escrow nonce is %s-%llu b\n", __FILE__, __LINE__,
                   TALER_B2S (&r->ri->dps[j].nonces[a]),
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 8f61d89..d9428dc 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -222,19 +222,24 @@ struct RecoverSecretState
   struct ANASTASIS_RecoveryInformation *ri;
 
   /**
-   * Coresecret to check if decryption worked
+   * Information about the challenges.
    */
-  const void *core_secret;
+  struct ANASTASIS_ChallengeInformation *challenges;
 
   /**
-   * Information about the challenges.
+   * Amount of challenges.
    */
-  static struct ANASTASIS_ChallengeInformation *challenges;
+  unsigned int challenges_length;
 
   /**
-   * Amount of challenges.
+   * Reference to a state.
    */
-  static unsigned int challenges_length;
+  json_t *state;
+
+  /**
+   * callback (#DispatchHandler) to call during/after operation
+   */
+  ANASTASIS_ActionCallback cb;
 
   struct GNUNET_SCHEDULER_Task *tt;
 };
@@ -944,21 +949,38 @@ policy_lookup_cb (void *cls,
                   const struct ANASTASIS_RecoveryInformation *ri,
                   const enum TALER_ErrorCode ec)
 {
+  json_t *challenge_information;
   struct RecoverSecretState *rss = cls;
-  rss->ri = (struct ANASTASIS_RecoveryInformation *) ri;
-  GNUNET_SCHEDULER_cancel (r->tt);
+
+  if (NULL != rss->tt)
+    GNUNET_SCHEDULER_cancel (rss->tt);
   rss->tt = NULL;
+
+  challenge_information = json_object_get (rss->state,
+                                           "challenge_information");
+  if (NULL == challenge_information)
+  {
+    challenge_information = json_array ();
+    GNUNET_assert (json_is_array (challenge_information));
+  }
+  else
+  {
+    GNUNET_assert (json_is_array (challenge_information));
+    return;
+  }
+
   if (NULL == ri)
   {
     GNUNET_break (0);
     return;
   }
+  rss->ri = (struct ANASTASIS_RecoveryInformation *) ri;
   rss->http_status = MHD_HTTP_OK;
+
   for (unsigned int i = 0; i < rss->ri->cs_len; i++)
   {
     struct ANASTASIS_ChallengeInformation *ci =
       ANASTASIS_get_challenge (rss->ri->cs[i]);
-
     unsigned int contains = 0;
     for (unsigned int i = 0; i < rss->challenges_length; i++)
     {
@@ -971,56 +993,30 @@ policy_lookup_cb (void *cls,
       }
     }
     if (0 == contains)
+    {
       GNUNET_array_append (rss->challenges,
                            rss->challenges_length,
-                           ci);
+                           *ci);
+      GNUNET_assert (
+        0 == json_array_append (
+          challenge_information,
+          ANASTASIS_challenge_information_to_json (ci)));
+    }
   }
-
-}
-
-
-/**
- * Function which collects the recovery information
- * and calls the #ANASTASIS_ActionCallback.
- *
- * @param r a handle to a recovery begin operation
- */
-static void
-conclude_recovery_begin (struct RecoverSecretState *r)
-{
-  if (MHD_HTTP_OK == r->http_status)
+  if (0 < json_array_size (challenge_information))
   {
-    json_t *recovery_information =
-      json_object_get (state,
-                       "recovery_information");
-    if (NULL == recovery_information)
-    {
-
-    }
-    r->cb (NULL,
-           ANASTASIS_EC_NONE,
-           r->state);
+    GNUNET_assert (
+      0 == json_object_set_new (rss->state,
+                                "challenge_information",
+                                challenge_information));
+    rss->cb (NULL,
+             ANASTASIS_EC_NONE,
+             rss->state);
+    rss->cb = NULL;
   }
 }
 
 
-/**
- * Retries a "recovery begin" after timeout.
- *
- * @param cls closure for a "recovery begin" request
- */
-static void
-policy_request_timeout (void *cls)
-{
-  struct RecoverSecretState *r = cls;
-
-  r->tt = NULL;
-  ANASTASIS_recovery_abort (r->recovery);
-  r->recovery = NULL;
-  conclude_recovery_begin (r);
-}
-
-
 /**
  * DispatchHandler/Callback function which is called for a
  * "enter_user_attributes" action.
@@ -1140,29 +1136,29 @@ enter_user_attributes (json_t *state,
   }
   else
   {
-    json_t *recovery_data;
     json_t *version;
     json_t *providers;
     json_t *p_value;
-    char *p_key;
+    const char *p_key;
     struct RecoverSecretState *rss
       = GNUNET_new (struct RecoverSecretState);
 
     providers = json_object_get (state,
                                  "authentication_providers");
     GNUNET_assert (NULL != providers);
-    rss->id_data = json_object_get (attributes,
-                                    "id_data");
-    GNUNET_assert (NULL != id_data);
-    version = json_object_get (attributes,
+    rss->id_data = attributes;
+    version = json_object_get (arguments,
                                "version");
-    rss->version = (unsigned int) json_integer_value (version);
+    if (NULL != version)
+      rss->version = (unsigned int) json_integer_value (version);
     rss->challenges_length = 0;
     json_object_set_new (state,
                          s_mode,
                          json_string (
                            ANASTASIS_recovery_state_to_string (
                              ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING)));
+    rss->state = json_incref (state);
+    rss->cb = cb;
 
     json_object_foreach (providers, p_key, p_value)
     {
@@ -1175,9 +1171,9 @@ enter_user_attributes (json_t *state,
         struct ANASTASIS_CRYPTO_PowSalt salt;
         json_t *provider_data;
         json_t *provider_url;
-        char *salt_str;
+        const char *salt_str;
         void *iter = json_object_iter (m_value);
-        char *key = json_object_iter_key (iter);
+        const char *key = json_object_iter_key (iter);
 
         provider_data = json_object_get (m_value,
                                          key);
@@ -1191,7 +1187,7 @@ enter_user_attributes (json_t *state,
                            "provider_salt"));
         GNUNET_assert (NULL != salt_str);
         GNUNET_assert (
-          GNUNET_OK !=
+          GNUNET_OK ==
           GNUNET_STRINGS_string_to_data (salt_str,
                                          strlen (salt_str),
                                          &salt,
@@ -1203,13 +1199,13 @@ enter_user_attributes (json_t *state,
             rss->id_data,
             (NULL != version)
             ? rss->version
-            : 0),
-        rss->anastasis_url,
-        &salt,
-        &policy_lookup_cb,
-        rss,
-        NULL,
-        rss);
+            : 0,
+            rss->anastasis_url,
+            &salt,
+            &policy_lookup_cb,
+            rss,
+            NULL,
+            rss);
 
         if (NULL == rss->recovery)
         {
@@ -1219,14 +1215,9 @@ enter_user_attributes (json_t *state,
               state);
           return NULL;
         }
-        else
-        {
-          rss->tt = GNUNET_SCHEDULER_add_delayed (CONFIG_GENERIC_TIMEOUT,
-                                                  &policy_request_timeout,
-                                                  rss);
-        }
       }
     }
+    return NULL;
   }
 }
 

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