I have a webapp hosted on HostGator shared Windows hosting. Inside Plesk, I secured the site with their Let's Encrypt SSL tool which automatically installs the certificate for you on creation. I can see, on visiting the site, that the browser confirms it is secured by Let's Encrypt.
Now, on starting my app, I am trying to obtain the certificate via thumbprint, but it is coming up empty handed with the following code(note: I have tried both CurrentUser and LocalMachine with the same results):
var x509Store = new X509Store(StoreLocation.CurrentUser);
x509Store.Open(OpenFlags.ReadOnly);
var x509Certificate = x509Store.Certificates
.Find(
X509FindType.FindByThumbprint,
builder.Configuration["Config:AzureADCertThumbprint"],
validOnly: false)
.OfType<X509Certificate2>()
.Single();
x509Store.Close();
So, to dig a bit deeper, I used the following to log all available certs so that I could search through and see what is going on:
logfile.WriteLine("\r\nExists Certs Name and Location");
logfile.WriteLine("------ ----- -------------------------");
foreach (StoreLocation storeLocation in (StoreLocation[])
Enum.GetValues(typeof(StoreLocation)))
{
foreach (StoreName storeName in (StoreName[])
Enum.GetValues(typeof(StoreName)))
{
X509Store store = new X509Store(storeName, storeLocation);
try
{
store.Open(OpenFlags.OpenExistingOnly);
logfile.WriteLine("Yes {0,4} {1}, {2}",
store.Certificates.Count, store.Name, store.Location);
foreach(var cert in store.Certificates)
{
logfile.WriteLine("---"+cert.Thumbprint+" name: "+cert.Subject);
}
}
catch (CryptographicException)
{
logfile.WriteLine("No {0}, {1}",
store.Name, store.Location);
}
}
logfile.WriteLine();
}
I see lots of certs in the stores, and even some Let's Encrypt certs, but none of them with a matching thumbprint. To be more thorough, I used openssl, to calculate the thumbprint in sha256, sha1, and md5. None of those had matches in my logs. Note, the sha1 calculation is the thumbprint I was given on certificate creation.
At this point, I am totally stumped at what is going on and how to proceed. All help is appreciated, thanks!