mod_ssl.h revision 6ace32dacb8313226eb9019275d0e4fa45a15148
/* _ _
** _ __ ___ ___ __| | ___ ___| | mod_ssl
** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
** |_____|
** mod_ssl.h
** Global header
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*/
/* ``The Apache Group: a collection
of talented individuals who are
trying to perfect the art of
never finishing something.''
-- Rob Hartill */
#ifndef MOD_SSL_H
#define MOD_SSL_H 1
#if 0 /* XXX */
/*
* Check whether Extended API (EAPI) is enabled
*/
#ifndef EAPI
#error "mod_ssl requires Extended API (EAPI)"
#endif
/*
* Optionally enable the experimental stuff, but allow the user to
* override the decision which experimental parts are included by using
* CFLAGS="-DSSL_EXPERIMENTAL_xxxx_IGNORE".
*/
#ifdef SSL_EXPERIMENTAL
#ifndef SSL_EXPERIMENTAL_PERDIRCA_IGNORE
#define SSL_EXPERIMENTAL_PERDIRCA
#endif
#ifndef SSL_EXPERIMENTAL_PROXY_IGNORE
#define SSL_EXPERIMENTAL_PROXY
#endif
#ifdef SSL_ENGINE
#ifndef SSL_EXPERIMENTAL_ENGINE_IGNORE
#define SSL_EXPERIMENTAL_ENGINE
#endif
#endif
#endif /* SSL_EXPERIMENTAL */
/*
* Power up our brain...
*/
/* OS headers */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <time.h>
#ifndef WIN32
#endif
#ifdef WIN32
#include <wincrypt.h>
#include <winsock2.h>
#endif
/* OpenSSL headers */
#ifdef SSL_EXPERIMENTAL_ENGINE
#endif
/* Apache headers */
#define CORE_PRIVATE
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_conf_globals.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_main.h"
#include "http_core.h"
#include "http_log.h"
#include "scoreboard.h"
#include "util_md5.h"
#include "fnmatch.h"
/* mod_ssl headers */
#include "ssl_expr.h"
#include "ssl_util_ssl.h"
#include "ssl_util_table.h"
/*
* Provide reasonable default for some defines
*/
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#endif
#ifndef PFALSE
#endif
#ifndef PTRUE
#endif
#ifndef UNSET
#define UNSET (-1)
#endif
#ifndef NUL
#define NUL '\0'
#endif
#ifndef RAND_MAX
#include <limits.h>
#endif
/*
* Provide reasonable defines for some types
*/
#ifndef BOOL
#define BOOL unsigned int
#endif
#ifndef UCHAR
#define UCHAR unsigned char
#endif
/*
* Provide useful shorthands
*/
#define AP_END_CMD \
{ NULL }
/*
* SSL Logging
*/
#define SSL_LOG_NONE (1<<0)
/*
* Defaults for the configuration
*/
#ifndef SSL_SESSION_CACHE_TIMEOUT
#define SSL_SESSION_CACHE_TIMEOUT 300
#endif
/*
* Support for file locking: Try to determine whether we should use fcntl() or
* flock(). Would be better ap_config.h could provide this... :-(
*/
#if defined(USE_FCNTL_SERIALIZED_ACCEPT)
#define SSL_USE_FCNTL 1
#include <fcntl.h>
#endif
#if defined(USE_FLOCK_SERIALIZED_ACCEPT)
#define SSL_USE_FLOCK 1
#endif
#if !defined(SSL_USE_FCNTL) && !defined(SSL_USE_FLOCK)
#define SSL_USE_FLOCK 1
#endif
#ifndef LOCK_UN
#define SSL_USE_FCNTL 1
#include <fcntl.h>
#endif
#endif
#ifdef AIX
#define SSL_USE_FCNTL 1
#include <fcntl.h>
#endif
/*
* Support for Mutex
*/
#ifndef WIN32
#else
#endif
#if defined(USE_SYSVSEM_SERIALIZED_ACCEPT) ||\
(defined(__FreeBSD__) && defined(__FreeBSD_version) &&\
__FreeBSD_version >= 300000) ||\
(defined (__digital__) && defined (__unix__))
#define SSL_CAN_USE_SEM
#define SSL_HAVE_IPCSEM
/*
* Some platforms have a `union semun' pre-defined but Single Unix
* Specification (SUSv2) says in semctl(2): `If required, it is of
* type union semun, which the application program must explicitly
* declare'. So we define it always ourself to avoid problems (but under
* a different name to avoid a namespace clash).
*/
union ssl_ipc_semun {
long val;
unsigned short int *array;
};
#endif
#ifdef WIN32
#define SSL_CAN_USE_SEM
#define SSL_HAVE_W32SEM
#include "multithread.h"
#include <process.h>
#endif
/*
* Support for MM library
*/
#ifndef WIN32
#else
#endif
/*
* Support for DBM library
*/
#ifndef WIN32
#else
#define SSL_USE_SDBM
#endif
#ifdef SSL_USE_SDBM
#include "ssl_util_sdbm.h"
#define ssl_dbm_open sdbm_open
#define ssl_dbm_close sdbm_close
#define ssl_dbm_store sdbm_store
#define ssl_dbm_fetch sdbm_fetch
#define ssl_dbm_delete sdbm_delete
#define ssl_dbm_firstkey sdbm_firstkey
#define ssl_dbm_nextkey sdbm_nextkey
#define SSL_DBM_FILE_SUFFIX_DIR ".dir"
#define SSL_DBM_FILE_SUFFIX_PAG ".pag"
#else /* !SSL_USE_SDBM */
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
#else
#include <ndbm.h>
#endif
#define ssl_dbm_open dbm_open
#define ssl_dbm_close dbm_close
#define ssl_dbm_store dbm_store
#define ssl_dbm_fetch dbm_fetch
#define ssl_dbm_delete dbm_delete
#define ssl_dbm_firstkey dbm_firstkey
#define ssl_dbm_nextkey dbm_nextkey
#if !defined(SSL_DBM_FILE_SUFFIX_DIR) && !defined(SSL_DBM_FILE_SUFFIX_PAG)
#if defined(DBM_SUFFIX)
#define SSL_DBM_FILE_SUFFIX_DIR DBM_SUFFIX
#define SSL_DBM_FILE_SUFFIX_PAG DBM_SUFFIX
#define SSL_DBM_FILE_SUFFIX_DIR ".db"
#define SSL_DBM_FILE_SUFFIX_PAG ".db"
#else
#define SSL_DBM_FILE_SUFFIX_DIR ".dir"
#define SSL_DBM_FILE_SUFFIX_PAG ".pag"
#endif
#endif
#endif /* !SSL_USE_SDBM */
/*
* Check for OpenSSL version
*/
#if SSL_LIBRARY_VERSION < 0x00903100
#error "mod_ssl requires OpenSSL 0.9.3 or higher"
#endif
/*
* The own data structures
*/
typedef struct {
} ssl_ds_array;
typedef struct {
} ssl_ds_table;
/*
* Define the certificate algorithm types
*/
typedef int ssl_algo_t;
#define SSL_ALGO_UNKNOWN (0)
#define SSL_ALGO_RSA (1<<0)
#define SSL_AIDX_RSA (0)
#define SSL_AIDX_DSA (1)
#define SSL_AIDX_MAX (2)
/*
* Define IDs for the temporary RSA keys and DH params
*/
#define SSL_TKP_GEN (0)
#define SSL_TKP_ALLOC (1)
#define SSL_TKP_FREE (2)
#define SSL_TKPIDX_RSA512 (0)
#define SSL_TKPIDX_RSA1024 (1)
#define SSL_TKPIDX_DH512 (2)
#define SSL_TKPIDX_DH1024 (3)
#define SSL_TKPIDX_MAX (4)
/*
* Define the SSL options
*/
#define SSL_OPT_NONE (0)
#define SSL_OPT_RELSET (1<<0)
#define SSL_OPT_ALL (SSL_OPT_STDENVVARS|SSL_OPT_COMPATENVVAR|SSL_OPT_EXPORTCERTDATA|SSL_OPT_FAKEBASICAUTH|SSL_OPT_STRICTREQUIRE|SSL_OPT_OPTRENEGOTIATE)
typedef int ssl_opt_t;
/*
* Define the SSL Protocol options
*/
#define SSL_PROTOCOL_NONE (0)
#define SSL_PROTOCOL_SSLV2 (1<<0)
typedef int ssl_proto_t;
/*
* Define the SSL verify levels
*/
typedef enum {
SSL_CVERIFY_NONE = 0,
SSL_CVERIFY_OPTIONAL = 1,
SSL_CVERIFY_REQUIRE = 2,
} ssl_verify_t;
/*
* Define the SSL pass phrase dialog types
*/
typedef enum {
SSL_PPTYPE_BUILTIN = 0,
/*
* Define the Path Checking modes
*/
#define SSL_PCM_EXISTS 1
#define SSL_PCM_ISREG 2
#define SSL_PCM_ISDIR 4
#define SSL_PCM_ISNONZERO 8
typedef unsigned int ssl_pathcheck_t;
/*
* Define the SSL session cache modes and structures
*/
typedef enum {
SSL_SCMODE_NONE = 0,
SSL_SCMODE_DBM = 1,
SSL_SCMODE_SHMHT = 2,
SSL_SCMODE_SHMCB = 3
} ssl_scmode_t;
/*
* Define the SSL mutex modes
*/
typedef enum {
SSL_MUTEXMODE_NONE = 0,
SSL_MUTEXMODE_FILE = 1,
/*
* Define the SSL requirement structure
*/
typedef struct {
char *cpExpr;
/*
* Define the SSL random number generator seeding source
*/
typedef enum {
SSL_RSCTX_STARTUP = 1,
} ssl_rsctx_t;
typedef enum {
SSL_RSSRC_BUILTIN = 1,
SSL_RSSRC_FILE = 2,
SSL_RSSRC_EXEC = 3
#if SSL_LIBRARY_VERSION >= 0x00905100
,SSL_RSSRC_EGD = 4
#endif
} 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 struct {
int nInitCount;
int nSessionCacheMode;
char *szSessionCacheDataFile;
char *szMutexFile;
int nMutexFD;
int nMutexSEMID;
void *pTmpKeys[SSL_TKPIDX_MAX];
#ifdef SSL_EXPERIMENTAL_ENGINE
char *szCryptoDevice;
#endif
struct {
} rCtx;
#ifdef SSL_VENDOR
#endif
/*
* Define the mod_ssl per-server configuration structure
* (i.e. the configuration for the main server
* and all <VirtualHost> contexts)
*/
typedef struct {
char *szPublicCertFile[SSL_AIDX_MAX];
char *szPrivateKeyFile[SSL_AIDX_MAX];
char *szCertificateChain;
char *szCACertificatePath;
char *szCACertificateFile;
char *szLogFile;
char *szCipherSuite;
int nLogLevel;
int nVerifyDepth;
int nSessionCacheTimeout;
char *szPassPhraseDialogPath;
char *szCARevocationPath;
char *szCARevocationFile;
#ifdef SSL_EXPERIMENTAL_PROXY
/* Configuration details for proxy operation */
int bProxyVerify;
int nProxyVerifyDepth;
char *szProxyCACertificatePath;
char *szProxyCACertificateFile;
char *szProxyClientCertificateFile;
char *szProxyClientCertificatePath;
char *szProxyCipherSuite;
#endif
#ifdef SSL_VENDOR
#endif
/*
* Define the mod_ssl per-directory configuration structure
* (i.e. the local configuration for all <Directory>
* and .htaccess contexts)
*/
typedef struct {
char *szCipherSuite;
int nVerifyDepth;
#ifdef SSL_EXPERIMENTAL_PERDIRCA
char *szCACertificatePath;
char *szCACertificateFile;
#endif
#ifdef SSL_VENDOR
#endif
/*
* function prototypes
*/
/* API glue structures */
/* configuration handling */
void ssl_config_global_create(void);
void ssl_config_global_fix(void);
BOOL ssl_config_global_isfixed(void);
void *ssl_config_server_merge(pool *, void *, void *);
void *ssl_config_perdir_create(pool *, char *);
void *ssl_config_perdir_merge(pool *, void *, void *);
const char *ssl_cmd_SSLMutex(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLPassPhraseDialog(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLCryptoDevice(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLRandomSeed(cmd_parms *, char *, char *, char *, char *);
const char *ssl_cmd_SSLEngine(cmd_parms *, char *, int);
const char *ssl_cmd_SSLCertificateFile(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLCertificateKeyFile(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLCertificateChainFile(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLSessionCache(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLSessionCacheTimeout(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLLog(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLLogLevel(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLProtocol(cmd_parms *, char *, const char *);
#ifdef SSL_EXPERIMENTAL_PROXY
const char *ssl_cmd_SSLProxyProtocol(cmd_parms *, char *, const char *);
const char *ssl_cmd_SSLProxyCipherSuite(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLProxyVerify(cmd_parms *, char *, int);
const char *ssl_cmd_SSLProxyVerifyDepth(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLProxyCACertificatePath(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLProxyCACertificateFile(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLProxyMachineCertificatePath(cmd_parms *, char *, char *);
const char *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, char *, char *);
#endif
/* module initialization */
void ssl_init_SSLLibrary(void);
void ssl_init_ChildKill(void *);
void ssl_init_ModuleKill(void *);
/* Apache API hooks */
void ssl_hook_AddModule(module *);
void ssl_hook_RemoveModule(module *);
char *ssl_hook_RewriteCommand(cmd_parms *, void *, const char *);
void ssl_hook_NewConnection(conn_rec *);
void ssl_hook_TimeoutConnection(int);
void ssl_hook_CloseConnection(conn_rec *);
int ssl_hook_Translate(request_rec *);
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_Handler(request_rec *);
/* OpenSSL callbacks */
int ssl_callback_SSLVerify(int, X509_STORE_CTX *);
void ssl_callback_LogTracingState(SSL *, int, int);
/* Session Cache Support */
void ssl_scache_kill(server_rec *);
void ssl_scache_expire(server_rec *);
char *ssl_scache_id2sz(UCHAR *, int);
void ssl_scache_dbm_kill(server_rec *);
void ssl_scache_dbm_expire(server_rec *);
void ssl_scache_shmht_kill(server_rec *);
void ssl_scache_shmht_expire(server_rec *);
void ssl_scache_shmcb_kill(server_rec *);
void ssl_scache_shmcb_expire(server_rec *);
/* Pass Phrase Support */
int ssl_pphrase_Handle_CB(char *, int, int);
/* Diffie-Hellman Parameter Support */
DH *ssl_dh_GetTmpParam(int);
DH *ssl_dh_GetParamFromFile(char *);
/* Data Structures */
void *ssl_ds_array_push(ssl_ds_array *);
void *ssl_ds_array_get(ssl_ds_array *, int);
void ssl_ds_array_wipeout(ssl_ds_array *);
void ssl_ds_array_kill(ssl_ds_array *);
void *ssl_ds_table_push(ssl_ds_table *, char *);
void *ssl_ds_table_get(ssl_ds_table *, char *);
void ssl_ds_table_wipeout(ssl_ds_table *);
void ssl_ds_table_kill(ssl_ds_table *);
/* Mutex Support */
void ssl_mutex_on(server_rec *);
void ssl_mutex_off(server_rec *);
void ssl_mutex_kill(server_rec *s);
void ssl_mutex_file_remove(void *);
BOOL ssl_mutex_file_acquire(void);
BOOL ssl_mutex_file_release(void);
void ssl_mutex_sem_remove(void *);
BOOL ssl_mutex_sem_acquire(void);
BOOL ssl_mutex_sem_release(void);
/* Logfile Support */
void ssl_log(server_rec *, int, const char *, ...);
void ssl_die(void);
/* Variables */
void ssl_var_register(void);
void ssl_var_unregister(void);
/* I/O */
void ssl_io_register(void);
void ssl_io_unregister(void);
long ssl_io_data_cb(BIO *, int, const char *, int, long, long);
#ifndef SSL_CONSERVATIVE
#endif
/* PRNG */
/* Extensions */
void ssl_ext_register(void);
void ssl_ext_unregister(void);
/* Compatibility */
#ifdef SSL_COMPAT
void ssl_compat_variables(request_rec *);
#endif
/* Utility Functions */
char *ssl_util_server_root_relative(pool *, char *, char *);
void ssl_util_strupper(char *);
void ssl_util_uuencode(char *, const char *, BOOL);
void ssl_util_uuencode_binary(unsigned char *, const unsigned char *, int, BOOL);
int ssl_util_ppopen_child(void *, child_info *);
char *ssl_util_algotypestr(ssl_algo_t);
char *ssl_util_ptxtsub(pool *, const char *, const char *, char *);
void ssl_util_thread_setup(void);
/* Vendor extension support */
#if defined(SSL_VENDOR) && defined(SSL_VENDOR_OBJS)
void ssl_vendor_register(void);
void ssl_vendor_unregister(void);
#endif
#endif /* XXX */
#endif /* MOD_SSL_H */