@@ -150,6 +150,26 @@ ngx_module_t ngx_http_encrypted_session_module = {
150
150
NGX_MODULE_V1_PADDING
151
151
};
152
152
153
+ static ngx_str_t ngx_http_get_variable_by_name (ngx_http_request_t * r ,
154
+ unsigned char * name , ngx_http_encrypted_session_conf_t * conf )
155
+ {
156
+ ngx_http_variable_value_t * v ;
157
+ ngx_str_t name_str ;
158
+ name_str .data = name ;
159
+ name_str .len = strlen ((const char * )name );
160
+
161
+ ngx_uint_t key = ngx_hash_strlow (name , name , name_str .len );
162
+ v = ngx_http_get_variable (r , & name_str , key );
163
+
164
+ if (v -> not_found ) {
165
+ return name_str ;
166
+ }
167
+
168
+ ngx_str_t var_value ;
169
+ var_value .len = v -> len ;
170
+ var_value .data = v -> data ;
171
+ return var_value ;
172
+ }
153
173
154
174
static ngx_int_t
155
175
ngx_http_set_encode_encrypted_session (ngx_http_request_t * r ,
@@ -176,9 +196,11 @@ ngx_http_set_encode_encrypted_session(ngx_http_request_t *r,
176
196
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
177
197
"encrypted_session: expires=%T" , conf -> expires );
178
198
199
+ ngx_str_t iv = ngx_http_get_variable_by_name (r , conf -> iv , conf );
200
+ ngx_str_t key = ngx_http_get_variable_by_name (r , conf -> key , conf );
201
+
179
202
rc = ngx_http_encrypted_session_aes_mac_encrypt (emcf , r -> pool ,
180
- r -> connection -> log , conf -> iv , ngx_http_encrypted_session_iv_length ,
181
- conf -> key , ngx_http_encrypted_session_key_length ,
203
+ r -> connection -> log , iv .data , iv .len , key .data , key .len ,
182
204
v -> data , v -> len , (ngx_uint_t ) conf -> expires , & dst , & len );
183
205
184
206
if (rc != NGX_OK ) {
@@ -218,9 +240,11 @@ ngx_http_set_decode_encrypted_session(ngx_http_request_t *r,
218
240
return NGX_ERROR ;
219
241
}
220
242
243
+ ngx_str_t iv = ngx_http_get_variable_by_name (r , conf -> iv , conf );
244
+ ngx_str_t key = ngx_http_get_variable_by_name (r , conf -> key , conf );
245
+
221
246
rc = ngx_http_encrypted_session_aes_mac_decrypt (emcf , r -> pool ,
222
- r -> connection -> log , conf -> iv , ngx_http_encrypted_session_iv_length ,
223
- conf -> key , ngx_http_encrypted_session_key_length ,
247
+ r -> connection -> log , iv .data , iv .len , key .data , key .len ,
224
248
v -> data , v -> len , & dst , & len );
225
249
226
250
if (rc != NGX_OK ) {
@@ -248,6 +272,11 @@ ngx_http_encrypted_session_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
248
272
249
273
value = cf -> args -> elts ;
250
274
275
+ if (value [1 ].len > 1 && value [1 ].data [0 ] == '$' ) {
276
+ llcf -> key = & (value [1 ].data [1 ]);
277
+ return NGX_CONF_OK ;
278
+ }
279
+
251
280
if (value [1 ].len != ngx_http_encrypted_session_key_length ) {
252
281
ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 ,
253
282
"encrypted_session_key: the key must be of %d "
@@ -276,6 +305,11 @@ ngx_http_encrypted_session_iv(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
276
305
277
306
value = cf -> args -> elts ;
278
307
308
+ if (value [1 ].len > 1 && value [1 ].data [0 ] == '$' ) {
309
+ llcf -> iv = & (value [1 ].data [1 ]);
310
+ return NGX_CONF_OK ;
311
+ }
312
+
279
313
if (value [1 ].len > ngx_http_encrypted_session_iv_length ) {
280
314
ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 ,
281
315
"encrypted_session_iv: the init vector must NOT "
0 commit comments