2015-01-16 13:50:07 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2015-02-08 00:16:22 +01:00
|
|
|
Copyright (C) 2014, 2015 GNUnet e.V.
|
2015-01-16 13:50:07 +01:00
|
|
|
|
|
|
|
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, If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file taler-mint-httpd_responses.c
|
|
|
|
* @brief API for generating the various replies of the mint; these
|
2015-03-27 19:58:40 +01:00
|
|
|
* functions are called TMH_RESPONSE_reply_ and they generate
|
2015-01-16 13:50:07 +01:00
|
|
|
* and queue MHD response objects for a given connection.
|
|
|
|
* @author Florian Dold
|
|
|
|
* @author Benedikt Mueller
|
|
|
|
* @author Christian Grothoff
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler-mint-httpd_responses.h"
|
2015-01-28 20:55:15 +01:00
|
|
|
#include "taler_util.h"
|
2015-01-27 14:55:05 +01:00
|
|
|
#include <gnunet/gnunet_util_lib.h>
|
2015-01-28 21:08:19 +01:00
|
|
|
#include "taler-mint-httpd_keystate.h"
|
2015-01-16 13:50:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-01-28 19:58:20 +01:00
|
|
|
* Send JSON object as response.
|
2015-01-16 13:50:07 +01:00
|
|
|
*
|
|
|
|
* @param connection the MHD connection
|
|
|
|
* @param json the json object
|
|
|
|
* @param response_code the http response code
|
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_json (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const json_t *json,
|
|
|
|
unsigned int response_code)
|
2015-01-16 13:50:07 +01:00
|
|
|
{
|
|
|
|
struct MHD_Response *resp;
|
|
|
|
char *json_str;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
json_str = json_dumps (json, JSON_INDENT(2));
|
|
|
|
resp = MHD_create_response_from_buffer (strlen (json_str), json_str,
|
|
|
|
MHD_RESPMEM_MUST_FREE);
|
|
|
|
if (NULL == resp)
|
|
|
|
return MHD_NO;
|
|
|
|
(void) MHD_add_response_header (resp,
|
|
|
|
MHD_HTTP_HEADER_CONTENT_TYPE,
|
|
|
|
"application/json");
|
|
|
|
ret = MHD_queue_response (connection, response_code, resp);
|
|
|
|
MHD_destroy_response (resp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to call to handle the request by building a JSON
|
|
|
|
* reply from a format string and varargs.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to handle
|
|
|
|
* @param response_code HTTP response code to use
|
|
|
|
* @param fmt format string for pack
|
|
|
|
* @param ... varargs
|
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
unsigned int response_code,
|
|
|
|
const char *fmt,
|
|
|
|
...)
|
2015-01-16 13:50:07 +01:00
|
|
|
{
|
|
|
|
json_t *json;
|
|
|
|
va_list argp;
|
2015-01-28 19:58:20 +01:00
|
|
|
int ret;
|
2015-01-16 13:50:07 +01:00
|
|
|
|
|
|
|
va_start (argp, fmt);
|
|
|
|
json = json_vpack_ex (NULL, 0, fmt, argp);
|
|
|
|
va_end (argp);
|
|
|
|
if (NULL == json)
|
|
|
|
return MHD_NO;
|
2015-03-27 19:58:40 +01:00
|
|
|
ret = TMH_RESPONSE_reply_json (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
json,
|
|
|
|
response_code);
|
2015-01-28 19:58:20 +01:00
|
|
|
json_decref (json);
|
|
|
|
return ret;
|
2015-01-16 13:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a response indicating an invalid argument.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @param param_name the parameter that is invalid
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const char *param_name)
|
2015-01-16 13:50:07 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_BAD_REQUEST,
|
|
|
|
"{s:s, s:s}",
|
|
|
|
"error", "invalid parameter",
|
|
|
|
"parameter", param_name);
|
2015-01-16 13:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 14:55:25 +01:00
|
|
|
/**
|
2015-04-08 22:28:52 +02:00
|
|
|
* Send a response indicating an argument refering to a
|
|
|
|
* resource unknown to the mint (i.e. unknown reserve or
|
|
|
|
* denomination key).
|
2015-01-28 14:55:25 +01:00
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
2015-04-08 22:28:52 +02:00
|
|
|
* @param param_name the parameter that is invalid
|
|
|
|
* @return a MHD result code
|
2015-01-28 14:55:25 +01:00
|
|
|
*/
|
|
|
|
int
|
2015-04-08 22:28:52 +02:00
|
|
|
TMH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection,
|
|
|
|
const char *param_name)
|
2015-01-28 14:55:25 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_NOT_FOUND,
|
|
|
|
"{s:s, s:s}",
|
|
|
|
"error", "unknown entity referenced",
|
|
|
|
"parameter", param_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a response indicating an invalid signature.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @param param_name the parameter that is invalid
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TMH_RESPONSE_reply_signature_invalid (struct MHD_Connection *connection,
|
|
|
|
const char *param_name)
|
|
|
|
{
|
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
|
|
|
MHD_HTTP_UNAUTHORIZED,
|
|
|
|
"{s:s, s:s}",
|
|
|
|
"error", "invalid signature",
|
|
|
|
"parameter", param_name);
|
2015-01-28 14:55:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-16 13:50:07 +01:00
|
|
|
/**
|
|
|
|
* Send a response indicating a missing argument.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @param param_name the parameter that is missing
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const char *param_name)
|
2015-01-16 13:50:07 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_BAD_REQUEST,
|
|
|
|
"{ s:s, s:s}",
|
|
|
|
"error", "missing parameter",
|
|
|
|
"parameter", param_name);
|
2015-01-16 13:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 22:09:15 +02:00
|
|
|
/**
|
|
|
|
* Send a response indicating permission denied.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @param hint hint about why access was denied
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TMH_RESPONSE_reply_permission_denied (struct MHD_Connection *connection,
|
|
|
|
const char *hint)
|
|
|
|
{
|
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
|
|
|
MHD_HTTP_FORBIDDEN,
|
|
|
|
"{s:s, s:s}",
|
|
|
|
"error", "permission denied",
|
|
|
|
"hint", hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-16 14:27:42 +01:00
|
|
|
/**
|
|
|
|
* Send a response indicating an internal error.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @param hint hint about the internal error's nature
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const char *hint)
|
2015-01-16 14:27:42 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
|
|
|
"{s:s, s:s}",
|
|
|
|
"error", "internal error",
|
|
|
|
"hint", hint);
|
2015-01-16 14:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-31 15:42:00 +01:00
|
|
|
/**
|
|
|
|
* Send a response indicating an external error.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @param hint hint about the error's nature
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
const char *hint)
|
2015-01-31 15:42:00 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-01-31 15:42:00 +01:00
|
|
|
MHD_HTTP_BAD_REQUEST,
|
|
|
|
"{s:s, s:s}",
|
|
|
|
"error", "client error",
|
|
|
|
"hint", hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 22:47:03 +01:00
|
|
|
/**
|
|
|
|
* Send a response indicating an error committing a
|
|
|
|
* transaction (concurrent interference).
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_commit_error (struct MHD_Connection *connection)
|
2015-01-28 22:47:03 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-01-28 22:47:03 +01:00
|
|
|
MHD_HTTP_BAD_REQUEST,
|
|
|
|
"{s:s}",
|
|
|
|
"error", "commit failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-21 14:21:58 +01:00
|
|
|
/**
|
|
|
|
* Send a response indicating a failure to talk to the Mint's
|
|
|
|
* database.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_internal_db_error (struct MHD_Connection *connection)
|
2015-01-21 14:21:58 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_internal_error (connection,
|
2015-01-21 14:21:58 +01:00
|
|
|
"Failed to connect to database");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-16 14:27:42 +01:00
|
|
|
/**
|
|
|
|
* Send a response indicating that the request was too big.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_request_too_large (struct MHD_Connection *connection)
|
2015-01-16 14:27:42 +01:00
|
|
|
{
|
|
|
|
struct MHD_Response *resp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
resp = MHD_create_response_from_buffer (0,
|
|
|
|
NULL,
|
|
|
|
MHD_RESPMEM_PERSISTENT);
|
|
|
|
if (NULL == resp)
|
|
|
|
return MHD_NO;
|
|
|
|
ret = MHD_queue_response (connection,
|
|
|
|
MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
|
|
|
|
resp);
|
|
|
|
MHD_destroy_response (resp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a response indicating that the JSON was malformed.
|
|
|
|
*
|
|
|
|
* @param connection the MHD connection to use
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_invalid_json (struct MHD_Connection *connection)
|
2015-01-16 14:27:42 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_BAD_REQUEST,
|
|
|
|
"{s:s}",
|
|
|
|
"error",
|
|
|
|
"invalid json");
|
2015-01-16 14:27:42 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 13:50:07 +01:00
|
|
|
|
2015-01-19 21:04:58 +01:00
|
|
|
/**
|
2015-01-28 15:35:41 +01:00
|
|
|
* Send confirmation of deposit success to client. This function
|
|
|
|
* will create a signed message affirming the given information
|
|
|
|
* and return it to the client. By this, the mint affirms that
|
|
|
|
* the coin had sufficient (residual) value for the specified
|
|
|
|
* transaction and that it will execute the requested deposit
|
|
|
|
* operation with the given wiring details.
|
2015-01-19 21:04:58 +01:00
|
|
|
*
|
|
|
|
* @param connection connection to the client
|
2015-01-28 15:35:41 +01:00
|
|
|
* @param coin_pub public key of the coin
|
|
|
|
* @param h_wire hash of wire details
|
|
|
|
* @param h_contract hash of contract details
|
|
|
|
* @param transaction_id transaction ID
|
2015-03-28 17:21:51 +01:00
|
|
|
* @param refund_deadline until when this deposit be refunded
|
2015-01-28 15:35:41 +01:00
|
|
|
* @param merchant merchant public key
|
2015-03-28 14:39:31 +01:00
|
|
|
* @param amount_without_fee fraction of coin value to deposit, without the fee
|
2015-01-19 21:04:58 +01:00
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_deposit_success (struct MHD_Connection *connection,
|
2015-05-16 14:15:34 +02:00
|
|
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
2015-03-28 17:21:51 +01:00
|
|
|
const struct GNUNET_HashCode *h_wire,
|
|
|
|
const struct GNUNET_HashCode *h_contract,
|
|
|
|
uint64_t transaction_id,
|
|
|
|
struct GNUNET_TIME_Absolute refund_deadline,
|
|
|
|
const struct TALER_MerchantPublicKeyP *merchant,
|
|
|
|
const struct TALER_Amount *amount_without_fee)
|
2015-01-19 21:04:58 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
struct TALER_DepositConfirmationPS dc;
|
|
|
|
struct TALER_MintSignatureP sig;
|
2015-01-28 19:48:41 +01:00
|
|
|
json_t *sig_json;
|
|
|
|
int ret;
|
|
|
|
|
2015-03-28 14:22:21 +01:00
|
|
|
dc.purpose.purpose = htonl (TALER_SIGNATURE_MINT_CONFIRM_DEPOSIT);
|
2015-03-27 19:58:40 +01:00
|
|
|
dc.purpose.size = htonl (sizeof (struct TALER_DepositConfirmationPS));
|
2015-01-28 19:48:41 +01:00
|
|
|
dc.h_contract = *h_contract;
|
|
|
|
dc.h_wire = *h_wire;
|
|
|
|
dc.transaction_id = GNUNET_htonll (transaction_id);
|
2015-03-28 17:21:51 +01:00
|
|
|
dc.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
|
|
|
|
dc.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
|
2015-03-28 14:39:31 +01:00
|
|
|
TALER_amount_hton (&dc.amount_without_fee,
|
|
|
|
amount_without_fee);
|
2015-01-28 19:48:41 +01:00
|
|
|
dc.coin_pub = *coin_pub;
|
|
|
|
dc.merchant = *merchant;
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_KS_sign (&dc.purpose,
|
2015-03-28 17:21:51 +01:00
|
|
|
&sig);
|
2015-03-27 19:58:40 +01:00
|
|
|
sig_json = TALER_json_from_eddsa_sig (&dc.purpose,
|
2015-03-22 22:14:30 +01:00
|
|
|
&sig.eddsa_signature);
|
2015-03-27 19:58:40 +01:00
|
|
|
ret = TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_OK,
|
|
|
|
"{s:s, s:o}",
|
|
|
|
"status", "DEPOSIT_OK",
|
|
|
|
"signature", sig_json);
|
2015-01-28 19:48:41 +01:00
|
|
|
json_decref (sig_json);
|
|
|
|
return ret;
|
2015-01-19 21:04:58 +01:00
|
|
|
}
|
2015-01-16 13:50:07 +01:00
|
|
|
|
2015-03-24 18:27:19 +01:00
|
|
|
|
2015-01-29 00:09:48 +01:00
|
|
|
/**
|
2015-03-10 16:15:14 +01:00
|
|
|
* Compile the transaction history of a coin into a JSON object.
|
2015-01-29 00:09:48 +01:00
|
|
|
*
|
2015-03-10 16:15:14 +01:00
|
|
|
* @param tl transaction history to JSON-ify
|
|
|
|
* @return json representation of the @a rh
|
2015-01-29 00:09:48 +01:00
|
|
|
*/
|
2015-03-10 16:15:14 +01:00
|
|
|
static json_t *
|
2015-03-28 14:39:31 +01:00
|
|
|
compile_transaction_history (const struct TALER_MINTDB_TransactionList *tl)
|
2015-01-29 00:09:48 +01:00
|
|
|
{
|
2015-03-09 12:29:41 +01:00
|
|
|
json_t *transaction;
|
|
|
|
const char *type;
|
|
|
|
struct TALER_Amount value;
|
2015-03-10 16:15:14 +01:00
|
|
|
json_t *history;
|
2015-03-28 14:39:31 +01:00
|
|
|
const struct TALER_MINTDB_TransactionList *pos;
|
2015-01-29 00:09:48 +01:00
|
|
|
|
2015-03-09 12:29:41 +01:00
|
|
|
history = json_array ();
|
2015-01-29 00:09:48 +01:00
|
|
|
for (pos = tl; NULL != pos; pos = pos->next)
|
|
|
|
{
|
|
|
|
switch (pos->type)
|
|
|
|
{
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_TT_DEPOSIT:
|
2015-03-09 12:29:41 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
struct TALER_DepositRequestPS dr;
|
2015-03-28 14:39:31 +01:00
|
|
|
const struct TALER_MINTDB_Deposit *deposit = pos->details.deposit;
|
2015-03-09 12:29:41 +01:00
|
|
|
|
|
|
|
type = "deposit";
|
2015-03-22 16:09:01 +01:00
|
|
|
value = deposit->amount_with_fee;
|
2015-03-28 14:22:21 +01:00
|
|
|
dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT);
|
2015-03-27 19:58:40 +01:00
|
|
|
dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS));
|
2015-03-09 12:29:41 +01:00
|
|
|
dr.h_contract = deposit->h_contract;
|
|
|
|
dr.h_wire = deposit->h_wire;
|
2015-03-28 17:10:39 +01:00
|
|
|
dr.timestamp = GNUNET_TIME_absolute_hton (deposit->timestamp);
|
|
|
|
dr.refund_deadline = GNUNET_TIME_absolute_hton (deposit->refund_deadline);
|
2015-03-09 12:29:41 +01:00
|
|
|
dr.transaction_id = GNUNET_htonll (deposit->transaction_id);
|
2015-03-22 16:09:01 +01:00
|
|
|
TALER_amount_hton (&dr.amount_with_fee,
|
|
|
|
&deposit->amount_with_fee);
|
2015-03-28 17:10:39 +01:00
|
|
|
TALER_amount_hton (&dr.deposit_fee,
|
|
|
|
&deposit->deposit_fee);
|
|
|
|
dr.merchant = deposit->merchant_pub;
|
2015-03-09 12:29:41 +01:00
|
|
|
dr.coin_pub = deposit->coin.coin_pub;
|
2015-05-16 14:15:34 +02:00
|
|
|
transaction = TALER_json_from_eddsa_sig (&dr.purpose,
|
|
|
|
&deposit->csig.eddsa_signature);
|
2015-03-09 12:29:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_TT_REFRESH_MELT:
|
2015-03-09 12:29:41 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
struct TALER_RefreshMeltCoinAffirmationPS ms;
|
2015-03-28 14:39:31 +01:00
|
|
|
const struct TALER_MINTDB_RefreshMelt *melt = pos->details.melt;
|
2015-04-08 22:29:21 +02:00
|
|
|
|
2015-03-09 12:29:41 +01:00
|
|
|
type = "melt";
|
2015-03-22 16:09:01 +01:00
|
|
|
value = melt->amount_with_fee;
|
2015-03-28 14:22:21 +01:00
|
|
|
ms.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_MELT);
|
2015-03-27 19:58:40 +01:00
|
|
|
ms.purpose.size = htonl (sizeof (struct TALER_RefreshMeltCoinAffirmationPS));
|
2015-03-24 16:56:06 +01:00
|
|
|
ms.session_hash = melt->session_hash;
|
2015-03-22 16:09:01 +01:00
|
|
|
TALER_amount_hton (&ms.amount_with_fee,
|
|
|
|
&melt->amount_with_fee);
|
2015-03-28 17:27:08 +01:00
|
|
|
TALER_amount_hton (&ms.melt_fee,
|
|
|
|
&melt->melt_fee);
|
2015-03-10 17:00:12 +01:00
|
|
|
ms.coin_pub = melt->coin.coin_pub;
|
2015-05-16 14:15:34 +02:00
|
|
|
transaction = TALER_json_from_eddsa_sig (&ms.purpose,
|
|
|
|
&melt->coin_sig.eddsa_signature);
|
2015-03-09 12:29:41 +01:00
|
|
|
}
|
2015-01-29 00:09:48 +01:00
|
|
|
break;
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_TT_LOCK:
|
2015-03-09 12:29:41 +01:00
|
|
|
{
|
|
|
|
type = "lock";
|
|
|
|
value = pos->details.lock->amount;
|
|
|
|
transaction = NULL;
|
|
|
|
GNUNET_break (0); /* #3625: Lock NOT implemented! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
GNUNET_assert (0);
|
2015-01-29 00:09:48 +01:00
|
|
|
}
|
2015-03-09 12:29:41 +01:00
|
|
|
json_array_append_new (history,
|
|
|
|
json_pack ("{s:s, s:o}",
|
|
|
|
"type", type,
|
2015-03-27 19:58:40 +01:00
|
|
|
"amount", TALER_json_from_amount (&value),
|
2015-03-09 12:29:41 +01:00
|
|
|
"signature", transaction));
|
2015-01-29 00:09:48 +01:00
|
|
|
}
|
2015-03-10 16:15:14 +01:00
|
|
|
return history;
|
|
|
|
}
|
2015-01-29 00:09:48 +01:00
|
|
|
|
2015-03-10 16:15:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send proof that a /withdraw request is invalid to client. This
|
|
|
|
* function will create a message with all of the operations affecting
|
|
|
|
* the coin that demonstrate that the coin has insufficient value.
|
|
|
|
*
|
|
|
|
* @param connection connection to the client
|
|
|
|
* @param tl transaction list to use to build reply
|
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_deposit_insufficient_funds (struct MHD_Connection *connection,
|
2015-03-28 17:27:08 +01:00
|
|
|
const struct TALER_MINTDB_TransactionList *tl)
|
2015-03-10 16:15:14 +01:00
|
|
|
{
|
|
|
|
json_t *history;
|
|
|
|
|
|
|
|
history = compile_transaction_history (tl);
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
MHD_HTTP_PRECONDITION_FAILED,
|
2015-03-28 17:27:08 +01:00
|
|
|
"{s:s, s:o}",
|
|
|
|
"error", "insufficient funds",
|
|
|
|
"history", history);
|
2015-01-29 00:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-19 21:53:23 +01:00
|
|
|
/**
|
2015-01-29 00:45:07 +01:00
|
|
|
* Compile the history of a reserve into a JSON object
|
|
|
|
* and calculate the total balance.
|
2015-01-19 21:53:23 +01:00
|
|
|
*
|
2015-01-29 00:45:07 +01:00
|
|
|
* @param rh reserve history to JSON-ify
|
2015-03-28 15:42:07 +01:00
|
|
|
* @param[out] balance set to current reserve balance
|
2015-03-18 18:55:41 +01:00
|
|
|
* @return json representation of the @a rh, NULL on error
|
2015-01-19 21:53:23 +01:00
|
|
|
*/
|
2015-01-29 00:45:07 +01:00
|
|
|
static json_t *
|
2015-03-28 14:39:31 +01:00
|
|
|
compile_reserve_history (const struct TALER_MINTDB_ReserveHistory *rh,
|
2015-01-29 00:45:07 +01:00
|
|
|
struct TALER_Amount *balance)
|
2015-01-19 21:53:23 +01:00
|
|
|
{
|
2015-01-29 00:09:48 +01:00
|
|
|
struct TALER_Amount deposit_total;
|
|
|
|
struct TALER_Amount withdraw_total;
|
|
|
|
struct TALER_Amount value;
|
|
|
|
json_t *json_history;
|
2015-03-09 13:04:51 +01:00
|
|
|
json_t *transaction;
|
2015-01-28 19:58:20 +01:00
|
|
|
int ret;
|
2015-03-28 14:39:31 +01:00
|
|
|
const struct TALER_MINTDB_ReserveHistory *pos;
|
2015-03-27 19:58:40 +01:00
|
|
|
struct TALER_WithdrawRequestPS wr;
|
2015-01-29 00:09:48 +01:00
|
|
|
|
|
|
|
json_history = json_array ();
|
|
|
|
ret = 0;
|
|
|
|
for (pos = rh; NULL != pos; pos = pos->next)
|
|
|
|
{
|
|
|
|
switch (pos->type)
|
|
|
|
{
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_RO_BANK_TO_MINT:
|
2015-01-29 00:09:48 +01:00
|
|
|
if (0 == ret)
|
|
|
|
deposit_total = pos->details.bank->amount;
|
|
|
|
else
|
2015-03-18 18:55:41 +01:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_amount_add (&deposit_total,
|
|
|
|
&deposit_total,
|
|
|
|
&pos->details.bank->amount))
|
|
|
|
{
|
|
|
|
json_decref (json_history);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-29 00:09:48 +01:00
|
|
|
ret = 1;
|
|
|
|
json_array_append_new (json_history,
|
|
|
|
json_pack ("{s:s, s:o, s:o}",
|
|
|
|
"type", "DEPOSIT",
|
|
|
|
"wire", pos->details.bank->wire,
|
2015-03-27 19:58:40 +01:00
|
|
|
"amount", TALER_json_from_amount (&pos->details.bank->amount)));
|
2015-01-29 00:09:48 +01:00
|
|
|
break;
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_RO_WITHDRAW_COIN:
|
2015-01-29 00:09:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for (pos = rh; NULL != pos; pos = pos->next)
|
|
|
|
{
|
|
|
|
switch (pos->type)
|
|
|
|
{
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_RO_BANK_TO_MINT:
|
2015-01-29 00:09:48 +01:00
|
|
|
break;
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_RO_WITHDRAW_COIN:
|
2015-04-13 13:11:54 +02:00
|
|
|
value = pos->details.withdraw->amount_with_fee;
|
2015-01-29 00:09:48 +01:00
|
|
|
if (0 == ret)
|
2015-04-13 13:11:54 +02:00
|
|
|
{
|
2015-01-29 00:09:48 +01:00
|
|
|
withdraw_total = value;
|
2015-04-13 13:11:54 +02:00
|
|
|
}
|
2015-01-29 00:09:48 +01:00
|
|
|
else
|
2015-04-13 13:11:54 +02:00
|
|
|
{
|
2015-03-18 18:55:41 +01:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_amount_add (&withdraw_total,
|
|
|
|
&withdraw_total,
|
|
|
|
&value))
|
|
|
|
{
|
|
|
|
json_decref (json_history);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-04-13 13:11:54 +02:00
|
|
|
}
|
2015-01-29 00:09:48 +01:00
|
|
|
ret = 1;
|
2015-03-28 14:22:21 +01:00
|
|
|
wr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW);
|
2015-03-27 19:58:40 +01:00
|
|
|
wr.purpose.size = htonl (sizeof (struct TALER_WithdrawRequestPS));
|
2015-03-09 13:04:51 +01:00
|
|
|
wr.reserve_pub = pos->details.withdraw->reserve_pub;
|
2015-03-28 16:51:54 +01:00
|
|
|
TALER_amount_hton (&wr.amount_with_fee,
|
2015-04-13 13:11:54 +02:00
|
|
|
&value);
|
2015-03-28 16:51:54 +01:00
|
|
|
TALER_amount_hton (&wr.withdraw_fee,
|
|
|
|
&pos->details.withdraw->withdraw_fee);
|
2015-03-22 22:14:30 +01:00
|
|
|
GNUNET_CRYPTO_rsa_public_key_hash (pos->details.withdraw->denom_pub.rsa_public_key,
|
2015-03-09 13:04:51 +01:00
|
|
|
&wr.h_denomination_pub);
|
|
|
|
wr.h_coin_envelope = pos->details.withdraw->h_coin_envelope;
|
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
transaction = TALER_json_from_eddsa_sig (&wr.purpose,
|
2015-03-22 22:14:30 +01:00
|
|
|
&pos->details.withdraw->reserve_sig.eddsa_signature);
|
2015-03-09 13:04:51 +01:00
|
|
|
|
2015-01-29 00:09:48 +01:00
|
|
|
json_array_append_new (json_history,
|
|
|
|
json_pack ("{s:s, s:o, s:o}",
|
|
|
|
"type", "WITHDRAW",
|
2015-03-09 13:04:51 +01:00
|
|
|
"signature", transaction,
|
2015-03-27 19:58:40 +01:00
|
|
|
"amount", TALER_json_from_amount (&value)));
|
2015-01-29 00:09:48 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 09:59:18 +02:00
|
|
|
if (0 == ret)
|
|
|
|
{
|
|
|
|
/* history is empty!? */
|
|
|
|
GNUNET_break (0);
|
|
|
|
json_decref (json_history);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-03-18 18:55:41 +01:00
|
|
|
if (GNUNET_SYSERR ==
|
|
|
|
TALER_amount_subtract (balance,
|
|
|
|
&deposit_total,
|
|
|
|
&withdraw_total))
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
json_decref (json_history);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-29 00:45:07 +01:00
|
|
|
return json_history;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send reserve status information to client.
|
|
|
|
*
|
|
|
|
* @param connection connection to the client
|
|
|
|
* @param rh reserve history to return
|
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_withdraw_status_success (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const struct TALER_MINTDB_ReserveHistory *rh)
|
2015-01-29 00:45:07 +01:00
|
|
|
{
|
|
|
|
json_t *json_balance;
|
|
|
|
json_t *json_history;
|
|
|
|
struct TALER_Amount balance;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
json_history = compile_reserve_history (rh,
|
|
|
|
&balance);
|
2015-03-18 18:55:41 +01:00
|
|
|
if (NULL == json_history)
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_internal_error (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
"balance calculation failure");
|
2015-03-27 19:58:40 +01:00
|
|
|
json_balance = TALER_json_from_amount (&balance);
|
|
|
|
ret = TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_OK,
|
|
|
|
"{s:o, s:o}",
|
|
|
|
"balance", json_balance,
|
|
|
|
"history", json_history);
|
2015-01-29 00:09:48 +01:00
|
|
|
json_decref (json_history);
|
2015-01-28 19:58:20 +01:00
|
|
|
json_decref (json_balance);
|
|
|
|
return ret;
|
2015-01-19 21:53:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-29 00:45:07 +01:00
|
|
|
/**
|
|
|
|
* Send reserve status information to client with the
|
|
|
|
* message that we have insufficient funds for the
|
|
|
|
* requested /withdraw/sign operation.
|
|
|
|
*
|
|
|
|
* @param connection connection to the client
|
|
|
|
* @param rh reserve history to return
|
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const struct TALER_MINTDB_ReserveHistory *rh)
|
2015-01-29 00:45:07 +01:00
|
|
|
{
|
|
|
|
json_t *json_balance;
|
|
|
|
json_t *json_history;
|
|
|
|
struct TALER_Amount balance;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
json_history = compile_reserve_history (rh,
|
|
|
|
&balance);
|
2015-03-18 18:55:41 +01:00
|
|
|
if (NULL == json_history)
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_internal_error (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
"balance calculation failure");
|
2015-03-27 19:58:40 +01:00
|
|
|
json_balance = TALER_json_from_amount (&balance);
|
|
|
|
ret = TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
MHD_HTTP_FORBIDDEN,
|
2015-04-08 22:28:52 +02:00
|
|
|
"{s:s, s:o, s:o}",
|
|
|
|
"error", "Insufficient funds"
|
|
|
|
"balance", json_balance,
|
|
|
|
"history", json_history);
|
2015-01-29 00:45:07 +01:00
|
|
|
json_decref (json_history);
|
|
|
|
json_decref (json_balance);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-19 21:53:23 +01:00
|
|
|
/**
|
|
|
|
* Send blinded coin information to client.
|
|
|
|
*
|
|
|
|
* @param connection connection to the client
|
|
|
|
* @param collectable blinded coin to return
|
|
|
|
* @return MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_withdraw_sign_success (struct MHD_Connection *connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
const struct TALER_MINTDB_CollectableBlindcoin *collectable)
|
2015-01-19 21:53:23 +01:00
|
|
|
{
|
2015-01-28 19:58:20 +01:00
|
|
|
json_t *sig_json;
|
|
|
|
int ret;
|
2015-01-19 21:53:23 +01:00
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
sig_json = TALER_json_from_rsa_signature (collectable->sig.rsa_signature);
|
|
|
|
ret = TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-08 22:28:52 +02:00
|
|
|
MHD_HTTP_OK,
|
|
|
|
"{s:o}",
|
|
|
|
"ev_sig", sig_json);
|
2015-01-28 19:58:20 +01:00
|
|
|
json_decref (sig_json);
|
|
|
|
return ret;
|
2015-01-19 21:53:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-20 17:12:51 +01:00
|
|
|
/**
|
2015-03-10 16:15:14 +01:00
|
|
|
* Send a response for a failed "/refresh/melt" request. The
|
|
|
|
* transaction history of the given coin demonstrates that the
|
|
|
|
* @a residual value of the coin is below the @a requested
|
|
|
|
* contribution of the coin for the melt. Thus, the mint
|
|
|
|
* refuses the melt operation.
|
2015-01-20 17:12:51 +01:00
|
|
|
*
|
|
|
|
* @param connection the connection to send the response to
|
2015-03-10 16:15:14 +01:00
|
|
|
* @param coin_pub public key of the coin
|
|
|
|
* @param coin_value original value of the coin
|
|
|
|
* @param tl transaction history for the coin
|
|
|
|
* @param requested how much this coin was supposed to contribute
|
|
|
|
* @param residual remaining value of the coin (after subtracting @a tl)
|
2015-01-20 17:12:51 +01:00
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_refresh_melt_insufficient_funds (struct MHD_Connection *connection,
|
2015-05-16 14:15:34 +02:00
|
|
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
2015-04-09 20:37:21 +02:00
|
|
|
struct TALER_Amount coin_value,
|
|
|
|
struct TALER_MINTDB_TransactionList *tl,
|
|
|
|
struct TALER_Amount requested,
|
|
|
|
struct TALER_Amount residual)
|
2015-01-20 17:12:51 +01:00
|
|
|
{
|
2015-03-10 16:15:14 +01:00
|
|
|
json_t *history;
|
2015-01-20 17:12:51 +01:00
|
|
|
|
2015-03-10 16:15:14 +01:00
|
|
|
history = compile_transaction_history (tl);
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
MHD_HTTP_NOT_FOUND,
|
|
|
|
"{s:s, s:o, s:o, s:o, s:o, s:o}",
|
|
|
|
"error", "insufficient funds",
|
|
|
|
"coin-pub", TALER_json_from_data (coin_pub,
|
2015-05-16 14:15:34 +02:00
|
|
|
sizeof (struct TALER_CoinSpendPublicKeyP)),
|
2015-04-09 20:37:21 +02:00
|
|
|
"original-value", TALER_json_from_amount (&coin_value),
|
|
|
|
"residual-value", TALER_json_from_amount (&residual),
|
|
|
|
"requested-value", TALER_json_from_amount (&requested),
|
|
|
|
"history", history);
|
2015-01-20 17:12:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-20 15:17:41 +01:00
|
|
|
/**
|
2015-03-10 16:15:14 +01:00
|
|
|
* Send a response to a "/refresh/melt" request.
|
2015-01-20 15:17:41 +01:00
|
|
|
*
|
|
|
|
* @param connection the connection to send the response to
|
2015-03-09 13:21:55 +01:00
|
|
|
* @param session_hash hash of the refresh session
|
|
|
|
* @param noreveal_index which index will the client not have to reveal
|
2015-01-20 15:17:41 +01:00
|
|
|
* @return a MHD status code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
const struct GNUNET_HashCode *session_hash,
|
|
|
|
uint16_t noreveal_index)
|
2015-01-20 15:17:41 +01:00
|
|
|
{
|
2015-03-27 19:58:40 +01:00
|
|
|
struct TALER_RefreshMeltConfirmationPS body;
|
|
|
|
struct TALER_MintSignatureP sig;
|
2015-01-20 15:17:41 +01:00
|
|
|
json_t *sig_json;
|
2015-01-28 19:58:20 +01:00
|
|
|
int ret;
|
2015-01-20 15:17:41 +01:00
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
body.purpose.size = htonl (sizeof (struct TALER_RefreshMeltConfirmationPS));
|
2015-03-28 14:22:21 +01:00
|
|
|
body.purpose.purpose = htonl (TALER_SIGNATURE_MINT_CONFIRM_MELT);
|
2015-03-09 13:21:55 +01:00
|
|
|
body.session_hash = *session_hash;
|
|
|
|
body.noreveal_index = htons (noreveal_index);
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_KS_sign (&body.purpose,
|
2015-01-20 15:17:41 +01:00
|
|
|
&sig);
|
2015-03-27 19:58:40 +01:00
|
|
|
sig_json = TALER_json_from_eddsa_sig (&body.purpose,
|
2015-03-22 22:14:30 +01:00
|
|
|
&sig.eddsa_signature);
|
2015-01-20 15:17:41 +01:00
|
|
|
GNUNET_assert (NULL != sig_json);
|
2015-03-27 19:58:40 +01:00
|
|
|
ret = TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
MHD_HTTP_OK,
|
|
|
|
"{s:i, s:o}",
|
|
|
|
"noreveal_index", (int) noreveal_index,
|
|
|
|
"signature", sig_json);
|
2015-01-28 19:58:20 +01:00
|
|
|
json_decref (sig_json);
|
|
|
|
return ret;
|
2015-01-20 15:17:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-21 13:38:57 +01:00
|
|
|
/**
|
|
|
|
* Send a response for "/refresh/reveal".
|
|
|
|
*
|
|
|
|
* @param connection the connection to send the response to
|
|
|
|
* @param num_newcoins number of new coins for which we reveal data
|
|
|
|
* @param sigs array of @a num_newcoins signatures revealed
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
unsigned int num_newcoins,
|
|
|
|
const struct TALER_DenominationSignature *sigs)
|
2015-01-21 13:38:57 +01:00
|
|
|
{
|
|
|
|
int newcoin_index;
|
|
|
|
json_t *root;
|
|
|
|
json_t *list;
|
2015-01-28 19:58:20 +01:00
|
|
|
int ret;
|
2015-01-21 13:38:57 +01:00
|
|
|
|
|
|
|
root = json_object ();
|
|
|
|
list = json_array ();
|
2015-03-15 16:44:53 +01:00
|
|
|
json_object_set_new (root,
|
|
|
|
"ev_sigs",
|
|
|
|
list);
|
2015-01-21 13:38:57 +01:00
|
|
|
for (newcoin_index = 0; newcoin_index < num_newcoins; newcoin_index++)
|
|
|
|
json_array_append_new (list,
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_from_rsa_signature (sigs[newcoin_index].rsa_signature));
|
|
|
|
ret = TMH_RESPONSE_reply_json (connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
root,
|
|
|
|
MHD_HTTP_OK);
|
2015-01-28 19:58:20 +01:00
|
|
|
json_decref (root);
|
|
|
|
return ret;
|
2015-01-21 13:38:57 +01:00
|
|
|
}
|
2015-01-20 15:17:41 +01:00
|
|
|
|
|
|
|
|
2015-03-13 09:49:47 +01:00
|
|
|
/**
|
|
|
|
* Send a response for a failed "/refresh/reveal", where the
|
|
|
|
* revealed value(s) do not match the original commitment.
|
|
|
|
*
|
|
|
|
* @param connection the connection to send the response to
|
2015-04-11 21:29:15 +02:00
|
|
|
* @param mc all information about the original commitment
|
2015-03-13 09:49:47 +01:00
|
|
|
* @param off offset in the array of kappa-commitments where
|
|
|
|
* the missmatch was detected
|
|
|
|
* @param j index of the coin for which the missmatch was
|
|
|
|
* detected
|
|
|
|
* @param missmatch_object name of the object that was
|
|
|
|
* bogus (i.e. "transfer key").
|
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
|
2015-04-11 21:29:15 +02:00
|
|
|
const struct TALER_MINTDB_MeltCommitment *mc,
|
2015-04-09 20:37:21 +02:00
|
|
|
unsigned int off,
|
|
|
|
unsigned int j,
|
|
|
|
const char *missmatch_object)
|
2015-03-13 09:49:47 +01:00
|
|
|
{
|
2015-04-11 22:17:13 +02:00
|
|
|
json_t *info_old;
|
|
|
|
json_t *info_new;
|
|
|
|
json_t *info_commit;
|
|
|
|
json_t *info_links;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
info_old = json_array ();
|
|
|
|
for (i=0;i<mc->num_oldcoins;i++)
|
|
|
|
{
|
|
|
|
const struct TALER_MINTDB_RefreshMelt *rm;
|
|
|
|
json_t *rm_json;
|
|
|
|
|
|
|
|
rm = &mc->melts[i];
|
|
|
|
rm_json = json_object ();
|
|
|
|
json_object_set_new (rm_json,
|
|
|
|
"coin_sig",
|
|
|
|
TALER_json_from_data (&rm->coin_sig,
|
|
|
|
sizeof (struct TALER_CoinSpendSignatureP)));
|
|
|
|
json_object_set_new (rm_json,
|
|
|
|
"coin_pub",
|
|
|
|
TALER_json_from_data (&rm->coin.coin_pub,
|
2015-05-16 14:15:34 +02:00
|
|
|
sizeof (struct TALER_CoinSpendPublicKeyP)));
|
2015-04-11 22:17:13 +02:00
|
|
|
json_object_set_new (rm_json,
|
|
|
|
"melt_amount_with_fee",
|
|
|
|
TALER_json_from_amount (&rm->amount_with_fee));
|
|
|
|
json_object_set_new (rm_json,
|
|
|
|
"melt_fee",
|
|
|
|
TALER_json_from_amount (&rm->melt_fee));
|
|
|
|
json_array_append_new (info_old,
|
|
|
|
rm_json);
|
|
|
|
}
|
|
|
|
info_new = json_array ();
|
|
|
|
for (i=0;i<mc->num_newcoins;i++)
|
|
|
|
{
|
|
|
|
const struct TALER_DenominationPublicKey *pk;
|
|
|
|
|
|
|
|
pk = &mc->denom_pubs[i];
|
|
|
|
json_array_append_new (info_new,
|
|
|
|
TALER_json_from_rsa_public_key (pk->rsa_public_key));
|
|
|
|
|
|
|
|
}
|
|
|
|
info_commit = json_array ();
|
|
|
|
info_links = json_array ();
|
|
|
|
for (k=0;k<TALER_CNC_KAPPA;k++)
|
|
|
|
{
|
|
|
|
json_t *info_commit_k;
|
|
|
|
json_t *info_link_k;
|
|
|
|
|
|
|
|
info_commit_k = json_array ();
|
|
|
|
for (i=0;i<mc->num_newcoins;i++)
|
|
|
|
{
|
|
|
|
const struct TALER_MINTDB_RefreshCommitCoin *cc;
|
|
|
|
json_t *cc_json;
|
|
|
|
|
|
|
|
cc = &mc->commit_coins[k][i];
|
|
|
|
cc_json = json_object ();
|
|
|
|
json_object_set_new (cc_json,
|
|
|
|
"coin_ev",
|
|
|
|
TALER_json_from_data (cc->coin_ev,
|
|
|
|
cc->coin_ev_size));
|
|
|
|
json_object_set_new (cc_json,
|
|
|
|
"coin_priv_enc",
|
|
|
|
TALER_json_from_data (cc->refresh_link->coin_priv_enc,
|
2015-05-16 14:15:34 +02:00
|
|
|
sizeof (struct TALER_CoinSpendPrivateKeyP)));
|
2015-04-11 22:17:13 +02:00
|
|
|
json_object_set_new (cc_json,
|
|
|
|
"blinding_key_enc",
|
|
|
|
TALER_json_from_data (cc->refresh_link->blinding_key_enc,
|
|
|
|
cc->refresh_link->blinding_key_enc_size));
|
|
|
|
|
|
|
|
json_array_append_new (info_commit_k,
|
|
|
|
cc_json);
|
|
|
|
}
|
|
|
|
json_array_append_new (info_commit,
|
|
|
|
info_commit_k);
|
|
|
|
info_link_k = json_array ();
|
|
|
|
for (i=0;i<mc->num_newcoins;i++)
|
|
|
|
{
|
|
|
|
const struct TALER_MINTDB_RefreshCommitLinkP *cl;
|
|
|
|
json_t *cl_json;
|
|
|
|
|
|
|
|
cl = &mc->commit_links[k][i];
|
|
|
|
cl_json = json_object ();
|
|
|
|
json_object_set_new (cl_json,
|
|
|
|
"transfer_pub",
|
|
|
|
TALER_json_from_data (&cl->transfer_pub,
|
|
|
|
sizeof (struct TALER_TransferPublicKeyP)));
|
|
|
|
json_object_set_new (cl_json,
|
|
|
|
"shared_secret_enc",
|
|
|
|
TALER_json_from_data (&cl->shared_secret_enc,
|
|
|
|
sizeof (struct TALER_EncryptedLinkSecretP)));
|
|
|
|
json_array_append_new (info_link_k,
|
|
|
|
cl_json);
|
|
|
|
}
|
|
|
|
json_array_append_new (info_links,
|
|
|
|
info_link_k);
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
return TMH_RESPONSE_reply_json_pack (connection,
|
2015-04-09 20:37:21 +02:00
|
|
|
MHD_HTTP_CONFLICT,
|
2015-04-11 22:17:13 +02:00
|
|
|
"{s:s, s:i, s:i, s:o, s:o, s:o, s:o, s:s}",
|
2015-04-08 22:28:52 +02:00
|
|
|
"error", "commitment violation",
|
|
|
|
"offset", (int) off,
|
|
|
|
"index", (int) j,
|
2015-04-11 22:17:13 +02:00
|
|
|
"oldcoin_infos", info_old,
|
|
|
|
"newcoin_infos", info_new,
|
|
|
|
"commit_infos", info_commit,
|
|
|
|
"link_infos", info_links,
|
2015-04-08 22:28:52 +02:00
|
|
|
"object", missmatch_object);
|
2015-03-13 09:49:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-31 20:53:19 +01:00
|
|
|
/**
|
|
|
|
* Send a response for "/refresh/link".
|
|
|
|
*
|
|
|
|
* @param connection the connection to send the response to
|
2015-06-15 14:18:37 +02:00
|
|
|
* @param num_sessions number of sessions the coin was used in
|
|
|
|
* @param sessions array of @a num_session entries with
|
|
|
|
* information for each session
|
2015-01-31 20:53:19 +01:00
|
|
|
* @return a MHD result code
|
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TMH_RESPONSE_reply_refresh_link_success (struct MHD_Connection *connection,
|
2015-06-15 14:18:37 +02:00
|
|
|
unsigned int num_sessions,
|
|
|
|
const struct TMH_RESPONSE_LinkSessionInfo *sessions)
|
2015-01-31 20:53:19 +01:00
|
|
|
{
|
|
|
|
json_t *root;
|
2015-06-15 14:18:37 +02:00
|
|
|
json_t *mlist;
|
2015-01-31 20:53:19 +01:00
|
|
|
int res;
|
2015-06-15 14:18:37 +02:00
|
|
|
unsigned int i;
|
2015-01-31 20:53:19 +01:00
|
|
|
|
2015-06-15 14:18:37 +02:00
|
|
|
mlist = json_array ();
|
|
|
|
for (i=0;i<num_sessions;i++)
|
2015-01-31 20:53:19 +01:00
|
|
|
{
|
2015-06-15 14:18:37 +02:00
|
|
|
const struct TALER_MINTDB_LinkDataList *pos;
|
|
|
|
json_t *list = json_array ();
|
2015-01-31 20:53:19 +01:00
|
|
|
|
2015-06-15 14:18:37 +02:00
|
|
|
for (pos = sessions[i].ldl; NULL != pos; pos = pos->next)
|
|
|
|
{
|
|
|
|
json_t *obj;
|
|
|
|
|
|
|
|
obj = json_object ();
|
|
|
|
json_object_set_new (obj,
|
|
|
|
"link_enc",
|
|
|
|
TALER_json_from_data (pos->link_data_enc->coin_priv_enc,
|
|
|
|
sizeof (struct TALER_CoinSpendPrivateKeyP) +
|
|
|
|
pos->link_data_enc->blinding_key_enc_size));
|
|
|
|
json_object_set_new (obj,
|
|
|
|
"denom_pub",
|
|
|
|
TALER_json_from_rsa_public_key (pos->denom_pub.rsa_public_key));
|
|
|
|
json_object_set_new (obj,
|
|
|
|
"ev_sig",
|
|
|
|
TALER_json_from_rsa_signature (pos->ev_sig.rsa_signature));
|
|
|
|
json_array_append_new (list,
|
|
|
|
obj);
|
|
|
|
}
|
|
|
|
root = json_object ();
|
|
|
|
json_object_set_new (root,
|
|
|
|
"new_coins",
|
|
|
|
list);
|
|
|
|
json_object_set_new (root,
|
|
|
|
"transfer_pub",
|
|
|
|
TALER_json_from_data (&sessions[i].transfer_pub,
|
|
|
|
sizeof (struct TALER_TransferPublicKeyP)));
|
|
|
|
json_object_set_new (root,
|
|
|
|
"secret_enc",
|
|
|
|
TALER_json_from_data (&sessions[i].shared_secret_enc,
|
|
|
|
sizeof (struct TALER_EncryptedLinkSecretP)));
|
|
|
|
json_array_append_new (mlist,
|
|
|
|
root);
|
|
|
|
}
|
2015-03-27 19:58:40 +01:00
|
|
|
res = TMH_RESPONSE_reply_json (connection,
|
2015-06-15 14:18:37 +02:00
|
|
|
mlist,
|
|
|
|
MHD_HTTP_OK);
|
|
|
|
json_decref (mlist);
|
2015-01-31 20:53:19 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-01-19 21:53:23 +01:00
|
|
|
|
2015-01-16 13:50:07 +01:00
|
|
|
/* end of taler-mint-httpd_responses.c */
|