Skip to content

ClientWebSocket client certificate not working with .NET Core #21916

@mvput

Description

@mvput

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();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions