Created
February 28, 2019 08:48
ssl_certificate_by_lua server_port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ruN openresty-1.13.6.2/bundle/lua-resty-core-0.1.15/lib/ngx/ssl.lua openresty-1.13.6.2-patched/bundle/lua-resty-core-0.1.15/lib/ngx/ssl.lua | |
--- openresty-1.13.6.2/bundle/lua-resty-core-0.1.15/lib/ngx/ssl.lua 2018-04-23 02:47:22.000000000 +0800 | |
+++ openresty-1.13.6.2-patched/bundle/lua-resty-core-0.1.15/lib/ngx/ssl.lua 2019-02-28 16:13:56.422720600 +0800 | |
@@ -38,6 +38,9 @@ | |
int ngx_http_lua_ffi_ssl_server_name(ngx_http_request_t *r, char **name, | |
size_t *namelen, char **err); | |
+int ngx_http_lua_ffi_ssl_server_port(ngx_http_request_t *r, | |
+ int *port, char **err); | |
+ | |
int ngx_http_lua_ffi_ssl_raw_client_addr(ngx_http_request_t *r, char **addr, | |
size_t *addrlen, int *addrtype, char **err); | |
@@ -162,6 +165,25 @@ | |
end | |
if rc == FFI_DECLINED then | |
+ return nil | |
+ end | |
+ | |
+ return nil, ffi_str(errmsg[0]) | |
+end | |
+ | |
+ | |
+function _M.server_port() | |
+ local r = getfenv(0).__ngx_req | |
+ if not r then | |
+ error("no request found") | |
+ end | |
+ | |
+ local rc = C.ngx_http_lua_ffi_ssl_server_port(r, intp, errmsg) | |
+ if rc == FFI_OK then | |
+ return intp[0] | |
+ end | |
+ | |
+ if rc == FFI_DECLINED then | |
return nil | |
end | |
diff -ruN openresty-1.13.6.2/bundle/ngx_lua-0.10.13/src/ngx_http_lua_ssl_certby.c openresty-1.13.6.2-patched/bundle/ngx_lua-0.10.13/src/ngx_http_lua_ssl_certby.c | |
--- openresty-1.13.6.2/bundle/ngx_lua-0.10.13/src/ngx_http_lua_ssl_certby.c 2018-04-23 02:41:56.000000000 +0800 | |
+++ openresty-1.13.6.2-patched/bundle/ngx_lua-0.10.13/src/ngx_http_lua_ssl_certby.c 2019-02-28 16:34:09.310299735 +0800 | |
@@ -880,6 +880,39 @@ | |
int | |
+ngx_http_lua_ffi_ssl_server_port(ngx_http_request_t *r, | |
+ int *port, char **err) | |
+{ | |
+ ngx_ssl_conn_t *ssl_conn; | |
+ ngx_connection_t *c; | |
+ int p; | |
+ if (r->connection == NULL || r->connection->ssl == NULL) { | |
+ *err = "bad request"; | |
+ return NGX_ERROR; | |
+ } | |
+ ssl_conn = r->connection->ssl->connection; | |
+ if (ssl_conn == NULL) { | |
+ *err = "bad ssl conn"; | |
+ return NGX_ERROR; | |
+ } | |
+ | |
+ c = ngx_ssl_get_connection(ssl_conn); | |
+ | |
+ if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { | |
+ return 0; | |
+ } | |
+ | |
+ p = ngx_inet_get_port(c->local_sockaddr); | |
+ | |
+ if (p > 0 && p < 65536) { | |
+ *port = p; | |
+ } | |
+ | |
+ return NGX_OK; | |
+} | |
+ | |
+ | |
+int | |
ngx_http_lua_ffi_ssl_raw_client_addr(ngx_http_request_t *r, char **addr, | |
size_t *addrlen, int *addrtype, char **err) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment