Home > database >  AuthenticationException: The remote certificate is invalid because of errors in the certificate chai
AuthenticationException: The remote certificate is invalid because of errors in the certificate chai

Time:08-20

I am consistenly receiving the following error when developing and authenticating locally in Visual Studio:

AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: NotValidTime, UntrustedRoot

Among others, it happens when using HttpClient to call one of our backend-endpoints (localhost) from one of our projects, so it all happens locally.

The certificate was signed/valid from this date last year, and has now run out after a year. None of the other developers on my team are receiving it or had the same problem.

I have then tried a lot of stuff, among others:

We don't have a centralized authentication procedure - it is spread around the system in various places and scenarios, so I am not able to use workarounds like if #DEBUG... //then ignore certificates. I need to generate a valid certificate correctly.

CodePudding user response:

Delete your offending localhost certificates:

Control Panel -> Internet Options - > Content tab.

  1. Click Certificates and remove the ones you no longer require.
  2. Click the Clear SSL State button.

Follow instructions here to recreate new certificate for each of your localhost sites, paying attention to the port number:

https://improveandrepeat.com/2020/05/recreate-the-self-signed-https-certificate-for-localhost-in-iis-express

CodePudding user response:

Cleaning all private keys from the following folder did the trick (I only had one, that I just renamed, which did the trick):

C:\Users\{User}\AppData\Roaming\ASP.NET\Https

Credit to this SO-post answer for the solution.

  • Related