exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit fee5dc76ce61aaec7c9f96e3f5581007fb3a0050
parent 4e256063b85d6c1f29e224a1b761d824bf266eb2
Author: Özgür Kesim <oec@codeblau.de>
Date:   Sat, 21 Nov 2026 12:57:28 +0100

exchange: refuse CS envelopes with a nonce not derived from blinding_seed (#12237, #12264)

The helper signs a Clause-Schnorr planchet under the nonce in the
planchet.  /withdraw and /melt now check, before any signing, that the
nonce of every CS envelope is the one derived from the request's
blinding_seed for the coin's index (TALER_cs_nonce_derive_indexed, the
same for every age-restriction or cut-and-choose batch of the coin), and
refuse the request otherwise (400, TALER_EC_GENERIC_PARAMETER_MALFORMED,
hint "coin_evs: nonce").  Without the check the client chooses the
nonce, the uniqueness of blinding_seed constrains nothing, and two
different blinded challenges signed under one nonce reveal the
denomination's private key.

The test test_exchange_api_cs_nonce_cs (#12264) passes.

Diffstat:
Msrc/exchange/taler-exchange-httpd_post-melt.c | 40++++++++++++++++++++++++++++++++++++++++
Msrc/exchange/taler-exchange-httpd_post-withdraw.c | 44++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_post-melt.c b/src/exchange/taler-exchange-httpd_post-melt.c @@ -51,6 +51,7 @@ enum MeltError MELT_ERROR_AMOUNT_WITH_FEE_INCORRECT, MELT_ERROR_BLINDING_SEED_REQUIRED, MELT_ERROR_COIN_CIPHER_MISMATCH, + MELT_ERROR_CS_NONCE_MISMATCH, MELT_ERROR_COIN_CONFLICTING_DENOMINATION_KEY, MELT_ERROR_COIN_EXPIRED_NO_ZOMBIE, MELT_ERROR_COIN_SIGNATURE_INVALID, @@ -926,6 +927,37 @@ phase_check_keys ( mc->request.cs_indices[j++] = i; } } + + /* The helper signs a CS planchet under the nonce in the planchet; it + must be the one derived from the blinding seed for the coin's index + (ext-cs.md (E1)), or the client chooses the nonce and two signatures + under one nonce reveal the denomination private key. */ + for (size_t i = 0; i < mc->request.refresh.num_coins; i++) + { + struct GNUNET_CRYPTO_CsSessionNonce nonce; + + if (! is_cs_denom[i]) + continue; + TALER_cs_nonce_derive_indexed (&mc->request.refresh.blinding_seed, + true, + (uint32_t) i, + &nonce); + for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++) + { + const struct GNUNET_CRYPTO_BlindedMessage *bm + = mc->request.planchets[k][i].blinded_message; + + if ( (GNUNET_CRYPTO_BSA_CS != bm->cipher) || + (0 != GNUNET_memcmp (&nonce, + &bm->details.cs_blinded_message.nonce)) ) + { + GNUNET_break_op (0); + SET_ERROR (mc, + MELT_ERROR_CS_NONCE_MISMATCH); + return; + } + } + } mc->phase++; } @@ -1627,6 +1659,14 @@ phase_generate_reply_error ( TALER_EC_GENERIC_PARAMETER_MALFORMED, "nonce reuse")); return; + case MELT_ERROR_CS_NONCE_MISMATCH: + finish_loop (mc, + TALER_MHD_reply_with_error ( + mc->rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "coin_evs: nonce")); + return; case MELT_ERROR_COIN_SIGNATURE_INVALID: finish_loop (mc, TALER_MHD_reply_with_ec ( diff --git a/src/exchange/taler-exchange-httpd_post-withdraw.c b/src/exchange/taler-exchange-httpd_post-withdraw.c @@ -56,6 +56,7 @@ enum WithdrawError WITHDRAW_ERROR_AMOUNT_PLUS_FEE_OVERFLOW, WITHDRAW_ERROR_BLINDING_SEED_REQUIRED, WITHDRAW_ERROR_CIPHER_MISMATCH, + WITHDRAW_ERROR_CS_NONCE_MISMATCH, WITHDRAW_ERROR_CONFIRMATION_SIGN, WITHDRAW_ERROR_DB_FETCH_FAILED, WITHDRAW_ERROR_DB_INVARIANT_FAILURE, @@ -1109,6 +1110,41 @@ phase_check_keys ( } } + /* The helper signs a CS planchet under the nonce in the planchet; it + must be the one derived from the blinding seed for the coin's index + (ext-cs.md (E1)). Otherwise the client chooses the nonce, and two + signatures under one nonce reveal the denomination private key. */ + for (size_t i = 0; i < wc->request.withdraw.num_coins; i++) + { + struct GNUNET_CRYPTO_CsSessionNonce nonce; + size_t kappa = wc->request.withdraw.age_proof_required + ? TALER_CNC_KAPPA + : 1; + + if (! is_cs_denom[i]) + continue; + TALER_cs_nonce_derive_indexed (&wc->request.withdraw.blinding_seed, + false, + (uint32_t) i, + &nonce); + for (size_t k = 0; k < kappa; k++) + { + const struct GNUNET_CRYPTO_BlindedMessage *bm + = wc->request.planchets[i + k * wc->request.withdraw.num_coins] + .blinded_message; + + if ( (GNUNET_CRYPTO_BSA_CS != bm->cipher) || + (0 != GNUNET_memcmp (&nonce, + &bm->details.cs_blinded_message.nonce)) ) + { + GNUNET_break_op (0); + SET_ERROR (wc, + WITHDRAW_ERROR_CS_NONCE_MISMATCH); + return; + } + } + } + wc->phase++; } @@ -1528,6 +1564,14 @@ phase_generate_reply_error ( TALER_EC_EXCHANGE_WITHDRAW_IDEMPOTENT_PLANCHET, NULL)); return; + case WITHDRAW_ERROR_CS_NONCE_MISMATCH: + finish_loop (wc, + TALER_MHD_reply_with_error ( + wc->rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "coin_evs: nonce")); + return; case WITHDRAW_ERROR_NONCE_REUSE: finish_loop (wc, TALER_MHD_reply_with_error (