gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 08/15: nonces use json array


From: gnunet
Subject: [taler-anastasis] 08/15: nonces use json array
Date: Sun, 31 Jan 2021 17:06:14 +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 3abff00e81b78e3f3a6dac0ac7d83358fa6aad26
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Jan 19 16:42:12 2021 +0100

    nonces use json array
---
 src/lib/anastasis.c           | 90 +++++++++++++++++++++++++++----------------
 src/lib/anastasis_api_redux.c | 21 ++++++++--
 2 files changed, 73 insertions(+), 38 deletions(-)

diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 79e3520..5ebc080 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -815,19 +815,25 @@ policy_lookup_cb (void *cls,
 
   for (unsigned int j = 0; j < r->ri->dps_len; j++)
   {
-    const char *nonces;
+    // const char *nonces;
+    size_t n_index;
+    json_t *nonces;
+    json_t *nonce;
 
     struct GNUNET_JSON_Specification spec[] = {
       GNUNET_JSON_spec_fixed_auto ("master_key",
                                    &r->ri->dps[j].emk),
-      GNUNET_JSON_spec_string ("nonces",
-                               &nonces),
+      // GNUNET_JSON_spec_string ("nonces",
+      //                          &nonces),
       GNUNET_JSON_spec_fixed_auto ("salt",
                                    &r->ri->dps[j].salt),
       GNUNET_JSON_spec_uint32 ("nonces_length",
                                &r->ri->dps[j].nonces_length),
       GNUNET_JSON_spec_end ()
     };
+    nonces = json_object_get (json_array_get (dec_policies, j),
+                              "nonces");
+    GNUNET_assert (json_is_array (nonces));
 
     if (GNUNET_OK !=
         GNUNET_JSON_parse (json_array_get (dec_policies, j),
@@ -843,25 +849,38 @@ policy_lookup_cb (void *cls,
     r->ri->dps[j].nonces = GNUNET_new_array (r->ri->dps[j].nonces_length,
                                              struct ANASTASIS_CRYPTO_NonceP);
 
-    for (int a = 0; a < r->ri->dps[j].nonces_length; a++)
+    json_array_foreach (nonces, n_index, nonce)
     {
-      char buf[52];
-
-      GNUNET_strlcpy (buf,
-                      nonces + a * 51,
-                      52);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "At %s:%d buf is %s\n", __FILE__, __LINE__,
-                  buf);
-      GNUNET_STRINGS_string_to_data (buf,
-                                     sizeof (buf),
-                                     &r->ri->dps[j].nonces[a],
+      const char *nonce_str = json_string_value (nonce);
+      GNUNET_STRINGS_string_to_data (nonce_str,
+                                     strlen (nonce_str),
+                                     &r->ri->dps[j].nonces[n_index],
                                      sizeof (struct ANASTASIS_CRYPTO_NonceP));
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "At %s:%d escrow nonce is %s-%llu b\n", __FILE__, __LINE__,
-                  TALER_B2S (&r->ri->dps[j].nonces[a]),
-                  (unsigned long long) sizeof (r->ri->dps[j].nonces[a]));
+                  TALER_B2S (&r->ri->dps[j].nonces[n_index]),
+                  (unsigned long long) sizeof (r->ri->dps[j].nonces[n_index]));
     }
+    // for (int a = 0; a < r->ri->dps[j].nonces_length; a++)
+    // {
+
+    //   char buf[53];
+
+    //   GNUNET_strlcpy (buf,
+    //                   nonces + a * 52,
+    //                   52);
+    //   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    //               "At %s:%d buf is %s\n", __FILE__, __LINE__,
+    //               buf);
+    //   GNUNET_STRINGS_string_to_data (buf,
+    //                                  sizeof (buf),
+    //                                  &r->ri->dps[j].nonces[a],
+    //                                  sizeof (struct 
ANASTASIS_CRYPTO_NonceP));
+    //   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    //               "At %s:%d escrow nonce is %s-%llu b\n", __FILE__, 
__LINE__,
+    //               TALER_B2S (&r->ri->dps[j].nonces[a]),
+    //               (unsigned long long) sizeof (r->ri->dps[j].nonces[a]));
+    // }
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "At %s:%d encrypted master key is %s-%llu b\n", __FILE__,
@@ -1982,31 +2001,34 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     // simply append  GNUNET_JSON_from_data_auto(&policy->nonces[b]) to
     // that array, keep the JSON structured!
 
-    char nonces[52 * policy->nonces_length + 1];
+    // char nonces[52 * policy->nonces_length + 1];
+    json_t *nonces = json_array ();
     for (unsigned int b = 0; b < policy->nonces_length; b++)
     {
-      char *nonce_str;
-      nonce_str = GNUNET_STRINGS_data_to_string_alloc (&policy->nonces[b],
-                                                       sizeof (policy->
-                                                               nonces[b]));
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "nonce is:  %s\n",
-                  nonce_str);
-      GNUNET_strlcpy (nonces + b * strlen (nonce_str),
-                      nonce_str,
-                      strlen (nonce_str));
-      GNUNET_free (nonce_str);
+      json_array_append (nonces,
+                         GNUNET_JSON_from_data_auto (&policy->nonces[b]));
+      // char *nonce_str;
+      // nonce_str = GNUNET_STRINGS_data_to_string_alloc (&policy->nonces[b],
+      //                                                  sizeof (policy->
+      //                                                          nonces[b]));
+      // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+      //             "nonce is:  %s\n",
+      //             nonce_str);
+      // GNUNET_strlcpy (nonces + b * strlen (nonce_str),
+      //                 nonce_str,
+      //                 strlen (nonce_str));
+      // GNUNET_free (nonce_str);
     }
 
