gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: warnings and changes


From: gnunet
Subject: [taler-anastasis] branch master updated: warnings and changes
Date: Tue, 05 May 2020 19:01:22 +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 7eb4b24  warnings and changes
7eb4b24 is described below

commit 7eb4b24d3c46162d5848422f1363ed5cc1d2dece
Author: Dominik Meister <address@hidden>
AuthorDate: Tue May 5 19:01:06 2020 +0200

    warnings and changes
---
 src/include/anastasis.h |   6 +-
 src/lib/Makefile.am     |   3 +-
 src/lib/anastasis.c     | 234 +++++++++++++++++++++++++-----------------------
 3 files changed, 128 insertions(+), 115 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index aab80ed..b9a343f 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -25,6 +25,7 @@
 #include <gnunet/gnunet_util_lib.h>
 #include <uuid/uuid.h>
 #include "anastasis_service.h"
+#include <stdbool.h>
 
 /*Download api*/
 
@@ -44,7 +45,7 @@ struct ANASTASIS_DecryptionPolicy
   /**
    * encrypted masterkey ( encrypted with the policy key)
    */
-  struct ANASTASIS_CRYPTO_EncryptedMasterKey *emk;
+  struct ANASTASIS_CRYPTO_EncryptedMasterKeyP *emk;
 };
 
 /**
@@ -212,7 +213,8 @@ struct ANASTASIS_Recovery;
 * @param csc_cls handle for the callback
 */
 struct ANASTASIS_Recovery *
-ANASTASIS_recovery_begin (const json_t *id_data,
+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_SaltP *salt,
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 8fb04e4..f91b244 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -76,6 +76,8 @@ libanastasistesting_la_SOURCES = \
   testing_trait_policy.c
 libanastasistesting_la_LIBADD = \
   $(top_builddir)/src/lib/libanastasisrest.la \
+  $(top_builddir)/src/lib/libanastasis.la \
+  $(top_builddir)/src/util/libanastasisutil.la \
   -ltalerexchange \
   -ltalerjson \
   -ltalerutil \
@@ -99,7 +101,6 @@ test_anastasisrest_api_SOURCES = \
   test_anastasis_api.c
 test_anastasisrest_api_LDADD = \
   $(top_builddir)/src/stasis/libanastasisdb.la \
-  libanastasis.la \
   $(LIBGCRYPT_LIBS) \
   -ltalertesting \
   libanastasistesting.la \
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index e7a2016..1d5c2e9 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -185,9 +185,17 @@ struct ANASTASIS_Recovery
    * Length of available decryption policies
    */
   unsigned int dps_len;
-
+  /**
+   * Length of available decryption policies
+   */
   struct ANASTASIS_CRYPTO_SaltP policy_salt;
-  struct ANASTASIS_Challenge *solved_challenges[10];
+  /**
+   * Length of available decryption policies
+   */
+  struct ANASTASIS_Challenge *solved_challenges;
+  /**
+   * Length of available decryption policies
+   */
   unsigned int solved_challenge_pos;
 };
 
@@ -290,52 +298,52 @@ keyshare_lookup_cb (void *cls,
            http_status);
     return;
   }
+
+
   ANASTASIS_CRYPTO_keyshare_decrypt (dd->encrypted_key_share,
                                      &c->recovery->id,
                                      &c->key_share);
-  c->recovery->solved_challenges[c->recovery->solved_challenge_pos] = c;
+  c->recovery->solved_challenges[c->recovery->solved_challenge_pos] = *c;
   c->recovery->solved_challenge_pos++;
-  /**
-   * determines if atleast one policy was completed
-   */
-  unsigned int finished = 0;
+  c->af (c->af_cls,
+         http_status);
+
   /**
    * 0 equals the uuid was not solved 1 it was solved
    */
-  unsigned int contains = 0;
+  bool missing = true;
   /**
    * Index of the policy which was completed
    */
