gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: implement proper information hi


From: gnunet
Subject: [taler-anastasis] branch master updated: implement proper information hiding for anastasis.h API
Date: Wed, 10 Feb 2021 20:37:38 +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 707bb04  implement proper information hiding for anastasis.h API
707bb04 is described below

commit 707bb04545951ffa0b8793b645a44ef70d304390
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Feb 10 20:37:36 2021 +0100

    implement proper information hiding for anastasis.h API
---
 src/include/anastasis.h      | 104 +++++++++-------
 src/lib/anastasis_recovery.c | 274 ++++++++++++++++++++++++++++---------------
 2 files changed, 238 insertions(+), 140 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 19470c8..74e2833 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -15,7 +15,7 @@
 */
 /**
  * @file include/anastasis.h
- * @brief anastasis client api
+ * @brief anastasis high-level client api
  * @author Christian Grothoff
  * @author Dominik Meister
  * @author Dennis Neufeld
@@ -32,8 +32,10 @@
 /* ********************* Recovery api *********************** */
 
 /**
- * Challenge struct contains the public key's needed for the recovery process 
and a reference to
- * ANASTASIS_Recovery.
+ * Defines the instructions for a challenge, what does the user have
+ * to do to fulfill the challenge.  Also defines the method and other
+ * information for the challenge like a link for the video indent or a
+ * information to which address an e-mail was sent.
  */
 struct ANASTASIS_Challenge;
 
@@ -44,14 +46,9 @@ struct ANASTASIS_Challenge;
  * information for the challenge like a link for the video indent or a
  * information to which address an e-mail was sent.
  */
-struct ANASTASIS_ChallengeInformation
+struct ANASTASIS_ChallengeDetails
 {
 
-  /**
-   * UUID which uniquely identifies the challenge
-   */
-  struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
-
   /**
    * Cost to solve this challenge
    */
@@ -77,12 +74,12 @@ struct ANASTASIS_ChallengeInformation
 
 
 /**
- * Returns detailed information about a challenge.
+ * Return public details about a challenge.
  *
- * @param challenge reference to the escrow challenge which is started
- * @return ANASTASIS_ChallengeInformation object
+ * @param challenge the challenge to inspect
+ * @return public details about the challenge
  */
-const struct ANASTASIS_ChallengeInformation *
+const struct ANASTASIS_ChallengeDetails *
 ANASTASIS_challenge_get_details (struct ANASTASIS_Challenge *challenge);
 
 
@@ -142,7 +139,7 @@ struct ANASTASIS_ChallengeStartResponse
   /**
    * Which challenge is this about?
    */
-  const struct ANASTASIS_Challenge *challenge;
+  struct ANASTASIS_Challenge *challenge;
 
   /**
    * Details depending on @e cs
@@ -311,24 +308,15 @@ ANASTASIS_challenge_abort (struct ANASTASIS_Challenge *c);
 struct ANASTASIS_DecryptionPolicy
 {
   /**
-   * Set of truths identfied by UUID
+   * Array of challenges needed to solve for this decryption policy.
    */
-  struct ANASTASIS_CRYPTO_TruthUUIDP *uuids;
+  struct ANASTASIS_Challenge **challenges;
 
   /**
-   * length of the @a uuids in this policy
+   * Length of the @a challenges in this policy.
    */
-  uint32_t uuids_length;
+  unsigned int challenges_length;
 
-  /**
-   * Encrypted masterkey (encrypted with the policy key).
-   */
-  struct ANASTASIS_CRYPTO_EncryptedMasterKeyP emk;
-
-  /**
-   * Salt used to decrypt master key.
-   */
-  struct ANASTASIS_CRYPTO_SaltP salt;
 };
 
 
@@ -337,16 +325,14 @@ struct ANASTASIS_DecryptionPolicy
  */
 struct ANASTASIS_RecoveryInformation
 {
-  // FIXME: document. Why is this exposed to the client!??
-  // struct ANASTASIS_CRYPTO_SaltP salt;
 
   /**
    * Array of @e dps_len policies that would allow recovery of the core secret.
    */
-  struct ANASTASIS_DecryptionPolicy *dps;
+  struct ANASTASIS_DecryptionPolicy **dps;
 
   /**
-   * Array of @e cs_len challenges to be solved (for any of the policies).
+   * Array of all @e cs_len challenges to be solved (for any of the policies).
    */
   struct ANASTASIS_Challenge **cs;
 
@@ -446,18 +432,19 @@ struct ANASTASIS_Recovery;
 
 
 /**
-* Starts the recovery process by opening callbacks for the coresecret and a 
policy callback. A list of
-* providers is checked for policies and passed back to the client.
-*
-* @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 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
-* @param csc_cls handle for the callback
-*/
+ * Starts the recovery process by opening callbacks for the coresecret and a 
policy callback. A list of
+ * providers is checked for policies and passed back to the client.
+ *
+ * @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 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
+ * @param csc_cls handle for the callback
+ * @return recovery operation handle
+ */
 struct ANASTASIS_Recovery *
 ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
                           const json_t *id_data,
@@ -469,6 +456,37 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
                           ANASTASIS_CoreSecretCallback csc,
                           void *csc_cls);
 
