exchange_api_post-melt.c (22580B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2025 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file lib/exchange_api_post-melt.c 19 * @brief Implementation of the /melt request 20 * @author Özgür Kesim 21 */ 22 #include <jansson.h> 23 #include <microhttpd.h> /* just for HTTP status codes */ 24 #include <gnunet/gnunet_util_lib.h> 25 #include <gnunet/gnunet_json_lib.h> 26 #include <gnunet/gnunet_curl_lib.h> 27 #include "taler/taler_json_lib.h" 28 #include "exchange_api_common.h" 29 #include "exchange_api_handle.h" 30 #include "taler/taler_signatures.h" 31 #include "exchange_api_curl_defaults.h" 32 #include "exchange_api_refresh_common.h" 33 34 35 /** 36 * @brief A /melt Handle 37 */ 38 struct TALER_EXCHANGE_PostMeltHandle 39 { 40 41 /** 42 * The keys of the this request handle will use 43 */ 44 struct TALER_EXCHANGE_Keys *keys; 45 46 /** 47 * Hash of the denomination of the melted coin, filled by 48 * #melt_coin_lookup() when checking a conflict reply. 49 */ 50 struct TALER_DenominationHashP h_melt_denom_pub; 51 52 /** 53 * The url for this request. 54 */ 55 char *url; 56 57 /** 58 * The exchange base url. 59 */ 60 char *exchange_url; 61 62 /** 63 * Curl context. 64 */ 65 struct GNUNET_CURL_Context *cctx; 66 67 /** 68 * Context for #TEH_curl_easy_post(). Keeps the data that must 69 * persist for Curl to make the upload. 70 */ 71 struct TALER_CURL_PostContext ctx; 72 73 /** 74 * Handle for the request. 75 */ 76 struct GNUNET_CURL_Job *job; 77 78 /** 79 * Function to call with refresh melt failure results. 80 */ 81 TALER_EXCHANGE_PostMeltCallback melt_cb; 82 83 /** 84 * Closure for @e result_cb and @e melt_failure_cb. 85 */ 86 void *melt_cb_cls; 87 88 /** 89 * Actual information about the melt operation. 90 */ 91 struct MeltData md; 92 93 /** 94 * The seed for the melt operation. 95 */ 96 struct TALER_PublicRefreshMasterSeedP rms; 97 98 /** 99 * Details about the characteristics of the requested melt operation. 100 */ 101 const struct TALER_EXCHANGE_MeltInput *rd; 102 103 /** 104 * True, if no blinding_seed is needed (no CS denominations involved) 105 */ 106 bool no_blinding_seed; 107 108 /** 109 * If @e no_blinding_seed is false, the blinding seed for the intermediate 110 * call to /blinding-prepare, in order to retrieve the R-values from the 111 * exchange for the blind Clause-Schnorr signature. 112 */ 113 struct TALER_BlindingMasterSeedP blinding_seed; 114 115 /** 116 * Array of `num_fresh_denom_pubs` per-coin values 117 * returned from melt operation. 118 */ 119 struct TALER_ExchangeBlindingValues *melt_blinding_values; 120 121 /** 122 * Handle for the preflight request, or NULL. 123 */ 124 struct TALER_EXCHANGE_PostBlindingPrepareHandle *bpr; 125 126 /** 127 * Public key of the coin being melted. 128 */ 129 struct TALER_CoinSpendPublicKeyP coin_pub; 130 131 /** 132 * Signature affirming the melt. 133 */ 134 struct TALER_CoinSpendSignatureP coin_sig; 135 136 /** 137 * @brief Public information about the coin's denomination key 138 */ 139 const struct TALER_EXCHANGE_DenomPublicKey *dki; 140 141 /** 142 * Gamma value chosen by the exchange during melt. 143 */ 144 uint32_t noreveal_index; 145 146 }; 147 148 149 /** 150 * Verify that the signature on the "200 OK" response 151 * from the exchange is valid. 152 * 153 * @param[in,out] mh melt handle 154 * @param json json reply with the signature 155 * @param[out] exchange_pub public key of the exchange used for the signature 156 * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not 157 */ 158 static enum GNUNET_GenericReturnValue 159 verify_melt_signature_ok (struct TALER_EXCHANGE_PostMeltHandle *mh, 160 const json_t *json, 161 struct TALER_ExchangePublicKeyP *exchange_pub) 162 { 163 struct TALER_ExchangeSignatureP exchange_sig; 164 struct GNUNET_JSON_Specification spec[] = { 165 GNUNET_JSON_spec_fixed_auto ("exchange_sig", 166 &exchange_sig), 167 GNUNET_JSON_spec_fixed_auto ("exchange_pub", 168 exchange_pub), 169 GNUNET_JSON_spec_uint32 ("noreveal_index", 170 &mh->noreveal_index), 171 GNUNET_JSON_spec_end () 172 }; 173 174 if (GNUNET_OK != 175 GNUNET_JSON_parse (json, 176 spec, 177 NULL, NULL)) 178 { 179 GNUNET_break_op (0); 180 return GNUNET_SYSERR; 181 } 182 /* check that exchange signing key is permitted */ 183 if (GNUNET_OK != 184 TALER_EXCHANGE_test_signing_key (mh->keys, 185 exchange_pub)) 186 { 187 GNUNET_break_op (0); 188 return GNUNET_SYSERR; 189 } 190 191 /* check that noreveal index is in permitted range */ 192 if (TALER_CNC_KAPPA <= mh->noreveal_index) 193 { 194 GNUNET_break_op (0); 195 return GNUNET_SYSERR; 196 } 197 198 if (GNUNET_OK != 199 TALER_exchange_online_melt_confirmation_verify ( 200 &mh->md.rc, 201 mh->noreveal_index, 202 exchange_pub, 203 &exchange_sig)) 204 { 205 GNUNET_break_op (0); 206 return GNUNET_SYSERR; 207 } 208 return GNUNET_OK; 209 } 210 211 212 /** 213 * Check that @a coin_pub is the melted coin and report how we used it. 214 * 215 * @param cls a `struct TALER_EXCHANGE_PostMeltHandle *` 216 * @param coin_pub public key of the coin named in the conflict reply 217 * @param[out] h_denom_pub set to the hash of the denomination we used 218 * @param[out] h_age_commitment set to the age commitment hash we used, or NULL 219 * @return #GNUNET_OK if found, #GNUNET_NO if the coin is not ours 220 */ 221 static enum GNUNET_GenericReturnValue 222 melt_coin_lookup (void *cls, 223 const struct TALER_CoinSpendPublicKeyP *coin_pub, 224 const struct TALER_DenominationHashP **h_denom_pub, 225 const struct TALER_AgeCommitmentHashP **h_age_commitment) 226 { 227 struct TALER_EXCHANGE_PostMeltHandle *mh = cls; 228 229 struct TALER_CoinSpendPublicKeyP my_pub; 230 231 GNUNET_CRYPTO_eddsa_key_get_public ( 232 &mh->md.melted_coin.coin_priv.eddsa_priv, 233 &my_pub.eddsa_pub); 234 if (0 != GNUNET_memcmp (coin_pub, 235 &my_pub)) 236 return GNUNET_NO; 237 TALER_denom_pub_hash (&mh->md.melted_coin.pub_key, 238 &mh->h_melt_denom_pub); 239 *h_denom_pub = &mh->h_melt_denom_pub; 240 *h_age_commitment = mh->md.melted_coin.h_age_commitment; 241 return GNUNET_OK; 242 } 243 244 245 /** 246 * Function called when we're done processing the 247 * HTTP /melt request. 248 * 249 * @param cls the `struct TALER_EXCHANGE_MeltHandle` 250 * @param response_code HTTP response code, 0 on error 251 * @param response parsed JSON result, NULL on error 252 */ 253 static void 254 handle_melt_finished (void *cls, 255 long response_code, 256 const void *response) 257 { 258 struct TALER_EXCHANGE_PostMeltHandle *mh = cls; 259 const json_t *j = response; 260 struct TALER_EXCHANGE_PostMeltResponse mr = { 261 .hr.reply = j, 262 .hr.http_status = (unsigned int) response_code 263 }; 264 265 mh->job = NULL; 266 switch (response_code) 267 { 268 case 0: 269 mr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; 270 break; 271 case MHD_HTTP_OK: 272 if (GNUNET_OK != 273 verify_melt_signature_ok (mh, 274 j, 275 &mr.details.ok.sign_key)) 276 { 277 GNUNET_break_op (0); 278 mr.hr.http_status = 0; 279 mr.hr.ec = TALER_EC_EXCHANGE_MELT_INVALID_SIGNATURE_BY_EXCHANGE; 280 break; 281 } 282 mr.details.ok.noreveal_index = mh->noreveal_index; 283 mr.details.ok.rc = mh->md.rc; 284 mr.details.ok.rc_version = mh->md.rc_version; 285 mr.details.ok.num_melt_blinding_values = mh->rd->num_fresh_denom_pubs; 286 mr.details.ok.melt_blinding_values = mh->melt_blinding_values; 287 mr.details.ok.blinding_seed = mh->no_blinding_seed 288 ? NULL 289 : &mh->blinding_seed; 290 mh->melt_cb (mh->melt_cb_cls, 291 &mr); 292 mh->melt_cb = NULL; 293 break; 294 case MHD_HTTP_BAD_REQUEST: 295 /* This should never happen, either us or the exchange is buggy 296 (or API version conflict); just pass JSON reply to the application */ 297 mr.hr.ec = TALER_JSON_get_error_code (j); 298 mr.hr.hint = TALER_JSON_get_error_hint (j); 299 break; 300 case MHD_HTTP_CONFLICT: 301 mr.hr.ec = TALER_JSON_get_error_code (j); 302 mr.hr.hint = TALER_JSON_get_error_hint (j); 303 switch (mr.hr.ec) 304 { 305 case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY: 306 case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_AGE_HASH: 307 if (GNUNET_OK != 308 TALER_EXCHANGE_check_coin_conflict_ (mh->keys, 309 mr.hr.ec, 310 j, 311 &melt_coin_lookup, 312 mh, 313 &mr.details.conflict)) 314 { 315 GNUNET_break_op (0); 316 mr.hr.http_status = 0; 317 mr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; 318 } 319 break; 320 default: 321 /* insufficient funds: proof is the coin history, checked by 322 the application via GET /coins/$COIN_PUB/history */ 323 break; 324 } 325 break; 326 case MHD_HTTP_FORBIDDEN: 327 /* Nothing really to verify, exchange says one of the signatures is 328 invalid; assuming we checked them, this should never happen, we 329 should pass the JSON reply to the application */ 330 mr.hr.ec = TALER_JSON_get_error_code (j); 331 mr.hr.hint = TALER_JSON_get_error_hint (j); 332 break; 333 case MHD_HTTP_NOT_FOUND: 334 /* Nothing really to verify, this should never 335 happen, we should pass the JSON reply to the application */ 336 mr.hr.ec = TALER_JSON_get_error_code (j); 337 mr.hr.hint = TALER_JSON_get_error_hint (j); 338 break; 339 case MHD_HTTP_INTERNAL_SERVER_ERROR: 340 /* Server had an internal issue; we should retry, but this API 341 leaves this to the application */ 342 mr.hr.ec = TALER_JSON_get_error_code (j); 343 mr.hr.hint = TALER_JSON_get_error_hint (j); 344 break; 345 default: 346 /* unexpected response code */ 347 mr.hr.ec = TALER_JSON_get_error_code (j); 348 mr.hr.hint = TALER_JSON_get_error_hint (j); 349 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 350 "Unexpected response code %u/%d for exchange melt\n", 351 (unsigned int) response_code, 352 mr.hr.ec); 353 GNUNET_break_op (0); 354 break; 355 } 356 if (NULL != mh->melt_cb) 357 mh->melt_cb (mh->melt_cb_cls, 358 &mr); 359 TALER_EXCHANGE_free_coin_conflict_ (&mr.hr, 360 &mr.details.conflict); 361 TALER_EXCHANGE_post_melt_cancel (mh); 362 } 363 364 365 /** 366 * Start the actual melt operation, now that we have 367 * the exchange's input values. 368 * 369 * @param[in,out] mh melt operation to run 370 * @return #GNUNET_OK if we could start the operation 371 */ 372 static enum GNUNET_GenericReturnValue 373 start_melt (struct TALER_EXCHANGE_PostMeltHandle *mh) 374 { 375 json_t *j_request_body; 376 json_t *j_transfer_pubs; 377 json_t *j_coin_evs; 378 CURL *eh; 379 struct TALER_DenominationHashP h_denom_pub; 380 381 if (GNUNET_OK != 382 TALER_EXCHANGE_get_melt_data (&mh->rms, 383 mh->rd, 384 mh->no_blinding_seed 385 ? NULL 386 : &mh->blinding_seed, 387 mh->melt_blinding_values, 388 mh->rd->rc_version, 389 &mh->md)) 390 { 391 GNUNET_break (0); 392 return GNUNET_SYSERR; 393 } 394 TALER_denom_pub_hash ( 395 &mh->md.melted_coin.pub_key, 396 &h_denom_pub); 397 TALER_wallet_melt_sign ( 398 &mh->md.melted_coin.melt_amount_with_fee, 399 &mh->md.melted_coin.fee_melt, 400 &mh->md.rc, 401 &h_denom_pub, 402 mh->md.melted_coin.h_age_commitment, 403 &mh->md.melted_coin.coin_priv, 404 &mh->coin_sig); 405 GNUNET_CRYPTO_eddsa_key_get_public ( 406 &mh->md.melted_coin.coin_priv.eddsa_priv, 407 &mh->coin_pub.eddsa_pub); 408 mh->dki = TALER_EXCHANGE_get_denomination_key ( 409 mh->keys, 410 &mh->md.melted_coin.pub_key); 411 j_request_body = GNUNET_JSON_PACK ( 412 GNUNET_JSON_pack_data_auto ("old_coin_pub", 413 &mh->coin_pub), 414 GNUNET_JSON_pack_data_auto ("old_denom_pub_h", 415 &h_denom_pub), 416 TALER_JSON_pack_denom_sig ("old_denom_sig", 417 &mh->md.melted_coin.sig), 418 GNUNET_JSON_pack_data_auto ("confirm_sig", 419 &mh->coin_sig), 420 TALER_JSON_pack_amount ("value_with_fee", 421 &mh->md.melted_coin.melt_amount_with_fee), 422 GNUNET_JSON_pack_allow_null ( 423 (NULL != mh->md.melted_coin.h_age_commitment) 424 ? GNUNET_JSON_pack_data_auto ("old_age_commitment_h", 425 mh->md.melted_coin.h_age_commitment) 426 : GNUNET_JSON_pack_string ("old_age_commitment_h", 427 NULL)), 428 GNUNET_JSON_pack_data_auto ("refresh_seed", 429 &mh->md.refresh_seed), 430 GNUNET_JSON_pack_allow_null ( 431 (mh->md.no_blinding_seed) 432 ? GNUNET_JSON_pack_string ("blinding_seed", 433 NULL) 434 : GNUNET_JSON_pack_data_auto ("blinding_seed", 435 &mh->md.blinding_seed)), 436 TALER_JSON_pack_array_of_data_auto ("denoms_h", 437 mh->md.num_fresh_coins, 438 mh->md.denoms_h) 439 ); 440 GNUNET_assert (NULL != j_request_body); 441 GNUNET_assert (NULL != 442 (j_transfer_pubs = json_array ())); 443 GNUNET_assert (NULL != 444 (j_coin_evs = json_array ())); 445 /** 446 * Fill the kappa array of coin envelopes and 447 * the array of transfer pubs. 448 */ 449 for (uint8_t k=0; k<TALER_CNC_KAPPA; k++) 450 { 451 json_t *j_envs; 452 json_t *j_tbs = GNUNET_JSON_PACK ( 453 TALER_JSON_pack_array_of_data_auto ("_", 454 mh->md.num_fresh_coins, 455 mh->md.kappa_transfer_pubs[k]) 456 ); 457 458 GNUNET_assert (NULL != (j_envs = json_array ())); 459 GNUNET_assert (NULL != j_tbs); 460 461 for (size_t i = 0; i < mh->md.num_fresh_coins; i++) 462 { 463 json_t *j_coin = GNUNET_JSON_PACK ( 464 TALER_JSON_pack_blinded_planchet (NULL, 465 &mh->md.kappa_blinded_planchets[k][i]) 466 ); 467 GNUNET_assert (NULL != j_coin); 468 GNUNET_assert (0 == 469 json_array_append_new (j_envs, 470 j_coin)); 471 } 472 GNUNET_assert (0 == 473 json_array_append_new (j_coin_evs, 474 j_envs)); 475 GNUNET_assert (0 == 476 json_array_append (j_transfer_pubs, 477 json_object_get (j_tbs, 478 "_"))); 479 json_decref (j_tbs); 480 } 481 GNUNET_assert (0 == 482 json_object_set_new (j_request_body, 483 "coin_evs", 484 j_coin_evs)); 485 GNUNET_assert (0 == 486 json_object_set_new (j_request_body, 487 "transfer_pubs", 488 j_transfer_pubs)); 489 /* and now we can at last begin the actual request handling */ 490 mh->url = TALER_url_join (mh->exchange_url, 491 "melt", 492 NULL); 493 if (NULL == mh->url) 494 { 495 json_decref (j_request_body); 496 return GNUNET_SYSERR; 497 } 498 eh = TALER_EXCHANGE_curl_easy_get_ (mh->url); 499 if ( (NULL == eh) || 500 (GNUNET_OK != 501 TALER_curl_easy_post (&mh->ctx, 502 eh, 503 j_request_body)) ) 504 { 505 GNUNET_break (0); 506 if (NULL != eh) 507 curl_easy_cleanup (eh); 508 json_decref (j_request_body); 509 return GNUNET_SYSERR; 510 } 511 json_decref (j_request_body); 512 mh->job = GNUNET_CURL_job_add2 (mh->cctx, 513 eh, 514 mh->ctx.headers, 515 &handle_melt_finished, 516 mh); 517 if (NULL == mh->job) 518 { 519 GNUNET_break (0); 520 /* GNUNET_CURL_job_add2() already released @a eh */ 521 return GNUNET_SYSERR; 522 } 523 return GNUNET_OK; 524 } 525 526 527 /** 528 * The melt request @a mh failed, return an error to 529 * the application and cancel the operation. 530 * 531 * @param[in] mh melt request that failed 532 * @param ec error code to fail with 533 */ 534 static void 535 fail_mh (struct TALER_EXCHANGE_PostMeltHandle *mh, 536 enum TALER_ErrorCode ec) 537 { 538 struct TALER_EXCHANGE_PostMeltResponse mr = { 539 .hr.ec = ec 540 }; 541 542 mh->melt_cb (mh->melt_cb_cls, 543 &mr); 544 TALER_EXCHANGE_post_melt_cancel (mh); 545 } 546 547 548 /** 549 * Callbacks of this type are used to serve the result of submitting a 550 * /blinding-prepare request to a exchange. 551 * 552 * @param cls closure with our `struct TALER_EXCHANGE_MeltHandle *` 553 * @param bpr response details 554 */ 555 static void 556 blinding_prepare_cb ( 557 void *cls, 558 const struct TALER_EXCHANGE_PostBlindingPrepareResponse *bpr) 559 { 560 struct TALER_EXCHANGE_PostMeltHandle *mh = cls; 561 unsigned int nks_off = 0; 562 563 mh->bpr = NULL; 564 if (MHD_HTTP_OK != bpr->hr.http_status) 565 { 566 struct TALER_EXCHANGE_PostMeltResponse mr = { 567 .hr = bpr->hr 568 }; 569 570 mr.hr.hint = "/blinding-prepare failed"; 571 mh->melt_cb (mh->melt_cb_cls, 572 &mr); 573 TALER_EXCHANGE_post_melt_cancel (mh); 574 return; 575 } 576 for (unsigned int i = 0; i<mh->rd->num_fresh_denom_pubs; i++) 577 { 578 const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk = 579 &mh->rd->fresh_denom_pubs[i]; 580 struct TALER_ExchangeBlindingValues *wv = &mh->melt_blinding_values[i]; 581 582 switch (fresh_pk->key.bsign_pub_key->cipher) 583 { 584 case GNUNET_CRYPTO_BSA_INVALID: 585 GNUNET_break (0); 586 fail_mh (mh, 587 TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR); 588 return; 589 case GNUNET_CRYPTO_BSA_RSA: 590 break; 591 case GNUNET_CRYPTO_BSA_CS: 592 TALER_denom_ewv_copy (wv, 593 &bpr->details.ok.blinding_values[nks_off]); 594 nks_off++; 595 break; 596 } 597 } 598 if (GNUNET_OK != 599 start_melt (mh)) 600 { 601 GNUNET_break (0); 602 fail_mh (mh, 603 TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR); 604 return; 605 } 606 } 607 608 609 struct TALER_EXCHANGE_PostMeltHandle * 610 TALER_EXCHANGE_post_melt_create ( 611 struct GNUNET_CURL_Context *ctx, 612 const char *url, 613 struct TALER_EXCHANGE_Keys *keys, 614 const struct TALER_PublicRefreshMasterSeedP *rms, 615 const struct TALER_EXCHANGE_MeltInput *rd) 616 { 617 struct TALER_EXCHANGE_PostMeltHandle *mh; 618 619 if (0 == rd->num_fresh_denom_pubs) 620 { 621 GNUNET_break (0); 622 return NULL; 623 } 624 mh = GNUNET_new (struct TALER_EXCHANGE_PostMeltHandle); 625 mh->noreveal_index = TALER_CNC_KAPPA; /* invalid value */ 626 mh->cctx = ctx; 627 mh->exchange_url = GNUNET_strdup (url); 628 mh->rd = rd; 629 mh->rms = *rms; 630 mh->no_blinding_seed = true; 631 mh->melt_blinding_values = 632 GNUNET_new_array (rd->num_fresh_denom_pubs, 633 struct TALER_ExchangeBlindingValues); 634 for (unsigned int i = 0; i < rd->num_fresh_denom_pubs; i++) 635 { 636 const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk = 637 &rd->fresh_denom_pubs[i]; 638 639 switch (fresh_pk->key.bsign_pub_key->cipher) 640 { 641 case GNUNET_CRYPTO_BSA_INVALID: 642 GNUNET_break (0); 643 GNUNET_free (mh->melt_blinding_values); 644 GNUNET_free (mh->exchange_url); 645 GNUNET_free (mh); 646 return NULL; 647 case GNUNET_CRYPTO_BSA_RSA: 648 TALER_denom_ewv_copy (&mh->melt_blinding_values[i], 649 TALER_denom_ewv_rsa_singleton ()); 650 break; 651 case GNUNET_CRYPTO_BSA_CS: 652 mh->no_blinding_seed = false; 653 break; 654 } 655 } 656 mh->keys = TALER_EXCHANGE_keys_incref (keys); 657 return mh; 658 } 659 660 661 enum TALER_ErrorCode 662 TALER_EXCHANGE_post_melt_start ( 663 struct TALER_EXCHANGE_PostMeltHandle *mh, 664 TALER_EXCHANGE_PostMeltCallback melt_cb, 665 TALER_EXCHANGE_POST_MELT_RESULT_CLOSURE *melt_cb_cls) 666 { 667 mh->melt_cb = melt_cb; 668 mh->melt_cb_cls = melt_cb_cls; 669 670 if (! mh->no_blinding_seed) 671 { 672 struct TALER_EXCHANGE_NonceKey nks[ 673 GNUNET_NZL (mh->rd->num_fresh_denom_pubs)]; 674 unsigned int nks_off = 0; 675 676 for (unsigned int i = 0; i < mh->rd->num_fresh_denom_pubs; i++) 677 { 678 const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk = 679 &mh->rd->fresh_denom_pubs[i]; 680 681 if (GNUNET_CRYPTO_BSA_CS == 682 fresh_pk->key.bsign_pub_key->cipher) 683 { 684 nks[nks_off].pk = fresh_pk; 685 nks[nks_off].cnc_num = i; 686 nks_off++; 687 } 688 } 689 TALER_cs_refresh_seed_to_blinding_seed ( 690 &mh->rms, 691 &mh->rd->melt_priv, 692 &mh->blinding_seed); 693 mh->bpr = TALER_EXCHANGE_post_blinding_prepare_for_melt_create ( 694 mh->cctx, 695 mh->exchange_url, 696 &mh->blinding_seed, 697 nks_off, 698 nks); 699 if (NULL == mh->bpr) 700 { 701 GNUNET_break (0); 702 return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; 703 } 704 { 705 enum TALER_ErrorCode ec; 706 707 ec = TALER_EXCHANGE_post_blinding_prepare_start (mh->bpr, 708 &blinding_prepare_cb, 709 mh); 710 if (TALER_EC_NONE != ec) 711 { 712 GNUNET_break (0); 713 TALER_EXCHANGE_post_blinding_prepare_cancel (mh->bpr); 714 mh->bpr = NULL; 715 return ec; 716 } 717 } 718 return TALER_EC_NONE; 719 } 720 if (GNUNET_OK != 721 start_melt (mh)) 722 { 723 GNUNET_break (0); 724 return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; 725 } 726 return TALER_EC_NONE; 727 } 728 729 730 void 731 TALER_EXCHANGE_post_melt_cancel (struct TALER_EXCHANGE_PostMeltHandle *mh) 732 { 733 for (unsigned int i = 0; i < mh->rd->num_fresh_denom_pubs; i++) 734 TALER_denom_ewv_free (&mh->melt_blinding_values[i]); 735 if (NULL != mh->job) 736 { 737 GNUNET_CURL_job_cancel (mh->job); 738 mh->job = NULL; 739 } 740 if (NULL != mh->bpr) 741 { 742 TALER_EXCHANGE_post_blinding_prepare_cancel (mh->bpr); 743 mh->bpr = NULL; 744 } 745 TALER_EXCHANGE_free_melt_data (&mh->md); /* does not free 'md' itself */ 746 GNUNET_free (mh->melt_blinding_values); 747 GNUNET_free (mh->url); 748 GNUNET_free (mh->exchange_url); 749 TALER_curl_easy_post_finished (&mh->ctx); 750 TALER_EXCHANGE_keys_decref (mh->keys); 751 GNUNET_free (mh); 752 } 753 754 755 /* end of exchange_api_melt.c */