Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: added ssl_certificiate_by_lua* directives to allow controlling downstream SSL handshakes with Lua #637

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e7705e5
feature: implemented the ssl_certificate_by_lua and ssl_certificate_b…
agentzh Sep 24, 2014
5b81bc6
tests: added passing tests for set DER certificate chain.
agentzh Sep 24, 2014
dd5644e
feature: implemented the ssl_certificate_by_lua and ssl_certificate_b…
agentzh Sep 24, 2014
e5fbd97
tests: added passing tests for set DER certificate chain.
agentzh Sep 24, 2014
11c1131
feature: ngx.ssl: renamed set_der_pkey to set_der_priv_key. also adde…
agentzh Sep 29, 2014
c04b57e
Merge branch 'ssl-cert-by-lua' of ssh://stash.cloudflare.com:7999/MIR…
agentzh Sep 29, 2014
942d460
refactor: renamed the "ctx" field in ngx_ssl_connection_t to "lua_ctx".
agentzh Oct 14, 2014
e2db181
feature: added the get_ocsp_responder_from_der_chain() function to th…
agentzh Oct 14, 2014
418a977
feature: added the create_ocsp_request() function to the ngx.ssl Lua …
agentzh Oct 15, 2014
3a170b4
feature: added new function validate_ocsp_response() to the ngx.ssl L…
agentzh Oct 16, 2014
da70dfe
style: minor fixes.
agentzh Oct 16, 2014
7c09341
feature: tcpsock:sslhandshake(): added an optional 5th argument, "sta…
agentzh Oct 16, 2014
08300ab
ngx.ssl: make use of the new FFI_BUSY constant in the latest lua-rest…
agentzh Oct 16, 2014
d66e6f1
feature: ngx.ssl: added new Lua function set_ocsp_status_resp().
agentzh Oct 16, 2014
4eec342
bugfix: ssl_certificate_by_lua: memory issues might happen in ngx_htt…
agentzh Oct 17, 2014
8c3c48b
feature: ngx.ssl: added new Lua functions get_tls1_version() and get_…
agentzh Oct 18, 2014
f278484
ssl_certificate_by_lua: removed unused code.
agentzh Oct 18, 2014
01ba35b
ssl_certificate_by_lua*: enabled the ngx.exit() API function in this …
agentzh Oct 18, 2014
26a31d4
Merge branch 'master' into ssl-cert-by-lua
agentzh Oct 29, 2014
1a0c632
bugfix: ngx.get_phase() did not work in the context of ssl_certificat…
agentzh Oct 29, 2014
73edb09
Merge branch 'master' into ssl-cert-by-lua
agentzh Oct 29, 2014
a05bca3
ssl: we did not clear OpenSSL's error stack when OCSP response valida…
agentzh Nov 4, 2014
d29e1af
removed --- ONLY from 014-bugs.t.
agentzh Nov 15, 2014
da1803f
bugfix: we did not abort our set cert cb as soon as the main ssl conn…
agentzh Nov 15, 2014
99663aa
merge master into ssl-cert-by-lua.
agentzh Nov 26, 2014
c3b90b3
bugfix: fixed a merge issue.
agentzh Nov 26, 2014
c1ef760
feature: ssl_certificate_by_lua*: now error messages contain the ", c…
agentzh Nov 27, 2014
c3c07c1
Merge branch 'master' into ssl-cert-by-lua
agentzh Dec 10, 2014
146763c
Merge branch 'master' into ssl-cert-by-lua
agentzh Dec 10, 2014
903fd2b
Merge branch 'master' into ssl-cert-by-lua
agentzh Jan 20, 2015
3dccace
bugfix: we did not print proper context name for ssl_certificate_by_l…
agentzh Feb 10, 2015
2e18b38
Merge branch 'master' into ssl-cert-by-lua
agentzh Feb 20, 2015
ceddd21
bugfix: ssl_certificate_by_lua_file could not be used in the server {…
agentzh Mar 19, 2015
f4c7cba
fixed a comment in ngx_http_lua_create_srv_conf.
agentzh Mar 20, 2015
1b2e4f5
Merge remote-tracking branch 'origin/master' into ssl-cert-by-lua
agentzh Mar 24, 2015
bee2165
Merge remote-tracking branch 'openresty/master' into ssl-cert-by-lua
agentzh Mar 24, 2015
6d378bd
minor coding style fixes.
agentzh Mar 24, 2015
58daafa
fixed a potential test failure for ssl_certificate_by_lua. thanks Shu…
agentzh Mar 31, 2015
b4eeb04
Merge branch 'master' into ssl-cert-by-lua
agentzh Jul 9, 2015
f0b5373
merged the latest master (v0.9.20) into ssl-cert-by-lua.
agentzh Dec 23, 2015
7eb1757
fixed merge issues in the previous commit; also fixed the test suite …
agentzh Dec 23, 2015
c0121f0
merged git master (v0.10.0) into ssl-cert-by-lua.
agentzh Jan 1, 2016
1d2bada
util/build2.sh: added support for changing openssl libs at runtime vi…
agentzh Jan 1, 2016
2805992
avoided hard-coded copyright year in the Lua source.
agentzh Jan 1, 2016
6a53b1b
bugfix: fixed compilation errors with OpenSSL older than 1.0.2.
agentzh Jan 1, 2016
5311b18
various minor fixes.
agentzh Jan 1, 2016
6b450e5
Merge branch 'master' into ssl-cert-by-lua
agentzh Jan 2, 2016
9e2c0e4
renamed source files ngx_http_lua_sslcertby.[ch] to ngx_http_lua_ssl_…
agentzh Jan 2, 2016
4fd4087
refator: moved OCSP related FFI C API functions from ngx_http_lua_ssl…
agentzh Jan 2, 2016
17409ee
minor tweaks in tests.
agentzh Jan 2, 2016
eea52ab
tests: renamed t/130-ssl-cert-by.t to t/139-ssl-cert-by.t.
agentzh Jan 2, 2016
3648acb
bugfix: compilation failed without http_ssl_module in the nginx build.
agentzh Jan 2, 2016
7caa2f8
feature: enabled the coroutine.* API in the context of ssl_certificat…
agentzh Jan 2, 2016
bbc75f2
feature: enabled the ngx.thread.* API in the context of ssl_certifica…
agentzh Jan 2, 2016
b4675a5
replaced ssl_certificate_by_lua "..." with ssl_certificate_by_lua_blo…
agentzh Jan 2, 2016
ba66f24
refactor: extracted the OCSP related API from the ngx.ssl module to f…
agentzh Jan 2, 2016
29523de
resolved issues due to the most recent merge.
agentzh Jan 2, 2016
ed9663d
refactor: removed the Lua modules ngx.ssl and ngx.ocsp and their rela…
agentzh Jan 2, 2016
16cb774
refactor: now we no longer rely on the lua_ctx field added by patchin…
agentzh Jan 2, 2016
0659a97
minor coding style tweaks.
agentzh Jan 3, 2016
fd56abd
feature: enabled the ngx.semaphore API in the ssl_certificate_by_lua*…
agentzh Jan 3, 2016
d391688
Merge branch 'master' into ssl-cert-by-lua-2
agentzh Jan 3, 2016
e238794
Merge branch 'master' into ssl-cert-by-lua-2
agentzh Jan 3, 2016
4d02c3f
feature: enabled the datagram-typed cosocket API in the context of ss…
agentzh Jan 3, 2016
34596e1
documented the ssl_certificate_by_lua* directives.
agentzh Jan 3, 2016
050221a
resolved conflicts while merging "master" into "ssl-cert-by-lua-2".
agentzh Jan 3, 2016
d014f9a
added pure C API function, ngx_http_lua_ffi_priv_key_pem_to_der. than…
agentzh Jan 3, 2016
acd0109
doc: updated TODO to reflect recent changes.
agentzh Jan 3, 2016
3ab6105
doc: fixed links for ssl_certificate_by_lua*.
agentzh Jan 3, 2016
f8200c4
doc: mentioned ngx.ssl and ngx.ocsp in the Lua API section.
agentzh Jan 3, 2016
76a4fa9
doc: documented the optional "send_status_req" argument of sslhandsha…
agentzh Jan 4, 2016
ec10995
removed patches/nginx-ssl-cert.patch which is now obsolete.
agentzh Jan 4, 2016
d03fd00
bugfix: ssl.raw_server_addr: avoided using constants like AF_INET6 in…
agentzh Jan 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ src/uthread.[ch]
src/timer.[ch]
src/config.[ch]
src/worker.[ch]
src/certby.[ch]
src/ocsp.c
src/lex.[ch]
src/balancer.[ch]
src/semaphore.[ch]
Expand Down
208 changes: 175 additions & 33 deletions README.markdown

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/src/ngx_http_lua_timer.c \
$ngx_addon_dir/src/ngx_http_lua_config.c \
$ngx_addon_dir/src/ngx_http_lua_worker.c \
$ngx_addon_dir/src/ngx_http_lua_ssl_certby.c \
$ngx_addon_dir/src/ngx_http_lua_ssl_ocsp.c \
$ngx_addon_dir/src/ngx_http_lua_lex.c \
$ngx_addon_dir/src/ngx_http_lua_balancer.c \
"
Expand Down Expand Up @@ -407,6 +409,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ngx_addon_dir/src/ngx_http_lua_timer.h \
$ngx_addon_dir/src/ngx_http_lua_config.h \
$ngx_addon_dir/src/ngx_http_lua_worker.h \
$ngx_addon_dir/src/ngx_http_lua_ssl_certby.h \
$ngx_addon_dir/src/ngx_http_lua_lex.h \
$ngx_addon_dir/src/ngx_http_lua_balancer.h \
"
Expand Down
191 changes: 158 additions & 33 deletions doc/HttpLuaModule.wiki

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions src/ngx_http_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#endif


#if (!defined OPENSSL_NO_OCSP && defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
# define NGX_HTTP_LUA_USE_OCSP 1
#endif


#ifndef MD5_DIGEST_LENGTH
#define MD5_DIGEST_LENGTH 16
#endif
Expand Down Expand Up @@ -95,6 +100,7 @@ typedef struct {
#define NGX_HTTP_LUA_CONTEXT_TIMER 0x080
#define NGX_HTTP_LUA_CONTEXT_INIT_WORKER 0x100
#define NGX_HTTP_LUA_CONTEXT_BALANCER 0x200
#define NGX_HTTP_LUA_CONTEXT_SSL_CERT 0x400


#ifndef NGX_LUA_NO_FFI_API
Expand All @@ -104,7 +110,7 @@ typedef struct {


typedef struct ngx_http_lua_main_conf_s ngx_http_lua_main_conf_t;
typedef struct ngx_http_lua_srv_conf_s ngx_http_lua_srv_conf_t;
typedef union ngx_http_lua_srv_conf_u ngx_http_lua_srv_conf_t;


typedef struct ngx_http_lua_balancer_peer_data_s
Expand All @@ -114,7 +120,7 @@ typedef struct ngx_http_lua_balancer_peer_data_s
typedef struct ngx_http_lua_semaphore_mm_s ngx_http_lua_semaphore_mm_t;


typedef ngx_int_t (*ngx_http_lua_conf_handler_pt)(ngx_log_t *log,
typedef ngx_int_t (*ngx_http_lua_main_conf_handler_pt)(ngx_log_t *log,
ngx_http_lua_main_conf_t *lmcf, lua_State *L);
typedef ngx_int_t (*ngx_http_lua_srv_conf_handler_pt)(ngx_http_request_t *r,
ngx_http_lua_srv_conf_t *lmcf, lua_State *L);
Expand Down Expand Up @@ -156,11 +162,11 @@ struct ngx_http_lua_main_conf_s {
ngx_flag_t postponed_to_rewrite_phase_end;
ngx_flag_t postponed_to_access_phase_end;

ngx_http_lua_conf_handler_pt init_handler;
ngx_str_t init_src;
ngx_http_lua_main_conf_handler_pt init_handler;
ngx_str_t init_src;

ngx_http_lua_conf_handler_pt init_worker_handler;
ngx_str_t init_worker_src;
ngx_http_lua_main_conf_handler_pt init_worker_handler;
ngx_str_t init_worker_src;

ngx_http_lua_balancer_peer_data_t *balancer_peer_data;
/* balancer_by_lua does not support yielding and
Expand All @@ -182,7 +188,15 @@ struct ngx_http_lua_main_conf_s {
};


struct ngx_http_lua_srv_conf_s {
union ngx_http_lua_srv_conf_u {
#if (NGX_HTTP_SSL)
struct {
ngx_http_lua_srv_conf_handler_pt cert_handler;
ngx_str_t cert_src;
u_char *cert_src_key;
} ssl;
#endif

struct {
ngx_str_t src;
u_char *src_key;
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_lua_contentby.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ngx_http_lua_common.h"


ngx_int_t ngx_http_lua_content_by_chunk(lua_State *l, ngx_http_request_t *r);
ngx_int_t ngx_http_lua_content_by_chunk(lua_State *L, ngx_http_request_t *r);
void ngx_http_lua_content_wev_handler(ngx_http_request_t *r);
ngx_int_t ngx_http_lua_content_handler_file(ngx_http_request_t *r);
ngx_int_t ngx_http_lua_content_handler_inline(ngx_http_request_t *r);
Expand Down
46 changes: 43 additions & 3 deletions src/ngx_http_lua_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ ngx_http_lua_ngx_redirect(lua_State *L)
static int
ngx_http_lua_ngx_exit(lua_State *L)
{
ngx_int_t rc;
ngx_http_request_t *r;
ngx_http_lua_ctx_t *ctx;
ngx_int_t rc;

if (lua_gettop(L) != 1) {
return luaL_error(L, "expecting one argument");
Expand All @@ -317,10 +317,30 @@ ngx_http_lua_ngx_exit(lua_State *L)
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_HEADER_FILTER
| NGX_HTTP_LUA_CONTEXT_BALANCER);
| NGX_HTTP_LUA_CONTEXT_BALANCER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT);

rc = (ngx_int_t) luaL_checkinteger(L, 1);

if (ctx->context == NGX_HTTP_LUA_CONTEXT_SSL_CERT) {

#if (NGX_HTTP_SSL)

ctx->exit_code = rc;
ctx->exited = 1;

ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua exit with code %i", rc);

return lua_yield(L, 0);

#else

return luaL_error(L, "no SSL support");

#endif
}

if (ctx->no_abort
&& rc != NGX_ERROR
&& rc != NGX_HTTP_CLOSE
Expand Down Expand Up @@ -438,13 +458,33 @@ ngx_http_lua_ffi_exit(ngx_http_request_t *r, int status, u_char *err,
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_HEADER_FILTER,
| NGX_HTTP_LUA_CONTEXT_HEADER_FILTER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT,
err, errlen)
!= NGX_OK)
{
return NGX_ERROR;
}

if (ctx->context == NGX_HTTP_LUA_CONTEXT_SSL_CERT) {

#if (NGX_HTTP_SSL)

ctx->exit_code = status;
ctx->exited = 1;

ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua exit with code %d", status);

return NGX_OK;

#else

return NGX_ERROR;

#endif
}

if (ctx->no_abort
&& status != NGX_ERROR
&& status != NGX_HTTP_CLOSE
Expand Down
12 changes: 8 additions & 4 deletions src/ngx_http_lua_coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ ngx_http_lua_coroutine_create_helper(lua_State *L, ngx_http_request_t *r,
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER);
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT);

vm = ngx_http_lua_get_lua_vm(r, ctx);

Expand Down Expand Up @@ -151,7 +152,8 @@ ngx_http_lua_coroutine_resume(lua_State *L)
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER);
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT);

p_coctx = ctx->cur_co_ctx;
if (p_coctx == NULL) {
Expand Down Expand Up @@ -210,7 +212,8 @@ ngx_http_lua_coroutine_yield(lua_State *L)
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER);
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT);

coctx = ctx->cur_co_ctx;

Expand Down Expand Up @@ -358,7 +361,8 @@ ngx_http_lua_coroutine_status(lua_State *L)
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER);
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT);

coctx = ngx_http_lua_get_co_ctx(co, ctx);
if (coctx == NULL) {
Expand Down
5 changes: 3 additions & 2 deletions src/ngx_http_lua_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ngx_http_lua_initby.h"
#include "ngx_http_lua_initworkerby.h"
#include "ngx_http_lua_shdict.h"
#include "ngx_http_lua_ssl_certby.h"
#include "ngx_http_lua_lex.h"


Expand Down Expand Up @@ -1126,7 +1127,7 @@ ngx_http_lua_init_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}

lmcf->init_handler = (ngx_http_lua_conf_handler_pt) cmd->post;
lmcf->init_handler = (ngx_http_lua_main_conf_handler_pt) cmd->post;

if (cmd->post == ngx_http_lua_init_by_file) {
name = ngx_http_lua_rebase_path(cf->pool, value[1].data,
Expand Down Expand Up @@ -1186,7 +1187,7 @@ ngx_http_lua_init_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,

value = cf->args->elts;

lmcf->init_worker_handler = (ngx_http_lua_conf_handler_pt) cmd->post;
lmcf->init_worker_handler = (ngx_http_lua_main_conf_handler_pt) cmd->post;

if (cmd->post == ngx_http_lua_init_worker_by_file) {
name = ngx_http_lua_rebase_path(cf->pool, value[1].data,
Expand Down
58 changes: 58 additions & 0 deletions src/ngx_http_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "ngx_http_lua_probe.h"
#include "ngx_http_lua_semaphore.h"
#include "ngx_http_lua_balancer.h"
#include "ngx_http_lua_ssl_certby.h"
#include <openssl/ssl.h>


#if !defined(nginx_version) || nginx_version < 8054
Expand All @@ -38,6 +40,7 @@ static void *ngx_http_lua_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_lua_merge_srv_conf(ngx_conf_t *cf, void *parent,
void *child);
static void *ngx_http_lua_create_loc_conf(ngx_conf_t *cf);

static char *ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent,
void *child);
static ngx_int_t ngx_http_lua_init(ngx_conf_t *cf);
Expand Down Expand Up @@ -506,6 +509,24 @@ static ngx_command_t ngx_http_lua_cmds[] = {
offsetof(ngx_http_lua_loc_conf_t, ssl_ciphers),
NULL },

#if (NGX_HTTP_SSL)

{ ngx_string("ssl_certificate_by_lua_block"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
ngx_http_lua_ssl_cert_by_lua_block,
NGX_HTTP_SRV_CONF_OFFSET,
0,
(void *) ngx_http_lua_ssl_cert_handler_inline },

{ ngx_string("ssl_certificate_by_lua_file"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
ngx_http_lua_ssl_cert_by_lua,
NGX_HTTP_SRV_CONF_OFFSET,
0,
(void *) ngx_http_lua_ssl_cert_handler_file },

#endif /* NGX_HTTP_SSL */

{ ngx_string("lua_ssl_verify_depth"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
Expand Down Expand Up @@ -840,6 +861,9 @@ ngx_http_lua_create_srv_conf(ngx_conf_t *cf)
}

/* set by ngx_pcalloc:
* lscf->ssl.cert_handler = NULL;
* lscf->ssl.cert_src = { 0, NULL };
* lscf->ssl.cert_src_key = NULL;
* lscf->balancer.handler = NULL;
* lscf->balancer.src = { 0, NULL };
* lscf->balancer.src_key = NULL;
Expand All @@ -852,6 +876,40 @@ ngx_http_lua_create_srv_conf(ngx_conf_t *cf)
static char *
ngx_http_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{
#if (NGX_HTTP_SSL)

ngx_http_lua_srv_conf_t *prev = parent;
ngx_http_lua_srv_conf_t *conf = child;
ngx_http_ssl_srv_conf_t *sscf;

dd("merge srv conf");

if (conf->ssl.cert_src.len == 0) {
conf->ssl.cert_src = prev->ssl.cert_src;
conf->ssl.cert_handler = prev->ssl.cert_handler;
}

if (conf->ssl.cert_src.len) {
sscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_ssl_module);
if (sscf == NULL || sscf->ssl.ctx == NULL) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"no ssl configured for the server");

return NGX_CONF_ERROR;
}

#if OPENSSL_VERSION_NUMBER >= 0x1000205fL

SSL_CTX_set_cert_cb(sscf->ssl.ctx, ngx_http_lua_ssl_cert_handler, NULL);

#else

return NGX_CONF_ERROR;

#endif
}

#endif /* NGX_HTTP_SSL */
return NGX_CONF_OK;
}

Expand Down
4 changes: 4 additions & 0 deletions src/ngx_http_lua_phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ ngx_http_lua_ngx_get_phase(lua_State *L)
lua_pushliteral(L, "timer");
break;

case NGX_HTTP_LUA_CONTEXT_SSL_CERT:
lua_pushliteral(L, "ssl_cert");
break;

default:
return luaL_error(L, "unknown phase: %d", (int) ctx->context);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ngx_http_lua_semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ ngx_http_lua_ffi_semaphore_wait(ngx_http_request_t *r,
rc = ngx_http_lua_ffi_check_context(ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER,
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT,
err, errlen);

if (rc != NGX_OK) {
Expand Down
3 changes: 2 additions & 1 deletion src/ngx_http_lua_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ ngx_http_lua_ngx_sleep(lua_State *L)
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER);
| NGX_HTTP_LUA_CONTEXT_TIMER
| NGX_HTTP_LUA_CONTEXT_SSL_CERT);

coctx = ctx->cur_co_ctx;
if (coctx == NULL) {
Expand Down
Loading