/* This file is part of TALER (C) 2014--2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. TALER is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see */ /** * @file taler-merchant-httpd_helper.c * @brief shared logic for various handlers * @author Christian Grothoff */ #include "platform.h" #include #include #include #include "taler-merchant-httpd_helper.h" /** * check @a payto_uris for well-formedness * * @param payto_uris JSON array of payto URIs (presumably) * @return true if they are all valid URIs (and this is an array of strings) */ bool TMH_payto_uri_array_valid (const json_t *payto_uris) { bool payto_ok = true; if (! json_is_array (payto_uris)) { GNUNET_break_op (0); payto_ok = false; } else { unsigned int len = json_array_size (payto_uris); for (unsigned int i = 0; ij_wire = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("payto_uri", payto_uri), GNUNET_JSON_pack_data_auto ("salt", &salt)); GNUNET_assert (NULL != wm->j_wire); /* This also tests for things like the IBAN being malformed */ GNUNET_assert (GNUNET_OK == TALER_JSON_merchant_wire_signature_hash (wm->j_wire, &wm->h_wire)); wm->wire_method = TALER_payto_get_method (payto_uri); GNUNET_assert (NULL != wm->wire_method); /* checked earlier */ wm->active = true; return wm; } enum GNUNET_GenericReturnValue TMH_check_auth_config (struct MHD_Connection *connection, const json_t *jauth, const char **auth_token) { bool auth_wellformed = false; const char *auth_method = json_string_value (json_object_get (jauth, "method")); *auth_token = NULL; if (NULL == auth_method) { GNUNET_break_op (0); } else if (0 == strcmp (auth_method, "external")) { auth_wellformed = true; } else if (0 == strcmp (auth_method, "token")) { *auth_token = json_string_value (json_object_get (jauth, "token")); if (NULL == *auth_token) { GNUNET_break_op (0); } else { if (0 != strncasecmp (RFC_8959_PREFIX, *auth_token, strlen (RFC_8959_PREFIX))) GNUNET_break_op (0); else auth_wellformed = true; } } if (! auth_wellformed) { GNUNET_break_op (0); return (MHD_YES == TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_BAD_AUTH, "bad authentication config")) ? GNUNET_NO : GNUNET_SYSERR; } return GNUNET_OK; } /** * Generate binary UUID from client-provided UUID-string. * * @param uuids string intpu * @param[out] uuid set to binary UUID */ void TMH_uuid_from_string (const char *uuids, struct GNUNET_Uuid *uuid) { struct GNUNET_HashCode hc; GNUNET_CRYPTO_hash (uuids, strlen (uuids), &hc); GNUNET_static_assert (sizeof (hc) > sizeof (*uuid)); memcpy (uuid, &hc, sizeof (*uuid)); }