donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 20ed2719ae7b286d38c78d9f4bf30db812ea04d3
parent 92122c17fd59c4259ff05a90b116074c98912c6a
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Tue, 14 May 2024 16:14:11 +0200

work on csr route

Diffstat:
Msrc/donau/Makefile.am | 1+
Msrc/donau/donau-httpd.c | 15++++++++-------
Msrc/donau/donau-httpd_csr.c | 62++++++++++++++++----------------------------------------------
Msrc/donau/donau-httpd_keys.c | 31+++++++++++++++++++++++++++++++
Msrc/donau/donau-httpd_keys.h | 13+++++++++++++
5 files changed, 69 insertions(+), 53 deletions(-)

diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am @@ -49,6 +49,7 @@ donau_httpd_SOURCES = \ donau-httpd_donation-statement.c donau-httpd_donation-statement.h \ donau-httpd_batch-submit.c donau_httpd_batch-submit.h \ donau-httpd_terms.c donau-httpd_terms.h \ + donau-httpd_csr.c donau-httpd_csr.h \ donau-httpd_batch-issue.c donau_httpd_batch-issue.h # Testcases diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c @@ -36,6 +36,7 @@ #include "donau-httpd_batch-issue.h" #include "donau-httpd_batch-submit.h" #include "donau-httpd_history.h" +#include "donau-httpd_csr.h" #include "donau-httpd_terms.h" #include "donaudb_plugin.h" #include <gnunet/gnunet_mhd_compat.h> @@ -467,13 +468,13 @@ handle_mhd_request (void *cls, .handler.delete = &DH_handler_charity_delete, .nargs = 1 }, - // /* POST get csr values*/ - // { - // .url = "csr-issue", - // .method = MHD_HTTP_METHOD_POST, - // .handler.post = &DH_handler_csr_issue, - // .nargs = 0 - // }, + /* POST get csr values*/ + { + .url = "csr-issue", + .method = MHD_HTTP_METHOD_POST, + .handler.post = &DH_handler_csr_issue, + .nargs = 0 + }, /* POST batch issue receipts */ { .url = "batch-issue", diff --git a/src/donau/donau-httpd_csr.c b/src/donau/donau-httpd_csr.c @@ -30,6 +30,7 @@ #include <taler/taler_mhd_lib.h> #include <taler/taler_signatures.h> #include "donaudb_plugin.h" +#include "donau-httpd_keys.h" #include "donau-httpd_csr.h" @@ -70,66 +71,35 @@ DH_handler_csr_issue (struct DH_RequestContext *rc, } { - struct DH_KeyStateHandle *ksh; - - ksh = DH_keys_get_state (); - if (NULL == ksh) - { - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, - NULL); - } - dk = TEH_keys_donation_unit_by_hash_from_state (ksh, - &du_pub_hash, - NULL, - NULL); + dk = DH_keys_donation_unit_by_hash (&du_pub_hash); if (NULL == dk) { - return TEH_RESPONSE_reply_unknown_du_pub_hash ( - rc->connection, - &du_pub_hash); - } - if (GNUNET_TIME_absolute_is_past (dk->meta.expire_withdraw.abs_time)) - { - /* This donation_unit is past the expiration time for withdraws/refreshes*/ - return TEH_RESPONSE_reply_expired_du_pub_hash ( - rc->connection, - &du_pub_hash, - TALER_EC_EXCHANGE_GENERIC_DENOMINATION_EXPIRED, - "csr-withdraw"); - } - if (GNUNET_TIME_absolute_is_future (dk->meta.start.abs_time)) - { - /* This donation_unit is not yet valid, no need to check - for idempotency! */ - return TEH_RESPONSE_reply_expired_du_pub_hash ( + GNUNET_break (0); + return TALER_MHD_reply_with_error ( rc->connection, - &du_pub_hash, - TALER_EC_EXCHANGE_GENERIC_DENOMINATION_VALIDITY_IN_FUTURE, - "csr-withdraw"); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, // FIXME + NULL); } if (GNUNET_CRYPTO_BSA_CS != - dk->denom_pub.bsign_pub_key->cipher) + dk->donation_unit_pub.bsign_pub_key->cipher) { /* donation_unit is valid but not for CS */ - return TEH_RESPONSE_reply_invalid_denom_cipher_for_operation ( + GNUNET_break (0); + return TALER_MHD_reply_with_error ( rc->connection, - &du_pub_hash); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, // FIXME + NULL); } } /* derive r_pub */ { enum TALER_ErrorCode ec; - const struct TEH_CsDeriveData cdd = { - .h_du_pub = &du_pub_hash, - .nonce = &nonce - }; - - ec = TEH_keys_donation_unit_cs_r_pub (&cdd, - false, - &ewv.details.cs_values); + ec = DH_keys_donation_unit_cs_r_pub (&du_pub_hash, + &nonce, + &ewv.details.cs_values); if (TALER_EC_NONE != ec) { GNUNET_break (0); diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -1441,4 +1441,35 @@ DH_keys_donation_unit_by_hash ( } +enum TALER_ErrorCode +DH_keys_donation_unit_cs_r_pub ( + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + const struct GNUNET_CRYPTO_CsSessionNonce *nonce, + struct GNUNET_CRYPTO_CSPublicRPairP *r_pub) +{ + struct DH_DonationUnitKey *dk; + dk = DH_keys_donation_unit_by_hash (&h_donation_unit_pub->hash); + if (NULL == dk) + { + return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN; + } + if (GNUNET_CRYPTO_BSA_CS != + dk->donation_unit_pub.bsign_pub_key->cipher) + { + return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; + } + + { + struct TALER_CRYPTO_CsDeriveRequest cdr = { + .h_cs = &dk->h_donation_unit_pub, + .nonce = nonce + }; + return TALER_CRYPTO_helper_cs_r_derive (csdh, + &cdr, + false, + r_pub); + } +} + + /* end of donau-httpd_keys.c */ diff --git a/src/donau/donau-httpd_keys.h b/src/donau/donau-httpd_keys.h @@ -187,5 +187,18 @@ DH_keys_donation_unit_batch_sign ( const struct DONAU_BkpSignData bkps[num_bkps], struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]); +/** + * Request to derive CS @a r_pub using the donation_unit and nonce from @a cdd. + * + * @param h_donation_unit_pub hash to compute @a r_pub from + * @param nonce + * @param[out] r_pub where to write the result + * @return #TALER_EC_NONE on success + */ +enum TALER_ErrorCode +DH_keys_donation_unit_cs_r_pub ( + const struct DONAU_DonationUnitHashP *h_donation_unit_pub, + const struct GNUNET_CRYPTO_CsSessionNonce *nonce, + struct GNUNET_CRYPTO_CSPublicRPairP *r_pub); #endif