Skip to content

Refactor initialization of custom OpenSSL BIO#16651

Merged
straight-shoota merged 7 commits intocrystal-lang:masterfrom
ysbaddaden:refactor/openssl-bio-initialization
Feb 12, 2026
Merged

Refactor initialization of custom OpenSSL BIO#16651
straight-shoota merged 7 commits intocrystal-lang:masterfrom
ysbaddaden:refactor/openssl-bio-initialization

Conversation

@ysbaddaden
Copy link
Collaborator

Properly initializes the custom BIO by asking libcrypto for an available BIO identifier and declaring the actual BIO types (SOURCE SINK, DESCRIPTOR) instead of enabling all flags and hardcoding an arbitrary identifier.

Implements BIO_C_GET_FD when the underlying IO is a file descriptor since we declare the BIO as being a DESCRIPTOR.

Also fixes Crystal::BIO#initialize that stored the boxed IO, but Box.box(IO) merely casts IO as a Void* so we end up storing the same pointer to IO twice.

Follow up to #16640.
Extracted from #16642.

Properly declare a BIO id with correct flag types instead of hardcording
0xFF and enabling all the type flags.
Because Box(Reference) merely casts the reference as a void pointer so
we end up saving the same pointer to IO twice.
@straight-shoota straight-shoota added this to the 1.20.0 milestone Feb 10, 2026
@ysbaddaden
Copy link
Collaborator Author

ysbaddaden commented Feb 10, 2026

Just added: some BIO methods can fail. That should never happen, but something may have registered 127 custom BIOs or we could reach OOM when calling BIO_new.

ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Feb 10, 2026
@straight-shoota straight-shoota merged commit 7c514a2 into crystal-lang:master Feb 12, 2026
52 checks passed
@ysbaddaden ysbaddaden deleted the refactor/openssl-bio-initialization branch February 12, 2026 11:05
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.

2 participants