Skip to content

Add Kernel TLS support to custom OpenSSL::BIO#16646

Merged
straight-shoota merged 10 commits intocrystal-lang:masterfrom
ysbaddaden:feature/add-ktls-support-to-openssl-bio
Feb 28, 2026
Merged

Add Kernel TLS support to custom OpenSSL::BIO#16646
straight-shoota merged 10 commits intocrystal-lang:masterfrom
ysbaddaden:feature/add-ktls-support-to-openssl-bio

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Feb 9, 2026

NOTES:

  • OpenSSL enables KTLS support by default (verified), can be disabled with:
    ctx = OpenSSL::SSL::Context::[Client|Server].new
    ctx.remove_options(OpenSSL::SSL::OPTIONS::ENABLE_KTLS)
  • OpenSSL 3.0 and 3.6 ✔️
  • Linux 6.17 (needs modprobe tls) ✔️
  • FreeBSD 14.1 (needs sysctl kern.ipc.tls.enable=1) ✔️
  • No support for legacy libevent evloop (only epoll & kqueue).

Draft PR because a number of independent PR shall be extracted (branched off #16640 + no flush on read + fix BIO init + class Crystal::BIO instead of struct + Box, ...).

Closes #16642.

These are extension methods to the Crystal::EventLoop::Socket interface
to enable support for evented OpenSSL::BIO for sockets with Kernel TLS
enabled.

Unlike the rest of the interface, these methods don't raise but instead
return an Int32 | Errno union that must be acted upon by the caller.
@ysbaddaden ysbaddaden force-pushed the feature/add-ktls-support-to-openssl-bio branch from 0c8bd11 to da2927c Compare February 12, 2026 12:17
@ysbaddaden
Copy link
Collaborator Author

This is ready for review.

Co-authored-by: Johannes Müller <straightshoota@gmail.com>
@ysbaddaden ysbaddaden force-pushed the feature/add-ktls-support-to-openssl-bio branch from 19bd9ca to 7fd1192 Compare February 26, 2026 11:24
@straight-shoota straight-shoota added this to the 1.20.0 milestone Feb 26, 2026
@ysbaddaden
Copy link
Collaborator Author

Allright, there's something definitely wrong with MinGW + UCRT64 w.r.t OpenSSL.

The std specs for both this PR and #16569 both fail with the same exit code (67) and no error message. They both are related to TLS.

{% if flag?(:win32) && flag?(:gnu) && flag?(:x86_64) %}
# FIXME: why does the spec causes the process to die with status code 67?
pending! "process dies with exit code 67 on msys2-ucrt-x86_64 on CI"
{% end %}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't pretty, but it at least allows to move on until we can figure out the issue on this specific msys2 environment. I cherry-picked the same commit to #16569 where the issue is also fixed.

It might be related to raising exceptions in OpenSSL::BIO callbacks from C.

@straight-shoota straight-shoota merged commit e13f4b3 into crystal-lang:master Feb 28, 2026
61 checks passed
@ysbaddaden ysbaddaden deleted the feature/add-ktls-support-to-openssl-bio branch March 1, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Kernel TLS support to OpenSSL sockets

3 participants