gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: worked on salt api


From: gnunet
Subject: [taler-anastasis] branch master updated: worked on salt api
Date: Wed, 15 Apr 2020 10:32:44 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new bd7a177  worked on salt api
bd7a177 is described below

commit bd7a17711c9688d205a8157fdf836279af161085
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed Apr 15 08:32:34 2020 +0000

    worked on salt api
---
 src/backend/Makefile.am               |   1 +
 src/backend/anastasis-httpd.c         |  31 +++++++++
 src/backend/anastasis-httpd.h         |   5 ++
 src/backend/anastasis-httpd_salt.c    |  52 ++++++++++++++
 src/backend/anastasis-httpd_salt.h    |  38 +++++++++++
 src/backend/anastasis.conf            |   3 +
 src/include/anastasis_crypto_lib.h    |   4 +-
 src/include/anastasis_service.h       |  11 +--
 src/lib/anastasis_api_policy_lookup.c |   3 +-
 src/lib/anastasis_api_salt.c          | 124 +++++++++++++++++++++++++++++++++-
 10 files changed, 262 insertions(+), 10 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index e4cb8d8..d913acd 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -16,6 +16,7 @@ anastasis_httpd_SOURCES = \
   anastasis-httpd_mhd.c anastasis-httpd_mhd.h \
   anastasis-httpd_policy.c anastasis-httpd_policy.h \
   anastasis-httpd_policy_upload.c \
+  anastasis-httpd_salt.c anastasis-httpd_salt.h \
   anastasis-httpd_truth.c anastasis-httpd_truth.h \
   anastasis-httpd_truth_upload.c
 
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 631846e..857fe90 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -28,6 +28,7 @@
 #include "anastasis_database_lib.h"
 #include "anastasis-httpd_policy.h"
 #include "anastasis-httpd_truth.h"
+#include "anastasis-httpd_salt.h"
 
 /**
  * Backlog for listen operation on unix-domain sockets.
@@ -59,6 +60,11 @@ char *AH_fulfillment_url;
  */
 struct GNUNET_TIME_Relative AH_truth_expiration;
 
+/**
+ * Our server salt.
+ */
+char *AH_server_salt;
+
 /**
  * Our context for making HTTP requests.
  */
@@ -312,6 +318,19 @@ url_handler (void *cls,
                                     upload_data_size);
     }
   }
+  if (0 == strncmp (url,
+                    "/salt",
+                    strlen ("/salt")))
+  {
+    // return handle_salt (...);
+    if (0 == strcmp (method,
+                     MHD_HTTP_METHOD_GET))
+    {
+      return AH_handler_salt (connection,
+                              url,
+                              con_cls);
+    }
+  }
   for (unsigned int i = 0; NULL != handlers[i].url; i++)
   {
     struct TMH_RequestHandler *rh = &handlers[i];
@@ -573,6 +592,18 @@ run (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (config,
+                                             "anastasis",
+                                             "SERVER_SALT",
+                                             &AH_server_salt))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               "anastasis",
+                               "SERVER_SALT");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
 
   /* setup HTTP client event loop */
   AH_ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index 3d5998a..14c6230 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -161,6 +161,11 @@ extern char *AH_fulfillment_url;
  */
 extern struct GNUNET_TIME_Relative AH_truth_expiration;
 
