-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Make sync SslStream.AuthenticateAs overload with SslOptions public #34638
Comments
Ping: @dotnet/ncl @stephentoub |
The effects of making a synchronous HttpClient.Send 😢 |
I looked into meaningfulness of adding Though I'm not sure if this is OK with regard to the stream state. What if we leave some bytes in the stream because we do not finish reading due to cancellation? What about the state of the server if we stop in the middle of the handshake? Will both sides be able to recover (with the assumption that the client will not continue with this particular request)? |
Cancellation of an I/O operation is rarely recoverable. At the Socket layer, cancelling a pending I/O might leave the socket in a usable state. But higher-layer APIs like SslStream where cancellation is invoked usually result in the stream being unusable after that. Do we know if canceling the async AuthenticateAsServer/Client APIs result in the stream still being usable for a subsequent authentication attempt? |
If you have sent any data to the otherside it is highly unlikely you can do much but re-establish the tcp socket. |
I don't think we can recover if we abort in middle of the handshake. The benefit would be ability to stop and unblock synchronous call. Since the SyncSslIOAdapter has no way how to pass it down to underline stream, it would be possible only between reading TLS frames. If overall timeout is desirable, it may be better to set it on NetworkStream/Socket before passed to SslStream constructor. That would be than applicable to each Read() operation instead to handshake as whole. |
When considering cancellation here, we should look at how it realistically interacts with how someone uses Are we checking for cancellation between I/Os there too? In this case making these cancellable in the same way makes some sense. This sort of best-effort cancellation isn't the best experience when e.g. a Are we closing the socket? In this case we already handle cancellation at a lower layer and don't need it in |
We don't currently. But we used to: |
Triage: (notes from yesterday)
|
So there are two ways which I can be done:
Personally, I like the second option better. What about you @dotnet/ncl ? |
I think the second option is just fine. You'll want to think about where you can translate the |
Triage:
The API is ready to be reviewed as-is now. |
Looks good as proposed: public partial class SslStream : System.Net.Security.AuthenticatedStream
{
public void AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions);
public void AuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions);
} |
Make
SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
public.Possibly make
SslStream.AuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions)
public as well to keep the API consistent. This one is not required, only suggested.Motivation
To properly support sync implementation of
HttpClient
(see #32125).Without this overload, it is not possible to pass custom certificate callbacks (neither
RemoteCertificateValidationCallback
norLocalCertificateSelectionCallback
). Eventually failing authentication which would otherwise pass in an async scenario.The corresponding async method
AuthenticateAsClientAsync(SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken = default)
already is public. And there are other sync overloads which are public. This issue is not the first one introducing sync methods onSslStream
.Existing API for
AuthenticateAsClient(Async)
: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.Security/ref/System.Net.Security.cs#L185-L191Existing API for
AuthenticateAsServer(Async)
: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.Security/ref/System.Net.Security.cs#L192-L198Proposed API
The text was updated successfully, but these errors were encountered: