Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@robguima
Copy link
Collaborator

hi, this PR enables ossl-1.1.1 session cache resumption support by moving from the get1 session api to the the new_session callback. Also sets the session cache context and the explicit client session behavior when creating new ossl CTXs (proxy).

this should make t/50reverse-proxy-session-resumption.t happy when linking against openssl-1.1.0 and openssl1.1.1

Note that Dockerfile has changed and the CI image will need an update to install openssl-1.1.1c in /opt/openssl-1.1.1

robguima added 4 commits July 23, 2019 22:22
… api to the the new_session callback. also set the context and explicit client session behavior when creating new ossl CTXs.

Fixes 50reverse-proxy-session-resumption.t when linking against openssl-1.1.1
@robguima robguima force-pushed the robguima/ossl111_ci branch from a451f24 to f556558 Compare July 27, 2019 18:32
@robguima robguima requested a review from kazuho July 27, 2019 20:06
Copy link
Member

@kazuho kazuho left a comment

Choose a reason for hiding this comment

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

Thank you for working on this PR. I've left my comments. Please let me know what you think.

{
sock->ssl->ossl = SSL_new(sock->ssl->ssl_ctx);
/* set app data to be used in h2o_socket_ssl_new_session_cb */
assert(SSL_set_app_data(sock->ssl->ossl, sock));
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to split assert and the call to SSL_set_app_data. Otherwise, the call to the OpenSSL function will be eliminated when NBEGUG is set.


SSL_SESSION *session = NULL;
if (!SSL_is_server(s) && sock->ssl->handshake.client.session_cache != NULL) {
session = SSL_get_session(sock->ssl->ossl);
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if it is correct to use SSL_get_session here.

sock->ssl->handshake.client.session_cache is our client-side session cache, and the lifetime of the objects that are registered to the cache should be incremented before they are added to the cache. The h2o_socket_ssl_destroy_session_cache_entry function destroys the entries in the cache when they are to be evicted, by decrementing the reference count.

If there is a concern in using SSL_get1_session here, I think what we should be doing is call i2d_SSL_SESSION and store the serialized form of the resumption token in our session cache.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review! Based on your concern here, I think we can use get1_session here and return 0 with the same effect, as openssl is concerned.
Will push a commit soon which will address the other two as well. 👍

Copy link
Collaborator Author

@robguima robguima Jul 29, 2019

Choose a reason for hiding this comment

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

Actually, I'm not sure get1_session would make any difference. Looking at how the new session cb is called in openssl, and it looks like the ref count is incremented before the cb is invoked:

        if (s->session_ctx->new_session_cb != NULL) {
            SSL_SESSION_up_ref(s->session);
            if (!s->session_ctx->new_session_cb(s, s->session))
                SSL_SESSION_free(s->session);
        }

https://github.com/openssl/openssl/blob/master/ssl/ssl_lib.c#L3569

It looks like the current behavior is sound? Please let me me know if this works for you.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for checking.

Actually, now it seems to me that there is no need to call SSL_get_session at all.

I think we can simply use sess (the argument passed to this function)? And return 1 if we called h2o_cache_set. Does that make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yeah 😄the get_session is really unnecessary there will push the change. thanks!

Copy link
Collaborator Author

@robguima robguima Jul 30, 2019

Choose a reason for hiding this comment

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

yes and your observation points to a bug in the function: within the ifdef is_resumable may still set the session variable, but not store in the cache, which will leak the sess. Will fix that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe 0a077f3 addresses the concerns. Could you please confirm that h2o_cache_set always add the new value even if the key already exists (in which case the function returns 1).
heh hope there is no path in which we destroy the cache without decrementing the SSL ref too, btw.

Copy link
Member

Choose a reason for hiding this comment

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

Could you please confirm that h2o_cache_set always add the new value even if the key already exists (in which case the function returns 1).

Yes. The function guarantees that the new value to be always added.

SSL_CTX_set_options(ctx, options);
SSL_CTX_set_session_id_context(ctx, (const uint8_t*)"h2o", sizeof("h2o") - 1);
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL_STORE);
SSL_CTX_sess_set_new_cb(ctx, h2o_socket_ssl_new_session_cb);
Copy link
Member

Choose a reason for hiding this comment

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

These changes look good.

The only suggestion I have is to define a macro for the arguments of SSL_CTX_set_session_id_context, possibily declaring them in include/h2o/socket.h, and using them throughout this PR.

@kazuho kazuho merged commit af17156 into master Aug 1, 2019
@kazuho
Copy link
Member

kazuho commented Aug 1, 2019

Thank you for your efforts! Merged.

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.

3 participants