diff options
author | Florian Dold <florian@dold.me> | 2024-11-07 22:58:25 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-11-07 22:58:30 +0100 |
commit | 0a44c2c17504771a284a8c214c0c98def99339fb (patch) | |
tree | 32d9ab62cf87de91c542b00e1d356304d9c6ce3a | |
parent | 7af02519be095b214d2820fb57318ab74157a02e (diff) |
get rid of TEH_kyc_finish
Instead, we now have two more specific functions to run for instant
measures / after having obtained attributes respectively.
-rw-r--r-- | src/exchange/taler-exchange-httpd_aml-decision.c | 4 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_common_kyc.c | 256 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_common_kyc.h | 63 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-proof.c | 8 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-upload.c | 8 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-webhook.c | 11 |
6 files changed, 165 insertions, 185 deletions
diff --git a/src/exchange/taler-exchange-httpd_aml-decision.c b/src/exchange/taler-exchange-httpd_aml-decision.c index 04f5defcd..2a7f530e7 100644 --- a/src/exchange/taler-exchange-httpd_aml-decision.c +++ b/src/exchange/taler-exchange-httpd_aml-decision.c @@ -68,7 +68,7 @@ struct AmlDecisionContext /** * Handle for async KYC processing. */ - struct TEH_KycAmlTrigger *kat; + struct TEH_KycMeasureRunContext *kat; }; @@ -110,7 +110,7 @@ aml_decision_cleaner (struct TEH_RequestContext *rc) if (NULL != adc->kat) { - TEH_kyc_finished_cancel (adc->kat); + TEH_kyc_run_measure_cancel (adc->kat); adc->kat = NULL; } if (NULL != adc->response) diff --git a/src/exchange/taler-exchange-httpd_common_kyc.c b/src/exchange/taler-exchange-httpd_common_kyc.c index 0cf57347a..0b72eb2ea 100644 --- a/src/exchange/taler-exchange-httpd_common_kyc.c +++ b/src/exchange/taler-exchange-httpd_common_kyc.c @@ -40,7 +40,7 @@ #define EXTRA_CHECK 0 -struct TEH_KycAmlTrigger +struct TEH_KycMeasureRunContext { /** @@ -81,7 +81,7 @@ struct TEH_KycAmlTrigger /** * function to call with the result */ - TEH_KycAmlTriggerCallback cb; + TEH_KycMeasureRunContextCallback cb; /** * closure for @e cb @@ -136,7 +136,7 @@ struct TEH_KycAmlTrigger * Function called with the result of activating a * fallback measure. * - * @param cls a `struct TEH_KycAmlTrigger *` + * @param cls a `struct TEH_KycMeasureRunContext *` * @param result true if the fallback was activated * successfully * @param requirement_row row of @@ -147,7 +147,7 @@ fallback_result_cb (void *cls, bool result, uint64_t requirement_row) { - struct TEH_KycAmlTrigger *kat = cls; + struct TEH_KycMeasureRunContext *kat = cls; struct GNUNET_AsyncScopeSave old_scope; kat->fb = NULL; @@ -166,7 +166,7 @@ fallback_result_cb (void *cls, TALER_EC_EXCHANGE_GENERIC_KYC_FALLBACK_FAILED, kat->fallback_name); } - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); GNUNET_async_scope_restore (&old_scope); } @@ -174,7 +174,7 @@ fallback_result_cb (void *cls, /** * Type of a callback that receives a JSON @a result. * - * @param cls closure of type `struct TEH_KycAmlTrigger *` + * @param cls closure of type `struct TEH_KycMeasureRunContext *` * @param apr AML program result */ static void @@ -182,7 +182,7 @@ kyc_aml_finished ( void *cls, const struct TALER_KYCLOGIC_AmlProgramResult *apr) { - struct TEH_KycAmlTrigger *kat = cls; + struct TEH_KycMeasureRunContext *kat = cls; enum GNUNET_DB_QueryStatus qs; size_t eas; void *ea; @@ -208,7 +208,7 @@ kyc_aml_finished ( kat->cb (kat->cb_cls, TALER_EC_GENERIC_DB_STORE_FAILED, "insert_kyc_failure"); - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); GNUNET_async_scope_restore (&old_scope); return; } @@ -219,7 +219,7 @@ kyc_aml_finished ( kat->cb (kat->cb_cls, TALER_EC_EXCHANGE_KYC_AML_PROGRAM_FAILURE, NULL); - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); GNUNET_async_scope_restore (&old_scope); return; } @@ -243,7 +243,7 @@ kyc_aml_finished ( kat->cb (kat->cb_cls, TALER_EC_EXCHANGE_GENERIC_KYC_FALLBACK_UNKNOWN, kat->fallback_name); - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); GNUNET_async_scope_restore (&old_scope); return; } @@ -320,7 +320,7 @@ kyc_aml_finished ( 0); } done: - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); GNUNET_async_scope_restore (&old_scope); } @@ -456,27 +456,52 @@ add_kyc_history_entry ( } -struct TEH_KycAmlTrigger * -TEH_kyc_finished ( +void +TEH_kyc_run_measure_cancel (struct TEH_KycMeasureRunContext *kat) +{ + if (NULL != kat->kyc_aml) + { + TALER_KYCLOGIC_run_aml_program_cancel (kat->kyc_aml); + kat->kyc_aml = NULL; + } + if (NULL != kat->fb) + { + TEH_kyc_fallback_cancel (kat->fb); + kat->fb = NULL; + } + GNUNET_free (kat->provider_name); + GNUNET_free (kat->provider_user_id); + GNUNET_free (kat->provider_legitimization_id); + GNUNET_free (kat->fallback_name); + json_decref (kat->jmeasures); + json_decref (kat->attributes); + json_decref (kat->aml_history); + json_decref (kat->kyc_history); + GNUNET_free (kat); +} + + +struct TEH_KycMeasureRunContext * +TEH_kyc_run_measure_for_attributes ( const struct GNUNET_AsyncScopeId *scope, uint64_t process_row, - const struct TALER_KYCLOGIC_Measure *instant_ms, const struct TALER_NormalizedPaytoHashP *account_id, - const char *provider_name, const char *provider_user_id, const char *provider_legitimization_id, struct GNUNET_TIME_Absolute expiration, - const json_t *attributes, - TEH_KycAmlTriggerCallback cb, + const json_t *new_attributes, + TEH_KycMeasureRunContextCallback cb, void *cb_cls) { - struct TEH_KycAmlTrigger *kat; - enum GNUNET_DB_QueryStatus qs; + /* FIXME(fdold, 2024-11-07): + Consider storing the attributes *before* we run the AMP. + Also, we're only passing *new* attributes here, but the AMP + should receive *all* attributes. */ - /* FIXME: We should look up the provider name instead of - taking it as an argument. Or at least check consistency. */ + struct TEH_KycMeasureRunContext *kat; + enum GNUNET_DB_QueryStatus qs; - kat = GNUNET_new (struct TEH_KycAmlTrigger); + kat = GNUNET_new (struct TEH_KycMeasureRunContext); kat->scope = *scope; kat->process_row = process_row; kat->account_id = *account_id; @@ -487,37 +512,8 @@ TEH_kyc_finished ( kat->provider_legitimization_id = GNUNET_strdup (provider_legitimization_id); kat->expiration = expiration; - kat->attributes = json_incref ((json_t*) attributes); kat->cb = cb; kat->cb_cls = cb_cls; - if (NULL == instant_ms) - { - qs = TEH_plugin->lookup_active_legitimization ( - TEH_plugin->cls, - process_row, - &kat->measure_index, - &kat->provider_name, - &kat->jmeasures); - switch (qs) - { - case GNUNET_DB_STATUS_HARD_ERROR: - case GNUNET_DB_STATUS_SOFT_ERROR: - GNUNET_break (0); - TEH_kyc_finished_cancel (kat); - return NULL; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break (0); - TEH_kyc_finished_cancel (kat); - return NULL; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - break; - } - } - /* We optionally pass in the provider name to double check with DB. */ - GNUNET_assert ( (NULL == provider_name) || (0 == strcasecmp (provider_name, - kat-> - provider_name)) ) - ; kat->aml_history = json_array (); kat->kyc_history = json_array (); qs = TEH_plugin->lookup_aml_history ( @@ -530,7 +526,7 @@ TEH_kyc_finished ( case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); return NULL; case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: /* empty history is fine! */ @@ -548,7 +544,7 @@ TEH_kyc_finished ( case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_break (0); - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); return NULL; case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: /* empty history is fine! */ @@ -556,84 +552,57 @@ TEH_kyc_finished ( case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; } - if (NULL == instant_ms) - { - kat->kyc_aml - = TALER_KYCLOGIC_run_aml_program ( - kat->attributes, - kat->aml_history, - kat->kyc_history, - kat->jmeasures, - kat->measure_index, - &kyc_aml_finished, - kat); - } - else - { - kat->kyc_aml - = TALER_KYCLOGIC_run_aml_program3 ( - instant_ms, - kat->attributes, - kat->aml_history, - kat->kyc_history, - &kyc_aml_finished, - kat); - } + + kat->kyc_aml + = TALER_KYCLOGIC_run_aml_program ( + kat->attributes, + kat->aml_history, + kat->kyc_history, + kat->jmeasures, + kat->measure_index, + &kyc_aml_finished, + kat); + if (NULL == kat->kyc_aml) { GNUNET_break (0); - TEH_kyc_finished_cancel (kat); + TEH_kyc_run_measure_cancel (kat); return NULL; } return kat; } -void -TEH_kyc_finished_cancel (struct TEH_KycAmlTrigger *kat) -{ - if (NULL != kat->kyc_aml) - { - TALER_KYCLOGIC_run_aml_program_cancel (kat->kyc_aml); - kat->kyc_aml = NULL; - } - if (NULL != kat->fb) - { - TEH_kyc_fallback_cancel (kat->fb); - kat->fb = NULL; - } - GNUNET_free (kat->provider_name); - GNUNET_free (kat->provider_user_id); - GNUNET_free (kat->provider_legitimization_id); - GNUNET_free (kat->fallback_name); - json_decref (kat->jmeasures); - json_decref (kat->attributes); - json_decref (kat->aml_history); - json_decref (kat->kyc_history); - GNUNET_free (kat); -} - - -struct TEH_KycAmlTrigger * +struct TEH_KycMeasureRunContext * TEH_kyc_run_measure_instant ( const struct GNUNET_AsyncScopeId *scope, const struct TALER_KYCLOGIC_Measure *instant_ms, const struct TALER_NormalizedPaytoHashP *account_id, - TEH_KycAmlTriggerCallback cb, + TEH_KycMeasureRunContextCallback cb, void *cb_cls) { + struct TEH_KycMeasureRunContext *kat; uint64_t process_row; uint64_t legi_measure_serial_id; bool bad_kyc_auth; enum GNUNET_DB_QueryStatus qs; - json_t *jmeasures; struct TALER_FullPayto null_account = { .full_payto = NULL }; - jmeasures = TALER_KYCLOGIC_measure_to_jmeasures (instant_ms); + kat = GNUNET_new (struct TEH_KycMeasureRunContext); - GNUNET_assert (NULL != jmeasures); + kat->jmeasures = TALER_KYCLOGIC_measure_to_jmeasures (instant_ms); + kat->provider_name = GNUNET_strdup ("SKIP"); + kat->measure_index = 0; + kat->scope = *scope; + kat->process_row = process_row; + kat->account_id = *account_id; + kat->expiration = GNUNET_TIME_UNIT_FOREVER_ABS; + kat->cb = cb; + kat->cb_cls = cb_cls; + + GNUNET_assert (NULL != kat->jmeasures); qs = TEH_plugin->trigger_kyc_rule_for_account ( TEH_plugin->cls, @@ -641,7 +610,7 @@ TEH_kyc_run_measure_instant ( account_id, NULL, NULL, - jmeasures, + kat->jmeasures, 0, /* no particular priority */ &legi_measure_serial_id, &bad_kyc_auth); @@ -676,19 +645,62 @@ TEH_kyc_run_measure_instant ( return NULL; } - return TEH_kyc_finished ( - scope, - process_row, - instant_ms, + /* FIXME(fdold, 2024-11-07): + We need to look up the attributes before running the AMP. */ + + kat->aml_history = json_array (); + kat->kyc_history = json_array (); + qs = TEH_plugin->lookup_aml_history ( + TEH_plugin->cls, account_id, - "SKIP", - NULL, - NULL, - GNUNET_TIME_UNIT_FOREVER_ABS, - NULL, - cb, - cb_cls - ); + &add_aml_history_entry, + kat->aml_history); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + TEH_kyc_run_measure_cancel (kat); + return NULL; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + /* empty history is fine! */ + break; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } + qs = TEH_plugin->lookup_kyc_history ( + TEH_plugin->cls, + account_id, + &add_kyc_history_entry, + kat->kyc_history); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + TEH_kyc_run_measure_cancel (kat); + return NULL; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + /* empty history is fine! */ + break; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } + kat->kyc_aml + = TALER_KYCLOGIC_run_aml_program3 ( + instant_ms, + kat->attributes, + kat->aml_history, + kat->kyc_history, + &kyc_aml_finished, + kat); + if (NULL == kat->kyc_aml) + { + GNUNET_break (0); + TEH_kyc_run_measure_cancel (kat); + return NULL; + } + return kat; } @@ -1013,7 +1025,7 @@ struct TEH_LegitimizationCheckHandle /** * Handle to asynchronously running instant measure. */ - struct TEH_KycAmlTrigger *kat; + struct TEH_KycMeasureRunContext *kat; /** * Payto-URI of the account. @@ -1928,7 +1940,7 @@ TEH_legitimization_check_cancel ( } if (NULL != lch->kat) { - TEH_kyc_finished_cancel (lch->kat); + TEH_kyc_run_measure_cancel (lch->kat); lch->kat = NULL; } if (NULL != lch->aprh) diff --git a/src/exchange/taler-exchange-httpd_common_kyc.h b/src/exchange/taler-exchange-httpd_common_kyc.h index ab07bcc38..b517d2838 100644 --- a/src/exchange/taler-exchange-httpd_common_kyc.h +++ b/src/exchange/taler-exchange-httpd_common_kyc.h @@ -30,29 +30,6 @@ #include "taler-exchange-httpd.h" -/* Proposed new definitions, for review. */ - -#if 0 -/** - * Run measure after storing attributes from the given - * provider. - * - * Only works when a process is active. - */ -struct TEH_KycAmlTrigger * -TEH_kyc_run_measure_for_attributes ( - const struct GNUNET_AsyncScopeId *scope, - uint64_t process_row, - const char *provider_user_id, - const char *provider_legitimization_id, - struct GNUNET_TIME_Absolute expiration, - const json_t *new_attributes, - TEH_KycAmlTriggerCallback cb, - void *cb_cls); - -#endif - - /** * Function called after the KYC-AML trigger is done. * @@ -61,7 +38,7 @@ TEH_kyc_run_measure_for_attributes ( * @param detail error message or NULL on success / no info */ typedef void -(*TEH_KycAmlTriggerCallback) ( +(*TEH_KycMeasureRunContextCallback) ( void *cls, enum TALER_ErrorCode ec, const char *detail); @@ -71,42 +48,38 @@ typedef void * Handle for an asynchronous operation to finish * a KYC process after running the AML trigger. */ -struct TEH_KycAmlTrigger; +struct TEH_KycMeasureRunContext; /** - * We have finished a KYC process and obtained new - * @a attributes for a given @a account_id. - * Check with the KYC-AML trigger to see if we need - * to initiate an AML process, and store the attributes - * in the database. Then call @a cb. + * Run measure after storing attributes from the given + * provider. + * + * Only works when a process is active. + * + * FIXME: Isn't the account_id redundant via the process_row? * * @param scope the HTTP request logging scope * @param process_row legitimization process the data provided is about - * @param instant_measure instant measure to run, used if @a process_row is 0, - * otherwise must be NULL - * @param account_id account the webhook was about - * @param provider_name name of the provider with the logic that was run + * @param account_id account the the data provided is about * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown * @param expiration until when is the KYC check valid - * @param attributes user attributes returned by the provider + * @param new_attributes user attributes returned by the provider * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle to cancel the operation */ -struct TEH_KycAmlTrigger * -TEH_kyc_finished ( +struct TEH_KycMeasureRunContext * +TEH_kyc_run_measure_for_attributes ( const struct GNUNET_AsyncScopeId *scope, uint64_t process_row, - const struct TALER_KYCLOGIC_Measure *instant_measure, const struct TALER_NormalizedPaytoHashP *account_id, - const char *provider_name, const char *provider_user_id, const char *provider_legitimization_id, struct GNUNET_TIME_Absolute expiration, - const json_t *attributes, - TEH_KycAmlTriggerCallback cb, + const json_t *new_attributes, + TEH_KycMeasureRunContextCallback cb, void *cb_cls); @@ -126,22 +99,22 @@ TEH_kyc_finished ( * @param cb_cls closure for @a cb * @return handle to cancel the operation */ -struct TEH_KycAmlTrigger * +struct TEH_KycMeasureRunContext * TEH_kyc_run_measure_instant ( const struct GNUNET_AsyncScopeId *scope, const struct TALER_KYCLOGIC_Measure *instant_ms, const struct TALER_NormalizedPaytoHashP *account_id, - TEH_KycAmlTriggerCallback cb, + TEH_KycMeasureRunContextCallback cb, void *cb_cls); /** - * Cancel KYC finish operation. + * Cancel running KYC measure. * * @param[in] kat operation to abort */ void -TEH_kyc_finished_cancel (struct TEH_KycAmlTrigger *kat); +TEH_kyc_run_measure_cancel (struct TEH_KycMeasureRunContext *kat); /** diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.c b/src/exchange/taler-exchange-httpd_kyc-proof.c index b6d91a8d1..2ff9a865b 100644 --- a/src/exchange/taler-exchange-httpd_kyc-proof.c +++ b/src/exchange/taler-exchange-httpd_kyc-proof.c @@ -72,7 +72,7 @@ struct KycProofContext /** * KYC AML trigger operation. */ - struct TEH_KycAmlTrigger *kat; + struct TEH_KycMeasureRunContext *kat; /** * Process information about the user for the plugin from the database, can @@ -328,12 +328,10 @@ proof_cb ( GNUNET_log (GNUNET_ERROR_TYPE_INFO, "KYC process #%llu succeeded with KYC provider\n", (unsigned long long) kpc->process_row); - kpc->kat = TEH_kyc_finished ( + kpc->kat = TEH_kyc_run_measure_for_attributes ( &rc->async_scope_id, kpc->process_row, - NULL, /* instant_measure */ &kpc->h_payto, - kpc->provider_name, provider_user_id, provider_legitimization_id, expiration, @@ -431,7 +429,7 @@ clean_kpc (struct TEH_RequestContext *rc) } if (NULL != kpc->kat) { - TEH_kyc_finished_cancel (kpc->kat); + TEH_kyc_run_measure_cancel (kpc->kat); kpc->kat = NULL; } if (NULL != kpc->response) diff --git a/src/exchange/taler-exchange-httpd_kyc-upload.c b/src/exchange/taler-exchange-httpd_kyc-upload.c index 4e0b0cd70..fa62c1bcf 100644 --- a/src/exchange/taler-exchange-httpd_kyc-upload.c +++ b/src/exchange/taler-exchange-httpd_kyc-upload.c @@ -86,7 +86,7 @@ struct UploadContext /** * Handle for async KYC processing. */ - struct TEH_KycAmlTrigger *kat; + struct TEH_KycMeasureRunContext *kat; /** * Uploaded data, in JSON. @@ -239,7 +239,7 @@ upload_cleaner (struct TEH_RequestContext *rc) if (NULL != uc->kat) { - TEH_kyc_finished_cancel (uc->kat); + TEH_kyc_run_measure_cancel (uc->kat); uc->kat = NULL; } if (NULL != uc->response) @@ -590,12 +590,10 @@ TEH_handler_kyc_upload ( "insert_kyc_requirement_process"); } - uc->kat = TEH_kyc_finished ( + uc->kat = TEH_kyc_run_measure_for_attributes ( &rc->async_scope_id, legi_process_row, - NULL, /* instant_measure */ &h_payto, - "FORM", NULL /* provider account */, NULL /* provider legi ID */, GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ diff --git a/src/exchange/taler-exchange-httpd_kyc-webhook.c b/src/exchange/taler-exchange-httpd_kyc-webhook.c index 605288ce7..2b265dbef 100644 --- a/src/exchange/taler-exchange-httpd_kyc-webhook.c +++ b/src/exchange/taler-exchange-httpd_kyc-webhook.c @@ -57,7 +57,7 @@ struct KycWebhookContext /** * Handle for the KYC-AML trigger interaction. */ - struct TEH_KycAmlTrigger *kat; + struct TEH_KycMeasureRunContext *kat; /** * Plugin responsible for the webhook. @@ -238,18 +238,17 @@ webhook_finished_cb ( switch (status) { case TALER_KYCLOGIC_STATUS_SUCCESS: - kwh->kat = TEH_kyc_finished ( + kwh->kat = TEH_kyc_run_measure_for_attributes ( &kwh->rc->async_scope_id, process_row, - NULL, /* instant_measure */ account_id, - provider_name, provider_user_id, provider_legitimization_id, expiration, attributes, &kyc_aml_webhook_finished, - kwh); + kwh + ); if (NULL == kwh->kat) { kyc_aml_webhook_finished (kwh, @@ -315,7 +314,7 @@ clean_kwh (struct TEH_RequestContext *rc) } if (NULL != kwh->kat) { - TEH_kyc_finished_cancel (kwh->kat); + TEH_kyc_run_measure_cancel (kwh->kat); kwh->kat = NULL; } if (NULL != kwh->response) |