-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
Milestone
Description
Using the ClientWebSocket to establish a secure WebSocket connection with client certificates. The project is targeting netcoreapp1.1. With the following code, the ConnectAsync throws an exception: WinHttpException: A certificate is required to complete client authentication. When changing the TFM to net461 the connection is successfully established. I removed the template id of the certificate for security reasons.
ClientWebSocket client = new ClientWebSocket();
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
var cert = store.Certificates.Find(X509FindType.FindByTemplateName, "<templateid>", true);
client.Options.ClientCertificates = new X509CertificateCollection();
client.Options.ClientCertificates.Add(cert[0]);
client.ConnectAsync(new Uri("wss://localhost:44301/path"), CancellationToken.None).Wait();