gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: get file-challenge-run-2 to pas


From: gnunet
Subject: [taler-anastasis] branch master updated: get file-challenge-run-2 to pass
Date: Sun, 14 Feb 2021 12:04:51 +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 9071b88  get file-challenge-run-2 to pass
9071b88 is described below

commit 9071b88c8649c5be07fe9852393c7cf312134c6d
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Feb 14 12:04:48 2021 +0100

    get file-challenge-run-2 to pass
---
 .../anastasis_authorization_plugin_file.c          | 101 ++++++++++++---------
 .../anastasis_authorization_plugin_sms.c           |   2 +-
 src/backend/anastasis-httpd_truth.c                |  25 ++---
 src/restclient/anastasis_api_keyshare_lookup.c     |  21 ++---
 src/stasis/plugin_anastasis_postgres.c             |   5 +-
 src/testing/testing_api_cmd_keyshare_lookup.c      |  65 ++++++-------
 src/testing/testing_api_cmd_truth_store.c          |  21 ++++-
 src/util/test_anastasis_crypto.c                   |   8 --
 8 files changed, 135 insertions(+), 113 deletions(-)

diff --git a/src/authorization/anastasis_authorization_plugin_file.c 
b/src/authorization/anastasis_authorization_plugin_file.c
index dd5ad7a..d2adc54 100644
--- a/src/authorization/anastasis_authorization_plugin_file.c
+++ b/src/authorization/anastasis_authorization_plugin_file.c
@@ -145,59 +145,72 @@ static enum ANASTASIS_AUTHORIZATION_Result
 file_process (struct ANASTASIS_AUTHORIZATION_State *as,
               struct MHD_Connection *connection)
 {
-  MHD_RESULT mres;
-  struct MHD_Response *resp;
-  FILE *f = fopen (as->filename, "w");
-
-  if (f == NULL)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Could not open file");
-    resp = TALER_MHD_make_error (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
-                                 "Failed to open filebuffer");
-    mres = MHD_queue_response (connection,
-                               MHD_HTTP_INTERNAL_SERVER_ERROR,
-                               resp);
-    MHD_destroy_response (resp);
-    if (MHD_YES != mres)
-      return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED;
-    return ANASTASIS_AUTHORIZATION_RES_FAILED;
+    FILE *f = fopen (as->filename, "w");
+
+    if (NULL == f)
+    {
+      struct MHD_Response *resp;
+      MHD_RESULT mres;
+
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                                "open",
+                                as->filename);
+      resp = TALER_MHD_make_error (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+                                   "Failed to open file");
+      mres = MHD_queue_response (connection,
+                                 MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                 resp);
+      MHD_destroy_response (resp);
+      if (MHD_YES != mres)
+        return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED;
+      return ANASTASIS_AUTHORIZATION_RES_FAILED;
+    }
+
+    /* print challenge code to file */
+    if (0 >= fprintf (f,
+                      "%lu",
+                      as->code))
+    {
+      struct MHD_Response *resp;
+      MHD_RESULT mres;
+
+      GNUNET_break (0 == fclose (f));
+      resp = TALER_MHD_make_error (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+                                   "Failed to write to file");
+      mres = MHD_queue_response (connection,
+                                 MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                 resp);
+      MHD_destroy_response (resp);
+      if (MHD_YES != mres)
+        return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED;
+      return ANASTASIS_AUTHORIZATION_RES_FAILED;
+    }
+    GNUNET_break (0 == fclose (f));
   }
 
-  /* print challenge code to file */
-  if (0 >= fprintf (f, "%lu", as->code))
   {
-    fclose (f);
-    resp = TALER_MHD_make_error (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
-                                 "Failed to write to file");
+    struct MHD_Response *resp;
+    size_t response_size;
+    char *response;
+    MHD_RESULT mres;
+
+    /* FIXME: internationalization, etc. */
+    response_size = GNUNET_asprintf (&response,
+                                     "Challenge written to file");
+    resp = MHD_create_response_from_buffer (response_size,
+                                            response,
+                                            MHD_RESPMEM_MUST_FREE);
+    GNUNET_free (response);
+    TALER_MHD_add_global_headers (resp);
     mres = MHD_queue_response (connection,
-                               MHD_HTTP_INTERNAL_SERVER_ERROR,
+                               MHD_HTTP_FORBIDDEN,
                                resp);
     MHD_destroy_response (resp);
     if (MHD_YES != mres)
-      return ANASTASIS_AUTHORIZATION_RES_FAILED_REPLY_FAILED;
-    return ANASTASIS_AUTHORIZATION_RES_FAILED;
+      return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
+    return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
   }
