How to use non default ca certs for dotnet core and nuget?

Viewed 2179

My company use its own ssl certificates when communicating to internet, the command line e.g. dotnet add package will failed to run:

error: Unable to load the service index for source 
https://api.nuget.org/v3/index.json.
error:   The SSL connection could not be established, see inner exception.
error:   Authentication failed, see inner exception.
error:   The client and server cannot communicate, because they do not possess a common algorithm

Is there anyway to let dotnet tool and libraries use an alternate cert?

2 Answers

As far as I understand, there is an intermediary in your company which encapsulates all connections with company SSL, thus Nuget cannot trust your SSL certificate (It thinks that there is a man in the middle which causes security hole).

you may want to check Issue #4387 and Issue 5773

You may consider to fork Nuget Repository to disable SSL Enforcement.

Also, AFAIK SSL_CERT_DIR and SSL_CERT_FILE environment variables are supported starting from .Net Core 2.1 [3]

Just to elaborate a little bit here. Recently been working on containerization of one of the apps and since there was private nuget repo used as well as nuget.org what we ended up doing is copying nuget config file with all the repos and copying certificate crt file.

If you have only one repo server (under one domain) then you can use SSL_CERT_FILE variable that will contain the path to certificate's crt file.

If you have several repo servers like in my case (nuget.org and one private) then you should you SSL_CERT_DIR environment variable. It should be set to directory where the certs for all repos are. Usually you don't need the cert for nuget.org. The reason you can't use SSL_CERT_FILE variable in this case is that it will try it for nuget.org as well and will fail. so, SSL_CERT_DIR was the solution in our case with just one crt file for private repo.

then dotnet restore --configfile nuget.config stopped complaining

Related