Search code examples
c#azure-functionshanacryptoapi

How to use msCrypto in Azure Function? (Error when connecting to SAP HANA over SSL from Azure Function)


I have an C# Azure Function that connects to SAP HANA and runs queries. Sap.Data.Hana.Core.v2.1.dll and libadonetHDB.dll have been added to the project to allow it to run in Azure (without needing a server with drivers installed). This works fine as long as I don't have encrypt=true on the connection string. However I need to get it working with SSL, which works locally but not in Azure. When run in Azure I get the following error: Connection failed (RTE:[1000013] The system cannot find the file specified.

My understanding is that the database driver defaults to using msCrypto as crypto provider when run on Windows systems. Should/can msCrypto work in Azure Function's without a dedicated host? If so what do I need to do in order to get it working?


Solution

  • Found the solution. The missing file error was caused by the SAP HANA driver not being able to find the default msCrypto trust store. It seems that non had been created by default in our App Service Plan that hosted our Azure Functions. So in order to get it to work, I needed to add a public certificate under TLS/SSL settings on one of our functions within the App Service Plan (guessing it could have been done on the plan itself as well) and then remove it, simply adding it creates the trust store file on disk for the App Service Plan.

    In short, it boils down to the SAP HANA driver trying to use the trust store even though sslValidateCertificate=false setting was used in the connection string. Also find it somewhat confusing that no empty store is created by default from Microsoft side.