2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision: 1330964 $ -->
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
14 http://www.apache.org/licenses/LICENSE-2.0
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.
23 <modulesynopsis metafile="mod_crypto.xml.meta">
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>
33 <p>This module provides the ability to <strong>encrypt and decrypt</strong>
34 data on the input and output filter stacks.</p>
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>
41 <p>Alternatively, it can be used to deliver secure data over insecure CDN
42 to suitable clients.</p>
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>
52 <seealso><a href="../filter.html">Filters</a></seealso>
55 <title>Stream Format</title>
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>
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>
67 <title>Keys and IVs</title>
71 <directive module="mod_crypto">CryptoKey</directive>
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
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>
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.
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.
103 <section id="handler">
104 <title>Crypto Key Handler</title>
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>
111 <example><title>Crypto Key Handler with a File</title>
112 <Location /key><br />
114 SetHandler crypto-key<br />
115 CryptoCipher aes128<br />
116 CryptoKey file:/path/to/file.key<br />
120 </Location><br />
126 <title>HTTP Live Streaming</title>
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>
132 <p>The IV used for encrypting each media segment is specified within
133 HLS in one of two ways:</p>
137 Explicitly specified within an IV attribute inside the EXT-X-KEY
138 tag as a <strong>hexadecimal</strong> value.
141 Implicitly specified by interpreting the <strong>decimal</strong>
142 value of the EXT-X-MEDIA-SEQUENCE tag.
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.
151 <example><title>HLS Example - IV from media sequence</title>
152 <LocationMatch (?<SEQUENCE>[\d]+)[^\d^/]+$><br />
154 SetOutputFilter ENCRYPT<br />
155 CryptoCipher aes128<br />
156 CryptoKey file:/path/to/file.key<br />
157 CryptoIV decimal:%{env:MATCH_SEQUENCE}<br />
159 </LocationMatch><br />
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>
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>
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>
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>
197 <p>Possible values depend on the crypto driver in use, and could be one of:</p>
199 <ul><li>3des192</li><li>aes128</li><li>aes192</li><li>aes256</li></ul>
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>
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>
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>
224 <ul><li>file:</li><li>hex:</li><li>decimal:</li><li>base64:</li></ul>
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>
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>
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>
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>
252 <ul><li>file:</li><li>hex:</li><li>decimal:</li><li>base64:</li></ul>
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>
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>
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>