+
+/**
+ * Serialize recovery operation state and returning it.
+ * The recovery MAY still continue, applications should call
+ * #ANASTASIS_recovery_abort() to truly end the recovery.
+ *
+ * @param r recovery operation to suspend.
+ * @return JSON serialized state of @a r
+ */
+json_t *
+ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r);
+
+
+/**
+ * Suspend recovery operation, serializing its state and returning it.
+ *
+ * @param input result from #ANASTASIS_recovery_serialize()
+ * @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
+ * @param csc_cls handle for the callback
+ * @return recovery operation handle
+ */
+struct ANASTASIS_Recovery *
+ANASTASIS_recovery_deserialize (const json_t *input,
+                                ANASTASIS_PolicyCallback pc,
+                                void *pc_cls,
+                                ANASTASIS_CoreSecretCallback csc,
+                                void *csc_cls);
+
+
 /**
  * Cancels the recovery process
  *
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index 60087f2..3a5a909 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -28,156 +28,195 @@
 
 
 /**
- * stores provider URLs, identity key material, decrypted recovery document 
(internally!)
-*/
-struct ANASTASIS_Recovery
+ * Challenge struct contains the uuid and public key's needed for the
+ * recovery process and a reference to ANASTASIS_Recovery.
+ */
+struct ANASTASIS_Challenge
 {
 
   /**
-   * Identity key material used for the derivation of keys
+   * Information exported to clients about this challenge.
    */
-  struct ANASTASIS_CRYPTO_UserIdentifierP id;
+  struct ANASTASIS_ChallengeDetails ci;
 
   /**
-   * Recovery information which is sent to the user
+   * UUID which identifies this challenge
    */
-  struct ANASTASIS_RecoveryInformation ri;
+  struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
 
   /**
-   * Identity data to user id from.
+   * Key used to encrypt the truth passed to the server
    */
-  json_t *id_data;
+  struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
 
   /**
-   * Callback to send back a recovery document with the policies and the 
version
+   * Salt used to encrypt the truth
    */
-  ANASTASIS_PolicyCallback pc;
+  struct ANASTASIS_CRYPTO_PowSalt truth_salt;
 
   /**
-   * closure for the Policy callback
+   * Decrypted key share for this challenge.  Set once the
+   * challenge was @e ri.solved.
    */
-  void *pc_cls;
+  struct ANASTASIS_CRYPTO_KeyShareP key_share;
 
   /**
-   * Callback to send back the core secret which was saved by
-   * anastasis, after all challenges are completed
-  */
-  ANASTASIS_CoreSecretCallback csc;
+   * Callback which gives back the instructions and a status code of
+   * the request to the user when answering a challenge was initiated.
+   */
+  ANASTASIS_AnswerFeedback af;
 
   /**
-   * Closure for the core secret callback
+   * Closure for the challenge callback
    */
-  void *csc_cls;
+  void *af_cls;
 
   /**
-   * Curl context
+   * Defines the base URL of the Anastasis provider used for the challenge.
    */
-  struct GNUNET_CURL_Context *ctx;
+  char *url;
 
   /**
-   * Reference to the policy lookup operation which is executed
+   * Which method is this challenge (E-Mail, Security Question, SMS...)
    */
-  struct ANASTASIS_PolicyLookupOperation *plo;
+  char *method;
 
   /**
-   * Array of challenges that have been solved.
-   * Valid entries up to @e solved_challenge_pos.
-   * Length matches the total number of challenges in @e ri.
+   * Instructions for solving the challenge (generic, set client-side
+   * when challenge was established).
    */
-  struct ANASTASIS_Challenge *solved_challenges;
+  char *instructions;
 
   /**
-   * Retrieved encrypted core secret from policy
+   * Reference to the recovery process which is ongoing
    */
-  void *enc_core_secret;
+  struct ANASTASIS_Recovery *recovery;
 
   /**
-   * Size of the @e enc_core_secret
+   * keyshare lookup operation
    */
-  size_t enc_core_secret_size;
+  struct ANASTASIS_KeyShareLookupOperation *kslo;
 
   /**
-   * Current offset in the @e solved_challenges array.
+   * The /truth GET operation handle.
    */
-  unsigned int solved_challenge_pos;
+  struct ANASTASIS_KeyShareLookupOperation *cro;
 
 };
 
 
 /**
- * Challenge struct contains the uuid and public key's needed for the
- * recovery process and a reference to ANASTASIS_Recovery.
+ * Defines a decryption policy with multiple escrow methods
  */