-    nonces[52 * policy->nonces_length] = '\0';
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "At %s:%d nonces are %s b\n", __FILE__, __LINE__,
-                nonces);
+    // nonces[52 * policy->nonces_length] = '\0';
+    // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    //             "At %s:%d nonces are %s b\n", __FILE__, __LINE__,
+    //             nonces);
     if (0 !=
         json_array_append_new (
           dec_policies,
           json_pack ("{s:o,"   /* encrypted master key */
-                     " s:s,"   /* policy nonces  */
+                     " s:o,"   /* policy nonces  */
                      " s:o,"   /* policy salt  */
                      " s:i}",  /* policy nonces length */
                      "master_key",
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index bc528be..0f3f01d 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -1010,16 +1010,29 @@ policy_lookup_cb (void *cls,
           ANASTASIS_challenge_information_to_json (ci)));
     }
   }
-  for (unsigned int i = 0; i < rss->ri->dps_len; i++)
+  for (unsigned int i = 0; i < ri->dps_len; i++)
   {
     json_t *policy = json_array ();
     GNUNET_assert (json_is_array (policy));
-    for (unsigned int j = 0; j < rss->ri->dps[i].nonces_length; j++)
+    for (unsigned int j = 0; j < ri->dps[i].nonces_length; j++)
     {
       for (unsigned int k = 0; k < rss->challenges_length; k++)
       {
-        if (0 == memcmp (&rss->ri->dps[i].nonces[j],
-                         &rss->challenges[k].nonce,
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "At %s:%d nonce 1 is %s-%llu b\n",
+                    __FILE__,
+                    __LINE__,
+                    TALER_B2S (&ri->dps[i].nonces[j]),
+                    (unsigned long long) sizeof (ri->dps[i].nonces[j]));
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "At %s:%d nonce 2 is %s-%llu b\n\n",
+                    __FILE__,
+                    __LINE__,
+                    TALER_B2S (rss->challenges[k].nonce),
+                    (unsigned long long) sizeof (*rss->challenges[k].nonce));
+
+        if (0 == memcmp (&ri->dps[i].nonces[j],
+                         rss->challenges[k].nonce,
                          sizeof (struct ANASTASIS_CRYPTO_NonceP)))
           GNUNET_assert (
             0 == json_array_append (policy,

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