9
votes

I deployed a web application as a Web App on Azure App Service. I uploaded some certificates to the Azure Portal, since the Web App runs over SSL, and we use another certificate to perform some decryption.

For the latter case I have a method (which works fine locally) to find a certificate:

public static X509Certificate2 FindCertificate(KnownCertificate certificate)
    {
        return FindCertificate(StoreName.My, StoreLocation.CurrentUser, X509FindType.FindByThumbprint, certificate.Thumbprint);
    }

But I get an error that the certificate with thumbprint XYZ is not found. Although, on the Azure Portal it is present. (I had uploaded and imported it)

I am using StoreLocation.CurrentUser as suggested in THIS POST but it still does not work. Am I using the wrong store or what else am I missing?

EDIT: I have managed to remotetly debug my WebApp and with the ImmediateWindow feature of VisualStudio I have executed this code

new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser).Certificates.Find(findType, findValue, false).Count;

testing all possible combinations of StoreNames and StoreLocations but to no avail.

Is it possible like stated here that for using certificate with purposes other than https traffic you would need a Cloud Service and that (I suppose that) App Services do not support it?

1
For any one whos having similar issue -y ou don't need to do this - "testing all possible combinations", when you upload certificate to Azure app service, it always goes into StoreName.My, Store Location.CurrentUser.Dhanuka777

1 Answers

19
votes

You need to add WEBSITE_LOAD_CERTIFICATES to your web app App Settings. Set the value to either ' * ' or to the thumbprint of your certificate you want loaded into the web app environment. My personal preference is to set this value to ' * ', which means, load all certificates that have been uploaded.

enter image description here

After you apply this change you should be able to load your certificate from within your web app code.

More information on how to use certificates is available here. The article is a bit dated (in today's standards) but still relevant.