-struct ANASTASIS_Challenge
+struct DecryptionPolicy
 {
 
   /**
-   * Information exported to clients about this challenge.
+   * Publicly visible details about a decryption policy.
    */
-  struct ANASTASIS_ChallengeInformation ci;
+  struct ANASTASIS_DecryptionPolicy pub_details;
 
   /**
-   * UUID which identifies this challenge
+   * Encrypted masterkey (encrypted with the policy key).
    */
-  struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
+  struct ANASTASIS_CRYPTO_EncryptedMasterKeyP emk;
 
   /**
-   * Key used to encrypt the truth passed to the server
+   * Salt used to decrypt master key.
    */
-  struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
+  struct ANASTASIS_CRYPTO_SaltP salt;
 
   /**
-   * Salt used to encrypt the truth
+   * Array of challenges needed to solve for this decryption policy.
    */
-  struct ANASTASIS_CRYPTO_PowSalt truth_salt;
+  struct ANASTASIS_Challenge **challenges;
+
+};
+
+
+/**
+ * stores provider URLs, identity key material, decrypted recovery document 
(internally!)
+ */
+struct ANASTASIS_Recovery
+{
 
   /**
-   * Callback which gives back the instructions and a status code of
-   * the request to the user when answering a challenge was initiated.
+   * Identity key material used for the derivation of keys
    */
-  ANASTASIS_AnswerFeedback af;
+  struct ANASTASIS_CRYPTO_UserIdentifierP id;
 
   /**
-   * Closure for the challenge callback
+   * Recovery information which is given to the user
    */
-  void *af_cls;
+  struct ANASTASIS_RecoveryInformation ri;
 
   /**
-   * Defines the base URL of the Anastasis provider used for the challenge.
+   * Internal of @e ri.dps_len policies that would allow recovery of the core 
secret.
    */
-  char *url;
+  struct DecryptionPolicy *dps;
 
   /**
-   * Which method is this challenge (E-Mail, Security Question, SMS...)
+   * Array of @e ri.cs_len challenges to be solved (for any of the policies).
    */
-  char *method;
+  struct ANASTASIS_Challenge *cs;
 
   /**
-   * Instructions for solving the challenge (generic, set client-side
-   * when challenge was established).
+   * Identity data to user id from.
    */
-  char *instructions;
+  json_t *id_data;
 
   /**
-   * Reference to the recovery process which is ongoing
+   * Callback to send back a recovery document with the policies and the 
version
    */
-  struct ANASTASIS_Recovery *recovery;
+  ANASTASIS_PolicyCallback pc;
 
   /**
-   * keyshare lookup operation
+   * closure for the Policy callback
    */
-  struct ANASTASIS_KeyShareLookupOperation *kslo;
+  void *pc_cls;
 
   /**
-   * Decrypted key share for this challenge.  Set once the
-   * challenge was @e ri.solved.
+   * Callback to send back the core secret which was saved by
+   * anastasis, after all challenges are completed
+  */
+  ANASTASIS_CoreSecretCallback csc;
+
+  /**
+   * Closure for the core secret callback
    */
-  struct ANASTASIS_CRYPTO_KeyShareP key_share;
+  void *csc_cls;
 
   /**
-   * The /truth GET operation handle.
+   * Curl context
    */
-  struct ANASTASIS_KeyShareLookupOperation *cro;
+  struct GNUNET_CURL_Context *ctx;
+
+  /**
+   * Reference to the policy lookup operation which is executed
+   */
+  struct ANASTASIS_PolicyLookupOperation *plo;
+
+  /**
+   * Array of challenges that have been solved.
+   * Valid entries up to @e solved_challenge_pos.
+   * Length matches the total number of challenges in @e ri.
+   */
+  struct ANASTASIS_Challenge **solved_challenges;
+
+  /**
+   * Retrieved encrypted core secret from policy
+   */
+  void *enc_core_secret;
+
+  /**
+   * Size of the @e enc_core_secret
+   */
+  size_t enc_core_secret_size;
+
+  /**
+   * Current offset in the @e solved_challenges array.
+   */
+  unsigned int solved_challenge_pos;
 
 };
 
