gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix salt


From: gnunet
Subject: [taler-anastasis] branch master updated: fix salt
Date: Sun, 07 Mar 2021 15:56:21 +0100

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 114044e  fix salt
114044e is described below

commit 114044eb4a00ce9ad9bc0c5b9a1caa12d254ab6f
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Mar 7 15:56:19 2021 +0100

    fix salt
---
 src/include/anastasis.h                  |   4 +-
 src/include/anastasis_testing_lib.h      |  15 ++
 src/lib/anastasis_backup.c               |   2 +-
 src/lib/anastasis_recovery.c             |   9 +-
 src/testing/test_anastasis.c             |   5 +-
 src/testing/testing_cmd_recover_secret.c | 226 +++++++++++++++++++++++++++++--
 6 files changed, 245 insertions(+), 16 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 5a9f7e0..75ddfdf 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -444,7 +444,7 @@ struct ANASTASIS_Recovery;
  * @param id_data contains the users identity, (user account on providers)
  * @param version defines the version which will be downloaded NULL for latest 
version
  * @param anastasis_provider_url NULL terminated list of possible provider urls
- * @param salt the server salt
+ * @param provider_salt the server salt
  * @param pc opens the policy call back which holds the downloaded version and 
the policies
  * @param pc_cls closure for callback
  * @param csc core secret callback is opened, with this the core secert is 
passed to the client after the authentication
@@ -456,7 +456,7 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
                           const json_t *id_data,
                           unsigned int version,
                           const char *anastasis_provider_url,
-                          const struct ANASTASIS_CRYPTO_PowSalt *salt,
+                          const struct ANASTASIS_CRYPTO_PowSalt *provider_salt,
                           ANASTASIS_PolicyCallback pc,
                           void *pc_cls,
                           ANASTASIS_CoreSecretCallback csc,
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index f4de245..c82e610 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -798,6 +798,21 @@ ANASTASIS_TESTING_cmd_recover_secret (
   const char *core_secret_ref);
 
 
+/**
+ * Make "recover secret finish" command.
+ *
+ * @param label command label
+ * @param recover_label label of a "recover secret" command to wait for
+ * @param timeout how long to wait at most
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_recover_secret_finish (
+  const char *label,
+  const char *recover_label,
+  struct GNUNET_TIME_Relative timeout);
+
+
 /* ********************* test challenge answer ********************* */
 /**
  * Obtain a challenge from @a cmd.
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index 33a3042..698ad14 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -864,7 +864,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
         GNUNET_assert (index_pss < pss_length);
         pssi = &ss->pss[index_pss++];
         pssi->anastasis_url = GNUNET_strdup (pt->url);
-        pssi->server_salt = &pt->salt;
+        pssi->server_salt = &pt->provider_salt;
         for (unsigned int m = 0; 0 < pds_len; m++)
         {
           if (NULL == pds[m].provider_url)
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index 1865c30..544455a 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -542,6 +542,11 @@ policy_lookup_cb (void *cls,
   case MHD_HTTP_OK:
     break;
   case MHD_HTTP_NOT_FOUND:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Policy unknown to server (HTTP status %u in %s:%u\n)",
+                http_status,
+                __FILE__,
+                __LINE__);
     r->csc (r->csc_cls,
             ANASTASIS_RS_POLICY_DOWNLOAD_FAILED,
             NULL,
@@ -842,7 +847,7 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
                           const json_t *id_data,
                           unsigned int version,
                           const char *anastasis_provider_url,
-                          const struct ANASTASIS_CRYPTO_PowSalt *salt,
+                          const struct ANASTASIS_CRYPTO_PowSalt *provider_salt,
                           ANASTASIS_PolicyCallback pc,
                           void *pc_cls,
                           ANASTASIS_CoreSecretCallback csc,
@@ -860,7 +865,7 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
   r->id_data = json_incref ((json_t *) id_data);
   r->provider_url = GNUNET_strdup (anastasis_provider_url);
   ANASTASIS_CRYPTO_user_identifier_derive (id_data,
-                                           salt,
+                                           provider_salt,
                                            &r->id);
   ANASTASIS_CRYPTO_account_public_key_derive (&r->id,
                                               &pub_key);
diff --git a/src/testing/test_anastasis.c b/src/testing/test_anastasis.c
index 834f778..999773c 100644
--- a/src/testing/test_anastasis.c
+++ b/src/testing/test_anastasis.c
@@ -287,8 +287,9 @@ run (void *cls,
                                             "SomeTruth2",
                                             0, /* mode */
                                             ANASTASIS_CHALLENGE_STATUS_SOLVED),
