From 2d84d7f6ddce69b5c1d4d44a16a9aa0663fd4eba Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 7 May 2022 23:27:56 +0200 Subject: add function for purse status signing --- src/include/taler_crypto_lib.h | 19 +++++++++ src/include/taler_signatures.h | 8 +++- src/util/exchange_signatures.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index 1ee080abc..cf160c689 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -3976,6 +3976,25 @@ TALER_exchange_online_purse_merged_verify ( const struct TALER_ExchangeSignatureP *sig); +enum TALER_ErrorCode +TALER_exchange_purse_status_sign ( + TALER_ExchangeSignCallback scb, + struct GNUNET_TIME_Timestamp merge_timestamp, + struct GNUNET_TIME_Timestamp deposit_timestamp, + const struct TALER_Amount *balance, + struct TALER_ExchangePublicKeyP *pub, + struct TALER_ExchangeSignatureP *sig); + + +enum GNUNET_GenericReturnValue +TALER_exchange_purse_status_verify ( + struct GNUNET_TIME_Timestamp merge_timestamp, + struct GNUNET_TIME_Timestamp deposit_timestamp, + const struct TALER_Amount *balance, + const struct TALER_ExchangePublicKeyP *exchange_pub, + const struct TALER_ExchangeSignatureP *exchange_sig); + + /* ********************* offline signing ************************** */ diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h index 9897082d8..57c84b50b 100644 --- a/src/include/taler_signatures.h +++ b/src/include/taler_signatures.h @@ -189,6 +189,13 @@ */ #define TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_MERGED 1046 +/** + * Purpose for the state of a purse, signed by the exchange's signing + * key. + */ +#define TALER_SIGNATURE_EXCHANGE_PURSE_STATUS 1047 + + /**********************/ /* Auditor signatures */ /**********************/ @@ -383,5 +390,4 @@ #define TALER_SIGNATURE_SYNC_BACKUP_UPLOAD 1450 - #endif diff --git a/src/util/exchange_signatures.c b/src/util/exchange_signatures.c index d6214ab3e..41f2b61a1 100644 --- a/src/util/exchange_signatures.c +++ b/src/util/exchange_signatures.c @@ -1505,4 +1505,93 @@ TALER_exchange_online_purse_merged_verify ( } +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * @brief Format used to generate the signature on a purse status + * from the exchange. + */ +struct TALER_PurseStatusPS +{ + /** + * Purpose must be #TALER_SIGNATURE_EXCHANGE_PURSE_STATUS. Signed + * by a `struct TALER_ExchangePublicKeyP` using EdDSA. + */ + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + + /** + * Time when the purse was merged, possibly 'never'. + */ + struct GNUNET_TIME_TimestampNBO merge_timestamp; + + /** + * Time when the purse was deposited last, possibly 'never'. + */ + struct GNUNET_TIME_TimestampNBO deposit_timestamp; + + /** + * Amount deposited in total in the purse without fees. + * May be possibly less than the target amount. + */ + struct TALER_AmountNBO balance; + +}; + +GNUNET_NETWORK_STRUCT_END + + +enum TALER_ErrorCode +TALER_exchange_purse_status_sign ( + TALER_ExchangeSignCallback scb, + struct GNUNET_TIME_Timestamp merge_timestamp, + struct GNUNET_TIME_Timestamp deposit_timestamp, + const struct TALER_Amount *balance, + struct TALER_ExchangePublicKeyP *pub, + struct TALER_ExchangeSignatureP *sig) +{ + struct TALER_PurseStatusPS dcs = { + .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_PURSE_STATUS), + .purpose.size = htonl (sizeof (dcs)), + .merge_timestamp = GNUNET_TIME_timestamp_hton (merge_timestamp), + .deposit_timestamp = GNUNET_TIME_timestamp_hton (deposit_timestamp) + }; + + TALER_amount_hton (&dcs.balance, + balance); + return scb (&dcs.purpose, + pub, + sig); +} + + +enum GNUNET_GenericReturnValue +TALER_exchange_online_purse_status_verify ( + struct GNUNET_TIME_Timestamp merge_timestamp, + struct GNUNET_TIME_Timestamp deposit_timestamp, + const struct TALER_Amount *balance, + const struct TALER_ExchangePublicKeyP *exchange_pub, + const struct TALER_ExchangeSignatureP *exchange_sig) +{ + struct TALER_PurseStatusPS dcs = { + .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_PURSE_STATUS), + .purpose.size = htonl (sizeof (dcs)), + .merge_timestamp = GNUNET_TIME_timestamp_hton (merge_timestamp), + .deposit_timestamp = GNUNET_TIME_timestamp_hton (deposit_timestamp) + }; + + TALER_amount_hton (&dcs.balance, + balance); + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_PURSE_STATUS, + &dcs, + &exchange_sig->eddsa_signature, + &exchange_pub->eddsa_pub)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + /* end of exchange_signatures.c */ -- cgit v1.2.3