challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

challenger-httpd.h (4981B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2023 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file challenger/challenger-httpd.h
     18  * @brief OAuth 2.0 address validation server
     19  * @author Christian Grothoff
     20  */
     21 #ifndef challenger_HTTPD_H
     22 #define challenger_HTTPD_H
     23 
     24 #include "platform.h"
     25 #include <microhttpd.h>
     26 #include <taler/taler_mhd_lib.h>
     27 #include "challenger_database_lib.h"
     28 #include <gnunet/gnunet_mhd_compat.h>
     29 
     30 
     31 /**
     32  * @brief Struct describing an URL and the handler for it.
     33  */
     34 struct CH_RequestHandler;
     35 
     36 /**
     37  * Signature of a function used to clean up the context
     38  * of this handler.
     39  *
     40  * @param cls closure to clean up.
     41  */
     42 typedef void
     43 (*CH_ContextCleanup)(void *cls);
     44 
     45 
     46 /**
     47  * Each MHD response handler that sets the "connection_cls" to a
     48  * non-NULL value must use a struct that has this struct as its first
     49  * member.  This struct contains a single callback, which will be
     50  * invoked to clean up the memory when the connection is completed.
     51  */
     52 struct CH_HandlerContext
     53 {
     54 
     55   /**
     56    * Function to execute the handler-specific cleanup of the
     57    * (typically larger) context.
     58    */
     59   CH_ContextCleanup cc;
     60 
     61   /**
     62    * Handler-specific context, will be passed to @e cc
     63    * upon completion.
     64    */
     65   void *ctx;
     66 
     67   /**
     68    * Connection being processed.
     69    */
     70   struct MHD_Connection *connection;
     71 
     72   /**
     73    * remaining URL path
     74    */
     75   const char *path;
     76 
     77   /**
     78    * Copy of our original full URL with query parameters.
     79    */
     80   char *full_url;
     81 
     82   /**
     83    * Request handler for this request.
     84    */
     85   const struct CH_RequestHandler *rh;
     86 
     87   /**
     88    * Asynchronous request context id.
     89    */
     90   struct GNUNET_AsyncScopeId async_scope_id;
     91 
     92 };
     93 
     94 
     95 /**
     96  * @brief Struct describing an URL and the handler for it.
     97  */
     98 struct CH_RequestHandler
     99 {
    100 
    101   /**
    102    * URL the handler is for.  End with a '/' to make
    103    * this only a prefix to match. However, "/" will
    104    * only match "/" and not be treated as a prefix.
    105    */
    106   const char *url;
    107 
    108   /**
    109    * HTTP method the handler is for.
    110    */
    111   const char *method;
    112 
    113   /**
    114    * Function to call to handle the request.
    115    *
    116    * @param hc handler context
    117    * @param upload_data upload data
    118    * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
    119    * @return MHD result code
    120    */
    121   MHD_RESULT (*handler)(struct CH_HandlerContext *hc,
    122                         const char *upload_data,
    123                         size_t *upload_data_size);
    124 
    125 };
    126 
    127 
    128 /**
    129  * Handle to the database backend.
    130  */
    131 extern struct CHALLENGER_DatabasePlugin *CH_db;
    132 
    133 /**
    134  * Our context for making HTTP requests.
    135  */
    136 extern struct GNUNET_CURL_Context *CH_ctx;
    137 
    138 /**
    139  * Helper command to run for transmission of
    140  * challenge values.
    141  */
    142 extern char *CH_auth_command;
    143 
    144 /**
    145  * Type of addresses this challenger validates.
    146  */
    147 extern char *CH_address_type;
    148 
    149 /**
    150  * Hint to show to users on what address to enter.
    151  */
    152 extern char *CH_address_hint;
    153 
    154 /**
    155  * (external) base URL of this service.
    156  */
    157 extern char *CH_base_url;
    158 
    159 /**
    160  * Mustach template for the letter to send.
    161  * WARNING: not 0-terminated! Allocated via mmap(), free with munmap()!
    162  */
    163 extern void *CH_message_template;
    164 
    165 /**
    166  * Number of bytes in #CH_message_template
    167  */
    168 extern size_t CH_message_template_len;
    169 
    170 /**
    171  * How long is an individual validation request valid?
    172  */
    173 extern struct GNUNET_TIME_Relative CH_validation_duration;
    174 
    175 /**
    176  * How long validated data considered to be valid?
    177  */
    178 extern struct GNUNET_TIME_Relative CH_validation_expiration;
    179 
    180 /**
    181  * How often do we retransmit the challenge.
    182  */
    183 extern struct GNUNET_TIME_Relative CH_pin_retransmission_frequency;
    184 
    185 /**
    186  * JSON object with key-object pairs mapping address keys (from the
    187  * form) to an object with a field "regex" containing a regular
    188  * expressions expressing restrictions on values for the address and a
    189  * field "hint" (and possibly "hint_i18n") containing a human-readable
    190  * message explaining the restriction. Missing map entries indicate
    191  * that the input is unrestricted.
    192  */
    193 extern json_t *CH_restrictions;
    194 
    195 /**
    196  * Kick MHD to run now, to be called after MHD_resume_connection().
    197  * Basically, we need to explicitly resume MHD's event loop whenever
    198  * we made progress serving a request.  This function re-schedules
    199  * the task processing MHD's activities to run immediately.
    200  */
    201 void
    202 CH_trigger_daemon (void);
    203 
    204 
    205 /**
    206  * Kick GNUnet Curl scheduler to begin curl interactions.
    207  */
    208 void
    209 CH_trigger_curl (void);
    210 
    211 
    212 #endif