diff options
| author | Christian Grothoff <christian@grothoff.org> | 2020-01-17 19:54:16 +0100 | 
|---|---|---|
| committer | Christian Grothoff <christian@grothoff.org> | 2020-01-17 19:54:16 +0100 | 
| commit | 11c52837112421af755bc7bc21569011274909ad (patch) | |
| tree | 68c44a348c9189daad2d0b9f4c72468514f257ca | |
| parent | 33bd1ca2bbd61019b224c9de8ac48126d0a57ab0 (diff) | |
prepare API to enable verification of fees in coin history check
| -rw-r--r-- | src/include/taler_exchange_service.h | 5 | ||||
| -rw-r--r-- | src/lib/exchange_api_common.c | 5 | ||||
| -rw-r--r-- | src/lib/exchange_api_deposit.c | 14 | ||||
| -rw-r--r-- | src/lib/exchange_api_payback.c | 8 | ||||
| -rw-r--r-- | src/lib/exchange_api_refresh.c | 16 | 
5 files changed, 35 insertions, 13 deletions
| diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index eb145256..972b94aa 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -1685,6 +1685,7 @@ TALER_EXCHANGE_track_transaction_cancel (struct   * Convenience function.  Verifies a coin's transaction history as   * returned by the exchange.   * + * @param dk fee structure for the coin, NULL to skip verifying fees   * @param currency expected currency for the coin   * @param coin_pub public key of the coin   * @param history history of the coin in json encoding @@ -1692,7 +1693,9 @@ TALER_EXCHANGE_track_transaction_cancel (struct   * @return #GNUNET_OK if @a history is valid, #GNUNET_SYSERR if not   */  int -TALER_EXCHANGE_verify_coin_history (const char *currency, +TALER_EXCHANGE_verify_coin_history (const struct +                                    TALER_EXCHANGE_DenomPublicKey *dk, +                                    const char *currency,                                      const struct                                      TALER_CoinSpendPublicKeyP *coin_pub,                                      json_t *history, diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index c7e76985..3860a661 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -29,6 +29,7 @@  /**   * Verify a coins transaction history as returned by the exchange.   * + * @param dk fee structure for the coin, NULL to skip verifying fees   * @param currency expected currency for the coin   * @param coin_pub public key of the coin   * @param history history of the coin in json encoding @@ -36,7 +37,9 @@   * @return #GNUNET_OK if @a history is valid, #GNUNET_SYSERR if not   */  int -TALER_EXCHANGE_verify_coin_history (const char *currency, +TALER_EXCHANGE_verify_coin_history (const struct +                                    TALER_EXCHANGE_DenomPublicKey *dk, +                                    const char *currency,                                      const struct                                      TALER_CoinSpendPublicKeyP *coin_pub,                                      json_t *history, diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index 69584ee2..23ec8a3b 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -101,9 +101,10 @@ struct TALER_EXCHANGE_DepositHandle    struct TALER_Amount amount_with_fee;    /** -   * Total value of the coin being transacted with. +   * @brief Public information about the coin's denomination key. +   * Note that the "key" field itself has been zero'ed out.     */ -  struct TALER_Amount coin_value; +  struct TALER_EXCHANGE_DenomPublicKey dki;    /**     * Chance that we will inform the auditor about the deposit @@ -250,7 +251,8 @@ verify_deposit_signature_forbidden (const struct    history = json_object_get (json,                               "history");    if (GNUNET_OK != -      TALER_EXCHANGE_verify_coin_history (dh->coin_value.currency, +      TALER_EXCHANGE_verify_coin_history (&dh->dki, +                                          dh->dki.value.currency,                                            &dh->depconf.coin_pub,                                            history,                                            &total)) @@ -269,7 +271,7 @@ verify_deposit_signature_forbidden (const struct    }    if (0 >= TALER_amount_cmp (&total, -                             &dh->coin_value)) +                             &dh->dki.value))    {      /* transaction should have still fit */      GNUNET_break (0); @@ -604,7 +606,9 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,    dh->depconf.coin_pub = *coin_pub;    dh->depconf.merchant = *merchant_pub;    dh->amount_with_fee = *amount; -  dh->coin_value = dki->value; +  dh->dki = *dki; +  dh->dki.key.rsa_public_key = NULL; /* lifetime not warranted, so better +                                        not copy the pointer */    eh = TEL_curl_easy_get (dh->url);    if (GNUNET_OK != diff --git a/src/lib/exchange_api_payback.c b/src/lib/exchange_api_payback.c index f9df27e7..b2ef9f20 100644 --- a/src/lib/exchange_api_payback.c +++ b/src/lib/exchange_api_payback.c @@ -237,7 +237,8 @@ handle_payback_finished (void *cls,        history = json_object_get (j,                                   "history");        if (GNUNET_OK != -          TALER_EXCHANGE_verify_coin_history (dki->fee_deposit.currency, +          TALER_EXCHANGE_verify_coin_history (dki, +                                              dki->fee_deposit.currency,                                                &ph->coin_pub,                                                history,                                                &total)) @@ -366,8 +367,7 @@ TALER_EXCHANGE_payback (struct TALER_EXCHANGE_Handle *exchange,    ph->coin_pub = pr.coin_pub;    ph->exchange = exchange;    ph->pk = *pk; -  ph->pk.key.rsa_public_key = GNUNET_CRYPTO_rsa_public_key_dup ( -    pk->key.rsa_public_key); +  ph->pk.key.rsa_public_key = NULL; /* zero out, as lifetime cannot be warranted */    ph->cb = payback_cb;    ph->cb_cls = payback_cb_cls;    ph->url = TEAH_path_to_url (exchange, "/payback"); @@ -382,7 +382,6 @@ TALER_EXCHANGE_payback (struct TALER_EXCHANGE_Handle *exchange,      curl_easy_cleanup (eh);      json_decref (payback_obj);      GNUNET_free (ph->url); -    GNUNET_CRYPTO_rsa_public_key_free (ph->pk.key.rsa_public_key);      GNUNET_free (ph);      return NULL;    } @@ -416,7 +415,6 @@ TALER_EXCHANGE_payback_cancel (struct TALER_EXCHANGE_PaybackHandle *ph)    }    GNUNET_free (ph->url);    TALER_curl_easy_post_finished (&ph->ctx); -  GNUNET_CRYPTO_rsa_public_key_free (ph->pk.key.rsa_public_key);    GNUNET_free (ph);  } diff --git a/src/lib/exchange_api_refresh.c b/src/lib/exchange_api_refresh.c index a75baec8..cf852d37 100644 --- a/src/lib/exchange_api_refresh.c +++ b/src/lib/exchange_api_refresh.c @@ -864,6 +864,11 @@ struct TALER_EXCHANGE_RefreshMeltHandle     * Actual information about the melt operation.     */    struct MeltData *md; + +  /** +   * @brief Public information about the coin's denomination key +   */ +  struct TALER_EXCHANGE_DenomPublicKey dki;  }; @@ -1000,7 +1005,8 @@ verify_refresh_melt_signature_conflict (struct    history = json_object_get (json,                               "history");    if (GNUNET_OK != -      TALER_EXCHANGE_verify_coin_history (original_value.currency, +      TALER_EXCHANGE_verify_coin_history (&rmh->dki, +                                          original_value.currency,                                            &coin_pub,                                            history,                                            &total)) @@ -1153,6 +1159,8 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,                               TALER_EXCHANGE_RefreshMeltCallback melt_cb,                               void *melt_cb_cls)  { +  const struct TALER_EXCHANGE_Keys *key_state; +  const struct TALER_EXCHANGE_DenomPublicKey *dki;    json_t *melt_obj;    struct TALER_EXCHANGE_RefreshMeltHandle *rmh;    CURL *eh; @@ -1208,10 +1216,16 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,      free_melt_data (md);      return NULL;    } +  key_state = TALER_EXCHANGE_get_keys (exchange); +  dki = TALER_EXCHANGE_get_denomination_key (key_state, +                                             &md->melted_coin.pub_key);    /* and now we can at last begin the actual request handling */    rmh = GNUNET_new (struct TALER_EXCHANGE_RefreshMeltHandle);    rmh->exchange = exchange; +  rmh->dki = *dki; +  rmh->dki.key.rsa_public_key = NULL; /* lifetime not warranted, so better +                                         not copy the pointer */    rmh->melt_cb = melt_cb;    rmh->melt_cb_cls = melt_cb_cls;    rmh->md = md; | 
