summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-11-06 16:52:14 +0100
committerChristian Grothoff <christian@grothoff.org>2021-11-06 16:52:14 +0100
commit8175fdfa0f47e74e239190e809eff4dda5565a76 (patch)
treeb8d46fe55fc9de418953eae23bc12f35295f4ba1 /src/lib
parent938e2ce39c56ae5afc6c12f15be8f49c7edbf2fd (diff)
downloadexchange-8175fdfa0f47e74e239190e809eff4dda5565a76.tar.gz
exchange-8175fdfa0f47e74e239190e809eff4dda5565a76.tar.bz2
exchange-8175fdfa0f47e74e239190e809eff4dda5565a76.zip
introduce TALER_wallet_deposit_verify
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/exchange_api_common.c51
-rw-r--r--src/lib/exchange_api_deposit.c93
-rw-r--r--src/lib/exchange_api_refund.c58
3 files changed, 79 insertions, 123 deletions
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c
index 4da7e33e8..900c871d2 100644
--- a/src/lib/exchange_api_common.c
+++ b/src/lib/exchange_api_common.c
@@ -492,30 +492,31 @@ TALER_EXCHANGE_verify_coin_history (
if (0 == strcasecmp (type,
"DEPOSIT"))
{
- struct TALER_DepositRequestPS dr = {
- .purpose.size = htonl (sizeof (dr)),
- .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT),
- .coin_pub = *coin_pub
- };
+ struct TALER_MerchantWireHash h_wire;
+ struct TALER_PrivateContractHash h_contract_terms;
+ // struct TALER_ExtensionContractHash h_extensions; // FIXME!
+ struct GNUNET_TIME_Absolute wallet_timestamp;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Absolute refund_deadline = {0};
struct TALER_CoinSpendSignatureP sig;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("coin_sig",
&sig),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &dr.h_contract_terms),
+ &h_contract_terms),
GNUNET_JSON_spec_fixed_auto ("h_wire",
- &dr.h_wire),
+ &h_wire),
GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
- &dr.h_denom_pub),
- TALER_JSON_spec_absolute_time_nbo ("timestamp",
- &dr.wallet_timestamp),
+ h_denom_pub),
+ TALER_JSON_spec_absolute_time ("timestamp",
+ &wallet_timestamp),
GNUNET_JSON_spec_mark_optional (
- TALER_JSON_spec_absolute_time_nbo ("refund_deadline",
- &dr.refund_deadline)),
- TALER_JSON_spec_amount_any_nbo ("deposit_fee",
- &dr.deposit_fee),
+ TALER_JSON_spec_absolute_time ("refund_deadline",
+ &refund_deadline)),
+ TALER_JSON_spec_amount_any ("deposit_fee",
+ &fee),
GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &dr.merchant),
+ &merchant_pub),
GNUNET_JSON_spec_end ()
};
@@ -527,23 +528,25 @@ TALER_EXCHANGE_verify_coin_history (
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- TALER_amount_hton (&dr.amount_with_fee,
- &amount);
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
- &dr,
- &sig.eddsa_signature,
- &coin_pub->eddsa_pub))
+ TALER_wallet_deposit_verify (&amount,
+ &fee,
+ &h_wire,
+ &h_contract_terms,
+ NULL /* h_extensions! */,
+ h_denom_pub,
+ wallet_timestamp,
+ &merchant_pub,
+ refund_deadline,
+ coin_pub,
+ &sig))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- *h_denom_pub = dr.h_denom_pub;
if (NULL != dk)
{
/* check that deposit fee matches our expectations from /keys! */
- TALER_amount_ntoh (&fee,
- &dr.deposit_fee);
if ( (GNUNET_YES !=
TALER_amount_cmp_currency (&fee,
&dk->fee_deposit)) ||
diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c
index 8abb73518..188c17f18 100644
--- a/src/lib/exchange_api_deposit.c
+++ b/src/lib/exchange_api_deposit.c
@@ -431,39 +431,26 @@ verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki,
struct GNUNET_TIME_Absolute refund_deadline,
const struct TALER_CoinSpendSignatureP *coin_sig)
{
+ if (GNUNET_OK !=
+ TALER_wallet_deposit_verify (amount,
+ &dki->fee_deposit,
+ h_wire,
+ h_contract_terms,
+ NULL /* FIXME: h_extensions! */,
+ denom_pub_hash,
+ timestamp,
+ merchant_pub,
+ refund_deadline,
+ coin_pub,
+ coin_sig))
{
- struct TALER_DepositRequestPS dr = {
- .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT),
- .purpose.size = htonl (sizeof (dr)),
- .h_contract_terms = *h_contract_terms,
- .h_wire = *h_wire,
- .h_denom_pub = *denom_pub_hash,
- .wallet_timestamp = GNUNET_TIME_absolute_hton (timestamp),
- .refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline),
- .merchant = *merchant_pub,
- .coin_pub = *coin_pub
- };
-
- TALER_amount_hton (&dr.amount_with_fee,
- amount);
- TALER_amount_hton (&dr.deposit_fee,
- &dki->fee_deposit);
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
- &dr,
- &coin_sig->eddsa_signature,
- &coin_pub->eddsa_pub))
- {
- GNUNET_break_op (0);
- TALER_LOG_WARNING ("Invalid coin signature on /deposit request!\n");
- {
- TALER_LOG_DEBUG ("... amount_with_fee was %s\n",
- TALER_amount2s (amount));
- TALER_LOG_DEBUG ("... deposit_fee was %s\n",
- TALER_amount2s (&dki->fee_deposit));
- }
- return GNUNET_SYSERR;
- }
+ GNUNET_break_op (0);
+ TALER_LOG_WARNING ("Invalid coin signature on /deposit request!\n");
+ TALER_LOG_DEBUG ("... amount_with_fee was %s\n",
+ TALER_amount2s (amount));
+ TALER_LOG_DEBUG ("... deposit_fee was %s\n",
+ TALER_amount2s (&dki->fee_deposit));
+ return GNUNET_SYSERR;
}
/* check coin signature */
@@ -496,48 +483,6 @@ verify_signatures (const struct TALER_EXCHANGE_DenomPublicKey *dki,
}
-void
-TALER_EXCHANGE_deposit_permission_sign (
- const struct TALER_Amount *amount,
- const struct TALER_Amount *deposit_fee,
- const struct TALER_MerchantWireHash *h_wire,
- const struct TALER_PrivateContractHash *h_contract_terms,
- const struct TALER_ExtensionContractHash *h_extensions,
- const struct TALER_DenominationHash *h_denom_pub,
- const struct TALER_CoinSpendPrivateKeyP *coin_priv,
- struct GNUNET_TIME_Absolute wallet_timestamp,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- struct GNUNET_TIME_Absolute refund_deadline,
- struct TALER_CoinSpendSignatureP *coin_sig)
-{
- struct TALER_DepositRequestPS dr = {
- .purpose.size = htonl (sizeof (dr)),
- .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT),
- .h_contract_terms = *h_contract_terms,
- .h_wire = *h_wire,
- .h_denom_pub = *h_denom_pub,
- .wallet_timestamp = GNUNET_TIME_absolute_hton (wallet_timestamp),
- .refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline),
- .merchant = *merchant_pub
- };
-
- // FIXME: sign also over h_extensions!
- GNUNET_assert (GNUNET_OK ==
- GNUNET_TIME_round_abs (&wallet_timestamp));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_TIME_round_abs (&refund_deadline));
- GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
- &dr.coin_pub.eddsa_pub);
- TALER_amount_hton (&dr.amount_with_fee,
- amount);
- TALER_amount_hton (&dr.deposit_fee,
- deposit_fee);
- GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
- &dr,
- &coin_sig->eddsa_signature);
-}
-
-
struct TALER_EXCHANGE_DepositHandle *
TALER_EXCHANGE_deposit (
struct TALER_EXCHANGE_Handle *exchange,
diff --git a/src/lib/exchange_api_refund.c b/src/lib/exchange_api_refund.c
index a73f19fc9..1362a9c26 100644
--- a/src/lib/exchange_api_refund.c
+++ b/src/lib/exchange_api_refund.c
@@ -87,7 +87,7 @@ struct TALER_EXCHANGE_RefundHandle
* @param[out] exchange_sig set to the exchange's signature
* @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
*/
-static int
+static enum GNUNET_GenericReturnValue
verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh,
const json_t *json,
struct TALER_ExchangePublicKeyP *exchange_pub,
@@ -138,7 +138,7 @@ verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh,
* @param json json reply with the coin transaction history
* @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
*/
-static int
+static enum GNUNET_GenericReturnValue
verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh,
const json_t *json)
{
@@ -196,29 +196,32 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh,
if (0 == strcasecmp (type,
"DEPOSIT"))
{
- struct TALER_DepositRequestPS dr = {
- .purpose.size = htonl (sizeof (dr)),
- .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT),
- .coin_pub = rh->depconf.coin_pub
- };
+ struct TALER_Amount deposit_fee;
+ struct TALER_MerchantWireHash h_wire;
+ struct TALER_PrivateContractHash h_contract_terms;
+ // struct TALER_ExtensionContractHash h_extensions; // FIXME!
+ struct TALER_DenominationHash h_denom_pub;
+ struct GNUNET_TIME_Absolute wallet_timestamp;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Absolute refund_deadline;
struct TALER_CoinSpendSignatureP sig;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("coin_sig",
&sig),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &dr.h_contract_terms),
+ &h_contract_terms),
GNUNET_JSON_spec_fixed_auto ("h_wire",
- &dr.h_wire),
+ &h_wire),
GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
- &dr.h_denom_pub),
- TALER_JSON_spec_absolute_time_nbo ("timestamp",
- &dr.wallet_timestamp),
- TALER_JSON_spec_absolute_time_nbo ("refund_deadline",
- &dr.refund_deadline),
- TALER_JSON_spec_amount_any_nbo ("deposit_fee",
- &dr.deposit_fee),
+ &h_denom_pub),
+ TALER_JSON_spec_absolute_time ("timestamp",
+ &wallet_timestamp),
+ TALER_JSON_spec_absolute_time ("refund_deadline",
+ &refund_deadline),
+ TALER_JSON_spec_amount_any ("deposit_fee",
+ &deposit_fee),
GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &dr.merchant),
+ &merchant_pub),
GNUNET_JSON_spec_end ()
};
@@ -230,21 +233,26 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- TALER_amount_hton (&dr.amount_with_fee,
- &amount);
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
- &dr,
- &sig.eddsa_signature,
- &rh->depconf.coin_pub.eddsa_pub))
+ TALER_wallet_deposit_verify (&amount,
+ &deposit_fee,
+ &h_wire,
+ &h_contract_terms,
+ NULL /* h_extensions! */,
+ &h_denom_pub,
+ wallet_timestamp,
+ &merchant_pub,
+ refund_deadline,
+ &rh->depconf.coin_pub,
+ &sig))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
if ( (0 != GNUNET_memcmp (&rh->depconf.h_contract_terms,
- &dr.h_contract_terms)) ||
+ &h_contract_terms)) ||
(0 != GNUNET_memcmp (&rh->depconf.merchant,
- &dr.merchant)) )
+ &merchant_pub)) )
{
/* deposit information is about a different merchant/contract */
GNUNET_break_op (0);