13

I am trying to use the 'dotnet dev-certs' tool to export an https certificate to include with a Docker image. Right now I am using:

dotnet dev-certs https -v -ep $(HOME)\.aspnet\https -p <password>

and I get the error:

Exporting the certificate including the private key.
Writing exported certificate to path 'xxx\.aspnet\https'.
Failed writing the certificate to the target path
Exception message: Access to the path 'xxx\.aspnet\https' is denied.
An error ocurred exporting the certificate.
Exception message: Access to the path 'xxx\.aspnet\https' is denied.
There was an error exporting HTTPS developer certificate to a file.

The problem I see is that no matter what path I supply to export the certificate to I get the same 'Access to the path is denied' error. What am I missing? I know this command has been suggested in numerous places. But I cannot seem to get it to work.

Thank you.

Kevin Burton
  • 2,032
  • 4
  • 26
  • 43

3 Answers3

14

The export path should specify a file, not a directory. This fixed the issue for me on Mac:

dotnet dev-certs https -v -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p <password>

Daniel B
  • 4,145
  • 1
  • 21
  • 21
1

For Ubuntu users:

  1. install libnss3-tools:

    sudo apt-get update -y

    sudo apt-get install -y libnss3-tools

  2. create or verify if the folder below exists on machine:

    $HOME/.pki/nssdb

  3. export the certificate:

    dotnet dev-certs https -v -ep ${HOME}/.aspnet/https/aspnetapp.pfx

  4. Run the following commands:

    certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n localhost -i /home/<REPLACE_WITH_YOUR_USER>/.aspnet/https/aspnetapp.pfx

    certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n localhost -i /home/<REPLACE_WITH_YOUR_USER>/.aspnet/https/aspnetapp.pfx

  5. exit and restart the browser

Source: https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-5.0&tabs=visual-studio#ssl-linux

Realdo Dias
  • 517
  • 5
  • 11
  • 1
    Thanks this works. I failed on linux mint to get chrome to trust the dotnet localhost cert for hours by following what is written in https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-5.0&tabs=visual-studio#ssl-linux The differences I see between yours and theirs is that you're using local user directories and exporting / trusting the cert as a pfx file. I'm not sure why yours works when theirs doesn't .. but I'm happy it works. – Joe Jul 18 '21 at 11:49
  • Hi, i get "Unix LocalMachine X509Store is limited to the Root and CertificateAuthority stores." on step 3. – root Mar 09 '23 at 20:01
0

For me the problem was I was using .Net 5 under CentOS 7.8. Uninstalling .Net 5 and using .Net Core 3.1 SDK instead solved the problem.

bN_
  • 772
  • 14
  • 20