Add SSLSocket server handshake aliases - #1094
Conversation
Add SSLSocket#start and #start_nonblock as aliases for #accept and #accept_nonblock. This gives server code a handshake-oriented name when SSLServer#start_immediately is disabled, while preserving the existing interface and behavior.\n\nRelated to ruby#760. Assisted-By: devx/3ed43c18-3c9a-4ad9-a6f5-6668caa29658
|
TLS is a client-initiated protocol, so if we had As I've written in #760, I don't really see problems with the current names
|
|
Thanks. The concrete problem is that
if socket.respond_to?(:start)
socket.start
endThe actual implementation is here: https://github.com/socketry/io-endpoint/blob/5e7c6aff6ba7b52c1a30f6d3a6e5a5aa86b41bf0/lib/io/endpoint/wrapper.rb#L217-L226 For an Therefore, This PR does not replace or change |
|
Shouldn't the TLS handshake generally handled outside generic socket handling code, since it is specific to TLS? I don't think So, for now, I'm inclined to leave
It's a good point that Perhaps we should deprecate this class and recommend using |
The generic accept loop does not implement TLS. It handles the lifecycle transition from “transport connection accepted” to “socket ready for the application,” while the socket itself performs any protocol-specific negotiation: if socket.respond_to?(:start)
socket.start
endThis is the actual That transition needs to occur after dispatching the connection to its fiber or thread, so negotiation for one connection does not serialize the accept loop. The generic code should not need to know whether that negotiation is TLS or inspect the concrete socket class.
I agree that it is not currently established; this PR proposes it as that convention. If
Using those classes directly does not remove this lifecycle transition. After accepting the TCP connection and constructing the I would like to find an upstream interface for that operation rather than requiring libraries to define their own convention or add type-specific branches. |
|
IMO I see no good reason for setting up the instance ( I think But none of these names seem clearly enough better than |
TL;DR
Add
OpenSSL::SSL::SSLSocket#startand#start_nonblockas aliases for#acceptand#accept_nonblock.Context
When
OpenSSL::SSL::SSLServer#start_immediatelyis disabled,SSLServer#acceptreturns the accepted transport before performing the TLS handshake. The caller then invokesSSLSocket#accepton that already-accepted socket to perform the server-side handshake.io-endpointcurrently defines these aliases itself so accepted connections can be dispatched to a fiber or thread and the TLS handshake can be initiated with#start, without treating handshake initiation as another connection acceptance operation in generic server code.Related to #760.
Changes
SSLSocket#starttoSSLSocket#accept.SSLSocket#start_nonblocktoSSLSocket#accept_nonblock.The existing methods and behavior are unchanged.
Tophatting
bundle exec rake compilebundle exec ruby -Itest -Ilib test/openssl/test_ssl.rb --name=test_server_handshake_aliasesbundle exec rake test(628 tests, 4,606 assertions, 0 failures, 0 errors, 2 expected FIPS omissions)