integrate /kyc-* handlers with dispatching logic

This commit is contained in:
Christian Grothoff 2021-10-17 19:02:26 +02:00
parent b38b51d5e8
commit adb9335528
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
7 changed files with 130 additions and 72 deletions

View File

@ -835,6 +835,25 @@ handle_mhd_request (void *cls,
.handler.get = &TEH_handler_deposits_get, .handler.get = &TEH_handler_deposits_get,
.nargs = 4 .nargs = 4
}, },
/* KYC endpoints */
{
.url = "kyc-check",
.method = MHD_HTTP_METHOD_GET,
.handler.get = &TEH_handler_kyc_check,
.nargs = 1
},
{
.url = "kyc-proof",
.method = MHD_HTTP_METHOD_GET,
.handler.get = &TEH_handler_kyc_proof,
.nargs = 1
},
{
.url = "kyc-wallet",
.method = MHD_HTTP_METHOD_POST,
.handler.post = &TEH_handler_kyc_wallet,
.nargs = 0
},
/* POST management endpoints */ /* POST management endpoints */
{ {
.url = "management", .url = "management",

View File

@ -98,69 +98,89 @@ kyc_check (void *cls,
MHD_RESULT MHD_RESULT
TEH_handler_kyc_check ( TEH_handler_kyc_check (
struct MHD_Connection *connection, struct TEH_RequestContext *rc,
uint64_t payment_target_uuid) const char *const args[])
{ {
struct KycCheckContext kcc = { unsigned long long payment_target_uuid;
.payment_target_uuid = payment_target_uuid
};
MHD_RESULT res; MHD_RESULT res;
enum GNUNET_GenericReturnValue ret; enum GNUNET_GenericReturnValue ret;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); char dummy;
if (1 !=
sscanf (args[0],
"%llu%c",
&payment_target_uuid,
&dummy))
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"payment_target_uuid");
}
(void) GNUNET_TIME_round_abs (&now);
if (TEH_KYC_NONE == TEH_kyc_config.mode) if (TEH_KYC_NONE == TEH_kyc_config.mode)
return TALER_MHD_reply_static ( return TALER_MHD_reply_static (
connection, rc->connection,
MHD_HTTP_NO_CONTENT, MHD_HTTP_NO_CONTENT,
NULL, NULL,
NULL, NULL,
0); 0);
ret = TEH_DB_run_transaction (connection,
"kyc check",
&res,
&kyc_check,
&kcc);
if (GNUNET_SYSERR == ret)
return res;
if (! kcc.kyc.ok)
{ {
GNUNET_assert (TEH_KYC_OAUTH2 == TEH_kyc_config.mode); struct GNUNET_TIME_Absolute now;
return TALER_MHD_REPLY_JSON_PACK ( struct KycCheckContext kcc = {
connection, .payment_target_uuid = payment_target_uuid
MHD_HTTP_ACCEPTED,
GNUNET_JSON_pack_string ("kyc_url",
TEH_kyc_config.details.oauth2.url));
}
{
struct TALER_ExchangePublicKeyP pub;
struct TALER_ExchangeSignatureP sig;
struct TALER_ExchangeAccountSetupSuccessPS as = {
.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
.purpose.size = htonl (sizeof (as)),
.h_payto = kcc.h_payto,
.timestamp = GNUNET_TIME_absolute_hton (now)
}; };
enum TALER_ErrorCode ec;
if (TALER_EC_NONE != now = GNUNET_TIME_absolute_get ();
(ec = TEH_keys_exchange_sign (&as, (void) GNUNET_TIME_round_abs (&now);
&pub, ret = TEH_DB_run_transaction (rc->connection,
&sig))) "kyc check",
&res,
&kyc_check,
&kcc);
if (GNUNET_SYSERR == ret)
return res;
if (! kcc.kyc.ok)
{ {
return TALER_MHD_reply_with_ec (connection, GNUNET_assert (TEH_KYC_OAUTH2 == TEH_kyc_config.mode);
ec, return TALER_MHD_REPLY_JSON_PACK (
NULL); rc->connection,
MHD_HTTP_ACCEPTED,
GNUNET_JSON_pack_string ("kyc_url",
TEH_kyc_config.details.oauth2.url));
}
{
struct TALER_ExchangePublicKeyP pub;
struct TALER_ExchangeSignatureP sig;
struct TALER_ExchangeAccountSetupSuccessPS as = {
.purpose.purpose = htonl (
TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
.purpose.size = htonl (sizeof (as)),
.h_payto = kcc.h_payto,
.timestamp = GNUNET_TIME_absolute_hton (now)
};
enum TALER_ErrorCode ec;
if (TALER_EC_NONE !=
(ec = TEH_keys_exchange_sign (&as,
&pub,
&sig)))
{
return TALER_MHD_reply_with_ec (rc->connection,
ec,
NULL);
}
return TALER_MHD_REPLY_JSON_PACK (
rc->connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_data_auto ("exchange_sig",
&sig),
GNUNET_JSON_pack_data_auto ("exchange_pub",
&pub),
GNUNET_JSON_pack_time_abs ("now",
now));
} }
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_data_auto ("exchange_sig",
&sig),
GNUNET_JSON_pack_data_auto ("exchange_pub",
&pub),
GNUNET_JSON_pack_time_abs ("now",
now));
} }
} }

View File

@ -30,13 +30,13 @@
* status of the given account and returns it. * status of the given account and returns it.
* *
* @param connection request to handle * @param connection request to handle
* @param payment_target_uuid which account are we to check * @param args one argument with the payment_target_uuid
* @return MHD result code * @return MHD result code
*/ */
MHD_RESULT MHD_RESULT
TEH_handler_kyc_check ( TEH_handler_kyc_check (
struct MHD_Connection *connection, struct TEH_RequestContext *rc,
uint64_t payment_target_uuid); const char *const args[]);
#endif #endif

