commit 617fb934e289344d32fb14ce2c6947b3422510d8
parent 44fcd28d9b765a1e768e7eacc502b29d7a5a840b
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Mon, 3 Oct 2016 14:06:57 +0200
testcase for #4702
Diffstat:
2 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
@@ -50,16 +50,6 @@ struct MerchantInstance *mi;
struct PayContext;
/**
- * Information to return to the wallet whenever the merchant does
- * not echo back something returned by the exchange. Currently used
- * to return signed 200 OK responses
- */
-struct MerchantResponse
-{
- struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
-};
-
-/**
* Information kept during a /pay request for each coin.
*/
struct DepositConfirmation
@@ -356,7 +346,7 @@ deposit_cb (void *cls,
struct DepositConfirmation *dc = cls;
struct PayContext *pc = dc->pc;
struct GNUNET_CRYPTO_EddsaSignature sig;
- struct MerchantResponse mr;
+ struct PaymentResponsePS mr;
dc->dh = NULL;
pc->pending--;
@@ -428,7 +418,11 @@ deposit_cb (void *cls,
resume_pay_with_response (pc,
MHD_HTTP_OK,
TMH_RESPONSE_make_json_pack ("{s:s}",
- "merchant_sig", GNUNET_JSON_from_data_auto (&sig)));
+ "merchant_sig",
+ json_string_value (GNUNET_JSON_from_data_auto (&sig))));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "responding with: %s\n",
+ json_string_value (GNUNET_JSON_from_data_auto (&sig)));
}
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
@@ -441,6 +441,11 @@ struct Command
*/
uint64_t transaction_id;
+ /**
+ * Merchant's public key
+ */
+ struct TALER_MerchantPublicKeyP merchant_pub;
+
} pay;
struct {
@@ -1000,6 +1005,9 @@ pay_cb (void *cls,
{
struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip];
+ struct PaymentResponsePS mr;
+ struct GNUNET_CRYPTO_EddsaSignature sig;
+ json_t *jsig;
cmd->details.pay.ph = NULL;
if (cmd->expected_response_code != http_status)
@@ -1012,6 +1020,36 @@ pay_cb (void *cls,
fail (is);
return;
}
+ if (MHD_HTTP_OK == http_status)
+ {
+ /* Check signature */
+ GNUNET_break (NULL !=
+ (jsig = json_object_get (obj, "merchant_sig")));
+ mr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_PAYMENT_OK);
+ mr.purpose.size = htonl (sizeof (mr));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Got DP: %s\n",
+ json_dumps (obj,
+ JSON_INDENT (2)));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_string_to_data (json_string_value (jsig),
+ strlen (json_string_value (jsig)),
+ &sig,
+ sizeof (sig)));
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_PAYMENT_OK,
+ &mr.purpose,
+ &sig,
+ &cmd->details.pay.merchant_pub.eddsa_pub))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Merchant signature given in response to /pay invalid\n");
+ fail (is);
+ return;
+ }
+
+ }
+
next_command (is);
}
@@ -1592,6 +1630,7 @@ interpreter_run (void *cls)
return;
}
cmd->details.pay.transaction_id = transaction_id;
+ cmd->details.pay.merchant_pub = merchant_pub;
}
TALER_JSON_hash (ref->details.contract.contract,