Jump to content

Remote certificate is invalid when calling an external endpoint from web app

Featured Replies

Posted

Using .NET code to resolve “Remote certificate is invalid” when multi-tenant web app is configured as client in client-server model.

 

 

 

You can implement the server thumbprint in the .NET application code to resolve “Remote certificate is invalid” when multi-tenant web app is configured as client in client-server model and making HTTS request to a server configured with a private CA.

 

 

When a web app acts as a client and makes an HTTPS call to an external server secured by a private CA, the web app uses its default installed trusted root CA’s public key to validate the server’s certificate. However, the remote server certificate is signed by a private CA, and since there is no such trusted CA in the web app’s trusted source list, it will not be validated by the web app. You cannot modify the list of Trusted Root Certificates in multi-tenant App Service.

 

 

 

The lab below implements .NET code to resolve “Remote certificate is invalid”.

 

 

 

Prerequisites

 

  • Server: an Azure VM with IIS Server installed
  • Client: windows web app
  • Domain: emmamusic.org (Here, we use app service domain in Azure)
  • Certificates: two certificates. One is signed by well-known CA and another one is signed by private CA.

 

Server

 

  • 731x150vv2.png.030835e8b838e130473b45cb0f4442de.png

 

Client

 

  • web app webapp-windows
    mediumvv2px400.png.a9ff69ea584a604c53a2e8e64ab20e1c.png

 

 

 

Implementation

 

The following code is referencing below GitHub repository.

 

ardoric/TrustDotNET: Sample dot net web app showing how to add TLS Trusted CA via code (github.com)

 

 

 

The application code implements two HTTPS calls to remote server.

 

 

Lab

 

Test 1: remote server with server certificate signed by a well-known CA

 

Success: HttpClientBase

 

mediumvv2px400.png.5f42206b9a3d2525fe8f4af95086841d.png

 

Test 2: remote server with server certificate signed by a private CA

 

Failed: HttpClientBase is without custom validation and private CA is not listed in trusted root CA list of web app as well.

 

776x182vv2.png.dccf9371874134adcf22528ac003f9fb.png

 

 

 

If app service logs is enabled, you can use log stream to view the error message 780x139vv2.png.85756101c8b78a444066f46aa6989c93.png

 

 

 

You can also use the command: openssl s_client -connect emmamusic.org:443 to check remote server certificate as illustrated below.

 

mediumvv2px400.png.4d8fe9c21e35b5220e3681c210fb0ca9.png

 

 

 

Test 3: remote server with server certificate signed by a private CA

 

Success: HttpClientCustom is with a custom server certificate validation. Though the private CA is not listed in trusted root CA list of web app, it is validated in the application code by thumbprint.

 

564x109vv2.png.285944de02ab8a81fa6df800b748e10e.png

 

mediumvv2px400.png.f7bd87c03f42050683cb3227bf4db696.png

 

 

 

Conclusion

 

You cannot modify in the list of Trusted Root Certificates in multi-tenant App Service; so therefore, you have 3 solutions:

 

  1. Bind the server with a Trusted CA certificate.
  2. Use an App Service Environment
  3. Implement Server thumbprint in code.

 

Reference

 

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...