How to manage signed certificates with Azure Function V2

纵然是瞬间 提交于 2020-01-02 06:59:35

问题


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:


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.

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.

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();
    ...


来源:https://stackoverflow.com/questions/53778977/how-to-manage-signed-certificates-with-azure-function-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!