]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_crypto.xml
fix properties
[apache] / docs / manual / mod / mod_crypto.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <modulesynopsis metafile="mod_crypto.xml.meta">
24
25 <name>mod_crypto</name>
26 <description>Support for symmetrical encryption and decryption</description>
27 <status>Extension</status>
28 <sourcefile>mod_crypto.c</sourcefile>
29 <identifier>crypto_module</identifier>
30 <compatibility>Available in Apache 2.5 and later</compatibility>
31
32 <summary>
33     <p>This module provides the ability to <strong>encrypt and decrypt</strong>
34     data on the input and output filter stacks.</p>
35
36     <p>Most specifically, it can be used to implement <strong>on-the-fly HLS
37     encryption</strong> as described by
38     <a href="http://www.ietf.org/id/draft-pantos-http-live-streaming-19.txt">
39     draft-pantos-http-live-streaming-19</a>.</p>
40
41     <p>Alternatively, it can be used to deliver secure data over insecure CDN
42     to suitable clients.</p>
43
44     <p>The crypto filter may be added to either the input or the
45     output filter stacks, as appropriate, using the
46     <directive module="core">SetInputFilter</directive>,
47     <directive module="core">SetOutputFilter</directive>,
48     <directive module="mod_mime">AddOutputFilter</directive> or
49     <directive module="mod_filter">AddOutputFilterByType</directive> directives.</p>
50
51 </summary>
52 <seealso><a href="../filter.html">Filters</a></seealso>
53
54 <section id="format">
55     <title>Stream Format</title>
56
57     <p>The encrypted stream consists of an optional IV block, followed by encrypted
58     blocks using the chosen cipher. The final block is padded before being written. The
59     size of the blocks is governed by the choice of cipher in use.</p>
60
61     <p>When the IV is specified with the <directive module="mod_crypto">CryptoIV</directive>
62     directive, that IV is used, and is not written to or read from the stream.</p>
63
64 </section>
65
66 <section id="config">
67     <title>Keys and IVs</title>
68
69     <p>
70         The
71         <directive module="mod_crypto">CryptoKey</directive>
72         and
73         <directive module="mod_crypto">CryptoIV</directive>
74         directives expect binary
75         values which can be specified in a number of ways as below. The most significant bits of the relevant values
76         are used, and if the values are too short, they are padded on the left
77         with zero bits.
78     </p>
79
80     <dl>
81     <dt>file:</dt><dd>Read the value directly from the given file.</dd>
82     <dt>hex:</dt><dd>Parse the expression as a hex value, which may contain colon separators.</dd>
83     <dt>decimal:</dt><dd>Parse the expression as a decimal value.</dd>
84     <dt>base64:</dt><dd>Parse the expression as a base64 value.</dd>
85     <dt>none</dt><dd>No value is specified.</dd>
86     </dl>
87
88     <p>If the IV is unspecified a random IV will be generated during
89         encryption and written
90         as the first block. During decryption, the first block will be
91         interpreted as the IV.
92     </p>
93
94     <p>With the exception of file:, the <directive module="mod_crypto">CryptoKey</directive>
95        and <directive module="mod_crypto">CryptoIV</directive> directives allow
96        <a href="../expr.html">expression syntax</a> to provide flexibility when setting the values.
97        This allows both keys and IVs to be salted with values available to the webserver, such
98        as REMOTE_USER, or the URL.
99     </p>
100
101 </section>
102
103 <section id="handler">
104     <title>Crypto Key Handler</title>
105
106     <p>For convenience, the <strong>crypto-key</strong> handler can be used to serve the key
107     to suitably authorized clients, removing the need to store the key within the directory
108     space of the webserver. This also allows the same <a href="../expr.html">expression
109     syntax</a> to be used to derive the key for both the clients and the encrypted content.</p>
110
111     <example><title>Crypto Key Handler with a File</title>
112       &lt;Location /key&gt;<br />
113       <indent>
114         SetHandler crypto-key<br />
115         CryptoCipher aes128<br />
116         CryptoKey file:/path/to/file.key<br />
117         AuthType basic<br />
118         ...<br />
119         </indent>
120       &lt;/Location&gt;<br />
121     </example>
122
123 </section>
124
125 <section id="hls">
126     <title>HTTP Live Streaming</title>
127
128     <p>The HLS protocol supports encrypted streams using the AES-128 cipher and a
129     corresponding key. Access is granted to the stream by sharing the key with
130     the HLS client, typically over a secured connection.</p>
131
132     <p>The IV used for encrypting each media segment is specified within
133         HLS in one of two ways:</p>
134
135     <ul>
136         <li>
137             Explicitly specified within an IV attribute inside the EXT-X-KEY
138             tag as a <strong>hexadecimal</strong> value.
139         </li>
140         <li>
141             Implicitly specified by interpreting the <strong>decimal</strong>
142             value of the EXT-X-MEDIA-SEQUENCE tag.
143         </li>
144     </ul>
145
146     <p>The media sequence value is usually embedded within the media
147         segment filenames, and can be matched by using named regular
148         expressions as per the example below.
149     </p>
150
151     <example><title>HLS Example - IV from media sequence</title>
152       &lt;LocationMatch (?&lt;SEQUENCE&gt;[\d]+)[^\d^/]+$&gt;<br />
153       <indent>
154         SetOutputFilter ENCRYPT<br />
155         CryptoCipher aes128<br />
156         CryptoKey file:/path/to/file.key<br />
157         CryptoIV decimal:%{env:MATCH_SEQUENCE}<br />
158         </indent>
159       &lt;/LocationMatch&gt;<br />
160     </example>
161
162 </section>
163
164 <directivesynopsis>
165 <name>CryptoDriver</name>
166 <description>Name of the crypto driver to use</description>
167 <syntax>CryptoDriver name</syntax>
168 <default>CryptoDriver openssl</default>
169 <contextlist><context>server config</context>
170 </contextlist>
171
172 <usage>
173     <p>The <directive module="mod_crypto">CryptoDriver</directive>
174     directive specifies the name of the crypto driver to use. There is usually
175     a recommended default driver on each platform. Possible values include
176     <strong>openssl</strong>, <strong>commoncrypto</strong> and
177     <strong>nss</strong>.</p>
178 </usage>
179 </directivesynopsis>
180
181 <directivesynopsis>
182 <name>CryptoCipher</name>
183 <description>Cipher to be used by the crypto filter</description>
184 <syntax>CryptoCipher name</syntax>
185 <default>CryptoCipher aes256</default>
186 <contextlist><context>server config</context>
187 <context>virtual host</context>
188 <context>directory</context>
189 <context>.htaccess</context>
190 </contextlist>
191
192 <usage>
193     <p>The <directive>CryptoCipher</directive> directive allows specification of
194     the cipher to be used during encryption or decryption. If not specified, the
195     cipher defaults to <code>aes256</code>.</p>
196
197     <p>Possible values depend on the crypto driver in use, and could be one of:</p>
198
199     <ul><li>3des192</li><li>aes128</li><li>aes192</li><li>aes256</li></ul>
200
201 </usage>
202 </directivesynopsis>
203
204 <directivesynopsis>
205 <name>CryptoIV</name>
206 <description>IV (Initialisation Vector) to be used by the crypto filter</description>
207 <syntax>CryptoIV value</syntax>
208 <default>CryptoIV none</default>
209 <contextlist><context>server config</context>
210 <context>virtual host</context>
211 <context>directory</context>
212 <context>.htaccess</context>
213 </contextlist>
214
215 <usage>
216     <p>The <directive>CryptoIV</directive> directive allows the IV (initialisation
217     vector) to be specified for the particular URL space. The IV can be read from
218     a file, or can be set based on the <a href="../expr.html">expression parser</a>,
219     allowing for flexible scenarios for the setting of keys.</p>
220
221     <p>Values can be specified as read from a file, or as a hexadecimal, decimal or
222     base64 value based on the following prefixes:</p>
223
224     <ul><li>file:</li><li>hex:</li><li>decimal:</li><li>base64:</li></ul>
225
226     <p>The value 'none' disables setting of the IV. In this case, during encryption
227     a random IV will be generated and inserted as the first block, and during
228     decryption the first block will interpreted as the IV.</p>
229 </usage>
230 </directivesynopsis>
231
232 <directivesynopsis>
233 <name>CryptoKey</name>
234 <description>Key to be used by the crypto filter</description>
235 <syntax>CryptoKey value</syntax>
236 <default>CryptoKey none</default>
237 <contextlist><context>server config</context>
238 <context>virtual host</context>
239 <context>directory</context>
240 <context>.htaccess</context>
241 </contextlist>
242
243 <usage>
244     <p>The <directive>CryptoKey</directive> directive allows the encryption / decryption
245     key to be specified for the particular URL space. The key can be read from a file, or
246     can be set based on the <a href="../expr.html">expression parser</a>, allowing for
247     flexible scenarios for the setting of keys.</p>
248
249     <p>Values can be specified as read from a file, or as a hexadecimal, decimal or
250     base64 value based on the following prefixes:</p>
251
252     <ul><li>file:</li><li>hex:</li><li>decimal:</li><li>base64:</li></ul>
253
254     <p>The value 'none' disables the key. An attempt to serve a file through the ENCRYPT
255     or DECRYPT filters without a key will cause the request to fail.</p>
256 </usage>
257 </directivesynopsis>
258
259 <directivesynopsis>
260 <name>CryptoSize</name>
261 <description>Maximum size in bytes to buffer by the crypto filter</description>
262 <syntax>CryptoSize integer</syntax>
263 <default>CryptoSize 131072</default>
264 <contextlist><context>server config</context>
265 <context>virtual host</context>
266 <context>directory</context>
267 <context>.htaccess</context>
268 </contextlist>
269
270 <usage>
271     <p>The <directive module="mod_crypto">CryptoSize</directive>
272     directive specifies the amount of data in bytes that will be
273     buffered before being encrypted or decrypted during each request.
274     The default is 128 kilobytes.</p>
275 </usage>
276 </directivesynopsis>
277
278 </modulesynopsis>