Debug

Linux .NET SSL Connection Error

If you are running into a “SSL connection could not be established” error on your .NET application while using a linux distribution, then this solution might help you solve that.

I was setting up Ubuntu 22.04 LTS with a frontend and backend .NET application recently, and ran into an issue when I tried to call the backend API from the frontend. A few solutions from searching online did not work out for me, but they gave me some hints on what was going wrong. It seemed like either my browser was looking in the wrong folder for my certs, or my dev certs were invalid.

Solution 1

This was a popular solution on stackoverflow, but it did not solve the issue for me on Ubuntu 22.04 LTS. However, this solution did make the dotnet binary print out a recommended solution on my terminal.

dotnet dev-certs https --trust

Solution 2

In the above solution, dotnet will point you to this article on microsoft’s website: https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-8.0&tabs=visual-studio%2Clinux-ubuntu#ssl-linux

Running the following was enough to get SSL to work on firefox, but there is also a section in the article about getting the certs to work on Firefox.

sudo apt update
sudo apt install libnss3-tools

dotnet dev-certs https
sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM

certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n localhost -i /usr/local/share/ca-certificates/aspnet/https.crt
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n localhost -i /usr/local/share/ca-certificates/aspnet/https.crt

If this didn’t help solve your SSL solution, then I guess keep trying out different solutions ¯_(ツ)_/¯

kokopi
guide C#