Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure App Services - Can't find certificate by thumbprint

I have a B1 App Service in Azure and I've installed my certificate in it as shown below: enter image description here

When I try to get the certificate, it can't find it. As if no certificates are installed. Here's my code:

using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
    certStore.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection certCollection = certStore.Certificates.Find(
        X509FindType.FindByThumbprint,
        certificateThumbprint,
        false);

    if (certCollection.Count > 0)
    {
        return certCollection[0];
    }

    throw new Exception("Certificate not found!");
}

I've verified the certificate thumbprint and even tried putting it hard-coded as string.

When I try to print the number of certificates in the store like this:

Console.WriteLine("certStore.Certificates.Count : " + certStore.Certificates.Count);

it returns zero certificates.

I also tried changing StoreName and StoreLocation - still same result. And even when not giving any StoreName or StoreLocation it still doesn't find any certificates.

like image 579
developer82 Avatar asked Jun 21 '17 09:06

developer82


1 Answers

You need to add an app setting called: WEBSITE_LOAD_CERTIFICATES

From https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/?v=17.23h:

Adding an app setting named WEBSITE_LOAD_CERTIFICATES with its value set to the thumbprint of the certificate will make it accessible to your web application. You can have multiple comma-separated thumbprint values or can set this value to “ * “ (without quotes) in which case all your certificates will be loaded to your web applications personal certificate store.

like image 181
Saca Avatar answered Nov 15 '22 09:11

Saca