donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 64d2365db8d0183e21a02a56ec46e01753136b44
parent dac2dee0d9e6edaad5f50b436d82c04846c17b56
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Wed, 28 Feb 2024 10:14:27 +0100

Merge remote-tracking branch 'refs/remotes/origin/master'

Diffstat:
Msrc/donau/Makefile.am | 1-
Msrc/donau/donau-httpd.c | 17+++++++++++++++++
Msrc/donau/donau-httpd.h | 18++++++++++++++++++
Msrc/donau/donau-httpd_keys.c | 248+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/testing/test_donau_api.conf | 1+
5 files changed, 165 insertions(+), 120 deletions(-)

diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am @@ -23,7 +23,6 @@ donau_httpd_LDADD = \ $(LIBGCRYPT_LIBS) \ $(top_builddir)/src/donaudb/libdonaudb.la \ $(top_builddir)/src/util/libdonauutil.la \ - $(top_builddir)/src/pq/libdonaupq.la \ -lmicrohttpd \ -ltalermhd \ -ltalerutil \ diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c @@ -100,6 +100,11 @@ unsigned int DH_currency_fraction_digits; char *DH_currency; /** + * Our domain. + */ +char *DH_domain; + +/** * Our base URL. */ char *DH_base_url; @@ -467,6 +472,7 @@ handle_mhd_request (void *cls, .url = "keys", .method = MHD_HTTP_METHOD_GET, .handler.get = &DH_handler_keys + // .handler.get = &DH_keys_get_handler }, /* GET charities */ { @@ -774,6 +780,17 @@ donau_serve_process_config (void) if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (DH_cfg, "donau", + "DOMAIN", + &DH_domain)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "donau", + "DOMAIN"); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (DH_cfg, + "donau", "BASE_URL", &DH_base_url)) { diff --git a/src/donau/donau-httpd.h b/src/donau/donau-httpd.h @@ -68,6 +68,11 @@ extern unsigned int DH_currency_fraction_digits; extern char *DH_currency; /** + * Our domain. + */ +extern char *DH_domain; + +/** * Our (externally visible) base URL. */ extern char *DH_base_url; @@ -235,4 +240,17 @@ struct DH_RequestHandler bool nargs_is_upper_bound; }; +/** + * Function to call to handle requests to "/keys" by sending + * back our current key material. + * + * @param rc request context + * @param args array of additional options (must be empty for this function) + * @return MHD result code + */ +// MHD_RESULT +// DH_keys_get_handler (struct DH_RequestContext *rc, +// const char *const args[]); + + #endif diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c @@ -19,6 +19,7 @@ * @author Christian Grothoff * @author Özgür Kesim * @author Pius Loosli + * @author Johannes Casaburi */ #include <taler/platform.h> #include <taler/taler_json_lib.h> @@ -588,7 +589,7 @@ finish_keys_response (struct DH_KeyStateHandle *ksh) struct GNUNET_TIME_Timestamp last_cherry_pick_date; struct GNUNET_CONTAINER_Heap *heap; struct GNUNET_HashContext *hash_context = NULL; - // struct GNUNET_HashCode grouped_hash_xor = {0}; + struct GNUNET_HashCode grouped_hash_xor = {0}; sctx.signkeys = json_array (); GNUNET_assert (NULL != sctx.signkeys); @@ -626,18 +627,18 @@ finish_keys_response (struct DH_KeyStateHandle *ksh) GNUNET_CRYPTO_hash_context_finish (hash_context, &hc); // if (GNUNET_OK != - // create_krd (ksh, - // &hc, - // last_cherry_pick_date, - // sctx.signkeys, - // recoup, - // grouped_donation_units, - // &grouped_hash_xor)) + // create_krd (ksh, + // &hc, + // last_cherry_pick_date, + // sctx.signkeys, + // recoup, + // grouped_donation_units, + // &grouped_hash_xor)) // { - // GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - // "Failed to generate key response data for %s\n", - // GNUNET_TIME_timestamp2s (last_cherry_pick_date)); - // goto CLEANUP; + // GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + // "Failed to generate key response data for %s\n", + // GNUNET_TIME_timestamp2s (last_cherry_pick_date)); + // goto CLEANUP; // } ksh->management_only = false; } @@ -1521,11 +1522,20 @@ DH_handler_keys (struct DH_RequestContext *rc, } GNUNET_assert (NULL != kbc.donation_units); GNUNET_assert (NULL != kbc.signkeys); + GNUNET_assert (NULL != DH_currency); GNUNET_CONTAINER_multihashmap_iterate (ksh->helpers->donation_unit_keys, &add_donation_unitkey_cb, &kbc); GNUNET_CONTAINER_multipeermap_iterate (ksh->helpers->esign_keys, &add_signkey_cb, &kbc); reply = GNUNET_JSON_PACK ( + // GNUNET_JSON_pack_string ("version", + // DONAU_PROTOCOL_VERSION), + GNUNET_JSON_pack_string ("domain", + DH_domain), + GNUNET_JSON_pack_string ("base_url", + DH_base_url), + GNUNET_JSON_pack_string ("currency", + DH_currency), GNUNET_JSON_pack_array_steal ("donation_units", kbc.donation_units), GNUNET_JSON_pack_array_steal ("signkeys", kbc.signkeys), @@ -1613,113 +1623,113 @@ DH_RESPONSE_reply_not_modified (struct MHD_Connection *connection, } -MHD_RESULT -DH_keys_get_handler (struct DH_RequestContext *rc, - const char *const args[]) -{ - struct GNUNET_TIME_Timestamp last_issue_date; - const char *etag; - - etag = MHD_lookup_connection_value (rc->connection, - MHD_HEADER_KIND, - MHD_HTTP_HEADER_IF_NONE_MATCH); - (void) args; - { - const char *have_cherrypick; - - have_cherrypick = MHD_lookup_connection_value (rc->connection, - MHD_GET_ARGUMENT_KIND, - "last_issue_date"); - if (NULL != have_cherrypick) - { - unsigned long long cherrypickn; - - if (1 != - sscanf (have_cherrypick, - "%llu", - &cherrypickn)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - have_cherrypick); - } - /* The following multiplication may overflow; but this should not really - be a problem, as giving back 'older' data than what the client asks for - (given that the client asks for data in the distant future) is not - problematic */ - last_issue_date = GNUNET_TIME_timestamp_from_s (cherrypickn); - } - else - { - last_issue_date = GNUNET_TIME_UNIT_ZERO_TS; - } - } - - { - struct DH_KeyStateHandle *ksh; - const struct KeysResponseData *krd; - - ksh = DH_keys_get_state (); - if ( (NULL == ksh) || - (0 == ksh->krd_array_length) ) - { - if ( ( (SKR_LIMIT == skr_size) && - (rc->connection == skr_connection) ) || - DH_suicide) - { - return TALER_MHD_reply_with_error ( - rc->connection, - MHD_HTTP_SERVICE_UNAVAILABLE, - TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, - DH_suicide - ? "server terminating" - : "too many connections suspended waiting on /keys"); - } - return suspend_request (rc->connection); - } - krd = bsearch (&last_issue_date, - ksh->krd_array, - ksh->krd_array_length, - sizeof (struct KeysResponseData), - &krd_search_comparator); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Filtering /keys by cherry pick date %s found entry %u/%u\n", - GNUNET_TIME_timestamp2s (last_issue_date), - (unsigned int) (krd - ksh->krd_array), - ksh->krd_array_length); - if ( (NULL == krd) && - (ksh->krd_array_length > 0) ) - { - if (! GNUNET_TIME_absolute_is_zero (last_issue_date.abs_time)) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Client provided invalid cherry picking timestamp %s, returning full response\n", - GNUNET_TIME_timestamp2s (last_issue_date)); - krd = &ksh->krd_array[ksh->krd_array_length - 1]; - } - if (NULL == krd) - { - /* Likely keys not ready *yet*. - Wait until they are. */ - return suspend_request (rc->connection); - } - if ( (NULL != etag) && - (0 == strcmp (etag, - krd->etag)) ) - return DH_RESPONSE_reply_not_modified (rc->connection, - krd->etag, - &setup_general_response_headers, - ksh); - - return MHD_queue_response (rc->connection, - MHD_HTTP_OK, - (MHD_YES == - TALER_MHD_can_compress (rc->connection)) - ? krd->response_compressed - : krd->response_uncompressed); - } -} +// MHD_RESULT +// DH_keys_get_handler (struct DH_RequestContext *rc, +// const char *const args[]) +// { +// struct GNUNET_TIME_Timestamp last_issue_date; +// const char *etag; +// +// etag = MHD_lookup_connection_value (rc->connection, +// MHD_HEADER_KIND, +// MHD_HTTP_HEADER_IF_NONE_MATCH); +// (void) args; +// { +// const char *have_cherrypick; +// +// have_cherrypick = MHD_lookup_connection_value (rc->connection, +// MHD_GET_ARGUMENT_KIND, +// "last_issue_date"); +// if (NULL != have_cherrypick) +// { +// unsigned long long cherrypickn; +// +// if (1 != +// sscanf (have_cherrypick, +// "%llu", +// &cherrypickn)) +// { +// GNUNET_break_op (0); +// return TALER_MHD_reply_with_error (rc->connection, +// MHD_HTTP_BAD_REQUEST, +// TALER_EC_GENERIC_PARAMETER_MALFORMED, +// have_cherrypick); +// } +// /* The following multiplication may overflow; but this should not really +// be a problem, as giving back 'older' data than what the client asks for +// (given that the client asks for data in the distant future) is not +// problematic */ +// last_issue_date = GNUNET_TIME_timestamp_from_s (cherrypickn); +// } +// else +// { +// last_issue_date = GNUNET_TIME_UNIT_ZERO_TS; +// } +// } +// +// { +// struct DH_KeyStateHandle *ksh; +// const struct KeysResponseData *krd; +// +// ksh = DH_keys_get_state (); +// if ( (NULL == ksh) || +// (0 == ksh->krd_array_length) ) +// { +// if ( ( (SKR_LIMIT == skr_size) && +// (rc->connection == skr_connection) ) || +// DH_suicide) +// { +// return TALER_MHD_reply_with_error ( +// rc->connection, +// MHD_HTTP_SERVICE_UNAVAILABLE, +// TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, +// DH_suicide +// ? "server terminating" +// : "too many connections suspended waiting on /keys"); +// } +// return suspend_request (rc->connection); +// } +// krd = bsearch (&last_issue_date, +// ksh->krd_array, +// ksh->krd_array_length, +// sizeof (struct KeysResponseData), +// &krd_search_comparator); +// GNUNET_log (GNUNET_ERROR_TYPE_INFO, +// "Filtering /keys by cherry pick date %s found entry %u/%u\n", +// GNUNET_TIME_timestamp2s (last_issue_date), +// (unsigned int) (krd - ksh->krd_array), +// ksh->krd_array_length); +// if ( (NULL == krd) && +// (ksh->krd_array_length > 0) ) +// { +// if (! GNUNET_TIME_absolute_is_zero (last_issue_date.abs_time)) +// GNUNET_log (GNUNET_ERROR_TYPE_WARNING, +// "Client provided invalid cherry picking timestamp %s, returning full response\n", +// GNUNET_TIME_timestamp2s (last_issue_date)); +// krd = &ksh->krd_array[ksh->krd_array_length - 1]; +// } +// if (NULL == krd) +// { +// /* Likely keys not ready *yet*. +// Wait until they are. */ +// return suspend_request (rc->connection); +// } +// if ( (NULL != etag) && +// (0 == strcmp (etag, +// krd->etag)) ) +// return DH_RESPONSE_reply_not_modified (rc->connection, +// krd->etag, +// &setup_general_response_headers, +// ksh); +// +// return MHD_queue_response (rc->connection, +// MHD_HTTP_OK, +// (MHD_YES == +// TALER_MHD_can_compress (rc->connection)) +// ? krd->response_compressed +// : krd->response_uncompressed); +// } +// } /* end of donau-httpd_keys.c */ diff --git a/src/testing/test_donau_api.conf b/src/testing/test_donau_api.conf @@ -16,6 +16,7 @@ TERMS_ETAG = tos PRIVACY_ETAG = 0 PORT = 8080 DB = postgres +DOMAIN = "Bern" BASE_URL = "http://localhost:8080/" SERVE = tcp EXPIRE_IDLE_SLEEP_INTERVAL ="1 s"