Search code examples
.net-coressl-certificatekestrel-http-server

Certificate issue in Kestrel ssl JSON configuration


Referencing to Kestrel documentation is it possible to configure https using appsettings.json file:

  "HttpsInlineCertStore": {
    "Url": "https://+:5002",
    "Certificate": {
      "Subject": "<coma separated multi-line subject name>",
      "Store": "Root",
      "Location": "LocalMachine"
  }

This certificate exist for sure and next code returns finds it:

        using (var certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
        {
            certStore.Open(OpenFlags.ReadOnly);
            var certificates = certStore.Certificates.Find(
                X509FindType.FindBySubjectDistinguishedName, "<coma separated multi-line subject name>", true);

            return certificates .Count > 0 ? certificates [0] : null;;
        }

At the same time if to search certificate by X509FindType.FindBySubjectName it founds nothing and I believe this is the issue even though microsoft says that FindBySubjectDistinguishedName is more specific search.


Solution

  • Finally I was able to fix this issue: is something like "CN=name, C=UK, ..." but if you want to FindBySubjectName you must remove "CN=" from search string and leave only the name so it is looks not like "CN=name" but like "name".