-  unsigned int success;
+  unsigned int success = UINT_MAX;
 
   for (unsigned int i = 0; i < c->recovery->dps_len; i++)
   {
     for (unsigned int j = 0; j < c->recovery->dps[i].uuids_length; j++)
     {
-      contains = 0;
+      missing = true;
       for (unsigned int k = 0; k < c->recovery->solved_challenge_pos; k++)
       {
-        if (0 == strncmp (c->recovery->dps[i].escrow_uuids[j],
-                          c->recovery->solved_challenges[k]->challenge_uuid,
-                          sizeof(uuid_t)))
+        if (0 == uuid_compare (c->recovery->dps[i].escrow_uuids[j],
+                               
c->recovery->solved_challenges[k].challenge_uuid))
         {
-          contains = 1;
+          missing = false;
           break;
         }
       }
-      if (contains == 0)
+      if (missing == true)
       {
         break;
       }
     }
-    if (contains == 1)
+    if (missing == false)
     {
-      finished = 1;
       success = i;
+      break;
     }
   }
 
-  if (finished == 1)
+  if (success != UINT_MAX)
   {
     void *core_secret;
     size_t core_secret_size;
@@ -346,11 +354,10 @@ keyshare_lookup_cb (void *cls,
     {
       for (unsigned int m = 0; m < c->recovery->solved_challenge_pos; m++)
       {
-        if (0 == strncmp (c->recovery->dps[l].escrow_uuids[m],
-                          c->recovery->solved_challenges[m]->challenge_uuid,
-                          sizeof(uuid_t)))
+        if (0 == uuid_compare (c->recovery->dps[l].escrow_uuids[m],
+                               
c->recovery->solved_challenges[m].challenge_uuid))
         {
-          key_shares[l] = *c->recovery->solved_challenges[m]->key_share;
+          key_shares[l] = *c->recovery->solved_challenges[m].key_share;
         }
       }
     }
@@ -369,8 +376,6 @@ keyshare_lookup_cb (void *cls,
                       core_secret,
                       core_secret_size);
   }
-  c->af (c->af_cls,
-         http_status);
 }
 /**
  * Challenge answer from the user like input SMS pin. Is referenced to a 
challenge and
@@ -399,7 +404,7 @@ ANASTASIS_challenge_answer (struct ANASTASIS_Challenge *c,
   c->http_status = MHD_HTTP_OK;
   c->kslo = ANASTASIS_keyshare_lookup (c->ctx,
                                        c->url,
-                                       c->challenge_uuid,
+                                       &c->challenge_uuid,
                                        &c->truth_key,
                                        &hashed_answer,
                                        &keyshare_lookup_cb,
@@ -419,6 +424,8 @@ ANASTASIS_challenge_run (struct ANASTASIS_Challenge 
*challenge,
                          ANASTASIS_ChallengeCallback cc,
                          void *cc_cls)
 {
+
+  // FIXME
   struct ANASTASIS_ChallengeInformation *ci;
   ci = GNUNET_new (struct ANASTASIS_ChallengeInformation);
   challenge->cc = cc;
@@ -461,8 +468,10 @@ policy_lookup_cb (void *cls,
                   const struct ANASTASIS_DownloadDetails *dd)
 {
   struct ANASTASIS_Recovery *r = cls;
-
+  struct ANASTASIS_RecoveryInformation *ri;
+  ri = GNUNET_new (struct ANASTASIS_RecoveryInformation);
   r->plo = NULL;
+
   if (http_status != r->http_status)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -470,20 +479,95 @@ policy_lookup_cb (void *cls,
                 http_status,
                 __FILE__,
                 __LINE__);
-    GNUNET_break (0);
+
+    r->pc (r->pc_cls,
+           ri,
+           r->http_status);
+    r->pc = NULL;
     return;
   }
   if (dd->policy == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "No recovery data available");
-    GNUNET_break (0);
+    r->pc (r->pc_cls,
+           ri,
+           r->http_status);
+    r->pc = NULL;
     return;
   }
-  r->enc_rec_doc_size = dd->policy_size;
-  r->encrypted_recovery_document = GNUNET_malloc (r->enc_rec_doc_size);
-  memcpy (r->encrypted_recovery_document, dd->policy, r->enc_rec_doc_size);
+  void *plaintext;
+  size_t size_plaintext;
+  json_t *recovery_document;
+  json_error_t json_error;
+  json_t *dec_policies = json_array ();
+  json_t *esc_methods = json_array ();
   r->response_code = http_status;
+
+  ANASTASIS_CRYPTO_recovery_document_decrypt (&r->id,
+                                              dd->policy,
+                                              dd->policy_size,
+                                              &plaintext,
+                                              &size_plaintext);
+  // FIXME COMPRESSION
+
+  recovery_document = json_loadb ((char *) plaintext,size_plaintext,
+                                  JSON_DECODE_ANY,&json_error);
+  GNUNET_assert (0 ==
+                 json_unpack (recovery_document,
+                              "{s:o,"   /* policies */
+                              " s:o,"   /* decryption policies */
+                              " s:o,"   /* encrypted core secret */
+                              "policies", dec_policies,
+                              "escrow_methods", esc_methods,
+                              "core_secret", r->enc_core_secret));
+
+  ri->cs_len = json_array_size (esc_methods);
+  ri->dps_len = json_array_size (dec_policies);
+  r->dps = GNUNET_new_array (ri->dps_len, struct ANASTASIS_DecryptionPolicy);
+  r->solved_challenges = GNUNET_new_array (ri->cs_len, struct
+                                           ANASTASIS_Challenge);
+  struct ANASTASIS_Challenge cs[ri->cs_len];
+
+  for (unsigned int i = 0; i < ri->cs_len; i++)
+  {
+    GNUNET_assert (0 ==
+                   json_unpack (json_array_get (esc_methods, i),
+                                "{s:o,"       /* truth uuid */
+                                " s:s,"       /* provider url */
+                                " s:o,"       /* truth key */
+                                " s:o,"       /* truth salt */
+                                " s:s}",       /* escrow method */
+                                "uuid", cs[i].challenge_uuid,
+                                "url", cs[i].url,
+                                "truth_key",cs[i].truth_key,
+                                "salt",cs[i].truth_salt,
+                                "escrow_method", cs[i].escrow_method));
+    cs[i].recovery = r;
+  }
+
+  for (unsigned int j = 0; j < ri->dps_len; j++ )
+  {
+    GNUNET_assert (0 ==
+                   json_unpack (json_array_get (dec_policies, j),
+                                "{s:o,"         /* encrypted master key */
+                                " s:o,"         /* policy uuids  */
+                                " s:i}",        /* policy uuids length */
+                                "master_key",r->dps[j].emk,
+                                "uuids",r->dps[j].escrow_uuids,
+                                "uuid_length", r->dps[j].uuids_length));
+  }
+  r->solved_challenge_pos = 0;
+  // SETUP POLICY CALLBACK
+  ri->dps = r->dps;
+  ri->cs = cs;
+  if (NULL != r->pc)
+  {
+    r->pc (r->pc_cls,
+           ri,
+           r->http_status);
+    r->pc = NULL;
+  }
   return;
 }
 
