gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 05/12: added return value to ANASTASIS_challenge_answe


From: gnunet
Subject: [taler-anastasis] 05/12: added return value to ANASTASIS_challenge_answer
Date: Mon, 07 Dec 2020 20:28:39 +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 235bf5a8bba1a713a42f72a28079d80541847ad5
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Dec 4 09:14:16 2020 +0100

    added return value to ANASTASIS_challenge_answer
---
 src/cli/test_anastasis_reducer_enter_secret.sh |  6 +-
 src/include/anastasis.h                        | 18 +++++-
 src/lib/anastasis.c                            | 77 ++++++++++++++++++++++++--
 src/lib/testing_cmd_challenge_answer.c         | 29 ++++++++--
 4 files changed, 118 insertions(+), 12 deletions(-)

diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 64adc19..fc890ac 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -21,7 +21,7 @@ function cleanup()
     do
         kill $n 2> /dev/null || true
     done
-    rm -f $SFILE $TFILE $CONF $CONF_1 $CONF_2 $CONF_3 $CONF_4 
+    rm -f $CONF $CONF_1 $CONF_2 $CONF_3 $CONF_4 
     wait
 }
 
@@ -33,7 +33,7 @@ CONF_2=`mktemp test_reducerXXXXXX_2.conf`
 CONF_3=`mktemp test_reducerXXXXXX_3.conf`
 CONF_4=`mktemp test_reducerXXXXXX_4.conf`
 SFILE=ressources/test_reducer_stateSESTATE
-TFILE=`mktemp test_reducer_stateXXXXXX`
+TFILE=ressources/test_reducer_stateBFSTATE
 
 trap cleanup EXIT
 
@@ -183,6 +183,8 @@ echo "Beginning with actual reducer test"
 # Test enter secret in a backup state
 echo " "
 echo "Test enter secret in a backup state"
+mkdir -p ressources
+touch $TFILE
 ./anastasis-reducer -a \
   '{"secret": "veryhardtoguesssecret",
     "type": "password"}' \
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 705ed89..f65d52b 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -117,6 +117,21 @@ typedef void
                             enum TALER_ErrorCode ec);
 
 
+/**
+ * Handle to a challenge answer operation.
+ */
+struct ANASTASIS_ChallengeAnswerOperation;
+
+/**
+ * Cancel a challenge answer operation.
+ *
+ * @param pso the challenge answer operation to cancel
+ */
+void
+ANASTASIS_challenge_answer_cancel (struct
+                                   ANASTASIS_ChallengeAnswerOperation *cao);
+
+
 /**
  * Challenge answer from the user like input SMS pin. Is referenced to a 
challenge and
  * sends back an AnswerFeedback.
@@ -126,8 +141,9 @@ typedef void
  * @param answer user input instruction defines which input is needed
  * @param af reference to the answerfeedback which is passed back to the user
  * @param af_cls handle for the challenge answer struct
+ * @return handle to an challenge answer operation
  */
-void
+struct ANASTASIS_ChallengeAnswerOperation *
 ANASTASIS_challenge_answer (struct GNUNET_CURL_Context *ctx,
                             struct ANASTASIS_Challenge *c,
                             const char *answer,
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 6e6ce75..45ce1a2 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -228,10 +228,12 @@ struct ANASTASIS_Challenge
    * Cost for authentication
    */
   struct TALER_Amount cost;
+
   /**
    * Passes back the payment information for the current challenge
    */
   ANASTASIS_ChallengePaymentCallback cpc;
+
   /**
    * Closure for the payment callback
    */
@@ -241,14 +243,17 @@ struct ANASTASIS_Challenge
    * The /truth GET operation handle.
    */
   struct ANASTASIS_ChallengeRunOperation *cro;
+
   /**
    * Sends back the status and the instructions of the challenge start
    */
   ANASTASIS_ChallengeStartCallback csc;
+
   /**
    * Closure for the Challenge Start
    */
   void *csc_cls;
+
   /**
    * Payment identifier.
    */
@@ -267,6 +272,12 @@ struct ANASTASIS_Challenge
   bool payment_requested;
 };
 
+
+struct ANASTASIS_ChallengeAnswerOperation
+{
+  struct ANASTASIS_Challenge *c;
+};
+
 /**
  * Function called with the results of a #ANASTASIS_keyshare_lookup().
  *
@@ -403,13 +414,34 @@ keyshare_lookup_cb (void *cls,
 }
 
 
+/**
+ * Cancel a challenge answer operation.
+ *
+ * @param pso the challenge answer operation to cancel
+ */
 void
