gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: misc fixes


From: gnunet
Subject: [taler-anastasis] branch master updated: misc fixes
Date: Sat, 13 Feb 2021 21:27:50 +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 bc4bd1b  misc fixes
bc4bd1b is described below

commit bc4bd1b26d5277c812147ee4b97ac00ac7482dfe
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Feb 13 21:27:47 2021 +0100

    misc fixes
---
 src/backend/anastasis-httpd_truth.c            | 178 +++++++++++++------------
 src/restclient/anastasis_api_keyshare_lookup.c |   4 +-
 src/testing/test_anastasis_api.c               |   2 +-
 src/testing/testing_api_cmd_keyshare_lookup.c  | 104 ++++++++++++++-
 4 files changed, 197 insertions(+), 91 deletions(-)

diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index ec90a9f..048bca7 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -254,7 +254,7 @@ make_payment_request (struct GetContext *gc)
       &gc->payment_identifier,
       sizeof (gc->payment_identifier));
     GNUNET_asprintf (&hdr,
-                     "%spay/%s%s",
+                     "%spay/%s%s/",
                      pfx,
                      hn,
                      order_id);
@@ -582,7 +582,93 @@ AH_handler_truth_get (
   char *truth_mime = NULL;
   bool is_question;
 
-  if (NULL != gc)
+  if (NULL == gc)
+  {
+    /* Fresh request, do initial setup */
+    gc = GNUNET_new (struct GetContext);
+    gc->hc = hc;
+    hc->ctx = gc;
+    gc->connection = connection;
+    gc->truth_uuid = *truth_uuid;
+    gc->hc->cc = &request_done;
+    {
+      const char *pay_id;
+
+      pay_id = MHD_lookup_connection_value (connection,
+                                            MHD_HEADER_KIND,
+                                            
ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER);
+      if (NULL != pay_id)
+      {
+        if (GNUNET_OK !=
+            GNUNET_STRINGS_string_to_data (
+              pay_id,
+              strlen (pay_id),
+              &gc->payment_identifier,
+              sizeof (struct ANASTASIS_PaymentSecretP)))
+        {
+          GNUNET_break_op (0);
+          return TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                             
ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER);
+        }
+        gc->payment_identifier_provided = true;
+      }
+    }
+
+    {
+      /* check if header contains Truth-Decryption-Key */
+      const char *tdk;
+
+      tdk = MHD_lookup_connection_value (connection,
+                                         MHD_HEADER_KIND,
+                                         
ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY);
+      if (NULL == tdk)
+      {
+        GNUNET_break_op (0);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_BAD_REQUEST,
+                                           TALER_EC_GENERIC_PARAMETER_MISSING,
+                                           
ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY);
+      }
+
+      if (GNUNET_OK !=
+          GNUNET_STRINGS_string_to_data (
+            tdk,
+            strlen (tdk),
+            &truth_key,
+            sizeof (struct ANASTASIS_CRYPTO_TruthKeyP)))
+      {
+        GNUNET_break_op (0);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_BAD_REQUEST,
+                                           
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                           
ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY);
+      }
+    }
+
+    {
+      const char *challenge_response_s;
+
+      challenge_response_s = MHD_lookup_connection_value (connection,
+                                                          
MHD_GET_ARGUMENT_KIND,
+                                                          "response");
+      if ( (NULL != challenge_response_s) &&
+           (GNUNET_OK !=
+            GNUNET_CRYPTO_hash_from_string (challenge_response_s,
+                                            &challenge_response)) )
+      {
+        GNUNET_break_op (0);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_BAD_REQUEST,
+                                           
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                           "response");
+      }
+      have_response = (NULL != challenge_response_s);
+    }
+
+  } /* end of first-time initialization (if NULL == gc) */
+  else
   {
     if (NULL != gc->resp)
     {
@@ -642,92 +728,8 @@ AH_handler_truth_get (
         return MHD_NO;
       }
     }
-    /* How can we get here? */
-    GNUNET_break (0);
-    return MHD_NO;
-  }
-
-  /* Fresh request, do initial setup */
-  gc = GNUNET_new (struct GetContext);
-  gc->hc = hc;
-  hc->ctx = gc;
-  gc->connection = connection;
-  gc->truth_uuid = *truth_uuid;
-  gc->hc->cc = &request_done;
-  {
-    const char *pay_id;
-
-    pay_id = MHD_lookup_connection_value (connection,
-                                          MHD_HEADER_KIND,
-                                          
ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER);
-    if (NULL != pay_id)
-    {
-      if (GNUNET_OK !=
-          GNUNET_STRINGS_string_to_data (
-            pay_id,
-            strlen (pay_id),
-            &gc->payment_identifier,
-            sizeof (struct ANASTASIS_PaymentSecretP)))
-      {
-        GNUNET_break_op (0);
-        return TALER_MHD_reply_with_error (connection,
-                                           MHD_HTTP_BAD_REQUEST,
-                                           
TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                           
ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER);
-      }
-      gc->payment_identifier_provided = true;
-    }
-  }
-
-  {
-    /* check if header contains Truth-Decryption-Key */
-    const char *tdk;
-
-    tdk = MHD_lookup_connection_value (connection,
-                                       MHD_HEADER_KIND,
-                                       
ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY);
-    if (NULL == tdk)
-    {
-      GNUNET_break_op (0);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_GENERIC_PARAMETER_MISSING,
-                                         
ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY);
-    }
-
-    if (GNUNET_OK !=
-        GNUNET_STRINGS_string_to_data (
-          tdk,
-          strlen (tdk),
-          &truth_key,
-          sizeof (struct ANASTASIS_CRYPTO_TruthKeyP)))
-    {
-      GNUNET_break_op (0);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                         
ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY);
-    }
-  }
-
-  {
-    const char *challenge_response_s;
-
-    challenge_response_s = MHD_lookup_connection_value (connection,
-                                                        MHD_GET_ARGUMENT_KIND,
-                                                        "response");
-    if ( (NULL != challenge_response_s) &&
-         (GNUNET_OK !=
-          GNUNET_CRYPTO_hash_from_string (challenge_response_s,
-                                          &challenge_response)) )
-    {
-      GNUNET_break_op (0);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                         "response");
-    }
-    have_response = (NULL != challenge_response_s);
+    /* We get here if the async check for payment said this request
+       was indeed paid! */
   }
 
   {
diff --git a/src/restclient/anastasis_api_keyshare_lookup.c 
b/src/restclient/anastasis_api_keyshare_lookup.c
index f65f6a1..8732188 100644
--- a/src/restclient/anastasis_api_keyshare_lookup.c
+++ b/src/restclient/anastasis_api_keyshare_lookup.c
@@ -172,7 +172,9 @@ handle_keyshare_lookup_finished (void *cls,
             TALER_MERCHANT_parse_pay_uri (kslo->pay_uri,
                                           &pd)) )
       {
-        GNUNET_break_op (0);
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Failed to parse `%s'\n",
+                    kslo->pay_uri);
         kdd.status = ANASTASIS_KSD_SERVER_ERROR;
         break;
       }
diff --git a/src/testing/test_anastasis_api.c b/src/testing/test_anastasis_api.c
index 797eb12..d0d1cb5 100644
--- a/src/testing/test_anastasis_api.c
+++ b/src/testing/test_anastasis_api.c
@@ -242,7 +242,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal-2",
                                             merchant_url,
                                             MHD_HTTP_OK,
-                                            "challenge-run-1",
+                                            "file-challenge-run-1",
                                             NULL),
     /* make the payment */
     TALER_TESTING_cmd_merchant_pay_order ("pay-account-2",
diff --git a/src/testing/testing_api_cmd_keyshare_lookup.c 
b/src/testing/testing_api_cmd_keyshare_lookup.c
index 63b8064..bdb7d37 100644
--- a/src/testing/testing_api_cmd_keyshare_lookup.c
+++ b/src/testing/testing_api_cmd_keyshare_lookup.c
@@ -25,6 +25,7 @@
 #include "anastasis_testing_lib.h"
 #include <taler/taler_util.h>
 #include <taler/taler_testing_lib.h>
+#include <taler/taler_merchant_service.h>
 
 
 /**
@@ -67,6 +68,31 @@ struct KeyShareLookupState
    */
   const char *payment_reference;
 
+  /**
+   * Payment secret requested by the service, if any.
+   */
+  struct ANASTASIS_PaymentSecretP payment_secret_response;
+
+  /**
+   * Taler-URI with payment request, if any.
+   */
+  char *pay_uri;
+
+  /**
+   * Order ID for payment request, if any.
+   */
+  char *order_id;
+
+  /**
+   * Redirect-URI for challenge, if any.
+   */
+  char *redirect_uri;
+
+  /**
+   * "instructions" for challenge, if any.
+   */
+  char *instructions;
+
   /**
    * Mode for the lookup(0 = question, 1 = code based)
    */
@@ -74,6 +100,7 @@ struct KeyShareLookupState
 
 };
 
+
 static void
 keyshare_lookup_cb (void *cls,
                     const struct ANASTASIS_KeyShareDownloadDetails *dd)
@@ -92,6 +119,43 @@ keyshare_lookup_cb (void *cls,
     TALER_TESTING_interpreter_fail (ksls->is);
     return;
   }
+  switch (dd->status)
+  {
+  case ANASTASIS_KSD_SUCCESS:
+    break;
+  case ANASTASIS_KSD_PAYMENT_REQUIRED:
+    ksls->pay_uri = GNUNET_strdup (dd->details.payment_required.taler_pay_uri);
+    ksls->payment_secret_response = 
dd->details.payment_required.payment_secret;
+    {
+      struct TALER_MERCHANT_PayUriData pd;
+
+      if (GNUNET_OK !=
+          TALER_MERCHANT_parse_pay_uri (ksls->pay_uri,
+                                        &pd))
+      {
+        GNUNET_break (0);
+        TALER_TESTING_interpreter_fail (ksls->is);
+        return;
+      }
+      ksls->order_id = GNUNET_strdup (pd.order_id);
+      TALER_MERCHANT_parse_pay_uri_free (&pd);
+    }
+
+    break;
+  case ANASTASIS_KSD_INVALID_ANSWER:
+    ksls->instructions = GNUNET_strdup (
+      dd->details.open_challenge.instructions);
+    break;
+  case ANASTASIS_KSD_REDIRECT_FOR_AUTHENTICATION:
+    ksls->redirect_uri = GNUNET_strdup (dd->details.redirect_url);
+    break;
+  case ANASTASIS_KSD_SERVER_ERROR:
+    break;
+  case ANASTASIS_KSD_CLIENT_FAILURE:
+    break;
+  case ANASTASIS_KSD_TRUTH_UNKNOWN:
+    break;
+  }
   TALER_TESTING_interpreter_next (ksls->is);
 }
 
@@ -251,10 +315,47 @@ keyshare_lookup_cleanup (void *cls,
     ANASTASIS_keyshare_lookup_cancel (ksls->kslo);
     ksls->kslo = NULL;
   }
+  GNUNET_free (ksls->pay_uri);
+  GNUNET_free (ksls->order_id);
+  GNUNET_free (ksls->instructions);
+  GNUNET_free (ksls->redirect_uri);
   GNUNET_free (ksls);
 }
 
 
+/**
+ * Offer internal data to other commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param[out] trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+keyshare_lookup_traits (void *cls,
+                        const void **ret,
+                        const char *trait,
+                        unsigned int index)
+{
+  struct KeyShareLookupState *ksls = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    ANASTASIS_TESTING_make_trait_payment_secret (0,
+                                                 
&ksls->payment_secret_response),
+    TALER_TESTING_make_trait_url (TALER_TESTING_UT_TALER_URL,
+                                  ksls->pay_uri),
+    TALER_TESTING_make_trait_order_id (0,
+                                       ksls->order_id),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
 struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_keyshare_lookup (
   const char *label,
@@ -280,7 +381,8 @@ ANASTASIS_TESTING_cmd_keyshare_lookup (
       .cls = ksls,
       .label = label,
       .run = &keyshare_lookup_run,
-      .cleanup = &keyshare_lookup_cleanup
+      .cleanup = &keyshare_lookup_cleanup,
+      .traits = &keyshare_lookup_traits
     };
 
     return cmd;

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