gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix tpk parsing logic


From: gnunet
Subject: [taler-anastasis] branch master updated: fix tpk parsing logic
Date: Tue, 09 Feb 2021 15:47:49 +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 7afbc2f  fix tpk parsing logic
7afbc2f is described below

commit 7afbc2f6ddcba2ee3385b2c6d9ffd58835263d4b
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Feb 9 15:47:47 2021 +0100

    fix tpk parsing logic
---
 src/backend/anastasis-httpd.c              |  21 ++++-
 src/backend/anastasis-httpd_truth.c        |  26 ++----
 src/backend/anastasis-httpd_truth.h        |  22 ++---
 src/backend/anastasis-httpd_truth_upload.c | 140 +++++++++++++----------------
 4 files changed, 99 insertions(+), 110 deletions(-)

diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 7a97780..883c4bd 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -369,11 +369,28 @@ url_handler (void *cls,
                     "/truth/",
                     strlen ("/truth/")))
   {
+    struct ANASTASIS_CRYPTO_TruthPublicKeyP tpk;
+    const char *pub_key_str;
+
+    pub_key_str = &url[strlen ("/truth/")];
+    if (GNUNET_OK !=
+        GNUNET_STRINGS_string_to_data (
+          pub_key_str,
+          strlen (pub_key_str),
+          &tpk,
+          sizeof(tpk)))
+    {
+      GNUNET_break_op (0);
+      return TALER_MHD_reply_with_error (connection,
+                                         MHD_HTTP_BAD_REQUEST,
+                                         TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                         "truth public key");
+    }
     if (0 == strcmp (method,
                      MHD_HTTP_METHOD_GET))
     {
       return AH_handler_truth_get (connection,
-                                   url,
+                                   &tpk,
                                    hc);
     }
     if (0 == strcmp (method,
@@ -381,7 +398,7 @@ url_handler (void *cls,
     {
       return AH_handler_truth_post (connection,
                                     hc,
-                                    url + strlen ("/truth/"),
+                                    &tpk,
                                     upload_data,
                                     upload_data_size);
     }
diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 6bceec7..dd89522 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -519,9 +519,10 @@ return_key_share (
  * @return MHD result code
  */
 MHD_RESULT
-AH_handler_truth_get (struct MHD_Connection *connection,
-                      const char *url,
-                      struct TM_HandlerContext *hc)
+AH_handler_truth_get (
+  struct MHD_Connection *connection,
+  const struct ANASTASIS_CRYPTO_TruthPublicKeyP *truth_public_key,
+  struct TM_HandlerContext *hc)
 {
   struct GetContext *gc = hc->ctx;
   struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
@@ -604,6 +605,7 @@ AH_handler_truth_get (struct MHD_Connection *connection,
   gc->hc = hc;
   hc->ctx = gc;
   gc->connection = connection;
+  gc->truth_public_key = *truth_public_key;
 
   {
     const char *pay_id;
@@ -629,24 +631,6 @@ AH_handler_truth_get (struct MHD_Connection *connection,
       gc->payment_identifier_provided = true;
     }
   }
-  {
-    const char *pub_key_str;
-
-    pub_key_str = &url[strlen ("/truth/")];
-    if (GNUNET_OK !=
-        GNUNET_STRINGS_string_to_data (
-          pub_key_str,
-          strlen (pub_key_str),
-          &gc->truth_public_key,
-          sizeof(struct ANASTASIS_CRYPTO_TruthPublicKeyP)))
-    {
-      GNUNET_break_op (0);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                         "truth public key");
-    }
-  }
 
   {
     /* check if header contains Truth-Decryption-Key */
diff --git a/src/backend/anastasis-httpd_truth.h 
b/src/backend/anastasis-httpd_truth.h
index c34c268..0ad4d8e 100644
--- a/src/backend/anastasis-httpd_truth.h
+++ b/src/backend/anastasis-httpd_truth.h
@@ -30,28 +30,30 @@ AH_truth_shutdown (void);
 
 /**
  * @param connection the MHD connection to handle
- * @param url handles a URL of the format 
"/truth/$TRUTH_PUBLIC_KEY[&response=$RESPONSE]"
+ * @param truth_public_key the truth public key
  * @param con_cls
  * @return MHD result code
  */
 MHD_RESULT
-AH_handler_truth_get (struct MHD_Connection *connection,
-                      const char *url,
-                      struct TM_HandlerContext *hc);
+AH_handler_truth_get (
+  struct MHD_Connection *connection,
+  const struct ANASTASIS_CRYPTO_TruthPublicKeyP *truth_public_key,
+  struct TM_HandlerContext *hc);
 
 /**
  * @param connection the MHD connection to handle
  * @param con_cls the connection's closure
- * @param pub_key_str base32 encoded truth public key
+ * @param truth_public_key the truth public key
  * @param truth_data truth data
  * @param truth_data_size number of bytes (left) in @a truth_data
  * @return MHD result code
  */
 int
-AH_handler_truth_post (struct MHD_Connection *connection,
-                       struct TM_HandlerContext *hc,
-                       const char *pub_key_str,
-                       const char *truth_data,
-                       size_t *truth_data_size);
+AH_handler_truth_post (
+  struct MHD_Connection *connection,
+  struct TM_HandlerContext *hc,
+  const struct ANASTASIS_CRYPTO_TruthPublicKeyP *truth_public_key,
+  const char *truth_data,
+  size_t *truth_data_size);
 
 #endif
diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index d231aac..52e65cd 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -47,91 +47,77 @@ cleanup_parse_post_json (struct TM_HandlerContext *hc)
  * @return MHD result code
  */
 int
-AH_handler_truth_post (struct MHD_Connection *connection,
-                       struct TM_HandlerContext *hc,
-                       const char *pub_key_str,
-                       const char *truth_data,
-                       size_t *truth_data_size)
+AH_handler_truth_post (
+  struct MHD_Connection *connection,
+  struct TM_HandlerContext *hc,
+  const struct ANASTASIS_CRYPTO_TruthPublicKeyP *truth_public_key,
+  const char *truth_data,
+  size_t *truth_data_size)
 {
   json_t *json;
   MHD_RESULT ret;
-  struct ANASTASIS_CRYPTO_TruthPublicKeyP truth_public_key;
   int res;
   struct ANASTASIS_DB_Truth truth;
   enum GNUNET_DB_QueryStatus qs;
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_fixed_auto ("keyshare_data", &truth.keyshare_data),
+    GNUNET_JSON_spec_string ("method", &truth.method),
+    GNUNET_JSON_spec_varsize ("encrypted_truth", &truth.encrypted_truth,
+                              &truth.encrypted_truth_size),
+    GNUNET_JSON_spec_string ("truth_mime", &truth.truth_mime),
+    GNUNET_JSON_spec_end ()
+  };
 
-  /* extract public key from url */
-  {
-    GNUNET_STRINGS_string_to_data (pub_key_str,
-                                   strlen (pub_key_str),
-                                   &truth_public_key,
-                                   sizeof(struct
-                                          ANASTASIS_CRYPTO_TruthPublicKeyP));
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "public key from Url: %s\n",
-                pub_key_str);
-  }
-  {
-    struct GNUNET_JSON_Specification spec[] = {
-      GNUNET_JSON_spec_fixed_auto ("keyshare_data", &truth.keyshare_data),
-      GNUNET_JSON_spec_string ("method", &truth.method),
-      GNUNET_JSON_spec_varsize ("encrypted_truth", &truth.encrypted_truth,
-                                &truth.encrypted_truth_size),
-      GNUNET_JSON_spec_string ("truth_mime", &truth.truth_mime),
-      GNUNET_JSON_spec_end ()
-    };
+  hc->cc = &cleanup_parse_post_json;
+  res = TALER_MHD_parse_post_json (connection,
+                                   &hc->ctx,
+                                   truth_data,
+                                   truth_data_size,
+                                   &json);
+  if (GNUNET_SYSERR == res)
+    return MHD_NO;
+  if ( (GNUNET_NO == res) ||
+       (NULL == json) )
+    return MHD_YES;
+  res = TALER_MHD_parse_json_data (connection,
+                                   json,
+                                   spec);
 
-    hc->cc = &cleanup_parse_post_json;
-    res = TALER_MHD_parse_post_json (connection,
-                                     &hc->ctx,
-                                     truth_data,
-                                     truth_data_size,
-                                     &json);
-    if (GNUNET_SYSERR == res)
-      return MHD_NO;
-    if ( (GNUNET_NO == res) ||
-         (NULL == json) )
-      return MHD_YES;
-    res = TALER_MHD_parse_json_data (connection,
-                                     json,
-                                     spec);
-
-    if (GNUNET_SYSERR == res)
-      return MHD_NO; /* hard failure */
-    if (GNUNET_NO == res)
-      return MHD_YES; /* failure */
-    qs = db->store_truth (db->cls,
-                          &truth_public_key,
-                          &truth.keyshare_data,
-                          truth.truth_mime,
-                          truth.encrypted_truth,
-                          truth.encrypted_truth_size,
-                          truth.method,
-                          AH_truth_expiration);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Store truth db status: %i\n",
-                qs);
-    json_decref (json);
-    GNUNET_JSON_parse_free (spec);
-    if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
-    {
-      struct MHD_Response *resp;
+  if (GNUNET_SYSERR == res)
+    return MHD_NO;   /* hard failure */
+  if (GNUNET_NO == res)
+    return MHD_YES;   /* failure */
+  qs = db->store_truth (db->cls,
+                        truth_public_key,
+                        &truth.keyshare_data,
+                        truth.truth_mime,
+                        truth.encrypted_truth,
+                        truth.encrypted_truth_size,
+                        truth.method,
+                        AH_truth_expiration);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Store truth db status: %i\n",
+              qs);
+  json_decref (json);
+  GNUNET_JSON_parse_free (spec);
+  if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+  {
+    struct MHD_Response *resp;
 
-      resp = MHD_create_response_from_buffer (0,
-                                              NULL,
-                                              MHD_RESPMEM_PERSISTENT);
-      TALER_MHD_add_global_headers (resp);
-      ret = MHD_queue_response (connection,
-                                MHD_HTTP_NO_CONTENT,
-                                resp);
-      MHD_destroy_response (resp);
-      return ret;
-    }
-    GNUNET_break (0);
-    // FIXME: probably should consider 'qs' values in more detail here...
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                       TALER_EC_GENERIC_DB_INVARIANT_FAILURE,
-                                       "database failure");
+    resp = MHD_create_response_from_buffer (0,
+                                            NULL,
+                                            MHD_RESPMEM_PERSISTENT);
+    TALER_MHD_add_global_headers (resp);
+    ret = MHD_queue_response (connection,
+                              MHD_HTTP_NO_CONTENT,
+                              resp);
+    MHD_destroy_response (resp);
+    return ret;
   }
+  GNUNET_break (0);
+  // FIXME: probably should consider 'qs' values in more detail here...
+  return TALER_MHD_reply_with_error (connection,
+                                     MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                     TALER_EC_GENERIC_DB_INVARIANT_FAILURE,
+                                     "database failure");
 }

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