Skip to content

Commit 88e92d6

Browse files
committed
An IV should be generated for each encryption
We now have the ability to decide if the IV is communicated to the client in a non forgeable manner or we only keep it on the server side. Closes openresty#2
1 parent 99662f8 commit 88e92d6

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/ngx_http_encrypted_session_module.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct {
2121
u_char *key;
2222
u_char *iv;
2323
time_t expires;
24-
24+
ngx_flag_t iv_in_content;
2525
} ngx_http_encrypted_session_conf_t;
2626

2727

@@ -42,6 +42,8 @@ static char *ngx_http_encrypted_session_iv(ngx_conf_t *cf, ngx_command_t *cmd,
4242
static char *ngx_http_encrypted_session_expires(ngx_conf_t *cf,
4343
ngx_command_t *cmd, void *conf);
4444

45+
static char *ngx_http_encrypted_iv_in_content(ngx_conf_t *cf,
46+
ngx_command_t *cmd, void *conf);
4547

4648
static ngx_int_t ngx_http_encrypted_session_init(ngx_conf_t *cf);
4749
static void *ngx_http_encrypted_session_create_main_conf(ngx_conf_t *cf);
@@ -53,7 +55,6 @@ static void *ngx_http_encrypted_session_create_conf(ngx_conf_t *cf);
5355
static char *ngx_http_encrypted_session_merge_conf(ngx_conf_t *cf, void *parent,
5456
void *child);
5557

56-
5758
static ndk_set_var_t ngx_http_set_encode_encrypted_session_filter = {
5859
NDK_SET_VAR_VALUE,
5960
(void *) ngx_http_set_encode_encrypted_session,
@@ -115,7 +116,14 @@ static ngx_command_t ngx_http_encrypted_session_commands[] = {
115116
0,
116117
&ngx_http_set_decode_encrypted_session_filter
117118
},
118-
119+
{ ngx_string("include_iv_in_encrypted_payload"),
120+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
121+
|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_NOARGS,
122+
ngx_http_encrypted_iv_in_content,
123+
NGX_HTTP_LOC_CONF_OFFSET,
124+
0,
125+
NULL
126+
},
119127
ngx_null_command
120128
};
121129

@@ -360,6 +368,13 @@ ngx_http_encrypted_session_expires(ngx_conf_t *cf, ngx_command_t *cmd,
360368
return NGX_CONF_OK;
361369
}
362370

371+
static char *ngx_http_encrypted_iv_in_content(ngx_conf_t *cf,
372+
ngx_command_t *cmd, void *conf)
373+
{
374+
ngx_http_encrypted_session_conf_t *llcf = conf;
375+
llcf->iv_in_content = 1;
376+
return NGX_CONF_OK;
377+
}
363378

364379
static void
365380
ngx_http_encrypted_session_free_cipher_ctx(void *data)
@@ -437,6 +452,7 @@ ngx_http_encrypted_session_create_conf(ngx_conf_t *cf)
437452
conf->key = NGX_CONF_UNSET_PTR;
438453
conf->iv = NGX_CONF_UNSET_PTR;
439454
conf->expires = NGX_CONF_UNSET;
455+
conf->iv_in_content = NGX_CONF_UNSET;
440456

441457
return conf;
442458
}
@@ -455,6 +471,7 @@ ngx_http_encrypted_session_merge_conf(ngx_conf_t *cf, void *parent, void *child)
455471

456472
ngx_conf_merge_value(conf->expires, prev->expires,
457473
ngx_http_encrypted_session_default_expires);
474+
ngx_conf_merge_value(conf->iv_in_content, prev->iv_in_content, 0);
458475

459476
return NGX_CONF_OK;
460477
}

0 commit comments

Comments
 (0)