-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Refactor: dust off OpenSSL::BIO [fixup #16480]
#16640
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
ysbaddaden
merged 1 commit into
crystal-lang:master
from
ysbaddaden:refactor/dead-code-in-openssl-bio
Feb 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
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.
thought: Not directly related to this change: What happens when these methods raise?
Do we need to rescue exceptions and return an error value?
Uh oh!
There was an error while loading. Please reload this page.
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.
Exactly my thoughts when I saw that. It looks like it's working in practice, but we might want to investigate.
We should review the
writeandwrite_exmethods (and read counterparts) to see if we shall rescue and return-errnoor-1and seterrno, or set the SSL error, or something else entirely.(in a follow up)
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.
Let's review the whole BIO and compare it with https://github.com/openssl/openssl/blob/baf4156f7052cf5fa08aaf5187dc1f5d25e49664/crypto/bio/bss_sock.c
There's likely a bunch of details to fix (and KTLS support to hack in).
Uh oh!
There was an error while loading. Please reload this page.
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.
Example:
BIO_meth_new(Int32::MAX, "crystal")should be (omitting LibCrypto for readability):Uh oh!
There was an error while loading. Please reload this page.
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.
Reading the OpenSSL source code, I believe it expects the BIO methods to return
-1with the system error set (Errno,WinError, ...). In practice the nested C calls are expected to each fail immediately and return-1with the system error already set by the libc functions.We'd probably want to do that. Exceptions going from Crystal -> C -> Crystal, thus bypassing the C land, might be a bad idea. Though it might not be an issue in practice: read or write fails and the C functions might just
return ret if ret <= 0(bubble the error up with no cleanup).An issue is that we'd raise twice. If we could assume that
iois aSocket, then maybe we could bypassIO(i.e. callCrystal::EventLoop#read(Socket)directly), and rework theCrystal::EventLoopinterface to return system errors (e.g.#read : Errno | WinError | SizeT) instead of raising 🤔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.
Interacting directly with
Socketon the event loop would align well with #16642.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 actually need it to be a general
IO. There's one usage in stdlib where we use anIO::Memoryfor getting the value out of x509 certificate.Now, nothing prevents us from having two custom BIOs: one for general IO and another dedicated for Socket.