Skip to content

Commit 40f3999

Browse files
committed
feat(ssl) add the ssl and ssl_ctx module
1 parent 187116d commit 40f3999

File tree

13 files changed

+1227
-7
lines changed

13 files changed

+1227
-7
lines changed

.github/workflows/tests.yml

+17-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ jobs:
3939
# openssl_opts: "fips --with-fipsdir=/home/runner/work/cache/ssl/fips"
4040
# latest and one older version with alpha release
4141
- nginx: "1.17.8"
42-
openssl: "3.0.0-alpha9"
42+
openssl: "3.0.0-alpha10"
4343
nginx_cc_opts: "-Wno-error"
4444
- nginx: "1.19.3"
45-
openssl: "3.0.0-alpha9"
45+
openssl: "3.0.0-alpha10"
4646
nginx_cc_opts: "-Wno-error"
4747

4848
env:
@@ -91,6 +91,7 @@ jobs:
9191
git clone https://github.com/simpl/ngx_devel_kit.git ./ndk-nginx-module
9292
git clone https://github.com/openresty/lua-nginx-module.git ./lua-nginx-module -b v0.10.17
9393
git clone https://github.com/openresty/no-pool-nginx.git ./no-pool-nginx
94+
git clone https://github.com/fffonion/lua-resty-openssl-aux-module ./lua-resty-openssl-aux-module
9495
# lua libraries at parent directory of current repository
9596
popd
9697
git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core -b v0.1.19
@@ -138,9 +139,11 @@ jobs:
138139
if ["$USE_VALGRIND" != ""]; then NGINX_CC_OPTS="$NGINX_CC_OPTS -O0"; fi
139140
export PATH=$BASE_PATH/work/nginx/sbin:$BASE_PATH/../nginx-devel-utils:$PATH
140141
export LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
142+
export NGX_LUA_LOC=$BASE_PATH/../lua-nginx-module
143+
export NGX_STREAM_LUA_LOC=$BASE_PATH/../stream-lua-nginx-module
141144
export
142145
cd $BASE_PATH
143-
if [ ! -e work ]; then ngx-build $NGINX_VERSION --add-module=../ndk-nginx-module --add-module=../lua-nginx-module --with-http_ssl_module --with-cc-opt="-I$OPENSSL_INC $NGINX_CC_OPTS" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --with-debug > build.log 2>&1 || (cat build.log && exit 1); fi
146+
if [ ! -e work ]; then ngx-build $NGINX_VERSION --add-module=../ndk-nginx-module --add-module=../lua-nginx-module --add-module=../lua-resty-openssl-aux-module --with-http_ssl_module --with-cc-opt="-I$OPENSSL_INC $NGINX_CC_OPTS" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --with-debug > build.log 2>&1 || (cat build.log && exit 1); fi
144147
nginx -V
145148
ldd `which nginx`|grep -E 'luajit|ssl|pcre'
146149
@@ -150,11 +153,21 @@ jobs:
150153
export PATH=$BASE_PATH/work/nginx/sbin:$PATH
151154
TEST_NGINX_TIMEOUT=10 prove -j$JOBS -r t/ 2>&1
152155
156+
echo "Nginx SSL plain FFI"
157+
export CI_SKIP_NGINX_C=1
158+
TEST_NGINX_TIMEOUT=10 prove -j$JOBS t/openssl/ssl*.t 2>&1
159+
153160
- name: Run Valgrind
154161
if: ${{ matrix.valgrind != '' }}
155162
run: |
156163
export LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
157164
export TEST_NGINX_USE_VALGRIND='--num-callers=100 -q --tool=memcheck --leak-check=full --show-possibly-lost=no --gen-suppressions=all --suppressions=valgrind.suppress --track-origins=yes' TEST_NGINX_TIMEOUT=60 TEST_NGINX_SLEEP=1
158165
export PATH=$BASE_PATH/work/nginx/sbin:$PATH
159166
stdbuf -o 0 -e 0 prove -j$JOBS -r t/ 2>&1 | grep -v "Connection refused" | grep -v "Retry connecting after" | tee output.log
160-
if grep -q 'insert_a_suppression_name_here' output.log; then echo "Valgrind found problems"; exit 1; fi
167+
if grep -q 'insert_a_suppression_name_here' output.log; then echo "Valgrind found problems"; exit 1; fi
168+
169+
echo "Nginx SSL plain FFI"
170+
export CI_SKIP_NGINX_C=1
171+
stdbuf -o 0 -e 0 prove -j$JOBS t/openssl/ssl*.t 2>&1 | grep -v "Connection refused" | grep -v "Retry connecting after" | tee output.log
172+
if grep -q 'insert_a_suppression_name_here' output.log; then echo "Valgrind found problems"; exit 1; fi
173+

README.md

