System.Net.SslStream is not currently supporting TLS Alerts as specified by RFC 2246 sections 7.2.1: Closure alerts and 7.2.2: Error alerts.
Proposed API
In order to support closing the TLS channel gracefully the following async API is proposed:
public virtual System.Threading.Tasks.Task System.Net.SslStream.ShutdownAsync()
Details
The ShutdownAsync semantics are similar to Socket.Shutdown(SocketShutdown.Send) or WebSocket.CloseOutputAsync. After ShutdownAsync has been called, the write portion of the full-duplex channel is closed and the channel becomes read-only. The handshake is completed when no more bytes can be read from the SslStream (Read APIs return 0.)
New API Usage
The following code shows usage of the new API as well as new server-side behavior. This as well as tests demonstrating the new behavior to support 7.2.2. during TLS Handshake is available in SslStreamAlertsTest.cs, dotnet/corefx#11489.
var handshake = new Task[2];
handshake[0] = server.AuthenticateAsServerAsync(certificate);
handshake[1] = client.AuthenticateAsClientAsync(certificate.GetNameInfo(X509NameType.SimpleName, false));
await Task.WhenAll(handshake).TimeoutAfter(TestConfiguration.PassingTestTimeoutMilliseconds);
var readBuffer = new byte[1024];
await server.ShutdownAsync();
int bytesRead = await client.ReadAsync(readBuffer, 0, readBuffer.Length);
// close_notify received by the client.
Assert.Equal(0, bytesRead);
await client.ShutdownAsync();
bytesRead = await server.ReadAsync(readBuffer, 0, readBuffer.Length);
// close_notify received by the server.
Assert.Equal(0, bytesRead);
Pull Requests
WIP (tooling/WIP) API change: dotnet/corefx#11265.
Implementation and tests: dotnet/corefx#11489:
System.Net.SslStream is not currently supporting TLS Alerts as specified by RFC 2246 sections 7.2.1: Closure alerts and 7.2.2: Error alerts.
Proposed API
In order to support closing the TLS channel gracefully the following async API is proposed:
public virtual System.Threading.Tasks.Task System.Net.SslStream.ShutdownAsync()Details
The ShutdownAsync semantics are similar to
Socket.Shutdown(SocketShutdown.Send)orWebSocket.CloseOutputAsync. After ShutdownAsync has been called, the write portion of the full-duplex channel is closed and the channel becomes read-only. The handshake is completed when no more bytes can be read from the SslStream (Read APIs return 0.)New API Usage
The following code shows usage of the new API as well as new server-side behavior. This as well as tests demonstrating the new behavior to support 7.2.2. during TLS Handshake is available in
SslStreamAlertsTest.cs, dotnet/corefx#11489.Pull Requests
WIP (tooling/WIP) API change: dotnet/corefx#11265.
Implementation and tests: dotnet/corefx#11489: