diff options
Diffstat (limited to 'src/kyclogic/taler-exchange-kyc-tester.c')
-rw-r--r-- | src/kyclogic/taler-exchange-kyc-tester.c | 176 |
1 files changed, 124 insertions, 52 deletions
diff --git a/src/kyclogic/taler-exchange-kyc-tester.c b/src/kyclogic/taler-exchange-kyc-tester.c index 64b140877..c2efafd72 100644 --- a/src/kyclogic/taler-exchange-kyc-tester.c +++ b/src/kyclogic/taler-exchange-kyc-tester.c @@ -28,7 +28,7 @@ #include "taler_mhd_lib.h" #include "taler_json_lib.h" #include "taler_templating_lib.h" -#include "taler_crypto_lib.h" +#include "taler_util.h" #include "taler_kyclogic_lib.h" #include "taler_kyclogic_plugin.h" #include <gnunet/gnunet_mhd_compat.h> @@ -436,6 +436,7 @@ kyc_webhook_cleanup (void) * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown * @param status KYC status * @param expiration until when is the KYC check valid + * @param attributes user attributes returned by the provider * @param http_status HTTP status code of @a response * @param[in] response to return to the HTTP client */ @@ -449,6 +450,7 @@ webhook_finished_cb ( const char *provider_legitimization_id, enum TALER_KYCLOGIC_KycStatus status, struct GNUNET_TIME_Absolute expiration, + const json_t *attributes, unsigned int http_status, struct MHD_Response *response) { @@ -457,12 +459,31 @@ webhook_finished_cb ( (void) expiration; (void) provider_section; kwh->wh = NULL; - GNUNET_break (0 == GNUNET_memcmp (account_id, - &cmd_line_h_payto)); - GNUNET_break (0 == strcmp (provider_user_id, - cmd_provider_user_id)); - GNUNET_break (0 == strcmp (provider_legitimization_id, - cmd_provider_legitimization_id)); + if ( (NULL != account_id) && + (0 != GNUNET_memcmp (account_id, + &cmd_line_h_payto)) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received webhook for unexpected account\n"); + } + if ( (NULL != provider_user_id) && + (NULL != cmd_provider_user_id) && + (0 != strcmp (provider_user_id, + cmd_provider_user_id)) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received webhook for unexpected provider user ID (%s)\n", + provider_user_id); + } + if ( (NULL != provider_legitimization_id) && + (NULL != cmd_provider_legitimization_id) && + (0 != strcmp (provider_legitimization_id, + cmd_provider_legitimization_id)) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received webhook for unexpected provider legitimization ID (%s)\n", + provider_legitimization_id); + } switch (status) { case TALER_KYCLOGIC_STATUS_SUCCESS: @@ -471,6 +492,12 @@ webhook_finished_cb ( "KYC successful for user `%s' (legi: %s)\n", provider_user_id, provider_legitimization_id); + GNUNET_break (NULL != attributes); + fprintf (stderr, + "Extracted attributes:\n"); + json_dumpf (attributes, + stderr, + JSON_INDENT (2)); break; default: GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -567,11 +594,12 @@ handler_kyc_webhook_generic ( rc->rh_ctx = kwh; rc->rh_cleaner = &clean_kwh; - if (GNUNET_OK != - TALER_KYCLOGIC_lookup_logic (args[0], - &kwh->plugin, - &kwh->pd, - &kwh->section_name)) + if ( (NULL == args[0]) || + (GNUNET_OK != + TALER_KYCLOGIC_lookup_logic (args[0], + &kwh->plugin, + &kwh->pd, + &kwh->section_name)) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "KYC logic `%s' unknown (check KYC provider configuration)\n", @@ -581,14 +609,6 @@ handler_kyc_webhook_generic ( TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN, args[0]); } - if (0 != strcmp (args[0], - kwh->section_name)) - { - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "$PROVIDER_SECTION"); - } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calling KYC provider specific webhook\n"); kwh->wh = kwh->plugin->webhook (kwh->plugin->cls, @@ -649,6 +669,8 @@ handler_kyc_webhook_get ( struct TEKT_RequestContext *rc, const char *const args[]) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Webhook GET triggered\n"); return handler_kyc_webhook_generic (rc, MHD_HTTP_METHOD_GET, NULL, @@ -670,6 +692,8 @@ handler_kyc_webhook_post ( const json_t *root, const char *const args[]) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Webhook POST triggered\n"); return handler_kyc_webhook_generic (rc, MHD_HTTP_METHOD_POST, root, @@ -688,6 +712,7 @@ handler_kyc_webhook_post ( * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown * @param expiration until when is the KYC check valid + * @param attributes attributes about the user * @param http_status HTTP status code of @a response * @param[in] response to return to the HTTP client */ @@ -698,6 +723,7 @@ proof_cb ( const char *provider_user_id, const char *provider_legitimization_id, struct GNUNET_TIME_Absolute expiration, + const json_t *attributes, unsigned int http_status, struct MHD_Response *response) { @@ -710,13 +736,26 @@ proof_cb ( status, http_status, provider_user_id); - MHD_resume_connection (rs->rc->connection); - TALER_MHD_daemon_trigger (); + if (TALER_KYCLOGIC_STATUS_SUCCESS == status) + { + GNUNET_break (NULL != attributes); + fprintf (stderr, + "Extracted attributes:\n"); + json_dumpf (attributes, + stderr, + JSON_INDENT (2)); + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Returning response %p with status %u\n", + response, + http_status); rs->rc->response = response; rs->rc->http_status = http_status; GNUNET_CONTAINER_DLL_remove (rs_head, rs_tail, rs); + MHD_resume_connection (rs->rc->connection); + TALER_MHD_daemon_trigger (); GNUNET_free (rs); } @@ -727,32 +766,44 @@ proof_cb ( * * @param rc request context * @param args remaining URL arguments; - * args[0] is the 'h_payto', - * args[1] should be the logic plugin name + * args[0] should be the logic plugin name */ static MHD_RESULT handler_kyc_proof_get ( struct TEKT_RequestContext *rc, - const char *const args[]) + const char *const args[1]) { struct TALER_PaytoHashP h_payto; struct TALER_KYCLOGIC_ProviderDetails *pd; struct TALER_KYCLOGIC_Plugin *logic; struct ProofRequestState *rs; const char *section_name; + const char *h_paytos; - if ( (NULL == args[0]) || - (NULL == args[1]) ) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "GET /kyc-proof triggered\n"); + if (NULL == args[0]) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_NOT_FOUND, TALER_EC_GENERIC_ENDPOINT_UNKNOWN, - "'/$H_PAYTO/$LOGIC' required after '/kyc-proof'"); + "'/kyc-proof/$PROVIDER_SECTION?state=$H_PAYTO' required"); + } + h_paytos = MHD_lookup_connection_value (rc->connection, + MHD_GET_ARGUMENT_KIND, + "state"); + if (NULL == h_paytos) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MISSING, + "h_payto"); } if (GNUNET_OK != - GNUNET_STRINGS_string_to_data (args[0], - strlen (args[0]), + GNUNET_STRINGS_string_to_data (h_paytos, + strlen (h_paytos), &h_payto, sizeof (h_payto))) { @@ -774,18 +825,18 @@ handler_kyc_proof_get ( } if (GNUNET_OK != - TALER_KYCLOGIC_lookup_logic (args[1], + TALER_KYCLOGIC_lookup_logic (args[0], &logic, &pd, §ion_name)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not initiate KYC with provider `%s' (configuration error?)\n", - args[1]); + args[0]); return TALER_MHD_reply_with_error (rc->connection, MHD_HTTP_NOT_FOUND, TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN, - args[1]); + args[0]); } rs = GNUNET_new (struct ProofRequestState); rs->rc = rc; @@ -796,7 +847,6 @@ handler_kyc_proof_get ( rs); rs->ph = logic->proof (logic->cls, pd, - &args[2], rc->connection, &h_payto, kyc_row_id, @@ -940,9 +990,9 @@ proceed_with_handler (struct TEKT_RequestContext *rc, /* Parse command-line arguments */ /* make a copy of 'url' because 'strtok_r()' will modify */ - memcpy (d, - url, - ulen); + GNUNET_memcpy (d, + url, + ulen); i = 0; args[i++] = strtok_r (d, "/", &sp); while ( (NULL != args[i - 1]) && @@ -1032,8 +1082,7 @@ handle_mhd_request (void *cls, .url = "kyc-proof", .method = MHD_HTTP_METHOD_GET, .handler.get = &handler_kyc_proof_get, - .nargs = 128, - .nargs_is_upper_bound = true + .nargs = 1 }, { .url = "kyc-webhook", @@ -1137,15 +1186,19 @@ handle_mhd_request (void *cls, return TALER_MHD_reply_cors_preflight (connection); } GNUNET_assert (NULL != rh->method); - if (0 == strcasecmp (method, + if (0 != strcasecmp (method, rh->method)) - /* cache to avoid the loop next time */ - rc->rh = rh; - /* run handler */ - return proceed_with_handler (rc, - url + tok_size + 1, - upload_data, - upload_data_size); + { + found = true; + continue; + } + /* cache to avoid the loop next time */ + rc->rh = rh; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Handler found for %s '%s'\n", + method, + url); + return MHD_YES; } if (found) @@ -1326,11 +1379,30 @@ initiate_cb ( GNUNET_SCHEDULER_shutdown (); return; } - fprintf (stdout, - "Visit `%s' to begin KYC process (-u: '%s', -U: '%s')\n", - redirect_url, - provider_user_id, - provider_legitimization_id); + { + char *s; + + s = GNUNET_STRINGS_data_to_string_alloc (&cmd_line_h_payto, + sizeof (cmd_line_h_payto)); + if (NULL != provider_user_id) + { + fprintf (stdout, + "Visit `%s' to begin KYC process.\nAlso use: taler-exchange-kyc-tester -w -u '%s' -U '%s' -p %s\n", + redirect_url, + provider_user_id, + provider_legitimization_id, + s); + } + else + { + fprintf (stdout, + "Visit `%s' to begin KYC process.\nAlso use: taler-exchange-kyc-tester -w -U '%s' -p %s\n", + redirect_url, + provider_legitimization_id, + s); + } + GNUNET_free (s); + } GNUNET_free (cmd_provider_user_id); GNUNET_free (cmd_provider_legitimization_id); if (NULL != provider_user_id) |