+84
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ Table of Contents
208208
* [resty.openssl.x509.revoked](#restyopensslx509revoked)
209209
+ [revoked.new](#revokednew)
210210
+ [revoked.istype](#revokedistype)
211+
* [resty.openssl.ssl](#restyopensslssl)
212+
+ [ssl.from_request](#sslfrom_request)
213+
+ [ssl.from_socket](#sslfrom_socket)
214+
+ [ssl:get_peer_certificate](#sslget_peer_certificate)
215+
+ [ssl:get_peer_cert_chain](#sslget_peer_cert_chain)
216+
* [resty.openssl.ssl_ctx](#restyopensslssl_ctx)
217+
+ [ssl_ctx.from_request](#ssl_ctxfrom_request)
218+
+ [ssl_ctx.from_socket](#ssl_ctxfrom_socket)
211219
* [Functions for stack-like objects](#functions-for-stack-like-objects)
212220
+ [metamethods](#metamethods)
213221
+ [each](#each)
@@ -281,6 +289,8 @@ return {
281289
extensions = require("resty.openssl.x509.extensions"),
282290
name = require("resty.openssl.x509.name"),
283291
store = require("resty.openssl.x509.store"),
292+
ssl = require("resty.openssl.ssl"),
293+
ssl_ctx = require("resty.openssl.ssl_ctx"),
284294
}
285295
```
286296

@@ -3123,6 +3133,80 @@ Returns `true` if table is an instance of `revoked`. Returns `false` otherwise.
31233133

31243134
[Back to TOC](#table-of-contents)
31253135

3136+
## resty.openssl.ssl
3137+
3138+
Module to interact with SSL connection.
3139+
3140+
**This module is currently considered experimental.**
3141+
3142+
**Note: to use this module in production, user is encouraged to compile [lua-resty-openssl-aux-module](https://github.com/fffonion/lua-resty-openssl-aux-module).**
3143+
3144+
[Back to TOC](#table-of-contents)
3145+
3146+
### ssl.from_request
3147+
3148+
**syntax**: *sess, err = ssl.from_request()*
3149+
3150+
Wraps the `SSL*` instance from current downstream request.
3151+
3152+
[Back to TOC](#table-of-contents)
3153+
3154+
### ssl.from_socket
3155+
3156+
**syntax**: *sess, err = ssl.from_socket(sock)*
3157+
3158+
Wraps the `SSL*` instance from a TCP cosocket, the cosocket must have already
3159+
been called `sslhandshake`.
3160+
3161+
[Back to TOC](#table-of-contents)
3162+
3163+
### ssl:get_peer_certificate
3164+
3165+
**syntax**: *x509, err = ssl:get_peer_certificate()*
3166+
3167+
Return the peer certificate as a [x509](#restyopensslx509) instance. Depending on the type
3168+
of `ssl`, peer certificate means the server certificate on client side, or the client certificate
3169+
on server side.
3170+
3171+
[Back to TOC](#table-of-contents)
3172+
3173+
### ssl:get_peer_cert_chain
3174+
3175+
**syntax**: *chain, err = ssl:get_peer_certificate()*
3176+
3177+
Return the whole peer certificate chain as a [x509.chain](#restyopensslx509chain) instance.
3178+
Depending on the type of `ssl`, peer certificate means the server certificate on client side,
3179+
or the client certificate on server side.
3180+
3181+
[Back to TOC](#table-of-contents)
3182+
3183+
## resty.openssl.ssl_ctx
3184+
3185+
Module to interact with SSL_CTX context.
3186+
3187+
**This module is currently considered experimental.**
3188+
3189+
**Note: to use this module in production, user is encouraged to compile [lua-resty-openssl-aux-module](https://github.com/fffonion/lua-resty-openssl-aux-module).**
3190+
3191+
[Back to TOC](#table-of-contents)
3192+
3193+
### ssl_ctx.from_request
3194+
3195+
**syntax**: *ctx, err = ssl_ctx.from_request()*
3196+
3197+
Wraps the `SSL_CTX*` instance from current downstream request.
3198+
3199+
[Back to TOC](#table-of-contents)
3200+
3201+
### ssl_ctx.from_request
3202+
3203+
**syntax**: *sess, err = ssl_ctx.from_socket(sock)*
3204+
3205+
Wraps the `SSL_CTX*` instance from a TCP cosocket, the cosocket must have already
3206+
been called `sslhandshake`.
3207+
3208+
[Back to TOC](#table-of-contents)
3209+
31263210
## Functions for stack-like objects
31273211

31283212
[Back to TOC](#table-of-contents)

lib/resty/openssl.lua

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ local _M = {
2323
revoked = require("resty.openssl.x509.revoked"),
2424
store = require("resty.openssl.x509.store"),
2525
pkcs12 = require("resty.openssl.pkcs12"),
26+
ssl = require("resty.openssl.ssl"),
27+
ssl_ctx = require("resty.openssl.ssl_ctx"),
2628
}
2729

2830
if OPENSSL_30 then

0 commit comments

Comments
 (0)