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

Adding SSL support with official OpenResty SSL cosockets implementation #7

Closed
wants to merge 8 commits into from

Conversation

blablacio
Copy link

Adding support for SSL:

  • wss:// scheme should be used for SSL connections
  • ssl_verify parameter can be passed along with options table to connect method (false by default)

@agentzh
Copy link
Member

agentzh commented Jul 24, 2014

@blablacio Thank you for the patch! Will you add a test case for it to the existing test suite?

Also, I've noted a use of uninitialized Lua global variable "session" on the following line in your patch:

local session, err = sock:sslhandshake(session, host, ssl_verify)

Because you're not reusing SSL sessions here anyway, better feed the sslhandshake() method call with nil for the "session" parameter.

UPDATE Sorry, I actually meant passing false for the reused_session parameter. See the official doc for more details: https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake

@blablacio
Copy link
Author

Thanks for the input, you're right!

I'll tweak code to your suggestion and add some tests.

@blablacio
Copy link
Author

Any chance to get this into the next release?

@@ -113,6 +114,10 @@ function _M.connect(self, uri, opts)
if pool then
sock_opts = { pool = pool }
end

if opts.ssl_verify then
ssl_verify = opts.ssl_verify
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better assign true directly to the ssl_verify variable here?

@agentzh
Copy link
Member

agentzh commented Dec 13, 2014

@blablacio Sorry for my delay on my side. Made some more comments on your latest patch :) Thanks for your time!

@blablacio
Copy link
Author

Thanks for the input, I'll fix the issues tomorrow and get back to you with updated patch.
All tests were passing last time I tested so I must have messed the commit up on my side somehow :)

@agentzh
Copy link
Member

agentzh commented Dec 13, 2014

@blablacio I'm not saying I'm seeing failures. I mean for testing ssl_verify = true, we not only need a positive example but also a negative example (that is, the case that the verification expects to fail). Sorry for the confusion.

@blablacio
Copy link
Author

@agentzh Ah, sure, will add that test too. Good point.

@agentzh
Copy link
Member

agentzh commented Dec 13, 2014

@blablacio Hopefully these can get included in the next 1.7.7.2 formal release (which might be the last release of the year 2014) :)

@blablacio
Copy link
Author

@agentzh Sounds fantastic! I'll push changes in the next 24 hours. Hopefully you can get the set-misc-nginx-module changes into the next release too :)

@agentzh
Copy link
Member

agentzh commented Dec 13, 2014

@blablacio No need to be too hurry; we still have time :) Yes, sure, the ngx_set_misc too :)

- ssl_verify is now set to true directly
- passing false to sslhandshake method as first parameter as we're not reusing sessions
- adding some checks to ensure SSL sockets are supported in ngx_lua or throw an error otherwise when using the wss scheme
- adding a new test with SSL verification and failed handshake
@blablacio
Copy link
Author

@agentzh Just added the improvements we discussed, let me know if I missed something when you have a moment to review :)

if not ssl_support then
return nil, "ngx_lua 0.9.11+ required for SSL sockets"
end
local session, err = sock:sslhandshake(false, host, ssl_verify)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better rename the return value session to ok since now sslhandshake never returns the session because we have disabled it by specifying the false argument.

@blablacio
Copy link
Author

@agentzh Sorry for the delay, just got around to fixing the issues you pointed out.

@agentzh
Copy link
Member

agentzh commented Dec 20, 2014

@blablacio Thank you very much! Looking good to me now :) I'll try merging this very soon :)

agentzh added a commit that referenced this pull request Dec 21, 2014
…s (i.e., the "wss://" scheme). thanks Vladislav Manchev for the patch in #7.
@agentzh
Copy link
Member

agentzh commented Dec 21, 2014

@blablacio Just applied a slightly modified version of your patch to git master. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants