How to manage signed certificates with Azure Funct

2019-05-14 08:37发布

I am working on Azure Functions App on Consumption Plan. The Func App required to load a specific signed certificate.

In local machine I setup the certificate as personal certificate and everything works fine.

After publishing on azure, I am getting this error:

There are 0 certificates with the subject name cert.name in LocalMachine, MyUse scripts/certificates/ to generate this

Nothing helpful on SO or even in Azure Func documentation on how to use certificate with azure functions.

Anyone has experience with that?

1条回答
地球回转人心会变
2楼-- · 2019-05-14 08:59

I got it and it's pretty straight forward.

First go to platform features under your Function App and you should find SSL as shown below.

enter image description here

Then you can add a public, private or SSL certificate based on your needs. In my case I want to add a private Certificate which i already exported and have it's private key.

enter image description here

After uploading your certificate, go to your app settings and add this key/value:

WEBSITE_LOAD_CERTIFICATES: "Your Cert Thumbprint"

You should be able to load the certificate using this Thumbprint like this:

using System;
using System.Security.Cryptography.X509Certificates;

    ...
    X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    certStore.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection certCollection = certStore.Certificates.Find(
                                X509FindType.FindByThumbprint,
                                // Replace below with your certificate's thumbprint
                                "000000000000000000000000000000000000000",
                                false);
    // Get the first cert with the thumbprint
    if (certCollection.Count > 0)
    {
        X509Certificate2 cert = certCollection[0];
        // Use certificate
        Console.WriteLine(cert.FriendlyName);
    }
    certStore.Close();
    ...
查看更多
登录 后发表回答