+/**
+ * Our server salt.
+ */
+extern char *AH_server_salt;
+
 
 /**
  * Our context for making HTTP requests.
diff --git a/src/backend/anastasis-httpd_salt.c 
b/src/backend/anastasis-httpd_salt.c
new file mode 100644
index 0000000..44e4525
--- /dev/null
+++ b/src/backend/anastasis-httpd_salt.c
@@ -0,0 +1,52 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2019 GNUnet e.V.
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Affero General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more 
details.
+
+  You should have received a copy of the GNU Affero General Public License 
along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file anastasis-httpd_salt.c
+ * @brief functions to handle incoming requests on /salt
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "anastasis-httpd.h"
+#include "anastasis-httpd_salt.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_rest_lib.h>
+
+
+/**
+ * @param connection the MHD connection to handle
+ * @param url handles a URL of the format "/salt"
+ * @param con_cls
+ * @return MHD result code
+ */
+int
+AH_handler_salt (struct MHD_Connection *connection,
+                 const char *url,
+                 void **con_cls)
+{
+  struct ANASTASIS_CRYPTO_Salt salt;
+  salt.salt = (char *) AH_server_salt;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Server Salt: %s\n",
+              salt.salt);
+  return TALER_MHD_reply_json_pack (connection,
+                                    MHD_HTTP_OK,
+                                    "{s:o}",
+                                    "server_salt",
+                                    GNUNET_JSON_from_data_auto (&salt));
+}
\ No newline at end of file
diff --git a/src/backend/anastasis-httpd_salt.h 
b/src/backend/anastasis-httpd_salt.h
new file mode 100644
index 0000000..1ea3da4
--- /dev/null
+++ b/src/backend/anastasis-httpd_salt.h
@@ -0,0 +1,38 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2019 GNUnet e.V.
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Affero General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more 
details.
+
+  You should have received a copy of the GNU Affero General Public License 
along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file anastasis-httpd_salt.c
+ * @brief functions to handle incoming requests on /salt
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ * @author Christian Grothoff
+ */
+#ifndef ANASTASIS_HTTPD_SALT_H
+#define ANASTASIS_HTTPD_SALT_H
+#include <microhttpd.h>
+
+/**
+ * @param connection the MHD connection to handle
+ * @param url handles a URL of the format "/salt"
+ * @param con_cls
+ * @return MHD result code
+ */
+int
+AH_handler_salt (struct MHD_Connection *connection,
+                 const char *url,
+                 void **con_cls);
+
+#endif
\ No newline at end of file
diff --git a/src/backend/anastasis.conf b/src/backend/anastasis.conf
index 9c61c61..6346e60 100644
--- a/src/backend/anastasis.conf
+++ b/src/backend/anastasis.conf
@@ -38,6 +38,9 @@ PAYMENT_BACKEND_URL = http://localhost:9976/
 # Standard expiration time in microseconds range of truth (2 years)
 TRUTH_EXPIRATION = 63115200000000
 
+# Server salt 256 bits
+SERVER_SALT = 
gUfO1KGOKYIFlFQgBv9NeYqiSgS16Y0dcgj74YewVnSEsEkXaG5duaGphWXgQGI84OOezaS9tlffQ0J27u6iAcvWMMdR8oANz5GeoWZFAAQDW65qMrUoTfDK170hY7krj6GZ04PFgBzBRtNAyGqPTkRbOFQ04lu6pa0bYF9JAwmwrFD0csVliuvapL33ukOwHdKDyg81FQuRW1bNbj9D0GMPoVcacJUrOXk0mIWhyG3Q2OoVOfW1LiIaXwfitLGd
+
 # Configuration for postgres database.
 [anastasisdb-postgres]
 CONFIG = postgres:///anastasis
diff --git a/src/include/anastasis_crypto_lib.h 
b/src/include/anastasis_crypto_lib.h
index 25642df..9bfd407 100644
--- a/src/include/anastasis_crypto_lib.h
+++ b/src/include/anastasis_crypto_lib.h
@@ -53,11 +53,11 @@ struct ANASTASIS_CRYPTO_TruthKey
 
 
 /**
- * Specifies a Salt value, here 32 Byte large.
+ * Specifies a Salt value, should be 32 Byte large.
 */
 struct ANASTASIS_CRYPTO_Salt
 {
-  uint32_t salt[8];
+  char*salt;
 };
 
 
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 7916ed8..f7a67e0 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -94,7 +94,7 @@ struct ANASTASIS_Salt
   /**
    * Salt is specified as 32 byte (256 bit).
    */
-  uint32_t value[8];
+  char value[256];
 };
 
 GNUNET_NETWORK_STRUCT_END
@@ -245,15 +245,16 @@ struct ANASTASIS_UploadDetails
 
 
 typedef void
-(ANASTASIS_SaltCallback)(void *cls,
-                         const struct ANASTASIS_Salt *salt);
+(*ANASTASIS_SaltCallback)(void *cls,
+                          unsigned int http_status,
+                          struct ANASTASIS_CRYPTO_Salt *salt);
 
 
 struct ANASTASIS_SaltOperation *
 ANASTASIS_salt (struct GNUNET_CURL_Context *ctx,
                 const char *base_url,
-                ANASTASIS_SaltCallback sb,
-                void *sb_cls);
+                ANASTASIS_SaltCallback cb,
+                void *cb_cls);
 
 
 void
diff --git a/src/lib/anastasis_api_policy_lookup.c 
b/src/lib/anastasis_api_policy_lookup.c
index 1654637..f5b3c84 100644
--- a/src/lib/anastasis_api_policy_lookup.c
+++ b/src/lib/anastasis_api_policy_lookup.c
@@ -96,8 +96,7 @@ struct ANASTASIS_PolicyLookupOperation
  * @param handle from the operation to cancel
  */
 void