+ANASTASIS_challenge_answer_cancel (struct
+                                   ANASTASIS_ChallengeAnswerOperation *cao)
+{
+  if (NULL != cao->c)
+  {
+    GNUNET_free (cao->c);
+  }
+  GNUNET_free (cao);
+}
+
+
+struct ANASTASIS_ChallengeAnswerOperation *
 ANASTASIS_challenge_answer (struct GNUNET_CURL_Context *ctx,
                             struct ANASTASIS_Challenge *c,
                             const char *answer_str,
                             ANASTASIS_AnswerFeedback af,
                             void *af_cls)
 {
+  struct ANASTASIS_ChallengeAnswerOperation *cao;
+
+  cao = GNUNET_new (struct ANASTASIS_ChallengeAnswerOperation);
+  cao->c = c;
   c->af = af;
   c->ctx = ctx;
   c->af_cls = af_cls;
@@ -446,6 +478,11 @@ ANASTASIS_challenge_answer (struct GNUNET_CURL_Context 
*ctx,
                                          &keyshare_lookup_cb,
                                          c);
     GNUNET_free (str);
+    if (NULL == c->kslo)
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
   }
   else
   {
@@ -458,7 +495,13 @@ ANASTASIS_challenge_answer (struct GNUNET_CURL_Context 
*ctx,
                                          answer_str,
                                          &keyshare_lookup_cb,
                                          c);
+    if (NULL == c->kslo)
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
   }
+  return cao;
 }
 
 
@@ -590,6 +633,11 @@ ANASTASIS_challenge_start (struct GNUNET_CURL_Context *ctx,
                                     c->payment_requested,
                                     &challenge_run_cb,
                                     c);
+  if (NULL == c->cro)
+  {
+    GNUNET_break (0);
+    return;
+  }
 }
 
 
@@ -881,6 +929,11 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
                                               &policy_lookup_cb,
                                               r,
                                               &version);
+    if (NULL == r->plo)
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
   }
   else
   {
@@ -889,6 +942,11 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
                                       &r->pub_key,
                                       &policy_lookup_cb,
                                       r);
+    if (NULL == r->plo)
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
   }
 
   return r;
@@ -1217,11 +1275,13 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
   if (NULL == truth)
   {
     GNUNET_break (0);
-    return tu;
+    return NULL;
   }
 
   ANASTASIS_CRYPTO_truth_public_key_derive (&t->nonce,
                                             &pub_key);
+  tu->tc = tc;
+  tu->tc_cls = tc_cls;
   tu->tso = ANASTASIS_truth_store (tu->ctx,
                                    t->url,
                                    &pub_key,
@@ -1230,15 +1290,22 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
                                    tu->paid_order_id,
                                    &truth_store_callback,
                                    tu);
-  // SETUP TRUTH CALLBACK
-  tu->tc = tc;
-  tu->tc_cls = tc_cls;
+  if (NULL == tu->tso)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
   if (NULL != tu->tc)
   {
     tu->tc (tu->tc_cls,
             t);
     tu->tc = NULL;
   }
+  else
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
   // FIXME PAYMENT CALLBACK
   return tu;
 }
@@ -1700,7 +1767,9 @@ policy_store_cb (void *cls,
                     http_status);
       pss->ss->src = NULL;
     }
+    return;
   }
+  GNUNET_break (0);
 }
 
 
diff --git a/src/lib/testing_cmd_challenge_answer.c 
b/src/lib/testing_cmd_challenge_answer.c
index 4abca36..3f7baa2 100644
--- a/src/lib/testing_cmd_challenge_answer.c
+++ b/src/lib/testing_cmd_challenge_answer.c
@@ -66,6 +66,11 @@ struct ChallengeState
    * 0 for no plugin needed 1 for plugin needed to authenticate
    */
   unsigned int mode;
+
+  /**
+   * Handle for an challenge answer operation
+   */
+  struct ANASTASIS_ChallengeAnswerOperation *cao;
 };
 
 
@@ -145,11 +150,17 @@ challenge_answer_run (void *cls,
     cs->answer = code;
   }
 
-  ANASTASIS_challenge_answer (is->ctx,
-                              (struct ANASTASIS_Challenge *) c,
-                              cs->answer,
-                              &challenge_answer_cb,
-                              cs);
+  cs->cao = ANASTASIS_challenge_answer (is->ctx,
+                                        (struct ANASTASIS_Challenge *) c,
+                                        cs->answer,
+                                        &challenge_answer_cb,
+                                        cs);
+  if (NULL == cs->cao)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (cs->is);
+    return;
+  }
 }
 
 
@@ -165,6 +176,14 @@ challenge_answer_cleanup (void *cls,
                           const struct TALER_TESTING_Command *cmd)
 {
   struct ChallengeState *cs = cls;
+  if (NULL != cs->cao)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command '%s' did not complete (challenge answer)\n",
+                cmd->label);
+    ANASTASIS_challenge_answer_cancel (cs->cao);
+    cs->cao = NULL;
+  }
   GNUNET_free (cs);
 }
 

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