diff options
-rw-r--r-- | src/exchange/taler-exchange-httpd.c | 19 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-check.c | 116 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-check.h | 8 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-proof.c | 25 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-proof.h | 9 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-wallet.c | 15 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-wallet.h | 10 |
7 files changed, 130 insertions, 72 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index 194a2378a..5491c3ef3 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -835,6 +835,25 @@ handle_mhd_request (void *cls, .handler.get = &TEH_handler_deposits_get, .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 */ { .url = "management", diff --git a/src/exchange/taler-exchange-httpd_kyc-check.c b/src/exchange/taler-exchange-httpd_kyc-check.c index 1e29ba2c9..13f5810b8 100644 --- a/src/exchange/taler-exchange-httpd_kyc-check.c +++ b/src/exchange/taler-exchange-httpd_kyc-check.c @@ -98,69 +98,89 @@ kyc_check (void *cls, MHD_RESULT TEH_handler_kyc_check ( - struct MHD_Connection *connection, - uint64_t payment_target_uuid) + struct TEH_RequestContext *rc, + const char *const args[]) { - struct KycCheckContext kcc = { - .payment_target_uuid = payment_target_uuid - }; + unsigned long long payment_target_uuid; MHD_RESULT res; 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) return TALER_MHD_reply_static ( - connection, + rc->connection, MHD_HTTP_NO_CONTENT, NULL, NULL, 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); - return TALER_MHD_REPLY_JSON_PACK ( - 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) + struct GNUNET_TIME_Absolute now; + struct KycCheckContext kcc = { + .payment_target_uuid = payment_target_uuid }; - enum TALER_ErrorCode ec; - if (TALER_EC_NONE != - (ec = TEH_keys_exchange_sign (&as, - &pub, - &sig))) + now = GNUNET_TIME_absolute_get (); + (void) GNUNET_TIME_round_abs (&now); + ret = TEH_DB_run_transaction (rc->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); + return TALER_MHD_REPLY_JSON_PACK ( + rc->connection, + MHD_HTTP_ACCEPTED, + GNUNET_JSON_pack_string ("kyc_url", + TEH_kyc_config.details.oauth2.url)); + } { - return TALER_MHD_reply_with_ec (connection, - ec, - NULL); + 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)); } } diff --git a/src/exchange/taler-exchange-httpd_kyc-check.h b/src/exchange/taler-exchange-httpd_kyc-check.h index 12f24488b..8120a173b 100644 --- a/src/exchange/taler-exchange-httpd_kyc-check.h +++ b/src/exchange/taler-exchange-httpd_kyc-check.h @@ -30,13 +30,13 @@ * status of the given account and returns it. * * @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 - */ + */ MHD_RESULT TEH_handler_kyc_check ( - struct MHD_Connection *connection, - uint64_t payment_target_uuid); + struct TEH_RequestContext *rc, + const char *const args[]); #endif diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.c b/src/exchange/taler-exchange-httpd_kyc-proof.c index cb3f00dde..be7fc50fe 100644 --- a/src/exchange/taler-exchange-httpd_kyc-proof.c +++ b/src/exchange/taler-exchange-httpd_kyc-proof.c @@ -67,21 +67,36 @@ proof_kyc_check (void *cls, MHD_RESULT TEH_handler_kyc_proof ( - struct MHD_Connection *connection, - ...) + struct TEH_RequestContext *rc, + const char *const args[]) { struct KycProofContext kpc; MHD_RESULT res; 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)) return TALER_MHD_reply_static ( - connection, + rc->connection, MHD_HTTP_NO_CONTENT, NULL, NULL, 0); - ret = TEH_DB_run_transaction (connection, + ret = TEH_DB_run_transaction (rc->connection, "check proof kyc", &res, &proof_kyc_check, @@ -89,7 +104,7 @@ TEH_handler_kyc_proof ( if (GNUNET_SYSERR == ret) return res; return TALER_MHD_REPLY_JSON_PACK ( - connection, + rc->connection, MHD_HTTP_OK, GNUNET_JSON_pack_uint64 ("42", 42)); diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.h b/src/exchange/taler-exchange-httpd_kyc-proof.h index 1958a0043..9cf1963c7 100644 --- a/src/exchange/taler-exchange-httpd_kyc-proof.h +++ b/src/exchange/taler-exchange-httpd_kyc-proof.h @@ -28,13 +28,14 @@ /** * 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 - */ + */ MHD_RESULT TEH_handler_kyc_proof ( - struct MHD_Connection *connection, - ...); + struct TEH_RequestContext *rc, + const char *const args[]); #endif diff --git a/src/exchange/taler-exchange-httpd_kyc-wallet.c b/src/exchange/taler-exchange-httpd_kyc-wallet.c index d5bbb8515..dcab3dca2 100644 --- a/src/exchange/taler-exchange-httpd_kyc-wallet.c +++ b/src/exchange/taler-exchange-httpd_kyc-wallet.c @@ -89,8 +89,9 @@ wallet_kyc_check (void *cls, MHD_RESULT TEH_handler_kyc_wallet ( - struct MHD_Connection *connection, - const json_t *root) + struct TEH_RequestContext *rc, + const json_t *root, + const char *const args[]) { struct TALER_ReserveSignatureP reserve_sig; struct KycRequestContext krc; @@ -108,7 +109,7 @@ TEH_handler_kyc_wallet ( .purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP) }; - ret = TALER_MHD_parse_json_data (connection, + ret = TALER_MHD_parse_json_data (rc->connection, root, spec); if (GNUNET_SYSERR == ret) @@ -124,19 +125,19 @@ TEH_handler_kyc_wallet ( { GNUNET_break_op (0); return TALER_MHD_reply_with_error ( - connection, + rc->connection, MHD_HTTP_FORBIDDEN, TALER_EC_EXCHANGE_KYC_WALLET_SIGNATURE_INVALID, NULL); } if (TEH_KYC_NONE == TEH_kyc_config.mode) return TALER_MHD_reply_static ( - connection, + rc->connection, MHD_HTTP_NO_CONTENT, NULL, NULL, 0); - ret = TEH_DB_run_transaction (connection, + ret = TEH_DB_run_transaction (rc->connection, "check wallet kyc", &res, &wallet_kyc_check, @@ -144,7 +145,7 @@ TEH_handler_kyc_wallet ( if (GNUNET_SYSERR == ret) return res; return TALER_MHD_REPLY_JSON_PACK ( - connection, + rc->connection, MHD_HTTP_OK, GNUNET_JSON_pack_uint64 ("payment_target_uuid", krc.kyc.payment_target_uuid)); diff --git a/src/exchange/taler-exchange-httpd_kyc-wallet.h b/src/exchange/taler-exchange-httpd_kyc-wallet.h index 70ac50949..bd8ae1b08 100644 --- a/src/exchange/taler-exchange-httpd_kyc-wallet.h +++ b/src/exchange/taler-exchange-httpd_kyc-wallet.h @@ -30,14 +30,16 @@ * reserve and the signature "reserve_sig" which affirms the operation. If OK, * 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 args empty array * @return MHD result code - */ + */ MHD_RESULT TEH_handler_kyc_wallet ( - struct MHD_Connection *connection, - const json_t *root); + struct TEH_RequestContext *rc, + const json_t *root, + const char *const args[]); #endif |