diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-11-18 18:29:18 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-11-18 18:29:18 +0100 |
commit | 7d6b8d53d5a6ee6ca1545fb5d458199c6249edc5 (patch) | |
tree | f44f7afb792184ef46e6d4882cb20de0e2d8b519 /src/exchange | |
parent | de68a7b301fd78a89c4f5e6f34791c8debab36e0 (diff) | |
download | exchange-7d6b8d53d5a6ee6ca1545fb5d458199c6249edc5.tar.gz exchange-7d6b8d53d5a6ee6ca1545fb5d458199c6249edc5.tar.bz2 exchange-7d6b8d53d5a6ee6ca1545fb5d458199c6249edc5.zip |
addressing #4803: nicer error messages for invalid wire formats
Diffstat (limited to 'src/exchange')
-rw-r--r-- | src/exchange/taler-exchange-httpd_admin.c | 18 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_deposit.c | 19 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_validation.c | 38 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_validation.h | 8 |
4 files changed, 54 insertions, 29 deletions
diff --git a/src/exchange/taler-exchange-httpd_admin.c b/src/exchange/taler-exchange-httpd_admin.c index 72cdcb7d6..8bb4b4988 100644 --- a/src/exchange/taler-exchange-httpd_admin.c +++ b/src/exchange/taler-exchange-httpd_admin.c @@ -50,6 +50,8 @@ TEH_ADMIN_handler_admin_add_incoming (struct TEH_RequestHandler *rh, struct TALER_ReservePublicKeyP reserve_pub; struct TALER_Amount amount; struct GNUNET_TIME_Absolute at; + enum TALER_ErrorCode ec; + char *emsg; json_t *sender_account_details; json_t *transfer_details; json_t *root; @@ -82,15 +84,17 @@ TEH_ADMIN_handler_admin_add_incoming (struct TEH_RequestHandler *rh, json_decref (root); return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; } - if (GNUNET_YES != - TEH_json_validate_wireformat (sender_account_details, - GNUNET_NO)) + if (TALER_EC_NONE != + (ec = TEH_json_validate_wireformat (sender_account_details, + GNUNET_NO, + &emsg))) { - GNUNET_break_op (0); GNUNET_JSON_parse_free (spec); - return TEH_RESPONSE_reply_arg_unknown (connection, - TALER_EC_ADMIN_ADD_INCOMING_WIREFORMAT_UNSUPPORTED, - "sender_account_details"); + res = TEH_RESPONSE_reply_external_error (connection, + ec, + emsg); + GNUNET_free (emsg); + return res; } if (0 != strcasecmp (amount.currency, TEH_exchange_currency_string)) diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c index b0ab42e7f..d3b4d031f 100644 --- a/src/exchange/taler-exchange-httpd_deposit.c +++ b/src/exchange/taler-exchange-httpd_deposit.c @@ -106,6 +106,8 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh, json_t *json; int res; json_t *wire; + char *emsg; + enum TALER_ErrorCode ec; struct TALER_EXCHANGEDB_Deposit deposit; struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki; struct TEH_KS_StateHandle *key_state; @@ -156,14 +158,17 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh, "refund_deadline"); } - if (GNUNET_YES != - TEH_json_validate_wireformat (wire, - GNUNET_NO)) + if (TALER_EC_NONE != + (ec = TEH_json_validate_wireformat (wire, + GNUNET_NO, + &emsg))) { GNUNET_JSON_parse_free (spec); - return TEH_RESPONSE_reply_arg_unknown (connection, - TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT, - "wire"); + res = TEH_RESPONSE_reply_external_error (connection, + ec, + emsg); + GNUNET_free (emsg); + return res; } if (GNUNET_OK != TALER_JSON_hash (wire, @@ -223,7 +228,7 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh, TALER_EC_DEPOSIT_NEGATIVE_VALUE_AFTER_FEE, "deposited amount smaller than depositing fee"); } - + res = verify_and_execute_deposit (connection, &deposit); GNUNET_JSON_parse_free (spec); diff --git a/src/exchange/taler-exchange-httpd_validation.c b/src/exchange/taler-exchange-httpd_validation.c index 9d7b4ffcb..f5221feb7 100644 --- a/src/exchange/taler-exchange-httpd_validation.c +++ b/src/exchange/taler-exchange-httpd_validation.c @@ -144,23 +144,27 @@ TEH_VALIDATION_done () * * @param wire the JSON wire format object * @param ours #GNUNET_YES if the signature should match our master key - * @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not + * @param[OUT] emsg set to error message if we return an error code + * @return #TALER_EC_NONE if correctly formatted; otherwise error code */ -int +enum TALER_ErrorCode TEH_json_validate_wireformat (const json_t *wire, - int ours) + int ours, + char **emsg) { const char *stype; json_error_t error; struct Plugin *p; + *emsg = NULL; if (0 != json_unpack_ex ((json_t *) wire, &error, 0, "{s:s}", "type", &stype)) { - GNUNET_break (0); - return GNUNET_SYSERR; + GNUNET_asprintf (emsg, + "No `type' specified in the wire details\n"); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_TYPE_MISSING; } for (p=wire_head; NULL != p; p = p->next) if (0 == strcasecmp (p->type, @@ -169,8 +173,12 @@ TEH_json_validate_wireformat (const json_t *wire, wire, (GNUNET_YES == ours) ? &TEH_master_public_key - : NULL); - return GNUNET_NO; + : NULL, + emsg); + GNUNET_asprintf (emsg, + "Wire format type `%s' is not supported by this exchange\n", + stype); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_TYPE_UNSUPPORTED; } @@ -190,6 +198,8 @@ TEH_VALIDATION_get_wire_methods (const char *prefix) struct Plugin *p; struct TALER_WIRE_Plugin *plugin; char *account_name; + char *emsg; + enum TALER_ErrorCode ec; methods = json_object (); for (p=wire_head;NULL != p;p = p->next) @@ -202,13 +212,17 @@ TEH_VALIDATION_get_wire_methods (const char *prefix) method = plugin->get_wire_details (plugin->cls, cfg, account_name); - if (GNUNET_YES != - TEH_json_validate_wireformat (method, - GNUNET_YES)) + if (TALER_EC_NONE != + (ec = TEH_json_validate_wireformat (method, + GNUNET_YES, + &emsg))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Account details for method `%s' ill-formed. Disabling method\n", - p->type); + "Disabling method `%s' as details are ill-formed: %s (%d)\n", + p->type, + emsg, + ec); + GNUNET_free (emsg); json_decref (method); method = NULL; } diff --git a/src/exchange/taler-exchange-httpd_validation.h b/src/exchange/taler-exchange-httpd_validation.h index 7722460b7..7f2393279 100644 --- a/src/exchange/taler-exchange-httpd_validation.h +++ b/src/exchange/taler-exchange-httpd_validation.h @@ -48,11 +48,13 @@ TEH_VALIDATION_done (void); * * @param wire the JSON wire format object * @param ours #GNUNET_YES if the signature should match our master key - * @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not + * @param[OUT] emsg set to error message if we return an error code + * @return #TALER_EC_NONE if correctly formatted; otherwise error code */ -int +enum TALER_ErrorCode TEH_json_validate_wireformat (const json_t *wire, - int ours); + int ours, + char **emsg); /** |