/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SSL_PRIVATE_H
#define SSL_PRIVATE_H
/**
* @file ssl_private.h
* @brief Internal interfaces private to mod_ssl.
*
* @defgroup MOD_SSL_PRIVATE Private
* @ingroup MOD_SSL
* @{
*/
/** Apache headers */
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_connection.h"
#include "http_request.h"
#include "http_protocol.h"
#include "http_vhost.h"
#include "util_script.h"
#include "util_filter.h"
#include "util_ebcdic.h"
#include "util_mutex.h"
#include "apr.h"
#include "apr_strings.h"
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#include "apr_tables.h"
#include "apr_lib.h"
#include "apr_fnmatch.h"
#include "apr_strings.h"
#include "apr_global_mutex.h"
#include "apr_optional.h"
#include "ap_socache.h"
#include "mod_auth.h"
/* The #ifdef macros are only defined AFTER including the above
* therefore we cannot include these system files at the top :-(
*/
#ifdef APR_HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif
#include <unistd.h> /* needed for STDIN_FILENO et.al., at least on FreeBSD */
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#endif
#ifndef BOOL
#define BOOL unsigned int
#endif
#include "ap_expr.h"
/* OpenSSL headers */
#include <openssl/opensslv.h>
#if (OPENSSL_VERSION_NUMBER >= 0x10001000)
/* must be defined before including ssl.h */
#define OPENSSL_NO_SSL_INTERN
#endif
#include <openssl/x509_vfy.h>
/* Avoid tripping over an engine build installed globally and detected
* when the user points at an explicit non-engine flavor of OpenSSL
*/
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
#endif
#if (OPENSSL_VERSION_NUMBER < 0x0090801f)
#endif
/**
* ...shifting sands of OpenSSL...
* Note: when adding support for new OpenSSL features, avoid explicit
* version number checks whenever possible, and use "feature-based"
* detection instead (check for definitions of constants or functions)
*/
#if (OPENSSL_VERSION_NUMBER >= 0x10000000)
#define MODSSL_SSL_CIPHER_CONST const
#define MODSSL_SSL_METHOD_CONST const
#else
#define MODSSL_SSL_CIPHER_CONST
#define MODSSL_SSL_METHOD_CONST
#endif
#if defined(OPENSSL_FIPS)
#define HAVE_FIPS
#endif
#if defined(SSL_OP_NO_TLSv1_2)
#define HAVE_TLSV1_X
#endif
#if defined(SSL_CONF_FLAG_FILE)
#define HAVE_SSL_CONF_CMD
#endif
/**
* The following features all depend on TLS extension support.
* Within this block, check again for features (not version numbers).
*/
#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name)
#define HAVE_TLSEXT
/* ECC: make sure we have at least 1.0.0 */
#if !defined(OPENSSL_NO_EC) && defined(TLSEXT_ECPOINTFORMAT_uncompressed)
#define HAVE_ECC
#endif
/* OCSP stapling */
#if !defined(OPENSSL_NO_OCSP) && defined(SSL_CTX_set_tlsext_status_cb)
#define HAVE_OCSP_STAPLING
/* backward compatibility with OpenSSL < 1.0 */
#ifndef sk_OPENSSL_STRING_num
#endif
#ifndef sk_OPENSSL_STRING_value
#endif
#ifndef sk_OPENSSL_STRING_pop
#endif
#endif
/* TLS session tickets */
#if defined(SSL_CTX_set_tlsext_ticket_key_cb)
#define HAVE_TLS_SESSION_TICKETS
#ifndef tlsext_tick_md
#ifdef OPENSSL_NO_SHA256
#else
#endif
#endif
#endif
/* Next Protocol Negotiation */
#if !defined(OPENSSL_NO_NEXTPROTONEG) && defined(OPENSSL_NPN_NEGOTIATED)
#define HAVE_TLS_NPN
#endif
/* ALPN Protocol Negotiation */
#define HAVE_TLS_ALPN
#endif
/* Next Protocol Negotiation */
#if !defined(OPENSSL_NO_NEXTPROTONEG) && !defined(OPENSSL_NO_TLSEXT) && defined(OPENSSL_NPN_NEGOTIATED)
#define HAVE_TLS_NPN
#endif
/* Secure Remote Password */
#if !defined(OPENSSL_NO_SRP) && defined(SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB)
#define HAVE_SRP
#endif
#endif /* !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name) */
/* mod_ssl headers */
#include "ssl_util_ssl.h"
/*
* Provide reasonable default for some defines
*/
#ifndef PFALSE
#endif
#ifndef PTRUE
#endif
#ifndef UNSET
#endif
#ifndef NUL
#endif
#ifndef RAND_MAX
#include <limits.h>
#endif
/**
* Provide reasonable defines for some types
*/
#ifndef UCHAR
#define UCHAR unsigned char
#endif
/**
* Provide useful shorthands
*/
#define myConnConfig(c) \
/**
* Defaults for the configuration
*/
#ifndef SSL_SESSION_CACHE_TIMEOUT
#endif
/* Default setting for per-dir reneg buffer. */
#ifndef DEFAULT_RENEG_BUFFER_SIZE
#endif
/* Default for OCSP response validity */
#ifndef DEFAULT_OCSP_MAX_SKEW
#endif
/* Default timeout for OCSP queries */
#ifndef DEFAULT_OCSP_TIMEOUT
#endif
/**
* Define the SSL options
*/
#define SSL_OPT_NONE (0)
typedef int ssl_opt_t;
/**
* Define the SSL Protocol options
*/
#define SSL_PROTOCOL_NONE (0)
#ifdef HAVE_TLSV1_X
#else
#endif
typedef int ssl_proto_t;
/**
* Define the SSL verify levels
*/
typedef enum {
SSL_CVERIFY_NONE = 0,
} ssl_verify_t;
#define SSL_VERIFY_PEER_STRICT \
|| (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
|| (errnum == X509_V_ERR_CERT_UNTRUSTED) \
/**
* CRL checking modes
*/
typedef enum {
SSL_CRLCHECK_NONE = 0,
/**
* Define the SSL pass phrase dialog types
*/
typedef enum {
SSL_PPTYPE_BUILTIN = 0,
/**
* Define the Path Checking modes
*/
typedef unsigned int ssl_pathcheck_t;
/**
* Define the SSL enabled state
*/
typedef enum {
SSL_ENABLED_FALSE = 0,
/**
* Define the SSL requirement structure
*/
typedef struct {
char *cpExpr;
/**
* Define the SSL random number generator seeding source
*/
typedef enum {
} ssl_rsctx_t;
typedef enum {
} ssl_rssrc_t;
typedef struct {
char *cpPath;
int nBytes;
/**
* Define the structure of an ASN.1 anything
*/
typedef struct {
long int nData;
unsigned char *cpData;
} ssl_asn1_t;
/**
* Define the mod_ssl per-module configuration structure
* (i.e. the global configuration for each httpd process)
*/
typedef enum {
typedef struct {
const char *client_dn;
const char *verify_info;
const char *verify_error;
int verify_depth;
int is_proxy;
int disabled;
enum {
/* Track the handshake/renegotiation state for the connection so
* that all client-initiated renegotiations can be rejected, as a
* partial fix for CVE-2009-3555. */
enum {
* renegotiation should be rejected */
* place (as dictated by configuration) */
* connection */
} reneg_state;
#ifdef HAVE_TLS_NPN
/* Poor man's inter-module optional hooks for NPN. */
#endif
#ifdef HAVE_TLS_ALPN
/* Poor man's inter-module optional hooks for ALPN. */
#endif
} SSLConnRec;
/* BIG FAT WARNING: SSLModConfigRec has unusual memory lifetime: it is
* allocated out of the "process" pool and only a single such
* structure is created and used for the lifetime of the process.
* (The process pool is s->process->pool and is stored in the .pPool
* field.) Most members of this structure are likewise allocated out
* of the process pool, but notably sesscache and sesscache_context
* are not.
*
* The structure is treated as mostly immutable after a single config
* parse has completed; the post_config hook (ssl_init_Module) flips
* the bFixed flag to true and subsequent invocations of the config
* callbacks hence do nothing.
*
* This odd lifetime strategy is used so that encrypted private keys
* can be decrypted once at startup and continue to be used across
* subsequent server reloads where the interactive password prompt is
* not possible.
* It is really an ABI nightmare waiting to happen since DSOs are
* reloaded across restarts, and nothing prevents the struct type
* changing across such reloads, yet the cached structure will be
* assumed to match regardless.
*
* This should really be fixed using a smaller structure which only
* stores that which is absolutely necessary (the private keys, maybe
* the random seed), and have that structure be strictly ABI-versioned
* for safety.
*/
typedef struct {
/* OpenSSL SSL_SESS_CACHE_* flags: */
long sesscache_mode;
/* The configured provider, and associated private data
* structure. */
/* A hash table of pointers to ssl_asn1_t structures. The structures
* are used to store private keys in raw DER format (serialized OpenSSL
* PrivateKey structures). The table is indexed by (vhost-id,
* index), for example the string "vhost.example.com:443:0". */
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
const char *szCryptoDevice;
#endif
#ifdef HAVE_OCSP_STAPLING
#endif
/** Structure representing configured filenames for certs and keys for
* a given vhost */
typedef struct {
/* Lists of configured certs and keys for this server */
/** Certificates which specify the set of CA names which should be
* sent in the CertificateRequest message: */
const char *ca_name_path;
const char *ca_name_file;
typedef struct {
const char *cert_file;
const char *cert_path;
const char *ca_cert_file;
* each item in certs.
* (ptr to array of ptrs) */
/** stuff related to authentication that can also be per-dir */
typedef struct {
const char *ca_cert_path;
const char *ca_cert_file;
const char *cipher_suite;
/** for client or downstream server authentication */
int verify_depth;
#ifdef HAVE_TLS_SESSION_TICKETS
typedef struct {
const char *file_path;
#endif
#ifdef HAVE_SSL_CONF_CMD
typedef struct {
const char *name;
const char *value;
#endif
typedef struct {
/** we are one or the other */
#ifdef HAVE_TLS_SESSION_TICKETS
#endif
int protocol_set;
/** config for handling encrypted keys */
const char *pphrase_dialog_path;
const char *cert_chain;
/** certificate revocation list */
const char *crl_path;
const char *crl_file;
#ifdef HAVE_OCSP_STAPLING
/** OCSP stapling options */
long stapling_resptime_skew;
long stapling_resp_maxage;
const char *stapling_force_url;
#endif
#ifdef HAVE_SRP
char *srp_vfile;
char *srp_unknown_user_seed;
#endif
* used regardless of per-cert URL */
long ocsp_resptime_skew;
long ocsp_resp_maxage;
#ifdef HAVE_SSL_CONF_CMD
#endif
#if defined(HAVE_TLS_ALPN) || defined(HAVE_TLS_NPN)
#endif
} modssl_ctx_t;
struct SSLSrvConfigRec {
const char *vhost_id;
int vhost_id_len;
#ifdef HAVE_TLSEXT
#endif
#ifdef HAVE_FIPS
#endif
#ifndef OPENSSL_NO_COMP
#endif
};
/**
* Define the mod_ssl per-directory configuration structure
* (i.e. the local configuration for all <Directory>
* and .htaccess contexts)
*/
typedef struct {
const char *szCipherSuite;
int nVerifyDepth;
const char *szCACertificatePath;
const char *szCACertificateFile;
const char *szUserName;
/**
* function prototypes
*/
/** API glue structures */
/** configuration handling */
void ssl_config_global_fix(SSLModConfigRec *);
void *ssl_config_server_merge(apr_pool_t *, void *, void *);
void *ssl_config_perdir_create(apr_pool_t *, char *);
void *ssl_config_perdir_merge(apr_pool_t *, void *, void *);
const char *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCryptoDevice(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLRandomSeed(cmd_parms *, void *, const char *, const char *, const char *);
const char *ssl_cmd_SSLEngine(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCipherSuite(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCertificateFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCertificateChainFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCACertificatePath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCACertificateFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCADNRequestPath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCADNRequestFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCARevocationPath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCARevocationFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCARevocationCheck(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLVerifyClient(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLVerifyDepth(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLSessionCache(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProtocol(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLOptions(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLRequireSSL(cmd_parms *, void *);
const char *ssl_cmd_SSLRequire(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLUserName(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyProtocol(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyVerify(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyCARevocationPath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyCARevocationFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyCARevocationCheck(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyMachineCertificateChainFile(cmd_parms *, void *, const char *);
#ifdef HAVE_TLS_SESSION_TICKETS
#endif
#ifdef HAVE_SSL_CONF_CMD
const char *ssl_cmd_SSLOpenSSLConfCmd(cmd_parms *cmd, void *dcfg, const char *arg1, const char *arg2);
#endif
#if defined(HAVE_TLS_ALPN) || defined(HAVE_TLS_NPN)
#endif
#ifdef HAVE_SRP
#endif
/** module initialization */
/** Apache API hooks */
int ssl_hook_Auth(request_rec *);
int ssl_hook_UserCheck(request_rec *);
int ssl_hook_Access(request_rec *);
int ssl_hook_Fixup(request_rec *);
int ssl_hook_ReadReq(request_rec *);
int ssl_hook_Upgrade(request_rec *);
/** Apache authz provisders */
extern const authz_provider ssl_authz_provider_require_ssl;
extern const authz_provider ssl_authz_provider_verify_client;
/** OpenSSL callbacks */
int ssl_callback_SSLVerify(int, X509_STORE_CTX *);
void ssl_callback_Info(const SSL *, int, int);
#ifdef HAVE_TLSEXT
#endif
#ifdef HAVE_TLS_SESSION_TICKETS
int ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
EVP_CIPHER_CTX *, HMAC_CTX *, int);
#endif
#ifdef HAVE_TLS_ALPN
#endif
#ifdef HAVE_TLS_NPN
int ssl_callback_AdvertiseNextProtos(SSL *ssl, const unsigned char **data, unsigned int *len, void *arg);
#endif
/** Session Cache Support */
void ssl_scache_status_register(apr_pool_t *p);
void ssl_scache_kill(server_rec *);
apr_pool_t *);
/** OCSP Stapling Support */
#ifdef HAVE_OCSP_STAPLING
const char *ssl_cmd_SSLStaplingCache(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLUseStapling(cmd_parms *, void *, int);
const char *ssl_cmd_SSLStaplingResponseTimeSkew(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLStaplingResponseMaxAge(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLStaplingStandardCacheTimeout(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLStaplingErrorCacheTimeout(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLStaplingReturnResponderErrors(cmd_parms *, void *, int);
const char *ssl_cmd_SSLStaplingFakeTryLater(cmd_parms *, void *, int);
const char *ssl_cmd_SSLStaplingResponderTimeout(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLStaplingForceURL(cmd_parms *, void *, const char *);
modssl_ctx_t *, X509 *);
#endif
#ifdef HAVE_SRP
int ssl_callback_SRPServerParams(SSL *, int *, void *);
#endif
/** I/O */
void ssl_io_filter_register(apr_pool_t *);
long ssl_io_data_cb(BIO *, int, const char *, int, long, long);
/* ssl_io_buffer_fill fills the setaside buffering of the HTTP request
* to allow an SSL renegotiation to take place. */
/** PRNG */
/** Utility Functions */
const char * const *);
const char * const *);
void ssl_util_thread_setup(apr_pool_t *);
/** Pass Phrase Support */
const char *, apr_array_header_t **);
/** Diffie-Hellman Parameter Support */
DH *ssl_dh_GetParamFromFile(const char *);
#ifdef HAVE_ECC
EC_GROUP *ssl_ec_GetParamFromFile(const char *);
#endif
const char *key,
long int length);
const char *key);
const char *key);
/** Mutex Support */
int ssl_mutex_on(server_rec *);
int ssl_mutex_off(server_rec *);
/* mutex type names for Mutex directive */
/** Logfile Support */
void ssl_log_ssl_error(const char *, int, int, server_rec *);
/* ssl_log_xerror, ssl_log_cxerror and ssl_log_rxerror are wrappers for the
* respective ap_log_*error functions and take a certificate as an
* additional argument (whose details are appended to the log message).
* The other arguments are interpreted exactly as with their ap_log_*error
* counterparts. */
const char *format, ...)
const char *format, ...)
/** Variables */
/* Register variables for the lifetime of the process pool 'p'. */
void ssl_var_register(apr_pool_t *p);
void ssl_var_log_config_register(apr_pool_t *p);
/* Extract SSL_*_DN_* variables into table 't' from SSL object 'ssl',
* allocating from 'p': */
/* Extract SSL_*_SAN_* variables (subjectAltName entries) into table 't'
* from SSL object 'ssl', allocating from 'p'. */
#ifndef OPENSSL_NO_OCSP
/* Perform OCSP validation of the current cert in the given context.
* Returns non-zero on success or zero on failure. On failure, the
* context error code is set. */
/* OCSP helper interface; dispatches the given OCSP request to the
* responder at the given URI. Returns the decoded OCSP response
* object, or NULL on error (in which case, errors will have been
* logged). Pool 'p' is used for temporary allocations. */
conn_rec *c, apr_pool_t *p);
#endif
/* Retrieve DH parameters for given key length. Return value should
* be treated as unmutable, since it is stored in process-global
* memory. */
#if HAVE_VALGRIND
extern int ssl_running_on_valgrind;
#endif
#endif /* SSL_PRIVATE_H */
/** @} */