exchange

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

commit 11f9a80ba8b8abc12205ee5a72f7e9e27f244f93
parent d65dd114687f5eab40ef62caf1a5f156f00f667e
Author: Özgür Kesim <oec@codeblau.de>
Date:   Tue, 27 Oct 2026 12:06:16 +0100

[lib] v45: choose the commitment by the exchange's version (#11862)

TALER_TESTING_cmd_melt_with_legacy_commitment() tests the fallback.

Diffstat:
Msrc/include/taler/exchange/post-melt.h | 8++++++++
Msrc/include/taler/exchange/post-reveal-melt.h | 6++++++
Msrc/include/taler/taler_testing_lib.h | 13+++++++++++++
Msrc/lib/exchange_api_handle.c | 4++--
Msrc/lib/exchange_api_post-melt.c | 3+++
Msrc/lib/exchange_api_post-reveal-melt.c | 1+
Msrc/lib/exchange_api_refresh_common.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/lib/exchange_api_refresh_common.h | 22++++++++++++++++++++++
Msrc/testing/test_exchange_api.c | 36++++++++++++++++++++++++++++++++++++
Msrc/testing/testing_api_cmd_refresh.c | 109++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
10 files changed, 233 insertions(+), 25 deletions(-)

diff --git a/src/include/taler/exchange/post-melt.h b/src/include/taler/exchange/post-melt.h @@ -109,6 +109,14 @@ struct TALER_EXCHANGE_PostMeltResponse * /reveal-melt and /recoup-refresh. */ struct TALER_RefreshCommitmentP rc; + + /** + * Version of the refresh commitment @e rc, chosen by the client + * library according to the protocol version of the exchange. + * Not part of the response of the server; it must be passed to + * /reveal-melt in #TALER_EXCHANGE_RevealMeltInput. + */ + enum TALER_RefreshCommitmentVersion rc_version; } ok; /** diff --git a/src/include/taler/exchange/post-reveal-melt.h b/src/include/taler/exchange/post-reveal-melt.h @@ -170,6 +170,12 @@ struct TALER_EXCHANGE_RevealMeltInput */ uint32_t noreveal_index; + /** + * Version of the refresh commitment that was used during the call + * to /melt, as returned by it. + */ + enum TALER_RefreshCommitmentVersion rc_version; + }; diff --git a/src/include/taler/taler_testing_lib.h b/src/include/taler/taler_testing_lib.h @@ -1647,6 +1647,19 @@ TALER_TESTING_cmd_melt_with_retry (struct TALER_TESTING_Command cmd); /** + * Modify a "refresh melt" command to melt like a client facing an + * exchange from before protocol v45, which only accepts the refresh + * commitment without the transfer public keys (#11862). + * + * @param cmd command + * @return modified command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_melt_with_legacy_commitment ( + struct TALER_TESTING_Command cmd); + + +/** * Create a "refresh reveal" command. * * @param label command label. diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c @@ -35,12 +35,12 @@ * Which version of the Taler protocol is implemented * by this library? Used to determine compatibility. */ -#define EXCHANGE_PROTOCOL_CURRENT 42 +#define EXCHANGE_PROTOCOL_CURRENT 45 /** * How many versions are we backwards compatible with? */ -#define EXCHANGE_PROTOCOL_AGE 0 +#define EXCHANGE_PROTOCOL_AGE 3 /** * Set to 1 for extra debug logging. diff --git a/src/lib/exchange_api_post-melt.c b/src/lib/exchange_api_post-melt.c @@ -281,6 +281,7 @@ handle_melt_finished (void *cls, } mr.details.ok.noreveal_index = mh->noreveal_index; mr.details.ok.rc = mh->md.rc; + mr.details.ok.rc_version = mh->md.rc_version; mr.details.ok.num_melt_blinding_values = mh->rd->num_fresh_denom_pubs; mr.details.ok.melt_blinding_values = mh->melt_blinding_values; mr.details.ok.blinding_seed = mh->no_blinding_seed @@ -384,6 +385,8 @@ start_melt (struct TALER_EXCHANGE_PostMeltHandle *mh) ? NULL : &mh->blinding_seed, mh->melt_blinding_values, + TALER_EXCHANGE_refresh_commitment_version_ ( + mh->keys), &mh->md)) { GNUNET_break (0); diff --git a/src/lib/exchange_api_post-reveal-melt.c b/src/lib/exchange_api_post-reveal-melt.c @@ -394,6 +394,7 @@ TALER_EXCHANGE_post_reveal_melt_create ( reveal_melt_input->melt_input, reveal_melt_input->blinding_seed, reveal_melt_input->blinding_values, + reveal_melt_input->rc_version, &mrh->md)) { GNUNET_break (0); diff --git a/src/lib/exchange_api_refresh_common.c b/src/lib/exchange_api_refresh_common.c @@ -65,6 +65,7 @@ TALER_EXCHANGE_get_melt_data ( const struct TALER_EXCHANGE_MeltInput *rd, const struct TALER_BlindingMasterSeedP *blinding_seed, const struct TALER_ExchangeBlindingValues *blinding_values, + enum TALER_RefreshCommitmentVersion rc_version, struct MeltData *md) { struct TALER_Amount total; @@ -76,10 +77,21 @@ TALER_EXCHANGE_get_melt_data ( GNUNET_CRYPTO_eddsa_key_get_public (&rd->melt_priv.eddsa_priv, &coin_pub.eddsa_pub); + switch (rc_version) + { + case TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN: + case TALER_REFRESH_COMMITMENT_VERSION_CURRENT: + break; + default: + /* v27 is not implemented by this library */ + GNUNET_break (0); + return GNUNET_SYSERR; + } memset (md, 0, sizeof (*md)); /* build up melt data structure */ + md->rc_version = rc_version; md->refresh_seed = *rms; md->num_fresh_coins = rd->num_fresh_denom_pubs; md->melted_coin.coin_priv = rd->melt_priv; @@ -277,6 +289,19 @@ TALER_EXCHANGE_get_melt_data ( } /* Finally, compute refresh commitment */ + if (TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN == rc_version) + { + TALER_refresh_get_commitment_legacy_vDOLDPLUS_broken ( + &md->rc, + &md->refresh_seed, + uses_cs + ? &md->blinding_seed + : NULL, + &k_h_bps, + &coin_pub, + &rd->melt_amount); + } + else { struct TALER_KappaTransferPublicKeys k_tr_pubs = { .num_transfer_pubs = md->num_fresh_coins, @@ -297,3 +322,34 @@ TALER_EXCHANGE_get_melt_data ( } return GNUNET_OK; } + + +/** + * First version of the exchange protocol that accepts the refresh + * commitment with the transfer public keys (#11862). + */ +#define EXCHANGE_PROTOCOL_REFRESH_COMMITMENT_CURRENT 45 + + +enum TALER_RefreshCommitmentVersion +TALER_EXCHANGE_refresh_commitment_version_ ( + const struct TALER_EXCHANGE_Keys *keys) +{ + struct TALER_JSON_ProtocolVersion pv; + char dummy; + + if ( (NULL == keys->version) || + (3 != sscanf (keys->version, + "%u:%u:%u%c", + &pv.current, + &pv.revision, + &pv.age, + &dummy)) ) + { + GNUNET_break_op (0); + return TALER_REFRESH_COMMITMENT_VERSION_CURRENT; + } + if (pv.current < EXCHANGE_PROTOCOL_REFRESH_COMMITMENT_CURRENT) + return TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN; + return TALER_REFRESH_COMMITMENT_VERSION_CURRENT; +} diff --git a/src/lib/exchange_api_refresh_common.h b/src/lib/exchange_api_refresh_common.h @@ -126,6 +126,11 @@ struct MeltData struct TALER_RefreshCommitmentP rc; /** + * Version of the refresh commitment @e rc. + */ + enum TALER_RefreshCommitmentVersion rc_version; + + /** * Information about the melted coin. */ struct MeltedCoin melted_coin; @@ -196,6 +201,8 @@ struct MeltData * @param rd refresh data with the characteristics of the operation * @param blinding_seed seed for blinding in case of CS denominations, can be NULL * @param alg_values contributions from the exchange into the melt + * @param rc_version version of the refresh commitment to compute, + * #TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 is not supported * @param[out] md where to write the derived melt data */ enum GNUNET_GenericReturnValue @@ -204,8 +211,23 @@ TALER_EXCHANGE_get_melt_data ( const struct TALER_EXCHANGE_MeltInput *rd, const struct TALER_BlindingMasterSeedP *blinding_seed, const struct TALER_ExchangeBlindingValues *alg_values, + enum TALER_RefreshCommitmentVersion rc_version, struct MeltData *md); + +/** + * Determine which version of the refresh commitment to use for + * a melt at the exchange with the given @a keys: exchanges before + * protocol v45 only accept the commitment without the transfer + * public keys (#11862). + * + * @param keys the keys of the exchange + * @return version of the refresh commitment to use + */ +enum TALER_RefreshCommitmentVersion +TALER_EXCHANGE_refresh_commitment_version_ ( + const struct TALER_EXCHANGE_Keys *keys); + /** * Free all information associated with a melting session. Note * that we allow the melting session to be only partially initialized, diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c @@ -403,6 +403,42 @@ run (void *cls, MHD_HTTP_CONFLICT, NULL), + /** + * Refresh like a client that does not yet include the transfer + * public keys in the refresh commitment (#11862), which the + * exchange must still accept and reveal. + */ + CMD_TRANSFER_TO_EXCHANGE ( + "refresh-create-reserve-legacy", + "EUR:5.01"), + TALER_TESTING_cmd_check_bank_admin_transfer ( + "ck-refresh-create-reserve-legacy", + "EUR:5.01", + cred.user42_payto, + cred.exchange_payto, + "refresh-create-reserve-legacy"), + CMD_EXEC_WIREWATCH ("wirewatch-refresh-legacy"), + TALER_TESTING_cmd_withdraw_amount ( + "refresh-withdraw-coin-legacy", + "refresh-create-reserve-legacy", + "EUR:5", + 0, /* age restriction off */ + MHD_HTTP_OK), + TALER_TESTING_cmd_melt_with_legacy_commitment ( + TALER_TESTING_cmd_melt_double ( + "refresh-melt-legacy", + "refresh-withdraw-coin-legacy", + MHD_HTTP_OK, + NULL)), + TALER_TESTING_cmd_melt_reveal ( + "refresh-reveal-legacy", + "refresh-melt-legacy", + MHD_HTTP_OK), + TALER_TESTING_cmd_melt_reveal ( + "refresh-reveal-legacy-idempotency", + "refresh-melt-legacy", + MHD_HTTP_OK), + TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c @@ -194,6 +194,11 @@ struct MeltState struct TALER_RefreshCommitmentP rc; /** + * Version of the refresh commitment @e rc. + */ + enum TALER_RefreshCommitmentVersion rc_version; + + /** * The kappa refresh nonces for signing with the old coin. */ struct TALER_KappaPublicRefreshNoncesP kappa_nonces; @@ -242,6 +247,13 @@ struct MeltState bool double_melt; /** + * If true, melt like a client facing an exchange from before + * protocol v45, that is, with the refresh commitment that does not + * include the transfer public keys (#11862). + */ + bool legacy_commitment; + + /** * How often should we retry on (transient) failures? */ unsigned int do_retry; @@ -581,6 +593,7 @@ melt_reveal_run (void *cls, ms->reveal_melt_input.num_blinding_values = ms->num_blinding_values; ms->reveal_melt_input.blinding_values = ms->blinding_values; ms->reveal_melt_input.noreveal_index = ms->noreveal_index; + ms->reveal_melt_input.rc_version = ms->rc_version; rrs->rmh = TALER_EXCHANGE_post_reveal_melt_create ( TALER_TESTING_interpreter_get_context (is), TALER_TESTING_get_exchange_url (is), @@ -657,6 +670,50 @@ do_melt_retry (void *cls) /** + * Create and start the POST /melt operation of @a ms. + * + * @param[in,out] ms melt command state, with @e melt_input set up + * @param cb callback for the result + * @return #GNUNET_OK on success + */ +static enum GNUNET_GenericReturnValue +start_melt (struct MeltState *ms, + TALER_EXCHANGE_PostMeltCallback cb) +{ + struct TALER_EXCHANGE_Keys *keys = TALER_TESTING_get_keys (ms->is); + + if (ms->legacy_commitment) + { + /* Pretend that the exchange speaks a protocol version from before + the fix of the refresh commitment */ + json_t *jkeys = TALER_EXCHANGE_keys_to_json (keys); + + GNUNET_assert (NULL != jkeys); + keys = TALER_EXCHANGE_keys_from_json (jkeys); + json_decref (jkeys); + GNUNET_assert (NULL != keys); + GNUNET_free (keys->version); + keys->version = GNUNET_strdup ("42:0:8"); + } + ms->mh = TALER_EXCHANGE_post_melt_create ( + TALER_TESTING_interpreter_get_context (ms->is), + TALER_TESTING_get_exchange_url (ms->is), + keys, + &ms->rms, + &ms->melt_input); + if (ms->legacy_commitment) + TALER_EXCHANGE_keys_decref (keys); + if (NULL == ms->mh) + return GNUNET_SYSERR; + GNUNET_assert (TALER_EC_NONE == + TALER_EXCHANGE_post_melt_start (ms->mh, + cb, + ms)); + return GNUNET_OK; +} + + +/** * Callback for a " /melt" operation; checks if the HTTP * response code is okay and re-run the melt operation if the * CMD was set to do so. @@ -727,6 +784,16 @@ melt_cb (struct MeltState *ms, { ms->noreveal_index = mr->details.ok.noreveal_index; ms->rc = mr->details.ok.rc; + ms->rc_version = mr->details.ok.rc_version; + if (ms->rc_version != + (ms->legacy_commitment + ? TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN + : TALER_REFRESH_COMMITMENT_VERSION_CURRENT)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ms->is); + return; + } if (mr->details.ok.num_melt_blinding_values != ms->num_fresh_coins) { GNUNET_break (0); @@ -764,17 +831,9 @@ melt_cb (struct MeltState *ms, { TALER_LOG_DEBUG ("Doubling the melt (%s)\n", ms->cmd->label); - ms->mh = TALER_EXCHANGE_post_melt_create ( - TALER_TESTING_interpreter_get_context (ms->is), - TALER_TESTING_get_exchange_url (ms->is), - TALER_TESTING_get_keys (ms->is), - &ms->rms, - &ms->melt_input); - GNUNET_assert (NULL != ms->mh); - GNUNET_assert (TALER_EC_NONE == - TALER_EXCHANGE_post_melt_start (ms->mh, - &melt_cb, - ms)); + GNUNET_assert (GNUNET_OK == + start_melt (ms, + &melt_cb)); ms->double_melt = false; return; } @@ -965,23 +1024,14 @@ melt_run (void *cls, else rms->che.details.melt.no_hac = true; - rms->mh = TALER_EXCHANGE_post_melt_create ( - TALER_TESTING_interpreter_get_context (is), - TALER_TESTING_get_exchange_url (is), - TALER_TESTING_get_keys (is), - &rms->rms, - &rms->melt_input); - - if (NULL == rms->mh) + if (GNUNET_OK != + start_melt (rms, + &melt_cb)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (rms->is); return; } - GNUNET_assert (TALER_EC_NONE == - TALER_EXCHANGE_post_melt_start (rms->mh, - &melt_cb, - rms)); } } @@ -1213,6 +1263,19 @@ TALER_TESTING_cmd_melt_with_retry (struct TALER_TESTING_Command cmd) } +struct TALER_TESTING_Command +TALER_TESTING_cmd_melt_with_legacy_commitment ( + struct TALER_TESTING_Command cmd) +{ + struct MeltState *rms; + + GNUNET_assert (&melt_run == cmd.run); + rms = cmd.cls; + rms->legacy_commitment = true; + return cmd; +} + + /** * Offer internal data from a "refresh reveal" CMD. *