2

I have seen this question answered but it doesn't seem to be working for .net core 3.1 This code finds the Certificate:

using (var store = new X509Store("Root", StoreLocation.LocalMachine))
{
    store.Open(OpenFlags.ReadOnly);
    var certCollection = store.Certificates;  
    var currentCerts = certCollection.Find(X509FindType.FindBySubjectName, "*.timedesk.com", false);
    if (currentCerts.Count == 0)
        throw new Exception("Https certificate is not found.");
}

This appsettings.json does not find the certificate:

"Kestrel": {
  "Endpoints": {
    "Https": {
      "URL": "https://toast.timedesk.com:443",
      "Scheme": "https",
      "Certificate": {
        "Store": "Root",
        "Location": "LocalMachine",
        "Subject": "*.timedesk.com",
        "AllowInvalid": false
      }
    }
  }
}

Gives the follow error:

System.InvalidOperationException: 'The requested certificate *.timedesk.com could not be found in LocalMachine/Root with AllowInvalid setting: False.'
Dartis
  • 51
  • 1
  • 5

2 Answers2

3

I figured out the issue, the Cert on the server did not have a private key. Once i got a private key this started working.Cert showing it now has private key

Dartis
  • 51
  • 1
  • 5
0

My issue is the custom dev certificate was installed into the Personal | Certificates instead of Web Hosting | Certificates store. Easy fix, drag -n- drop.

Racingman
  • 18
  • 3