A team member contacted me because he no longer could invoke a local service he was developing. I had a look at the error message the API returned:
One or more errors occurred.
An error occurred while sending the request.
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
The remote certificate is invalid according to the validation procedure
This was a local service using a self-signed certificate and it turned out that the certificate was expired.
Time to create a new self-signed certificate…
Create a self-signed certificate using dotnet dev-certs
Generating a new self-signed certificate is easy in .NET Core thanks to the built-in support in the dotnet commandline tool.
Open a command prompt and execute the following command:
dotnet dev-certs https -ep c:\users\BaWu\localhost.pfx -p crypticpassword
Remark: If the command returns the following response "A valid HTTPS certificate is already present.", a trusted certificate already exists in your store.
Import certificate in IIS
OK, almost there. A last step to get it working in IIS is to import our generated pfx in IIS:
- Open IIS using inetmgr.
- Go to Server Certificates.
- Click on the Import… action on the right. The Import certificate screen is shown.
- Select the pfx, specify the password and click OK.
- Now that the certificate is available in IIS, you can change the bindings to use it. Click on the Default Web site(or any other site) on the left.
- Click on the Bindings… action on the right. The Site Bindings screen is shown.
- Click on the https item in the list and choose Edit… . The Edit Site Binding screen is shown.
- Select the newly created SSL certificate from the list and click OK.