From 3240844e48dc62b80c6167558677bcd7b83dd3c0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 29 Nov 2020 14:32:39 +0100 Subject: get code for most new endpoints to build (but DB not done) --- src/exchange/Makefile.am | 14 +++- src/exchange/taler-exchange-httpd.c | 14 ++++ src/exchange/taler-exchange-httpd.h | 5 ++ src/exchange/taler-exchange-httpd_auditors.c | 67 +++++++++++--------- .../taler-exchange-httpd_management_auditors.c | 24 +++---- ...exchange-httpd_management_auditors_AP_disable.c | 20 +++--- ...nge-httpd_management_denominations_HDP_revoke.c | 4 +- .../taler-exchange-httpd_management_post_keys.c | 67 ++++++++++---------- ...r-exchange-httpd_management_signkey_EP_revoke.c | 6 +- .../taler-exchange-httpd_management_wire.c | 59 +++++++---------- .../taler-exchange-httpd_management_wire_disable.c | 67 ++++++++------------ .../taler-exchange-httpd_management_wire_fees.c | 74 +++++++++++----------- 12 files changed, 220 insertions(+), 201 deletions(-) (limited to 'src/exchange') diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am index 179604042..a2a9840f4 100644 --- a/src/exchange/Makefile.am +++ b/src/exchange/Makefile.am @@ -78,14 +78,22 @@ taler_exchange_transfer_LDADD = \ taler_exchange_httpd_SOURCES = \ taler-exchange-httpd.c taler-exchange-httpd.h \ + taler-exchange-httpd_auditors.c \ taler-exchange-httpd_db.c taler-exchange-httpd_db.h \ taler-exchange-httpd_deposit.c taler-exchange-httpd_deposit.h \ taler-exchange-httpd_deposits_get.c taler-exchange-httpd_deposits_get.h \ taler-exchange-httpd_keystate.c taler-exchange-httpd_keystate.h \ taler-exchange-httpd_link.c taler-exchange-httpd_link.h \ + taler-exchange-httpd_management_auditors.c \ + taler-exchange-httpd_management_auditors_AP_disable.c \ + taler-exchange-httpd_management_denominations_HDP_revoke.c \ + taler-exchange-httpd_management_signkey_EP_revoke.c \ + taler-exchange-httpd_management_wire.c \ + taler-exchange-httpd_management_wire_disable.c \ + taler-exchange-httpd_management_wire_fees.c \ + taler-exchange-httpd_melt.c taler-exchange-httpd_melt.h \ taler-exchange-httpd_mhd.c taler-exchange-httpd_mhd.h \ taler-exchange-httpd_recoup.c taler-exchange-httpd_recoup.h \ - taler-exchange-httpd_melt.c taler-exchange-httpd_melt.h \ taler-exchange-httpd_refreshes_reveal.c taler-exchange-httpd_refreshes_reveal.h \ taler-exchange-httpd_refund.c taler-exchange-httpd_refund.h \ taler-exchange-httpd_reserves_get.c taler-exchange-httpd_reserves_get.h \ @@ -94,6 +102,10 @@ taler_exchange_httpd_SOURCES = \ taler-exchange-httpd_transfers_get.c taler-exchange-httpd_transfers_get.h \ taler-exchange-httpd_wire.c taler-exchange-httpd_wire.h \ taler-exchange-httpd_withdraw.c taler-exchange-httpd_withdraw.h + +# taler-exchange-httpd_management_post_keys.c + + taler_exchange_httpd_LDADD = \ $(LIBGCRYPT_LIBS) \ $(top_builddir)/src/bank-lib/libtalerbank.la \ diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index 1faea14fa..6dc689848 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -112,6 +112,11 @@ struct TALER_MasterPublicKeyP TEH_master_public_key; */ struct TALER_EXCHANGEDB_Plugin *TEH_plugin; +/** + * Our currency. + */ +char *TEH_currency; + /** * Default timeout in seconds for HTTP requests. */ @@ -814,6 +819,15 @@ exchange_serve_process_config (void) "REVOCATION_DIR"); return GNUNET_SYSERR; } + if (GNUNET_OK != + TALER_config_get_currency (TEH_cfg, + &TEH_currency)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "taler", + "CURRENCY"); + return GNUNET_SYSERR; + } { char *master_public_key_str; diff --git a/src/exchange/taler-exchange-httpd.h b/src/exchange/taler-exchange-httpd.h index b1e8079fe..ad46788c4 100644 --- a/src/exchange/taler-exchange-httpd.h +++ b/src/exchange/taler-exchange-httpd.h @@ -68,6 +68,11 @@ extern struct TALER_MasterPublicKeyP TEH_master_public_key; */ extern struct TALER_EXCHANGEDB_Plugin *TEH_plugin; +/** + * Our currency. + */ +extern char *TEH_currency; + /** * @brief Struct describing an URL and the handler for it. diff --git a/src/exchange/taler-exchange-httpd_auditors.c b/src/exchange/taler-exchange-httpd_auditors.c index 954cb9983..0aa10812e 100644 --- a/src/exchange/taler-exchange-httpd_auditors.c +++ b/src/exchange/taler-exchange-httpd_auditors.c @@ -26,9 +26,9 @@ #include #include "taler_json_lib.h" #include "taler_mhd_lib.h" -#include "taler-exchange-httpd_refund.h" +#include "taler_signatures.h" #include "taler-exchange-httpd_responses.h" -#include "taler-exchange-httpd_keystate.h" + /** * Closure for the #add_auditor_denom_sig transaction. @@ -78,12 +78,13 @@ add_auditor_denom_sig (void *cls, struct AddAuditorDenomContext *awc = cls; struct TALER_EXCHANGEDB_DenominationKeyMetaData meta; enum GNUNET_DB_QueryStatus qs; + char *auditor_url; bool enabled; - qs = TEH_plugin->lookup_deomination_key ( + qs = TEH_plugin->lookup_denomination_key ( TEH_plugin->cls, session, - aws->h_denom_pub, + awc->h_denom_pub, &meta); if (qs < 0) { @@ -92,23 +93,25 @@ add_auditor_denom_sig (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup denomination key"); return qs; } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_XXX, - "denomination unkown"); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN, + GNUNET_h2s (awc->h_denom_pub)); return GNUNET_DB_STATUS_HARD_ERROR; } qs = TEH_plugin->lookup_auditor_status ( TEH_plugin->cls, session, - aws->auditor_pub, + awc->auditor_pub, + &auditor_url, &enabled); if (qs < 0) { @@ -117,36 +120,39 @@ add_auditor_denom_sig (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup auditor"); return qs; } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_PRECONDITION_FAILED, - TALER_EC_EXCHANGE_XXX, - "auditor unkown"); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_PRECONDITION_FAILED, + TALER_EC_EXCHANGE_AUDITORS_AUDITOR_UNKNOWN, + TALER_B2S (awc->auditor_pub)); return GNUNET_DB_STATUS_HARD_ERROR; } if (! enabled) { - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_GONE, - TALER_EC_EXCHANGE_XXX, - "auditor no longer in use"); + GNUNET_free (auditor_url); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_GONE, + TALER_EC_EXCHANGE_AUDITORS_AUDITOR_INACTIVE, + TALER_B2S (awc->auditor_pub)); return GNUNET_DB_STATUS_HARD_ERROR; } { struct TALER_ExchangeKeyValidityPS kv = { .purpose.purpose = htonl (TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS), - .purpose.size = htonl (kv), - .master = TEH_master_public_key.eddsa_pub, - .start = meta->start, + .purpose.size = htonl (sizeof (kv)), + .master = TEH_master_public_key, + .start = GNUNET_TIME_absolute_hton (meta.start), .expire_withdraw = GNUNET_TIME_absolute_hton (meta.expire_withdraw), .expire_deposit = GNUNET_TIME_absolute_hton (meta.expire_deposit), .expire_legal = GNUNET_TIME_absolute_hton (meta.expire_legal), - .denom_hash = meta->denom_hash + .denom_hash = *awc->h_denom_pub }; TALER_amount_hton (&kv.value, @@ -162,19 +168,21 @@ add_auditor_denom_sig (void *cls, GNUNET_CRYPTO_hash (auditor_url, strlen (auditor_url) + 1, &kv.auditor_url_hash); + GNUNET_free (auditor_url); if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS, &kv, - &master_sig.eddsa_sig, + &awc->auditor_sig.eddsa_sig, &TEH_master_public_key.eddsa_pub)) { /* signature invalid */ GNUNET_break_op (0); - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_XXX, - NULL); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_FORBIDDEN, + TALER_EC_EXCHANGE_AUDITORS_AUDITOR_SIGNATURE_INVALID, + NULL); return GNUNET_DB_STATUS_HARD_ERROR; } } @@ -183,7 +191,7 @@ add_auditor_denom_sig (void *cls, session, awc->h_denom_pub, awc->auditor_pub, - &aws->auditor_sig); + &awc->auditor_sig); if (qs < 0) { GNUNET_break (0); @@ -223,6 +231,7 @@ TEH_handler_management_denominations_auditors ( GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + MHD_RESULT res; { enum GNUNET_GenericReturnValue res; diff --git a/src/exchange/taler-exchange-httpd_management_auditors.c b/src/exchange/taler-exchange-httpd_management_auditors.c index 4d4d411e7..adfe94d91 100644 --- a/src/exchange/taler-exchange-httpd_management_auditors.c +++ b/src/exchange/taler-exchange-httpd_management_auditors.c @@ -81,6 +81,7 @@ add_auditor (void *cls, { struct AddAuditorContext *aac = cls; struct GNUNET_TIME_Absolute last_date; + enum GNUNET_DB_QueryStatus qs; qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls, session, @@ -93,16 +94,16 @@ add_auditor (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup auditor"); return qs; } - if (last_date.abs_value_us > aac->start_date.abs_value_us) + if (last_date.abs_value_us > aac->validity_start.abs_value_us) { *mhd_ret = TALER_MHD_reply_with_error ( connection, MHD_HTTP_CONFLICT, - TALER_EC_EXCHANGE_AUDITOR_MORE_RECENT_PRESENT, + TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_MORE_RECENT_PRESENT, NULL); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -111,14 +112,14 @@ add_auditor (void *cls, session, &aac->auditor_pub, aac->auditor_url, - aac->start_date, + aac->validity_start, &aac->master_sig); else qs = TEH_plugin->update_auditor (TEH_plugin->cls, session, &aac->auditor_pub, aac->auditor_url, - aac->start_date, + aac->validity_start, &aac->master_sig, true); if (qs < 0) @@ -163,6 +164,7 @@ TEH_handler_management_auditors ( GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + MHD_RESULT res; { enum GNUNET_GenericReturnValue res; @@ -180,25 +182,25 @@ TEH_handler_management_auditors ( .purpose.purpose = htonl ( TALER_SIGNATURE_MASTER_ADD_AUDITOR), .purpose.size = htonl (sizeof (aa)), - .start_date = GNUNET_TIME_absolute_hton (validity_start), - .auditor_pub = *auditor_pub + .start_date = GNUNET_TIME_absolute_hton (aac.validity_start), + .auditor_pub = aac.auditor_pub }; - GNUNET_CRYPTO_hash (auditor_url, - strlen (auditor_url) + 1, + GNUNET_CRYPTO_hash (aac.auditor_url, + strlen (aac.auditor_url) + 1, &aa.h_auditor_url); if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_ADD_AUDITOR, &aa, - &master_sig.eddsa_sig, + &aac.master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_AUDITOR_ADD_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_ADD_SIGNATURE_INVALID, NULL); } } diff --git a/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c b/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c index 043482bef..60f0f5398 100644 --- a/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c +++ b/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c @@ -81,6 +81,7 @@ del_auditor (void *cls, { struct DelAuditorContext *dac = cls; struct GNUNET_TIME_Absolute last_date; + enum GNUNET_DB_QueryStatus qs; qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls, session, @@ -93,16 +94,16 @@ del_auditor (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup auditor"); return qs; } - if (last_date.abs_value_us > dac->end_date.abs_value_us) + if (last_date.abs_value_us > dac->validity_end.abs_value_us) { *mhd_ret = TALER_MHD_reply_with_error ( connection, MHD_HTTP_CONFLICT, - TALER_EC_EXCHANGE_AUDITOR_MORE_RECENT_PRESENT, + TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_MORE_RECENT_PRESENT, NULL); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -111,7 +112,7 @@ del_auditor (void *cls, *mhd_ret = TALER_MHD_reply_with_error ( connection, MHD_HTTP_NOT_FOUND, - TALER_EC_EXCHANGE_AUDITOR_NOT_FOUND, + TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_NOT_FOUND, NULL); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -119,7 +120,7 @@ del_auditor (void *cls, session, &dac->auditor_pub, "", - dac->end_date, + dac->validity_end, &dac->master_sig, false); if (qs < 0) @@ -162,6 +163,7 @@ TEH_handler_management_auditors_AP_disable ( GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + MHD_RESULT res; { enum GNUNET_GenericReturnValue res; @@ -179,22 +181,22 @@ TEH_handler_management_auditors_AP_disable ( .purpose.purpose = htonl ( TALER_SIGNATURE_MASTER_DEL_AUDITOR), .purpose.size = htonl (sizeof (da)), - .end_date = GNUNET_TIME_absolute_hton (validity_end), - .auditor_pub = *auditor_pub + .end_date = GNUNET_TIME_absolute_hton (dac.validity_end), + .auditor_pub = dac.auditor_pub }; if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_DEL_AUDITOR, &da, - &master_sig.eddsa_sig, + &dac.master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_AUDITOR_DEL_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_DEL_SIGNATURE_INVALID, NULL); } } diff --git a/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c b/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c index 990dd2e34..bd4b5f342 100644 --- a/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c +++ b/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c @@ -76,14 +76,14 @@ TEH_handler_management_denominations_HDP_revoke ( GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED, &rm, - &master_sig.eddsa_sig, + &master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_DENOMINATION_REVOKE_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_DENOMINATION_REVOKE_SIGNATURE_INVALID, NULL); } } diff --git a/src/exchange/taler-exchange-httpd_management_post_keys.c b/src/exchange/taler-exchange-httpd_management_post_keys.c index ab7afd34b..4d5a65af9 100644 --- a/src/exchange/taler-exchange-httpd_management_post_keys.c +++ b/src/exchange/taler-exchange-httpd_management_post_keys.c @@ -26,9 +26,8 @@ #include #include "taler_json_lib.h" #include "taler_mhd_lib.h" -#include "taler-exchange-httpd_refund.h" +#include "taler_signatures.h" #include "taler-exchange-httpd_responses.h" -#include "taler-exchange-httpd_keystate.h" /** @@ -126,7 +125,7 @@ add_keys (void *cls, bool is_active = false; struct TALER_EXCHANGEDB_DenominationKeyMetaData meta; - qs = TEH_plugin->lookup_future_deomination_key ( + qs = TEH_plugin->lookup_future_denomination_key ( TEH_plugin->cls, session, &akc->d_sigs[i].h_denom_pub, @@ -134,7 +133,7 @@ add_keys (void *cls, if (0 == qs) { /* For idempotency, check if the key is already active */ - qs = TEH_plugin->lookup_deomination_key ( + qs = TEH_plugin->lookup_denomination_key ( TEH_plugin->cls, session, &akc->d_sigs[i].h_denom_pub, @@ -148,17 +147,17 @@ add_keys (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup denomination key"); return qs; } if (0 == qs) { - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_GENERIC_DENOM_UNKNOWN, - GNUNET_h2s ( - &aks->d_sigs[i].h_denom_pub)); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN, + GNUNET_h2s (&akc->d_sigs[i].h_denom_pub)); return qs; } @@ -190,20 +189,20 @@ add_keys (void *cls, GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY, &dkv, - &akc->d_sigs[i].master_sig.eddsa_sig, + &akc->d_sigs[i].master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_KEYS_ADD_SIGNATURE_INVALID, - GNUNET_h2s (&aks->d_sigs[i].h_denom_pub)); + TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_ADD_SIGNATURE_INVALID, + GNUNET_h2s (&akc->d_sigs[i].h_denom_pub)); } } if (is_active) continue; /* skip, already known */ - qs = TEH_plugin->activate_deomination_key ( + qs = TEH_plugin->activate_denomination_key ( TEH_plugin->cls, session, &akc->d_sigs[i].h_denom_pub, @@ -252,17 +251,17 @@ add_keys (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup signing key"); return qs; } if (0 == qs) { - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_GENERIC_SIGNKEY_UNKNOWN, - TALER_B2S ( - &aks->s_sigs[i].exchange_pub)); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_UNKNOWN, + TALER_B2S (&akc->s_sigs[i].exchange_pub)); return qs; } @@ -271,27 +270,27 @@ add_keys (void *cls, struct TALER_ExchangeSigningKeyValidityPS skv = { .purpose.purpose = htonl ( TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY), - .purpose.size = htonl (sizeof (dkv)), + .purpose.size = htonl (sizeof (skv)), .master_public_key = TEH_master_public_key, .start = x, .expire = y, .end = z, - .signkey_pub = akc->d_sigs[i].exchange_pub + .signkey_pub = akc->s_sigs[i].exchange_pub }; if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY, &skv, - &akc->s_sigs[i].master_sig.eddsa_sig, + &akc->s_sigs[i].master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_KEYS_ADD_SIGNATURE_INVALID, - GNUNET_h2s (&aks->d_sigs[i].h_denom_pub)); + TALER_EC_EXCHANGE_MANAGEMENT_KEYS_DENOMKEY_ADD_SIGNATURE_INVALID, + GNUNET_h2s (&akc->d_sigs[i].h_denom_pub)); } } if (is_active) @@ -365,7 +364,7 @@ TEH_handler_management_post_keys ( return TALER_MHD_reply_with_error ( connection, MHD_HTTP_BAD_REQUEST, - TALER_EC_XXX, + TALER_EC_GENERIC_PARAMETER_MALFORMED, "array expected for denom_sigs and signkey_sigs"); } akc.nd_sigs = json_array_size (denom_sigs); @@ -375,7 +374,7 @@ TEH_handler_management_post_keys ( for (unsigned int i = 0; imaster_sig), GNUNET_JSON_spec_fixed_auto ("h_denom_pub", @@ -385,9 +384,9 @@ TEH_handler_management_post_keys ( enum GNUNET_GenericReturnValue res; res = TALER_MHD_parse_json_data (connection, - root, json_array_get (denom_sigs, - i)); + i), + ispec); if (GNUNET_SYSERR == res) { ret = MHD_NO; /* hard failure */ @@ -412,7 +411,7 @@ TEH_handler_management_post_keys ( for (unsigned int i = 0; imaster_sig), GNUNET_JSON_spec_fixed_auto ("exchange_pub", @@ -422,9 +421,9 @@ TEH_handler_management_post_keys ( enum GNUNET_GenericReturnValue res; res = TALER_MHD_parse_json_data (connection, - root, json_array_get (signkey_sigs, - i)); + i), + ispec); if (GNUNET_SYSERR == res) { ret = MHD_NO; /* hard failure */ @@ -446,11 +445,11 @@ TEH_handler_management_post_keys ( } qs = TEH_DB_run_transaction (connection, "add keys", - &res, + &ret, &add_keys, &akc); if (qs < 0) - return res; + return ret; return TALER_MHD_reply_static ( connection, MHD_HTTP_NO_CONTENT, diff --git a/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c b/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c index 4fc190b38..bbe3ae10f 100644 --- a/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c +++ b/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c @@ -64,7 +64,7 @@ TEH_handler_management_signkeys_EP_revoke ( return MHD_YES; /* failure */ } { - struct TALER_MasterDenominationKeyRevocationPS rm = { + struct TALER_MasterSigningKeyRevocationPS rm = { .purpose.purpose = htonl ( TALER_SIGNATURE_MASTER_SIGNING_KEY_REVOKED), .purpose.size = htonl (sizeof (rm)), @@ -75,14 +75,14 @@ TEH_handler_management_signkeys_EP_revoke ( GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_SIGNING_KEY_REVOKED, &rm, - &master_sig.eddsa_sig, + &master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_SIGNKEY_REVOKE_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_SIGNKEY_REVOKE_SIGNATURE_INVALID, NULL); } } diff --git a/src/exchange/taler-exchange-httpd_management_wire.c b/src/exchange/taler-exchange-httpd_management_wire.c index a841a1e67..812570fca 100644 --- a/src/exchange/taler-exchange-httpd_management_wire.c +++ b/src/exchange/taler-exchange-httpd_management_wire.c @@ -26,9 +26,9 @@ #include #include "taler_json_lib.h" #include "taler_mhd_lib.h" -#include "taler-exchange-httpd_refund.h" +#include "taler_signatures.h" #include "taler-exchange-httpd_responses.h" -#include "taler-exchange-httpd_keystate.h" + /** * Closure for the #add_wire transaction. @@ -50,7 +50,7 @@ struct AddWireContext /** * Payto:// URI this is about. */ - const char *payto_url; + const char *payto_uri; /** * Timestamp for checking against replay attacks. @@ -83,6 +83,7 @@ add_wire (void *cls, { struct AddWireContext *awc = cls; struct GNUNET_TIME_Absolute last_date; + enum GNUNET_DB_QueryStatus qs; qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls, session, @@ -95,31 +96,30 @@ add_wire (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup wire"); return qs; } - if (last_date.abs_value_us > awc->start_date.abs_value_us) + if (last_date.abs_value_us > awc->validity_start.abs_value_us) { *mhd_ret = TALER_MHD_reply_with_error ( connection, MHD_HTTP_CONFLICT, - TALER_EC_EXCHANGE_WIRE_MORE_RECENT_PRESENT, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_MORE_RECENT_PRESENT, NULL); return GNUNET_DB_STATUS_HARD_ERROR; } if (0 == qs) qs = TEH_plugin->insert_wire (TEH_plugin->cls, session, - &awc->payto_uri, - awc->start_date, - &awc->master_sig_add); + awc->payto_uri, + awc->validity_start, + &awc->master_sig_wire); else qs = TEH_plugin->update_wire (TEH_plugin->cls, session, - &awc->payto_uri, - awc->start_date, - &awc->master_sig_add, + awc->payto_uri, + awc->validity_start, true); if (qs < 0) { @@ -132,21 +132,6 @@ add_wire (void *cls, "add wire"); return qs; } - qs = TEH_plugin->insert_wire_details (TEH_plugin->cls, - session, - &awc->payto_uri, - &awc->master_sig_wire); - if (qs < 0) - { - GNUNET_break (0); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - return qs; - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "add wire details"); - return qs; - } return qs; } @@ -176,6 +161,7 @@ TEH_handler_management_denominations_wire ( GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + MHD_RESULT ret; { enum GNUNET_GenericReturnValue res; @@ -190,10 +176,9 @@ TEH_handler_management_denominations_wire ( } { struct TALER_MasterAddWirePS aw = { - .purpose.purpose = htonl ( - TALER_SIGNATURE_MASTER_ADD_WIRE), + .purpose.purpose = htonl (TALER_SIGNATURE_MASTER_ADD_WIRE), .purpose.size = htonl (sizeof (aw)), - .start_date = GNUNET_TIME_absolute_hton (validity_start), + .start_date = GNUNET_TIME_absolute_hton (awc.validity_start), }; GNUNET_CRYPTO_hash (awc.payto_uri, @@ -203,14 +188,14 @@ TEH_handler_management_denominations_wire ( GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_ADD_WIRE, &aw, - &master_sig.eddsa_sig, + &awc.master_sig_add.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_WIRE_ADD_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_ADD_SIGNATURE_INVALID, NULL); } } @@ -223,30 +208,30 @@ TEH_handler_management_denominations_wire ( GNUNET_CRYPTO_hash (awc.payto_uri, strlen (awc.payto_uri) + 1, - &wd.h_wire); + &wd.h_wire_details); if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_WIRE_DETAILS, &wd, - &master_sig.eddsa_sig, + &awc.master_sig_wire.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_WIRE_DETALS_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_DETAILS_SIGNATURE_INVALID, NULL); } } qs = TEH_DB_run_transaction (connection, "add wire", - &res, + &ret, &add_wire, &awc); if (qs < 0) - return res; + return ret; return TALER_MHD_reply_static ( connection, MHD_HTTP_NO_CONTENT, diff --git a/src/exchange/taler-exchange-httpd_management_wire_disable.c b/src/exchange/taler-exchange-httpd_management_wire_disable.c index af6b2e56f..19a30fc23 100644 --- a/src/exchange/taler-exchange-httpd_management_wire_disable.c +++ b/src/exchange/taler-exchange-httpd_management_wire_disable.c @@ -44,12 +44,12 @@ struct DelWireContext /** * Payto:// URI this is about. */ - const char *payto_url; + const char *payto_uri; /** * Timestamp for checking against replay attacks. */ - struct GNUNET_TIME_Absolute validity_start; + struct GNUNET_TIME_Absolute validity_end; }; @@ -77,11 +77,12 @@ del_wire (void *cls, { struct DelWireContext *awc = cls; struct GNUNET_TIME_Absolute last_date; + enum GNUNET_DB_QueryStatus qs; - qs = TEH_plugin->lookup_wire (TEH_plugin->cls, - session, - awc->payto_uri, - &last_date); + qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls, + session, + awc->payto_uri, + &last_date); if (qs < 0) { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) @@ -89,46 +90,33 @@ del_wire (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup wire"); return qs; } - if (last_date.abs_value_us > awc->start_date.abs_value_us) + if (last_date.abs_value_us > awc->validity_end.abs_value_us) { *mhd_ret = TALER_MHD_reply_with_error ( connection, MHD_HTTP_CONFLICT, - TALER_EC_EXCHANGE_WIRE_MORE_RECENT_PRESENT, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_MORE_RECENT_PRESENT, NULL); return GNUNET_DB_STATUS_HARD_ERROR; } if (0 == qs) - qs = TEH_plugin->insert_wire (TEH_plugin->cls, - session, - &awc->payto_uri, - awc->end_date, - &awc->master_sig_del); - else - qs = TEH_plugin->update_wire (TEH_plugin->cls, - session, - &awc->payto_uri, - awc->end_date, - &awc->master_sig_del, - false); - if (qs < 0) { - GNUNET_break (0); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - return qs; - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "del wire"); - return qs; + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_NOT_FOUND, + NULL); + return GNUNET_DB_STATUS_HARD_ERROR; } - qs = TEH_plugin->delete_wire_details (TEH_plugin->cls, - session, - &awc->payto_uri); + qs = TEH_plugin->update_wire (TEH_plugin->cls, + session, + awc->payto_uri, + awc->validity_end, + false); if (qs < 0) { GNUNET_break (0); @@ -137,7 +125,7 @@ del_wire (void *cls, *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_STORE_FAILED, - "del wire details"); + "del wire"); return qs; } return qs; @@ -167,6 +155,7 @@ TEH_handler_management_denominations_wire_disable ( GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + MHD_RESULT ret; { enum GNUNET_GenericReturnValue res; @@ -184,7 +173,7 @@ TEH_handler_management_denominations_wire_disable ( .purpose.purpose = htonl ( TALER_SIGNATURE_MASTER_DEL_WIRE), .purpose.size = htonl (sizeof (aw)), - .end_date = GNUNET_TIME_absolute_hton (validity_end), + .end_date = GNUNET_TIME_absolute_hton (awc.validity_end), }; GNUNET_CRYPTO_hash (awc.payto_uri, @@ -194,24 +183,24 @@ TEH_handler_management_denominations_wire_disable ( GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_DEL_WIRE, &aw, - &master_sig.eddsa_sig, + &awc.master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( connection, MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_WIRE_DEL_SIGNATURE_INVALID, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_DEL_SIGNATURE_INVALID, NULL); } } qs = TEH_DB_run_transaction (connection, "del wire", - &res, + &ret, &del_wire, &awc); if (qs < 0) - return res; + return ret; return TALER_MHD_reply_static ( connection, MHD_HTTP_NO_CONTENT, diff --git a/src/exchange/taler-exchange-httpd_management_wire_fees.c b/src/exchange/taler-exchange-httpd_management_wire_fees.c index dca489c68..c126f056b 100644 --- a/src/exchange/taler-exchange-httpd_management_wire_fees.c +++ b/src/exchange/taler-exchange-httpd_management_wire_fees.c @@ -26,9 +26,9 @@ #include #include "taler_json_lib.h" #include "taler_mhd_lib.h" -#include "taler-exchange-httpd_refund.h" +#include "taler_signatures.h" #include "taler-exchange-httpd_responses.h" -#include "taler-exchange-httpd_keystate.h" + /** * Closure for the #add_fee transaction. @@ -94,12 +94,12 @@ add_fee (void *cls, struct TALER_Amount wire_fee; struct TALER_Amount closing_fee; - qs = TEH_plugin->lookup_wire_fee ( + qs = TEH_plugin->lookup_wire_fee_by_time ( TEH_plugin->cls, session, - aws->wire_method, - aws->start_time, - aws->end_time, + afc->wire_method, + afc->start_time, + afc->end_time, &wire_fee, &closing_fee); if (qs < 0) @@ -109,7 +109,7 @@ add_fee (void *cls, GNUNET_break (0); *mhd_ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_LOOKUP_FAILED, + TALER_EC_GENERIC_DB_FETCH_FAILED, "lookup wire fee"); return qs; } @@ -129,10 +129,11 @@ add_fee (void *cls, } else { - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_XXX, - NULL); + *mhd_ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_CONFLICT, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_FEE_MISMATCH, + NULL); } return GNUNET_DB_STATUS_HARD_ERROR; } @@ -140,12 +141,12 @@ add_fee (void *cls, qs = TEH_plugin->insert_wire_fee ( TEH_plugin->cls, session, - aws->wire_method, - aws->start_time, - aws->end_time, - &aws->wire_fee, - &aws->closing_fee, - &aws->master_sig); + afc->wire_method, + afc->start_time, + afc->end_time, + &afc->wire_fee, + &afc->closing_fee, + &afc->master_sig); if (qs < 0) { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) @@ -179,10 +180,10 @@ TEH_handler_management_post_wire_fees ( &afc.master_sig), GNUNET_JSON_spec_string ("wire_method", &afc.wire_method), - TALER_JSON_spec_time_abs ("fee_start", - &afc.start_time), - TALER_JSON_spec_time_abs ("fee_end", - &afc.end_time), + TALER_JSON_spec_absolute_time ("fee_start", + &afc.start_time), + TALER_JSON_spec_absolute_time ("fee_end", + &afc.end_time), TALER_JSON_spec_amount ("closing_fee", &afc.closing_fee), TALER_JSON_spec_amount ("wire_fee", @@ -190,6 +191,7 @@ TEH_handler_management_post_wire_fees ( GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; + MHD_RESULT ret; { enum GNUNET_GenericReturnValue res; @@ -211,7 +213,7 @@ TEH_handler_management_post_wire_fees ( GNUNET_break_op (0); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_BAD_CURRENCY, + TALER_EC_GENERIC_CURRENCY_MISMATCH, NULL); } if (0 != @@ -221,21 +223,21 @@ TEH_handler_management_post_wire_fees ( /* currency does not match exchange's currency */ return TALER_MHD_reply_with_error (connection, MHD_HTTP_PRECONDITION_FAILED, - TALER_EC_GENERIC_BAD_CURRENCY, + TALER_EC_GENERIC_CURRENCY_MISMATCH, TEH_currency); } { struct TALER_MasterWireFeePS wf = { .purpose.purpose = htonl (TALER_SIGNATURE_MASTER_WIRE_FEES), - .purpose.size = htonl (wf), - .start_date = GNUNET_TIME_absolute_hton (afc.start_date), - .end_date = GNUNET_TIME_absolute_hton (afc.end_date), + .purpose.size = htonl (sizeof (wf)), + .start_date = GNUNET_TIME_absolute_hton (afc.start_time), + .end_date = GNUNET_TIME_absolute_hton (afc.end_time), }; - TALER_amount_hton (&kv.wire_fee, + TALER_amount_hton (&wf.wire_fee, &afc.wire_fee); - TALER_amount_hton (&kv.closing_fee, + TALER_amount_hton (&wf.closing_fee, &afc.closing_fee); GNUNET_CRYPTO_hash (afc.wire_method, strlen (afc.wire_method) + 1, @@ -244,26 +246,26 @@ TEH_handler_management_post_wire_fees ( GNUNET_CRYPTO_eddsa_verify ( TALER_SIGNATURE_MASTER_WIRE_FEES, &wf, - &afc.master_sig.eddsa_sig, + &afc.master_sig.eddsa_signature, &TEH_master_public_key.eddsa_pub)) { /* signature invalid */ GNUNET_break_op (0); - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_FORBIDDEN, - TALER_EC_EXCHANGE_XXX, - NULL); - return GNUNET_DB_STATUS_HARD_ERROR; + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_FORBIDDEN, + TALER_EC_EXCHANGE_MANAGEMENT_WIRE_FEE_SIGNATURE_INVALID, + NULL); } } qs = TEH_DB_run_transaction (connection, "add wire fee", - &res, + &ret, &add_fee, &afc); if (qs < 0) - return res; + return ret; return TALER_MHD_reply_static ( connection, MHD_HTTP_NO_CONTENT, -- cgit v1.2.3