-ANASTASIS_policy_lookup_cancel (struct
-                                ANASTASIS_PolicyLookupOperation *plo)
+ANASTASIS_policy_lookup_cancel (struct ANASTASIS_PolicyLookupOperation *plo)
 {
   if (NULL != plo->job)
   {
diff --git a/src/lib/anastasis_api_salt.c b/src/lib/anastasis_api_salt.c
index d6a464e..67cdaea 100644
--- a/src/lib/anastasis_api_salt.c
+++ b/src/lib/anastasis_api_salt.c
@@ -28,7 +28,9 @@
 #include <microhttpd.h> /* just for HTTP status codes */
 #include <gnunet/gnunet_util_lib.h>
 #include <gnunet/gnunet_curl_lib.h>
+#include <gnunet/gnunet_json_lib.h>
 #include "anastasis_service.h"
+#include "anastasis_api_curl_defaults.h"
 
 
 /**
@@ -36,7 +38,6 @@
  */
 struct ANASTASIS_SaltOperation
 {
-
   /**
    * The url for this request.
    */
@@ -52,6 +53,127 @@ struct ANASTASIS_SaltOperation
    */
   struct GNUNET_CURL_Context *ctx;
 
+  /**
+  * The callback to pass the backend response to
+  */
+  ANASTASIS_SaltCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Server salt.
+   */
+  struct ANASTASIS_CRYPTO_Salt salt;
 };
 
+
+/**
+ * Function called when we're done processing the
+ * HTTP /salt request.
+ *
+ * @param cls the `struct ANASTASIS_SaltOperation`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_salt_finished (void *cls,
+                      long response_code,
+                      const void *response)
+{
+  struct ANASTASIS_SaltOperation *so = cls;
+  const json_t *json = response;
+
+  so->job = NULL;
+  switch (response_code)
+  {
+  case 0:
+    /* Hard error */
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Backend didn't even return from GET /policy\n");
+    break;
+  case MHD_HTTP_OK:
+    {
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_fixed_auto ("server_salt", &so->salt),
+        GNUNET_JSON_spec_end ()
+      };
+
+      GNUNET_assert (GNUNET_OK ==
+                     GNUNET_JSON_parse (json,
+                                        spec,
+                                        NULL, NULL));
+    }
+    break;
+  case MHD_HTTP_BAD_REQUEST:
+    /* This should never happen, either us or the anastasis server is buggy
+       (or API version conflict); just pass JSON reply to the application */
+    break;
+  case MHD_HTTP_NOT_FOUND:
+    /* Nothing really to verify */
+    break;
+  case MHD_HTTP_INTERNAL_SERVER_ERROR:
+    /* Server had an internal issue; we should retry, but this API
+       leaves this to the application */
+    break;
+  default:
+    /* unexpected response code */
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u\n",
+                (unsigned int) response_code);
+    GNUNET_break (0);
+    response_code = 0;
+    break;
+  }
+  if (NULL != so->cb)
+  {
+    so->cb (so->cb_cls,
+            response_code,
+            &so->salt);
+    so->cb = NULL;
+  }
+  ANASTASIS_salt_cancel (so);
+}
+
+
+struct ANASTASIS_SaltOperation *
+ANASTASIS_salt (struct GNUNET_CURL_Context *ctx,
+                const char *base_url,
+                ANASTASIS_SaltCallback cb,
+                void *cb_cls)
+{
+  struct ANASTASIS_SaltOperation *so;
+  CURL *eh;
+
+  so = GNUNET_new (struct ANASTASIS_SaltOperation);
+  so->url = TALER_url_join (base_url,
+                            "/salt",
+                            NULL);
+  so->ctx = ctx;
+  so->cb = cb;
+  so->cb_cls = cb_cls;
+  eh = ANASTASIS_curl_easy_get_ (so->url);
+  so->job = GNUNET_CURL_job_add (ctx,
+                                 eh,
+                                 GNUNET_NO,
+                                 &handle_salt_finished,
+                                 so);
+  return so;
+}
+
+
+void
+ANASTASIS_salt_cancel (struct ANASTASIS_SaltOperation *so)
+{
+  if (NULL != so->job)
+  {
+    GNUNET_CURL_job_cancel (so->job);
+    so->job = NULL;
+  }
+  GNUNET_free (so->url);
+  GNUNET_free (so);
+}
+
 /* end of anastasis_api_salt.c */

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



reply via email to

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