Certificate issue in Kestrel ssl JSON configuration using .net Core 3.1

微笑、不失礼 提交于 2021-01-28 11:39:50

问题


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.'

回答1:


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



来源:https://stackoverflow.com/questions/59921131/certificate-issue-in-kestrel-ssl-json-configuration-using-net-core-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!