.netazurecertificate

Azure Certificate Issue


I have created an API app service in Azure. This API connects securely to another API using 2 certificates that I have uploaded through the SSL panel for that project. So a few things here:

1) I'm using the free trial where SSL is not enabled. But it allows me to change the plan and upload them anyway. I'm wondering though if they are truly being used because of my plan?

2) When I try to find one of the certs based on its thumbprint, it can't be found and obviously I can't make a connection to the other API.

3) My domain is not secure, I don't have a certificate for my API, would this disallow me from connecting to the other API.

Everything works from a local environment with these 2 certs installed, but I've been stumped on this issue for a few days now. Any help would be appreciated.


Solution

  • You need to set an app setting with a key of WEBSITE_LOAD_CERTIFICATES and a value containing either:

    1. Comma-separated thumbprints for the ones you want to load
    2. Or just an asterisk * to load all of them

    This will allow your app to use the certificates you upload.

    More on that you can find here: https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/

    Example code from the above link:

    using System;
    using System.Security.Cryptography.X509Certificates;
    
    namespace UseCertificateInAzureWebsiteApp
    {
      class Program
      {
        static void Main(string[] args)
        {
          X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
          certStore.Open(OpenFlags.ReadOnly);
          X509Certificate2Collection certCollection = certStore.Certificates.Find(
                                     X509FindType.FindByThumbprint,
                                     // Replace below with your cert's thumbprint
                                     “E661583E8FABEF4C0BEF694CBC41C28FB81CD870”,
                                     false);
          // Get the first cert with the thumbprint
          if (certCollection.Count > 0)
          {
            X509Certificate2 cert = certCollection[0];
            // Use certificate
            Console.WriteLine(cert.FriendlyName);
          }
          certStore.Close();
        }
      }
    }