@@ -493,6 +577,7 @@ policy_lookup_cb (void *cls,
 * 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 ctx the CURL context used to connect to the backend
 * @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
@@ -503,7 +588,8 @@ policy_lookup_cb (void *cls,
 * @param csc_cls handle for the callback
 */
 struct ANASTASIS_Recovery *
-ANASTASIS_recovery_begin (const json_t *id_data,
+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_SaltP *salt,
@@ -514,16 +600,11 @@ ANASTASIS_recovery_begin (const json_t *id_data,
 {
   struct ANASTASIS_Recovery *r;
   r = GNUNET_new (struct ANASTASIS_Recovery);
-  struct ANASTASIS_RecoveryInformation *ri;
-  ri = GNUNET_new (struct ANASTASIS_RecoveryInformation);
   r->csc = csc;
   r->csc_cls = csc_cls;
-  void *plaintext;
-  size_t size_plaintext;
-  json_t *recovery_document;
-  json_error_t json_error;
-  json_t *dec_policies = json_array ();
-  json_t *esc_methods = json_array ();
+  r->pc = pc;
+  r->pc_cls = pc_cls;
+  r->ctx = ctx;
   r->http_status = MHD_HTTP_OK;
   ANASTASIS_CRYPTO_user_identifier_derive (id_data,
                                            salt,
@@ -547,77 +628,6 @@ ANASTASIS_recovery_begin (const json_t *id_data,
                                       &policy_lookup_cb,
                                       r);
   }
-
-
-
-  ANASTASIS_CRYPTO_recovery_document_decrypt (&r->id,
-                                              r->encrypted_recovery_document,
-                                              r->enc_rec_doc_size,
-                                              &plaintext,
-                                              &size_plaintext);
-
-  // FIXME COMPRESSION
-
-  recovery_document = json_loadb ((char *) plaintext,size_plaintext,
-                                  JSON_DECODE_ANY,&json_error);
-
-
-  GNUNET_assert (0 ==
-                 json_unpack (recovery_document,
-                              "{s:o," /* policies */
-                              " s:o," /* decryption policies */
-                              " s:o," /* encrypted core secret */
-                              "policies", dec_policies,
-                              "escrow_methods", esc_methods,
-                              "core_secret", r->enc_core_secret));
-
-  ri->cs_len = json_array_size (esc_methods);
-  ri->dps_len = json_array_size (dec_policies);
-  struct ANASTASIS_Challenge cs[ri->cs_len];
-  struct ANASTASIS_DecryptionPolicy dps[ri->dps_len];
-
-
-  for (unsigned int i = 0; i < ri->cs_len; i++)
-  {
-    GNUNET_assert (0 ==
-                   json_unpack (json_array_get (esc_methods, i),
-                                "{s:o,"   /* truth uuid */
-                                " s:s,"   /* provider url */
-                                " s:o,"   /* truth key */
-                                " s:o,"   /* truth salt */
-                                " s:s}",   /* escrow method */
-                                "uuid", cs[i].challenge_uuid,
-                                "url", cs[i].url,
-                                "truth_key",cs[i].truth_key,
-                                "salt",cs[i].truth_salt,
-                                "escrow_method", cs[i].escrow_method));
-    cs[i].recovery = r;
-  }
-
-  for (unsigned int j = 0; j < ri->dps_len; j++ )
-  {
-    GNUNET_assert (0 ==
-                   json_unpack (json_array_get (dec_policies, j),
-                                "{s:o,"     /* encrypted master key */
-                                " s:o,"     /* policy uuids  */
-                                " s:i}",    /* policy uuids length */
-                                "master_key",dps[j].emk,
-                                "uuids",dps[j].escrow_uuids,
-                                "uuid_length", dps[j].uuids_length));
-  }
-  r->solved_challenge_pos = 0;
-  // SETUP POLICY CALLBACK
-  ri->dps = dps;
-  ri->cs = cs;
-  r->pc = pc;
-  r->pc_cls = pc_cls;
-  if (NULL != r->pc)
-  {
-    r->pc (r->pc_cls,
-           ri,
-           r->http_status);
-    r->pc = NULL;
-  }
   return r;
 }
 
@@ -917,7 +927,7 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
   if (NULL == truth)
   {
     GNUNET_break (0);
-    return;
+    return tu;
   }
   tu->tso = ANASTASIS_truth_store (tu->ctx,
                                    t->url,

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



reply via email to

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