summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/http/httpd-ssl-conf
blob: f6082dea143e33adc88a057ee1552e1e2525a31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh

#  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
#  
#    http://www.apache.org/licenses/LICENSE-2.0
#    
#  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.

# Generate a minimal HTTPD SSL configuration
here=`readlink -f $0`; here=`dirname $here`
root=`readlink -f $1`
host=$2
sslport=`echo $3 | awk -F "/" '{ print $1 }'`
sslpport=`echo $3 | awk -F "/" '{ print $2 }'`
if [ "$sslpport" = "" ]; then
    sslpport=$sslport
fi
htdocs=`readlink -f $4`
httpd_prefix=`cat $here/httpd.prefix`
vhost=$5

# Extract organization name from our CA certificate
org=`openssl x509 -noout -subject -nameopt multiline -in $root/conf/ca.crt | grep organizationName | awk -F "= " '{ print $2 }'`

# Generate HTTPD configuration
cat >>$root/conf/httpd.conf <<EOF
# Redirect all HTTP traffic to HTTPS
<Location />
RewriteEngine on
RewriteCond %{SERVER_PORT} !^$sslpport$  
RewriteRule .* https://%{SERVER_NAME}:$sslpport%{REQUEST_URI} [R,L]
</Location>

# Setup SSL support
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog  builtin
SSLSessionCache "shmcb:$root/logs/ssl_scache(512000)"
SSLSessionCacheTimeout 300
SSLMutex "file:$root/logs/ssl_mutex"
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

# Setup HTTPS virtual hosts
Listen $sslport

SSLCACertificateFile "$root/conf/ca.crt"
SSLCertificateFile "$root/conf/server.crt"
SSLCertificateKeyFile "$root/conf/server.key"

<VirtualHost *:$sslport>
ServerName https://$host:$sslpport
UseCanonicalName Off

# Enable SSL
Include conf/ssl-vhost.conf
</VirtualHost>

# Route all wiring through HTTPS
SCAWiringServerName https://$host:$sslpport

EOF

# Generate VirtualHost SSL configuration
cat >$root/conf/ssl-vhost.conf <<EOF
# Enable SSL
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

# Logging
CustomLog "$root/logs/ssl_request_log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
LogFormat "%h %l %u %t %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" sslcombined
CustomLog $root/logs/ssl_access_log sslcombined
LogLevel warn

# Require clients to present either:
# a certificate signed with our certification authority certificate
# or a userid + password for HTTP basic authentication
<Location />
Satisfy Any

SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +FakeBasicAuth
SSLRequireSSL
SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128 and %{SSL_CLIENT_I_DN_O} == "$org"

AuthType Basic
AuthName "$host"
AuthUserFile "$root/conf/httpd.passwd"
Require valid-user
</Location>

EOF

# Generate mass dynamic virtual hosting configuration
if [ "$vhost" = "vhost" ]; then

cat >>$root/conf/httpd.conf <<EOF
# Setup mass dynamic virtual hosting
NameVirtualHost *:$sslport
SSLStrictSNIVHostCheck Off

<VirtualHost *:$sslport>
ServerName https://vhost.$host:$sslpport
ServerAlias *.$host
UseCanonicalName Off
VirtualDocumentRoot $htdocs/domains/%1/

# Enable SSL
SSLCACertificateFile "$root/conf/ca.crt"
SSLCertificateFile "$root/conf/vhost.crt"
SSLCertificateKeyFile "$root/conf/vhost.key"
Include conf/ssl-vhost.conf
</VirtualHost>

EOF

fi

# Create test users for HTTP basic authentication
$httpd_prefix/bin/htpasswd -bc $root/conf/httpd.passwd test test 2>/dev/null
$httpd_prefix/bin/htpasswd -b $root/conf/httpd.passwd foo foo 2>/dev/null
$httpd_prefix/bin/htpasswd -b $root/conf/httpd.passwd bar bar 2>/dev/null