libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

mhd_tls_acme_func.h (5424B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2026 Evgeny Grin (Karlson2k)
      5 
      6   GNU libmicrohttpd is free software; you can redistribute it and/or
      7   modify it under the terms of the GNU Lesser General Public
      8   License as published by the Free Software Foundation; either
      9   version 2.1 of the License, or (at your option) any later version.
     10 
     11   GNU libmicrohttpd is distributed in the hope that it will be useful,
     12   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14   Lesser General Public License for more details.
     15 
     16   Alternatively, you can redistribute GNU libmicrohttpd and/or
     17   modify it under the terms of the GNU General Public License as
     18   published by the Free Software Foundation; either version 2 of
     19   the License, or (at your option) any later version, together
     20   with the eCos exception, as follows:
     21 
     22     As a special exception, if other files instantiate templates or
     23     use macros or inline functions from this file, or you compile this
     24     file and link it with other works to produce a work based on this
     25     file, this file does not by itself cause the resulting work to be
     26     covered by the GNU General Public License. However the source code
     27     for this file must still be made available in accordance with
     28     section (3) of the GNU General Public License v2.
     29 
     30     This exception does not invalidate any other reasons why a work
     31     based on this file might be covered by the GNU General Public
     32     License.
     33 
     34   You should have received copies of the GNU Lesser General Public
     35   License and the GNU General Public License along with this library;
     36   if not, see <https://www.gnu.org/licenses/>.
     37 */
     38 
     39 /**
     40  * @file src/mhd2/mhd_tls_acme_func.h
     41  * @brief  Internal header for ALPN challenge functions for ACME protocol
     42  * @author Karlson2k (Evgeny Grin)
     43  */
     44 
     45 #ifndef MHD_TLS_ACME_FUNC_H
     46 #define MHD_TLS_ACME_FUNC_H 1
     47 
     48 #include "mhd_sys_options.h"
     49 
     50 #ifndef MHD_SUPPORT_HTTPS
     51 #  error This file can be used only with TLS support enabled
     52 #endif
     53 #ifndef MHD_SUPPORT_ACME
     54 #  error This file can be used only with ACME support enabled
     55 #endif
     56 
     57 #include "sys_bool_type.h"
     58 #include "sys_sizet_type.h"
     59 
     60 #include "mhd_tls_choice.h"
     61 
     62 #include "mhd_status_code_int.h"
     63 
     64 struct MHD_Daemon;              /* Forward declaration */
     65 struct mhd_TlsCertsList;        /* Forward declaration */
     66 
     67 #ifdef mhd_HAVE_TLS_ACME
     68 /**
     69  * Initialise daemon ACME certificates data.
     70  * Must be called only for daemons with TLS/HTTPS support enabled
     71  * @param d the daemon to initialise
     72  * @return #MHD_SC_OK on success,
     73  *         error code otherwise
     74  */
     75 MHD_INTERNAL mhd_StatusCodeInt
     76 mhd_daemon_acme_certs_init (struct MHD_Daemon *d)
     77 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_;
     78 
     79 /**
     80  * De-initialise daemon ACME certificates data
     81  *
     82  * Must be called only if #mhd_daemon_acme_certs_init() has been called
     83  * earlier.
     84  * @param d the daemon to de-initialise
     85  */
     86 MHD_INTERNAL void
     87 mhd_daemon_acme_certs_deinit (struct MHD_Daemon *d)
     88 MHD_FN_PAR_NONNULL_ALL_;
     89 
     90 #else  /* ! mhd_HAVE_TLS_ACME */
     91 #  define mhd_daemon_acme_certs_init(d)   ((void)(d), 0)
     92 #  define mhd_daemon_acme_certs_deinit(d) ((void)d)
     93 #endif /* ! mhd_HAVE_TLS_ACME */
     94 
     95 /**
     96  * Get the list of ACME certificates for the daemon
     97  * @param d the daemon to get the list of ACME certificates for
     98  * @return pointer to the list of ACME certificates (valid until
     99  *         the daemon @p d is de-initialised)
    100  */
    101 MHD_INTERNAL struct mhd_TlsCertsList *
    102 mhd_daemon_get_acme_certs (struct MHD_Daemon *d)
    103 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_RETURNS_NONNULL_;
    104 
    105 /**
    106  * Quick check whether the daemon has any ACME certificates
    107  *
    108  * @param acme_certs the list of ACME certificates to check
    109  * @return 'true' if the list @p acme_certs has any ACME certificate,
    110  *         'false' otherwise
    111  */
    112 MHD_INTERNAL bool
    113 mhd_daemon_has_acme_certs (struct mhd_TlsCertsList *restrict acme_certs)
    114 MHD_FN_PAR_NONNULL_ALL_;
    115 
    116 /**
    117  * Get ACME certificate for specified DNS domain name.
    118  *
    119  * When function returns non-NULL pointer the data in the daemon remains
    120  * locked.
    121  * Function #mhd_daemon_acme_cert_r_unlock() must be called when certificate
    122  * data is processed.
    123  *
    124  * @param acme_certs the list of ACME certificates to search in
    125  * @param domain_len the number of characters in @p domain, must not be zero
    126  * @param domain the domain name indicated by the client, does not need to be
    127  *               zero-terminated
    128  * @return NULL if no ACME certificate was assigned to the requested @p domain,
    129  *         pointer to ACME certificate data (valid until unlock function
    130  *         #mhd_daemon_acme_cert_r_unlock() is called)
    131  */
    132 MHD_INTERNAL const union mhd_TlsCredDataPtr *
    133 mhd_daemon_acme_cert_get_r_lock (struct mhd_TlsCertsList *restrict acme_certs,
    134                                  size_t domain_len,
    135                                  const char *restrict domain)
    136 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2);
    137 
    138 /**
    139  * This function must be called after each successful (return is non-NULL) call
    140  * of #mhd_daemon_acme_cert_get_r_lock() function.
    141  *
    142  * @param acme_certs the list of ACME certificates to search in
    143  */
    144 MHD_INTERNAL void
    145 mhd_daemon_acme_cert_r_unlock (struct mhd_TlsCertsList *restrict acme_certs)
    146 MHD_FN_PAR_NONNULL_ALL_;
    147 
    148 
    149 #endif /* ! MHD_TLS_ACME_FUNC_H */