Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Certificate from within a C# Azure function

I need to access a certificate from my Azure Function.

I followed the steps outlined in Runtime error loading certificate in Azure Functions but it didn't work out.

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

}

Two certificates where uploaded to the Azure Function and the setting WEBSITE_LOAD_CERTIFICATES was added as well and set to either * or to the thumpbrint of the required certificate, but to no avail.

The GetCertificate method should print a list of all certificates in the store, but the store is empty.

Any clues on how to solve this?

like image 564
Henning Krause Avatar asked Dec 07 '16 09:12

Henning Krause


1 Answers

UPDATE: Client certificates are now supported in the Consumption plan.

Client certificates are not yet supported in our Consumption plan, only in App Service plan. This is tracked by an issue in our repo here. We're working on it - please follow that issue for status. Thanks.

like image 63
mathewc Avatar answered Oct 14 '22 07:10

mathewc