-    // FIXME: need some 'recover_secret_conclude' command here!
-
+    ANASTASIS_TESTING_cmd_recover_secret_finish ("recover-finish-1",
+                                                 "recover-secret-1",
+                                                 GNUNET_TIME_UNIT_SECONDS),
     TALER_TESTING_cmd_end ()
   };
 
diff --git a/src/testing/testing_cmd_recover_secret.c 
b/src/testing/testing_cmd_recover_secret.c
index f40219a..df71db1 100644
--- a/src/testing/testing_cmd_recover_secret.c
+++ b/src/testing/testing_cmd_recover_secret.c
@@ -1,6 +1,6 @@
 /*
   This file is part of Anastasis
-  Copyright (C) 2020 Taler Systems SA
+  Copyright (C) 2020, 2021 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
@@ -20,7 +20,6 @@
  * @author Dennis Neufeld
  * @author Dominik Meister
  */
-
 #include "platform.h"
 #include "anastasis_testing_lib.h"
 #include <taler/taler_util.h>
@@ -67,11 +66,6 @@ struct RecoverSecretState
    */
   json_t *id_data;
 
-  /**
-   * version of the recovery document
-   */
-  unsigned int version;
-
   /**
    * Salt to be used to derive the id
    */
@@ -86,9 +80,33 @@ struct RecoverSecretState
    * Coresecret to check if decryption worked
    */
   const void *core_secret;
+
+  /**
+   * Task scheduled to wait for recovery to complete.
+   */
+  struct GNUNET_SCHEDULER_Task *recovery_task;
+
+  /**
+   * version of the recovery document
+   */
+  unsigned int version;
+
+  /**
+   * #GNUNET_OK if the secret was recovered, #GNUNET_SYSERR if
+   * recovery failed (yielded wrong secret).
+   */
+  int recovered;
 };
 
 
+/**
+ * Callback which passes back the recovery document and its possible
+ * policies. Also passes back the version of the document for the user
+ * to check.
+ *
+ * @param cls closure for the callback
+ * @param ri recovery information struct which contains the policies
+ */
 static void
 policy_lookup_cb (void *cls,
                   const struct ANASTASIS_RecoveryInformation *ri)
@@ -106,6 +124,15 @@ policy_lookup_cb (void *cls,
 }
 
 
+/**
+ * This function is called whenever the recovery process ends.
+ * On success, the secret is returned in @a secret.
+ *
+ * @param cls closure
+ * @param ec error code
+ * @param secret contains the core secret which is passed to the user
+ * @param secret_size defines the size of the core secret
+ */
 static void
 core_secret_cb (void *cls,
                 enum ANASTASIS_RecoveryStatus rc,
@@ -115,15 +142,35 @@ core_secret_cb (void *cls,
   struct RecoverSecretState *rss = cls;
 
   rss->recovery = NULL;
+  if (ANASTASIS_RS_SUCCESS != rc)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Recovery failed with status %d\n",
+                rc);
+    TALER_TESTING_interpreter_fail (rss->is);
+    return;
+  }
   if (0 != memcmp (secret,
                    rss->core_secret,
                    secret_size))
   {
     GNUNET_break (0);
-    TALER_TESTING_interpreter_fail (rss->is);
+    rss->recovered = GNUNET_SYSERR;
+    if (NULL != rss->recovery_task)
+    {
+      GNUNET_SCHEDULER_cancel (rss->recovery_task);
+      rss->recovery_task = NULL;
+      TALER_TESTING_interpreter_fail (rss->is);
+    }
     return;
   }
-  TALER_TESTING_interpreter_next (rss->is);
+  rss->recovered = GNUNET_OK;
+  if (NULL != rss->recovery_task)
+  {
+    GNUNET_SCHEDULER_cancel (rss->recovery_task);
+    rss->recovery_task = NULL;
+    TALER_TESTING_interpreter_next (rss->is);
+  }
 }
 
 
@@ -204,6 +251,12 @@ recover_secret_run (void *cls,
 }
 
 
+/**
+ * Task to run the abort routine on the given @a cls object
+ * after the stack has fully unwound.
+ *
+ * @param cls a `struct ANASTASIS_Recovery *`
+ */
 static void
 delayed_abort (void *cls)
 {
@@ -235,6 +288,11 @@ recover_secret_cleanup (void *cls,
       rss->recovery);
     rss->recovery = NULL;
   }
