aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-11-07 22:09:58 +0100
committerFlorian Dold <florian@dold.me>2024-11-07 22:09:58 +0100
commitd70efe619e1c2ba0b02d6af41aea9cd8455ab0ee (patch)
tree61d6a51fe7b0d3e97517a781b57f7a553dece046
parentf10bc444579a5af215a8ac38c5d0e627786e423e (diff)
introduce TEH_kyc_run_measure_instant
-rw-r--r--src/exchange/taler-exchange-httpd_aml-decision.c47
-rw-r--r--src/exchange/taler-exchange-httpd_common_kyc.c84
-rw-r--r--src/exchange/taler-exchange-httpd_common_kyc.h66
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-proof.c1
-rw-r--r--src/include/taler_kyclogic_lib.h11
-rw-r--r--src/kyclogic/kyclogic_api.c30
6 files changed, 157 insertions, 82 deletions
diff --git a/src/exchange/taler-exchange-httpd_aml-decision.c b/src/exchange/taler-exchange-httpd_aml-decision.c
index e73302dea..04f5defcd 100644
--- a/src/exchange/taler-exchange-httpd_aml-decision.c
+++ b/src/exchange/taler-exchange-httpd_aml-decision.c
@@ -399,7 +399,6 @@ TEH_handler_post_aml_decision (
/* Run instant measure if necessary */
{
const struct TALER_KYCLOGIC_Measure *instant_ms = NULL;
- enum GNUNET_DB_QueryStatus qs;
if (NULL != new_measures)
{
@@ -411,49 +410,16 @@ TEH_handler_post_aml_decision (
/* We have an 'instant' measure which means we must run the
AML program immediately instead of waiting for the account owner
to select some measure and contribute their KYC data. */
- json_t *attributes
- = json_object (); /* instant: empty attributes */
- uint64_t process_row;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Running instant measure after AML decision\n");
-
- GNUNET_assert (NULL != attributes);
-
- qs = TEH_plugin->insert_kyc_requirement_process (
- TEH_plugin->cls,
+ adc->kat = TEH_kyc_run_measure_instant (
+ &rc->async_scope_id,
+ instant_ms,
&h_payto,
- 0, /* measure index */
- legi_measure_serial_id,
- "SKIP",
- NULL, /* provider_account_id */
- NULL, /* provider_legitimziation_id */
- &process_row);
- if (qs < 0)
- {
- GNUNET_break (0);
- ret = TALER_MHD_reply_with_error (
- rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "insert_kyc_requirement_process");
- goto done;
- }
- /* FIXME: Insert start time of KYC process' AML program */
- adc->kat
- = TEH_kyc_finished (
- &rc->async_scope_id,
- process_row,
- instant_ms,
- &h_payto,
- "SKIP", /* provider */
- NULL,
- NULL,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- attributes,
- &aml_trigger_callback,
- adc);
- json_decref (attributes);
+ &aml_trigger_callback,
+ adc
+ );
if (NULL == adc->kat)
{
GNUNET_break (0);
@@ -464,7 +430,6 @@ TEH_handler_post_aml_decision (
"TEH_kyc_finished");
goto done;
}
-
MHD_suspend_connection (adc->rc->connection);
GNUNET_CONTAINER_DLL_insert (adc_head,
adc_tail,
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.c b/src/exchange/taler-exchange-httpd_common_kyc.c
index 7546c3fb7..f0545e503 100644
--- a/src/exchange/taler-exchange-httpd_common_kyc.c
+++ b/src/exchange/taler-exchange-httpd_common_kyc.c
@@ -473,6 +473,9 @@ TEH_kyc_finished (
struct TEH_KycAmlTrigger *kat;
enum GNUNET_DB_QueryStatus qs;
+ /* FIXME: We should look up the provider name instead of
+ taking it as an argument. Or at least check consistency. */
+
kat = GNUNET_new (struct TEH_KycAmlTrigger);
kat->scope = *scope;
kat->process_row = process_row;
@@ -607,6 +610,84 @@ TEH_kyc_finished_cancel (struct TEH_KycAmlTrigger *kat)
}
+struct TEH_KycAmlTrigger *
+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,
+ void *cb_cls)
+{
+ 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);
+
+ GNUNET_assert (NULL != jmeasures);
+
+ qs = TEH_plugin->trigger_kyc_rule_for_account (
+ TEH_plugin->cls,
+ null_account,
+ account_id,
+ NULL,
+ NULL,
+ jmeasures,
+ 0, /* no particular priority */
+ &legi_measure_serial_id,
+ &bad_kyc_auth);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return NULL;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0);
+ return NULL;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+
+ /* We're not checking kyc auth, so it can't be bad. */
+ GNUNET_assert (! bad_kyc_auth);
+
+ qs = TEH_plugin->insert_kyc_requirement_process (
+ TEH_plugin->cls,
+ account_id,
+ 0, /* measure index */
+ legi_measure_serial_id,
+ "SKIP",
+ NULL, /* provider_account_id */
+ NULL, /* provider_legitimziation_id */
+ &process_row);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+
+ return TEH_kyc_finished (
+ scope,
+ 0, /* FIXME: Start process! */
+ instant_ms,
+ account_id,
+ "SKIP",
+ NULL,
+ NULL,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ NULL,
+ cb,
+ cb_cls
+ );
+}
+
+
struct TEH_KycAmlFallback
{
@@ -689,7 +770,7 @@ handle_aml_fallback_result (
apr->details.failure.error_message,
apr->details.failure.ec))
{
- /* tripple-bad: error during error handling of fallback */
+ /* triple-bad: error during error handling of fallback */
GNUNET_break (0);
fb->cb (fb->cb_cls,
false,
@@ -1700,6 +1781,7 @@ legitimization_check_run (
}
else
{
+ /* FIXME: Replace by call to TEH_kyc_run_measure_instant. */
run_check (lch,
&kcc);
goto cleanup;
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.h b/src/exchange/taler-exchange-httpd_common_kyc.h
index fb2ee1306..ab07bcc38 100644
--- a/src/exchange/taler-exchange-httpd_common_kyc.h
+++ b/src/exchange/taler-exchange-httpd_common_kyc.h
@@ -34,31 +34,12 @@
#if 0
/**
- * Function called after finishing running a measure.
- *
- * @param cls closure
- * @param ec error code, 0 on success
- * @param msg error message, NULL on success
- */
-typedef void
-(*TEH_AmlMeasureRunCallback) (
- void *cls,
- enum TALER_ErrorCode ec,
- const char *msg);
-
-/**
- * Handle for an asynchronous operation to finish
- * a KYC process after running the AML trigger.
- */
-struct TEH_AmlMeasureRunContext;
-
-/**
* Run measure after storing attributes from the given
* provider.
*
* Only works when a process is active.
*/
-struct TEH_AmlMeasureRunContext *
+struct TEH_KycAmlTrigger *
TEH_kyc_run_measure_for_attributes (
const struct GNUNET_AsyncScopeId *scope,
uint64_t process_row,
@@ -66,25 +47,7 @@ TEH_kyc_run_measure_for_attributes (
const char *provider_legitimization_id,
struct GNUNET_TIME_Absolute expiration,
const json_t *new_attributes,
- TEH_AmlMeasureRunCallback cb,
- void *cb_cls);
-
-
-/**
- * Run an instant measure.
- *
- * Inserts a legitimization process and measure
- * into the database before running the measure program.
- *
- * After running the measure program, the result is stored
- * in the DB.
- */
-struct TEH_AmlMeasureRunContext *
-TEH_kyc_run_measure_instant (
- const struct GNUNET_AsyncScopeId *scope,
- const struct TALER_KYCLOGIC_Measure *instant_ms,
- const struct TALER_NormalizedPaytoHashP *account_id,
- TEH_AmlMeasureRunCallback cb,
+ TEH_KycAmlTriggerCallback cb,
void *cb_cls);
#endif
@@ -148,6 +111,31 @@ TEH_kyc_finished (
/**
+ * Run an instant measure.
+ *
+ * Inserts a legitimization process and measure
+ * into the database before running the measure program.
+ *
+ * After running the measure program, the result is stored
+ * in the DB.
+ *
+ * @param scope the HTTP request logging scope
+ * @param instant_measure instant measure to run
+ * @param account_id account affected by the measure
+ * @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_run_measure_instant (
+ const struct GNUNET_AsyncScopeId *scope,
+ const struct TALER_KYCLOGIC_Measure *instant_ms,
+ const struct TALER_NormalizedPaytoHashP *account_id,
+ TEH_KycAmlTriggerCallback cb,
+ void *cb_cls);
+
+
+/**
* Cancel KYC finish operation.
*
* @param[in] kat operation to abort
diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.c b/src/exchange/taler-exchange-httpd_kyc-proof.c
index c3e38e3df..b6d91a8d1 100644
--- a/src/exchange/taler-exchange-httpd_kyc-proof.c
+++ b/src/exchange/taler-exchange-httpd_kyc-proof.c
@@ -366,7 +366,6 @@ proof_cb (
GNUNET_asprintf (&msg,
"Failure by KYC provider (HTTP status %u)\n",
http_status);
- http_status = MHD_HTTP_BAD_GATEWAY;
proof_finish (
kpc,
TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
diff --git a/src/include/taler_kyclogic_lib.h b/src/include/taler_kyclogic_lib.h
index 098b9c7fe..f25295b99 100644
--- a/src/include/taler_kyclogic_lib.h
+++ b/src/include/taler_kyclogic_lib.h
@@ -788,6 +788,17 @@ TALER_KYCLOGIC_get_instant_measure (
/**
+ * Convert a measure to JSON.
+ *
+ * @param m measure to convert to JSON
+ * @returns JSON representation of the measure
+ */
+json_t *
+TALER_KYCLOGIC_measure_to_jmeasures (
+ const struct TALER_KYCLOGIC_Measure *m);
+
+
+/**
* Handle to manage a running AML program.
*/
struct TALER_KYCLOGIC_AmlProgramRunnerHandle;
diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c
index 06797bc7a..2c706f0ee 100644
--- a/src/kyclogic/kyclogic_api.c
+++ b/src/kyclogic/kyclogic_api.c
@@ -1336,6 +1336,36 @@ TALER_KYCLOGIC_check_to_measures (
}
+json_t *
+TALER_KYCLOGIC_measure_to_jmeasures (
+ const struct TALER_KYCLOGIC_Measure *m)
+{
+ json_t *jmeasures;
+ json_t *mi;
+
+ mi = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("check_name",
+ m->check_name),
+ GNUNET_JSON_pack_string ("prog_name",
+ m->prog_name),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("context",
+ (json_t *) m->context)));
+ jmeasures = json_array ();
+ GNUNET_assert (NULL != jmeasures);
+ GNUNET_assert (0 ==
+ json_array_append_new (jmeasures,
+ mi));
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("measures",
+ jmeasures),
+ GNUNET_JSON_pack_bool ("is_and_combinator",
+ true),
+ GNUNET_JSON_pack_bool ("verboten",
+ false));
+}
+
+
uint32_t
TALER_KYCLOGIC_rule2priority (
const struct TALER_KYCLOGIC_KycRule *r)