Skip to content

Commit cd24241

Browse files
bugfix: failed to build with old ssl.
1 parent 4fbaf9c commit cd24241

14 files changed

Lines changed: 46 additions & 232 deletions

src/ngx_stream_lua_common.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
#include <lualib.h>
3232
#include <lauxlib.h>
3333

34+
#if (NGX_STREAM_SSL)
35+
36+
#include <openssl/ssl.h>
37+
38+
#ifdef HAVE_PROXY_SSL_PATCH
39+
40+
#if defined(LIBRESSL_VERSION_NUMBER)
41+
/* do nothing */
42+
#elif defined(OPENSSL_IS_BORINGSSL)
43+
/* do nothing */
44+
#elif defined(SSL_ERROR_WANT_RETRY_VERIFY) && \
45+
OPENSSL_VERSION_NUMBER >= 0x30000020uL
46+
#define HAVE_LUA_PROXY_SSL 1
47+
#endif
48+
49+
#endif /* HAVE_PROXY_SSL_PATCH */
50+
#endif /* NGX_STREAM_SSL */
3451

3552
#include "ngx_stream_lua_request.h"
3653

src/ngx_stream_lua_control.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ ngx_stream_lua_ffi_exit(ngx_stream_lua_request_t *r, int status, u_char *err,
116116
| NGX_STREAM_LUA_CONTEXT_BALANCER
117117
| NGX_STREAM_LUA_CONTEXT_SSL_CLIENT_HELLO
118118
| NGX_STREAM_LUA_CONTEXT_SSL_CERT
119-
#ifdef HAVE_PROXY_SSL_PATCH
119+
#ifdef HAVE_LUA_PROXY_SSL
120120
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_CERT
121121
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_VERIFY
122122
#endif
@@ -127,7 +127,7 @@ ngx_stream_lua_ffi_exit(ngx_stream_lua_request_t *r, int status, u_char *err,
127127
}
128128

129129
if (ctx->context & (NGX_STREAM_LUA_CONTEXT_SSL_CERT
130-
#ifdef HAVE_PROXY_SSL_PATCH
130+
#ifdef HAVE_LUA_PROXY_SSL
131131
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_CERT
132132
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_VERIFY
133133
#endif

src/ngx_stream_lua_coroutine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ ngx_stream_lua_coroutine_resume(lua_State *L)
205205
| NGX_STREAM_LUA_CONTEXT_TIMER
206206
| NGX_STREAM_LUA_CONTEXT_SSL_CLIENT_HELLO
207207
| NGX_STREAM_LUA_CONTEXT_SSL_CERT
208-
#ifdef HAVE_PROXY_SSL_PATCH
208+
#ifdef HAVE_LUA_PROXY_SSL
209209
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_CERT
210210
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_VERIFY
211211
#endif
@@ -270,7 +270,7 @@ ngx_stream_lua_coroutine_yield(lua_State *L)
270270
| NGX_STREAM_LUA_CONTEXT_TIMER
271271
| NGX_STREAM_LUA_CONTEXT_SSL_CLIENT_HELLO
272272
| NGX_STREAM_LUA_CONTEXT_SSL_CERT
273-
#ifdef HAVE_PROXY_SSL_PATCH
273+
#ifdef HAVE_LUA_PROXY_SSL
274274
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_CERT
275275
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_VERIFY
276276
#endif
@@ -434,7 +434,7 @@ ngx_stream_lua_coroutine_status(lua_State *L)
434434
| NGX_STREAM_LUA_CONTEXT_TIMER
435435
| NGX_STREAM_LUA_CONTEXT_SSL_CLIENT_HELLO
436436
| NGX_STREAM_LUA_CONTEXT_SSL_CERT
437-
#ifdef HAVE_PROXY_SSL_PATCH
437+
#ifdef HAVE_LUA_PROXY_SSL
438438
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_CERT
439439
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_VERIFY
440440
#endif

src/ngx_stream_lua_module.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "ngx_stream_lua_ssl_client_helloby.h"
3232
#include "ngx_stream_lua_ssl_certby.h"
3333

34-
#ifdef HAVE_PROXY_SSL_PATCH
34+
#ifdef HAVE_LUA_PROXY_SSL
3535
#include "ngx_stream_lua_proxy_ssl_certby.h"
3636
#include "ngx_stream_lua_proxy_ssl_verifyby.h"
3737
#endif
@@ -433,7 +433,7 @@ static ngx_command_t ngx_stream_lua_cmds[] = {
433433
0,
434434
(void *) ngx_stream_lua_ssl_cert_handler_file },
435435

436-
#if HAVE_PROXY_SSL_PATCH
436+
#if HAVE_LUA_PROXY_SSL
437437
/* same context as proxy_pass directive */
438438
{ ngx_string("proxy_ssl_certificate_by_lua_block"),
439439
NGX_STREAM_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
@@ -921,13 +921,11 @@ ngx_stream_lua_create_srv_conf(ngx_conf_t *cf)
921921

922922
conf->log_socket_errors = NGX_CONF_UNSET;
923923

924-
#if (NGX_STREAM_SSL)
924+
#ifdef HAVE_LUA_PROXY_SSL
925925
conf->ssl_verify_depth = NGX_CONF_UNSET_UINT;
926926
conf->ssl_certificates = NGX_CONF_UNSET_PTR;
927927
conf->ssl_certificate_keys = NGX_CONF_UNSET_PTR;
928-
#ifdef HAVE_PROXY_SSL_PATCH
929928
conf->ups.upstream_skip_openssl_default_verify = NGX_CONF_UNSET;
930-
#endif
931929
#endif
932930

933931
return conf;
@@ -1061,7 +1059,7 @@ ngx_stream_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
10611059
NULL);
10621060
#endif
10631061

1064-
#ifdef HAVE_PROXY_SSL_PATCH
1062+
#ifdef HAVE_LUA_PROXY_SSL
10651063
if (conf->ups.proxy_ssl_cert_src.len == 0) {
10661064
conf->ups.proxy_ssl_cert_src = prev->ups.proxy_ssl_cert_src;
10671065
conf->ups.proxy_ssl_cert_handler = prev->ups.proxy_ssl_cert_handler;

src/ngx_stream_lua_phase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ngx_stream_lua_ngx_get_phase(lua_State *L)
6666
lua_pushliteral(L, "content");
6767
break;
6868

69-
#ifdef HAVE_PROXY_SSL_PATCH
69+
#ifdef HAVE_LUA_PROXY_SSL
7070
case NGX_STREAM_LUA_CONTEXT_PROXY_SSL_CERT:
7171
lua_pushliteral(L, "proxy_ssl_cert");
7272
break;

src/ngx_stream_lua_proxy_ssl_certby.c

Lines changed: 4 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#ifndef DDEBUG
66
#define DDEBUG 0
77
#endif
8-
#include "ddebug.h"
9-
108

11-
#if (NGX_STREAM_SSL)
9+
#include "ddebug.h"
10+
#include "ngx_stream_lua_proxy_ssl_certby.h"
1211

12+
#ifdef HAVE_LUA_PROXY_SSL
1313
#include "ngx_stream_lua_cache.h"
1414
#include "ngx_stream_lua_initworkerby.h"
1515
#include "ngx_stream_lua_util.h"
@@ -18,9 +18,6 @@
1818
#include "ngx_stream_lua_directive.h"
1919
#include "ngx_stream_lua_ssl.h"
2020

21-
#ifdef HAVE_PROXY_SSL_PATCH
22-
#include "ngx_stream_lua_proxy_ssl_certby.h"
23-
2421

2522
static void ngx_stream_lua_proxy_ssl_cert_done(void *data);
2623
static void ngx_stream_lua_proxy_ssl_cert_aborted(void *data);
@@ -31,16 +28,6 @@ static ngx_int_t ngx_stream_lua_proxy_ssl_cert_by_chunk(lua_State *L,
3128
ngx_int_t
3229
ngx_stream_lua_proxy_ssl_cert_set_callback(ngx_conf_t *cf)
3330
{
34-
35-
#ifdef LIBRESSL_VERSION_NUMBER
36-
37-
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
38-
"LibreSSL does not support by proxy_ssl_certificate_by_lua*");
39-
40-
return NGX_ERROR;
41-
42-
#else
43-
4431
ngx_flag_t proxy_ssl = 0;
4532
ngx_pool_cleanup_t *cln;
4633
ngx_ssl_t *ssl;
@@ -76,22 +63,9 @@ ngx_stream_lua_proxy_ssl_cert_set_callback(ngx_conf_t *cf)
7663
return NGX_ERROR;
7764
}
7865

79-
#if OPENSSL_VERSION_NUMBER >= 0x1000205fL
80-
8166
SSL_CTX_set_cert_cb(ssl->ctx, ngx_stream_lua_proxy_ssl_cert_handler, NULL);
8267

8368
return NGX_OK;
84-
85-
#else
86-
87-
ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "OpenSSL too old to support "
88-
"proxy_ssl_certificate_by_lua*");
89-
90-
return NGX_ERROR;
91-
92-
#endif
93-
94-
#endif
9569
}
9670

9771

@@ -160,16 +134,6 @@ char *
160134
ngx_stream_lua_proxy_ssl_cert_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
161135
void *conf)
162136
{
163-
#if OPENSSL_VERSION_NUMBER < 0x1000205fL
164-
165-
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
166-
"at least OpenSSL 1.0.2e required but found "
167-
OPENSSL_VERSION_TEXT);
168-
169-
return NGX_CONF_ERROR;
170-
171-
#else
172-
173137
u_char *p;
174138
u_char *name;
175139
ngx_str_t *value;
@@ -239,8 +203,6 @@ ngx_stream_lua_proxy_ssl_cert_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
239203
}
240204

