From 1bb5a77c8da3e460b45b3faa49ed10ab6ae9190d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 20 Mar 2022 02:39:28 +0100 Subject: add new reserve status/history signatures --- src/include/taler_crypto_lib.h | 66 ++++++++++++++++++++++++++++++++-- src/include/taler_signatures.h | 55 ++++++++++++++++++++++++++++ src/util/wallet_signatures.c | 82 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 2 deletions(-) diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index 5f091e771..8786a3783 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -2778,7 +2778,7 @@ TALER_wallet_recoup_verify ( * @param h_denom_pub hash of the denomiantion public key of the coin * @param coin_bks blinding factor used when withdrawing the coin * @param coin_priv coin key of the coin to be recouped - * @param coin_sig resulting signature + * @param[out] coin_sig resulting signature */ void TALER_wallet_recoup_sign ( @@ -2811,7 +2811,7 @@ TALER_wallet_recoup_refresh_verify ( * @param h_denom_pub hash of the denomiantion public key of the coin * @param coin_bks blinding factor used when withdrawing the coin * @param coin_priv coin key of the coin to be recouped - * @param coin_sig resulting signature + * @param[out] coin_sig resulting signature */ void TALER_wallet_recoup_refresh_sign ( @@ -2821,6 +2821,68 @@ TALER_wallet_recoup_refresh_sign ( struct TALER_CoinSpendSignatureP *coin_sig); +/** + * Verify reserve history request signature. + * + * @param ts timestamp used + * @param history_fee how much did the wallet say it would pay + * @param reserve_pub reserve the history request was for + * @param reserve_sig resulting signature + * @return #GNUNET_OK if the signature is valid + */ +enum GNUNET_GenericReturnValue +TALER_wallet_reserve_history_verify ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_Amount *history_fee, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_ReserveSignatureP *reserve_sig); + + +/** + * Create reserve history request signature. + * + * @param ts timestamp used + * @param history_fee how much do we expect to pay + * @param reserve_pub reserve the history request is for + * @param[out] reserve_sig resulting signature + */ +void +TALER_wallet_reserve_history_sign ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_Amount *history_fee, + const struct TALER_ReservePrivateKeyP *reserve_priv, + struct TALER_ReserveSignatureP *reserve_sig); + + +/** + * Verify reserve status request signature. + * + * @param ts timestamp used + * @param reserve_pub reserve the status request was for + * @param reserve_sig resulting signature + * @return #GNUNET_OK if the signature is valid + */ +enum GNUNET_GenericReturnValue +TALER_wallet_reserve_status_verify ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_ReserveSignatureP *reserve_sig); + + +/** + * Create reserve status request signature. + * + * @param ts timestamp used + * @param reserve_pub reserve the status request is for + * @param[out] reserve_sig resulting signature + */ +void +TALER_wallet_reserve_status_sign ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_ReservePrivateKeyP *reserve_priv, + struct TALER_ReserveSignatureP *reserve_sig); + + /* ********************* merchant signing ************************** */ diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h index 5c5aaeebf..2aa826200 100644 --- a/src/include/taler_signatures.h +++ b/src/include/taler_signatures.h @@ -283,6 +283,16 @@ */ #define TALER_SIGNATURE_WALLET_AGE_ATTESTATION 1207 +/** + * Request full reserve history and pay for it. + */ +#define TALER_SIGNATURE_WALLET_RESERVE_HISTORY 1208 + +/** + * Request detailed account status (for free). + */ +#define TALER_SIGNATURE_WALLET_RESERVE_STATUS 1209 + /******************************/ /* Security module signatures */ @@ -443,6 +453,51 @@ struct TALER_LinkDataPS }; +/** + * Response by which a wallet requests an account status. + */ +struct TALER_ReserveStatusRequestPS +{ + + /** + * Purpose is #TALER_SIGNATURE_WALLET_RESERVE_STATUS + */ + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + + /** + * When did the wallet make the requst. + */ + struct GNUNET_TIME_TimestampNBO request_timestamp; + +}; + + +/** + * Response by which a wallet requests a full + * reserve history and indicates it is willing + * to pay for it. + */ +struct TALER_ReserveHistoryRequestPS +{ + + /** + * Purpose is #TALER_SIGNATURE_WALLET_RESERVE_HISTORY + */ + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + + /** + * When did the wallet make the requst. + */ + struct GNUNET_TIME_TimestampNBO request_timestamp; + + /** + * How much does the exchange charge for the history? + */ + struct TALER_AmountNBO history_fee; + +}; + + /** * @brief Format used for to generate the signature on a request to withdraw * coins from a reserve. diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c index 69a265205..ef8870442 100644 --- a/src/util/wallet_signatures.c +++ b/src/util/wallet_signatures.c @@ -373,4 +373,86 @@ TALER_wallet_account_setup_sign ( } +enum GNUNET_GenericReturnValue +TALER_wallet_reserve_history_verify ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_Amount *history_fee, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_ReserveSignatureP *reserve_sig) +{ + struct TALER_ReserveHistoryRequestPS rhr = { + .purpose.size = htonl (sizeof (rhr)), + .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_HISTORY), + .request_timestamp = GNUNET_TIME_timestamp_hton (ts) + }; + + TALER_amount_hton (&rhr.history_fee, + history_fee); + return GNUNET_CRYPTO_eddsa_verify ( + TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW, + &rhr, + &reserve_sig->eddsa_signature, + &reserve_pub->eddsa_pub); +} + + +void +TALER_wallet_reserve_history_sign ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_Amount *history_fee, + const struct TALER_ReservePrivateKeyP *reserve_priv, + struct TALER_ReserveSignatureP *reserve_sig) +{ + struct TALER_ReserveHistoryRequestPS rhr = { + .purpose.size = htonl (sizeof (rhr)), + .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_HISTORY), + .request_timestamp = GNUNET_TIME_timestamp_hton (ts) + }; + + TALER_amount_hton (&rhr.history_fee, + history_fee); + GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv, + &rhr, + &reserve_sig->eddsa_signature); +} + + +enum GNUNET_GenericReturnValue +TALER_wallet_reserve_status_verify ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_ReserveSignatureP *reserve_sig) +{ + struct TALER_ReserveStatusRequestPS rsr = { + .purpose.size = htonl (sizeof (rsr)), + .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_STATUS), + .request_timestamp = GNUNET_TIME_timestamp_hton (ts) + }; + + return GNUNET_CRYPTO_eddsa_verify ( + TALER_SIGNATURE_WALLET_RESERVE_STATUS, + &rsr, + &reserve_sig->eddsa_signature, + &reserve_pub->eddsa_pub); +} + + +void +TALER_wallet_reserve_status_sign ( + const struct GNUNET_TIME_Timestamp ts, + const struct TALER_ReservePrivateKeyP *reserve_priv, + struct TALER_ReserveSignatureP *reserve_sig) +{ + struct TALER_ReserveStatusRequestPS rsr = { + .purpose.size = htonl (sizeof (rsr)), + .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_STATUS), + .request_timestamp = GNUNET_TIME_timestamp_hton (ts) + }; + + GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv, + &rsr, + &reserve_sig->eddsa_signature); +} + + /* end of wallet_signatures.c */ -- cgit v1.2.3