diff options
author | Florian Dold <florian@dold.me> | 2024-11-05 19:39:47 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-11-05 19:39:50 +0100 |
commit | 0463167cb5ac96aec3a6d896099db83f9797e143 (patch) | |
tree | 51082f2393c2c7fef16c89ccbeaddd45714739c4 | |
parent | eb4a284cb5335010cba85c4d2b9ee09e85bb0580 (diff) |
use insert_kyc_measure_result, remove insert_programmatic_legitimization_outcome
-rw-r--r-- | src/exchange/taler-exchange-httpd_common_kyc.c | 122 | ||||
-rw-r--r-- | src/exchangedb/Makefile.am | 1 | ||||
-rw-r--r-- | src/exchangedb/exchange_do_insert_kyc_measure_result.sql | 3 | ||||
-rw-r--r-- | src/exchangedb/exchange_do_insert_programmatic_legitimization_outcome.sql | 178 | ||||
-rw-r--r-- | src/exchangedb/pg_insert_kyc_measure_result.c | 6 | ||||
-rw-r--r-- | src/exchangedb/pg_insert_programmatic_legitimization_outcome.c | 92 | ||||
-rw-r--r-- | src/exchangedb/pg_insert_programmatic_legitimization_outcome.h | 55 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 3 | ||||
-rw-r--r-- | src/exchangedb/procedures.sql.in | 1 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 27 |
10 files changed, 71 insertions, 417 deletions
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.c b/src/exchange/taler-exchange-httpd_common_kyc.c index 4e63aed68..8023c096d 100644 --- a/src/exchange/taler-exchange-httpd_common_kyc.c +++ b/src/exchange/taler-exchange-httpd_common_kyc.c @@ -1333,16 +1333,24 @@ legi_check_aml_program_cb ( expiration_time = TALER_KYCLOGIC_rules_get_expiration (lrs); TALER_KYCLOGIC_rules_free (lrs); - qs = TEH_plugin->insert_programmatic_legitimization_outcome ( + qs = TEH_plugin->insert_kyc_measure_result ( TEH_plugin->cls, + lch->lcr.kyc.requirement_row, &lch->h_payto, - GNUNET_TIME_timestamp_get (), + 0, /* birthday */ + GNUNET_TIME_timestamp_get (), /* decision time */ + "SKIP", + NULL, + NULL, expiration_time.abs_time, apr->details.success.account_properties, - apr->details.success.to_investigate, apr->details.success.new_rules, + apr->details.success.to_investigate, apr->details.success.num_events, - apr->details.success.events); + apr->details.success.events, + 0, /* enc attr size */ + NULL /* enc attrs*/ + ); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -1388,14 +1396,66 @@ run_check ( struct TEH_LegitimizationCheckHandle *lch, const struct TALER_KYCLOGIC_KycCheckContext *kcc) { + enum GNUNET_DB_QueryStatus qs; json_t *jmeasures; jmeasures = TALER_KYCLOGIC_check_to_measures (kcc); + + /* require kcc.check! */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Requiring KYC for `%s'\n", + lch->payto_uri.full_payto); +#if EXTRA_CHECK + { + struct TALER_NormalizedPaytoHashP npt; + + TALER_full_payto_normalize_and_hash (lch->payto_uri, + &npt); + GNUNET_assert (0 == + GNUNET_memcmp (&npt, + &lch->h_payto)); + } +#endif + qs = TEH_plugin->trigger_kyc_rule_for_account ( + TEH_plugin->cls, + lch->payto_uri, + &lch->h_payto, + lch->have_account_pub ? &lch->account_pub : NULL, + lch->have_merchant_pub ? &lch->merchant_pub : NULL, + jmeasures, + 0, /* no particular priority */ + &lch->lcr.kyc.requirement_row, + &lch->lcr.bad_kyc_auth); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + legi_fail (lch, + TALER_EC_GENERIC_DB_STORE_FAILED, + "trigger_kyc_rule_for_account"); + goto cleanup; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_break (0); + legi_fail (lch, + TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, + "trigger_kyc_rule_for_account"); + goto cleanup; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "trigger_kyc_rule_for_account-2 on %d/%d returned %d/%llu/%d\n", + lch->have_account_pub, + lch->have_merchant_pub, + (int) qs, + (unsigned long long) lch->lcr.kyc.requirement_row, + lch->lcr.bad_kyc_auth); + if (NULL == kcc->check) { /* check was skip; directly run AML program */ - enum GNUNET_DB_QueryStatus qs; json_t *attributes; json_t *aml_history; json_t *kyc_history; @@ -1475,58 +1535,6 @@ run_check ( } else { - enum GNUNET_DB_QueryStatus qs; - - /* require kcc.check! */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Requiring KYC for `%s'\n", - lch->payto_uri.full_payto); -#if EXTRA_CHECK - { - struct TALER_NormalizedPaytoHashP npt; - - TALER_full_payto_normalize_and_hash (lch->payto_uri, - &npt); - GNUNET_assert (0 == - GNUNET_memcmp (&npt, - &lch->h_payto)); - } -#endif - qs = TEH_plugin->trigger_kyc_rule_for_account ( - TEH_plugin->cls, - lch->payto_uri, - &lch->h_payto, - lch->have_account_pub ? &lch->account_pub : NULL, - lch->have_merchant_pub ? &lch->merchant_pub : NULL, - jmeasures, - 0, /* no particular priority */ - &lch->lcr.kyc.requirement_row, - &lch->lcr.bad_kyc_auth); - switch (qs) - { - case GNUNET_DB_STATUS_HARD_ERROR: - case GNUNET_DB_STATUS_SOFT_ERROR: - GNUNET_break (0); - legi_fail (lch, - TALER_EC_GENERIC_DB_STORE_FAILED, - "trigger_kyc_rule_for_account"); - goto cleanup; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break (0); - legi_fail (lch, - TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, - "trigger_kyc_rule_for_account"); - goto cleanup; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - break; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "trigger_kyc_rule_for_account-2 on %d/%d returned %d/%llu/%d\n", - lch->have_account_pub, - lch->have_merchant_pub, - (int) qs, - (unsigned long long) lch->lcr.kyc.requirement_row, - lch->lcr.bad_kyc_auth); /* return success! */ lch->async_task = GNUNET_SCHEDULER_add_now ( diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index e517ac1b9..f34573724 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -145,7 +145,6 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \ pg_insert_drain_profit.h pg_insert_drain_profit.c \ pg_insert_kyc_failure.h pg_insert_kyc_failure.c \ pg_inject_auditor_triggers.h pg_inject_auditor_triggers.c \ - pg_insert_programmatic_legitimization_outcome.h pg_insert_programmatic_legitimization_outcome.c \ pg_create_tables.h pg_create_tables.c \ pg_event_listen.h pg_event_listen.c \ pg_event_listen_cancel.h pg_event_listen_cancel.c \ diff --git a/src/exchangedb/exchange_do_insert_kyc_measure_result.sql b/src/exchangedb/exchange_do_insert_kyc_measure_result.sql index 228e7926f..04679742d 100644 --- a/src/exchangedb/exchange_do_insert_kyc_measure_result.sql +++ b/src/exchangedb/exchange_do_insert_kyc_measure_result.sql @@ -68,7 +68,8 @@ RETURNING INTO my_trigger_outcome_serial; -IF in_process_row IS NOT NULL +IF (in_process_row IS NOT NULL) AND + (encrypted_attributes IS NOT NULL) THEN INSERT INTO kyc_attributes (h_payto diff --git a/src/exchangedb/exchange_do_insert_programmatic_legitimization_outcome.sql b/src/exchangedb/exchange_do_insert_programmatic_legitimization_outcome.sql deleted file mode 100644 index 146556402..000000000 --- a/src/exchangedb/exchange_do_insert_programmatic_legitimization_outcome.sql +++ /dev/null @@ -1,178 +0,0 @@ --- --- This file is part of TALER --- Copyright (C) 2023, 2024 Taler Systems SA --- --- TALER is free software; you can redistribute it and/or modify it under the --- terms of the GNU General Public License as published by the Free Software --- Foundation; either version 3, or (at your option) any later version. --- --- TALER is distributed in the hope that it will be useful, but WITHOUT ANY --- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR --- A PARTICULAR PURPOSE. See the GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License along with --- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> --- - -DROP FUNCTION IF EXISTS exchange_do_insert_programmatic_legitimization_outcome; -CREATE OR REPLACE FUNCTION exchange_do_insert_programmatic_legitimization_outcome( - IN in_h_normalized_payto BYTEA, - IN in_decision_time INT8, - IN in_expiration_time INT8, - IN in_properties TEXT, - IN in_new_rules TEXT, - IN in_to_investigate BOOLEAN, - IN ina_events TEXT[], - IN in_notify_s TEXT, - OUT out_account_unknown BOOLEAN) -LANGUAGE plpgsql -AS $$ -DECLARE - my_outcome_serial_id INT8; - my_access_token BYTEA; - my_max_dp INT4; - my_i INT4; - ini_event TEXT; -BEGIN - -out_account_unknown=FALSE; - --- Note: in_payto_uri is allowed to be NULL *if* --- in_h_normalized_payto is already in wire_targets -SELECT access_token - INTO my_access_token - FROM wire_targets - WHERE h_normalized_payto=in_h_normalized_payto; - --- Very strange, should never happen that we --- take an AML decision on an unknown account! -IF NOT FOUND -THEN - RAISE NOTICE 'failed to find account for which AML decision was to be taken (bug)'; - out_account_unknown=TRUE; - RETURN; -END IF; -out_account_unknown=FALSE; - --- Did KYC measures get prescribed? -IF in_jmeasures IS NULL -THEN - -- AML decision without measure: mark all - -- active measures finished! - UPDATE legitimization_measures - SET is_finished=TRUE - WHERE access_token=my_access_token - AND NOT is_finished; -ELSE - -- Find current maximum DP - SELECT COALESCE(MAX(display_priority),0) - INTO my_max_dp - FROM legitimization_measures - WHERE access_token=my_access_token - AND NOT is_finished; - - -- First check if a perfectly equivalent legi measure - -- already exists, to avoid creating tons of duplicates. - UPDATE legitimization_measures - SET display_priority=GREATEST(my_max_dp,display_priority) - WHERE access_token=my_access_token - AND jmeasures=in_jmeasures - AND NOT is_finished; - - IF NOT FOUND - THEN - -- Enable new legitimization measure - INSERT INTO legitimization_measures - (access_token - ,start_time - ,jmeasures - ,display_priority) - VALUES - (my_access_token - ,in_decision_time - ,in_jmeasures - ,my_max_dp + 1); - END IF; - - -- end if for where we had non-NULL in_jmeasures -END IF; - -UPDATE legitimization_outcomes - SET is_active=FALSE - WHERE h_payto=in_h_normalized_payto - -- this clause is a minor optimization to avoid - -- updating outcomes that have long expired. - AND expiration_time >= in_decision_time; - -INSERT INTO legitimization_outcomes - (h_payto - ,decision_time - ,expiration_time - ,jproperties - ,new_measure_name - ,to_investigate - ,jnew_rules - ) - VALUES - (in_h_normalized_payto - ,in_decision_time - ,in_expiration_time - ,in_properties - ,in_new_measure_name - ,in_to_investigate - ,in_new_rules - ) - RETURNING - outcome_serial_id - INTO - my_outcome_serial_id; - --- FIXME: do we want/need programmatic --- decisions in the AML history? We --- have no justification or decider, --- so IF we would need to change the table --- significantly, which may break other things... - ---INSERT INTO aml_history --- (h_payto --- ,outcome_serial_id --- ,justification --- ,decider_pub --- ,decider_sig --- ) VALUES --- (in_h_normalized_payto --- ,my_outcome_serial_id --- ,in_justification --- ,in_decider_pub --- ,in_decider_sig --- ); - --- wake up taler-exchange-aggregator -INSERT INTO kyc_alerts - (h_payto - ,trigger_type) - VALUES - (in_h_normalized_payto,1) - ON CONFLICT DO NOTHING; - - -FOR i IN 1..COALESCE(array_length(ina_events,1),0) -LOOP - ini_event = ina_events[i]; - INSERT INTO kyc_events - (event_timestamp - ,event_type) - VALUES - (in_collection_time_ts - ,ini_event); -END LOOP; - -EXECUTE FORMAT ( - 'NOTIFY %s' - ,in_notify_s); - -END $$; - - -COMMENT ON FUNCTION exchange_do_insert_programmatic_legitimization_outcome(BYTEA, INT8, INT8, TEXT, TEXT, BOOLEAN, TEXT[], TEXT) - IS 'Inserts an AML decision that was taken automatically by an AML program into the database'; diff --git a/src/exchangedb/pg_insert_kyc_measure_result.c b/src/exchangedb/pg_insert_kyc_measure_result.c index 11a9ff1f1..1ddf1f6d4 100644 --- a/src/exchangedb/pg_insert_kyc_measure_result.c +++ b/src/exchangedb/pg_insert_kyc_measure_result.c @@ -78,8 +78,10 @@ TEH_PG_insert_kyc_measure_result ( GNUNET_PQ_query_param_array_ptrs_string (num_events, events, pg->conn), - GNUNET_PQ_query_param_fixed_size (enc_attributes, - enc_attributes_size), + (NULL == enc_attributes) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_fixed_size (enc_attributes, + enc_attributes_size), GNUNET_PQ_query_param_bool (to_investigate), GNUNET_PQ_query_param_string (kyc_completed_notify_s), GNUNET_PQ_query_param_end diff --git a/src/exchangedb/pg_insert_programmatic_legitimization_outcome.c b/src/exchangedb/pg_insert_programmatic_legitimization_outcome.c deleted file mode 100644 index 289a888cf..000000000 --- a/src/exchangedb/pg_insert_programmatic_legitimization_outcome.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_insert_programmatic_legitimization_outcome.c - * @brief Implementation of the insert_programmatic_legitimization_outcome function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_insert_programmatic_legitimization_outcome.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_insert_programmatic_legitimization_outcome ( - void *cls, - const struct TALER_NormalizedPaytoHashP *h_payto, - struct GNUNET_TIME_Timestamp decision_time, - struct GNUNET_TIME_Absolute expiration_time, - const json_t *account_properties, - bool to_investigate, - const json_t *new_rules, - unsigned int num_events, - const char **events) -{ - struct PostgresClosure *pg = cls; - struct TALER_KycCompletedEventP rep = { - .header.size = htons (sizeof (rep)), - .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED), - .h_payto = *h_payto - }; - - char *notify_s - = GNUNET_PQ_get_event_notify_channel (&rep.header); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_payto), - GNUNET_PQ_query_param_timestamp (&decision_time), - GNUNET_PQ_query_param_absolute_time (&expiration_time), - NULL != account_properties - ? TALER_PQ_query_param_json (account_properties) - : GNUNET_PQ_query_param_null (), - TALER_PQ_query_param_json (new_rules), - GNUNET_PQ_query_param_bool (to_investigate), - GNUNET_PQ_query_param_array_ptrs_string (num_events, - events, - pg->conn), - GNUNET_PQ_query_param_string (notify_s), - GNUNET_PQ_query_param_end - }; - bool unknown_account; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("out_account_unknown", - &unknown_account), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "do_insert_programmatic_legitimization_outcome", - "SELECT" - " out_account_unknown" - " FROM exchange_do_insert_programmatic_legitimization_decision" - "($1, $2, $3, $4, $5, $6, $7, $8);"); - qs = GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "do_insert_programmatic_legitimization_outcome", - params, - rs); - GNUNET_PQ_cleanup_query_params_closures (params); - GNUNET_free (notify_s); - GNUNET_PQ_event_do_poll (pg->conn); - if (qs <= 0) - return qs; - if (unknown_account) - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - return qs; -} diff --git a/src/exchangedb/pg_insert_programmatic_legitimization_outcome.h b/src/exchangedb/pg_insert_programmatic_legitimization_outcome.h deleted file mode 100644 index 4d6cd480c..000000000 --- a/src/exchangedb/pg_insert_programmatic_legitimization_outcome.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_insert_programmatic_legitimization_outcome.h - * @brief implementation of the insert_programmatic_legitimization_outcome function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_INSERT_PROGRAMMATIC_LEGITIMIZATION_OUTCOME_H -#define PG_INSERT_PROGRAMMATIC_LEGITIMIZATION_OUTCOME_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_exchangedb_plugin.h" - - -/** - * Store automated legitimization outcome. - * - * @param cls closure - * @param h_payto account for which the attribute data is stored - * @param decision_time when was the decision taken - * @param expiration_time when does the data expire - * @param account_properties new account properties - * @param to_investigate true to flag account for investigation - * @param new_rules new KYC rules to apply to the account - * @param num_events length of the @a events array - * @param events array of KYC events to trigger - * @return database transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_insert_programmatic_legitimization_outcome ( - void *cls, - const struct TALER_NormalizedPaytoHashP *h_payto, - struct GNUNET_TIME_Timestamp decision_time, - struct GNUNET_TIME_Absolute expiration_time, - const json_t *account_properties, - bool to_investigate, - const json_t *new_rules, - unsigned int num_events, - const char **events); - -#endif diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 6118cec01..4648520f5 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -49,7 +49,6 @@ #include "pg_get_unfinished_close_requests.h" #include "pg_insert_close_request.h" #include "pg_insert_records_by_table.h" -#include "pg_insert_programmatic_legitimization_outcome.h" #include "pg_insert_reserve_open_deposit.h" #include "pg_get_pending_kyc_requirement_process.h" #include "pg_iterate_kyc_reference.h" @@ -785,8 +784,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_abort_shard; plugin->insert_kyc_failure = &TEH_PG_insert_kyc_failure; - plugin->insert_programmatic_legitimization_outcome - = &TEH_PG_insert_programmatic_legitimization_outcome; plugin->complete_shard = &TEH_PG_complete_shard; plugin->release_revolving_shard diff --git a/src/exchangedb/procedures.sql.in b/src/exchangedb/procedures.sql.in index 683a9320c..9adb1ef3b 100644 --- a/src/exchangedb/procedures.sql.in +++ b/src/exchangedb/procedures.sql.in @@ -53,7 +53,6 @@ SET search_path TO exchange; #include "exchange_do_kycauth_in_insert.sql" #include "exchange_do_trigger_kyc_rule_for_account.sql" #include "exchange_do_lookup_kyc_requirement_by_row.sql" -#include "exchange_do_insert_programmatic_legitimization_outcome.sql" #include "exchange_do_insert_active_legitimization_measure.sql" #include "exchange_do_select_aggregations_above_serial.sql" diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index e3f447c38..39d971f09 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -7248,33 +7248,6 @@ struct TALER_EXCHANGEDB_Plugin /** - * Store automated legitimization outcome. - * - * @param cls closure - * @param h_payto account for which the attribute data is stored - * @param decision_time when was the decision taken - * @param expiration_time when does the data expire - * @param account_properties new account properties - * @param to_investigate true to flag account for investigation - * @param new_rules new KYC rules to apply to the account - * @param num_events length of the @a events array - * @param events array of KYC events to trigger - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*insert_programmatic_legitimization_outcome)( - void *cls, - const struct TALER_NormalizedPaytoHashP *h_payto, - struct GNUNET_TIME_Timestamp decision_time, - struct GNUNET_TIME_Absolute expiration_time, - const json_t *account_properties, - bool to_investigate, - const json_t *new_rules, - unsigned int num_events, - const char **events); - - - /** * Store KYC attribute data, update KYC process status and * AML status for the given account. * |