drethedevjs
drethedevjs

Reputation: 484

Cannot create developer certificate on Mac

This happened overnight. Yesterday I was able to work on my .NET Core we application. Now every time I try to do a dotnet run I get the following error in my cmd line:

enter image description here

As you can see, I tried running the suggested commands to create a developer certificate which are dotnet dev-certs https and then dotnet dev-certs https --trust. Running both of them, I get

There was an error saving the HTTPS developer certificate to the current user personal certificate store.

Before I ran those commands, I read on this page that I had two competing localhost certifications in my Keychain. So I go in the keychain to delete one of them to no avail. I then delete the other thinking that I can recreate it somehow. Hence me running the commands above.

I then found out that I get the same "There was an error saving the HTTPS..." error for most variations of the command dotnet dev-certs https [options] options (options can be found running dotnet dev-certs https -h

Anyone know why I might be getting this error? How can I get more info as to why it's not able to save to the "certificate store"? It seems like I'm being denied access to some kind of folder.

Upvotes: 8

Views: 21895

Answers (10)

SeeSharp
SeeSharp

Reputation: 698

In my case, I followed the following instructions to fix the issue on macOS Sequoia:

1- Delete any certs that currently exist. Open a terminal and run: dotnet dev-certs https --clean

2- Download the tar.gz file of the "main" release from the .NET SDK package table.

3- Unpack the downloaded file.

4- Remove the quarantine attribute from the unpacked folder. From your terminal run: xattr -d com.apple.quarantine -r Replace with the name of your unpacked folder.

5- Navigate to the unpacked folder

6- From within this folder, run the following to generate and trust the certificate. ./dotnet dev-certs https --trust

Link

Upvotes: 0

Magnus Nygaard Lund
Magnus Nygaard Lund

Reputation: 21

I just had to install the newest .NET SDK link to download .NET 9.0

Upvotes: 2

Dikembe Mutombo
Dikembe Mutombo

Reputation: 148

I used Rider, and my certificate should be stored in the users/{your username}/.aspnet/dev-certs/https folder. This folder had higher permissions, so I couldn't open it, even with a double-click. The solution was:

  1. Delete the users/{your username}/.aspnet/dev-certs/https folder
  2. Create a new folder with the same name in the same directory
  3. Run dotnet dev-certs https --trust

Upvotes: 0

Redbeard
Redbeard

Reputation: 293

I was able to get back working (Mac OS Sequoia) by upgrading to .Net Version 8.0.10 according to this post. Once I upgraded I did the following with success:

  1. dotnet dev-certs https --clean
  2. dotnet dev-certs https --trust

Image that shows successful creation of dev cert

Upvotes: 0

Sgedda
Sgedda

Reputation: 1531

Solutions here did not work for me on Mac OS Sequoia.

This did the trick:

  1. Download tar.gz for mac os and unpack.
  2. Remove quarantine attribute from the unpacked .net sdk directory xattr -d com.apple.quarantine -r dotnet-sdk-9.0.100-rtm.24504.15-osx-x64 (make sure to match version with dowloaded sdk version)
  3. Navigate to the unpacked directory and run: ./dotnet dev-certs https --trust

Reference: https://dev.to/michaelcharles/fixing-the-https-developer-certificate-error-in-net-on-macos-sequoia-516h

Upvotes: 2

Anton Swanevelder
Anton Swanevelder

Reputation: 1175

What worked for me:

  1. Delete all localhost certificates in Keychain
  2. Run dotnet dev-certs https --clean
  3. Run dotnet dev-certs https --trust

Upvotes: 3

Lloyd Powell
Lloyd Powell

Reputation: 18810

I had a different issue to the current answers so thought I'd share to help any other poor souls.

I just had to trust the certificate. In KeyChain, double click the localhost certificate (not the expired one), then set all to always trust:

enter image description here

Upvotes: 1

Ян Ёлкин
Ян Ёлкин

Reputation: 1

run this command from user

dotnet tool uninstall --global dotnet-dev-certs
dotnet tool install --global dotnet-dev-certs

Upvotes: 0

HimalayanCoder
HimalayanCoder

Reputation: 9850

Just open Keychain Access on your Mac

  • Unlock it
  • Lock it
  • Unlock it

enter image description here

and retry

enter image description here

Upvotes: 11

drethedevjs
drethedevjs

Reputation: 484

Ok, so I finally just restarted my computer. When I ran the dotnet run command in VS Code, some prompt came up asking me for my password to allow something in keychain to get access to....something. I should taken a screenshot....my bad. When I put in my password, I received the same error. I, again, followed the steps to create a dev certification by entering the dotnet commands in the initial question. Then I ran dotnet run a second time and viola. It works.

No idea what happened. If anyone can provide some insight then that would be awesome.

If you're experiencing the same problem, then try restarting your computer and following those prompts.

Upvotes: 2

Related Questions