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 implemenation truth u


From: gnunet
Subject: [taler-anastasis] branch master updated: worked on implemenation truth up/download
Date: Fri, 17 Jan 2020 16:37:12 +0100

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

ds-meister pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new cac96d7  worked on implemenation truth up/download
cac96d7 is described below

commit cac96d7f698b2d85b7f6b752a51386086e8eb696
Author: Dominik Meister <address@hidden>
AuthorDate: Fri Jan 17 16:37:03 2020 +0100

    worked on implemenation truth up/download
---
 src/include/anastasis_service.h         |  51 ++++--
 src/lib/anastasis_api_keyshare_lookup.c | 308 ++++++++++++++++++++++++++++++++
 2 files changed, 346 insertions(+), 13 deletions(-)

diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 4a27cbf..43644cf 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -48,7 +48,6 @@ struct ANASTASIS_AccountPrivP
   struct GNUNET_CRYPTO_EddsaPrivateKey priv;
 };
 
-
 /**
  * Random identifier used to later charge a payment.
  */
@@ -66,6 +65,13 @@ struct ANASTASIS_UuidP
 {
   uuid_t uuid;
 };
+/**
+ * Truth Key used for the decryption of the truth on the server
+ */
+struct ANASTASIS_TruthKey
+{
+  uint32_t key[8];
+};
 
 /**
  * Data signed by the account public key of a sync client to
@@ -190,6 +196,21 @@ struct ANASTASIS_DownloadDetails
 
 };
 
+/**
+ * Detailed results from the successful download.
+ */
+struct ANASTASIS_KeyShareDownloadDetails
+{
+  /**
+   * The backup we downloaded
+   */
+  const void *encrypted_key_share;
+
+   /**
+     * Number of bytes in truth_data.
+     */
+  size_t encrypted_key_share_size;
+};
 
 /**
  * Result of an upload.
@@ -398,7 +419,7 @@ ANASTASIS_policy_store_cancel (struct
 /**
  * Handle for a GET /truth operation.
  */
-struct ANASTASIS_TruthLookupOperation;
+struct ANASTASIS_KeyShareLookupOperation;
 
 /**
  * Callback to process a GET /truth request
@@ -409,9 +430,9 @@ struct ANASTASIS_TruthLookupOperation;
  * @param obj the response body
  */
 typedef void
-(*ANASTASIS_TruthLookupCallback) (void *cls,
-                                  unsigned int http_status,
-                                  const struct ANASTASIS_DownloadDetails *dd);
+(*ANASTASIS_KeyShareLookupCallback) (void *cls,
+                                     unsigned int http_status,
+                                     const struct 
ANASTASIS_KeyShareDownloadDetails *kdd);
 
 /**
  * Does a GET /truth.
@@ -419,16 +440,20 @@ typedef void
  * @param ctx execution context
  * @param backend_url base URL of the merchant backend
  * @param truth_uuid identification of the Truth
+ * @param truth_key Key used to Decrypt the Truth on the Server
+ * @param hashed_answer Hashed answer for the Securityquestion
  * @param cb callback which will work the response gotten from the backend
  * @param cb_cls closure to pass to the callback
  * @return handle for this operation, NULL upon errors
  */
-struct ANASTASIS_TruthLookupOperation *
-ANASTASIS_truth_lookup (struct GNUNET_CURL_Context *ctx,
-                        const char *backend_url,
-                        const struct ANASTASIS_UuidP *truth_uuid,
-                        ANASTASIS_TruthLookupCallback cb,
-                        void *cb_cls);
+struct ANASTASIS_KeyShareLookupOperation *
+ANASTASIS_key_share_lookup (struct GNUNET_CURL_Context *ctx,
+                            const char *backend_url,
+                            const struct ANASTASIS_UuidP *truth_uuid,
+                            const struct ANASTASIS_TruthKey *truth_key,
+                            const struct GNUNET_HashCode *hashed_answer,
+                            ANASTASIS_KeyShareLookupCallback cb,
+                            void *cb_cls);
 
 /**
  * Cancel a GET /truth request.
@@ -436,8 +461,8 @@ ANASTASIS_truth_lookup (struct GNUNET_CURL_Context *ctx,
  * @param tlo cancel the truth lookup operation
  */
 void
