From 7c711596319812b9a3224c67b4ef1828bde5b16b Mon Sep 17 00:00:00 2001 From: chronolaw Date: Mon, 22 May 2023 16:36:06 +0800 Subject: [PATCH] remove cipher related code --- src/ngx_lua_resty_lmdb_module.c | 14 +--- t/10-validation-tag-cipher.t | 141 -------------------------------- 2 files changed, 1 insertion(+), 154 deletions(-) delete mode 100644 t/10-validation-tag-cipher.t diff --git a/src/ngx_lua_resty_lmdb_module.c b/src/ngx_lua_resty_lmdb_module.c index 70f4cb9e..96d8bf1e 100644 --- a/src/ngx_lua_resty_lmdb_module.c +++ b/src/ngx_lua_resty_lmdb_module.c @@ -25,9 +25,6 @@ static ngx_str_t ngx_lua_resty_lmdb_file_names[] = { }; -static ngx_cycle_t *ngx_lua_resty_lmdb_ngx_cycle; - - static void *ngx_lua_resty_lmdb_create_conf(ngx_cycle_t *cycle); static char *ngx_lua_resty_lmdb_init_conf(ngx_cycle_t *cycle, void *conf); static ngx_int_t ngx_lua_resty_lmdb_init(ngx_cycle_t *cycle); @@ -670,17 +667,11 @@ static ngx_int_t ngx_lua_resty_lmdb_init(ngx_cycle_t *cycle) return NGX_ERROR; } - /* save cycle in init phase for ngx_lua_resty_lmdb_cipher() */ - ngx_lua_resty_lmdb_ngx_cycle = cycle; - if (ngx_lua_resty_lmdb_validate(cycle, lcf) != NGX_OK) { ngx_lua_resty_lmdb_close_file(cycle, lcf); return NGX_ERROR; } - /* reset to NULL for worker processes */ - ngx_lua_resty_lmdb_ngx_cycle = NULL; - if (ngx_lua_resty_lmdb_close_file(cycle, lcf) != NGX_OK) { return NGX_ERROR; } @@ -763,16 +754,13 @@ ngx_lua_resty_lmdb_cipher(const MDB_val *src, MDB_val *dst, const MDB_val *key, int encdec) { ngx_lua_resty_lmdb_conf_t *lcf; - volatile ngx_cycle_t *cycle; u_char iv[12]; int ivl, outl, rc; mdb_size_t *ptr; EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); - cycle = ngx_lua_resty_lmdb_ngx_cycle ? ngx_lua_resty_lmdb_ngx_cycle : ngx_cycle; - - lcf = (ngx_lua_resty_lmdb_conf_t *) ngx_get_conf(cycle->conf_ctx, + lcf = (ngx_lua_resty_lmdb_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, ngx_lua_resty_lmdb_module); ngx_lua_resty_lmdb_assert(lcf->cipher != NULL); diff --git a/t/10-validation-tag-cipher.t b/t/10-validation-tag-cipher.t deleted file mode 100644 index d7c978a9..00000000 --- a/t/10-validation-tag-cipher.t +++ /dev/null @@ -1,141 +0,0 @@ -# vim:set ft= ts=4 sw=4 et: - -# run this test after 00-init_mdb.t - -use Test::Nginx::Socket::Lua; -use Cwd qw(cwd); - -repeat_each(1); - -plan tests => repeat_each() * blocks() * 5 + 2; - -my $pwd = cwd(); - -# remove db for testing -system("rm -rf /tmp/test10-cipher.mdb"); - -our $MainConfig1 = qq{ - lmdb_environment_path /tmp/test10-cipher.mdb; - lmdb_map_size 5m; - lmdb_encryption_key /etc/hostname; - lmdb_encryption_mode "chacha20-poly1305"; -}; - -our $MainConfig2 = qq{ - lmdb_environment_path /tmp/test10-cipher.mdb; - lmdb_map_size 5m; - lmdb_encryption_key /etc/hostname; - lmdb_encryption_mode "chacha20-poly1305"; - lmdb_validation_tag 3.3; -}; - -our $MainConfig3 = qq{ - lmdb_environment_path /tmp/test10-cipher.mdb; - lmdb_map_size 5m; - lmdb_encryption_key /etc/hostname; - lmdb_encryption_mode "chacha20-poly1305"; - lmdb_validation_tag 3.4; -}; - -our $HttpConfig = qq{ - lua_package_path "$pwd/lib/?.lua;;"; -}; - -no_long_string(); -#no_diff(); - -no_shuffle(); -run_tests(); - -__DATA__ - -=== TEST 1: no validation_tag ---- http_config eval: $::HttpConfig ---- main_config eval: $::MainConfig1 ---- config - location = /t { - content_by_lua_block { - local l = require("resty.lmdb") - - ngx.say(l.set("test", "value")) - ngx.say(l.get("test")) - ngx.say(l.get("test_not_exist")) - - ngx.say(l.get("validation_tag")) - } - } ---- request -GET /t ---- response_body -true -value -nil -nil ---- no_error_log -[error] -[warn] -[crit] - - -=== TEST 2: start and set validation_tag ---- http_config eval: $::HttpConfig ---- main_config eval: $::MainConfig2 ---- config - location = /t { - content_by_lua_block { - local l = require("resty.lmdb") - - ngx.say(l.get("validation_tag")) - ngx.say(l.get("test")) - - ngx.say(l.set("test", "value")) - ngx.say(l.get("test")) - ngx.say(l.get("test_not_exist")) - } - } ---- request -GET /t ---- response_body -3.3 -nil -true -value -nil ---- error_log -LMDB has no validation_tag ---- no_error_log -[emerg] -[error] -[crit] - - -=== TEST 3: change validation_tag ---- http_config eval: $::HttpConfig ---- main_config eval: $::MainConfig3 ---- config - location = /t { - content_by_lua_block { - local l = require("resty.lmdb") - - ngx.say(l.get("validation_tag")) - ngx.say(l.get("test")) - - ngx.say(l.set("test", "value")) - ngx.say(l.get("test")) - ngx.say(l.get("test_not_exist")) - } - } ---- request -GET /t ---- response_body -3.4 -nil -true -value -nil ---- error_log -LMDB validation failed ---- no_error_log -[emerg] -[error] -[crit]