misc cleanup, moving TALER_MINT_config_load to libtalerutil

This commit is contained in:
Christian Grothoff 2015-01-28 14:55:25 +01:00
parent ea3fac6063
commit 49d4f24f8d
18 changed files with 400 additions and 179 deletions

View File

@ -29,6 +29,7 @@
#define TALER_SIGNATURES_H #define TALER_SIGNATURES_H
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include "taler_util.h"
/** /**
* Purpose for signing public keys signed * Purpose for signing public keys signed
@ -141,6 +142,45 @@ struct TALER_WithdrawRequest
}; };
/**
* Format used to generate the signature on a request to deposit
* a coin into the account of a merchant.
*/
struct TALER_DepositRequest
{
/**
* Purpose must be #TALER_SIGNATURE_DEPOSIT
*/
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
* Hash over the contract for which this deposit is made.
*/
struct GNUNET_HashCode h_contract;
/**
* Hash over the wiring information of the merchant.
*/
struct GNUNET_HashCode h_wire;
/**
* Merchant-generated transaction ID to detect duplicate
* transactions.
*/
uint64_t transaction_id GNUNET_PACKED;
/**
* Amount to be deposited.
*/
struct TALER_AmountNBO amount;
/**
* The coin's public key.
*/
struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub;
};
/** /**
* FIXME * FIXME

View File

@ -73,14 +73,27 @@ void
TALER_gcrypt_init (void); TALER_gcrypt_init (void);
/**
* Load configuration by parsing all configuration
* files in the given directory.
*
* @param base_dir directory with the configuration files
* @return NULL on error, otherwise configuration
*/
struct GNUNET_CONFIGURATION_Handle *
TALER_config_load (const char *base_dir);
/* *********************** Amount management ****************** */ /* *********************** Amount management ****************** */
/** /**
* Number of characters (plus 1 for 0-termination) we use to * Number of characters (plus 1 for 0-termination) we use to
* represent currency names (i.e. EUR, USD, etc.). * represent currency names (i.e. EUR, USD, etc.). We use
* 8 for alignment (!).
*/ */
#define TALER_CURRENCY_LEN 4 #define TALER_CURRENCY_LEN 8
GNUNET_NETWORK_STRUCT_BEGIN GNUNET_NETWORK_STRUCT_BEGIN
@ -127,7 +140,7 @@ struct TALER_Amount
/** /**
* Currency string, left adjusted and padded with zeros. * Currency string, left adjusted and padded with zeros.
*/ */
char currency[4]; char currency[TALER_CURRENCY_LEN];
}; };

View File

