gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 06/08: work on truth upload


From: gnunet
Subject: [taler-anastasis] 06/08: work on truth upload
Date: Fri, 06 Nov 2020 18:06:31 +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 bc0225d64079f0423f76dbc0ce33612a6088ee61
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Nov 5 16:05:56 2020 +0100

    work on truth upload
---
 src/lib/anastasis_api_backup_redux.c | 118 ++++++++++++++++++++++++++++++++---
 1 file changed, 110 insertions(+), 8 deletions(-)

diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index ac31257..fcdf342 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -895,7 +895,6 @@ initialize_truths (json_t *state)
   GNUNET_assert (json_is_array (policy_json_array));
   json_array_foreach (policy_json_array, policy_index, policy)
   {
-    struct ANASTASIS_Truth *truths;
     size_t index;
     json_t *method;
     json_t *policy_methods = json_object_get (policy,
@@ -907,6 +906,7 @@ initialize_truths (json_t *state)
       const char *instructions;
       const char *mime_type;
       const char *backend_url;
+      const char *backend_salt;
       size_t provider_index;
       size_t check_index;
       json_t *check_truth;
@@ -937,6 +937,8 @@ initialize_truths (json_t *state)
         {
           backend_url = json_object_get (provider_data,
                                          "provider_url");
+          backend_salt = json_string_value (json_object_get (provider_data,
+                                                             "provider_salt"));
           break;
         }
       }
@@ -973,21 +975,22 @@ initialize_truths (json_t *state)
         return NULL;
       }
 
-      json_t *truth = json_pack ("{s:I, s:s, s:s, s:s, s:o, s:s, s:s}",
+      json_t *truth = json_pack ("{s:I, s:s, s:s, s:s, s:o, s:s, s:s, s:s}",
                                  "auth_method_index",
                                  (json_int_t) auth_method_index,
                                  "backend_url",
                                  backend_url,
                                  "backend_id",
                                  backend_id,
-                                 "method_type",
+                                 "method",
                                  method,
                                  "truth_data",
                                  truth_data,
                                  "instructions",
                                  instructions,
                                  "mime_type",
-                                 mime_type);
+                                 mime_type,
+                                 "backend_salt");
       // check if truths allready contains this truth
       bool existing = false;
       json_array_foreach (truths, check_index, check_truth)
@@ -1006,6 +1009,48 @@ initialize_truths (json_t *state)
 }
 
 
+/**
+* Upload information
+* caller MUST free 't' using ANASTASIS_truth_free()
+*
+* @param cls closure for callback
+* @param t Truth object (contains provider url and truth public key)
+*/
+static void
+truth_upload_cb (void *cls,
+                 struct ANASTASIS_Truth *t)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+
+  if (NULL == t)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  tus->truth = t;
+}
+
+
+/**
+ * Initiates a callback for the payment of the truth upload
+ *
+ * @param cls closure
+ * @param taler_pay_url payment link for the transaction (taler://pay/Foo)
+ * @param ec status code of the request
+ */
+static void
+truth_payment_cb (void *cls,
+                  const char *taler_pay_url,
+                  enum TALER_ErrorCode ec)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+  // FIXME: Payment handling
+  return;
+}
+
+
 /**
  * DispatchHandler/Callback function which is called for a
  * "enter_secret" action.
@@ -1053,11 +1098,68 @@ enter_secret (json_t *state,
     return NULL;
   }
   GNUNET_assert (0 ==
-                 json_object_set_new (state,
-                                      "core_secret",
-                                      arguments));
+                 json_object_set (state,
+                                  "core_secret",
+                                  arguments));
+  {
+    // upload truths
+    size_t truth_index;
+    json_t *truth;
+    json_t *truths = initialize_truths (state);
 
-  // initialize #ANASTASIS_Policy array
+    GNUNET_assert (json_is_array (truths));
+    json_array_foreach (truths, truth_index, truth)
+    {
+      struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
+      struct ANASTASIS_CRYPTO_PowSalt backend_salt;
+      struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
+      const char *backend_url = json_string_value (json_object_get (truth,
+                                                                    
"backend_url"));
+
+      tus->method = json_string_value (json_object_get (truth,
+                                                        "method"));
+      tus->instructions = json_string_value (json_object_get (truth,
+                                                              "instructions"));
+      tus->mime_type = json_string_value (json_object_get (truth,
+                                                           "mime_type"));
+      const char *salt_str = json_string_value (json_object_get (truth,
+                                                                 
"backen_salt"));
+      GNUNET_STRINGS_string_to_data (salt_str,
+                                     strlen (salt_str),
+                                     &backend_salt,
+                                     sizeof (struct ANASTASIS_CRYPTO_PowSalt));
+
+      tus->id_data = json_object_get (state,
+                                      "identity_attributes");
+
+      if (0 == strcmp ("question", tus->method))
+      {
+        json_t *truth_data = json_object_get (truth,
+                                              "truth_data");
+        // FIXME: hash secure question or salt into truth_data?
+        tus->truth_data = json_string_value (json_object_get (truth_data,
+                                                              "answer"));
+        tus->truth_data_size = strlen (tus->truth_data);
+      }
+      // FIXME: other method types
+
+      ANASTASIS_CRYPTO_user_identifier_derive (tus->id_data,
+                                               &backend_salt,
+                                               &user_id);
+      tus->tuo = ANASTASIS_truth_upload (ctx,
+                                         &user_id,
+                                         backend_url,
+                                         tus->method,
+                                         tus->mime_type,
+                                         &backend_salt,
+                                         tus->truth_data,
+                                         tus->truth_data_size,
+                                         &truth_payment_cb,
+                                         tus->tpc_cls,
+                                         &truth_upload_cb,
+                                         tus);
+    }
+  }
 
   // try uploading recovery document
   /*

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