From 4cb035cd298139f606562ed88f60ba89dff0febc Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 18 Jun 2017 22:51:55 +0200 Subject: rename file to match content better --- src/exchange/Makefile.am | 2 +- src/exchange/taler-exchange-httpd.c | 3 +- src/exchange/taler-exchange-httpd_reserve.c | 152 --------------------- src/exchange/taler-exchange-httpd_reserve.h | 73 ---------- .../taler-exchange-httpd_reserve_withdraw.c | 152 +++++++++++++++++++++ .../taler-exchange-httpd_reserve_withdraw.h | 53 +++++++ 6 files changed, 208 insertions(+), 227 deletions(-) delete mode 100644 src/exchange/taler-exchange-httpd_reserve.c delete mode 100644 src/exchange/taler-exchange-httpd_reserve.h create mode 100644 src/exchange/taler-exchange-httpd_reserve_withdraw.c create mode 100644 src/exchange/taler-exchange-httpd_reserve_withdraw.h (limited to 'src') diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am index 96e9d7aa2..2c4c5a941 100644 --- a/src/exchange/Makefile.am +++ b/src/exchange/Makefile.am @@ -52,8 +52,8 @@ taler_exchange_httpd_SOURCES = \ taler-exchange-httpd_payback.c taler-exchange-httpd_payback.h \ taler-exchange-httpd_refresh.c taler-exchange-httpd_refresh.h \ taler-exchange-httpd_refund.c taler-exchange-httpd_refund.h \ - taler-exchange-httpd_reserve.c taler-exchange-httpd_reserve.h \ taler-exchange-httpd_reserve_status.c taler-exchange-httpd_reserve_status.h \ + taler-exchange-httpd_reserve_withdraw.c taler-exchange-httpd_reserve_withdraw.h \ taler-exchange-httpd_responses.c taler-exchange-httpd_responses.h \ taler-exchange-httpd_tracking.c taler-exchange-httpd_tracking.h \ taler-exchange-httpd_wire.c taler-exchange-httpd_wire.h \ diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index dbc270b47..67fef7143 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -31,7 +31,8 @@ #include "taler-exchange-httpd_admin.h" #include "taler-exchange-httpd_deposit.h" #include "taler-exchange-httpd_refund.h" -#include "taler-exchange-httpd_reserve.h" +#include "taler-exchange-httpd_reserve_status.h" +#include "taler-exchange-httpd_reserve_withdraw.h" #include "taler-exchange-httpd_payback.h" #include "taler-exchange-httpd_wire.h" #include "taler-exchange-httpd_refresh.h" diff --git a/src/exchange/taler-exchange-httpd_reserve.c b/src/exchange/taler-exchange-httpd_reserve.c deleted file mode 100644 index 08c904c54..000000000 --- a/src/exchange/taler-exchange-httpd_reserve.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014, 2015, 2016 GNUnet e.V. - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License along with - TALER; see the file COPYING. If not, see -*/ -/** - * @file taler-exchange-httpd_reserve.c - * @brief Handle /reserve/ requests - * @author Florian Dold - * @author Benedikt Mueller - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include "taler-exchange-httpd_reserve.h" -#include "taler-exchange-httpd_parsing.h" -#include "taler-exchange-httpd_responses.h" -#include "taler-exchange-httpd_keystate.h" - - -/** - * Handle a "/reserve/withdraw" request. Parses the "reserve_pub" - * EdDSA key of the reserve and the requested "denom_pub" which - * specifies the key/value of the coin to be withdrawn, and checks - * that the signature "reserve_sig" makes this a valid withdrawal - * request from the specified reserve. If so, the envelope - * with the blinded coin "coin_ev" is passed down to execute the - * withdrawl operation. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @return MHD result code - */ -int -TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size) -{ - json_t *root; - struct TALER_WithdrawRequestPS wsrd; - int res; - struct TALER_DenominationPublicKey denomination_pub; - char *blinded_msg; - size_t blinded_msg_len; - struct TALER_Amount amount; - struct TALER_Amount amount_with_fee; - struct TALER_Amount fee_withdraw; - struct TALER_ReserveSignatureP signature; - struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki; - struct TEH_KS_StateHandle *ks; - - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_varsize ("coin_ev", - (void **) &blinded_msg, - &blinded_msg_len), - GNUNET_JSON_spec_fixed_auto ("reserve_pub", - &wsrd.reserve_pub), - GNUNET_JSON_spec_fixed_auto ("reserve_sig", - &signature), - TALER_JSON_spec_denomination_public_key ("denom_pub", - &denomination_pub), - GNUNET_JSON_spec_end () - }; - - res = TEH_PARSE_post_json (connection, - connection_cls, - upload_data, - upload_data_size, - &root); - if (GNUNET_SYSERR == res) - return MHD_NO; - if ( (GNUNET_NO == res) || (NULL == root) ) - return MHD_YES; - res = TEH_PARSE_json_data (connection, - root, - spec); - json_decref (root); - if (GNUNET_OK != res) - return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; - ks = TEH_KS_acquire (); - dki = TEH_KS_denomination_key_lookup (ks, - &denomination_pub, - TEH_KS_DKU_WITHDRAW); - if (NULL == dki) - { - GNUNET_JSON_parse_free (spec); - TEH_KS_release (ks); - return TEH_RESPONSE_reply_arg_unknown (connection, - TALER_EC_WITHDRAW_DENOMINATION_KEY_NOT_FOUND, - "denom_pub"); - } - TALER_amount_ntoh (&amount, - &dki->issue.properties.value); - TALER_amount_ntoh (&fee_withdraw, - &dki->issue.properties.fee_withdraw); - GNUNET_assert (GNUNET_OK == - TALER_amount_add (&amount_with_fee, - &amount, - &fee_withdraw)); - TALER_amount_hton (&wsrd.amount_with_fee, - &amount_with_fee); - TALER_amount_hton (&wsrd.withdraw_fee, - &fee_withdraw); - TEH_KS_release (ks); - /* verify signature! */ - wsrd.purpose.size = htonl (sizeof (struct TALER_WithdrawRequestPS)); - wsrd.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW); - - GNUNET_CRYPTO_rsa_public_key_hash (denomination_pub.rsa_public_key, - &wsrd.h_denomination_pub); - GNUNET_CRYPTO_hash (blinded_msg, - blinded_msg_len, - &wsrd.h_coin_envelope); - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW, - &wsrd.purpose, - &signature.eddsa_signature, - &wsrd.reserve_pub.eddsa_pub)) - { - TALER_LOG_WARNING ("Client supplied invalid signature for /reserve/withdraw request\n"); - GNUNET_JSON_parse_free (spec); - return TEH_RESPONSE_reply_signature_invalid (connection, - TALER_EC_WITHDRAW_RESERVE_SIGNATURE_INVALID, - "reserve_sig"); - } - res = TEH_DB_execute_reserve_withdraw (connection, - &wsrd.reserve_pub, - &denomination_pub, - blinded_msg, - blinded_msg_len, - &signature); - GNUNET_JSON_parse_free (spec); - return res; -} - -/* end of taler-exchange-httpd_reserve.c */ diff --git a/src/exchange/taler-exchange-httpd_reserve.h b/src/exchange/taler-exchange-httpd_reserve.h deleted file mode 100644 index 1db7ea7a4..000000000 --- a/src/exchange/taler-exchange-httpd_reserve.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014 GNUnet e.V. - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License along with - TALER; see the file COPYING. If not, see -*/ -/** - * @file taler-exchange-httpd_reserve.h - * @brief Handle /reserve/ requests - * @author Florian Dold - * @author Benedikt Mueller - * @author Christian Grothoff - */ -#ifndef TALER_EXCHANGE_HTTPD_RESERVE_H -#define TALER_EXCHANGE_HTTPD_RESERVE_H - -#include -#include "taler-exchange-httpd.h" - -/** - * Handle a "/reserve/status" request. Parses the - * given "reserve_pub" argument (which should contain the - * EdDSA public key of a reserve) and then respond with the - * status of the reserve. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @return MHD result code - */ -int -TEH_RESERVE_handler_reserve_status (struct TEH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size); - - -/** - * Handle a "/reserve/withdraw" request. Parses the "reserve_pub" - * EdDSA key of the reserve and the requested "denom_pub" which - * specifies the key/value of the coin to be withdrawn, and checks - * that the signature "reserve_sig" makes this a valid withdrawl - * request from the specified reserve. If so, the envelope - * with the blinded coin "coin_ev" is passed down to execute the - * withdrawl operation. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @return MHD result code - */ -int -TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size); - -#endif diff --git a/src/exchange/taler-exchange-httpd_reserve_withdraw.c b/src/exchange/taler-exchange-httpd_reserve_withdraw.c new file mode 100644 index 000000000..6f6e66a6a --- /dev/null +++ b/src/exchange/taler-exchange-httpd_reserve_withdraw.c @@ -0,0 +1,152 @@ +/* + This file is part of TALER + Copyright (C) 2014, 2015, 2016 GNUnet e.V. + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see +*/ +/** + * @file taler-exchange-httpd_reserve_withdraw.c + * @brief Handle /reserve/withdraw requests + * @author Florian Dold + * @author Benedikt Mueller + * @author Christian Grothoff + */ +#include "platform.h" +#include +#include +#include "taler-exchange-httpd_reserve_withdraw.h" +#include "taler-exchange-httpd_parsing.h" +#include "taler-exchange-httpd_responses.h" +#include "taler-exchange-httpd_keystate.h" + + +/** + * Handle a "/reserve/withdraw" request. Parses the "reserve_pub" + * EdDSA key of the reserve and the requested "denom_pub" which + * specifies the key/value of the coin to be withdrawn, and checks + * that the signature "reserve_sig" makes this a valid withdrawal + * request from the specified reserve. If so, the envelope + * with the blinded coin "coin_ev" is passed down to execute the + * withdrawl operation. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param[in,out] connection_cls the connection's closure (can be updated) + * @param upload_data upload data + * @param[in,out] upload_data_size number of bytes (left) in @a upload_data + * @return MHD result code + */ +int +TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size) +{ + json_t *root; + struct TALER_WithdrawRequestPS wsrd; + int res; + struct TALER_DenominationPublicKey denomination_pub; + char *blinded_msg; + size_t blinded_msg_len; + struct TALER_Amount amount; + struct TALER_Amount amount_with_fee; + struct TALER_Amount fee_withdraw; + struct TALER_ReserveSignatureP signature; + struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki; + struct TEH_KS_StateHandle *ks; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_varsize ("coin_ev", + (void **) &blinded_msg, + &blinded_msg_len), + GNUNET_JSON_spec_fixed_auto ("reserve_pub", + &wsrd.reserve_pub), + GNUNET_JSON_spec_fixed_auto ("reserve_sig", + &signature), + TALER_JSON_spec_denomination_public_key ("denom_pub", + &denomination_pub), + GNUNET_JSON_spec_end () + }; + + res = TEH_PARSE_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &root); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ( (GNUNET_NO == res) || (NULL == root) ) + return MHD_YES; + res = TEH_PARSE_json_data (connection, + root, + spec); + json_decref (root); + if (GNUNET_OK != res) + return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; + ks = TEH_KS_acquire (); + dki = TEH_KS_denomination_key_lookup (ks, + &denomination_pub, + TEH_KS_DKU_WITHDRAW); + if (NULL == dki) + { + GNUNET_JSON_parse_free (spec); + TEH_KS_release (ks); + return TEH_RESPONSE_reply_arg_unknown (connection, + TALER_EC_WITHDRAW_DENOMINATION_KEY_NOT_FOUND, + "denom_pub"); + } + TALER_amount_ntoh (&amount, + &dki->issue.properties.value); + TALER_amount_ntoh (&fee_withdraw, + &dki->issue.properties.fee_withdraw); + GNUNET_assert (GNUNET_OK == + TALER_amount_add (&amount_with_fee, + &amount, + &fee_withdraw)); + TALER_amount_hton (&wsrd.amount_with_fee, + &amount_with_fee); + TALER_amount_hton (&wsrd.withdraw_fee, + &fee_withdraw); + TEH_KS_release (ks); + /* verify signature! */ + wsrd.purpose.size = htonl (sizeof (struct TALER_WithdrawRequestPS)); + wsrd.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW); + + GNUNET_CRYPTO_rsa_public_key_hash (denomination_pub.rsa_public_key, + &wsrd.h_denomination_pub); + GNUNET_CRYPTO_hash (blinded_msg, + blinded_msg_len, + &wsrd.h_coin_envelope); + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW, + &wsrd.purpose, + &signature.eddsa_signature, + &wsrd.reserve_pub.eddsa_pub)) + { + TALER_LOG_WARNING ("Client supplied invalid signature for /reserve/withdraw request\n"); + GNUNET_JSON_parse_free (spec); + return TEH_RESPONSE_reply_signature_invalid (connection, + TALER_EC_WITHDRAW_RESERVE_SIGNATURE_INVALID, + "reserve_sig"); + } + res = TEH_DB_execute_reserve_withdraw (connection, + &wsrd.reserve_pub, + &denomination_pub, + blinded_msg, + blinded_msg_len, + &signature); + GNUNET_JSON_parse_free (spec); + return res; +} + +/* end of taler-exchange-httpd_reserve.c */ diff --git a/src/exchange/taler-exchange-httpd_reserve_withdraw.h b/src/exchange/taler-exchange-httpd_reserve_withdraw.h new file mode 100644 index 000000000..0d5914d74 --- /dev/null +++ b/src/exchange/taler-exchange-httpd_reserve_withdraw.h @@ -0,0 +1,53 @@ +/* + This file is part of TALER + Copyright (C) 2014-2017 GNUnet e.V. + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see +*/ +/** + * @file taler-exchange-httpd_reserve_withdraw.h + * @brief Handle /reserve/withdraw requests + * @author Florian Dold + * @author Benedikt Mueller + * @author Christian Grothoff + */ +#ifndef TALER_EXCHANGE_HTTPD_RESERVE_WITHDRAW_H +#define TALER_EXCHANGE_HTTPD_RESERVE_WITHDRAW_H + +#include +#include "taler-exchange-httpd.h" + + +/** + * Handle a "/reserve/withdraw" request. Parses the "reserve_pub" + * EdDSA key of the reserve and the requested "denom_pub" which + * specifies the key/value of the coin to be withdrawn, and checks + * that the signature "reserve_sig" makes this a valid withdrawl + * request from the specified reserve. If so, the envelope + * with the blinded coin "coin_ev" is passed down to execute the + * withdrawl operation. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param[in,out] connection_cls the connection's closure (can be updated) + * @param upload_data upload data + * @param[in,out] upload_data_size number of bytes (left) in @a upload_data + * @return MHD result code + */ +int +TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size); + +#endif -- cgit v1.2.3