commit 450ce1ddef69afdb25050aa389d488884dee6b98
parent 514c686914b896df996537f24b865d005a8f7b39
Author: Christian Grothoff <christian@grothoff.org>
Date: Fri, 21 Apr 2023 00:23:14 +0200
skeleton for various challenger endpoints
Diffstat:
11 files changed, 638 insertions(+), 2 deletions(-)
diff --git a/src/challenger/Makefile.am b/src/challenger/Makefile.am
@@ -26,9 +26,13 @@ challenger_admin_LDADD = \
challenger_httpd_SOURCES = \
challenger-httpd.c challenger-httpd.h \
+ challenger-httpd_auth.c challenger-httpd_auth.h \
+ challenger-httpd_challenge.c challenger-httpd_challenge.h \
challenger-httpd_config.c challenger-httpd_config.h \
+ challenger-httpd_info.c challenger-httpd_info.h \
challenger-httpd_login.c challenger-httpd_login.h \
- challenger-httpd_mhd.c challenger-httpd_mhd.h
+ challenger-httpd_mhd.c challenger-httpd_mhd.h \
+ challenger-httpd_solve.c challenger-httpd_solve.h
challenger_httpd_LDADD = \
$(top_builddir)/src/util/libchallengerutil.la \
$(top_builddir)/src/challengerdb/libchallengerdb.la \
diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c
@@ -24,8 +24,12 @@
#include <gnunet/gnunet_curl_lib.h>
#include "challenger_util.h"
#include "challenger-httpd.h"
+#include "challenger-httpd_auth.h"
+#include "challenger-httpd_challenge.h"
+#include "challenger-httpd_info.h"
#include "challenger-httpd_login.h"
#include "challenger-httpd_mhd.h"
+#include "challenger-httpd_solve.h"
#include "challenger_database_lib.h"
#include "challenger-httpd_config.h"
@@ -143,6 +147,26 @@ url_handler (void *cls,
.handler = &CH_handler_login
},
{
+ .url = "/challenge",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler = &CH_handler_challenge
+ },
+ {
+ .url = "/solve",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler = &CH_handler_solve
+ },
+ {
+ .url = "/auth",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler = &CH_handler_auth
+ },
+ {
+ .url = "/info",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler = &CH_handler_info
+ },
+ {
NULL, NULL, NULL
}
};
diff --git a/src/challenger/challenger-httpd_auth.c b/src/challenger/challenger-httpd_auth.c
@@ -0,0 +1,136 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_auth.c
+ * @brief functions to handle incoming /auth requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "challenger-httpd.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "challenger-httpd_auth.h"
+#include <taler/taler_json_lib.h>
+#include <taler/taler_merchant_service.h>
+#include <taler/taler_signatures.h>
+
+
+/**
+ * Context for a /auth operation.
+ */
+struct AuthContext
+{
+
+ /**
+ * Handle for processing uploaded data.
+ */
+ struct MHD_PostProcessor *pp;
+};
+
+
+/**
+ * Function called to clean up a backup context.
+ *
+ * @param hc a `struct AuthContext`
+ */
+static void
+cleanup_ctx (void *cls)
+{
+ struct AuthContext *bc = cls;
+
+ if (NULL != bc->pp)
+ {
+ GNUNET_break_op (MHD_YES ==
+ MHD_destroy_post_processor (bc->pp));
+ }
+ GNUNET_free (bc);
+}
+
+
+/**
+ * Iterator over key-value pairs where the value may be made available
+ * in increments and/or may not be zero-terminated. Used for
+ * processing POST data.
+ *
+ * @param cls a `struct AuthContext *`
+ * @param kind type of the value, always #MHD_POSTDATA_KIND when called from MHD
+ * @param key 0-terminated key for the value
+ * @param filename name of the uploaded file, NULL if not known
+ * @param content_type mime-type of the data, NULL if not known
+ * @param transfer_encoding encoding of the data, NULL if not known
+ * @param data pointer to @a size bytes of data at the
+ * specified offset
+ * @param off offset of data in the overall value
+ * @param size number of bytes in @a data available
+ * @return #MHD_YES to continue iterating,
+ * #MHD_NO to abort the iteration
+ */
+static enum MHD_Result
+post_iter (void *cls,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *filename,
+ const char *content_type,
+ const char *transfer_encoding,
+ const char *data,
+ uint64_t off,
+ size_t size)
+{
+ struct AuthContext *bc = cls;
+
+ (void) bc;
+ GNUNET_break (0);
+ return MHD_NO;
+}
+
+
+MHD_RESULT
+CH_handler_auth (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ struct AuthContext *bc = hc->ctx;
+
+ if (NULL == bc)
+ {
+ /* first call, setup internals */
+ bc = GNUNET_new (struct AuthContext);
+ hc->cc = &cleanup_ctx;
+ hc->ctx = bc;
+ bc->pp = MHD_create_post_processor (hc->connection,
+ 1024,
+ &post_iter,
+ bc);
+ /* FIXME: check content-length is low-enough */
+ return MHD_YES;
+ }
+ /* handle upload */
+ if (0 != *upload_data_size)
+ {
+ enum MHD_Result res;
+
+ res = MHD_post_process (bc->pp,
+ upload_data,
+ *upload_data_size);
+ *upload_data_size = 0;
+ if (MHD_YES == res)
+ return MHD_YES;
+ /* FIXME: return more specific error if possible... */
+ return MHD_NO;
+ }
+
+ /* FIXME: generate proper response */
+ return MHD_NO;
+}
diff --git a/src/challenger/challenger-httpd_auth.h b/src/challenger/challenger-httpd_auth.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file authr-httpd_auth.h
+ * @brief functions to handle incoming requests on /auth
+ * @author Christian Grothoff
+ */
+#ifndef AUTHR_HTTPD_AUTH_H
+#define AUTHR_HTTPD_AUTH_H
+
+#include <microhttpd.h>
+
+
+/**
+ * Handle a client POSTing a /auth request
+ *
+ * @param hc context of the connection
+ * @param upload_data upload data, if any
+ * @param[in,out] upload_data_size remaining data in @a upload_data, to be updated
+ * @return MHD result code
+ */
+MHD_RESULT
+CH_handler_auth (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+
+#endif
diff --git a/src/challenger/challenger-httpd_challenge.c b/src/challenger/challenger-httpd_challenge.c
@@ -0,0 +1,136 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_challenge.c
+ * @brief functions to handle incoming /challenge requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "challenger-httpd.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "challenger-httpd_challenge.h"
+#include <taler/taler_json_lib.h>
+#include <taler/taler_merchant_service.h>
+#include <taler/taler_signatures.h>
+
+
+/**
+ * Context for a /challenge operation.
+ */
+struct ChallengeContext
+{
+
+ /**
+ * Handle for processing uploaded data.
+ */
+ struct MHD_PostProcessor *pp;
+};
+
+
+/**
+ * Function called to clean up a backup context.
+ *
+ * @param hc a `struct ChallengeContext`
+ */
+static void
+cleanup_ctx (void *cls)
+{
+ struct ChallengeContext *bc = cls;
+
+ if (NULL != bc->pp)
+ {
+ GNUNET_break_op (MHD_YES ==
+ MHD_destroy_post_processor (bc->pp));
+ }
+ GNUNET_free (bc);
+}
+
+
+/**
+ * Iterator over key-value pairs where the value may be made available
+ * in increments and/or may not be zero-terminated. Used for
+ * processing POST data.
+ *
+ * @param cls a `struct ChallengeContext *`
+ * @param kind type of the value, always #MHD_POSTDATA_KIND when called from MHD
+ * @param key 0-terminated key for the value
+ * @param filename name of the uploaded file, NULL if not known
+ * @param content_type mime-type of the data, NULL if not known
+ * @param transfer_encoding encoding of the data, NULL if not known
+ * @param data pointer to @a size bytes of data at the
+ * specified offset
+ * @param off offset of data in the overall value
+ * @param size number of bytes in @a data available
+ * @return #MHD_YES to continue iterating,
+ * #MHD_NO to abort the iteration
+ */
+static enum MHD_Result
+post_iter (void *cls,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *filename,
+ const char *content_type,
+ const char *transfer_encoding,
+ const char *data,
+ uint64_t off,
+ size_t size)
+{
+ struct ChallengeContext *bc = cls;
+
+ (void) bc;
+ GNUNET_break (0);
+ return MHD_NO;
+}
+
+
+MHD_RESULT
+CH_handler_challenge (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ struct ChallengeContext *bc = hc->ctx;
+
+ if (NULL == bc)
+ {
+ /* first call, setup internals */
+ bc = GNUNET_new (struct ChallengeContext);
+ hc->cc = &cleanup_ctx;
+ hc->ctx = bc;
+ bc->pp = MHD_create_post_processor (hc->connection,
+ 1024,
+ &post_iter,
+ bc);
+ /* FIXME: check content-length is low-enough */
+ return MHD_YES;
+ }
+ /* handle upload */
+ if (0 != *upload_data_size)
+ {
+ enum MHD_Result res;
+
+ res = MHD_post_process (bc->pp,
+ upload_data,
+ *upload_data_size);
+ *upload_data_size = 0;
+ if (MHD_YES == res)
+ return MHD_YES;
+ /* FIXME: return more specific error if possible... */
+ return MHD_NO;
+ }
+
+ /* FIXME: generate proper response */
+ return MHD_NO;
+}
diff --git a/src/challenger/challenger-httpd_challenge.h b/src/challenger/challenger-httpd_challenge.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_challenge.h
+ * @brief functions to handle incoming requests on /challenge
+ * @author Christian Grothoff
+ */
+#ifndef CHALLENGER_HTTPD_CHALLENGE_H
+#define CHALLENGER_HTTPD_CHALLENGE_H
+
+#include <microhttpd.h>
+
+
+/**
+ * Handle a client POSTing a /challenge request
+ *
+ * @param hc context of the connection
+ * @param upload_data upload data, if any
+ * @param[in,out] upload_data_size remaining data in @a upload_data, to be updated
+ * @return MHD result code
+ */
+MHD_RESULT
+CH_handler_challenge (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+
+#endif
diff --git a/src/challenger/challenger-httpd_info.c b/src/challenger/challenger-httpd_info.c
@@ -0,0 +1,36 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_info.c
+ * @brief functions to handle incoming requests for infos
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "challenger-httpd.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "challenger-httpd_info.h"
+
+
+MHD_RESULT
+CH_handler_info (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ return TALER_MHD_reply_with_error (hc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ NULL);
+}
diff --git a/src/challenger/challenger-httpd_info.h b/src/challenger/challenger-httpd_info.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_info.h
+ * @brief functions to handle incoming requests on /info
+ * @author Christian Grothoff
+ */
+#ifndef CHALLENGER_HTTPD_INFO_H
+#define CHALLENGER_HTTPD_INFO_H
+
+#include <microhttpd.h>
+
+
+/**
+ * Handle request on @a connection for /info.
+ *
+ * @param hc context of the connection
+ * @param upload_data upload data, if any
+ * @param[in,out] upload_data_size remaining data in @a upload_data, to be updated
+ * @return MHD result code
+ */
+MHD_RESULT
+CH_handler_info (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+
+#endif
diff --git a/src/challenger/challenger-httpd_login.h b/src/challenger/challenger-httpd_login.h
@@ -14,7 +14,7 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file challenger-httpd_policy.h
+ * @file challenger-httpd_login.h
* @brief functions to handle incoming requests on /login
* @author Christian Grothoff
*/
diff --git a/src/challenger/challenger-httpd_solve.c b/src/challenger/challenger-httpd_solve.c
@@ -0,0 +1,136 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_solve.c
+ * @brief functions to handle incoming /solve requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "challenger-httpd.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "challenger-httpd_solve.h"
+#include <taler/taler_json_lib.h>
+#include <taler/taler_merchant_service.h>
+#include <taler/taler_signatures.h>
+
+
+/**
+ * Context for a /solve operation.
+ */
+struct SolveContext
+{
+
+ /**
+ * Handle for processing uploaded data.
+ */
+ struct MHD_PostProcessor *pp;
+};
+
+
+/**
+ * Function called to clean up a backup context.
+ *
+ * @param hc a `struct SolveContext`
+ */
+static void
+cleanup_ctx (void *cls)
+{
+ struct SolveContext *bc = cls;
+
+ if (NULL != bc->pp)
+ {
+ GNUNET_break_op (MHD_YES ==
+ MHD_destroy_post_processor (bc->pp));
+ }
+ GNUNET_free (bc);
+}
+
+
+/**
+ * Iterator over key-value pairs where the value may be made available
+ * in increments and/or may not be zero-terminated. Used for
+ * processing POST data.
+ *
+ * @param cls a `struct SolveContext *`
+ * @param kind type of the value, always #MHD_POSTDATA_KIND when called from MHD
+ * @param key 0-terminated key for the value
+ * @param filename name of the uploaded file, NULL if not known
+ * @param content_type mime-type of the data, NULL if not known
+ * @param transfer_encoding encoding of the data, NULL if not known
+ * @param data pointer to @a size bytes of data at the
+ * specified offset
+ * @param off offset of data in the overall value
+ * @param size number of bytes in @a data available
+ * @return #MHD_YES to continue iterating,
+ * #MHD_NO to abort the iteration
+ */
+static enum MHD_Result
+post_iter (void *cls,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *filename,
+ const char *content_type,
+ const char *transfer_encoding,
+ const char *data,
+ uint64_t off,
+ size_t size)
+{
+ struct SolveContext *bc = cls;
+
+ (void) bc;
+ GNUNET_break (0);
+ return MHD_NO;
+}
+
+
+MHD_RESULT
+CH_handler_solve (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ struct SolveContext *bc = hc->ctx;
+
+ if (NULL == bc)
+ {
+ /* first call, setup internals */
+ bc = GNUNET_new (struct SolveContext);
+ hc->cc = &cleanup_ctx;
+ hc->ctx = bc;
+ bc->pp = MHD_create_post_processor (hc->connection,
+ 1024,
+ &post_iter,
+ bc);
+ /* FIXME: check content-length is low-enough */
+ return MHD_YES;
+ }
+ /* handle upload */
+ if (0 != *upload_data_size)
+ {
+ enum MHD_Result res;
+
+ res = MHD_post_process (bc->pp,
+ upload_data,
+ *upload_data_size);
+ *upload_data_size = 0;
+ if (MHD_YES == res)
+ return MHD_YES;
+ /* FIXME: return more specific error if possible... */
+ return MHD_NO;
+ }
+
+ /* FIXME: generate proper response */
+ return MHD_NO;
+}
diff --git a/src/challenger/challenger-httpd_solve.h b/src/challenger/challenger-httpd_solve.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file challenger-httpd_solve.h
+ * @brief functions to handle incoming requests on /solve
+ * @author Christian Grothoff
+ */
+#ifndef CHALLENGER_HTTPD_SOLVE_H
+#define CHALLENGER_HTTPD_SOLVE_H
+
+#include <microhttpd.h>
+
+
+/**
+ * Handle a client POSTing a /solve request
+ *
+ * @param hc context of the connection
+ * @param upload_data upload data, if any
+ * @param[in,out] upload_data_size remaining data in @a upload_data, to be updated
+ * @return MHD result code
+ */
+MHD_RESULT
+CH_handler_solve (struct CH_HandlerContext *hc,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+
+#endif