gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: testing anastasis recovery


From: gnunet
Subject: [taler-anastasis] branch master updated: testing anastasis recovery
Date: Wed, 06 May 2020 20:07:41 +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 75e2deb  testing anastasis recovery
75e2deb is described below

commit 75e2debee55fd1562a68a2aea23a7f0a78ff38af
Author: Dominik Meister <address@hidden>
AuthorDate: Wed May 6 20:07:30 2020 +0200

    testing anastasis recovery
---
 src/include/anastasis.h                |   2 +-
 src/include/anastasis_testing_lib.h    |  75 +++++++++++++-
 src/lib/Makefile.am                    |   5 +-
 src/lib/anastasis.c                    |   2 +-
 src/lib/test_anastasis.c               |   5 +-
 src/lib/testing_cmd_challenge_answer.c | 178 +++++++++++++++++++++++++++++++++
 src/lib/testing_cmd_recover_secret.c   |  99 ++++++++++++++++--
 src/lib/testing_trait_challenge.c      |  70 +++++++++++++
 src/lib/testing_trait_recovery.c       |  70 +++++++++++++
 9 files changed, 493 insertions(+), 13 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index b9a343f..e92c4d9 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -58,7 +58,7 @@ struct ANASTASIS_RecoveryInformation
 
   unsigned int dps_len;
 
-  struct ANASTASIS_Challenge *cs;
+  struct ANASTASIS_Challenge **cs;
 
   unsigned int cs_len;
 
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index ff45951..1dc46f7 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -633,22 +633,93 @@ enum ANASTASIS_TESTING_RecoverSecretOption
 
 };
 
+/**
+ * Obtain a recover from @a cmd.
+ *
+ * @param cmd command to extract the recovery from.
+ * @param index the index of the recovery
+ * @param r[out] set to the recovery coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_recovery (const struct TALER_TESTING_Command *cmd,
+                                      unsigned int index,
+                                      const struct ANASTASIS_Recovery **r);
+
+
+/**
+ * Offer a recovery process.
+ *
+ * @param index the recovery index number.
+ * @param r the recovery to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_recovery (unsigned int index,
+                                       const struct ANASTASIS_Recovery *r);
 /**
  * Make the "recover secret" command.
  *
  * @param label command label
  * @param anastasis_url base URL of the anastasis serving our requests.
+ * @param id_data identfication data from the user
+ * @param version of the recovery document to download
  * @param http_status expected HTTP status.
  * @param rso recover secret options
+ * @param download_ref salt download reference
  * @return the command
  */
 struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_recover_secret (const char *label,
                                       const char *anastasis_url,
+                                      json_t *id_data,
+                                      unsigned int version,
                                       unsigned int http_status,
-                                      enum
-                                      ANASTASIS_TESTING_RecoverSecretOption 
rso,
+                                      enum 
ANASTASIS_TESTING_RecoverSecretOption
+                                      rso,
                                       const char *download_ref);
 
 
+/* ********************* test challenge answer ********************* */
+/**
+ * Obtain a challenge from @a cmd.
+ *
+ * @param cmd command to extract the challenge from.
+ * @param index the index of the challenge
+ * @param c[out] set to the challenge coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_challenge (const struct TALER_TESTING_Command *cmd,
+                                       unsigned int index,
+                                       const struct ANASTASIS_Challenge **c);
+/**
+ * Offer a challenge.
+ *
+ * @param index the challenge index number.
+ * @param c the challenge to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_challenge (unsigned int index,
+                                        const struct ANASTASIS_Challenge *r);
+/**
+ * Make the "challenge answer" command.
+ *
+ * @param label command label
+ * @param http_status expected HTTP status.
+ * @param challenge_ref reference to the recovery process
+ * @param challenge_index defines the index of the trait to solve
+ * @param answer to the challenge
+ * @param answer_size size of the answer
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_challenge_answer (const char *label,
+                                        unsigned int http_status,
+                                        const char *challenge_ref,
+                                        unsigned int challenge_index,
+                                        const void *answer,
+                                        size_t answer_size);
+
 #endif
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index f91b244..adccffd 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -72,8 +72,11 @@ libanastasistesting_la_SOURCES = \
   testing_cmd_policy_create.c \
   testing_cmd_secret_share.c \
   testing_cmd_recover_secret.c \
+  testing_cmd_challenge_answer.c \
   testing_trait_truth.c \
-  testing_trait_policy.c
+  testing_trait_policy.c \
+  testing_trait_recovery.c \
+  testing_trait_challenge.c
 libanastasistesting_la_LIBADD = \
   $(top_builddir)/src/lib/libanastasisrest.la \
   $(top_builddir)/src/lib/libanastasis.la \
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 1d5c2e9..6460e9b 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -560,7 +560,7 @@ policy_lookup_cb (void *cls,
   r->solved_challenge_pos = 0;
   // SETUP POLICY CALLBACK
   ri->dps = r->dps;
-  ri->cs = cs;
+  ri->cs = &cs;
   if (NULL != r->pc)
   {
     r->pc (r->pc_cls,
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index 7348529..e82c05f 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -250,9 +250,12 @@ run (void *cls,
 
     ANASTASIS_TESTING_cmd_recover_secret ("recover-secret-1",
                                           anastasis_url,
+                                          
ANASTASIS_TESTING_make_id_data_example (
+                                          "MaxMuster123456789"),
+                                          0,
                                           MHD_HTTP_PAYMENT_REQUIRED,
                                           ANASTASIS_TESTING_RSO_NONE,
-                                          NULL),
+                                          salt-request-1),
     */
 
     TALER_TESTING_cmd_end ()
