mod_nw_ssl.c revision 417f504d4d11631c0d062be85347f82a26c88677
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
*
* above and is interfaced through WinSock on NetWare. As you can see in
*
* To load, simply place the module in the modules directory under the main
* apache tree. Then add a "SecureListen" with two arguments. The first
* name as created in ConsoleOne.
*
* Examples:
*
* SecureListen 443 "SSL CertificateIP"
* SecureListen 123.45.67.89:443 mycert
*/
#define WS_SSL
#define MAX_ADDRESS 512
#define MAX_KEY 80
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "ap_listen.h"
#include "apr_strings.h"
#include "apr_portable.h"
typedef struct NWSSLSrvConfigRec NWSSLSrvConfigRec;
typedef struct seclisten_rec seclisten_rec;
struct seclisten_rec {
int fd;
int used; /* Only used during restart */
int mutual;
char *addr;
int port;
};
struct NWSSLSrvConfigRec {
};
#define get_nwssl_cfg(srv) (NWSSLSrvConfigRec *) ap_get_module_config(srv->module_config, &nwssl_module)
/*
* Parses a host of the form <address>[:port]
* :port is permitted if 'port' is not NULL
*/
static unsigned long parse_addr(const char *w, unsigned short *ports)
{
unsigned long my_addr;
char *p;
p = strchr(w, ':');
*ports = 0;
}
if (p != NULL)
*p = '\0';
if (strcmp(w, "*") == 0) {
if (p != NULL)
*p = ':';
return htonl(INADDR_ANY);
}
my_addr = apr_inet_addr((char *)w);
if (my_addr != INADDR_NONE) {
if (p != NULL)
*p = ':';
return my_addr;
}
hep = gethostbyname(w);
exit(1);
}
exit(1);
}
if (p != NULL)
*p = ':';
}
{
}
}
return -1;
}
{
int s;
int one = 1;
char addr[MAX_ADDRESS];
struct sslserveropts opts;
unsigned int optParam;
int no = 1;
else
/* note that because we're about to slack we don't use psocket */
(LPWSAPROTOCOL_INFO)&SecureProtoInfo, 0, 0);
if (s == INVALID_SOCKET) {
errno = WSAGetLastError();
"make_secure_socket: failed to get a socket for %s", addr);
return -1;
}
if (!mutual) {
errno = WSAGetLastError();
"make_secure_socket: for %s, WSAIoctl: (SO_SSL_SET_FLAGS)", addr);
return -1;
}
}
opts.sidtimeout = 0;
opts.sidentries = 0;
errno = WSAGetLastError();
"make_secure_socket: for %s, WSAIoctl: (SO_SSL_SET_SERVER)", addr);
return -1;
}
if (mutual) {
errno = WSAGetLastError();
"make_secure_socket: for %s, WSAIoctl: (SO_SSL_SET_FLAGS)", addr );
return -1;
}
}
return s;
}
const char* mutual)
{
unsigned short port;
return err;
return "Missing IP address";
return "Address must end in :<port-number>";
*(ports++) = '\0';
}
else {
}
}
else {
}
if (!port)
return "Port must be numeric";
return NULL;
}
{
/* Remove our secure listener from the listener list */
/* slr is at the head of the list */
break;
}
/* slr is somewhere in between or at the end*/
break;
}
}
return APR_SUCCESS;
}
{
return OK;
}
{
if (lr) {
pconf)) != APR_SUCCESS) {
return HTTP_INTERNAL_SERVER_ERROR;
}
ap_listeners = lr;
}
} else {
return HTTP_INTERNAL_SERVER_ERROR;
}
}
return OK;
}
{
return new;
}
{
return merged;
}
static int isSecure (const request_rec *r)
{
char port[8];
int ret = 0;
if (s_secure)
ret = 1;
return ret;
}
static int nwssl_hook_Fixup(request_rec *r)
{
apr_table_t *e = r->subprocess_env;
if (!isSecure(r))
return DECLINED;
return DECLINED;
}
static const char *nwssl_hook_http_method (const request_rec *r)
{
if (isSecure(r))
return "https";
return NULL;
}
static const command_rec nwssl_module_cmds[] =
{
"Optional third parameter of MUTUAL configures the port for mutual authentication."),
{NULL}
};
static void register_hooks(apr_pool_t *p)
{
}
{
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
nwssl_config_server_create, /* server config */
nwssl_config_server_merge, /* merge server config */
nwssl_module_cmds, /* command apr_table_t */
};