diff options
| author | Christian Grothoff <christian@grothoff.org> | 2022-08-11 23:35:33 +0200 | 
|---|---|---|
| committer | Christian Grothoff <christian@grothoff.org> | 2022-08-11 23:35:33 +0200 | 
| commit | 1009084e94b8e8cf19e3b5568c3cccaba2bd2209 (patch) | |
| tree | a346997dedd05f685ba7addc59e288dfa550ad0e /src/lib | |
| parent | b061ea85c84facfc78c34edface367c5f040bc9c (diff) | |
major rework of the KYC logic, making it more configurable, not complete, but tests pass again
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/exchange_api_common.c | 48 | ||||
| -rw-r--r-- | src/lib/exchange_api_deposits_get.c | 9 | ||||
| -rw-r--r-- | src/lib/exchange_api_handle.c | 43 | ||||
| -rw-r--r-- | src/lib/exchange_api_kyc_check.c | 6 | ||||
| -rw-r--r-- | src/lib/exchange_api_kyc_proof.c | 18 | ||||
| -rw-r--r-- | src/lib/exchange_api_kyc_wallet.c | 3 | ||||
| -rw-r--r-- | src/lib/exchange_api_purse_merge.c | 1 | ||||
| -rw-r--r-- | src/lib/exchange_api_withdraw2.c | 44 | 
8 files changed, 78 insertions, 94 deletions
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index b64053f2..2cb379f8 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -1458,50 +1458,6 @@ TALER_EXCHANGE_check_purse_create_conflict_ (  } -static char * -make_payto (const char *exchange_url, -            const struct TALER_ReservePublicKeyP *reserve_pub) -{ -  char pub_str[sizeof (*reserve_pub) * 2]; -  char *end; -  bool is_http; -  char *reserve_url; - -  end = GNUNET_STRINGS_data_to_string ( -    reserve_pub, -    sizeof (*reserve_pub), -    pub_str, -    sizeof (pub_str)); -  *end = '\0'; -  if (0 == strncmp (exchange_url, -                    "http://", -                    strlen ("http://"))) -  { -    is_http = true; -    exchange_url = &exchange_url[strlen ("http://")]; -  } -  else if (0 == strncmp (exchange_url, -                         "https://", -                         strlen ("https://"))) -  { -    is_http = false; -    exchange_url = &exchange_url[strlen ("https://")]; -  } -  else -  { -    GNUNET_break (0); -    return NULL; -  } -  /* exchange_url includes trailing '/' */ -  GNUNET_asprintf (&reserve_url, -                   "payto://%s/%s%s", -                   is_http ? "taler+http" : "taler", -                   exchange_url, -                   pub_str); -  return reserve_url; -} - -  enum GNUNET_GenericReturnValue  TALER_EXCHANGE_check_purse_merge_conflict_ (    const struct TALER_PurseMergeSignatureP *cmerge_sig, @@ -1539,8 +1495,8 @@ TALER_EXCHANGE_check_purse_merge_conflict_ (    }    if (NULL == partner_url)      partner_url = exchange_url; -  payto_uri = make_payto (partner_url, -                          &reserve_pub); +  payto_uri = TALER_reserve_make_payto (partner_url, +                                        &reserve_pub);    if (GNUNET_OK !=        TALER_wallet_purse_merge_verify (          payto_uri, diff --git a/src/lib/exchange_api_deposits_get.c b/src/lib/exchange_api_deposits_get.c index baa254a8..4ebff3d8 100644 --- a/src/lib/exchange_api_deposits_get.c +++ b/src/lib/exchange_api_deposits_get.c @@ -176,11 +176,14 @@ handle_deposit_wtid_finished (void *cls,    case MHD_HTTP_ACCEPTED:      {        /* Transaction known, but not executed yet */ +      bool no_legi = false;        struct GNUNET_JSON_Specification spec[] = {          GNUNET_JSON_spec_timestamp ("execution_time",                                      &dr.details.accepted.execution_time), -        GNUNET_JSON_spec_uint64 ("payment_target_uuid", -                                 &dr.details.accepted.payment_target_uuid), +        GNUNET_JSON_spec_mark_optional ( +          GNUNET_JSON_spec_uint64 ("legitimization_uuid", +                                   &dr.details.accepted.payment_target_uuid), +          &no_legi),          GNUNET_JSON_spec_bool ("kyc_ok",                                 &dr.details.accepted.kyc_ok),          GNUNET_JSON_spec_end () @@ -196,6 +199,8 @@ handle_deposit_wtid_finished (void *cls,          dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;          break;        } +      if (no_legi) +        dr.details.accepted.payment_target_uuid = 0;        dwh->cb (dwh->cb_cls,                 &dr);        TALER_EXCHANGE_deposits_get_cancel (dwh); diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 488a419b..e2cad2df 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -736,6 +736,7 @@ decode_keys_json (const json_t *resp_obj,    struct GNUNET_HashCode hash_xor = {0};    struct TALER_ExchangePublicKeyP pub;    const char *currency; +  json_t *wblwk = NULL;    struct GNUNET_JSON_Specification mspec[] = {      GNUNET_JSON_spec_fixed_auto ("denominations_sig",                                   &denominations_sig), @@ -750,8 +751,8 @@ decode_keys_json (const json_t *resp_obj,      GNUNET_JSON_spec_string ("currency",                               ¤cy),      GNUNET_JSON_spec_mark_optional ( -      TALER_JSON_spec_amount_any ("wallet_balance_limit_without_kyc", -                                  &key_data->wallet_balance_limit_without_kyc), +      GNUNET_JSON_spec_json ("wallet_balance_limit_without_kyc", +                             &wblwk),        NULL),      GNUNET_JSON_spec_end ()    }; @@ -819,17 +820,6 @@ decode_keys_json (const json_t *resp_obj,                               NULL, NULL));    key_data->currency = GNUNET_strdup (currency); -  if (GNUNET_OK == -      TALER_amount_is_valid (&key_data->wallet_balance_limit_without_kyc)) -  { -    if (0 != strcasecmp (currency, -                         key_data->wallet_balance_limit_without_kyc.currency)) -    { -      GNUNET_break_op (0); -      return GNUNET_SYSERR; -    } -  } -    /* parse the global fees */    {      json_t *global_fees; @@ -882,6 +872,32 @@ decode_keys_json (const json_t *resp_obj,      }    } +  /* Parse balance limits */ +  if (NULL != wblwk) +  { +    key_data->wblwk_length = json_array_size (wblwk); +    key_data->wallet_balance_limit_without_kyc +      = GNUNET_new_array (key_data->wblwk_length, +                          struct TALER_Amount); +    for (unsigned int i = 0; i<key_data->wblwk_length; i++) +    { +      struct TALER_Amount *a = &key_data->wallet_balance_limit_without_kyc[i]; +      const json_t *aj = json_array_get (wblwk, +                                         i); +      struct GNUNET_JSON_Specification spec[] = { +        TALER_JSON_spec_amount (NULL, +                                currency, +                                a), +        GNUNET_JSON_spec_end () +      }; + +      EXITIF (GNUNET_OK != +              GNUNET_JSON_parse (aj, +                                 spec, +                                 NULL, NULL)); +    } +  } +    /* Parse the supported extension(s): age-restriction. */    /* TODO: maybe lift all this into a FP in TALER_Extension ? */    { @@ -1210,6 +1226,7 @@ free_key_data (struct TALER_EXCHANGE_Keys *key_data)    GNUNET_array_grow (key_data->auditors,                       key_data->auditors_size,                       0); +  GNUNET_free (key_data->wallet_balance_limit_without_kyc);    GNUNET_free (key_data->version);    GNUNET_free (key_data->currency);    GNUNET_free (key_data->global_fees); diff --git a/src/lib/exchange_api_kyc_check.c b/src/lib/exchange_api_kyc_check.c index 62a1db58..b67a3a58 100644 --- a/src/lib/exchange_api_kyc_check.c +++ b/src/lib/exchange_api_kyc_check.c @@ -207,7 +207,7 @@ handle_kyc_check_finished (void *cls,  struct TALER_EXCHANGE_KycCheckHandle *  TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange, -                          uint64_t payment_target, +                          uint64_t legitimization_uuid,                            const struct TALER_PaytoHashP *h_payto,                            struct GNUNET_TIME_Relative timeout,                            TALER_EXCHANGE_KycStatusCallback cb, @@ -238,8 +238,8 @@ 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?timeout_ms=%llu", +                     (unsigned long long) legitimization_uuid,                       payto_str,                       timeout_ms);    } diff --git a/src/lib/exchange_api_kyc_proof.c b/src/lib/exchange_api_kyc_proof.c index d3debbdb..0436e1c5 100644 --- a/src/lib/exchange_api_kyc_proof.c +++ b/src/lib/exchange_api_kyc_proof.c @@ -1,6 +1,6 @@  /*    This file is part of TALER -  Copyright (C) 2021 Taler Systems SA +  Copyright (C) 2021, 2022 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 @@ -142,8 +142,8 @@ handle_kyc_proof_finished (void *cls,  struct TALER_EXCHANGE_KycProofHandle *  TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,                            const struct TALER_PaytoHashP *h_payto, -                          const char *code, -                          const char *state, +                          const char *logic, +                          const char *args,                            TALER_EXCHANGE_KycProofCallback cb,                            void *cb_cls)  { @@ -151,13 +151,17 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,    struct GNUNET_CURL_Context *ctx;    char *arg_str; +  if (NULL == args) +    args = ""; +  else +    GNUNET_assert ( (args[0] == '?') || +                    (args[0] == '/') );    if (GNUNET_YES !=        TEAH_handle_is_ready (exchange))    {      GNUNET_break (0);      return NULL;    } -  /* TODO: any escaping of code/state needed??? */    {      char hstr[sizeof (struct TALER_PaytoHashP) * 2];      char *end; @@ -168,10 +172,10 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,                                           sizeof (hstr));      *end = '\0';      GNUNET_asprintf (&arg_str, -                     "/kyc-proof/%s?code=%s&state=%s", +                     "/kyc-proof/%s/%s%s",                       hstr, -                     code, -                     state); +                     logic, +                     args);    }    kph = GNUNET_new (struct TALER_EXCHANGE_KycProofHandle);    kph->exchange = exchange; diff --git a/src/lib/exchange_api_kyc_wallet.c b/src/lib/exchange_api_kyc_wallet.c index fe5e6b70..a03b1765 100644 --- a/src/lib/exchange_api_kyc_wallet.c +++ b/src/lib/exchange_api_kyc_wallet.c @@ -152,6 +152,7 @@ handle_kyc_wallet_finished (void *cls,  struct TALER_EXCHANGE_KycWalletHandle *  TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *exchange,                             const struct TALER_ReservePrivateKeyP *reserve_priv, +                           const struct TALER_Amount *balance,                             TALER_EXCHANGE_KycWalletCallback cb,                             void *cb_cls)  { @@ -167,6 +168,8 @@ TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *exchange,    TALER_wallet_account_setup_sign (reserve_priv,                                     &reserve_sig);    req = GNUNET_JSON_PACK ( +    TALER_JSON_pack_amount ("balance", +                            balance),      GNUNET_JSON_pack_data_auto ("reserve_pub",                                  &reserve_pub),      GNUNET_JSON_pack_data_auto ("reserve_sig", diff --git a/src/lib/exchange_api_purse_merge.c b/src/lib/exchange_api_purse_merge.c index abe6d8cf..07e6cd9d 100644 --- a/src/lib/exchange_api_purse_merge.c +++ b/src/lib/exchange_api_purse_merge.c @@ -232,7 +232,6 @@ handle_purse_merge_finished (void *cls,        GNUNET_CRYPTO_eddsa_key_get_public (&pch->merge_priv.eddsa_priv,                                            &merge_pub.eddsa_pub); -        if (GNUNET_OK !=            TALER_EXCHANGE_check_purse_merge_conflict_ (              &pch->merge_sig, diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c index a5371442..fc7c755d 100644 --- a/src/lib/exchange_api_withdraw2.c +++ b/src/lib/exchange_api_withdraw2.c @@ -264,28 +264,6 @@ handle_reserve_withdraw_finished (void *cls,      GNUNET_assert (NULL == wh->cb);      TALER_EXCHANGE_withdraw2_cancel (wh);      return; -  case MHD_HTTP_ACCEPTED: -    /* only validate reply is well-formed */ -    { -      uint64_t ptu; -      struct GNUNET_JSON_Specification spec[] = { -        GNUNET_JSON_spec_uint64 ("payment_target_uuid", -                                 &ptu), -        GNUNET_JSON_spec_end () -      }; - -      if (GNUNET_OK != -          GNUNET_JSON_parse (j, -                             spec, -                             NULL, NULL)) -      { -        GNUNET_break_op (0); -        hr.http_status = 0; -        hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; -        break; -      } -    } -    break;    case MHD_HTTP_BAD_REQUEST:      /* This should never happen, either us or the exchange is buggy         (or API version conflict); just pass JSON reply to the application */ @@ -333,6 +311,28 @@ handle_reserve_withdraw_finished (void *cls,      hr.ec = TALER_JSON_get_error_code (j);      hr.hint = TALER_JSON_get_error_hint (j);      break; +  case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS: +    /* only validate reply is well-formed */ +    { +      uint64_t ptu; +      struct GNUNET_JSON_Specification spec[] = { +        GNUNET_JSON_spec_uint64 ("payment_target_uuid", +                                 &ptu), +        GNUNET_JSON_spec_end () +      }; + +      if (GNUNET_OK != +          GNUNET_JSON_parse (j, +                             spec, +                             NULL, NULL)) +      { +        GNUNET_break_op (0); +        hr.http_status = 0; +        hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; +        break; +      } +    } +    break;    case MHD_HTTP_INTERNAL_SERVER_ERROR:      /* Server had an internal issue; we should retry, but this API         leaves this to the application */  | 
