从 C# Azure 函数中访问证书

2023-12-28

我需要从我的 Azure 函数访问证书。

我按照中概述的步骤操作在 Azure Functions 中加载证书时出现运行时错误 https://stackoverflow.com/questions/40240195/runtime-error-loading-certificate-in-azure-functions/40247512#40247512但没有成功。

private static X509Certificate2 GetCertificate(string thumbprint, TraceWriter log)
{
    X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    try
    {
        store.Open(OpenFlags.ReadOnly);
        log.Info("Enumerating certificates");
        foreach (var cert in store.Certificates) {
            log.Info(cert.Subject);
        }
        var col = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
        if (col == null || col.Count == 0)
        {
            return null;
        }
        return col[0];
    }
    finally
    {
        store.Close();
    }

}

两个证书已上传到 Azure 函数,并且还添加了设置 WEBSITE_LOAD_CERTIFICATES 并将其设置为 * 或所需证书的指纹,但无济于事。

GetCertificate 方法应打印存储中所有证书的列表,但存储为空。

关于如何解决这个问题有任何线索吗?


更新: 现在支持客户端证书消耗 plan.

我们的客户端尚不支持客户端证书消耗计划,仅在应用服务计划。这是由我们的仓库中的一个问题跟踪的here https://github.com/Azure/azure-webjobs-sdk-script/issues/538。我们正在努力解决这个问题 - 请关注该问题以了解状态。谢谢。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 C# Azure 函数中访问证书 的相关文章

随机推荐