View File

@ -67,21 +67,36 @@ proof_kyc_check (void *cls,
MHD_RESULT MHD_RESULT
TEH_handler_kyc_proof ( TEH_handler_kyc_proof (
struct MHD_Connection *connection, struct TEH_RequestContext *rc,
...) const char *const args[])
{ {
struct KycProofContext kpc; struct KycProofContext kpc;
MHD_RESULT res; MHD_RESULT res;
enum GNUNET_GenericReturnValue ret; enum GNUNET_GenericReturnValue ret;
unsigned long long payment_target_uuid;
char dummy;
if (1 !=
sscanf (args[0],
"%llu%c",
&payment_target_uuid,
&dummy))
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"payment_target_uuid");
}
if (1 || (TEH_KYC_NONE == TEH_kyc_config.mode)) if (1 || (TEH_KYC_NONE == TEH_kyc_config.mode))
return TALER_MHD_reply_static ( return TALER_MHD_reply_static (
connection, rc->connection,
MHD_HTTP_NO_CONTENT, MHD_HTTP_NO_CONTENT,
NULL, NULL,
NULL, NULL,
0); 0);
ret = TEH_DB_run_transaction (connection, ret = TEH_DB_run_transaction (rc->connection,
"check proof kyc", "check proof kyc",
&res, &res,
&proof_kyc_check, &proof_kyc_check,
@ -89,7 +104,7 @@ TEH_handler_kyc_proof (
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
return res; return res;
return TALER_MHD_REPLY_JSON_PACK ( return TALER_MHD_REPLY_JSON_PACK (
connection, rc->connection,
MHD_HTTP_OK, MHD_HTTP_OK,
GNUNET_JSON_pack_uint64 ("42", GNUNET_JSON_pack_uint64 ("42",
42)); 42));

View File

@ -28,13 +28,14 @@
/** /**
* Handle a "/kyc-proof" request. * Handle a "/kyc-proof" request.
* *
* @param connection request to handle * @param rc request to handle
* @param args one argument with the payment_target_uuid
* @return MHD result code * @return MHD result code
*/ */
MHD_RESULT MHD_RESULT
TEH_handler_kyc_proof ( TEH_handler_kyc_proof (
struct MHD_Connection *connection, struct TEH_RequestContext *rc,
...); const char *const args[]);
#endif #endif

View File

@ -89,8 +89,9 @@ wallet_kyc_check (void *cls,
MHD_RESULT MHD_RESULT
TEH_handler_kyc_wallet ( TEH_handler_kyc_wallet (
struct MHD_Connection *connection, struct TEH_RequestContext *rc,
const json_t *root) const json_t *root,
const char *const args[])
{ {
struct TALER_ReserveSignatureP reserve_sig; struct TALER_ReserveSignatureP reserve_sig;
struct KycRequestContext krc; struct KycRequestContext krc;
@ -108,7 +109,7 @@ TEH_handler_kyc_wallet (
.purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP) .purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP)
}; };
ret = TALER_MHD_parse_json_data (connection, ret = TALER_MHD_parse_json_data (rc->connection,
root, root,
spec); spec);
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
@ -124,19 +125,19 @@ TEH_handler_kyc_wallet (
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return TALER_MHD_reply_with_error ( return TALER_MHD_reply_with_error (
connection, rc->connection,
MHD_HTTP_FORBIDDEN, MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_KYC_WALLET_SIGNATURE_INVALID, TALER_EC_EXCHANGE_KYC_WALLET_SIGNATURE_INVALID,
NULL); NULL);
} }
if (TEH_KYC_NONE == TEH_kyc_config.mode) if (TEH_KYC_NONE == TEH_kyc_config.mode)
return TALER_MHD_reply_static ( return TALER_MHD_reply_static (
connection, rc->connection,
MHD_HTTP_NO_CONTENT, MHD_HTTP_NO_CONTENT,
NULL, NULL,
NULL, NULL,
0); 0);
ret = TEH_DB_run_transaction (connection, ret = TEH_DB_run_transaction (rc->connection,
"check wallet kyc", "check wallet kyc",
&res, &res,
&wallet_kyc_check, &wallet_kyc_check,
@ -144,7 +145,7 @@ TEH_handler_kyc_wallet (
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
return res; return res;
return TALER_MHD_REPLY_JSON_PACK ( return TALER_MHD_REPLY_JSON_PACK (
connection, rc->connection,
MHD_HTTP_OK, MHD_HTTP_OK,
GNUNET_JSON_pack_uint64 ("payment_target_uuid", GNUNET_JSON_pack_uint64 ("payment_target_uuid",
krc.kyc.payment_target_uuid)); krc.kyc.payment_target_uuid));

View File

@ -30,14 +30,16 @@
* reserve and the signature "reserve_sig" which affirms the operation. If OK, * reserve and the signature "reserve_sig" which affirms the operation. If OK,
* a KYC record is created (if missing) and the KYC status returned. * a KYC record is created (if missing) and the KYC status returned.
* *
* @param connection request to handle * @param rc request to handle
* @param root uploaded JSON data * @param root uploaded JSON data
* @param args empty array
* @return MHD result code * @return MHD result code
*/ */
MHD_RESULT MHD_RESULT
TEH_handler_kyc_wallet ( TEH_handler_kyc_wallet (
struct MHD_Connection *connection, struct TEH_RequestContext *rc,
const json_t *root); const json_t *root,
const char *const args[]);
#endif #endif