diff --git a/src/lib/testing_cmd_challenge_answer.c 
b/src/lib/testing_cmd_challenge_answer.c
new file mode 100644
index 0000000..f6d3a43
--- /dev/null
+++ b/src/lib/testing_cmd_challenge_answer.c
@@ -0,0 +1,178 @@
+/*
+  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/testing_cmd_challenge_answer.c
+ * @brief command to execute the anastasis recovery service
+ * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+#include <taler/taler_util.h>
+#include <taler/taler_testing_lib.h>
+
+
+/**
+ * State for a "challenge answer" CMD.
+ */
+struct ChallengeState
+{
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+  /**
+   * Reference to the challenge we are solving
+   */
+  struct ANASTASIS_Challenge *c;
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+  /**
+   * Answer to the challenge we are solving
+   */
+  const void *answer;
+  /**
+   * Size of the answer we are solving
+   */
+  size_t answer_size;
+  /**
+   * Referenece to the recovery process
+   */
+  const char *challenge_ref;
+  /**
+   * Index of the challenge we are solving
+   */
+  unsigned int challenge_index;
+};
+
+
+static void
+challenge_answer_cb (void *af_cls,
+                     enum TALER_ErrorCode ec)
+{
+  struct ChallengeState *cs = af_cls;
+  // FIXME
+
+  TALER_TESTING_interpreter_next (cs->is);
+}
+
+/**
+ * Run a "recover secret" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+challenge_answer_run (void *cls,
+                      const struct TALER_TESTING_Command *cmd,
+                      struct TALER_TESTING_Interpreter *is)
+{
+  struct ChallengeState *cs = cls;
+  const struct TALER_TESTING_Command *ref;
+  const struct ANASTASIS_Challenge *c;
+  cs->is = is;
+
+  if (NULL != cs->challenge_ref)
+  {
+    ref = TALER_TESTING_interpreter_lookup_command
+            (is,
+            cs->challenge_ref);
+    if (NULL == ref)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (cs->is);
+      return;
+    }
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_challenge (ref,
+                                               cs->challenge_index,
+                                               &c))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (cs->is);
+      return;
+    }
+  }
+
+  ANASTASIS_challenge_answer (c,
+                              cs->answer,
+                              cs->answer_size,
+                              &challenge_answer_cb,
+                              cs);
+}
+
+
+/**
+ * Free the state of a "recover secret" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ * @param cmd command being freed.
+ */
+static void
+challenge_answer_cleanup (void *cls,
+                          const struct TALER_TESTING_Command *cmd)
+{
+  // FIXME: Cleanup logic
+  struct ChallengeState *cs = cls;
+  GNUNET_free (cs);
+}
+
+/**
+ * Make the "challenge answer" command.
+ *
+ * @param label command label
+ * @param http_status expected HTTP status.
+ * @param challenge_ref reference to the recovery process
+ * @param challenge_index defines the index of the trait to solve
+ * @param answer to the challenge
+ * @param answer_size size of the answer
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_challenge_answer (const char *label,
+                                        unsigned int http_status,
+                                        const char *challenge_ref,
+                                        unsigned int challenge_index,
+                                        const void *answer,
+                                        size_t answer_size)
+{
+  struct ChallengeState *cs;
+
+  cs = GNUNET_new (struct ChallengeState);
+  cs->http_status = http_status;
+  cs->challenge_ref = challenge_ref;
+  cs->answer = answer;
+  cs->challenge_index = challenge_index;
+  cs->answer_size = answer_size;
+
+  struct TALER_TESTING_Command cmd = {
+    .cls = cs,
+    .label = label,
+    .run = &challenge_answer_run,
+    .cleanup = &challenge_answer_cleanup,
+  };
+
+  return cmd;
+}
+
+
+/* end of testing_cmd_challenge_answer.c */
\ No newline at end of file
diff --git a/src/lib/testing_cmd_recover_secret.c 
b/src/lib/testing_cmd_recover_secret.c
index 16b94ca..e586b9d 100644
--- a/src/lib/testing_cmd_recover_secret.c
+++ b/src/lib/testing_cmd_recover_secret.c
@@ -48,9 +48,9 @@ struct RecoverSecretState
   unsigned int http_status;
 
   /**
-   * The /truth GET operation handle.
+   * The /policy GET operation handle.
    */
