[age-withdraw] fixed h_commitment calculation in handler

This commit is contained in:
Özgür Kesim 2023-07-24 21:40:51 +02:00
parent 3e29bdfb8b
commit a1989efdab
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
4 changed files with 16 additions and 39 deletions

View File

@ -35,6 +35,7 @@
#include "taler-exchange-httpd_age-withdraw.h" #include "taler-exchange-httpd_age-withdraw.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_keys.h" #include "taler-exchange-httpd_keys.h"
#include "taler_util.h"
/** /**
@ -104,7 +105,7 @@ free_age_withdraw_context_resources (struct AgeWithdrawContext *awc)
* Parse the denominations and blinded coin data of an '/age-withdraw' request. * Parse the denominations and blinded coin data of an '/age-withdraw' request.
* *
* @param connection The MHD connection to handle * @param connection The MHD connection to handle
* @param j_denoms_h Array of n hashes of the denominations for the withdrawal, in JSON format * @param j_denom_hs Array of n hashes of the denominations for the withdrawal, in JSON format
* @param j_blinded_coin_evs Array of n arrays of kappa blinded envelopes of in JSON format for the coins. * @param j_blinded_coin_evs Array of n arrays of kappa blinded envelopes of in JSON format for the coins.
* @param[out] awc The context of the operation, only partially built at call time * @param[out] awc The context of the operation, only partially built at call time
* @param[out] mhd_ret The result if a reply is queued for MHD * @param[out] mhd_ret The result if a reply is queued for MHD
@ -122,6 +123,7 @@ parse_age_withdraw_json (
const char *error = NULL; const char *error = NULL;
unsigned int idx = 0; unsigned int idx = 0;
json_t *value = NULL; json_t *value = NULL;
struct GNUNET_HashContext *hash_context;
/* The age value MUST be on the beginning of an age group */ /* The age value MUST be on the beginning of an age group */
@ -160,6 +162,7 @@ parse_age_withdraw_json (
goto EXIT; goto EXIT;
awc->num_coins = num_coins; awc->num_coins = num_coins;
awc->commitment.num_coins = num_coins;
} }
/* Continue parsing the parts */ /* Continue parsing the parts */
@ -194,6 +197,9 @@ parse_age_withdraw_json (
awc->coin_evs = GNUNET_new_array (awc->num_coins * TALER_CNC_KAPPA, awc->coin_evs = GNUNET_new_array (awc->num_coins * TALER_CNC_KAPPA,
struct TALER_BlindedPlanchet); struct TALER_BlindedPlanchet);
hash_context = GNUNET_CRYPTO_hash_context_start ();
GNUNET_assert (NULL != hash_context);
/* Parse blinded envelopes. */ /* Parse blinded envelopes. */
json_array_foreach (j_blinded_coin_evs, idx, value) { json_array_foreach (j_blinded_coin_evs, idx, value) {
const json_t *j_kappa_coin_evs = value; const json_t *j_kappa_coin_evs = value;
@ -222,9 +228,6 @@ parse_age_withdraw_json (
size_t off = idx * TALER_CNC_KAPPA; size_t off = idx * TALER_CNC_KAPPA;
unsigned int kappa = 0; unsigned int kappa = 0;
enum GNUNET_GenericReturnValue ret; enum GNUNET_GenericReturnValue ret;
struct GNUNET_HashContext *hash_context;
hash_context = GNUNET_CRYPTO_hash_context_start ();
json_array_foreach (j_kappa_coin_evs, kappa, value) { json_array_foreach (j_kappa_coin_evs, kappa, value) {
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
@ -271,12 +274,13 @@ parse_age_withdraw_json (
} }
} }
/* Finally, calculate the h_commitment from all blinded envelopes */
GNUNET_CRYPTO_hash_context_finish (hash_context,
&awc->commitment.h_commitment.hash);
} }
}; /* json_array_foreach over j_blinded_coin_evs */ }; /* json_array_foreach over j_blinded_coin_evs */
/* Finally, calculate the h_commitment from all blinded envelopes */
GNUNET_CRYPTO_hash_context_finish (hash_context,
&awc->commitment.h_commitment.hash);
GNUNET_assert (NULL == error); GNUNET_assert (NULL == error);
@ -739,27 +743,6 @@ age_withdraw_transaction (void *cls,
&allowed_maximum_age, &allowed_maximum_age,
&reserve_birthday, &reserve_birthday,
&conflict); &conflict);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"XXXXXXX got from do_age_withdraw:"
"\n\tqs: %d"
"\n\tcommitment: %s"
"\n\tmax_age: %d"
"\n\tfound: %d"
"\n\tbalance_ok: %d"
"\n\tage_ok: %d"
"\n\tallowed_maximum_age: %d"
"\n\treserve_birthday: %d"
"\n\tconflict: %d\n",
qs,
GNUNET_h2s (&awc->commitment.h_commitment.hash),
awc->commitment.max_age,
found,
balance_ok,
age_ok,
allowed_maximum_age,
reserve_birthday,
conflict);
if (0 > qs) if (0 > qs)
{ {
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)

View File

@ -724,14 +724,6 @@ perform_protocol (
awbh->reserve_priv, awbh->reserve_priv,
&awbh->reserve_sig); &awbh->reserve_sig);
GNUNET_assert (GNUNET_OK ==
TALER_wallet_age_withdraw_verify (&awbh->h_commitment,
&awbh->amount_with_fee,
&awbh->age_mask,
awbh->max_age,
&awbh->reserve_pub,
&awbh->reserve_sig));
/* Initiate the POST-request */ /* Initiate the POST-request */
j_request_body = GNUNET_JSON_PACK ( j_request_body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_array_steal ("denom_hs", j_denoms), GNUNET_JSON_pack_array_steal ("denom_hs", j_denoms),

View File

@ -258,10 +258,10 @@ run (void *cls,
*/ */
struct TALER_TESTING_Command age_withdraw[] = { struct TALER_TESTING_Command age_withdraw[] = {
CMD_TRANSFER_TO_EXCHANGE ("create-reserve-kyc-1", CMD_TRANSFER_TO_EXCHANGE ("create-reserve-kyc-1",
"EUR:20.02"), "EUR:30.02"),
TALER_TESTING_cmd_check_bank_admin_transfer ( TALER_TESTING_cmd_check_bank_admin_transfer (
"check-create-reserve-1", "check-create-reserve-1",
"EUR:20.02", "EUR:30.02",
cred.user42_payto, cred.user42_payto,
cred.exchange_payto, cred.exchange_payto,
"create-reserve-kyc-1"), "create-reserve-kyc-1"),
@ -295,6 +295,8 @@ run (void *cls,
8, 8,
MHD_HTTP_OK, MHD_HTTP_OK,
"EUR:10", "EUR:10",
"EUR:5",
"EUR:5",
NULL), NULL),
TALER_TESTING_cmd_end (), TALER_TESTING_cmd_end (),
}; };

View File

@ -294,7 +294,7 @@ age_withdraw_run (
if (NULL == dpk) if (NULL == dpk)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to determine denomination key at %s\n", "Failed to determine denomination key for amount at %s\n",
(NULL != cmd) ? cmd->label : "<retried command>"); (NULL != cmd) ? cmd->label : "<retried command>");
GNUNET_break (0); GNUNET_break (0);
TALER_TESTING_interpreter_fail (is); TALER_TESTING_interpreter_fail (is);