-ANASTASIS_truth_lookup_cancel (struct
-                               ANASTASIS_TruthLookupOperation *tlo);
+ANASTASIS_key_share_lookup_cancel (struct
+                                   ANASTASIS_TruthLookupOperation *klo);
 
 /**
  * Handle for a POST /truth operation.
diff --git a/src/lib/anastasis_api_keyshare_lookup.c 
b/src/lib/anastasis_api_keyshare_lookup.c
new file mode 100644
index 0000000..4412eb8
--- /dev/null
+++ b/src/lib/anastasis_api_keyshare_lookup.c
@@ -0,0 +1,308 @@
+/*
+  This file is part of ANASTASIS
+  Copyright (C) 2014-2019 GNUnet e.V. and INRIA
+
+  ANASTASIS is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1,
+  or (at your option) any later version.
+
+  ANASTASIS 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 Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with ANASTASIS; see the file COPYING.LGPL.  If not,
+  see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file lib/anastasis_api_policy_lookup.c
+ * @brief Implementation of the /policy GET and POST
+ * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+#include "platform.h"
+#include <curl/curl.h>
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_json_lib.h>
+#include <taler/taler_curl_lib.h>
+#include <taler/taler_util.h>
+#include <taler/taler_signatures.h>
+#include "anastasis_service.h"
+
+
+/**
+ * @brief A Contract Operation Handle
+ */
+struct ANASTASIS_KeyShareLookupOperation
+{
+  /**
+   * The url for this request, including parameters.
+   */
+  char *url;
+
+  /**
+   * Handle for the request.
+   */
+  struct GNUNET_CURL_Job *job;
+
+  /**
+   * Function to call with the result.
+   */
+  ANASTASIS_KeyshareLookupCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Reference to the execution context.
+   */
+  struct GNUNET_CURL_Context *ctx;
+
+  /**
+   * Identification of the Truth Object
+   */
+  struct ANASTASIS_UuidP truth_uuid;
+
+  /**
+   * Key to decrypt the truth on the server
+   */
+  struct ANASTASIS_TruthKey truth_key;
+
+  /**
+   * Hash of the response (security question)
+   */
+  struct GNUNET_HashCode hashed_answer;
+};
+
+/**
+ * Cancel a pending /truth GET request
+ *
+ * @param handle from the operation to cancel
+ */
+void
+ANASTASIS_key_share_lookup_cancel (struct
+                                   ANASTASIS_KeyShareLookupOperation *klo)
+{
+  if (NULL != klo->job)
+  {
+    GNUNET_CURL_job_cancel (klo->job);
+    klo->job = NULL;
+  }
+  GNUNET_free (klo->url);
+  GNUNET_free (klo);
+}
+
+
+/**
+ * Process GET /truth response
+ */
+static void
+handle_key_share_lookup_finished (void *cls,
+                                  long response_code,
+                                  const void *data,
+                                  size_t data_size)
+{
+  struct ANASTASIS_KeyshareLookupOperation *klo = cls;
+
+  klo->job = NULL;
+  switch (response_code)
+  {
+  case 0:
+    /* Hard error */
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Backend didn't even return from GET /truth\n");
+    break;
+
+  case MHD_HTTP_OK:
+    {
+      struct ANASTASIS_KeyShareDownloadDetails kdd;
+
+      /* Success, call callback with all details! */
+      memset (&dd, 0, sizeof (dd));
+      kdd.keyshare = klo->data;
+      kdd.keyshare_size = klo->data_size;
+      klo->cb (klo->cb_cls,
+               response_code,
+               &kdd);
+      klo->cb = NULL;
+      ANASTASIS_key_share_lookup_cancel (klo);
+      return;
+    }
+  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 != klo->cb)
+  {
+    klo->cb (klo->cb_cls,
+             response_code,
+             NULL);
+    klo->cb = NULL;
+  }
+  ANASTASIS_key_share_lookup_cancel (klo);
+}
+
+
+/**
+ * Handle HTTP header received by curl.
+ *
+ * @param buffer one line of HTTP header data
+ * @param size size of an item
+ * @param nitems number of items passed
+ * @param userdata our `struct ANASTASIS_PolicyLookupOperation *`
+ * @return `size * nitems`
+ */
+static size_t
+handle_header (char *buffer,
+               size_t size,
+               size_t nitems,
+               void *userdata)
+{
+  struct ANASTASIS_KeyShareLookupOperation *klo = userdata;
+  size_t total = size * nitems;
+  char *ndup;
+  const char *hdr_type;
+  char *hdr_val;
+
+  ndup = GNUNET_strndup (buffer,
+                         total);
+  hdr_type = strtok (ndup,
+                     ":");
+  if (NULL == hdr_type)
+  {
+    GNUNET_free (ndup);
+    return total;
+  }
+  hdr_val = strtok (NULL,
+                    "\n\r");
+  if (NULL == hdr_val)
+  {
+    GNUNET_free (ndup);
+    return total;
+  }
+  if (' ' == *hdr_val)
+    hdr_val++;
+  if (0 == strcasecmp (hdr_type,
+                       "Anastasis-Policy-Signature"))
+  {
+    if (GNUNET_OK !=
+        GNUNET_STRINGS_string_to_data (hdr_val,
+                                       strlen (hdr_val),
+                                       &plo->account_sig,
+                                       sizeof (struct
+                                               ANASTASIS_AccountSignatureP)))
+    {
+      GNUNET_break_op (0);
+      GNUNET_free (ndup);
+      return 0;
+    }
+  }
+  /* FIXME: reasonable?*/
+  if (0 == strcasecmp (hdr_type,
+                       "Anastasis-Previous"))
+  {
+    if (GNUNET_OK !=
+        GNUNET_STRINGS_string_to_data (hdr_val,
+                                       strlen (hdr_val),
+                                       &plo->anastasis_previous,
+                                       sizeof (struct GNUNET_HashCode)))
+    {
+      GNUNET_break_op (0);
+      GNUNET_free (ndup);
+      return 0;
+    }
+  }
+  GNUNET_free (ndup);
+  return total;
+}
+
+
+/**
+ * Does a GET /truth.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param truth_uuid identification of the Truth
+ * @param truth_key Key used to Decrypt the Truth on the Server
+ * @param hashed_answer Hashed answer for the Securityquestion
+ * @param cb callback which will work the response gotten from the backend
+ * @param cb_cls closure to pass to the callback
+ * @return handle for this operation, NULL upon errors
+ */
+struct ANASTASIS_KeyShareLookupOperation *
+ANASTASIS_key_share_lookup (struct GNUNET_CURL_Context *ctx,
+                            const char *backend_url,
+                            const struct ANASTASIS_UuidP *truth_uuid,
+                            const struct ANASTASIS_TruthKey *truth_key,
+                            const struct GNUNET_HashCode *hashed_answer,
+                            ANASTASIS_KeyShareLookupCallback cb,
+                            void *cb_cls)
+{
+  struct ANASTASIS_KeyShareLookupOperation *klo;
+  CURL *eh;
+  char *uuid_str;
+  char *hashed_answer;
+  char *path;
+
+  klo = GNUNET_new (struct ANASTASIS_KeyShareLookupOperation);
+  klo->ctx = ctx;
+  klo->cb = cb;
+  klo->cb_cls = cb_cls;
+  klo->truth_key = truth_key;
+  uuid_str = GNUNET_STRINGS_data_to_string_alloc (&truth_uuid,
+                                                  sizeof (truth_uuid));
+  hashed_answer = GNUNET_STRINGS_data_to_string_alloc (&hashed_answer,
+                                                       sizeof (hashed_answer));
+  GNUNET_asprintf (&path,
+                   "truth/%s",
+                   uuid_str);
+  GNUNET_free (uuid_str);
+  klo->url = TALER_url_join (backend_url,
+                             path,
+                             "response",
+                             hashed_answer,
+                             NULL);
+  GNUNET_free (path);
+  GNUNET_free (hashed_answer);
+  eh = curl_easy_init ();
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_HEADERFUNCTION,
+                                   &handle_header));
+  GNUNET_assert ((CURLE_OK != curl_easy_setopt (eh,
+                                                CURLOPT_URL,
+                                                klo)));
+  klo->cb = cb;
+  klo->cb_cls = cb_cls;
+  klo->job = GNUNET_CURL_job_add_raw (ctx,
+                                      eh,
+                                      GNUNET_NO,
+                                      &handle_key_share_lookup_finished,
+                                      klo);
+  return klo;
+}

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



reply via email to

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