I'm getting this error when I call AuthenticateAsClientAsync
on the client's SslStream
: The handshake failed due to an unexpected packet format.
All of this worked successfully using sockets, so the certificates and thumbprints are set up correctly, but it's not working in Kestrel. The only thing I can think of is that Kestrel doesn't allow listening on hostnames and the hostname validation fails on the client? Did I miss something? How would I dig deeper into this error to find the underlying issue?
Client-Side Console App
var client = new TcpClient();
await client.ConnectAsync("one.two.local", 8005);
var sslStream = new SslStream(client.GetStream());;
// TODO: Use TLS 1.3 once Microsoft fixes their bugs
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions // #### ERROR HERE ####
{
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
TargetHost = "one.two.local",
EnabledSslProtocols = SslProtocols.Tls12,
EncryptionPolicy = EncryptionPolicy.RequireEncryption,
RemoteCertificateValidationCallback = (a, b, c, d) => true
});
Server-Side Host Builder:
Note that the X509CertificateUtility is loading certificates from the local machine store and the certificate is found.
WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services => { })
.UseKestrel(options =>
{
options.Listen(IPAddress.Parse("127.0.0.9"), 8005, builder =>
{
// child thumbprint (obfuscated for posting)
// certificate is found
var certificate = X509CertificateUtility.Find("4F6FFF21dFFF0FF743FFF44338F41F8FFFF46491");
// TODO: Use TLS 1.3 once Microsoft fixes their bugs
builder.UseHttps(new HttpsConnectionAdapterOptions
{
SslProtocols = SslProtocols.Tls12,
CheckCertificateRevocation = false,
ClientCertificateMode = ClientCertificateMode.NoCertificate,
ServerCertificate = certificate,
ClientCertificateValidation = (a, b, c) => true
});
builder.UseConnectionHandler<KairosConnectionHandler>();
});
})
.UseStartup<Startup>();
HOSTS file:
127.0.0.9 one.two.local
Cert Info
Subject: one.two.local
Enhanced Key Usage: Client + Server Authentication
Subject Alternative Name: DNS Name=one.two.local