From 7d6b8d53d5a6ee6ca1545fb5d458199c6249edc5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 18 Nov 2016 18:29:18 +0100 Subject: addressing #4803: nicer error messages for invalid wire formats --- src/exchange-lib/exchange_api_wire.c | 13 ++-- src/exchange-lib/test_exchange_api.c | 9 +++ src/exchange/taler-exchange-httpd_admin.c | 18 +++--- src/exchange/taler-exchange-httpd_deposit.c | 19 +++--- src/exchange/taler-exchange-httpd_validation.c | 38 ++++++++---- src/exchange/taler-exchange-httpd_validation.h | 8 ++- src/include/taler_error_codes.h | 49 ++++++++++++++- src/include/taler_wire_plugin.h | 10 +++- src/util/Makefile.am | 1 - src/wire/plugin_wire_sepa.c | 70 +++++++++++++--------- src/wire/plugin_wire_template.c | 14 +++-- src/wire/plugin_wire_test.c | 83 +++++++++++++++++--------- src/wire/test_sepa_wireformat.c | 30 ++++++---- src/wire/test_wire_plugin.c | 13 ++-- 14 files changed, 259 insertions(+), 116 deletions(-) (limited to 'src') diff --git a/src/exchange-lib/exchange_api_wire.c b/src/exchange-lib/exchange_api_wire.c index 7401e66d4..fe60d664c 100644 --- a/src/exchange-lib/exchange_api_wire.c +++ b/src/exchange-lib/exchange_api_wire.c @@ -95,7 +95,8 @@ verify_wire_method_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh, const struct TALER_EXCHANGE_Keys *key_state; struct TALER_WIRE_Plugin *plugin; char *lib_name; - int ret; + char *emsg; + enum TALER_ErrorCode ec; key_state = TALER_EXCHANGE_get_keys (wh->exchange); (void) GNUNET_asprintf (&lib_name, @@ -112,13 +113,15 @@ verify_wire_method_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh, return GNUNET_NO; } plugin->library_name = lib_name; - ret = plugin->wire_validate (plugin->cls, - json, - &key_state->master_pub); + ec = plugin->wire_validate (plugin->cls, + json, + &key_state->master_pub, + &emsg); + GNUNET_free_non_null (emsg); GNUNET_PLUGIN_unload (lib_name, plugin); GNUNET_free (lib_name); - return (GNUNET_YES == ret) ? GNUNET_OK : GNUNET_SYSERR; + return (TALER_EC_NONE == ec) ? GNUNET_OK : GNUNET_SYSERR; } diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index 8c5e17d15..7f6e86a4a 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -1596,6 +1596,7 @@ deposit_wtid_cb (void *cls, } break; default: + GNUNET_break (0); break; } next_command (is); @@ -2427,6 +2428,10 @@ do_shutdown (void *cls) struct Command *cmd; unsigned int i; + fprintf (stderr, + "Executing shutdown at `%s'\n", + is->commands[is->ip].label); + for (i=0;OC_END != (cmd = &is->commands[i])->oc;i++) { switch (cmd->oc) @@ -3084,6 +3089,9 @@ main (int argc, /* These might get in the way... */ unsetenv ("XDG_DATA_HOME"); unsetenv ("XDG_CONFIG_HOME"); + GNUNET_log_setup ("test-exchange-api", + "INFO", + NULL); proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL, NULL, @@ -3145,6 +3153,7 @@ main (int argc, result = GNUNET_SYSERR; sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); GNUNET_assert (NULL != sigpipe); + sleep (30); shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); GNUNET_SCHEDULER_run (&run, NULL); 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); /** diff --git a/src/include/taler_error_codes.h b/src/include/taler_error_codes.h index dd8a14972..6e6614579 100644 --- a/src/include/taler_error_codes.h +++ b/src/include/taler_error_codes.h @@ -48,6 +48,10 @@ enum TALER_ErrorCode */ TALER_EC_INVALID_RESPONSE = 2, + /** + * Generic implementation error: this function was not yet implemented. + */ + TALER_EC_NOT_IMPLEMENTED = 3, /* ********** generic error codes ************* */ @@ -324,10 +328,11 @@ enum TALER_ErrorCode /** * The exchange does not recognize the validity of or support the - * given wire (bank account) address. This response is provided + * given wire format type. + * This response is provided * with HTTP status code MHD_HTTP_BAD_REQUEST. */ - TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT = 1209, + TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_TYPE = 1209, /** * The exchange failed to canonicalize and hash the given wire format. @@ -353,6 +358,46 @@ enum TALER_ErrorCode */ TALER_EC_DEPOSIT_HISTORY_DB_ERROR_INSUFFICIENT_FUNDS = 1212, + /** + * The exchange detected that the given account number + * is invalid for the selected wire format type. + * This response is provided + * with HTTP status code MHD_HTTP_BAD_REQUEST. + */ + TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_ACCOUNT_NUMBER = 1213, + + /** + * The signature over the given wire details is invalid. + * This response is provided + * with HTTP status code MHD_HTTP_BAD_REQUEST. + */ + TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_SIGNATURE = 1214, + + /** + * The bank specified in the wire transfer format is not supported + * by this exchange. + * This response is provided + * with HTTP status code MHD_HTTP_BAD_REQUEST. + */ + TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_BANK = 1215, + + /** + * No wire format type was specified in the JSON wire format + * details. + * This response is provided + * with HTTP status code MHD_HTTP_BAD_REQUEST. + */ + TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_TYPE_MISSING = 1216, + + /** + * The given wire format type is not supported by this + * exchange. + * This response is provided + * with HTTP status code MHD_HTTP_BAD_REQUEST. + */ + TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_TYPE_UNSUPPORTED = 1217, + + /** * The respective coin did not have sufficient residual value * for the /refresh/melt operation. The "history" in this diff --git a/src/include/taler_wire_plugin.h b/src/include/taler_wire_plugin.h index c3c9c3a54..6c06e8247 100644 --- a/src/include/taler_wire_plugin.h +++ b/src/include/taler_wire_plugin.h @@ -24,6 +24,7 @@ #include #include #include "taler_util.h" +#include "taler_error_codes.h" /** @@ -137,12 +138,15 @@ struct TALER_WIRE_Plugin * @param cls the @e cls of this struct with the plugin-specific state * @param wire the JSON wire format object * @param master_pub public key of the exchange to verify against - * @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not + * @param[OUT] emsg set to an error message, unless we return #TALER_EC_NONE; + * error message must be freed by the caller using GNUNET_free() + * @return #TALER_EC_NONE if correctly formatted */ - int + enum TALER_ErrorCode (*wire_validate) (void *cls, const json_t *wire, - const struct TALER_MasterPublicKeyP *master_pub); + const struct TALER_MasterPublicKeyP *master_pub, + char **emsg); /** diff --git a/src/util/Makefile.am b/src/util/Makefile.am index ec6c11a7a..eb9ffe475 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -9,7 +9,6 @@ endif pkgcfgdir = $(prefix)/share/taler/config.d/ - pkgcfg_DATA = \ paths.conf diff --git a/src/wire/plugin_wire_sepa.c b/src/wire/plugin_wire_sepa.c index 61b30259a..cc00bcad7 100644 --- a/src/wire/plugin_wire_sepa.c +++ b/src/wire/plugin_wire_sepa.c @@ -451,12 +451,15 @@ verify_wire_sepa_signature_ok (const json_t *json, * @param cls the @e cls of this struct with the plugin-specific state * @param wire the JSON wire format object * @param master_pub public key of the exchange to verify against - * @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not + * @param[OUT] emsg set to an error message, unless we return #TALER_EC_NONE; + * error message must be freed by the caller using GNUNET_free() + * @return #TALER_EC_NONE if correctly formatted */ -static int +static enum TALER_ErrorCode sepa_wire_validate (void *cls, const json_t *wire, - const struct TALER_MasterPublicKeyP *master_pub) + const struct TALER_MasterPublicKeyP *master_pub, + char **emsg) { json_error_t error; const char *type; @@ -464,6 +467,7 @@ sepa_wire_validate (void *cls, const char *name; const char *bic; + *emsg = NULL; if (0 != json_unpack_ex ((json_t *) wire, &error, 0, @@ -478,39 +482,44 @@ sepa_wire_validate (void *cls, "name", &name, "bic", &bic)) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "JSON parsing failed at %s:%u: %s (%s)\n", - __FILE__, __LINE__, - error.text, error.source); - json_dumpf (wire, stderr, 0); - fprintf (stderr, "\n"); - return GNUNET_SYSERR; + char *dump; + + dump = json_dumps (wire, 0); + GNUNET_asprintf (emsg, + "JSON parsing failed at %s:%u: %s (%s): %s\n", + __FILE__, __LINE__, + error.text, + error.source, + dump); + free (dump); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_JSON; } if (0 != strcasecmp (type, "sepa")) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Transfer type `%s' invalid\n", - type); - return GNUNET_SYSERR; + GNUNET_asprintf (emsg, + "Transfer type `%s' invalid for SEPA wire plugin\n", + type); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_TYPE; } if (1 != validate_iban (iban)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "IBAN `%s' invalid\n", - iban); - return GNUNET_NO; + GNUNET_asprintf (emsg, + "IBAN `%s' invalid\n", + iban); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_ACCOUNT_NUMBER; } /* FIXME: don't parse again, integrate properly... */ if (GNUNET_OK != verify_wire_sepa_signature_ok (wire, master_pub)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Signature invalid\n"); - return GNUNET_NO; + GNUNET_asprintf (emsg, + "Signature using public key `%s' invalid\n", + TALER_B2S (master_pub)); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_SIGNATURE; } - return GNUNET_YES; + return TALER_EC_NONE; } @@ -531,6 +540,7 @@ sepa_get_wire_details (void *cls, char *sepa_wire_file; json_error_t err; json_t *ret; + char *emsg; /* Fetch reply */ if (GNUNET_OK != @@ -558,13 +568,17 @@ sepa_get_wire_details (void *cls, GNUNET_free (sepa_wire_file); return NULL; } - if (GNUNET_YES != sepa_wire_validate (cls, - ret, - NULL)) - { + if (TALER_EC_NONE != + sepa_wire_validate (cls, + ret, + NULL, + &emsg)) + { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to validate SEPA data in %s\n", - sepa_wire_file); + "Failed to validate SEPA data in %s: %s\n", + sepa_wire_file, + emsg); + GNUNET_free (emsg); GNUNET_free (sepa_wire_file); json_decref (ret); return NULL; diff --git a/src/wire/plugin_wire_template.c b/src/wire/plugin_wire_template.c index 2bc2a2abf..416eb9c58 100644 --- a/src/wire/plugin_wire_template.c +++ b/src/wire/plugin_wire_template.c @@ -98,15 +98,19 @@ template_get_wire_details (void *cls, * @param cls the @e cls of this struct with the plugin-specific state * @param wire the JSON wire format object * @param master_pub public key of the exchange to verify against - * @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not + * @param[OUT] emsg set to an error message, unless we return #TALER_EC_NONE; + * error message must be freed by the caller using GNUNET_free() + * @return #TALER_EC_NONE if correctly formatted */ -static int +static enum TALER_ErrorCode template_wire_validate (void *cls, const json_t *wire, - const struct TALER_MasterPublicKeyP *master_pub) + const struct TALER_MasterPublicKeyP *master_pub, + char **emsg) { - GNUNET_break (0); - return GNUNET_SYSERR; + GNUNET_asprintf (emsg, + "Not implemented"); + return TALER_EC_NOT_IMPLEMENTED; } diff --git a/src/wire/plugin_wire_test.c b/src/wire/plugin_wire_test.c index bdcf78058..7b52dee40 100644 --- a/src/wire/plugin_wire_test.c +++ b/src/wire/plugin_wire_test.c @@ -213,12 +213,15 @@ compute_purpose (uint64_t account, * @param cls the @e cls of this struct with the plugin-specific state * @param wire the JSON wire format object * @param master_pub public key of the exchange to verify against - * @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not + * @param[OUT] emsg set to an error message, unless we return #TALER_EC_NONE; + * error message must be freed by the caller using GNUNET_free() + * @return #TALER_EC_NONE if correctly formatted */ -static int +static enum TALER_ErrorCode test_wire_validate (void *cls, const json_t *wire, - const struct TALER_MasterPublicKeyP *master_pub) + const struct TALER_MasterPublicKeyP *master_pub, + char **emsg) { struct TestClosure *tc = cls; json_error_t error; @@ -228,6 +231,7 @@ test_wire_validate (void *cls, struct TALER_MasterWireDetailsPS wsd; struct TALER_MasterSignatureP sig; + *emsg = NULL; if (0 != json_unpack_ex ((json_t *) wire, &error, @@ -236,30 +240,41 @@ test_wire_validate (void *cls, "account_number", &account_no, "bank_uri", &bank_uri)) { - GNUNET_break_op (0); - return GNUNET_SYSERR; + char *dump; + + dump = json_dumps (wire, 0); + GNUNET_asprintf (emsg, + "JSON parsing failed at %s:%u: %s (%s): %s\n", + __FILE__, __LINE__, + error.text, + error.source, + dump); + free (dump); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_JSON; } if ( (account_no < 0) || (account_no > (1LL << 53)) ) { - GNUNET_break (0); - return GNUNET_SYSERR; + GNUNET_asprintf (emsg, + "Account number %llu outside of permitted range\n", + account_no); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_ACCOUNT_NUMBER; } if ( (NULL != tc->bank_uri) && (0 != strcmp (bank_uri, tc->bank_uri)) ) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Wire specifies bank URI %s, but this exchange only supports %s\n", - bank_uri, - tc->bank_uri); - return GNUNET_NO; + GNUNET_asprintf (emsg, + "Wire specifies bank URI `%s', but this exchange only supports `%s'\n", + bank_uri, + tc->bank_uri); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_BANK; } if (NULL == master_pub) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping signature check as master public key not given\n"); - return GNUNET_OK; + return TALER_EC_NONE; } if (0 != json_unpack_ex ((json_t *) wire, @@ -268,9 +283,9 @@ test_wire_validate (void *cls, "{s:s}", "sig", &sig_s)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Signature check required, but signature is missing\n"); - return GNUNET_NO; + GNUNET_asprintf (emsg, + "Signature check required, but signature is missing\n"); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_SIGNATURE; } compute_purpose (account_no, bank_uri, @@ -290,10 +305,12 @@ test_wire_validate (void *cls, &sig.eddsa_signature, &master_pub->eddsa_pub)) { - GNUNET_break (0); - return GNUNET_SYSERR; + GNUNET_asprintf (emsg, + "Signature using public key `%s' invalid\n", + TALER_B2S (master_pub)); + return TALER_EC_DEPOSIT_INVALID_WIRE_FORMAT_SIGNATURE; } - return GNUNET_YES; + return TALER_EC_NONE; } @@ -315,6 +332,7 @@ test_get_wire_details (void *cls, char *test_wire_file; json_error_t err; json_t *ret; + char *emsg; /* Fetch reply */ if (GNUNET_OK != @@ -342,13 +360,17 @@ test_get_wire_details (void *cls, GNUNET_free (test_wire_file); return NULL; } - if (GNUNET_YES != test_wire_validate (tc, - ret, - NULL)) + if (TALER_EC_NONE != + test_wire_validate (tc, + ret, + NULL, + &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to validate TEST wire data in %s\n", - test_wire_file); + "Failed to validate TEST wire data in %s: %s\n", + test_wire_file, + emsg); + GNUNET_free (emsg); GNUNET_free (test_wire_file); json_decref (ret); return NULL; @@ -478,13 +500,16 @@ test_prepare_wire_transfer (void *cls, { struct TestClosure *tc = cls; struct TALER_WIRE_PrepareHandle *pth; + char *emsg; - if (GNUNET_YES != + if (TALER_EC_NONE != test_wire_validate (tc, wire, - NULL)) + NULL, + &emsg)) { GNUNET_break_op (0); + GNUNET_free (emsg); return NULL; } pth = GNUNET_new (struct TALER_WIRE_PrepareHandle); @@ -624,6 +649,7 @@ test_execute_wire_transfer (void *cls, struct TALER_Amount amount; json_int_t account_no; struct BufFormatP bf; + char *emsg; if (NULL == tc->ctx) { @@ -650,10 +676,11 @@ test_execute_wire_transfer (void *cls, GNUNET_break (0); return NULL; } - GNUNET_assert (GNUNET_YES == + GNUNET_assert (TALER_EC_NONE == test_wire_validate (tc, wire, - NULL)); + NULL, + &emsg)); if (0 != json_unpack_ex (wire, &error, diff --git a/src/wire/test_sepa_wireformat.c b/src/wire/test_sepa_wireformat.c index 43bd51a32..07a3784c6 100644 --- a/src/wire/test_sepa_wireformat.c +++ b/src/wire/test_sepa_wireformat.c @@ -67,6 +67,7 @@ main(int argc, const char *const argv[]) { json_t *wire; + char *emsg; json_error_t error; int ret; struct GNUNET_CONFIGURATION_Handle *cfg; @@ -85,28 +86,35 @@ main(int argc, GNUNET_assert (NULL != plugin); (void) memset(&error, 0, sizeof(error)); GNUNET_assert (NULL != (wire = json_loads (unsupported_wire_str, 0, NULL))); - GNUNET_assert (GNUNET_YES != plugin->wire_validate (NULL, - wire, - NULL)); + GNUNET_assert (TALER_EC_NONE != plugin->wire_validate (NULL, + wire, + NULL, + &emsg)); + GNUNET_free (emsg); json_decref (wire); GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str, 0, NULL))); - GNUNET_assert (GNUNET_NO == plugin->wire_validate (NULL, - wire, - NULL)); + GNUNET_assert (TALER_EC_NONE != plugin->wire_validate (NULL, + wire, + NULL, + &emsg)); + GNUNET_free (emsg); json_decref (wire); GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str2, 0, NULL))); - GNUNET_assert (GNUNET_NO == plugin->wire_validate (NULL, - wire, - NULL)); + GNUNET_assert (TALER_EC_NONE != plugin->wire_validate (NULL, + wire, + NULL, + &emsg)); + GNUNET_free (emsg); json_decref (wire); GNUNET_assert (NULL != (wire = json_loads (valid_wire_str, 0, &error))); ret = plugin->wire_validate (NULL, wire, - NULL); + NULL, + &emsg); json_decref (wire); TALER_WIRE_plugin_unload (plugin); GNUNET_CONFIGURATION_destroy (cfg); - if (GNUNET_NO == ret) + if (TALER_EC_NONE != ret) return 1; return 0; } diff --git a/src/wire/test_wire_plugin.c b/src/wire/test_wire_plugin.c index c465302f1..0828a06b7 100644 --- a/src/wire/test_wire_plugin.c +++ b/src/wire/test_wire_plugin.c @@ -112,6 +112,7 @@ run_test (const struct TestBlock *test, json_t *lwire; struct TALER_Amount in; struct TALER_Amount expect; + char *emsg; GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &salt, @@ -134,12 +135,14 @@ run_test (const struct TestBlock *test, "sig", GNUNET_JSON_from_data (&sig, sizeof (sig))); - if (GNUNET_OK != + if (TALER_EC_NONE != plugin->wire_validate (plugin->cls, wire, - &pub_key)) + &pub_key, + &emsg)) { GNUNET_break (0); + GNUNET_free (emsg); return GNUNET_SYSERR; } /* load wire details from file */ @@ -151,12 +154,14 @@ run_test (const struct TestBlock *test, GNUNET_break (0); return GNUNET_SYSERR; } - if (GNUNET_OK != + if (TALER_EC_NONE != plugin->wire_validate (plugin->cls, lwire, - &pub_key)) + &pub_key, + &emsg)) { GNUNET_break (0); + GNUNET_free (emsg); json_decref (lwire); return GNUNET_SYSERR; } -- cgit v1.2.3