github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_4_58/include/http_ssl.h (about)

     1  /* Licensed to the Apache Software Foundation (ASF) under one or more
     2   * contributor license agreements.  See the NOTICE file distributed with
     3   * this work for additional information regarding copyright ownership.
     4   * The ASF licenses this file to You under the Apache License, Version 2.0
     5   * (the "License"); you may not use this file except in compliance with
     6   * the License.  You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  /**
    18   * @file  http_ssl.h
    19   * @brief SSL protocol handling
    20   *
    21   * @defgroup APACHE_CORE_PROTO SSL Protocol Handling
    22   * @ingroup  APACHE_CORE
    23   * @{
    24   */
    25  
    26  #ifndef APACHE_HTTP_SSL_H
    27  #define APACHE_HTTP_SSL_H
    28  
    29  #include "httpd.h"
    30  #include "apr_portable.h"
    31  #include "apr_mmap.h"
    32  
    33  #ifdef __cplusplus
    34  extern "C" {
    35  #endif
    36  
    37  struct ap_conf_vector_t;
    38  
    39  /**
    40   * This hook allows modules that manage SSL connection to register their
    41   * inquiry function for checking if a connection is using SSL from them.
    42   * @param c The current connection
    43   * @return OK if the connection is using SSL, DECLINED if not.
    44   * @ingroup hooks
    45   */
    46  AP_DECLARE_HOOK(int,ssl_conn_is_ssl,(conn_rec *c))
    47  
    48  /**
    49   * Return != 0 iff the connection is encrypted with SSL.
    50   * @param c the connection
    51   */
    52  AP_DECLARE(int) ap_ssl_conn_is_ssl(conn_rec *c);
    53  
    54  /**
    55   * This hook declares a connection to be outgoing and the configuration that applies to it.
    56   * This hook can be called several times in the lifetime of an outgoing connection, e.g.
    57   * when it is re-used in different request contexts. It will at least be called after the
    58   * connection was created and before the pre-connection hooks is invoked.
    59   * All outgoing-connection hooks are run until one returns something other than DECLINE.
    60   * if enable_ssl != 0, a hook that sets up SSL for the connection needs to return OK
    61   * to prevent subsequent hooks from doing the same.
    62   *
    63   * @param c The connection on which requests/data are to be sent.
    64   * @param dir_conf The directory configuration in which this connection is being used.
    65   * @param enable_ssl If != 0, the SSL protocol should be enabled for this connection.
    66   * @return DECLINED, OK when ssl was enabled
    67   */
    68  AP_DECLARE_HOOK(int, ssl_bind_outgoing,
    69                 (conn_rec *c, struct ap_conf_vector_t *dir_conf, int enable_ssl))
    70  
    71  /**
    72   * Assures the connection is marked as outgoing and invokes the ssl_bind_outgoing hook.
    73   * This may be called several times on an outgoing connection with varying dir_conf
    74   * values. require_ssl is not allowed to change on the same connection.
    75   *
    76   * @param c The connection on which requests/data are to be sent.
    77   * @param dir_conf The directory configuration in which this connection is being used.
    78   * @param require_ssl != 0 iff this connection needs to be secured by SSL/TLS protocol.
    79   * @return OK iff ssl was required and is enabled, DECLINED otherwise
    80   */
    81  AP_DECLARE(int) ap_ssl_bind_outgoing(conn_rec *c, struct ap_conf_vector_t *dir_conf,
    82                                       int require_ssl);
    83  
    84  /**
    85   * Return != 0 iff handlers/hooks for outgoing connections are registered.
    86   */
    87  AP_DECLARE(int) ap_ssl_has_outgoing_handlers(void);
    88  
    89  /**
    90   * This hook allows modules to look up SSL related variables for a
    91   * server/connection/request, depending on what they inquire. Some
    92   * variables will only be available for a connection/request, for example.
    93   * @param p The pool to allocate a returned value in, MUST be provided
    94   * @param s The server to inquire a value for, maybe NULL
    95   * @param c The current connection, maybe NULL
    96   * @param r The current request, maybe NULL
    97   * @param name The name of the variable to retrieve, MUST be provided
    98   * @return value or the variable or NULL if not provided/available
    99   * @ingroup hooks
   100   */
   101  AP_DECLARE_HOOK(const char *,ssl_var_lookup,
   102      (apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *name))
   103  
   104  /**
   105   * Lookup an SSL related variable for the server/connection/request or a global
   106   * value when all those parameters are set to NULL. Pool and name must always be
   107   * provided and the returned value (if not NULL) will be allocated from the pool.
   108   * @param p The pool to allocate a returned value in, MUST be provided
   109   * @param s The server to inquire a value for, maybe NULL
   110   * @param c The current connection, maybe NULL
   111   * @param r The current request, maybe NULL
   112   * @param name The name of the variable to retrieve, MUST be provided
   113   * @return value or the variable or NULL if not provided/available
   114   */
   115  AP_DECLARE(const char *) ap_ssl_var_lookup(apr_pool_t *p, server_rec *s,
   116                                             conn_rec *c, request_rec *r,
   117                                             const char *name);
   118  
   119  /**
   120   * Register to provide certificate/key files for servers. Certificate files are
   121   * expected to contain the certificate chain, beginning with the server's certificate,
   122   * excluding the trust anchor, in PEM format.
   123   * They must be accompanied by a private key file, also in PEM format.
   124   *
   125   * @param s the server certificates are collected for
   126   * @param p the pool to use for allocations
   127   * @param cert_files an array of const char* with the path to the certificate chain
   128   * @param key_files an array of const char* with the path to the private key file
   129   * @return OK if files were added, DECLINED if not, or other for error.
   130   */
   131  
   132  AP_DECLARE_HOOK(int, ssl_add_cert_files, (server_rec *s, apr_pool_t *p,
   133                                            apr_array_header_t *cert_files,
   134                                            apr_array_header_t *key_files))
   135  
   136  /**
   137   * Collect certificate/key files from all providers registered. This includes
   138   * providers registered at the global 'ssl_add_cert_files', as well as those
   139   * installed in the OPTIONAL 'ssl_add_cert_files' hook as may be provided by
   140   * ssl modules.
   141   *
   142   * @param s the server certificates are collected for
   143   * @param p the pool to use for allocations
   144   * @param cert_files an array of const char* with the path to the certificate chain
   145   * @param key_files an array of const char* with the path to the private key file
   146   */
   147  AP_DECLARE(apr_status_t) ap_ssl_add_cert_files(server_rec *s, apr_pool_t *p,
   148                                                 apr_array_header_t *cert_files,
   149                                                 apr_array_header_t *key_files);
   150  
   151  
   152  /**
   153   * Register to provide 'fallback' certificates in case no 'real' certificates
   154   * have been configured/added by other providers. Modules using these certificates
   155   * are encouraged to answer requests to this server with a 503 response code.
   156   *
   157   * @param s the server certificates are collected for
   158   * @param p the pool to use for allocations
   159   * @param cert_files an array of const char* with the path to the certificate chain
   160   * @param key_files an array of const char* with the path to the private key file
   161   * @return OK if files were added, DECLINED if not, or other for error.
   162   */
   163  AP_DECLARE_HOOK(int, ssl_add_fallback_cert_files, (server_rec *s, apr_pool_t *p,
   164                                                     apr_array_header_t *cert_files,
   165                                                     apr_array_header_t *key_files))
   166  
   167  /**
   168   * Collect 'fallback' certificate/key files from all registered providers, either
   169   * in the global 'ssl_add_fallback_cert_files' hook or the optional one of similar
   170   * name as provided by mod_ssl and sorts.
   171   * Certificates obtained this way are commonly self signed, temporary crutches.
   172   * To be used to the time it takes to retrieve a 'read', trusted certificate.
   173   * A module using fallbacks is encouraged to answer all requests with a 503.
   174   *
   175   * @param s the server certificates are collected for
   176   * @param p the pool to use for allocations
   177   * @param cert_files an array of const char* with the path to the certificate chain
   178   * @param key_files an array of const char* with the path to the private key file
   179   */
   180  AP_DECLARE(apr_status_t) ap_ssl_add_fallback_cert_files(server_rec *s, apr_pool_t *p,
   181                                                          apr_array_header_t *cert_files,
   182                                                          apr_array_header_t *key_files);
   183  
   184  
   185  /**
   186   * On TLS connections that do not relate to a configured virtual host
   187   * allow modules to provide a certificate and key to be used on the connection.
   188   *
   189   * A Certificate PEM added must be accompanied by a private key PEM. The private
   190   * key PEM may be given by a NULL pointer, in which case it is expected to be found in
   191   * the certificate PEM string.
   192   */
   193  AP_DECLARE_HOOK(int, ssl_answer_challenge, (conn_rec *c, const char *server_name,
   194                                              const char **pcert_pem, const char **pkey_pem))
   195  
   196  /**
   197   * Returns != 0 iff the connection is a challenge to the server, for example
   198   * as defined in RFC 8555 for the 'tls-alpn-01' domain verification, and needs
   199   * a specific certificate as answer in the handshake.
   200   *
   201   * ALPN protocol negotiation via the hooks 'protocol_propose' and 'protocol_switch'
   202   * need to have run before this call is made.
   203   *
   204   * Certificate PEMs added must be accompanied by a private key PEM. The private
   205   * key PEM may be given by a NULL pointer, in which case it is expected to be found in
   206   * the certificate PEM string.
   207   *
   208   * A certificate provided this way needs to replace any other certificates selected
   209   * by configuration or 'ssl_add_cert_pems` on this connection.
   210   */
   211  AP_DECLARE(int) ap_ssl_answer_challenge(conn_rec *c, const char *server_name,
   212                                          const char **pcert_pem, const char **pkey_pem);
   213  
   214  
   215  /**
   216   * Setup optional functions for ssl related queries so that functions
   217   * registered by old-style SSL module functions are interrogated by the
   218   * the new ap_is_ssl() and friends. Installs own optional functions, so that
   219   * old modules looking for these find one and get the correct results (shadowing).
   220   *
   221   * Needs to run in core's very early POST_CONFIG hook.
   222   * Modules providing such functions register their own optionals during
   223   * register_hooks(). Modules using such functions retrieve them often
   224   * in their own post-config or in the even later retrieval hook. When shadowing
   225   * other modules functions, core's early post-config is a good time.
   226   * @param pool The pool to use for allocations
   227   */
   228  AP_DECLARE(void) ap_setup_ssl_optional_fns(apr_pool_t *pool);
   229  
   230  /**
   231   * Providers of OCSP status responses register at this hook. Installed hooks returning OK
   232   * are expected to provide later OCSP responses via a 'ap_ssl_ocsp_get_resp_hook'.
   233   * @param s     the server being configured
   234   * @params p    a memory pool to use
   235   * @param id    opaque data uniquely identifying the certificate, provided by caller
   236   * @param pem   PEM data of certificate first, followed by PEM of issuer cert
   237   * @return OK iff stapling is being provided
   238   */
   239  AP_DECLARE_HOOK(int, ssl_ocsp_prime_hook, (server_rec *s, apr_pool_t *p,
   240                                             const char *id, apr_size_t id_len,
   241                                             const char *pem))
   242  
   243  /**
   244   * Registering a certificate for Provisioning of OCSP responses. It is the caller's
   245   * responsibility to provide a global (apache instance) unique id for the certificate
   246   * that is then used later in retrieving the OCSP response.
   247   * A certificate can be primed this way more than once, however the same identifier
   248   * has to be provided each time (byte-wise same, not pointer same).
   249   * The memory pointed to by `id` and `pem` is only valid for the duration of the call.
   250   *
   251   * @param s     the server being configured
   252   * @params p    a memory pool to use
   253   * @param id    opaque data uniquely identifying the certificate, provided by caller
   254   * @param pem   PEM data of certificate first, followed by chain certs, at least the issuer
   255   * @return APR_SUCCESS iff OCSP responses will be provided.
   256   *         APR_ENOENT when no provided was found or took responsibility.
   257   */
   258  AP_DECLARE(apr_status_t) ap_ssl_ocsp_prime(server_rec *s, apr_pool_t *p,
   259                                             const char *id, apr_size_t id_len,
   260                                             const char *pem);
   261  
   262  /**
   263   * Callback to copy over the OCSP response data. If OCSP response data is not
   264   * available, this will be called with NULL, 0 parameters!
   265   *
   266   * Memory allocation methods and lifetime of data will vary per module and
   267   * SSL library used. The caller requesting OCSP data will need to make a copy
   268   * for his own use.
   269   * Any passed data may only be valid for the duration of the call.
   270   */
   271  typedef void ap_ssl_ocsp_copy_resp(const unsigned char *der, apr_size_t der_len, void *userdata);
   272  
   273  /**
   274   * Asking for OCSP response DER data for a certificate formerly primed.
   275   * @param s     the (SNI selected) server of the connection
   276   * @param c     the connection
   277   * @param id    identifier for the certifate, as used in ocsp_stapling_prime()
   278   * @param cb    callback to invoke when response data is available
   279   * @param userdata caller supplied data passed to callback
   280   * @return OK iff response data has been provided, DECLINED otherwise
   281   */
   282  AP_DECLARE_HOOK(int, ssl_ocsp_get_resp_hook,
   283                  (server_rec *s, conn_rec *c, const char *id, apr_size_t id_len,
   284                   ap_ssl_ocsp_copy_resp *cb, void *userdata))
   285  
   286  /**
   287   * Retrieve the OCSP response data for a previously primed certificate. The id needs
   288   * to be byte-wise identical to the one used on priming. If the call return ARP_SUCCESS,
   289   * the callback has been invoked with the OCSP response DER data.
   290   * Otherwise, a different status code must be returned. Callers in SSL connection
   291   * handshakes are encouraged to continue the handshake without OCSP data for
   292   * server reliability. The decision to accept or reject a handshake with missing
   293   * OCSP stapling data needs to be done by the client.
   294   * For similar reasons, providers of responses might return seemingly expired ones
   295   * if they were unable to refresh a response in time.
   296   *
   297   * The memory pointed to by `id` is only valid for the duration of the call.
   298   * Also, the DER data passed to the callback is only valid for the duration
   299   * of the call.
   300   *
   301   * @param s     the (SNI selected) server of the connection
   302   * @param c     the connection
   303   * @param id    identifier for the certifate, as used in ocsp_stapling_prime()
   304   * @param cb    callback to invoke when response data is available
   305   * @param userdata caller supplied data passed to callback
   306   * @return APR_SUCCESS iff data has been provided
   307   */
   308  AP_DECLARE(apr_status_t) ap_ssl_ocsp_get_resp(server_rec *s, conn_rec *c,
   309                                                const char *id, apr_size_t id_len,
   310                                                ap_ssl_ocsp_copy_resp *cb, void *userdata);
   311  
   312  #ifdef __cplusplus
   313  }
   314  #endif
   315  
   316  #endif  /* !APACHE_HTTP_SSL_H */
   317  /** @} */