Implementing Swish payment C# - Only on Azure - Sending client certificate - The request was aborted: Could not create SSL/TLS secure channel

Viewed 919

Before writing this question I have gone through a lot of questions and answers but I can't seem to find a solution. What I'm trying to do is host an application as a Azure App Service that needs to make a call to the Swish API.

Please see this thread for how my implementation runs locally which works fine:

C# HttpClient with X509Certificate2 - WebException: The request was aborted: Could not create SSL/TLS secure channel

System diagnostics log from Azure:

https://pastebin.com/EBFb3zrA

I have tried the solutions from Microsoft forums and SO but none seem to do the trick:

https://social.msdn.microsoft.com/Forums/azure/en-US/ca6372be-3169-4fb5-870f-bfbea605faf6/azure-webapp-webjob-exception-could-not-create-ssltls-secure-channel?forum=windowsazurewebsitespreview

//Tested both, none of them work
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11

Since a lot of the questions are based on accessing an external service and not sending a client certificate the complexity rises a bit as well.

What I have done is in the SSL certificates tab on Azure import the Test certificate. Since .p12 and .pfx are both PKCS #12 files I just renamed the .p12-file. The application runs as B1 Basic App Service Plan so most functionality should be present.

https://stackoverflow.com/a/6821061/3850405

I have also tried this guide to add the certificate to the certificate store in Azure -> Application settings -> App Settings:

https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/

When this did not work I tried to add WEBSITE_LOAD_CERTIFICATES to appSettings in my application but it resulted in a HTTP 503.

Swish certificate and English guide:

https://www.getswish.se/content/uploads/2015/06/Guide-Testverktyg_20151210.zip

2 Answers

We were able to make this work in an Azure Web App. The trick was the appSetting WEBSITE_LOAD_CERTIFICATES and to upload all Swish certificates in the Azure portal. That is, the .pfx file from Swish contains three certs where two of them are root certs. So we exported the root certs and uploaded the .cer files under TLS/SSL settings -> Public Key Certificates (.cer) and then it started to work. You also need to upload them to all deployment slots since the certs will not be automatically copied to the slots.

Related