commit 2e6bedf7faeecdac7e3da70f5a8618a46feccf29
parent 7bd219d33ff963db6b3aafb8ca055a9a503aac30
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Thu, 1 May 2025 13:03:39 +0200
use a bool to return from find_denomination(), as we anyway no longer do the idempotency check here so the previous comment was wrong
Diffstat:
1 file changed, 50 insertions(+), 49 deletions(-)
diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c
@@ -864,9 +864,8 @@ phase_run_legi_check (struct WithdrawContext *wc)
* @param ksh The handle to the current state of (denomination) keys in the exchange
* @param denom_h Hash of the denomination key to check
* @param[out] pdk denomination key found, might be NULL
- * @return GNUNET_OK when denomation was found and valid,
- * GNUNET_NO when denomination was not valid but request was idempotent,
- * GNUNET_SYSERR otherwise (denomination invalid), with finish_loop called.
+ * @return true when denomation was found and valid,
+ * false when denomination was not valid and the state machine was advanced
*/
static enum GNUNET_GenericReturnValue
find_denomination (
@@ -888,7 +887,7 @@ find_denomination (
SET_ERROR_WITH_FIELD (wc,
WITHDRAW_ERROR_DENOMINATION_KEY_UNKNOWN,
denom_h);
- return GNUNET_NO;
+ return false;
}
if (GNUNET_TIME_absolute_is_past (
dk->meta.expire_withdraw.abs_time))
@@ -896,7 +895,7 @@ find_denomination (
SET_ERROR_WITH_FIELD (wc,
WITHDRAW_ERROR_DENOMINATION_EXPIRED,
denom_h);
- return GNUNET_SYSERR;
+ return false;
}
if (GNUNET_TIME_absolute_is_future (
dk->meta.start.abs_time))
@@ -905,13 +904,13 @@ find_denomination (
SET_ERROR_WITH_FIELD (wc,
WITHDRAW_ERROR_DENOMINATION_VALIDITY_IN_FUTURE,
denom_h);
- return GNUNET_SYSERR;
+ return false;
}
if (dk->recoup_possible)
{
SET_ERROR (wc,
WITHDRAW_ERROR_DENOMINATION_REVOKED);
- return GNUNET_SYSERR;
+ return false;
}
/* In case of age withdraw, make sure that the denomination supports age restriction */
if (wc->request.withdraw.age_proof_required)
@@ -922,11 +921,11 @@ find_denomination (
SET_ERROR_WITH_FIELD (wc,
WITHDRAW_ERROR_AGE_RESTRICTION_NOT_SUPPORTED_BY_DENOMINATION,
denom_h);
- return GNUNET_SYSERR;
+ return false;
}
}
*pdk = dk;
- return GNUNET_OK;
+ return true;
}
@@ -949,7 +948,6 @@ phase_check_keys (
memset (is_cs_denom,
0,
sizeof(is_cs_denom));
-
ksh = TEH_keys_get_state ();
if (NULL == ksh)
{
@@ -975,15 +973,20 @@ phase_check_keys (
{
struct TEH_DenominationKey *dk;
- if (GNUNET_OK != find_denomination (wc,
- ksh,
- &wc->request.denoms_h[i],
- &dk))
+ if (! find_denomination (wc,
+ ksh,
+ &wc->request.denoms_h[i],
+ &dk))
return;
-
- if (GNUNET_CRYPTO_BSA_CS ==
- dk->denom_pub.bsign_pub_key->cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
{
+ case GNUNET_CRYPTO_BSA_INVALID:
+ /* This should never happen (memory corruption?) */
+ GNUNET_assert (0);
+ case GNUNET_CRYPTO_BSA_RSA:
+ /* nothing to do here */
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
if (wc->request.withdraw.no_blinding_seed)
{
GNUNET_break_op (0);
@@ -993,6 +996,7 @@ phase_check_keys (
}
wc->request.withdraw.num_cs_r_values++;
is_cs_denom[i] = true;
+ break;
}
/* Ensure the ciphers from the planchets match the denominations'. */
@@ -1129,7 +1133,6 @@ static void
phase_check_reserve_signature (
struct WithdrawContext *wc)
{
-
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
TALER_wallet_withdraw_verify (
@@ -1137,14 +1140,14 @@ phase_check_reserve_signature (
&wc->request.fee,
&wc->request.withdraw.planchets_h,
wc->request.withdraw.no_blinding_seed
- ? NULL
- : &wc->request.withdraw.blinding_seed,
+ ? NULL
+ : &wc->request.withdraw.blinding_seed,
(wc->request.withdraw.age_proof_required)
- ? &TEH_age_restriction_config.mask
- : NULL,
+ ? &TEH_age_restriction_config.mask
+ : NULL,
(wc->request.withdraw.age_proof_required)
- ? wc->request.withdraw.max_age
- : 0,
+ ? wc->request.withdraw.max_age
+ : 0,
&wc->request.withdraw.reserve_pub,
&wc->request.withdraw.reserve_sig))
{
@@ -1153,12 +1156,28 @@ phase_check_reserve_signature (
WITHDRAW_ERROR_RESERVE_SIGNATURE_INVALID);
return;
}
-
wc->phase++;
}
/**
+ * Free data inside of @a wd, but not @a wd itself.
+ *
+ * @param[in] wd withdraw data to free
+ */
+static void
+free_db_withdraw_data (struct TALER_EXCHANGEDB_Withdraw *wd)
+{
+ if (NULL != wd->denom_sigs)
+ for (unsigned int i = 0; i<wd->num_coins; i++)
+ TALER_blinded_denom_sig_free (&wd->denom_sigs[i]);
+ GNUNET_free (wd->denom_sigs);
+ GNUNET_free (wd->denom_serials);
+ GNUNET_free (wd->cs_r_values);
+}
+
+
+/**
* Cleanup routine for withdraw request.
* The function is called upon completion of the request
* that should clean up @a rh_ctx. Can be NULL.
@@ -1175,38 +1194,20 @@ clean_withdraw_rc (struct TEH_RequestContext *rc)
TEH_legitimization_check_cancel (wc->lch);
wc->lch = NULL;
}
-
GNUNET_free (wc->request.denoms_h);
for (unsigned int i = 0; i<wc->request.num_planchets; i++)
TALER_blinded_planchet_free (&wc->request.planchets[i]);
-
GNUNET_free (wc->request.planchets);
- if (NULL != wc->request.withdraw.denom_sigs)
- for (unsigned int i = 0; i<wc->request.withdraw.num_coins; i++)
- TALER_blinded_denom_sig_free (&wc->request.withdraw.denom_sigs[i]);
-
- GNUNET_free (wc->request.withdraw.denom_sigs);
- GNUNET_free (wc->request.withdraw.denom_serials);
- GNUNET_free (wc->request.withdraw.cs_r_values);
+ free_db_withdraw_data (&wc->request.withdraw);
GNUNET_free (wc->request.cs_indices);
-
if (wc->request.is_idempotent)
- {
- for (unsigned int i = 0; i<wc->request.withdraw_idem.num_coins; i++)
- TALER_blinded_denom_sig_free (&wc->request.withdraw_idem.denom_sigs[i]);
-
- GNUNET_free (wc->request.withdraw_idem.denom_sigs);
- GNUNET_free (wc->request.withdraw_idem.denom_serials);
- GNUNET_free (wc->request.withdraw_idem.cs_r_values);
- }
-
- if (WITHDRAW_ERROR_LEGITIMIZATION_RESULT == wc->error.code &&
- NULL != wc->error.details.legitimization_result.response)
+ free_db_withdraw_data (&wc->request.withdraw_idem);
+ if ( (WITHDRAW_ERROR_LEGITIMIZATION_RESULT == wc->error.code) &&
+ (NULL != wc->error.details.legitimization_result.response) )
{
MHD_destroy_response (wc->error.details.legitimization_result.response);
wc->error.details.legitimization_result.response = NULL;
}
-
GNUNET_free (wc);
}
@@ -1222,8 +1223,8 @@ phase_generate_reply_success (struct WithdrawContext *wc)
struct TALER_EXCHANGEDB_Withdraw *db_obj;
db_obj = wc->request.is_idempotent
- ? &wc->request.withdraw_idem
- : &wc->request.withdraw;
+ ? &wc->request.withdraw_idem
+ : &wc->request.withdraw;
if (wc->request.withdraw.age_proof_required)
{