首页 > 解决方案 > How to manage signed certificates with Azure Function V2

问题描述

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?

标签: azuresslcertificateazure-functions

解决方案


我明白了,这很简单。

首先转到您的 Function App 下的平台功能,您应该会找到 SSL,如下所示。

在此处输入图像描述

然后,您可以根据需要添加公共、私有或 SSL 证书。在我的情况下,我想添加一个我已经导出并拥有它的私钥的私有证书。

在此处输入图像描述

上传您的证书后,转到您的应用设置并添加此键/值:

WEBSITE_LOAD_CERTIFICATES:“您的证书指纹”

您应该能够使用此指纹加载证书,如下所示:

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

推荐阅读