241205
return NGX_CONF_OK;
242-
243-
#endif /* OPENSSL_VERSION_NUMBER < 0x1000205fL */
244206
}
245207

246208

@@ -582,20 +544,6 @@ int
582544
ngx_stream_lua_ffi_proxy_ssl_clear_certs(ngx_stream_lua_request_t *r,
583545
char **err)
584546
{
585-
#ifdef LIBRESSL_VERSION_NUMBER
586-
587-
*err = "LibreSSL not supported";
588-
return NGX_ERROR;
589-
590-
#else
591-
592-
# if OPENSSL_VERSION_NUMBER < 0x1000205fL
593-
594-
*err = "at least OpenSSL 1.0.2e required but found " OPENSSL_VERSION_TEXT;
595-
return NGX_ERROR;
596-
597-
# else
598-
599547
ngx_stream_upstream_t *u;
600548
ngx_ssl_conn_t *ssl_conn;
601549
ngx_connection_t *c;
@@ -620,30 +568,13 @@ ngx_stream_lua_ffi_proxy_ssl_clear_certs(ngx_stream_lua_request_t *r,
620568

621569
SSL_certs_clear(ssl_conn);
622570
return NGX_OK;
623-
624-
# endif /* OPENSSL_VERSION_NUMBER < 0x1000205fL */
625-
#endif
626571
}
627572

628573

629574
int
630575
ngx_stream_lua_ffi_proxy_ssl_set_der_certificate(ngx_stream_lua_request_t *r,
631576
const char *data, size_t len, char **err)
632577
{
633-
#ifdef LIBRESSL_VERSION_NUMBER
634-
635-
*err = "LibreSSL not supported";
636-
return NGX_ERROR;
637-
638-
#else
639-
640-
# if OPENSSL_VERSION_NUMBER < 0x1000205fL
641-
642-
*err = "at least OpenSSL 1.0.2e required but found " OPENSSL_VERSION_TEXT;
643-
return NGX_ERROR;
644-
645-
# else
646-
647578
ngx_stream_upstream_t *u;
648579
ngx_ssl_conn_t *ssl_conn;
649580
ngx_connection_t *c;
@@ -722,9 +653,6 @@ ngx_stream_lua_ffi_proxy_ssl_set_der_certificate(ngx_stream_lua_request_t *r,
722653
ERR_clear_error();
723654

724655
return NGX_ERROR;
725-
726-
# endif /* OPENSSL_VERSION_NUMBER < 0x1000205fL */
727-
#endif
728656
}
729657

730658

@@ -798,20 +726,6 @@ int
798726
ngx_stream_lua_ffi_proxy_ssl_set_cert(ngx_stream_lua_request_t *r,
799727
void *cdata, char **err)
800728
{
801-
#ifdef LIBRESSL_VERSION_NUMBER
802-
803-
*err = "LibreSSL not supported";
804-
return NGX_ERROR;
805-
806-
#else
807-
808-
# if OPENSSL_VERSION_NUMBER < 0x1000205fL
809-
810-
*err = "at least OpenSSL 1.0.2e required but found " OPENSSL_VERSION_TEXT;
811-
return NGX_ERROR;
812-
813-
# else
814-
815729
#ifdef OPENSSL_IS_BORINGSSL
816730
size_t i;
817731
#else
@@ -883,9 +797,6 @@ ngx_stream_lua_ffi_proxy_ssl_set_cert(ngx_stream_lua_request_t *r,
883797
ERR_clear_error();
884798

885799
return NGX_ERROR;
886-
887-
# endif /* OPENSSL_VERSION_NUMBER < 0x1000205fL */
888-
#endif
889800
}
890801

891802

@@ -936,69 +847,4 @@ ngx_stream_lua_ffi_proxy_ssl_set_priv_key(ngx_stream_lua_request_t *r,
936847
return NGX_ERROR;
937848
}
938849

939-
940-
#else /* HAVE_PROXY_SSL_PATCH */
941-
942-
943-
int
944-
ngx_stream_lua_ffi_proxy_ssl_get_tls1_version(ngx_stream_lua_request_t *r,
945-
char **err)
946-
{
947-
*err = "Does not have HAVE_PROXY_SSL_PATCH to support this function";
948-
949-
return NGX_ERROR;
950-
}
951-
952-
953-
int
954-
ngx_stream_lua_ffi_proxy_ssl_clear_certs(ngx_stream_lua_request_t *r,
955-
char **err)
956-
{
957-
*err = "Does not have HAVE_PROXY_SSL_PATCH to support this function";
958-
959-
return NGX_ERROR;
960-
}
961-
962-
963-
int
964-
ngx_stream_lua_ffi_proxy_ssl_set_der_certificate(ngx_stream_lua_request_t *r,
965-
const char *data, size_t len, char **err)
966-
{
967-
*err = "Does not have HAVE_PROXY_SSL_PATCH to support this function";
968-
969-
return NGX_ERROR;
970-
}
971-
972-
973-
int
974-
ngx_stream_lua_ffi_proxy_ssl_set_der_private_key(ngx_stream_lua_request_t *r,
975-
const char *data, size_t len, char **err)
976-
{
977-
*err = "Does not have HAVE_PROXY_SSL_PATCH to support this function";
978-
979-
return NGX_ERROR;
980-
}
981-
982-
983-
int
984-
ngx_stream_lua_ffi_proxy_ssl_set_cert(ngx_stream_lua_request_t *r,
985-
void *cdata, char **err)
986-
{
987-
*err = "Does not have HAVE_PROXY_SSL_PATCH to support this function";
988-
989-
return NGX_ERROR;
990-
}
991-
992-
993-
int
994-
ngx_stream_lua_ffi_proxy_ssl_set_priv_key(ngx_stream_lua_request_t *r,
995-
void *cdata, char **err)
996-
{
997-
*err = "Does not have HAVE_PROXY_SSL_PATCH to support this function";
998-
999-
return NGX_ERROR;
1000-
}
1001-
1002-
1003-
#endif /* HAVE_PROXY_SSL_PATCH */
1004-
#endif /* NGX_STREAM_SSL */
850+
#endif /* HAVE_LUA_PROXY_SSL */

src/ngx_stream_lua_proxy_ssl_certby.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "ngx_stream_lua_common.h"
1010

1111

12-
#if (NGX_STREAM_SSL)
13-
#ifdef HAVE_PROXY_SSL_PATCH
12+
#ifdef HAVE_LUA_PROXY_SSL
1413

1514
/* do not introduce ngx_stream_proxy_module
1615
* to pollute ngx_stream_lua_module.c
@@ -33,8 +32,7 @@ int ngx_stream_lua_proxy_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, void *data);
3332

3433
ngx_int_t ngx_stream_lua_proxy_ssl_cert_set_callback(ngx_conf_t *cf);
3534

36-
#endif /* HAVE_PROXY_SSL_PATCH */
37-
#endif /* NGX_STREAM_SSL */
35+
#endif /* HAVE_LUA_PROXY_SSL */
3836
#endif /* _NGX_STREAM_LUA_PROXY_SSL_CERTBY_H_INCLUDED_ */
3937

4038
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

0 commit comments

Comments
 (0)