From a6f8fa98b0253091cae0f2e38fb5fcec47e115fa Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 20 Sep 2015 13:48:15 +0200 Subject: implement #3972: support multiple wire formats concurrently --- src/mint/taler-mint-httpd.c | 28 ++++++++++++++++++++++++++-- src/mint/taler-mint-httpd.h | 6 ++++-- src/mint/taler-mint-httpd_admin.c | 2 +- src/mint/taler-mint-httpd_deposit.c | 2 +- src/mint/taler-mint-httpd_wire.c | 37 +++++++++++++++++++++++++++---------- 5 files changed, 59 insertions(+), 16 deletions(-) (limited to 'src/mint') diff --git a/src/mint/taler-mint-httpd.c b/src/mint/taler-mint-httpd.c index cd2f62768..86d20fdba 100644 --- a/src/mint/taler-mint-httpd.c +++ b/src/mint/taler-mint-httpd.c @@ -62,8 +62,10 @@ struct GNUNET_CRYPTO_EddsaPublicKey TMH_master_public_key; /** * In which format does this MINT expect wiring instructions? + * NULL-terminated array of 0-terminated wire format types, + * suitable for passing to #TALER_json_validate_wireformat(). */ -char *TMH_expected_wire_format; +const char **TMH_expected_wire_formats; /** * Our DB plugin. @@ -363,6 +365,9 @@ mint_serve_process_config (const char *mint_directory) { unsigned long long port; char *TMH_master_public_key_str; + char *wireformats; + const char *token; + unsigned int len; cfg = TALER_config_load (mint_directory); if (NULL == cfg) @@ -390,17 +395,36 @@ mint_serve_process_config (const char *mint_directory) (unsigned int) TALER_CURRENCY_LEN); return GNUNET_SYSERR; } + /* Find out list of supported wire formats */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "mint", "wireformat", - &TMH_expected_wire_format)) + &wireformats)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "mint", "wireformat"); return GNUNET_SYSERR; } + /* build NULL-terminated array of TMH_expected_wire_formats */ + TMH_expected_wire_formats = GNUNET_new_array (1, + const char *); + len = 1; + for (token = strtok (wireformats, + " "); + NULL != token; + token = strtok (NULL, + " ")) + { + /* Grow by 1, appending NULL-terminator */ + GNUNET_array_append (TMH_expected_wire_formats, + len, + NULL); + TMH_expected_wire_formats[len - 2] = GNUNET_strdup (token); + } + GNUNET_free (wireformats); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "mint", diff --git a/src/mint/taler-mint-httpd.h b/src/mint/taler-mint-httpd.h index a54e5aa2e..3cbbc0dfd 100644 --- a/src/mint/taler-mint-httpd.h +++ b/src/mint/taler-mint-httpd.h @@ -48,9 +48,11 @@ extern int TMH_test_mode; extern char *TMH_mint_directory; /** - * In which format does this MINT expect wiring instructions? + * In which formats does this MINT expect wiring instructions? + * NULL-terminated array of 0-terminated wire format types, + * suitable for passing to #TALER_json_validate_wireformat(). */ -extern char *TMH_expected_wire_format; +extern const char **TMH_expected_wire_formats; /** * Master public key (according to the diff --git a/src/mint/taler-mint-httpd_admin.c b/src/mint/taler-mint-httpd_admin.c index 5fdfa58ee..3e3f13ad3 100644 --- a/src/mint/taler-mint-httpd_admin.c +++ b/src/mint/taler-mint-httpd_admin.c @@ -142,7 +142,7 @@ TMH_ADMIN_handler_admin_add_incoming (struct TMH_RequestHandler *rh, return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; } if (GNUNET_YES != - TALER_json_validate_wireformat (TMH_expected_wire_format, + TALER_json_validate_wireformat (TMH_expected_wire_formats, wire)) { TMH_PARSE_release_data (spec); diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index 5725cd1c6..c6ebe1d0d 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c @@ -160,7 +160,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, return MHD_YES; /* failure */ if (GNUNET_YES != - TALER_json_validate_wireformat (TMH_expected_wire_format, + TALER_json_validate_wireformat (TMH_expected_wire_formats, wire)) { TMH_PARSE_release_data (spec); diff --git a/src/mint/taler-mint-httpd_wire.c b/src/mint/taler-mint-httpd_wire.c index 13f23e8e0..68dc1419f 100644 --- a/src/mint/taler-mint-httpd_wire.c +++ b/src/mint/taler-mint-httpd_wire.c @@ -45,23 +45,32 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh, struct TALER_MintPublicKeyP pub; struct TALER_MintSignatureP sig; json_t *methods; + struct GNUNET_HashContext *hc; + unsigned int i; + const char *wf; + methods = json_array (); + hc = GNUNET_CRYPTO_hash_context_start (); + for (i=0;NULL != (wf = TMH_expected_wire_formats[i]); i++) + { + json_array_append_new (methods, + json_string (wf)); + GNUNET_CRYPTO_hash_context_read (hc, + wf, + strlen (wf) + 1); + } wsm.purpose.size = htonl (sizeof (wsm)); wsm.purpose.purpose = htonl (TALER_SIGNATURE_MINT_WIRE_TYPES); - GNUNET_CRYPTO_hash (TMH_expected_wire_format, - strlen (TMH_expected_wire_format) + 1, - &wsm.h_wire_types); + GNUNET_CRYPTO_hash_context_finish (hc, + &wsm.h_wire_types); TMH_KS_sign (&wsm.purpose, &pub, &sig); - methods = json_array (); /* NOTE: for now, we only support *ONE* wire format per mint instance; if we supply multiple, we need to add the strings for each type separately here -- and hash the 0-terminated strings above differently as well... See #3972. */ - json_array_append_new (methods, - json_string (TMH_expected_wire_format)); return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, "{s:o, s:o, s:o}", @@ -93,6 +102,7 @@ TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh, struct MHD_Response *response; int ret; char *wire_test_redirect; + unsigned int i; response = MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT); @@ -101,8 +111,11 @@ TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh, GNUNET_break (0); return MHD_NO; } - if (0 != strcasecmp ("test", - TMH_expected_wire_format)) + for (i=0;NULL != TMH_expected_wire_formats[i];i++) + if (0 == strcasecmp ("test", + TMH_expected_wire_formats[i])) + break; + if (NULL == TMH_expected_wire_formats[i]) { /* Return 501: not implemented */ ret = MHD_queue_response (connection, @@ -155,9 +168,13 @@ TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh, char *sepa_wire_file; int fd; struct stat sbuf; + unsigned int i; - if (0 != strcasecmp ("sepa", - TMH_expected_wire_format)) + for (i=0;NULL != TMH_expected_wire_formats[i];i++) + if (0 == strcasecmp ("sepa", + TMH_expected_wire_formats[i])) + break; + if (NULL == TMH_expected_wire_formats[i]) { /* Return 501: not implemented */ response = MHD_create_response_from_buffer (0, NULL, -- cgit v1.2.3