summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_kyc_check.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/exchange_api_kyc_check.c')
-rw-r--r--src/lib/exchange_api_kyc_check.c122
1 files changed, 73 insertions, 49 deletions
diff --git a/src/lib/exchange_api_kyc_check.c b/src/lib/exchange_api_kyc_check.c
index f64dfe4ea..5d3b3792b 100644
--- a/src/lib/exchange_api_kyc_check.c
+++ b/src/lib/exchange_api_kyc_check.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 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
@@ -37,14 +37,14 @@ struct TALER_EXCHANGE_KycCheckHandle
{
/**
- * The connection to exchange this request handle will use
+ * The url for this request.
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ char *url;
/**
- * The url for this request.
+ * Keys of the exchange.
*/
- char *url;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* Handle for the request.
@@ -64,7 +64,8 @@ struct TALER_EXCHANGE_KycCheckHandle
/**
* Hash of the payto:// URL that is being KYC'ed.
*/
- struct TALER_PaytoHash h_payto;
+ struct TALER_PaytoHashP h_payto;
+
};
@@ -95,22 +96,20 @@ handle_kyc_check_finished (void *cls,
break;
case MHD_HTTP_OK:
{
+ const json_t *kyc_details;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &ks.details.kyc_ok.exchange_sig),
+ &ks.details.ok.exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &ks.details.kyc_ok.exchange_pub),
- TALER_JSON_spec_absolute_time ("now",
- &ks.details.kyc_ok.timestamp),
+ &ks.details.ok.exchange_pub),
+ GNUNET_JSON_spec_timestamp ("now",
+ &ks.details.ok.timestamp),
+ GNUNET_JSON_spec_object_const ("kyc_details",
+ &kyc_details),
+ TALER_JSON_spec_aml_decision ("aml_status",
+ &ks.details.ok.aml_status),
GNUNET_JSON_spec_end ()
};
- const struct TALER_EXCHANGE_Keys *key_state;
- struct TALER_ExchangeAccountSetupSuccessPS kyc_purpose = {
- .purpose.size = htonl (sizeof (kyc_purpose)),
- .purpose.purpose = htonl (
- TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
- .h_payto = kch->h_payto
- };
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
@@ -122,12 +121,10 @@ handle_kyc_check_finished (void *cls,
ks.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- kyc_purpose.timestamp = GNUNET_TIME_absolute_hton (
- ks.details.kyc_ok.timestamp);
- key_state = TALER_EXCHANGE_get_keys (kch->exchange);
+ ks.details.ok.kyc_details = kyc_details;
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
- &ks.details.kyc_ok.exchange_pub))
+ TALER_EXCHANGE_test_signing_key (kch->keys,
+ &ks.details.ok.exchange_pub))
{
GNUNET_break_op (0);
ks.http_status = 0;
@@ -137,11 +134,12 @@ handle_kyc_check_finished (void *cls,
}
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (
- TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS,
- &kyc_purpose,
- &ks.details.kyc_ok.exchange_sig.eddsa_signature,
- &ks.details.kyc_ok.exchange_pub.eddsa_pub))
+ TALER_exchange_online_account_setup_success_verify (
+ &kch->h_payto,
+ ks.details.ok.kyc_details,
+ ks.details.ok.timestamp,
+ &ks.details.ok.exchange_pub,
+ &ks.details.ok.exchange_sig))
{
GNUNET_break_op (0);
ks.http_status = 0;
@@ -158,8 +156,10 @@ handle_kyc_check_finished (void *cls,
case MHD_HTTP_ACCEPTED:
{
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("kyc_url",
- &ks.details.kyc_url),
+ TALER_JSON_spec_web_url ("kyc_url",
+ &ks.details.accepted.kyc_url),
+ TALER_JSON_spec_aml_decision ("aml_status",
+ &ks.details.accepted.aml_status),
GNUNET_JSON_spec_end ()
};
@@ -186,12 +186,37 @@ handle_kyc_check_finished (void *cls,
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
break;
- case MHD_HTTP_UNAUTHORIZED:
+ case MHD_HTTP_FORBIDDEN:
ks.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_NOT_FOUND:
ks.ec = TALER_JSON_get_error_code (j);
break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_aml_decision (
+ "aml_status",
+ &ks.details.unavailable_for_legal_reasons.aml_status),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ ks.http_status = 0;
+ ks.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ }
+ kch->cb (kch->cb_cls,
+ &ks);
+ GNUNET_JSON_parse_free (spec);
+ TALER_EXCHANGE_kyc_check_cancel (kch);
+ return;
+ }
case MHD_HTTP_INTERNAL_SERVER_ERROR:
ks.ec = TALER_JSON_get_error_code (j);
/* Server had an internal issue; we should retry, but this API
@@ -214,24 +239,21 @@ handle_kyc_check_finished (void *cls,
struct TALER_EXCHANGE_KycCheckHandle *
-TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
- uint64_t payment_target,
- const struct TALER_PaytoHash *h_payto,
- struct GNUNET_TIME_Relative timeout,
- TALER_EXCHANGE_KycStatusCallback cb,
- void *cb_cls)
+TALER_EXCHANGE_kyc_check (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ uint64_t requirement_row,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_KYCLOGIC_KycUserType ut,
+ struct GNUNET_TIME_Relative timeout,
+ TALER_EXCHANGE_KycStatusCallback cb,
+ void *cb_cls)
{
struct TALER_EXCHANGE_KycCheckHandle *kch;
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
char *arg_str;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
{
char payto_str[sizeof (*h_payto) * 2];
char *end;
@@ -246,18 +268,19 @@ TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
timeout_ms = timeout.rel_value_us
/ GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
GNUNET_asprintf (&arg_str,
- "/kyc-check/%llu?h_payto=%s&timeout_ms=%llu",
- (unsigned long long) payment_target,
+ "kyc-check/%llu/%s/%s?timeout_ms=%llu",
+ (unsigned long long) requirement_row,
payto_str,
+ TALER_KYCLOGIC_kyc_user_type2s (ut),
timeout_ms);
}
kch = GNUNET_new (struct TALER_EXCHANGE_KycCheckHandle);
- kch->exchange = exchange;
kch->h_payto = *h_payto;
kch->cb = cb;
kch->cb_cls = cb_cls;
- kch->url = TEAH_path_to_url (exchange,
- arg_str);
+ kch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
GNUNET_free (arg_str);
if (NULL == kch->url)
{
@@ -272,7 +295,7 @@ TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_free (kch);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
+ kch->keys = TALER_EXCHANGE_keys_incref (keys);
kch->job = GNUNET_CURL_job_add_with_ct_json (ctx,
eh,
&handle_kyc_check_finished,
@@ -289,6 +312,7 @@ TALER_EXCHANGE_kyc_check_cancel (struct TALER_EXCHANGE_KycCheckHandle *kch)
GNUNET_CURL_job_cancel (kch->job);
kch->job = NULL;
}
+ TALER_EXCHANGE_keys_decref (kch->keys);
GNUNET_free (kch->url);
GNUNET_free (kch);
}