1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5              This file is generated from xml source: DO NOT EDIT
6        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7      -->
8<title>SSL/TLS Strong Encryption: How-To - Apache HTTP Server</title>
9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
12<script src="/style/scripts/prettify.js" type="text/javascript">
13</script>
14
15<link href="/images/favicon.ico" rel="shortcut icon" /></head>
16<body id="manual-page"><div id="page-header">
17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
18<p class="apache">Apache HTTP Server Version 2.2</p>
19<img alt="" src="/images/feather.gif" /></div>
20<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
21<div id="path">
22<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.2</a> &gt; <a href="./">SSL/TLS</a></div><div id="page-content"><div id="preamble"><h1>SSL/TLS Strong Encryption: How-To</h1>
23<div class="toplang">
24<p><span>Available Languages: </span><a href="/en/ssl/ssl_howto.html" title="English">&nbsp;en&nbsp;</a></p>
25</div>
26
27<blockquote>
28<p>The solution to this problem is trivial
29and is left as an exercise for the reader.</p>
30
31<p class="cite">-- <cite>Standard textbook cookie</cite></p>
32</blockquote>
33
34<p>How to solve particular security problems for an SSL-aware
35webserver is not always obvious because of the interactions between SSL,
36HTTP and Apache's way of processing requests. This chapter gives
37instructions on how to solve some typical situations. Treat it as a first
38step to find out the final solution, but always try to understand the 
39stuff before you use it. Nothing is worse than using a security solution
40without knowing its restrictions and how it interacts with other systems.</p>
41</div>
42<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#ciphersuites">Cipher Suites and Enforcing Strong Security</a></li>
43<li><img alt="" src="/images/down.gif" /> <a href="#accesscontrol">Client Authentication and Access Control</a></li>
44</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
45<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
46<div class="section">
47<h2><a name="ciphersuites" id="ciphersuites">Cipher Suites and Enforcing Strong Security</a></h2>
48
49<ul>
50<li><a href="#realssl">How can I create a real SSLv2-only server?</a></li>
51<li><a href="#onlystrong">How can I create an SSL server which accepts strong encryption only?</a></li>
52<li><a href="#upgradeenc">How can I create an SSL server which accepts strong encryption only, but allows
53export browsers to upgrade to stronger encryption?</a></li>
54<li><a href="#strongurl">How can I create an SSL server which accepts all types of ciphers in general, but 
55requires a strong cipher for access to a particular URL?</a></li>
56</ul>
57
58<h3><a name="realssl" id="realssl">How can I create a real SSLv2-only server?</a></h3>
59
60    <p>The following creates an SSL server which speaks only the SSLv2 protocol and
61    its ciphers.</p>
62
63    <div class="example"><h3>httpd.conf</h3><p><code>
64      SSLProtocol -all +SSLv2<br />
65      SSLCipherSuite SSLv2:+HIGH:+MEDIUM:+LOW:+EXP<br />
66    </code></p></div>
67
68
69<h3><a name="onlystrong" id="onlystrong">How can I create an SSL server which accepts strong encryption
70only?</a></h3>
71
72    <p>The following enables only the seven strongest ciphers:</p>
73    <div class="example"><h3>httpd.conf</h3><p><code>
74      SSLProtocol all<br />
75      SSLCipherSuite HIGH:MEDIUM<br />
76    </code></p></div>
77
78
79<h3><a name="upgradeenc" id="upgradeenc">How can I create an SSL server which accepts strong encryption
80only, but allows export browsers to upgrade to stronger encryption?</a></h3>
81
82    <p>This facility is called Server Gated Cryptography (SGC) and requires 
83    a Global ID server certificate, signed by a special CA certificate 
84    from Verisign. This enables strong encryption in 'export' versions of 
85    browsers, which traditionally could not support it (because of US export 
86    restrictions).</p>
87    <p>When a browser connects with an export cipher, the server sends its Global
88    ID certificate. The browser verifies this, and can then upgrade its
89    cipher suite before any HTTP communication takes place. The problem 
90    lies in allowing browsers to upgrade in this fashion, but still requiring
91    strong encryption. In other words, we want browsers to either start a 
92    connection with strong encryption, or to start with export ciphers but 
93    upgrade to strong encryption before beginning HTTP communication.</p>
94    <p>This can be done as follows:</p>
95    <div class="example"><h3>httpd.conf</h3><p><code>
96      # allow all ciphers for the initial handshake,<br />
97      # so export browsers can upgrade via SGC facility<br />
98      SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL<br />
99      <br />
100      &lt;Directory /usr/local/apache2/htdocs&gt;<br />
101      # but finally deny all browsers which haven't upgraded<br />
102      SSLRequire %{SSL_CIPHER_USEKEYSIZE} &gt;= 128<br />
103      &lt;/Directory&gt;
104    </code></p></div>
105
106
107<h3><a name="strongurl" id="strongurl">How can I create an SSL server which accepts all types of ciphers
108in general, but requires a strong ciphers for access to a particular
109URL?</a></h3>
110
111    <p>Obviously, a server-wide <code class="directive"><a href="/mod/mod_ssl.html#sslciphersuite">SSLCipherSuite</a></code> which restricts 
112    ciphers to the strong variants, isn't the answer here. However, 
113    <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> can be reconfigured within <code>Location</code>
114    blocks, to give a per-directory solution, and can automatically force
115    a renegotiation of the SSL parameters to meet the new configuration.
116    This can be done as follows:</p>
117    <div class="example"><p><code>
118      # be liberal in general<br />
119      SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL<br />
120      <br />
121      &lt;Location /strong/area&gt;<br />
122      # but https://hostname/strong/area/ and below<br />
123      # requires strong ciphers<br />
124      SSLCipherSuite HIGH:MEDIUM<br />
125      &lt;/Location&gt;
126    </code></p></div>
127
128</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
129<div class="section">
130<h2><a name="accesscontrol" id="accesscontrol">Client Authentication and Access Control</a></h2>
131
132<ul>
133<li><a href="#allclients">How can I force clients to authenticate using certificates?</a></li>
134<li><a href="#arbitraryclients">How can I force clients to authenticate using certificates for a 
135        particular URL, but still allow arbitrary clients to access the rest of the server?</a></li>
136<li><a href="#certauthenticate">How can I allow only clients who have certificates to access a
137        particular URL, but allow all clients to access the rest of the server?</a></li>
138<li><a href="#intranet">How can I require HTTPS with strong ciphers, and either
139basic authentication or client certificates, for access to part of the
140Intranet website, for clients coming from the Internet?</a></li>
141</ul>
142
143<h3><a name="allclients" id="allclients">How can I force clients to authenticate using certificates?</a></h3>
144
145
146    <p>When you know all of your users (eg, as is often the case on a corporate
147    Intranet), you can require plain certificate authentication. All you
148    need to do is to create client certificates signed by your own CA
149    certificate (<code>ca.crt</code>) and then verify the clients against this
150    certificate.</p>
151    <div class="example"><h3>httpd.conf</h3><p><code>
152      # require a client certificate which has to be directly<br />
153      # signed by our CA certificate in ca.crt<br />
154      SSLVerifyClient require<br />
155      SSLVerifyDepth 1<br />
156      SSLCACertificateFile conf/ssl.crt/ca.crt
157    </code></p></div>
158
159
160<h3><a name="arbitraryclients" id="arbitraryclients">How can I force clients to authenticate using certificates for a
161	particular URL, but still allow arbitrary clients to access the rest of the server?</a></h3>
162
163
164<p>To force clients to authenticate using certificates for a particular URL,
165	you can use the per-directory reconfiguration features of <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code>:</p>
166
167    <div class="example"><h3>httpd.conf</h3><p><code>
168    SSLVerifyClient none<br />
169    SSLCACertificateFile conf/ssl.crt/ca.crt<br />
170    <br />
171    &lt;Location /secure/area&gt;<br />
172    SSLVerifyClient require<br />
173    SSLVerifyDepth 1<br />
174    &lt;/Location&gt;<br />
175    </code></p></div>
176
177
178<h3><a name="certauthenticate" id="certauthenticate">How can I allow only clients who have certificates to access a
179	particular URL, but allow all clients to access the rest of the server?</a></h3>
180
181
182    <p>The key to doing this is checking that part of the client certificate
183    matches what you expect. Usually this means checking all or part of the
184    Distinguished Name (DN), to see if it contains some known string.
185    There are two ways to do this, using either <code class="module"><a href="/mod/mod_auth_basic.html">mod_auth_basic</a></code> or
186    <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code>.</p> 
187    
188    <p>The <code class="module"><a href="/mod/mod_auth_basic.html">mod_auth_basic</a></code> method is generally required when
189    the certificates are completely arbitrary, or when their DNs have
190    no common fields (usually the organisation, etc.). In this case,
191    you should establish a password database containing <em>all</em>
192    clients allowed, as follows:</p>
193    
194    <div class="example"><h3>httpd.conf</h3><pre>
195SSLCACertificateFile conf/ssl.crt/ca.crt
196SSLCACertificatePath conf/ssl.crt
197SSLVerifyClient      none
198
199&lt;Directory /usr/local/apache2/htdocs/secure/area&gt;
200SSLVerifyClient      require
201SSLVerifyDepth       5
202SSLOptions           +FakeBasicAuth
203SSLRequireSSL
204AuthName             "Snake Oil Authentication"
205AuthType             Basic
206AuthBasicProvider    file
207AuthUserFile         /usr/local/apache2/conf/httpd.passwd
208Require              valid-user
209&lt;/Directory&gt;</pre></div>
210    
211    <p>The password used in this example is the DES encrypted string "password".
212    See the <code class="directive"><a href="/mod/mod_ssl.html#ssloptions">SSLOptions</a></code> docs for more 
213    information.</p>
214    
215    <div class="example"><h3>httpd.passwd</h3><pre>
216/C=DE/L=Munich/O=Snake Oil, Ltd./OU=Staff/CN=Foo:xxj31ZMTZzkVA
217/C=US/L=S.F./O=Snake Oil, Ltd./OU=CA/CN=Bar:xxj31ZMTZzkVA
218/C=US/L=L.A./O=Snake Oil, Ltd./OU=Dev/CN=Quux:xxj31ZMTZzkVA</pre></div>
219
220    <p>When your clients are all part of a common hierarchy, which is encoded
221    into the DN, you can match them more easily using <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code>, as follows:</p>
222
223
224    <div class="example"><h3>httpd.conf</h3><pre>
225SSLVerifyClient      none
226SSLCACertificateFile conf/ssl.crt/ca.crt
227SSLCACertificatePath conf/ssl.crt
228
229&lt;Directory /usr/local/apache2/htdocs/secure/area&gt;
230  SSLVerifyClient      require
231  SSLVerifyDepth       5
232  SSLOptions           +FakeBasicAuth
233  SSLRequireSSL
234  SSLRequire       %{SSL_CLIENT_S_DN_O}  eq "Snake Oil, Ltd." \
235               and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"}
236&lt;/Directory&gt;</pre></div>
237
238
239<h3><a name="intranet" id="intranet">How can I require HTTPS with strong ciphers, and either basic
240authentication or client certificates, for access to part of the
241Intranet website, for clients coming from the Internet? I still want to allow
242plain HTTP access for clients on the Intranet.</a></h3>
243
244   
245   <p>These examples presume that clients on the Intranet have IPs in the range 
246   192.168.1.0/24, and that the part of the Intranet website you want to allow
247   internet access to is <code>/usr/local/apache2/htdocs/subarea</code>. 
248   This configuration should remain outside of your HTTPS virtual host, so
249   that it applies to both HTTPS and HTTP.</p>
250
251    <div class="example"><h3>httpd.conf</h3><pre>
252SSLCACertificateFile conf/ssl.crt/company-ca.crt
253
254&lt;Directory /usr/local/apache2/htdocs&gt;
255#   Outside the subarea only Intranet access is granted
256Order                deny,allow
257Deny                 from all
258Allow                from 192.168.1.0/24
259&lt;/Directory&gt;
260
261&lt;Directory /usr/local/apache2/htdocs/subarea&gt;
262#   Inside the subarea any Intranet access is allowed
263#   but from the Internet only HTTPS + Strong-Cipher + Password
264#   or the alternative HTTPS + Strong-Cipher + Client-Certificate
265
266#   If HTTPS is used, make sure a strong cipher is used.
267#   Additionally allow client certs as alternative to basic auth.
268SSLVerifyClient      optional
269SSLVerifyDepth       1
270SSLOptions           +FakeBasicAuth +StrictRequire
271SSLRequire           %{SSL_CIPHER_USEKEYSIZE} &gt;= 128
272
273#   Force clients from the Internet to use HTTPS
274RewriteEngine        on
275RewriteCond          %{REMOTE_ADDR} !^192\.168\.1\.[0-9]+$
276RewriteCond          %{HTTPS} !=on
277RewriteRule          .* - [F]
278
279#   Allow Network Access and/or Basic Auth
280Satisfy              any
281
282#   Network Access Control
283Order                deny,allow
284Deny                 from all
285Allow                192.168.1.0/24
286
287#   HTTP Basic Authentication
288AuthType             basic
289AuthName             "Protected Intranet Area"
290AuthBasicProvider    file
291AuthUserFile         conf/protected.passwd
292Require              valid-user
293&lt;/Directory&gt;</pre></div>
294
295</div></div>
296<div class="bottomlang">
297<p><span>Available Languages: </span><a href="/en/ssl/ssl_howto.html" title="English">&nbsp;en&nbsp;</a></p>
298</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
299<script type="text/javascript"><!--//--><![CDATA[//><!--
300var comments_shortname = 'httpd';
301var comments_identifier = 'http://httpd.apache.org/docs/2.2/ssl/ssl_howto.html';
302(function(w, d) {
303    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
304        d.write('<div id="comments_thread"><\/div>');
305        var s = d.createElement('script');
306        s.type = 'text/javascript';
307        s.async = true;
308        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
309        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
310    }
311    else { 
312        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
313    }
314})(window, document);
315//--><!]]></script></div><div id="footer">
316<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
317<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
318if (typeof(prettyPrint) !== 'undefined') {
319    prettyPrint();
320}
321//--><!]]></script>
322</body></html>