@@ -196,7 +235,7 @@ keyshare_lookup_cb (void *cls,
   struct ANASTASIS_Challenge *c = cls;
   struct ANASTASIS_Recovery *recovery = c->recovery;
   struct ANASTASIS_CRYPTO_UserIdentifierP id;
-  struct ANASTASIS_DecryptionPolicy *rdps;
+  struct DecryptionPolicy *rdps;
 
   c->kslo = NULL;
   switch (dd->status)
@@ -293,25 +332,23 @@ keyshare_lookup_cb (void *cls,
   ANASTASIS_CRYPTO_keyshare_decrypt (&dd->details.eks,
                                      &id,
                                      &c->key_share);
-  c->recovery->solved_challenges[c->recovery->solved_challenge_pos++] = *c;
+  c->recovery->solved_challenges[c->recovery->solved_challenge_pos++] = c;
 
   /* Check if there is a policy for which all challenges have
      been satisifed, if so, store it in 'rdps'. */
   rdps = NULL;
   for (unsigned int i = 0; i < recovery->ri.dps_len; i++)
   {
-    struct ANASTASIS_DecryptionPolicy *dps = &recovery->ri.dps[i];
+    struct DecryptionPolicy *dps = &recovery->dps[i];
     bool missing = false;
 
-    for (unsigned int j = 0; j < dps->uuids_length; j++)
+    for (unsigned int j = 0; j < dps->pub_details.challenges_length; j++)
     {
       bool found = false;
 
       for (unsigned int k = 0; k < recovery->solved_challenge_pos; k++)
       {
-        if (0 ==
-            GNUNET_memcmp (&dps->uuids[j],
-                           &recovery->solved_challenges[k].ci.uuid))
+        if (dps->challenges[j] == recovery->solved_challenges[k])
         {
           found = true;
           break;
@@ -335,17 +372,16 @@ keyshare_lookup_cb (void *cls,
   {
     void *core_secret;
     size_t core_secret_size;
-    struct ANASTASIS_CRYPTO_KeyShareP key_shares[rdps->uuids_length];
+    struct ANASTASIS_CRYPTO_KeyShareP
+      key_shares[rdps->pub_details.challenges_length];
     struct ANASTASIS_CRYPTO_PolicyKeyP policy_key;
 
-    for (unsigned int l = 0; l < rdps->uuids_length; l++)
+    for (unsigned int l = 0; l < rdps->pub_details.challenges_length; l++)
       for (unsigned int m = 0; m < recovery->solved_challenge_pos; m++)
-        if (0 ==
-            GNUNET_memcmp (&rdps->uuids[l],
-                           &recovery->solved_challenges[m].ci.uuid))
-          key_shares[l] = recovery->solved_challenges[m].key_share;
+        if (rdps->challenges[l] == recovery->solved_challenges[m])
+          key_shares[l] = recovery->solved_challenges[m]->key_share;
     ANASTASIS_CRYPTO_policy_key_derive (key_shares,
-                                        rdps->uuids_length,
+                                        rdps->pub_details.challenges_length,
                                         &rdps->salt,
                                         &policy_key);
     ANASTASIS_CRYPTO_core_secret_recover (&rdps->emk,
@@ -363,8 +399,8 @@ keyshare_lookup_cb (void *cls,
 }
 
 
-const struct ANASTASIS_ChallengeInformation *
-ANASTASIS_get_challenge (struct ANASTASIS_Challenge *challenge)
+const struct ANASTASIS_ChallengeDetails *
+ANASTASIS_challenge_get_details (struct ANASTASIS_Challenge *challenge)
 {
   return &challenge->ci;
 }
@@ -448,11 +484,6 @@ ANASTASIS_challenge_answer2 (struct ANASTASIS_Challenge *c,
 }
 
 
-/**
- * Abort challenge.
- *
- * @param c reference to the escrow challenge which was started
- */
 void
 ANASTASIS_challenge_abort (struct ANASTASIS_Challenge *c)
 {
@@ -624,20 +655,24 @@ policy_lookup_cb (void *cls,
   r->ri.cs_len = json_array_size (esc_methods);
   r->ri.dps_len = json_array_size (dec_policies);
   r->ri.dps = GNUNET_new_array (r->ri.dps_len,
-                                struct ANASTASIS_DecryptionPolicy);
+                                struct ANASTASIS_DecryptionPolicy *);
+  r->dps = GNUNET_new_array (r->ri.dps_len,
+                             struct DecryptionPolicy);
   r->solved_challenges = GNUNET_new_array (r->ri.cs_len,
-                                           struct ANASTASIS_Challenge);
+                                           struct ANASTASIS_Challenge *);
   r->ri.cs = GNUNET_new_array (r->ri.cs_len,
                                struct ANASTASIS_Challenge *);
+  r->cs = GNUNET_new_array (r->ri.cs_len,
+                            struct ANASTASIS_Challenge);
   for (unsigned int i = 0; i < r->ri.cs_len; i++)
   {
-    struct ANASTASIS_Challenge *cs = GNUNET_new (struct ANASTASIS_Challenge);
+    struct ANASTASIS_Challenge *cs = &r->cs[i];
     const char *instructions;
     const char *url;
     const char *escrow_method;
     struct GNUNET_JSON_Specification spec[] = {
       GNUNET_JSON_spec_fixed_auto ("uuid",
-                                   &cs->ci.uuid),
+                                   &cs->uuid),
       GNUNET_JSON_spec_string ("url",
                                &url),
       GNUNET_JSON_spec_string ("instructions",
@@ -679,11 +714,10 @@ policy_lookup_cb (void *cls,
 
   for (unsigned int j = 0; j < r->ri.dps_len; j++)
   {
-    struct ANASTASIS_DecryptionPolicy *dp = &r->ri.dps[j];
+    struct DecryptionPolicy *dp = &r->dps[j];
     json_t *uuids = NULL;
     json_t *uuid;
     size_t n_index;
-
     struct GNUNET_JSON_Specification spec[] = {
       GNUNET_JSON_spec_fixed_auto ("master_key",
                                    &dp->emk),
@@ -694,6 +728,7 @@ policy_lookup_cb (void *cls,
       GNUNET_JSON_spec_end ()
     };
 
+    r->ri.dps[j] = &r->dps[j].pub_details;
     if ( (GNUNET_OK !=
           GNUNET_JSON_parse (json_array_get (dec_policies,
                                              j),
@@ -712,20 +747,45 @@ policy_lookup_cb (void *cls,
       return;
     }
 
-    dp->uuids_length = json_array_size (uuids);
-    dp->uuids = GNUNET_new_array (dp->uuids_length,
-                                  struct ANASTASIS_CRYPTO_TruthUUIDP);
+    dp->pub_details.challenges_length = json_array_size (uuids);
+    dp->pub_details.challenges
+      = GNUNET_new_array (dp->pub_details.challenges_length,
+                          struct ANASTASIS_Challenge *);
     json_array_foreach (uuids, n_index, uuid)
     {
       const char *uuid_str = json_string_value (uuid);
+      struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
+      bool found = false;
 
       if ( (NULL == uuid_str) ||
            (GNUNET_OK !=
             GNUNET_STRINGS_string_to_data (
               uuid_str,
               strlen (uuid_str),
-              &dp->uuids[n_index],
-              sizeof (struct ANASTASIS_CRYPTO_TruthUUIDP))) )
+              &uuid,
+              sizeof (uuid))) )
+      {
+        GNUNET_break_op (0);
+        json_decref (dec_policies);
+        json_decref (uuids);
+        r->csc (r->csc_cls,
+                ANASTASIS_RS_POLICY_MALFORMED_JSON,
+                NULL,
+                0);
+        ANASTASIS_recovery_abort (r);
+        return;
+      }
+      for (unsigned int i = 0; i<r->ri.cs_len; i++)
+      {
+        if (0 !=
+            GNUNET_memcmp (&uuid,
+                           &r->cs[i].uuid))
+          continue;
+        found = true;
+        dp->challenges[n_index] = &r->cs[i];
+        break;
+      }
+      if (! found)
       {
         GNUNET_break_op (0);
         json_decref (dec_policies);
@@ -799,6 +859,26 @@ ANASTASIS_recovery_begin (struct GNUNET_CURL_Context *ctx,
 }
 
 
+json_t *
+ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r)
+{
+  GNUNET_break (0);
+  return NULL;
+}
+
+
+struct ANASTASIS_Recovery *
+ANASTASIS_recovery_deserialize (const json_t *input,
+                                ANASTASIS_PolicyCallback pc,
+                                void *pc_cls,
+                                ANASTASIS_CoreSecretCallback csc,
+                                void *csc_cls)
+{
+  GNUNET_break (0);
+  return NULL;
+}
+
+
 void
 ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r)
 {

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