Skip to content

feature: implemented ssl_session_fetch_by_lua* and ssl_session_store_by_lua* #822

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

Merged
merged 1 commit into from
Jul 29, 2016

Conversation

agentzh
Copy link
Member

@agentzh agentzh commented Jul 21, 2016

These directives can be used to implement (distributed) caching of SSL sessions (via SSL session IDs) for downstream connections.

The Lua API for manipulating SSL sessions in these two running contexts is provided in the following PR for lua-resty-core:

openresty/lua-resty-core#53

Dependencies:

  • NGINX core patch:
--- nginx-1.11.2/src/event/ngx_event_openssl.c  2016-07-05 08:56:15.000000000 -0700
+++ nginx-1.11.2-patched/src/event/ngx_event_openssl.c  2016-07-19 16:46:06.218017083 -0700
@@ -1306,6 +1306,25 @@ ngx_ssl_handshake(ngx_connection_t *c)
         return NGX_AGAIN;
     }

+#if OPENSSL_VERSION_NUMBER >= 0x10002000L
+    if (sslerr == SSL_ERROR_WANT_X509_LOOKUP
+        || sslerr == SSL_ERROR_PENDING_SESSION)
+    {
+        c->read->handler = ngx_ssl_handshake_handler;
+        c->write->handler = ngx_ssl_handshake_handler;
+
+        if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
+            return NGX_ERROR;
+        }
+
+        if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
+            return NGX_ERROR;
+        }
+
+        return NGX_AGAIN;
+    }
+#endif
+
     err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;

     c->ssl->no_wait_shutdown = 1;

The patch can also be applied cleanly to a little older versions of NGINX cores like 1.9.15.

If a recent version of OpenResty is used, like 1.9.15.1, then the following patch should be applied to OpenResty's bundled version of the NGINX core instead:

https://github.com/openresty/openresty/blob/master/patches/nginx-1.11.2-ssl_pending_session.patch

  • OpenSSL patch:

https://github.com/openresty/openresty/blob/master/patches/openssl-1.0.2h-sess_set_get_cb_yield.patch

This is for the latest OpenSSL 1.0.2h version. Earlier verisons like 1.0.2e might also work, but the latest version of OpenSSL is strongly encouraged.

Special thanks go to Zi Lin for contributing this new feature and also to CloudFlare for supporting this work.

@agentzh
Copy link
Member Author

agentzh commented Jul 21, 2016

@ghedo @lziest @doujiang24 @yangshuxin Please review this PR. Thanks!

@@ -7583,7 +7710,7 @@ coroutine.create
----------------
**syntax:** *co = coroutine.create(f)*

**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua**
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua**
Copy link
Member

Choose a reason for hiding this comment

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

@agentzh coroutine.create can not be used in ssl_session_fetch_by_lua and ssl_session_store_by_lua now.
Because it will failed in ngx_http_lua_check_context: https://github.com/openresty/lua-nginx-module/blob/master/src/ngx_http_lua_coroutine.c#L76
I think we can let coroutine.create used in ssl_session_fetch_by_lua by change the context check.

Copy link
Member Author

Choose a reason for hiding this comment

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

@doujiang24 Fixed. Thanks!

…by_lua* config directives for doing (distributed) caching of SSL sessions (via SSL session IDs) for downstream connections.

thanks Zi Lin for the patches.
@agentzh agentzh merged commit 5bcc53c into master Jul 29, 2016
@agentzh
Copy link
Member Author

agentzh commented Jul 29, 2016

This PR has just been merged. New issues found should be reported as separate GitHub issues. Thanks!

@thibaultcha thibaultcha deleted the ssl-session branch February 7, 2019 23:46
@thibaultcha thibaultcha restored the ssl-session branch February 7, 2019 23:47
@thibaultcha thibaultcha deleted the ssl-session branch September 24, 2019 22:54
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.

2 participants