-  fclose (f);
-
-  size_t response_size;
-  response_size = strlen (as->filename) * 5 / 8;
-  void *response = malloc (response_size);
-  GNUNET_STRINGS_string_to_data (as->filename,
-                                 strlen (as->filename),
-                                 response,
-                                 response_size);
-  resp = MHD_create_response_from_buffer (response_size,
-                                          response,
-                                          MHD_RESPMEM_MUST_FREE);
-  TALER_MHD_add_global_headers (resp);
-  mres = MHD_queue_response (connection,
-                             MHD_HTTP_OK,
-                             resp);
-  MHD_destroy_response (resp);
-  if (MHD_YES != mres)
-    return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
-  return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
 }
 
 
diff --git a/src/authorization/anastasis_authorization_plugin_sms.c 
b/src/authorization/anastasis_authorization_plugin_sms.c
index f65d940..939c55a 100644
--- a/src/authorization/anastasis_authorization_plugin_sms.c
+++ b/src/authorization/anastasis_authorization_plugin_sms.c
@@ -382,7 +382,7 @@ sms_process (struct ANASTASIS_AUTHORIZATION_State *as,
     GNUNET_free (reply);
     TALER_MHD_add_global_headers (resp);
     mres = MHD_queue_response (connection,
-                               MHD_HTTP_OK,
+                               MHD_HTTP_FORBIDDEN,
                                resp);
     MHD_destroy_response (resp);
   }
diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 048bca7..825d527 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -55,6 +55,11 @@ struct GetContext
    */
   struct ANASTASIS_CRYPTO_TruthUUIDP truth_uuid;
 
+  /**
+   * Key to decrypt the truth.
+   */
+  struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
+
   /**
    * true if client provided a payment secret / order ID?
    */
@@ -541,20 +546,17 @@ return_key_share (
 
   {
     struct MHD_Response *resp;
+    MHD_RESULT ret;
 
     resp = MHD_create_response_from_buffer (sizeof (encrypted_keyshare),
                                             &encrypted_keyshare,
                                             MHD_RESPMEM_MUST_COPY);
     TALER_MHD_add_global_headers (resp);
-    {
-      MHD_RESULT ret;
-
-      ret = MHD_queue_response (connection,
-                                MHD_HTTP_OK,
-                                resp);
-      MHD_destroy_response (resp);
-      return ret;
-    }
+    ret = MHD_queue_response (connection,
+                              MHD_HTTP_OK,
+                              resp);
+    MHD_destroy_response (resp);
+    return ret;
   }
 }
 
@@ -572,7 +574,6 @@ AH_handler_truth_get (
   struct TM_HandlerContext *hc)
 {
   struct GetContext *gc = hc->ctx;
-  struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
   struct GNUNET_HashCode challenge_response;
   bool have_response;
   void *encrypted_truth;
@@ -636,7 +637,7 @@ AH_handler_truth_get (
           GNUNET_STRINGS_string_to_data (
             tdk,
             strlen (tdk),
-            &truth_key,
+            &gc->truth_key,
             sizeof (struct ANASTASIS_CRYPTO_TruthKeyP)))
       {
         GNUNET_break_op (0);
@@ -846,7 +847,7 @@ AH_handler_truth_get (
   /* We've been paid, now validate response */
   {
     /* decrypt encrypted_truth */
-    ANASTASIS_CRYPTO_truth_decrypt (&truth_key,
+    ANASTASIS_CRYPTO_truth_decrypt (&gc->truth_key,
                                     encrypted_truth,
                                     encrypted_truth_size,
                                     &decrypted_truth,
diff --git a/src/restclient/anastasis_api_keyshare_lookup.c 
b/src/restclient/anastasis_api_keyshare_lookup.c
index 8732188..b46cbee 100644
--- a/src/restclient/anastasis_api_keyshare_lookup.c
+++ b/src/restclient/anastasis_api_keyshare_lookup.c
@@ -140,23 +140,20 @@ handle_keyshare_lookup_finished (void *cls,
     kdd.status = ANASTASIS_KSD_SERVER_ERROR;
     break;
   case MHD_HTTP_OK:
-    if (sizeof (struct ANASTASIS_CRYPTO_EncryptedKeyShareP) == data_size)
-    {
-      /* Success, call callback with all details! */
-      memcpy (&kdd.details.eks,
-              data,
-              data_size);
-      kslo->cb (kslo->cb_cls,
-                &kdd);
-      ANASTASIS_keyshare_lookup_cancel (kslo);
-      return;
-    }
-    else
+    if (sizeof (struct ANASTASIS_CRYPTO_EncryptedKeyShareP) != data_size)
     {
       GNUNET_break_op (0);
       kdd.status = ANASTASIS_KSD_SERVER_ERROR;
       break;
     }
+    /* Success, call callback with all details! */
+    memcpy (&kdd.details.eks,
+            data,
+            data_size);
+    kslo->cb (kslo->cb_cls,
+              &kdd);
+    ANASTASIS_keyshare_lookup_cancel (kslo);
+    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 */
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 4621537..622b9cb 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -1921,12 +1921,9 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             5),
     GNUNET_PQ_make_prepare ("truth_select",
                             "SELECT "
-                            "truth_uuid"
-                            ",key_share_data"
-                            ",method_name"
+                            " method_name"
                             ",encrypted_truth"
                             ",truth_mime"
-                            ",expiration"
                             " FROM anastasis_truth"
                             " WHERE truth_uuid =$1;",
                             1),
diff --git a/src/testing/testing_api_cmd_keyshare_lookup.c 
b/src/testing/testing_api_cmd_keyshare_lookup.c
index bdb7d37..d8768ca 100644
--- a/src/testing/testing_api_cmd_keyshare_lookup.c
+++ b/src/testing/testing_api_cmd_keyshare_lookup.c
@@ -171,7 +171,12 @@ keyshare_lookup_run (void *cls,
   const struct ANASTASIS_PaymentSecretP *payment_secret;
 
   ksls->is = is;
-  if (NULL != ksls->upload_reference)
+  if (NULL == ksls->upload_reference)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (ksls->is);
+    return;
+  }
   {
     const struct TALER_TESTING_Command *upload_cmd;
 
@@ -184,37 +189,35 @@ keyshare_lookup_run (void *cls,
       TALER_TESTING_interpreter_fail (ksls->is);
       return;
     }
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_truth_uuid (upload_cmd,
+                                                0,
+                                                &truth_uuid))
     {
-      if (GNUNET_OK !=
-          ANASTASIS_TESTING_get_trait_truth_uuid (upload_cmd,
-                                                  0,
-                                                  &truth_uuid))
-      {
-        GNUNET_break (0);
-        TALER_TESTING_interpreter_fail (ksls->is);
-        return;
-      }
-      if (NULL == truth_uuid)
-      {
-        GNUNET_break (0);
-        TALER_TESTING_interpreter_fail (ksls->is);
-        return;
-      }
-      if (GNUNET_OK !=
-          ANASTASIS_TESTING_get_trait_truth_key (upload_cmd,
-                                                 0,
-                                                 &truth_key))
-      {
-        GNUNET_break (0);
-        TALER_TESTING_interpreter_fail (ksls->is);
-        return;
-      }
-      if (NULL == truth_key)
-      {
-        GNUNET_break (0);
-        TALER_TESTING_interpreter_fail (ksls->is);
-        return;
-      }
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (ksls->is);
+      return;
+    }
+    if (NULL == truth_uuid)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (ksls->is);
+      return;
+    }
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_truth_key (upload_cmd,
+                                               0,
+                                               &truth_key))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (ksls->is);
+      return;
+    }
+    if (NULL == truth_key)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (ksls->is);
+      return;
     }
   }
 
diff --git a/src/testing/testing_api_cmd_truth_store.c 
b/src/testing/testing_api_cmd_truth_store.c
index 398229d..8e5a032 100644
--- a/src/testing/testing_api_cmd_truth_store.c
+++ b/src/testing/testing_api_cmd_truth_store.c
@@ -18,7 +18,6 @@
  * @brief command to execute the anastasis backend service.
  * @author Dennis Neufeld
  */
-
 #include "platform.h"
 #include "anastasis_testing_lib.h"
 #include <taler/taler_util.h>
@@ -266,6 +265,26 @@ truth_store_run (void *cls,
                                     tss->truth_data_size,
                                     &encrypted_truth,
                                     &size_encrypted_truth);
+    {
+      void *t;
+      size_t t_size;
+
+      ANASTASIS_CRYPTO_truth_decrypt (&tss->key,
+                                      encrypted_truth,
+                                      size_encrypted_truth,
+                                      &t,
+                                      &t_size);
+      if ( (t_size != tss->truth_data_size) ||
+           (0 != memcmp (tss->truth_data,
+                         t,
+                         t_size)) )
+      {
+        GNUNET_break (0);
+        TALER_TESTING_interpreter_fail (tss->is);
+        return;
+      }
+      GNUNET_free (t);
+    }
     tss->tso = ANASTASIS_truth_store (
       is->ctx,
       tss->anastasis_url,
diff --git a/src/util/test_anastasis_crypto.c b/src/util/test_anastasis_crypto.c
index 599d9c4..1c66862 100644
--- a/src/util/test_anastasis_crypto.c
+++ b/src/util/test_anastasis_crypto.c
@@ -111,11 +111,6 @@ test_recovery_document (void)
   ANASTASIS_CRYPTO_user_identifier_derive (id_data,
                                            &server_salt,
                                            &id);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ERD_BEFORE:   %s\n",
-              TALER_b2s (test, strlen (test)));
-
   ANASTASIS_CRYPTO_recovery_document_encrypt (&id,
                                               test,
                                               strlen (test),
@@ -127,9 +122,6 @@ test_recovery_document (void)
                                               size_ciphertext,
                                               &plaintext,
                                               &size_plaintext);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ERD_AFTER:   %s\n",
-              TALER_b2s (plaintext, size_plaintext));
   GNUNET_assert (strlen (test) == size_plaintext);
   ret = strncmp (plaintext, test, strlen (test));
   json_decref (id_data);

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