@@ -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 ) {
@@ -248,6 +270,11 @@ ngx_http_encrypted_session_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
248
270
249
271
value = cf -> args -> elts ;
250
272
273
+ if (value [1 ].len > 1 && value [1 ].data [0 ] == '$' ) {
274
+ llcf -> key = & (value [1 ].data [1 ]);
275
+ return NGX_CONF_OK ;
276
+ }
277
+
251
278
if (value [1 ].len != ngx_http_encrypted_session_key_length ) {
252
279
ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 ,
253
280
"encrypted_session_key: the key must be of %d "
@@ -276,6 +303,11 @@ ngx_http_encrypted_session_iv(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
276
303
277
304
value = cf -> args -> elts ;
278
305
306
+ if (value [1 ].len > 1 && value [1 ].data [0 ] == '$' ) {
307
+ llcf -> iv = & (value [1 ].data [1 ]);
308
+ return NGX_CONF_OK ;
309
+ }
310
+
279
311
if (value [1 ].len > ngx_http_encrypted_session_iv_length ) {
280
312
ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 ,
281
313
"encrypted_session_iv: the init vector must NOT "
0 commit comments