@ -35,6 +35,11 @@
#define DIR_SIGNKEYS "signkeys" #define DIR_SIGNKEYS "signkeys"
#define DIR_DENOMKEYS "denomkeys" #define DIR_DENOMKEYS "denomkeys"
/**
* For now, we just do EUR. Should become configurable
* in the future!
*/
#define MINT_CURRENCY "EUR"
/** /**
* On disk format used for a mint signing key. * On disk format used for a mint signing key.
@ -63,7 +68,9 @@ struct TALER_MINT_DenomKeyIssuePriv
/** /**
* Public information about a coin. * Public information about a coin (including the public key
* of the coin, the denomination key and the signature with
* the denomination key).
*/ */
struct TALER_CoinPublicInfo struct TALER_CoinPublicInfo
{ {
@ -118,6 +125,92 @@ struct CollectableBlindcoin
}; };
/**
* Specification for a /deposit operation.
*/
struct Deposit
{
/**
* Information about the coin that is being deposited.
*/
struct TALER_CoinPublicInfo coin;
/**
* ECDSA signature affirming that the customer intends
* this coin to be deposited at the merchant identified
* by @e h_wire in relation to the contract identified
* by @e h_contract.
*/
struct GNUNET_CRYPTO_EcdsaSignature csig;
/**
* Public key of the merchant. Enables later identification
* of the merchant in case of a need to rollback transactions.
*/
struct GNUNET_CRYPTO_EddsaPublicKey merchant_pub;
/**
* Hash over the contract between merchant and customer
* (remains unknown to the Mint).
*/
struct GNUNET_HashCode h_contract;
/**
* Hash of the (canonical) representation of @e wire, used
* to check the signature on the request. Generated by
* the mint from the detailed wire data provided by the
* merchant.
*/
struct GNUNET_HashCode h_wire;
/**
* Detailed wire information for executing the transaction.
*/
const json_t *wire;
/**
* Merchant-generated transaction ID to detect duplicate
* transactions.
*/
uint64_t transaction_id;
/**
* Fraction of the coin's remaining value to be deposited.
* The coin is identified by @e coin_pub.
*/
struct TALER_Amount amount;
/**
* Type of the deposit (also purpose of the signature). Either
* #TALER_SIGNATURE_DEPOSIT or #TALER_SIGNATURE_INCREMENTAL_DEPOSIT.
*/
uint32_t purpose; // FIXME: bad type, use ENUM!
};
/**
* FIXME
*/
struct KnownCoin
{
struct TALER_CoinPublicInfo public_info;
/**
* Refreshing session, only valid if
* is_refreshed==1.
*/
struct GNUNET_CRYPTO_EddsaPublicKey refresh_session_pub;
struct TALER_Amount expended_balance;
int is_refreshed;
};
/** /**
* Global information for a refreshing session. * Global information for a refreshing session.
*/ */
@ -168,6 +261,9 @@ struct RefreshSession
}; };
/** /**
* For each (old) coin being melted, we have a `struct * For each (old) coin being melted, we have a `struct
* RefreshCommitLink` that allows the user to find the shared secret * RefreshCommitLink` that allows the user to find the shared secret
@ -214,89 +310,8 @@ struct RefreshCommitCoin
}; };
/**
* FIXME
*/
struct KnownCoin
{
struct TALER_CoinPublicInfo public_info;
/**
* Refreshing session, only valid if
* is_refreshed==1.
*/
struct GNUNET_CRYPTO_EddsaPublicKey refresh_session_pub;
struct TALER_Amount expended_balance;
int is_refreshed;
};
/**
* Specification for a /deposit operation.
*/
struct Deposit
{
/**
* Information about the coin that is being deposited.
*/
struct TALER_CoinPublicInfo coin;
/**
* EdDSA signature affirming that the customer intends
* this coin to be deposited at the merchant identified
* by @e h_wire in relation to the contract identified
* by @e h_contract.
*/
struct GNUNET_CRYPTO_EddsaSignature csig;
/**
* Public key of the merchant. Enables later identification
* of the merchant in case of a need to rollback transactions.
*/
struct GNUNET_CRYPTO_EddsaPublicKey merchant_pub;
/**
* Hash over the contract between merchant and customer
* (remains unknown to the Mint).
*/
struct GNUNET_HashCode h_contract;
/**
* Hash of the (canonical) representation of @e wire, used
* to check the signature on the request. Generated by
* the mint from the detailed wire data provided by the
* merchant.
*/
struct GNUNET_HashCode h_wire;
/**
* Detailed wire information for executing the transaction.
*/
const json_t *wire;
/**
* Merchant-generated transaction ID to detect duplicate
* transactions.
*/
uint64_t transaction_id;
/**
* Fraction of the coin's remaining value to be deposited.
* The coin is identified by @e coin_pub.
*/
struct TALER_AmountNBO amount;
/**
* Type of the deposit (also purpose of the signature). Either
* #TALER_SIGNATURE_DEPOSIT or #TALER_SIGNATURE_INCREMENTAL_DEPOSIT.
*/
uint32_t purpose; // FIXME: bad type, use ENUM!
};
/** /**
@ -412,16 +427,6 @@ TALER_MINT_read_denom_key (const char *filename,
struct TALER_MINT_DenomKeyIssuePriv *dki); struct TALER_MINT_DenomKeyIssuePriv *dki);
/**
* Load the configuration for the mint in the given
* directory.
*
* @param mint_base_dir the mint's base directory
* @return the mint configuratin, or NULL on error
*/
struct GNUNET_CONFIGURATION_Handle *
TALER_MINT_config_load (const char *mint_base_dir);
int int
TALER_TALER_DB_extract_amount (PGresult *result, TALER_TALER_DB_extract_amount (PGresult *result,

View File

@ -231,27 +231,11 @@ TALER_MINT_denomkeys_iterate (const char *mint_base_dir,
} }
struct GNUNET_CONFIGURATION_Handle *
TALER_MINT_config_load (const char *mint_base_dir)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
char *cfg_dir;
int res;
res = GNUNET_asprintf (&cfg_dir, "%s" DIR_SEPARATOR_STR "config", mint_base_dir);
GNUNET_assert (res > 0);
cfg = GNUNET_CONFIGURATION_create ();
res = GNUNET_CONFIGURATION_load_from (cfg, cfg_dir);
GNUNET_free (cfg_dir);
if (GNUNET_OK != res)
return NULL;
return cfg;
}
int int
TALER_TALER_DB_extract_amount_nbo (PGresult *result, unsigned int row, TALER_TALER_DB_extract_amount_nbo (PGresult *result,
int indices[3], struct TALER_AmountNBO *denom_nbo) unsigned int row,
int indices[3],
struct TALER_AmountNBO *denom_nbo)
{ {
if ((indices[0] < 0) || (indices[1] < 0) || (indices[2] < 0)) if ((indices[0] < 0) || (indices[1] < 0) || (indices[2] < 0))
return GNUNET_NO; return GNUNET_NO;
@ -270,8 +254,10 @@ TALER_TALER_DB_extract_amount_nbo (PGresult *result, unsigned int row,
int int
TALER_TALER_DB_extract_amount (PGresult *result, unsigned int row, TALER_TALER_DB_extract_amount (PGresult *result,
int indices[3], struct TALER_Amount *denom) unsigned int row,
int indices[3],
struct TALER_Amount *denom)
{ {
struct TALER_AmountNBO denom_nbo; struct TALER_AmountNBO denom_nbo;
int res; int res;

View File

@ -1925,7 +1925,7 @@ TALER_MINT_DB_get_deposit (PGconn *db_conn,
EXITIF (GNUNET_OK != EXITIF (GNUNET_OK !=
TALER_DB_extract_result (result, rs, 0)); TALER_DB_extract_result (result, rs, 0));
EXITIF (GNUNET_OK != EXITIF (GNUNET_OK !=
TALER_DB_extract_amount_nbo (result, 0, TALER_DB_extract_amount (result, 0,
"amount_value", "amount_value",
"amount_fraction", "amount_fraction",
"amount_currency", "amount_currency",

View File

@ -256,7 +256,7 @@ main (int argc, char *const *argv)
return 1; return 1;
} }
cfg = TALER_MINT_config_load (mint_base_dir); cfg = TALER_config_load (mint_base_dir);
if (NULL == cfg) if (NULL == cfg)
{ {
fprintf (stderr, "Can't load mint configuration.\n"); fprintf (stderr, "Can't load mint configuration.\n");
@ -282,4 +282,3 @@ main (int argc, char *const *argv)
return 0; return 0;
} }

View File

@ -233,7 +233,7 @@ mint_serve_process_config (const char *mint_directory)
char *master_pub_str; char *master_pub_str;
char *db_cfg; char *db_cfg;
cfg = TALER_MINT_config_load (mint_directory); cfg = TALER_config_load (mint_directory);
if (NULL == cfg) if (NULL == cfg)
{ {
fprintf (stderr, fprintf (stderr,

View File

@ -117,7 +117,7 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
/* coin valid but not known => insert into DB */ /* coin valid but not known => insert into DB */
known_coin.is_refreshed = GNUNET_NO; known_coin.is_refreshed = GNUNET_NO;
known_coin.expended_balance = TALER_amount_ntoh (deposit->amount); known_coin.expended_balance = deposit->amount;
known_coin.public_info = coin_info; known_coin.public_info = coin_info;
if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin)) if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin))
@ -419,8 +419,7 @@ mint_amount_native_zero ()
struct TALER_Amount amount; struct TALER_Amount amount;
memset (&amount, 0, sizeof (amount)); memset (&amount, 0, sizeof (amount));
// FIXME: load from config memcpy (amount.currency, MINT_CURRENCY, strlen (MINT_CURRENCY) + 1);
memcpy (amount.currency, "EUR", 3);
return amount; return amount;
} }

View File

@ -23,9 +23,8 @@
* @author Christian Grothoff * @author Christian Grothoff
* *
* TODO: * TODO:
* - actually verify coin signature * - missing 'wire' format check (well-formed SEPA-details)
* - revisit `struct Deposit` parsing once the struct * - ugliy if-construction for deposit type
* has been finalized
*/ */
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
@ -59,19 +58,25 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
const struct Deposit *deposit) const struct Deposit *deposit)
{ {
struct MintKeyState *key_state; struct MintKeyState *key_state;
struct TALER_DepositRequest dr;
/* FIXME: verify coin signature! */ dr.purpose.purpose = htonl (TALER_SIGNATURE_DEPOSIT);
/* dr.purpose.size = htonl (sizeof (struct TALER_DepositRequest));
if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_DEPOSIT, dr.h_contract = deposit->h_contract;
&deposit->purpose, dr.h_wire = deposit->h_wire;
&deposit->coin_sig, dr.transaction_id = GNUNET_htonll (deposit->transaction_id);
&deposit->coin_pub)) dr.amount = TALER_amount_hton (deposit->amount);
dr.coin_pub = deposit->coin.coin_pub;
if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_verify (TALER_SIGNATURE_DEPOSIT,
&dr.purpose,
&deposit->csig,
&deposit->coin.coin_pub))
{ {
resp = json_pack ("{s:s}", "error", "Signature verfication failed"); LOG_WARNING ("Invalid signature on /deposit request\n");
return TALER_MINT_reply_arg_invalid (connection, return TALER_MINT_reply_arg_invalid (connection,
"csig"); "csig");
} }
*/
key_state = TALER_MINT_key_state_acquire (); key_state = TALER_MINT_key_state_acquire ();
if (GNUNET_YES != if (GNUNET_YES !=
@ -80,10 +85,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
{ {
LOG_WARNING ("Invalid coin passed for /deposit\n"); LOG_WARNING ("Invalid coin passed for /deposit\n");
TALER_MINT_key_state_release (key_state); TALER_MINT_key_state_release (key_state);
return TALER_MINT_reply_json_pack (connection, return TALER_MINT_reply_coin_invalid (connection);
MHD_HTTP_NOT_FOUND,
"{s:s}",
"error", "Coin is not valid");
} }
TALER_MINT_key_state_release (key_state); TALER_MINT_key_state_release (key_state);
@ -101,6 +103,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
* @param root root of the posted JSON * @param root root of the posted JSON
* @param purpose is this a #TALER_SIGNATURE_DEPOSIT or * @param purpose is this a #TALER_SIGNATURE_DEPOSIT or
* #TALER_SIGNATURE_INCREMENTAL_DEPOSIT // FIXME: bad type, use enum! * #TALER_SIGNATURE_INCREMENTAL_DEPOSIT // FIXME: bad type, use enum!
* @param amount how much should be deposited
* @param wire json describing the wire details (?) * @param wire json describing the wire details (?)
* @return MHD result code * @return MHD result code
*/ */
@ -108,6 +111,7 @@ static int
parse_and_handle_deposit_request (struct MHD_Connection *connection, parse_and_handle_deposit_request (struct MHD_Connection *connection,
const json_t *root, const json_t *root,
uint32_t purpose, uint32_t purpose,
const struct TALER_Amount *amount,
const json_t *wire) const json_t *wire)
{ {
int res; int res;
@ -155,6 +159,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
return TALER_MINT_reply_arg_invalid (connection, return TALER_MINT_reply_arg_invalid (connection,
"denom_pub"); "denom_pub");
} }
/* FIXME: check that "wire" is formatted correctly */
if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS))) if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS)))
{ {
GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub); GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub);
@ -172,9 +177,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
deposit.wire = wire; deposit.wire = wire;
deposit.purpose = purpose; deposit.purpose = purpose;
deposit.amount = *amount;
// FIXME: deposit.amount not initialized!
res = verify_and_execute_deposit (connection, res = verify_and_execute_deposit (connection,
&deposit); &deposit);
GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub); GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub);
@ -212,6 +215,8 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
const char *deposit_type; const char *deposit_type;
int res; int res;
uint32_t purpose; uint32_t purpose;
struct TALER_Amount amount;
json_t *f;
res = TALER_MINT_parse_post_json (connection, res = TALER_MINT_parse_post_json (connection,
connection_cls, connection_cls,
@ -223,16 +228,35 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
if ( (GNUNET_NO == res) || (NULL == json) ) if ( (GNUNET_NO == res) || (NULL == json) )
return MHD_YES; return MHD_YES;
if (-1 == json_unpack (json, if (-1 == json_unpack (json,
"{s:s, s:o}", "{s:s, s:o, f:o}",
"type", &deposit_type, "type", &deposit_type,
"wire", &wire)) "wire", &wire,
"f", &f))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
json_decref (json);
return TALER_MINT_reply_json_pack (connection, return TALER_MINT_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s}", "{s:s}",
"error", "Bad format"); "error", "Bad format");
} }
res = TALER_MINT_parse_amount_json (connection,
f,
&amount);
json_decref (f);
if (GNUNET_SYSERR == res)
{
json_decref (wire);
json_decref (json);
return MHD_NO;
}
if (GNUNET_NO == res)
{
json_decref (wire);
json_decref (json);
return MHD_YES;
}
/* FIXME: use array search and enum, this is ugly */
if (0 == strcmp ("DIRECT_DEPOSIT", deposit_type)) if (0 == strcmp ("DIRECT_DEPOSIT", deposit_type))
purpose = TALER_SIGNATURE_DEPOSIT; purpose = TALER_SIGNATURE_DEPOSIT;
else if (0 == strcmp ("INCREMENTAL_DEPOSIT", deposit_type)) else if (0 == strcmp ("INCREMENTAL_DEPOSIT", deposit_type))
@ -241,6 +265,7 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
json_decref (wire); json_decref (wire);
json_decref (json);
return TALER_MINT_reply_json_pack (connection, return TALER_MINT_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s}", "{s:s}",
@ -249,8 +274,10 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh,
res = parse_and_handle_deposit_request (connection, res = parse_and_handle_deposit_request (connection,
json, json,
purpose, purpose,
&amount,
wire); wire);
json_decref (wire); json_decref (wire);
json_decref (json);
return res; return res;
} }

View File

@ -110,8 +110,8 @@ buffer_deinit (struct Buffer *buf)
* @param data the data to append * @param data the data to append
* @param size the size of @a data * @param size the size of @a data
* @param max_size maximum size that the buffer can grow to * @param max_size maximum size that the buffer can grow to
* @return GNUNET_OK on success, * @return #GNUNET_OK on success,
* GNUNET_NO if the buffer can't accomodate for the new data * #GNUNET_NO if the buffer can't accomodate for the new data
*/ */
static int static int
buffer_append (struct Buffer *buf, buffer_append (struct Buffer *buf,
@ -153,14 +153,14 @@ buffer_append (struct Buffer *buf,
* @param upload_data the POST data * @param upload_data the POST data
* @param upload_data_size number of bytes in @a upload_data * @param upload_data_size number of bytes in @a upload_data
* @param json the JSON object for a completed request * @param json the JSON object for a completed request
* @returns * @return
* GNUNET_YES if json object was parsed or at least * #GNUNET_YES if json object was parsed or at least
* may be parsed in the future (call again); * may be parsed in the future (call again);
* `*json` will be NULL if we need to be called again, * `*json` will be NULL if we need to be called again,
* and non-NULL if we are done. * and non-NULL if we are done.
* GNUNET_NO is request incomplete or invalid * #GNUNET_NO is request incomplete or invalid
* (error message was generated) * (error message was generated)
* GNUNET_SYSERR on internal error * #GNUNET_SYSERR on internal error
* (we could not even queue an error message, * (we could not even queue an error message,
* close HTTP session with MHD_NO) * close HTTP session with MHD_NO)
*/ */
@ -605,6 +605,78 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec)
} }
/**
* Parse amount specified in JSON format.
*
* @param connection the MHD connection (to report errors)
* @param f json specification of the amount
* @param amount[OUT] set to the amount specified in @a f
* @return
* #GNUNET_YES if parsing was successful
* #GNUNET_NO if json is malformed, error response was generated
* #GNUNET_SYSERR on internal error, error response was not generated
*/
int
TALER_MINT_parse_amount_json (struct MHD_Connection *connection,
json_t *f,
struct TALER_Amount *amount)
{
json_int_t value;
json_int_t fraction;
const char *currency;
struct TALER_Amount a;
if (-1 == json_unpack (f,
"{s:I, s:I, s:s}",
"value", &value,
"fraction", &fraction,
"currency", &currency))
{
LOG_WARNING ("Failed to parse JSON amount specification\n");
if (MHD_YES !=
TALER_MINT_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST,
"{s:s}",
"error", "Bad format"))
return GNUNET_SYSERR;
return GNUNET_NO;
}
if ( (value < 0) ||
(fraction < 0) ||
(value > UINT32_MAX) ||
(fraction > UINT32_MAX) )
{
LOG_WARNING ("Amount specified not in allowed range\n");
if (MHD_YES !=
TALER_MINT_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST,
"{s:s}",
"error", "Amount outside of allowed range"))
return GNUNET_SYSERR;
return GNUNET_NO;
}
if (0 != strcmp (currency,
MINT_CURRENCY))
{
LOG_WARNING ("Currency specified not supported by this mint\n");
if (MHD_YES !=
TALER_MINT_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST,
"{s:s, s:s}",
"error", "Currency not supported",
"currency", currency))
return GNUNET_SYSERR;
return GNUNET_NO;
}
a.value = (uint32_t) value;
a.fraction = (uint32_t) fraction;
GNUNET_assert (strlen (MINT_CURRENCY) < TALER_CURRENCY_LEN);
strcpy (a.currency, MINT_CURRENCY);
*amount = TALER_amount_normalize (a);
return GNUNET_OK;
}
/** /**
* Extract base32crockford encoded data from request. * Extract base32crockford encoded data from request.
* *

View File

@ -25,6 +25,7 @@
#include <microhttpd.h> #include <microhttpd.h>
#include <jansson.h> #include <jansson.h>
#include "taler_util.h"
/** /**
@ -215,6 +216,23 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec);
#define TALER_MINT_PARSE_END { NULL, NULL, 0, 0 } #define TALER_MINT_PARSE_END { NULL, NULL, 0, 0 }
/**
* Parse amount specified in JSON format.
*
* @param connection the MHD connection (to report errors)
* @param f json specification of the amount
* @param amount[OUT] set to the amount specified in @a f
* @return
* #GNUNET_YES if parsing was successful
* #GNUNET_NO if json is malformed, error response was generated
* #GNUNET_SYSERR on internal error, error response was not generated
*/
int
TALER_MINT_parse_amount_json (struct MHD_Connection *connection,
json_t *f,
struct TALER_Amount *amount);
/** /**
* Extraxt fixed-size base32crockford encoded data from request. * Extraxt fixed-size base32crockford encoded data from request.
* *

View File

@ -124,6 +124,26 @@ TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection,
} }
/**
* Send a response indicating an invalid coin. (I.e. the signature
* over the public key of the coin does not match a valid signing key
* of this mint).
*
* @param connection the MHD connection to use
* @return MHD result code
*/
int
TALER_MINT_reply_coin_invalid (struct MHD_Connection *connection)
{
/* TODO: may want to be more precise in the future and
distinguish bogus signatures from bogus public keys. */
return TALER_MINT_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND,
"{s:s}",
"error", "Coin is not valid");
}
/** /**
* Send a response indicating a missing argument. * Send a response indicating a missing argument.
* *

View File

@ -77,6 +77,18 @@ TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection,
const char *param_name); const char *param_name);
/**
* Send a response indicating an invalid coin. (I.e. the signature
* over the public key of the coin does not match a valid signing key
* of this mint).
*
* @param connection the MHD connection to use
* @return MHD result code
*/
int
TALER_MINT_reply_coin_invalid (struct MHD_Connection *connection);
/** /**
* Send a response indicating a missing argument. * Send a response indicating a missing argument.
* *

View File

@ -162,7 +162,7 @@ main (int argc, char *const *argv)
return 1; return 1;
} }
kcfg = TALER_MINT_config_load (mintdir); kcfg = TALER_config_load (mintdir);
if (NULL == kcfg) if (NULL == kcfg)
{ {
fprintf (stderr, "can't load mint configuration\n"); fprintf (stderr, "can't load mint configuration\n");
@ -172,4 +172,3 @@ main (int argc, char *const *argv)
return 1; return 1;
return 0; return 0;
} }

View File

@ -621,7 +621,7 @@ main (int argc, char *const *argv)
} }
ROUND_TO_SECS (now, abs_value_us); ROUND_TO_SECS (now, abs_value_us);
kcfg = TALER_MINT_config_load (mintdir); kcfg = TALER_config_load (mintdir);
if (NULL == kcfg) if (NULL == kcfg)
{ {
fprintf (stderr, "can't load mint configuration\n"); fprintf (stderr, "can't load mint configuration\n");

View File

@ -178,7 +178,7 @@ main (int argc, char *const *argv)
return 1; return 1;
} }
kcfg = TALER_MINT_config_load (mintdir); kcfg = TALER_config_load (mintdir);
if (NULL == kcfg) if (NULL == kcfg)
{ {
fprintf (stderr, "can't load mint configuration\n"); fprintf (stderr, "can't load mint configuration\n");
@ -212,4 +212,3 @@ main (int argc, char *const *argv)
} }
return 0; return 0;
} }

View File

@ -104,9 +104,12 @@ run (void *cls, char *const *args, const char *cfgfile,
htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX));
deposit->amount.fraction = deposit->amount.fraction =
htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX));
strcpy (deposit->amount.currency, "EUR"); GNUNET_assert (strlen (MINT_CURRENCY) < sizeof (deposit->amount.currency));
strcpy (deposit->amount.currency, MINT_CURRENCY);
/* Copy wireformat */ /* Copy wireformat */
(void) memcpy (deposit->wire, wire, sizeof (wire)); memcpy (deposit->wire,
wire,
sizeof (wire));
EXITIF (GNUNET_OK != TALER_MINT_DB_insert_deposit (conn, EXITIF (GNUNET_OK != TALER_MINT_DB_insert_deposit (conn,
deposit)); deposit));
EXITIF (GNUNET_OK != TALER_MINT_DB_get_deposit (conn, EXITIF (GNUNET_OK != TALER_MINT_DB_get_deposit (conn,

View File

@ -16,7 +16,7 @@
/** /**
* @file util.c * @file util.c
* @brief Common utility functions * @brief Common utility functions; we might choose to move those to GNUnet at some point
* @author Sree Harsha Totakura <sreeharsha@totakura.in> * @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Florian Dold * @author Florian Dold
* @author Benedikt Mueller * @author Benedikt Mueller
@ -60,4 +60,33 @@ TALER_data_to_string_alloc (const void *buf, size_t size)
} }
/**
* Load configuration by parsing all configuration
* files in the given directory.
*
* @param base_dir directory with the configuration files
* @return NULL on error, otherwise configuration
*/
struct GNUNET_CONFIGURATION_Handle *
TALER_config_load (const char *base_dir)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
char *cfg_dir;
int res;
res = GNUNET_asprintf (&cfg_dir,
"%s" DIR_SEPARATOR_STR "config",
base_dir);
GNUNET_assert (res > 0);
cfg = GNUNET_CONFIGURATION_create ();
res = GNUNET_CONFIGURATION_load_from (cfg, cfg_dir);
GNUNET_free (cfg_dir);
if (GNUNET_OK != res)
return NULL;
return cfg;
}
/* end of util.c */ /* end of util.c */