How to use SSL Public Key to access secured mailbox from Azure Functions

Jitesh Raut 0 Reputation points
2023-02-01T11:18:33.6533333+00:00

Hello, I am using Azure Function (Operating System: Windows, Java) as a client to read emails from a secured mailbox (Using the JavaMail library and IMAP protocol). This mailbox needs SSL certificate authentication. I have Public Key Certificate (.cer) which I have added to Certificates in Function App settings as follows:
User's image

I have added the Thumbprint generated while adding a certificate to the function app configuration as WEBSITE_LOAD_CERIFICATES and WEBSITE_LOAD_ROOT_CERIFICATE.
User's image

I believed the above setting will allow the function app to access the public key certificate directly but I am getting the following error.
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I tried to add a certificate to cacert available at location JAVA_HOME\ lib\ Security using an Advance Tool available in Azure Function (KUDU) using keytool in CMD using below command:
keytool -import -alias aliasForKey -keystore "{Java-Home}/lib/security/cacerts" -storepass changeit -keypass changeit -file C:/temp/publickey.cer -noprompt

But seems like it needs admin rights to edit this file so that also didn't work for me.
What can be the possible solution for accessing seured mailbox from Azure Function (Java)? How can we configure the Azure function app to fetch emails from secured mailbox.
Any help would be appreciated, Thanks
Jitesh

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,263 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
762 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,421 Reputation points
    2023-02-18T06:15:04.8166667+00:00

    @Jitesh Raut

    Please set the value of WEBSITE_LOAD_CERTIFICATES=*

    In your code you will have to initialize the Java Key Store pointing to the Windows Key Store as:

    KeyStore keyStore = KeyStore.getInstance("Windows-MY");

    keyStore.load(null, null);  // Load keystore

    0 comments No comments