-  struct ANASTASIS_Recovery *rso;
+  struct ANASTASIS_Recovery *recovery;
 
   /**
    * Reference to download command we expect to lookup.
@@ -61,8 +61,49 @@ struct RecoverSecretState
    * Options for how we are supposed to do the download.
    */
   enum ANASTASIS_TESTING_RecoverSecretOption rsopt;
+  /**
+   * Identification data from the user
+   */
+  json_t *id_data;
+  /**
+   * version of the recovery document
+   */
+  unsigned int version;
+  /**
+   * Salt to be used to derive the id
+   */
+  struct ANASTASIS_CRYPTO_SaltP *salt;
+  /**
+   * Recovery information from the lookup
+   */
+  struct ANASTASIS_RecoveryInformation *ri;
+
 };
+static void
+policy_lookup_cb (void *cls,
+                  const struct ANASTASIS_RecoveryInformation *ri,
+                  const enum TALER_ErrorCode ec)
+{
+  struct RecoverSecretState *rss = cls;
+  rss->ri = ri;
+  if (NULL == ri)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (rss->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (rss->is);
+}
 
+static void
+core_secret_cb (void *cls,
+                const void *secret,
+                size_t secret_size)
+{
+/**
+ * FIXME check if same as uploaded by secret share
+ */
+}
 
 /**
  * Run a "recover secret" CMD.
@@ -77,11 +118,42 @@ recover_secret_run (void *cls,
                     struct TALER_TESTING_Interpreter *is)
 {
   struct RecoverSecretState *rss = cls;
-
+  const struct TALER_TESTING_Command *ref;
+  const struct ANASTASIS_CRYPTO_SaltP *salt;
   rss->is = is;
-  // FIXME: Whole secret share procedure here
 
-  if (NULL == rss->rso)
+  if (NULL != rss->download_reference)
+  {
+    ref = TALER_TESTING_interpreter_lookup_command
+            (is,
+            rss->download_reference);
+    if (NULL == ref)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (rss->is);
+      return;
+    }
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_salt (ref,
+                                          0,
+                                          &salt))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (rss->is);
+      return;
+    }
+  }
+
+  rss->recovery = ANASTASIS_recovery_begin (is->ctx,
+                                            rss->id_data,
+                                            rss->version,
+                                            rss->anastasis_url,
+                                            salt,
+                                            &policy_lookup_cb,
+                                            rss,
+                                            &core_secret_cb,
+                                            rss);
+  if (NULL == rss->recovery)
   {
     GNUNET_break (0);
     TALER_TESTING_interpreter_fail (rss->is);
@@ -125,7 +197,14 @@ recover_secret_traits (void *cls,
 {
   struct RecoverSecretState *rss = cls;
   struct TALER_TESTING_Trait traits[] = {
-    // FIXME: What traits are usefull?
+    ANASTASIS_TESTING_make_trait_recovery (0,
+                                           rss->recovery),
+    ANASTASIS_TESTING_make_trait_challenge (0,
+                                            rss->ri->cs[0]),
+    ANASTASIS_TESTING_make_trait_challenge (1,
+                                            rss->ri->cs[1]),
+    ANASTASIS_TESTING_make_trait_challenge (2,
+                                            rss->ri->cs[2]),
     TALER_TESTING_trait_end ()
   };
 
@@ -135,19 +214,23 @@ recover_secret_traits (void *cls,
                                   index);
 }
 
-
 /**
  * Make the "recover secret" command.
  *
  * @param label command label
  * @param anastasis_url base URL of the anastasis serving our requests.
+ * @param id_data identfication data from the user
+ * @param version of the recovery document to download
  * @param http_status expected HTTP status.
  * @param rso recover secret options
+ * @param download_ref salt download reference
  * @return the command
  */
 struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_recover_secret (const char *label,
                                       const char *anastasis_url,
+                                      json_t *id_data,
+                                      unsigned int version,
                                       unsigned int http_status,
                                       enum
                                       ANASTASIS_TESTING_RecoverSecretOption 
rso,
@@ -157,6 +240,8 @@ ANASTASIS_TESTING_cmd_recover_secret (const char *label,
 
   rss = GNUNET_new (struct RecoverSecretState);
   rss->http_status = http_status;
+  rss->version = version;
+  rss->id_data = id_data;
   rss->rsopt = rso;
   rss->anastasis_url = anastasis_url;
   rss->download_reference = download_ref;
diff --git a/src/lib/testing_trait_challenge.c 
b/src/lib/testing_trait_challenge.c
new file mode 100644
index 0000000..009821a
--- /dev/null
+++ b/src/lib/testing_trait_challenge.c
@@ -0,0 +1,70 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it
+  under the terms of the GNU 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 lib/testing_trait_challenge.c
+ * @brief traits to offer a challenge
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ */
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+
+#define ANASTASIS_TESTING_TRAIT_CHALLENGE "anastasis-challenge"
+
+/**
+ * Obtain a challenge from @a cmd.
+ *
+ * @param cmd command to extract the challenge from.
+ * @param index the index of the challenge
+ * @param c[out] set to the challenge coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_challenge (const struct TALER_TESTING_Command *cmd,
+                                       unsigned int index,
+                                       const struct ANASTASIS_Challenge **c)
+{
+  return cmd->traits (cmd->cls,
+                      (const void **) c,
+                      ANASTASIS_TESTING_TRAIT_CHALLENGE,
+                      index);
+}
+
+
+/**
+ * Offer a challenge.
+ *
+ * @param index the challenge index number.
+ * @param c the challenge to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_challenge
+  (unsigned int index,
+  const struct ANASTASIS_Challenge *c)
+{
+  struct TALER_TESTING_Trait ret = {
+    .index = index,
+    .trait_name = ANASTASIS_TESTING_TRAIT_CHALLENGE,
+    .ptr = (const void *) c
+  };
+  return ret;
+}
+/* end of testing_trait_challenge.c */
diff --git a/src/lib/testing_trait_recovery.c b/src/lib/testing_trait_recovery.c
new file mode 100644
index 0000000..f571d6d
--- /dev/null
+++ b/src/lib/testing_trait_recovery.c
@@ -0,0 +1,70 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it
+  under the terms of the GNU 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 lib/testing_trait_recovery.c
+ * @brief traits to offer a recovery process
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ */
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+
+#define ANASTASIS_TESTING_TRAIT_RECOVERY "anastasis-recovery"
+
+/**
+ * Obtain a recover from @a cmd.
+ *
+ * @param cmd command to extract the recovery from.
+ * @param index the index of the recovery
+ * @param r[out] set to the recovery coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_recovery (const struct TALER_TESTING_Command *cmd,
+                                      unsigned int index,
+                                      const struct ANASTASIS_Recovery **r)
+{
+  return cmd->traits (cmd->cls,
+                      (const void **) r,
+                      ANASTASIS_TESTING_TRAIT_RECOVERY,
+                      index);
+}
+
+
+/**
+ * Offer a recovery process.
+ *
+ * @param index the recovery index number.
+ * @param r the recovery to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_recovery
+  (unsigned int index,
+  const struct ANASTASIS_Recovery *r)
+{
+  struct TALER_TESTING_Trait ret = {
+    .index = index,
+    .trait_name = ANASTASIS_TESTING_TRAIT_RECOVERY,
+    .ptr = (const void *) r
+  };
+  return ret;
+}
+/* end of testing_trait_recovery.c */

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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