-
Notifications
You must be signed in to change notification settings - Fork 272
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: ssl.create_ctx and tcp:setsslctx #89
base: master
Are you sure you want to change the base?
Conversation
After refactor the codebase, these is a little different things. We remove the |
lib/ngx/ssl.lua
Outdated
_M.PROTOCOL_TLSv1 = 0x0008 | ||
_M.PROTOCOL_TLSv1_1 = 0x0010 | ||
_M.PROTOCOL_TLSv1_2 = 0x0020 | ||
local default_protocols = bor(bor(bor(_M.PROTOCOL_SSLv3,_M.PROTOCOL_TLSv1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bor
can accept multiple arguments, like:
resty -e " ngx.say(bit.bor(1, 2, 4)); "
7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha
lib/ngx/ssl.lua
Outdated
local protocols = default_protocols | ||
|
||
if options.protocols ~= nil then | ||
protocols = options.protocols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think local protocols = options.protocols or options.protocols
can be simpler :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha local protocols = options.protocols or default_protocols
lib/resty/core/socket/tcp.lua
Outdated
|
||
local rc = C.ngx_http_lua_ffi_socket_tcp_setsslctx(r, tcp, ssl_ctx, errmsg) | ||
if rc ~= FFI_OK then | ||
return false, ffi_str(errmsg[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use nil
instead false
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I found other statements is also using nil rather than false.
CI passed after merge newest commit on master branch :D |
lib/ngx/ssl.lua
Outdated
_M.PROTOCOL_TLSv1 = 0x0008 | ||
_M.PROTOCOL_TLSv1_1 = 0x0010 | ||
_M.PROTOCOL_TLSv1_2 = 0x0020 | ||
local default_protocols = bor(_M.PROTOCOL_SSLv3, _M.PROTOCOL_TLSv1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better put a blank line before this line for aesthetic considerations.
lib/resty/core/socket/tcp.lua
Outdated
|
||
int | ||
ngx_http_lua_ffi_socket_tcp_setsslctx(ngx_http_request_t *r, | ||
void *u, void *cdata_ctx, char **err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be consistent with the style in lib/ngx/ssl.lua
.
t/ssl-ctx.t
Outdated
local cert = ssl.parse_pem_cert(read_file("$TEST_NGINX_HTML_DIR/client.crt")) | ||
local priv_key = ssl.parse_pem_priv_key(read_file("$TEST_NGINX_HTML_DIR/client.unsecure.key")) | ||
|
||
local ssl_ctx, err = ssl.create_ctx({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know that we can safely omit the parentheses here?
lib/ngx/ssl.lua
Outdated
return nil, ffi_str(errmsg[0]) | ||
end | ||
|
||
ctx = ffi_gc(ctx, C.ngx_http_lua_ffi_ssl_ctx_free) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to assign to ctx
here.
lib/ngx/ssl.lua
Outdated
_M.PROTOCOL_SSLv3 = 0x0004 | ||
_M.PROTOCOL_TLSv1 = 0x0008 | ||
_M.PROTOCOL_TLSv1_1 = 0x0010 | ||
_M.PROTOCOL_TLSv1_2 = 0x0020 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thikn we can just omit the PROTOCOL_
prefix from these keys. They are not really needed IMHO.
Signed-off-by: detailyang <[email protected]>
Signed-off-by: detailyang <[email protected]>
Signed-off-by: detailyang <[email protected]>
bb43bbb
to
9ebd5b6
Compare
…a-resty-core into lua-ffi-api-sslctx
Fix the issue as the following and rebase the newest codebase:
Sorry for duplicated commits because of wrong usage of |
This is a sister PR at lua-nginx-module/pull/997.
I refer to Node.js JS Design as a guide. Now the API is the fowllong:
Now we proivde 3 arguments as the follwoing to feed
SSL_CTX
object.Openssl protocols are listed as OPENSSL PROTOCOL METHODS
Optional certificate in PEM format which can be parsed by
ssl.parse_pem_cert
Optional private keys in PEM format which can be parsed by
ssl.parse_pem_priv_key
It 's convenient that if we want to expose more arguments to user in future if we want.
Now it is not ready to provide the README document. when we agree on the API Design, I will provide.
@agentzh @thibaultcha @doujiang24
Can have a look at this PR ? Many thanks :D