diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-11-22 14:57:05 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-11-22 14:57:05 +0100 |
commit | 329adf6a4d3242fa4fb8c779f45e31f506f36a1e (patch) | |
tree | 1cc58063fb2cf69f1f5d928be34c97cce140da06 | |
parent | 7d2ea50b855633c4f595080048542a4fb423f54a (diff) |
use KYC context to pass address to validate to Challenger /setup step
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-start.c | 3 | ||||
-rw-r--r-- | src/include/taler_kyclogic_plugin.h | 2 | ||||
-rw-r--r-- | src/kyclogic/Makefile.am | 1 | ||||
-rw-r--r-- | src/kyclogic/plugin_kyclogic_kycaid.c | 3 | ||||
-rw-r--r-- | src/kyclogic/plugin_kyclogic_oauth2.c | 102 | ||||
-rw-r--r-- | src/kyclogic/plugin_kyclogic_persona.c | 3 | ||||
-rw-r--r-- | src/kyclogic/plugin_kyclogic_template.c | 3 | ||||
-rw-r--r-- | src/kyclogic/taler-exchange-kyc-tester.c | 1 |
8 files changed, 86 insertions, 32 deletions
diff --git a/src/exchange/taler-exchange-httpd_kyc-start.c b/src/exchange/taler-exchange-httpd_kyc-start.c index 7082c0b4d..521a63185 100644 --- a/src/exchange/taler-exchange-httpd_kyc-start.c +++ b/src/exchange/taler-exchange-httpd_kyc-start.c @@ -273,6 +273,7 @@ TEH_handler_kyc_start ( const struct TALER_KYCLOGIC_KycProvider *provider; struct TALER_KYCLOGIC_ProviderDetails *pd; bool is_finished; + const json_t *context; kyp = GNUNET_new (struct KycPoller); kyp->connection = rc->connection; @@ -379,7 +380,6 @@ TEH_handler_kyc_start ( { const char *check_name; const char *prog_name; - const json_t *context; kyp->ec = TALER_KYCLOGIC_select_measure ( kyp->jmeasures, @@ -463,6 +463,7 @@ TEH_handler_kyc_start ( pd, &kyp->h_payto, kyp->process_row, + context, &initiate_cb, kyp); if (NULL == kyp->ih) diff --git a/src/include/taler_kyclogic_plugin.h b/src/include/taler_kyclogic_plugin.h index 00f35fd60..0becabb05 100644 --- a/src/include/taler_kyclogic_plugin.h +++ b/src/include/taler_kyclogic_plugin.h @@ -284,6 +284,7 @@ struct TALER_KYCLOGIC_Plugin * @param pd provider configuration details * @param account_id which account to trigger process for * @param process_row unique ID for the legitimization process + * @param context additional contextual information for the legi process * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle to cancel operation early @@ -293,6 +294,7 @@ struct TALER_KYCLOGIC_Plugin const struct TALER_KYCLOGIC_ProviderDetails *pd, const struct TALER_NormalizedPaytoHashP *account_id, uint64_t process_row, + const json_t *context, TALER_KYCLOGIC_InitiateCallback cb, void *cb_cls); diff --git a/src/kyclogic/Makefile.am b/src/kyclogic/Makefile.am index 626051e65..c1d20853b 100644 --- a/src/kyclogic/Makefile.am +++ b/src/kyclogic/Makefile.am @@ -100,6 +100,7 @@ libtaler_plugin_kyclogic_oauth2_la_LDFLAGS = \ $(TALER_PLUGIN_LDFLAGS) \ $(top_builddir)/src/templating/libtalertemplating.la \ $(top_builddir)/src/mhd/libtalermhd.la \ + $(top_builddir)/src/curl/libtalercurl.la \ $(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/util/libtalerutil.la \ -lgnunetcurl \ diff --git a/src/kyclogic/plugin_kyclogic_kycaid.c b/src/kyclogic/plugin_kyclogic_kycaid.c index a5df10b4b..3e6947a94 100644 --- a/src/kyclogic/plugin_kyclogic_kycaid.c +++ b/src/kyclogic/plugin_kyclogic_kycaid.c @@ -571,6 +571,7 @@ handle_initiate_finished (void *cls, * @param pd provider configuration details * @param account_id which account to trigger process for * @param legitimization_uuid unique ID for the legitimization process + * @param context additional contextual information for the legi process * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle to cancel operation early @@ -580,6 +581,7 @@ kycaid_initiate (void *cls, const struct TALER_KYCLOGIC_ProviderDetails *pd, const struct TALER_NormalizedPaytoHashP *account_id, uint64_t legitimization_uuid, + const json_t *context, TALER_KYCLOGIC_InitiateCallback cb, void *cb_cls) { @@ -588,6 +590,7 @@ kycaid_initiate (void *cls, json_t *body; CURL *eh; + (void) context; eh = curl_easy_init (); if (NULL == eh) { diff --git a/src/kyclogic/plugin_kyclogic_oauth2.c b/src/kyclogic/plugin_kyclogic_oauth2.c index bb3b9dad2..20f0d9158 100644 --- a/src/kyclogic/plugin_kyclogic_oauth2.c +++ b/src/kyclogic/plugin_kyclogic_oauth2.c @@ -22,6 +22,7 @@ #include "taler_kyclogic_plugin.h" #include "taler_mhd_lib.h" #include "taler_templating_lib.h" +#include "taler_curl_lib.h" #include "taler_json_lib.h" #include <regex.h> #include "taler_util.h" @@ -174,6 +175,17 @@ struct TALER_KYCLOGIC_InitiateHandle */ void *cb_cls; + /** + * Initial address to pass to the KYC provider on /setup. + */ + json_t *initial_address; + + /** + * Context for #TEH_curl_easy_post(). Keeps the data that must + * persist for Curl to make the upload. + */ + struct TALER_CURL_PostContext ctx; + }; @@ -533,6 +545,30 @@ oauth2_load_configuration (void *cls, /** + * Cancel KYC check initiation. + * + * @param[in] ih handle of operation to cancel + */ +static void +oauth2_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih) +{ + if (NULL != ih->task) + { + GNUNET_SCHEDULER_cancel (ih->task); + ih->task = NULL; + } + if (NULL != ih->job) + { + GNUNET_CURL_job_cancel (ih->job); + ih->job = NULL; + } + TALER_curl_easy_post_finished (&ih->ctx); + json_decref (ih->initial_address); + GNUNET_free (ih); +} + + +/** * Logic to asynchronously return the response for * how to begin the OAuth2.0 checking process to * the client. @@ -586,7 +622,7 @@ initiate_with_url (struct TALER_KYCLOGIC_InitiateHandle *ih, NULL /* no error */); GNUNET_free (url); GNUNET_free (hps); - GNUNET_free (ih); + oauth2_initiate_cancel (ih); } @@ -620,7 +656,7 @@ handle_curl_setup_finished (void *cls, NULL, NULL, "/setup request to OAuth 2.0 backend returned no response"); - GNUNET_free (ih); + oauth2_initiate_cancel (ih); return; case MHD_HTTP_OK: { @@ -651,7 +687,7 @@ handle_curl_setup_finished (void *cls, NULL, NULL, "Unexpected response from KYC gateway: setup must return a nonce"); - GNUNET_free (ih); + oauth2_initiate_cancel (ih); return; } GNUNET_asprintf (&url, @@ -674,7 +710,7 @@ handle_curl_setup_finished (void *cls, NULL, NULL, "/setup request to OAuth 2.0 backend returned unexpected HTTP status code"); - GNUNET_free (ih); + oauth2_initiate_cancel (ih); return; } } @@ -714,7 +750,7 @@ initiate_task (void *cls) NULL, NULL, "curl_easy_init() failed"); - GNUNET_free (ih); + oauth2_initiate_cancel (ih); return; } GNUNET_assert (CURLE_OK == @@ -725,10 +761,31 @@ initiate_task (void *cls) curl_easy_setopt (eh, CURLOPT_POST, 1)); - GNUNET_assert (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_POSTFIELDS, - "")); + if (NULL == ih->initial_address) + { + GNUNET_assert (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_POSTFIELDS, + "")); + } + else + { + if (GNUNET_OK != + TALER_curl_easy_post (&ih->ctx, + eh, + ih->initial_address)) + { + curl_easy_cleanup (eh); + ih->cb (ih->cb_cls, + TALER_EC_GENERIC_ALLOCATION_FAILURE, + NULL, + NULL, + NULL, + "TALER_curl_easy_post() failed"); + oauth2_initiate_cancel (ih); + return; + } + } GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_FOLLOWLOCATION, @@ -760,6 +817,7 @@ initiate_task (void *cls) * @param pd provider configuration details * @param account_id which account to trigger process for * @param legitimization_uuid unique ID for the legitimization process + * @param context additional contextual information for the legi process * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle to cancel operation early @@ -769,6 +827,7 @@ oauth2_initiate (void *cls, const struct TALER_KYCLOGIC_ProviderDetails *pd, const struct TALER_NormalizedPaytoHashP *account_id, uint64_t legitimization_uuid, + const json_t *context, TALER_KYCLOGIC_InitiateCallback cb, void *cb_cls) { @@ -783,33 +842,14 @@ oauth2_initiate (void *cls, ih->pd = pd; ih->task = GNUNET_SCHEDULER_add_now (&initiate_task, ih); + if (NULL != context) + ih->initial_address = json_incref (json_object_get (context, + "initial_address")); return ih; } /** - * Cancel KYC check initiation. - * - * @param[in] ih handle of operation to cancel - */ -static void -oauth2_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih) -{ - if (NULL != ih->task) - { - GNUNET_SCHEDULER_cancel (ih->task); - ih->task = NULL; - } - if (NULL != ih->job) - { - GNUNET_CURL_job_cancel (ih->job); - ih->job = NULL; - } - GNUNET_free (ih); -} - - -/** * Cancel KYC proof. * * @param[in] ph handle of operation to cancel diff --git a/src/kyclogic/plugin_kyclogic_persona.c b/src/kyclogic/plugin_kyclogic_persona.c index 22abe7ca2..aa3977745 100644 --- a/src/kyclogic/plugin_kyclogic_persona.c +++ b/src/kyclogic/plugin_kyclogic_persona.c @@ -748,6 +748,7 @@ handle_initiate_finished (void *cls, * @param pd provider configuration details * @param account_id which account to trigger process for * @param legitimization_uuid unique ID for the legitimization process + * @param context additional contextual information for the legi process * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle to cancel operation early @@ -757,6 +758,7 @@ persona_initiate (void *cls, const struct TALER_KYCLOGIC_ProviderDetails *pd, const struct TALER_NormalizedPaytoHashP *account_id, uint64_t legitimization_uuid, + const json_t *context, TALER_KYCLOGIC_InitiateCallback cb, void *cb_cls) { @@ -765,6 +767,7 @@ persona_initiate (void *cls, json_t *body; CURL *eh; + (void) context; eh = curl_easy_init (); if (NULL == eh) { diff --git a/src/kyclogic/plugin_kyclogic_template.c b/src/kyclogic/plugin_kyclogic_template.c index d91988941..619717d39 100644 --- a/src/kyclogic/plugin_kyclogic_template.c +++ b/src/kyclogic/plugin_kyclogic_template.c @@ -235,6 +235,7 @@ template_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih) * @param pd provider configuration details * @param account_id which account to trigger process for * @param legitimization_uuid unique ID for the legitimization process + * @param context additional contextual information for the legi process * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle to cancel operation early @@ -244,12 +245,14 @@ template_initiate (void *cls, const struct TALER_KYCLOGIC_ProviderDetails *pd, const struct TALER_NormalizedPaytoHashP *account_id, uint64_t legitimization_uuid, + const json_t *context, TALER_KYCLOGIC_InitiateCallback cb, void *cb_cls) { struct TALER_KYCLOGIC_InitiateHandle *ih; (void) cls; + (void) context; ih = GNUNET_new (struct TALER_KYCLOGIC_InitiateHandle); ih->legitimization_uuid = legitimization_uuid; ih->cb = cb; diff --git a/src/kyclogic/taler-exchange-kyc-tester.c b/src/kyclogic/taler-exchange-kyc-tester.c index 483c637d7..382c5f1f1 100644 --- a/src/kyclogic/taler-exchange-kyc-tester.c +++ b/src/kyclogic/taler-exchange-kyc-tester.c @@ -1686,6 +1686,7 @@ run (void *cls, pd, &cmd_line_h_payto, kyc_row_id, + NULL, /* FIXME: support passing context*/ &initiate_cb, NULL); GNUNET_break (NULL != ih); |