mod_ssl.h revision ad668861e40da485f2eea24dc4c1f9940e470698
/* _ _
** _ __ ___ ___ __| | ___ ___| | 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-2002 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__
/*
* 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
#ifdef SSL_ENGINE
#ifndef SSL_EXPERIMENTAL_ENGINE_IGNORE
#define SSL_EXPERIMENTAL_ENGINE
#endif
#endif
#endif /* SSL_EXPERIMENTAL */
/*
* Power up our brain...
*/
/* 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 "util_script.h"
#include "util_filter.h"
#include "mpm.h"
#include "apr.h"
#include "apr_strings.h"
#include "apr_tables.h"
#include "apr_lib.h"
#include "apr_fnmatch.h"
#include "apr_strings.h"
#include "apr_dbm.h"
#include "apr_rmm.h"
#include "apr_shm.h"
#include "apr_global_mutex.h"
#include "apr_optional.h"
/* OpenSSL headers */
#include <ssl.h>
#include <err.h>
#include <x509.h>
#include <pem.h>
#include <crypto.h>
#include <evp.h>
#include <rand.h>
#ifdef SSL_EXPERIMENTAL_ENGINE
#include <engine.h>
#endif
#include "ssl_toolkit_compat.h"
#ifdef HAVE_SSL_X509V3_H
#include <x509v3.h>
#endif
/* mod_ssl headers */
#include "ssl_expr.h"
#include "ssl_util_ssl.h"
#include "ssl_util_table.h"
/* The #ifdef macros are only defined AFTER including the above
* therefore we cannot include these system files at the top :-(
*/
#endif
#include <unistd.h> /* needed for STDIN_FILENO et.al., at least on FreeBSD */
#endif
/*
* 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 myConnConfig(c) \
#define myConnConfigSet(c, val) \
/*
* Defaults for the configuration
*/
#ifndef SSL_SESSION_CACHE_TIMEOUT
#define SSL_SESSION_CACHE_TIMEOUT 300
#endif
/*
* Support for MM library
*/
/*
* Support for DBM library
*/
#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
/*
* 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_TMP_KEY_RSA_512 (0)
#define SSL_TMP_KEY_RSA_1024 (1)
#define SSL_TMP_KEY_DH_512 (2)
#define SSL_TMP_KEY_DH_1024 (3)
#define SSL_TMP_KEY_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 SSL_VERIFY_PEER_STRICT \
#ifndef X509_V_ERR_CERT_UNTRUSTED
#define X509_V_ERR_CERT_UNTRUSTED 27
#endif
#define ssl_verify_error_is_optional(errnum) \
|| (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
|| (errnum == X509_V_ERR_CERT_UNTRUSTED) \
/*
* Define the SSL pass phrase dialog types
*/
typedef enum {
SSL_PPTYPE_BUILTIN = 0,
SSL_PPTYPE_FILTER = 1,
SSL_PPTYPE_PIPE = 2
/*
* 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,
/*
* 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,
SSL_RSSRC_EGD = 4
} 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 {
} SSLFilterRec;
typedef enum {
typedef struct {
const char *client_dn;
const char *verify_info;
const char *verify_error;
int verify_depth;
int is_proxy;
int disabled;
int non_ssl_request;
} SSLConnRec;
typedef struct {
int nSessionCacheMode;
char *szSessionCacheDataFile;
const char *szMutexFile;
void *pTmpKeys[SSL_TMP_KEY_MAX];
#ifdef SSL_EXPERIMENTAL_ENGINE
char *szCryptoDevice;
#endif
struct {
} rCtx;
typedef struct {
/*
*/
const char *cert_files[SSL_AIDX_MAX];
const char *key_files[SSL_AIDX_MAX];
typedef struct {
const char *cert_file;
const char *cert_path;
/* 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;
typedef struct SSLSrvConfigRec SSLSrvConfigRec;
typedef struct {
/* we are one or the other */
/* 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;
} modssl_ctx_t;
struct SSLSrvConfigRec {
const char *vhost_id;
int vhost_id_len;
};
/*
* 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;
/*
* 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_SSLMutex(cmd_parms *, void *, const char *);
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 *, int);
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_SSLCARevocationPath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLCARevocationFile(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_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_SSLProxyMachineCertificatePath(cmd_parms *, void *, const char *);
const char *ssl_cmd_SSLProxyMachineCertificateFile(cmd_parms *, void *, const char *);
/* module initialization */
/* Apache API hooks */
void ssl_hook_NewConnection(conn_rec *);
void ssl_hook_TimeoutConnection(int);
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 */
#if 0 /* XXX */
void ssl_scache_status_register(apr_pool_t *p);
#endif
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 */
/* Diffie-Hellman Parameter Support */
DH *ssl_dh_GetTmpParam(int);
DH *ssl_dh_GetParamFromFile(char *);
const char *key,
long int length);
const char *key);
const char *key);
const char *ssl_asn1_keystr(int keytype);
const char *ssl_asn1_table_keyfmt(apr_pool_t *p,
const char *id,
int keytype);
/* Mutex Support */
int ssl_mutex_on(server_rec *);
int ssl_mutex_off(server_rec *);
/* Logfile Support */
void ssl_die(void);
void ssl_log_ssl_error(const char *, int, int, server_rec *);
/* Variables */
void ssl_var_register(void);
void ssl_var_log_config_register(apr_pool_t *p);
APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
(apr_pool_t *, server_rec *,
conn_rec *, request_rec *,
char *));
/* Proxy Support */
int ssl_proxy_enable(conn_rec *c);
int ssl_engine_disable(conn_rec *c);
/* I/O */
void ssl_io_filter_register(apr_pool_t *);
/* PRNG */
/* Utility Functions */
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);
const char * const *);
const char * const *);
char *ssl_util_algotypestr(ssl_algo_t);
char *ssl_util_ptxtsub(apr_pool_t *, const char *, const char *, char *);
void ssl_util_thread_setup(apr_pool_t *);
#endif /* __MOD_SSL_H__ */