-
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
SslStream.TargetHostName is unavailable #57105
Comments
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsDescription
runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Implementation.cs Lines 508 to 521 in 1dfe32a
ReproServer: using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
var port = 5001;
var ipEndPoint = new IPEndPoint(IPAddress.Loopback, port);
var listenSocket = new Socket(ipEndPoint.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
listenSocket.Bind(ipEndPoint);
listenSocket.Listen();
using var acceptSocket = await listenSocket.AcceptAsync();
using var ns = new NetworkStream(acceptSocket);
using var sslStream = new SslStream(ns);
using var store = new X509Store("My", StoreLocation.CurrentUser, OpenFlags.ReadOnly);
using var certificate = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", false)
.Where(c => c.HasPrivateKey)
.FirstOrDefault();
// Specifying a delegate instead of directly providing the certificate works
var sslOptions = new SslServerAuthenticationOptions
{
ServerCertificate = certificate,
// ServerCertificateSelectionCallback = (_, name) => certificate,
CertificateRevocationCheckMode = X509RevocationMode.NoCheck
};
sslStream.AuthenticateAsServer(sslOptions);
Debug.Assert(!string.IsNullOrEmpty(sslStream.TargetHostName));
await sslStream.WriteAsync(Encoding.UTF8.GetBytes("Hello, World!")); Client: 👀 @wfurt
|
Triage: we should either fix this or document the behavior. |
Not important. |
Description
SslStream.TargetHostName
is not set unless I've I'm using one of the callbacks onSslStream
(LocalCertificateSelectionCallback
or theServerOptionsSelectionCallback
). If I specify the certificate directly, you won't attempt to decode the SNI)runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Implementation.cs
Lines 508 to 521 in 1dfe32a
Repro
Server:
Client:
curl.exe -k https://localhost:5001
👀 @wfurt
The text was updated successfully, but these errors were encountered: