Repository navigation
Refactor callbacks in OpenSSL::SSL - #1080
Merged
Merged
Conversation
rhenium
force-pushed
the
ky/ssl-callback-errors
branch
2 times, most recently
from
August 31, 2026 12:32
a05a89f to
5ae433b
Compare
rhenium
force-pushed
the
ky/ssl-callback-errors
branch
from
October 13, 2026 09:58
5ae433b to
11bf938
Compare
rhenium
force-pushed
the
ky/ssl-callback-errors
branch
2 times, most recently
from
November 12, 2026 13:34
deb1dfb to
79b6a35
Compare
rhenium
force-pushed
the
ky/ssl-callback-errors
branch
3 times, most recently
from
November 23, 2026 15:02
be2c8c7 to
5955591
Compare
rhenium
force-pushed
the
ky/ssl-callback-errors
branch
from
November 23, 2026 15:08
5955591 to
465660b
Compare
Simplify handling of the temporary rb_protect() jump states. This also avoids potential corruption of OpenSSL's internal state if the SSLSocket object is frozen in the middle of SSL_*() calls. Also, skip calling Ruby callbacks while we are waiting for a chance to resume a jump with rb_jump_tag(). This cannot currently happen as far as I know, but it is cheap to check this.
Use rb_protect() to avoid exiting from SSL_accept() or SSL_read() prematurely. Also set the callback to SSL_CTX instead of SSL, similarly to what we do for other callbacks configurable on SSLContext.
Currently, if the callback raises an exception or returns an invalid value, the handshake is resumed as if the callback has not been called. This is contrary to the documentation. Propagate exceptions raised by the callback to the originating method. Raise an exception if the callback returns an invalid value. It is immediately caught by rb_protect() and will similarly be re-raised in the originating method.
Prepare the Array objects for the argument inside rb_protect(). This object allocation may potentially raise an exception and corrupt OpenSSL's internal state. Also look up the callback Proc objects directly from SSLContext's instance variables to simplify.
rhenium
force-pushed
the
ky/ssl-callback-errors
branch
from
November 23, 2026 15:54
465660b to
f1a1b37
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracted from #736
ssl: use ossl_cb_state_*() for handling exceptions in callbacks
Simplify handling of the temporary rb_protect() jump states. This also
avoids potential corruption of OpenSSL's internal state if the
SSLSocket object is frozen in the middle of SSL_*() calls.
Also, skip calling Ruby callbacks while we are waiting for a chance to
resume a jump with rb_jump_tag(). This cannot currently happen as far
as I know, but it is cheap to check this.
ssl: harden info_callback
Use rb_protect() to avoid exiting from SSL_accept() or SSL_read()
prematurely.
Also set the callback to SSL_CTX instead of SSL, similarly to what we
do for other callbacks configurable on SSLContext.
ssl: harden client_cert_cb
Currently, if the callback raises an exception or returns an invalid
value, the handshake is resumed as if the callback has not been called.
This is contrary to the documentation.
Propagate exceptions raised by the callback to the originating method.
Raise an exception if the callback returns an invalid value. It is
immediately caught by rb_protect() and will similarly be re-raised in
the originating method.
ssl: harden session_{get,new,remove}_cb
Prepare the Array objects for the argument inside rb_protect(). This
object allocation may potentially raise an exception and corrupt
OpenSSL's internal state.
Also look up the callback Proc objects directly from SSLContext's
instance variables to simplify.