[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/02: Worked on payment for policy upload
From: |
gnunet |
Subject: |
[taler-anastasis] 01/02: Worked on payment for policy upload |
Date: |
Tue, 21 Jan 2020 12:29:02 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 4ed17d27d55726f0d8ff987549d071e80c332369
Author: Dennis Neufeld <address@hidden>
AuthorDate: Mon Jan 20 22:42:03 2020 +0000
Worked on payment for policy upload
---
src/backend/anastasis-httpd.c | 19 +++++--
src/backend/anastasis-httpd_policy_upload.c | 78 +++++++++++++++++------------
src/include/anastasis_crypto_lib.h | 2 +-
src/lib/anastasis_api_policy_store.c | 32 ++++++++++--
src/lib/test_anastasis_api.c | 34 +++++--------
src/lib/test_anastasis_api.conf | 12 ++---
src/lib/testing_api_cmd_policy_store.c | 33 ++----------
7 files changed, 114 insertions(+), 96 deletions(-)
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 8d31620..a923e0c 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -290,11 +290,20 @@ url_handler (void *cls,
}
if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
{
- return AH_handler_policy_post (connection,
- con_cls,
- url,
- upload_data,
- upload_data_size);
+ int ret;
+ ret = AH_handler_policy_post (connection,
+ con_cls,
+ url,
+ upload_data,
+ upload_data_size);
+ hc = *con_cls;
+ if (NULL != hc)
+ {
+ /* Store the async context ID, so we can restore it if
+ * we get another callack for this request. */
+ hc->async_scope_id = aid;
+ }
+ return ret;
}
}
if (0 == strncmp (url,
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index 15b3c05..f6336f8 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -374,7 +374,10 @@ check_payment_cb (void *cls,
if (NULL != puc->existing_order_id)
{
/* repeat payment request */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Repeating payment request\n");
puc->resp = make_payment_request (puc->existing_order_id);
+ GNUNET_assert (NULL != puc->resp);
puc->response_code = MHD_HTTP_PAYMENT_REQUIRED;
return;
}
@@ -382,6 +385,7 @@ check_payment_cb (void *cls,
"Timeout waiting for payment\n");
puc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_TIMEOUT,
"Timeout awaiting promised payment");
+ GNUNET_assert (NULL != puc->resp);
puc->response_code = MHD_HTTP_REQUEST_TIMEOUT;
}
@@ -451,11 +455,20 @@ begin_payment (struct PolicyUploadContext *puc,
return ret;
}
- // generate new payment identifier
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- &puc->payment_identifier,
- sizeof (
- struct ANASTASIS_PaymentSecretP));
+ if (NULL == puc->order_id)
+ {
+ // generate new payment identifier
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &puc->payment_identifier,
+ sizeof (
+ struct ANASTASIS_PaymentSecretP));
+
+ order_id = GNUNET_STRINGS_data_to_string_alloc (&puc->payment_identifier,
+ sizeof(
+ struct
+
ANASTASIS_PaymentSecretP));
+
+ }
if (qs == ANASTASIS_DB_STATUS_NO_RESULTS)
{
@@ -466,11 +479,16 @@ begin_payment (struct PolicyUploadContext *puc,
GNUNET_TIME_UNIT_ZERO);
}
- order_id = GNUNET_STRINGS_data_to_string_alloc (&puc->payment_identifier,
- sizeof(
- struct
- ANASTASIS_PaymentSecretP));
- puc->order_id = order_id;
+ if (NULL != puc->existing_order_id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Have existing order, waiting for `%s' to complete\n",
+ puc->existing_order_id);
+ await_payment (puc,
+ GNUNET_TIME_UNIT_ZERO /* no long polling */,
+ puc->existing_order_id);
+ return MHD_YES;
+ }
GNUNET_CONTAINER_DLL_insert (puc_head,
puc_tail,
@@ -479,19 +497,22 @@ begin_payment (struct PolicyUploadContext *puc,
"Suspending connection while creating order at `%s'\n",
AH_backend_url);
MHD_suspend_connection (puc->con);
- order = json_pack ("{s:o, s:s, s:s}",
+ order = json_pack ("{s:o, s:s, s:s, s:s}",
"amount", TALER_JSON_from_amount (&AH_annual_fee),
"summary", "annual fee for anastasis service",
"fulfillment_url", AH_fulfillment_url,
"order_id", order_id);
+
puc->po = TALER_MERCHANT_order_put (AH_ctx,
AH_backend_url,
order,
&proposal_cb,
puc);
+
+ puc->existing_order_id = order_id;
+
AH_trigger_curl ();
json_decref (order);
- GNUNET_free_non_null (&order_id);
return MHD_YES;
}
@@ -522,12 +543,9 @@ handle_database_error (struct PolicyUploadContext *puc,
{
char *order_id;
- order_id = GNUNET_STRINGS_data_to_string_alloc (&puc->payment_identifier,
- sizeof (
- struct
-
ANASTASIS_PaymentSecretP));
-
- puc->order_id = order_id;
+ order_id = MHD_lookup_connection_value (puc->con,
+ MHD_GET_ARGUMENT_KIND,
+ "paying");
if ((NULL == order_id) || GNUNET_is_zero (order_id))
{
@@ -536,6 +554,7 @@ handle_database_error (struct PolicyUploadContext *puc,
return begin_payment (puc,
GNUNET_NO);
}
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Payment required, awaiting completion of `%s'\n",
order_id);
@@ -793,20 +812,21 @@ AH_handler_policy_post (struct MHD_Connection *connection,
resp = MHD_create_response_from_buffer (0,
NULL,
MHD_RESPMEM_PERSISTENT);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
-
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
- "*"));
+ TALER_MHD_add_global_headers (resp);
ret = MHD_queue_response (connection,
MHD_HTTP_NOT_MODIFIED,
resp);
+ (MHD_YES == ret);
MHD_destroy_response (resp);
return ret;
}
+
if (0 != GNUNET_memcmp (&hc,
&puc->old_policy_upload_hash))
{
/* Refuse upload: if-none-match failed! */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Conflict detected, returning existing recovery
document\n");
return AH_return_policy (connection,
&accountPubP,
MHD_HTTP_CONFLICT);
@@ -814,7 +834,6 @@ AH_handler_policy_post (struct MHD_Connection *connection,
}
/* check if the client insists on paying */
{
- // FIXME: How should the client show his will to pay?
const char *order_req;
order_req = MHD_lookup_connection_value (connection,
@@ -897,7 +916,8 @@ AH_handler_policy_post (struct MHD_Connection *connection,
// FIXME: version has to be delivered by header
uint32_t version;
-
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Uploading recovery document\n");
qs = db->store_recovery_document (db->cls,
&accountPubP,
&puc->account_sig,
@@ -921,10 +941,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
resp = MHD_create_response_from_buffer (0,
NULL,
MHD_RESPMEM_PERSISTENT);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
-
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
- "*"));
+ TALER_MHD_add_global_headers (resp);
ret = MHD_queue_response (connection,
MHD_HTTP_NOT_MODIFIED,
resp);
@@ -941,10 +958,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
resp = MHD_create_response_from_buffer (0,
NULL,
MHD_RESPMEM_PERSISTENT);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
-
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
- "*"));
+ TALER_MHD_add_global_headers (resp);
ret = MHD_queue_response (connection,
MHD_HTTP_NO_CONTENT,
resp);
diff --git a/src/include/anastasis_crypto_lib.h
b/src/include/anastasis_crypto_lib.h
index aa22b66..f406aa0 100644
--- a/src/include/anastasis_crypto_lib.h
+++ b/src/include/anastasis_crypto_lib.h
@@ -24,7 +24,7 @@ struct ANASTAIS_CRYPTO_Encrypted_Truth;
struct ANASTASIS_CRYPTO_AccountSignatureP
{
- struct GNUNET_CRYPTO_EddsaSignatureP eddsa_sig;
+ struct GNUNET_CRYPTO_EddsaSignature eddsa_sig;
};
struct ANASTASIS_CRYPTO_KeyShare
diff --git a/src/lib/anastasis_api_policy_store.c
b/src/lib/anastasis_api_policy_store.c
index 13172f3..61b1da0 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -232,8 +232,18 @@ handle_header (char *buffer,
if (0 == strcasecmp (hdr_type,
"Taler"))
{
+ size_t len;
+
/* found payment URI we care about! */
pso->pay_uri = GNUNET_strdup (hdr_val);
+ len = strlen (pso->pay_uri);
+ while ( (len > 0) &&
+ ( ('\n' == pso->pay_uri[len - 1]) ||
+ ('\r' == pso->pay_uri[len - 1]) ) )
+ {
+ len--;
+ pso->pay_uri[len] = '\0';
+ }
}
GNUNET_free (ndup);
return total;
@@ -282,6 +292,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
usp.purpose.size = htonl (sizeof (usp));
if (NULL != prev_recovery_data_hash)
usp.old_recovery_data_hash = *prev_recovery_data_hash;
+
GNUNET_CRYPTO_hash (recovery_data,
recovery_data_size,
&usp.new_recovery_data_hash);
@@ -357,7 +368,6 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
}
job_headers = ext;
}
-
/* Setup Payment-Identifier header */
if (NULL != paymentSecretP)
{
@@ -397,8 +407,24 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
"policy/%s",
acc_pub_str);
GNUNET_free (acc_pub_str);
- pso->url = TALER_url_join (backend_url,
- path);
+
+ pso->url = (GNUNET_YES == payment_requested)
+ ? TALER_url_join (backend_url,
+ path,
+ "pay",
+ "y",
+ (NULL != paymentSecretP)
+ ? "paying"
+ : NULL,
+ paymentSecretP,
+ NULL)
+ : TALER_url_join (backend_url,
+ path,
+ (NULL != paymentSecretP)
+ ? "paying"
+ : NULL,
+ paymentSecretP,
+ NULL);
GNUNET_free (path);
}
pso->ctx = ctx;
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
index 33348ec..991853b 100644
--- a/src/lib/test_anastasis_api.c
+++ b/src/lib/test_anastasis_api.c
@@ -37,6 +37,7 @@
#include <taler/taler_error_codes.h>
#include <taler/taler_merchant_testing_lib.h>
#include "anastasis_testing_lib.h"
+#include "anastasis_service.h"
/**
* Configuration file we use. One (big) configuration is used
@@ -70,24 +71,24 @@ static char *merchant_url;
static char *anastasis_url;
/**
- * Merchant process.
+ * Exchange base URL.
*/
-static struct GNUNET_OS_Process *merchantd;
+static char *exchange_url;
/**
- * Anastasis process.
+ * Auditor base URL; only used to fix FTBFS.
*/
-static struct GNUNET_OS_Process *anastasisd;
+static char *auditor_url;
/**
- * Exchange base URL.
+ * Merchant process.
*/
-static char *exchange_url;
+static struct GNUNET_OS_Process *merchantd;
/**
- * Auditor base URL; only used to fix FTBFS.
+ * Anastasis process.
*/
-static char *auditor_url;
+static struct GNUNET_OS_Process *anastasisd;
/**
* Account number of the exchange at the bank.
@@ -224,7 +225,6 @@ static void
run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
-
// fill data
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&paymentSecret,
@@ -241,14 +241,6 @@ run (void *cls,
* transfer.
*/
CMD_EXEC_WIREWATCH ("wirewatch-1"),
-
- TALER_TESTING_cmd_check_bank_transfer
- ("check_bank_transfer-2",
- EXCHANGE_URL,
- "EUR:10.02",
- USER_ACCOUNT_NO,
- EXCHANGE_ACCOUNT_NO),
-
TALER_TESTING_cmd_withdraw_amount
("withdraw-coin-1",
"create-reserve-1",
@@ -303,10 +295,10 @@ run (void *cls,
ANASTASIS_TESTING_cmd_policy_store ("policy-store-2",
anastasis_url,
"policy-store-1",
- MHD_HTTP_OK,
+ MHD_HTTP_NO_CONTENT,
ANASTASIS_TESTING_PSO_NONE,
- "Test-2",
- strlen ("Test-2")),
+ "Test-1",
+ strlen ("Test-1")),
ANASTASIS_TESTING_cmd_policy_lookup ("policy-lookup-1",
anastasis_url,
@@ -363,6 +355,7 @@ main (int argc,
(CONFIG_FILE,
"account-exchange")))
return 77;
+
if (NULL ==
(merchant_url = TALER_TESTING_prepare_merchant (CONFIG_FILE)))
return 77;
@@ -384,7 +377,6 @@ main (int argc,
return 77;
case GNUNET_OK:
-
if (NULL == (merchantd =
TALER_TESTING_run_merchant (CONFIG_FILE, merchant_url)))
return 1;
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index 7c5bbf9..c0cf0be 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -2,16 +2,16 @@
#
[PATHS]
# Persistant data storage for the testcase
-TALER_TEST_HOME = test_anastasis_api_home
+TALER_TEST_HOME = test_anastasis_api_home/
# Persistant data storage
-TALER_DATA_HOME = $TALER_HOME/.local/share/taler
+TALER_DATA_HOME = $TALER_HOME/.local/share/taler/
# Configuration files
-TALER_CONFIG_HOME = $TALER_HOME/.config/taler
+TALER_CONFIG_HOME = $TALER_HOME/.config/taler/
# Cached data, no big deal if lost
-TALER_CACHE_HOME = $TALER_HOME/.cache/taler
+TALER_CACHE_HOME = $TALER_HOME/.cache/taler/
[taler]
# What currency do we use?
@@ -28,7 +28,7 @@ PORT = 8086
DB = postgres
# Base URL of anastasis.
-BASE_URL = http://localhost:8086/
+# BASE_URL = http://localhost:8086/
# Where does our payment backend run? Must match PORT under [merchant]
PAYMENT_BACKEND_URL = http://localhost:8080/
@@ -217,7 +217,7 @@ BASE_URL = "http://localhost:8081/"
CONFIG = "postgres:///talercheck"
[auditordb-postgres]
-CONFIG = postgres:///talercheck
+CONFIG = "postgres:///talercheck"
# Account of the EXCHANGE
[account-exchange]
diff --git a/src/lib/testing_api_cmd_policy_store.c
b/src/lib/testing_api_cmd_policy_store.c
index 64a86b1..e5b2c09 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -143,10 +143,6 @@ policy_store_cb (void *cls,
pss->pso = NULL;
if (http_status != pss->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "\n\n\n HTTP-STATUS 1: %d\n HTTP-STATUS 2: %d\n\n\n",
- http_status,
- pss->http_status);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u to command %s in %s:%u\n",
http_status,
@@ -262,7 +258,6 @@ policy_store_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct PolicyStoreState *pss = cls;
-
pss->is = is;
if (NULL != pss->prev_upload)
{
@@ -341,7 +336,7 @@ policy_store_run (void *cls,
}
}
}
-
+ else
{
// Create an eddsa private key
struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
@@ -352,38 +347,19 @@ policy_store_run (void *cls,
&pss->anastasis_pub.pub);
GNUNET_free (priv);
}
- {
+ /*{
// generate nonce
GNUNET_CRYPTO_random_block
(GNUNET_CRYPTO_QUALITY_WEAK,
&pss->nonce,
sizeof (pss->nonce));
- }
+ }*/
{
// hash recovery data
GNUNET_CRYPTO_hash (pss->recovery_data,
pss->recovery_data_size,
&pss->curr_hash);
}
- if (NULL != pss->payment_order_req)
- {
- if (! GNUNET_is_zero (pss->payment_order_req))
- {
- const char *pay_req;
- struct ANASTASIS_PaymentSecretP pay_sec;
-
- pay_req = pss->payment_order_req;
-
- GNUNET_STRINGS_string_to_data (pay_req,
- strlen (pay_req),
- &pay_sec,
- sizeof (
- struct ANASTASIS_PaymentSecretP));
- pss->payment_id = &pay_sec;
- GNUNET_free (&pay_req);
- GNUNET_free (&pay_sec);
- }
- }
pss->pso = ANASTASIS_policy_store (is->ctx,
pss->anastasis_url,
&pss->anastasis_priv,
@@ -436,7 +412,7 @@ policy_store_cleanup (void *cls,
pss->pso = NULL;
}
- // GNUNET_free_non_null ((void *) pss->order_id);
+ GNUNET_free_non_null ((void *) pss->payment_order_id);
GNUNET_free (pss);
}
@@ -509,6 +485,7 @@ ANASTASIS_TESTING_cmd_policy_store (const char *label,
pss->http_status = http_status;
pss->psopt = pso;
pss->anastasis_url = anastasis_url;
+ pss->prev_upload = prev_upload;
struct TALER_TESTING_Command cmd = {
.cls = pss,
--
To stop receiving notification emails like this one, please contact
address@hidden.