gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 07/10: Worked on truth upload


From: gnunet
Subject: [taler-anastasis] 07/10: Worked on truth upload
Date: Wed, 15 Jan 2020 23:42: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 86e1c279a9278b25a7f4e2e9e26ccef98725b72e
Author: Dennis Neufeld <address@hidden>
AuthorDate: Mon Jan 6 15:58:09 2020 +0000

    Worked on truth upload
---
 src/backend/anastasis-httpd_truth.c        |   6 +-
 src/backend/anastasis-httpd_truth_upload.c |   5 ++
 src/include/anastasis_database_plugin.h    |   4 +
 src/include/anastasis_service.h            |  27 +++++++
 src/lib/anastasis_api_truth_store.c        | 122 ++++++++++++++---------------
 src/stasis/plugin_anastasis_postgres.c     |  22 ++++--
 src/stasis/test_anastasis_db.c             |  10 +++
 7 files changed, 124 insertions(+), 72 deletions(-)

diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 72bd840..dcf3cbd 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -64,8 +64,8 @@ AH_handler_truth_get (struct MHD_Connection *connection,
     uuid_parse (uuid_str, uuid);
 
     challenge_response_s = MHD_lookup_connection_value (connection,
-                                            MHD_GET_ARGUMENT_KIND,
-                                            "response");
+                                                        MHD_GET_ARGUMENT_KIND,
+                                                        "response");
   }
   {
     // check if header contains Truth-Decryption-Key
@@ -111,7 +111,7 @@ AH_handler_truth_get (struct MHD_Connection *connection,
 
     if (NULL == challenge_response_s)
     {
-      //FIXME: Return escrow challenge
+      // FIXME: Return escrow challenge
     }
   }
   {
diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index fc6c48c..9c84661 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -51,6 +51,7 @@ verify_and_execute_truth (struct MHD_Connection *connection,
                         truth->encrypted_truth,
                         sizeof (&truth->encrypted_truth),
                         &truth->aes_gcm_tag,
+                        &truth->truth_hash,
                         &truth->nonce,
                         truth->method,
                         AH_truth_expiration);
@@ -85,6 +86,9 @@ AH_handler_truth_post (struct MHD_Connection *connection,
 
     uuid_str = &url[strlen ("/truth/")];
     uuid_parse (uuid_str, uuid);
+  }
+  {
+
   }
   {
     struct GNUNET_JSON_Specification spec[] = {
@@ -92,6 +96,7 @@ AH_handler_truth_post (struct MHD_Connection *connection,
       GNUNET_JSON_spec_string ("method", &truth.method),
       GNUNET_JSON_spec_uint32 ("nonce", &truth.nonce),
       GNUNET_JSON_spec_fixed_auto ("aes_gcm_tag", &truth.aes_gcm_tag),
+      GNUNET_JSON_spec_fixed_auto ("truth_hash", &truth.truth_hash),
       GNUNET_JSON_spec_fixed_auto ("encrypted_truth", &truth.encrypted_truth),
       GNUNET_JSON_spec_string ("truth_mime", &truth.truth_mime),
       GNUNET_JSON_spec_end ()
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 83ce138..f2798d7 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -41,6 +41,8 @@ struct ANASTASIS_DB_Truth
   // AES_GCM_Tag
   const unsigned char aes_gcm_tag[16];
 
+  const struct GNUNET_HashCode *truth_hash;
+
   const void *encrypted_truth;
 
   const char *truth_mime;
@@ -258,6 +260,8 @@ struct ANASTASIS_DatabasePlugin
                  const char *mime_type,
                  const void *encrypted_truth,
                  size_t encrypted_truth_size,
+                 const struct
+                 GNUNET_HashCode *truth_data_hash,
                  const unsigned char aes_gcm_tag[16],
                  const uint32_t *nonce,
                  const char *method,
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 530b317..6dc8477 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -262,6 +262,8 @@ void
 ANASTASIS_salt_cancel (struct ANASTASIS_SaltOperation *so);
 
 
+/****** POLICY API ******/
+
 /**
  * Handle for a GET /policy operation.
  */
@@ -391,4 +393,29 @@ ANASTASIS_policy_store_cancel (struct
                                ANASTASIS_PolicyStoreOperation *pso);
 
 
+
+
+/****** TRUTH API ******/
+
+/**
+ * Handle for a POST /policy operation.
+ */
+struct ANASTASIS_TruthStoreOperation;
+
+
+/**
+ * Callback to process a POST /policy request
+ *
+ * @param cls closure
+ * @param http_status HTTP status code for this request
+ * @param ec anastasis-specific error code
+ * @param obj the response body
+ */
+typedef void
+(*ANASTASIS_TruthStoreCallback) (void *cls,
+                                 enum ANASTASIS_ErrorCode ec,
+                                 unsigned int http_status,
+                                 const struct ANASTASIS_UploadDetails *up);
+
+
 #endif  /* _ANASTASIS_SERVICE_H */
diff --git a/src/lib/anastasis_api_truth_store.c 
b/src/lib/anastasis_api_truth_store.c
index b66798d..e19951b 100644
--- a/src/lib/anastasis_api_truth_store.c
+++ b/src/lib/anastasis_api_truth_store.c
@@ -18,8 +18,8 @@
 */
 
 /**
- * @file lib/anastasis_api_policy_store.c
- * @brief Implementation of the /policy GET and POST
+ * @file lib/anastasis_api_truth_store.c
+ * @brief Implementation of the /truth GET and POST
  * @author Christian Grothoff
  * @author Dennis Neufeld
  * @author Dominik Meister
@@ -73,31 +73,31 @@ struct ANASTASIS_TruthStoreOperation
   /**
    * Hash of the data we are uploading.
    */
-  struct GNUNET_HashCode new_recovery_data_hash;
+  struct GNUNET_HashCode new_truth_data_hash;
 };
 
 /**
- * Cancel a POST /policy request.
+ * Cancel a POST /truth request.
  *
- * @param pso the policy store operation to cancel
+ * @param tso the truth store operation to cancel
  */
 void
-ANASTASIS_policy_store_cancel (struct
-                               ANASTASIS_TruthStoreOperation *pso)
+ANASTASIS_truth_store_cancel (struct
+                               ANASTASIS_TruthStoreOperation *tso)
 {
-  if (NULL != pso->job)
+  if (NULL != tso->job)
   {
-    GNUNET_CURL_job_cancel (pso->job);
-    pso->job = NULL;
+    GNUNET_CURL_job_cancel (tso->job);
+    tso->job = NULL;
   }
-  GNUNET_free_non_null (pso->pay_uri);
-  GNUNET_free (pso->url);
-  GNUNET_free (pso);
+  GNUNET_free_non_null (tso->pay_uri);
+  GNUNET_free (tso->url);
+  GNUNET_free (tso);
 }
 
 
 /**
- * Callback to process POST /policy response
+ * Callback to process POST /truth response
  *
  * @param cls the `struct ANASTASIS_TruthStoreOperation`
  * @param response_code HTTP response code, 0 on error
@@ -105,17 +105,17 @@ ANASTASIS_policy_store_cancel (struct
  * @param data_size
  */
 static void
-handle_policy_store_finished (void *cls,
+handle_truth_store_finished (void *cls,
                               long response_code,
                               const void *data,
                               size_t data_size)
 {
-  struct ANASTASIS_TruthStoreOperation *pso = cls;
+  struct ANASTASIS_TruthStoreOperation *tso = cls;
   enum TALER_ErrorCode ec = TALER_EC_INVALID;
   struct ANASTASIS_UploadDetails ud;
   struct ANASTASIS_UploadDetails *udp;
 
-  pso->job = NULL;
+  tso->job = NULL;
   udp = NULL;
   memset (&ud, 0, sizeof (ud));
   switch (response_code)
@@ -124,13 +124,13 @@ handle_policy_store_finished (void *cls,
     break;
   case MHD_HTTP_NO_CONTENT:
     ud.us = ANASTASIS_US_SUCCESS;
-    ud.details.curr_backup_hash = &pso->new_recovery_data_hash;
+    ud.details.curr_backup_hash = &tso->new_truth_data_hash;
     udp = &ud;
     ec = TALER_EC_NONE;
     break;
   case MHD_HTTP_NOT_MODIFIED:
     ud.us = ANASTASIS_US_SUCCESS;
-    ud.details.curr_backup_hash = &pso->new_recovery_data_hash;
+    ud.details.curr_backup_hash = &tso->new_truth_data_hash;
     udp = &ud;
     ec = TALER_EC_NONE;
     break;
@@ -141,7 +141,7 @@ handle_policy_store_finished (void *cls,
     break;
   case MHD_HTTP_PAYMENT_REQUIRED:
     ud.us = ANASTASIS_US_PAYMENT_REQUIRED;
-    ud.details.payment_request = pso->pay_uri;
+    ud.details.payment_request = tso->pay_uri;
     udp = &ud;
     ec = TALER_EC_NONE;
     break;
@@ -178,15 +178,15 @@ handle_policy_store_finished (void *cls,
                                      data_size);
     break;
   }
-  if (NULL != pso->cb)
+  if (NULL != tso->cb)
   {
-    pso->cb (pso->cb_cls,
+    tso->cb (tso->cb_cls,
              ec,
              response_code,
              udp);
-    pso->cb = NULL;
+    tso->cb = NULL;
   }
-  ANASTASIS_policy_store_cancel (pso);
+  ANASTASIS_truth_store_cancel (tso);
 }
 
 
@@ -205,7 +205,7 @@ handle_header (char *buffer,
                size_t nitems,
                void *userdata)
 {
-  struct ANASTASIS_TruthStoreOperation *pso = userdata;
+  struct ANASTASIS_TruthStoreOperation *tso = userdata;
   size_t total = size * nitems;
   char *ndup;
   const char *hdr_type;
@@ -233,7 +233,7 @@ handle_header (char *buffer,
                        "Taler"))
   {
     /* found payment URI we care about! */
-    pso->pay_uri = GNUNET_strdup (hdr_val);
+    tso->pay_uri = GNUNET_strdup (hdr_val);
   }
   GNUNET_free (ndup);
   return total;
@@ -241,50 +241,50 @@ handle_header (char *buffer,
 
 
 /**
- * Store policies, does a POST /policy/$AccountPub
+ * Store policies, does a POST /truth/$AccountPub
  *
  * @param ctx the CURL context used to connect to the backend
  * @param backend_url backend's base URL, including final "/"
  * @param anastasis_pub public key of the user's account
  * @param anastasis_priv private key of the user's account
- * @param prev_recovery_data_hash hash of the previous uploaded recovery 
document
- * @param recovery_data policy data to be stored
- * @param recovery_data_size number of bytes in @a recovery_data
+ * @param prev_truth_data_hash hash of the previous uploaded truth document
+ * @param truth_data truth data to be stored
+ * @param truth_data_size number of bytes in @a truth_data
  * @param payment_requested #GNUNET_YES if the client wants to pay more for 
the account now
  * @param paymentSecretP payment identifier of last payment
- * @param cb callback processing the response from /policy
+ * @param cb callback processing the response from /truth
  * @param cb_cls closure for cb
  * @return handle for the operation
  */
 struct ANASTASIS_TruthStoreOperation *
-ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
+ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
                         const char *backend_url,
                         const struct
                         ANASTASIS_AccountPrivP *anastasis_priv,
                         const struct
-                        GNUNET_HashCode *prev_recovery_data_hash,
-                        const void *recovery_data,
-                        size_t recovery_data_size,
+                        GNUNET_HashCode *prev_truth_data_hash,
+                        const void *truth_data,
+                        size_t truth_data_size,
                         int payment_requested,
                         const struct
                         ANASTASIS_PaymentSecretP *paymentSecretP,
                         ANASTASIS_TruthStoreCallback cb,
                         void *cb_cls)
 {
-  struct ANASTASIS_TruthStoreOperation *pso;
+  struct ANASTASIS_TruthStoreOperation *tso;
   struct ANASTASIS_AccountSignatureP account_sig;
   struct ANASTASIS_UploadSignaturePS usp;
   CURL *eh;
   struct curl_slist *job_headers;
 
   memset (&usp, 0, sizeof (usp));
-  usp.purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD);
+  usp.purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_TRUTH_UPLOAD);
   usp.purpose.size = htonl (sizeof (usp));
-  if (NULL != prev_recovery_data_hash)
-    usp.old_recovery_data_hash = *prev_recovery_data_hash;
-  GNUNET_CRYPTO_hash (recovery_data,
-                      recovery_data_size,
-                      &usp.new_recovery_data_hash);
+  if (NULL != prev_truth_data_hash)
+    usp.old_truth_data_hash = *prev_truth_data_hash;
+  GNUNET_CRYPTO_hash (truth_data,
+                      truth_data_size,
+                      &usp.new_truth_data_hash);
   if (GNUNET_OK !=
       GNUNET_CRYPTO_eddsa_sign (&anastasis_priv->priv,
                                 &usp.purpose,
@@ -304,7 +304,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
     val = GNUNET_STRINGS_data_to_string_alloc (&account_sig,
                                                sizeof (account_sig));
     GNUNET_asprintf (&hdr,
-                     "Anastasis-Policy-Signature: %s",
+                     "Anastasis-Truth-Signature: %s",
                      val);
     GNUNET_free (val);
     ext = curl_slist_append (job_headers,
@@ -319,7 +319,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
     job_headers = ext;
 
     /* set Etag header */
-    val = GNUNET_STRINGS_data_to_string_alloc (&usp.new_recovery_data_hash,
+    val = GNUNET_STRINGS_data_to_string_alloc (&usp.new_truth_data_hash,
                                                sizeof (struct 
GNUNET_HashCode));
     GNUNET_asprintf (&hdr,
                      "Etag: %s",
@@ -337,9 +337,9 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
     job_headers = ext;
 
     /* Setup If-Match header */
-    if (NULL != prev_recovery_data_hash)
+    if (NULL != prev_truth_data_hash)
     {
-      val = GNUNET_STRINGS_data_to_string_alloc (&usp.old_recovery_data_hash,
+      val = GNUNET_STRINGS_data_to_string_alloc (&usp.old_truth_data_hash,
                                                  sizeof (struct
                                                          GNUNET_HashCode));
       GNUNET_asprintf (&hdr,
@@ -381,8 +381,8 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
   }
   /* Finished setting up headers */
 
-  pso = GNUNET_new (struct ANASTASIS_TruthStoreOperation);
-  pso->new_recovery_data_hash = usp.new_recovery_data_hash;
+  tso = GNUNET_new (struct ANASTASIS_TruthStoreOperation);
+  tso->new_truth_data_hash = usp.new_truth_data_hash;
   {
     char *acc_pub_str;
     char *path;
@@ -394,25 +394,25 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
     acc_pub_str = GNUNET_STRINGS_data_to_string_alloc (&pub,
                                                        sizeof (pub));
     GNUNET_asprintf (&path,
-                     "policy/%s",
+                     "truth/%s",
                      acc_pub_str);
     GNUNET_free (acc_pub_str);
-    pso->url = TALER_url_join (backend_url,
+    tso->url = TALER_url_join (backend_url,
                                path);
     GNUNET_free (path);
   }
-  pso->ctx = ctx;
-  pso->cb = cb;
-  pso->cb_cls = cb_cls;
-  eh = ANASTASIS_curl_easy_get_ (pso->url);
+  tso->ctx = ctx;
+  tso->cb = cb;
+  tso->cb_cls = cb_cls;
+  eh = ANASTASIS_curl_easy_get_ (tso->url);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDS,
-                                   recovery_data));
+                                   truth_data));
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_POSTFIELDSIZE,
-                                   (long) recovery_data_size));
+                                   (long) truth_data_size));
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_HEADERFUNCTION,
@@ -420,12 +420,12 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_HEADERDATA,
-                                   pso));
-  pso->job = GNUNET_CURL_job_add_raw (ctx,
+                                   tso));
+  tso->job = GNUNET_CURL_job_add_raw (ctx,
                                       eh,
                                       job_headers,
-                                      &handle_policy_store_finished,
-                                      pso);
+                                      &handle_truth_store_finished,
+                                      tso);
   curl_slist_free_all (job_headers);
-  return pso;
+  return tso;
 }
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 6462859..65029d1 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -730,6 +730,8 @@ postgres_store_truth (void *cls,
                       const char *mime_type,
                       const void *encrypted_truth,
                       size_t encrypted_truth_size,
+                      const struct
+                      GNUNET_HashCode *truth_data_hash,
                       const unsigned char aes_gcm_tag[16],
                       const uint32_t *nonce,
                       const char *method,
@@ -759,6 +761,7 @@ postgres_store_truth (void *cls,
       GNUNET_PQ_query_param_string (method),
       GNUNET_PQ_query_param_auto_from_type (nonce),
       GNUNET_PQ_query_param_auto_from_type (aes_gcm_tag),
+      GNUNET_PQ_query_param_auto_from_type (truth_data_hash),
       GNUNET_PQ_query_param_fixed_size (encrypted_truth,
                                         encrypted_truth_size),
       GNUNET_PQ_query_param_string (mime_type),
@@ -1065,13 +1068,14 @@ libanastasis_plugin_db_postgres_init (void *cls)
        contract terms table */
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS anastasis_truth"
                             "( truth_id UUID PRIMARY KEY NOT NULL,"
-                            "key_share_data BYTEA NOT NULL,"
-                            "method VARCHAR,"
-                            "nonce BYTEA NOT NULL,"
-                            "aes_gcm_tag BYTEA NOT NULL,"
-                            "encrypted_truth BYTEA NOT NULL,"
-                            "truth_mime VARCHAR,"
-                            "expiration TIMESTAMP NOT NULL"
+                            " key_share_data BYTEA NOT NULL,"
+                            " method VARCHAR,"
+                            " nonce BYTEA NOT NULL,"
+                            " aes_gcm_tag BYTEA NOT NULL,"
+                            " encrypted_truth BYTEA NOT NULL,"
+                            " truth_hash BYTEA NOT NULL 
CHECK(length(truth_hash)=64),"
+                            " truth_mime VARCHAR,"
+                            " expiration TIMESTAMP NOT NULL"
                             ");"),
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS anastasis_user"
                             "( user_id BYTEA PRIMARY KEY 
CHECK(LENGTH(user_id)=32),"
@@ -1135,11 +1139,12 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             ",method"
                             ",nonce"
                             ",aes_gcm_tag"
+                            ",truth_hash"
                             ",encrypted_truth"
                             ",truth_mime"
                             ",expiration"
                             ") VALUES "
-                            "($1, $2, $3, $4, $5, $6, $7, $8);",
+                            "($1, $2, $3, $4, $5, $6, $7, $8, $9);",
                             7),
     GNUNET_PQ_make_prepare ("recovery_document_insert",
                             "INSERT INTO anastasis_recoverydocument "
@@ -1158,6 +1163,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             ",method"
                             ",nonce"
                             ",aes_gcm_tag"
+                            ",truth_hash"
                             ",encrypted_truth"
                             ",truth_mime"
                             ",expiration"
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index b0d6664..b8730ee 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -81,6 +81,11 @@ struct ANASTASIS_AccountSignatureP res_account_sig;
  */
 struct GNUNET_HashCode recoveryDataHash;
 
+/**
+ * Hash of the truth to be uploaded
+ */
+struct GNUNET_HashCode truthDataHash;
+
 /**
  * Hash of the current recovery document
  */
@@ -203,6 +208,10 @@ run (void *cls)
                       sizeof (recovery_data),
                       &recoveryDataHash);
 
+   GNUNET_CRYPTO_hash ("key_share_data",
+                      sizeof ("key_share_data"),
+                      &truthDataHash);
+
   purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
   purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
   GNUNET_CRYPTO_eddsa_sign (&accountPrivP.priv,
@@ -260,6 +269,7 @@ run (void *cls)
                                mime_type,
                                "encrypted_truth",
                                sizeof ("encrypted_truth"),
+                               &truthDataHash,
                                aes_gcm_tag,
                                &nonce,
                                "Methode",

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



reply via email to

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