+  if (NULL != rss->recovery_task)
+  {
+    GNUNET_SCHEDULER_cancel (rss->recovery_task);
+    rss->recovery_task = NULL;
+  }
   json_decref (rss->id_data);
   GNUNET_free (rss);
 }
@@ -258,7 +316,15 @@ recover_secret_traits (void *cls,
   struct RecoverSecretState *rss = cls;
 
   if (NULL == rss->ri)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (index >= rss->ri->cs_len)
+  {
+    GNUNET_break (0);
     return GNUNET_SYSERR;
+  }
   {
     struct TALER_TESTING_Trait traits[] = {
       ANASTASIS_TESTING_make_trait_challenge (index,
@@ -274,6 +340,54 @@ recover_secret_traits (void *cls,
 }
 
 
+/**
+ * Function called on timeout of the secret finishing operation.
+ *
+ * @param cls a `struct RecoverSecretState *`
+ */
+static void
+recovery_fail (void *cls)
+{
+  struct RecoverSecretState *rss = cls;
+
+  rss->recovery_task = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Timeout during secret recovery\n");
+  TALER_TESTING_interpreter_fail (rss->is);
+}
+
+
+/**
+ * Wait @a delay for @a cmd to finish secret recovery.
+ *
+ * @param cmd command to wait on
+ * @param delay how long to wait at most
+ */
+static void
+recover_secret_finish (struct TALER_TESTING_Command *cmd,
+                       struct GNUNET_TIME_Relative delay)
+{
+  struct RecoverSecretState *rss = cmd->cls;
+
+  GNUNET_assert (&recover_secret_run == cmd->run);
+  GNUNET_assert (NULL == rss->recovery_task);
+  switch (rss->recovered)
+  {
+  case GNUNET_OK:
+    TALER_TESTING_interpreter_next (rss->is);
+    break;
+  case GNUNET_NO:
+    rss->recovery_task = GNUNET_SCHEDULER_add_delayed (delay,
+                                                       &recovery_fail,
+                                                       rss);
+    break;
+  case GNUNET_SYSERR:
+    TALER_TESTING_interpreter_fail (rss->is);
+    break;
+  }
+}
+
+
 struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_recover_secret (
   const char *label,
@@ -307,4 +421,98 @@ ANASTASIS_TESTING_cmd_recover_secret (
 }
 
 
+/**
+ * State for a "recover secret finish" CMD.
+ */
+struct RecoverSecretFinishState
+{
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * URL of the anastasis backend.
+   */
+  const char *recover_label;
+
+  /**
+   * Timeout.
+   */
+  struct GNUNET_TIME_Relative timeout;
+
+};
+
+
+/**
+ * Run a "recover secret finish" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+recover_secret_finish_run (void *cls,
+                           const struct TALER_TESTING_Command *cmd,
+                           struct TALER_TESTING_Interpreter *is)
+{
+  struct RecoverSecretFinishState *rsfs = cls;
+  struct TALER_TESTING_Command *ref;
+
+  rsfs->is = is;
+  ref = (struct TALER_TESTING_Command *)
+        TALER_TESTING_interpreter_lookup_command (is,
+                                                  rsfs->recover_label);
+  if (NULL == ref)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (rsfs->is);
+    return;
+  }
+  recover_secret_finish (ref,
+                         rsfs->timeout);
+}
+
+
+/**
+ * Free the state of a "recover secret finish" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure
+ * @param cmd command being freed.
+ */
+static void
+recover_secret_finish_cleanup (void *cls,
+                               const struct TALER_TESTING_Command *cmd)
+{
+  struct RecoverSecretFinishState *rsfs = cls;
+
+  GNUNET_free (rsfs);
+}
+
+
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_recover_secret_finish (
+  const char *label,
+  const char *recover_label,
+  struct GNUNET_TIME_Relative timeout)
+{
+  struct RecoverSecretFinishState *rsfs;
+
+  rsfs = GNUNET_new (struct RecoverSecretFinishState);
+  rsfs->recover_label = recover_label;
+  rsfs->timeout = timeout;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = rsfs,
+      .label = label,
+      .run = &recover_secret_finish_run,
+      .cleanup = &recover_secret_finish_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
 /* end of testing_cmd_recover_secret.c */

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