aspnetcore: Can't create development certificate on macOS Catalina
Describe the bug
Trying to generate a development certificate on my macOS Catalina (10.15.4 Beta (19E242d)) using the dev-certs
tool but is not not working.
output:
iRuiMSFT-MBP:~ rmarinho$ dotnet dev-certs https
A valid HTTPS certificate with a key accessible across security partitions was not found. The following command will run to fix it:
'sudo security set-key-partition-list -D localhost -S unsigned:,teamid:UBF8T346G9'
This command will make the certificate key accessible across security partitions and might prompt you for your password. For more information see: https://aka.ms/aspnetcore/2.1/troubleshootcertissues
A valid HTTPS certificate with a key accessible across security partitions was not found. The following command will run to fix it:
'sudo security set-key-partition-list -D localhost -S unsigned:,teamid:UBF8T346G9'
This command will make the certificate key accessible across security partitions and might prompt you for your password. For more information see: https://aka.ms/aspnetcore/3.1/troubleshootcertissues
password to unlock /Users/rmarinho/Library/Keychains/login.keychain-db:
keychain: "/Users/rmarinho/Library/Keychains/login.keychain-db"
version: 512
class: 0x00000011
attributes:
0x00000000 <uint32>=<NULL>
0x00000001 <blob>="com.apple.AppleMediaServices.mediaToken.macappstore"
0x00000002 <blob>=<NULL>
0x00000003 <uint32>=<NULL>
0x00000004 <uint32>=<NULL>
0x00000005 <uint32>=<NULL>
0x00000006 <blob>=<NULL>
0x00000007 <blob>=<NULL>
0x00000008 <blob>=<NULL>
0x00000009 <uint32>=0x00000000
0x0000000A <uint32>=0x00000000
0x0000000B <uint32>=0x00000000
0x0000000C <blob>=<NULL>
0x0000000D <blob>=<NULL>
0x0000000E <uint32>=<NULL>
0x0000000F <uint32>=<NULL>
0x00000010 <uint32>=<NULL>
0x00000011 <uint32>=<NULL>
0x00000012 <uint32>=<NULL>
0x00000013 <uint32>=<NULL>
0x00000014 <uint32>=<NULL>
0x00000015 <uint32>=<NULL>
0x00000016 <uint32>=<NULL>
0x00000017 <uint32>=<NULL>
0x00000018 <uint32>=<NULL>
0x00000019 <uint32>=<NULL>
0x0000001A <uint32>=<NULL>
security: SecKeychainItemCopyAccess: A missing value was detected.
Something went wrong. The HTTPS developer certificate could not be created.
To Reproduce
Running
dotnet dev-certs https
Further technical details
- ASP.NET Core version : 3.1
- Include the output of
dotnet --info
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version
iRuiMSFT-MBP:~ rmarinho$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.102
Commit: 573d158fea
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.102/
Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26
.NET Core SDKs installed:
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.200 [/usr/local/share/dotnet/sdk]
2.1.300 [/usr/local/share/dotnet/sdk]
2.1.301 [/usr/local/share/dotnet/sdk]
2.1.302 [/usr/local/share/dotnet/sdk]
2.1.403 [/usr/local/share/dotnet/sdk]
2.1.500 [/usr/local/share/dotnet/sdk]
2.1.505 [/usr/local/share/dotnet/sdk]
2.1.700 [/usr/local/share/dotnet/sdk]
2.1.701 [/usr/local/share/dotnet/sdk]
2.2.101 [/usr/local/share/dotnet/sdk]
2.2.107 [/usr/local/share/dotnet/sdk]
2.2.203 [/usr/local/share/dotnet/sdk]
2.2.300 [/usr/local/share/dotnet/sdk]
3.0.100-rc1-014190 [/usr/local/share/dotnet/sdk]
3.0.100 [/usr/local/share/dotnet/sdk]
3.1.100-preview1-014459 [/usr/local/share/dotnet/sdk]
3.1.100-preview2-014569 [/usr/local/share/dotnet/sdk]
3.1.100-preview3-014645 [/usr/local/share/dotnet/sdk]
3.1.100 [/usr/local/share/dotnet/sdk]
3.1.101 [/usr/local/share/dotnet/sdk]
3.1.102 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview9.19424.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-rc1.19457.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0-preview1.19508.20 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0-preview2.19528.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0-preview3.19555.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-rc1-19456-20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0-preview1.19506.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0-preview2.19525.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0-preview3.19553.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 13
- Comments: 92 (34 by maintainers)
Important update
This is an ongoing issue in the latest SDK version (3.1.102) that we are still investigating. To workaround this issue follow these steps:
I was facing the issue as well. Found out that the issue started with the installation of ASP Net Core SDK 3.1.102. I’m using Mac OS 10.15.3 Beta.
After I removed the SDK 3.1.102, the issue went away.
Use this to remove SDK 3.1.102 sudo rm -rf /usr/local/share/dotnet/sdk/3.1.102 sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.2 sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/3.1.2 sudo rm -rf /usr/local/share/dotnet/host/fxr/3.1.2
What I notice while investigating between SDK 3.1.101 and SDK 3.1.102 for the localhost cert is that 3.1.102 is missing the localhost self-signed on System and the login localhost self-signed cert is not marked as always trusted whereas SDK 3.1.101 had both login and System localhost self-signed cert and both are set at always trust for all of the trust level.
For me, everything was fine until I updated the SDK, but this solved the problem. I just removed that SDK version and re-generated my certificates:
dotnet dev-certs https --clean
dotnet dev-certs https -t
Thank you @frozenfroze!!
Hi @rmarinho I’m going through the exact same error, with the exact same dev stack. I’ve gone through all the pages suggesting to remove the certificate from system key, run the --clean and --trust commands but nothing works.
Does anyone have further ideas on what to try next? It’d be greatly appreciated. Thank you.
Followed the steps from this link fixed the issue troubleshoot-certificate-problems
OS X - certificate not trusted
@rmarinho thanks for contacting us.
Could you check a few things? Do you have any “localhost” certificate on your keychain? (If so, assuming that it is an asp.net core generated one) Can you remove it manually? Also check on the system certificates for the same certificate and remove it from there too.
Can you run
dotnet dev-certs https --check
and report the exit code?This should be considered as part of looking at making the dev experience of certs better.
cc @ldillonel
What I noticed is that no matter how many times I run
dotnet dev-certs https --clean; dotnet dev-certs https --trust
it wouldn’t fix the issue until I re-installed the dotnet core sdk. So I’m doing active development for two client projects - one using dotnet core 2.2 and another using dotnet core 3.1. It seems that a valid trusted localhost certificate installed using one sdk won’t work in another. Re-issuing the certificate, restarting the machine, doesn’t do anything. The only thing that helps was to re-install the relevant sdk each time I switch projects. It seems that Microsoft has some bug in that the sdks can’t share the dotnet-dev-certs tool, and installing one sdk overwrites some files in dotnet-dev-certs. It doesn’t seem very robustly built.@aspnetde we are working on a solution to this problem.
The latest SDK 5.0-preview4 SDK contains an updated version of the tool that fixes this issue. We have plans to patch the current LTS SDK once we have enough confidence that the new approach doesn’t introduce additional issues.
I’m also running into this issue. Just started happening somewhat randomly. I installed dotnet 6 preview 6, ran into issues when trying to run a project and uninstalled it (by doing
rm -rf /usr/local/share/dotnet
). Then I reinstalled dotnet 6 preview 2 (which seems to be the most stable version on my M1 MacBook with Big Sur).Then when I tried to run an aspnet core project, and I got the error:
I tried all the above steps
./generate.sh
and--clean
then--trust
, manually deleting certificates. Nothing worked.I’ve gone as far as building AspNetCore locally to be able run the
dotnet-dev-certs
project in debug mode to see what’s going on.State 1
When I run
--trust
and my login AND System keychain have no localhost certificate I get the exception:Debugging locally was the only way I was able to track down this down. Passing the
--verbose
flag seems to have no effect for me and doesn’t make it print more things.State 2
After running
./generate.sh
then running--check
in debug shows me that the certificate doesn’t have a corresponding private key in my keychain.This explains why I get this error when running a project after running
./generate.sh
.Seem’s like there’s something really weird going on with my keychain. I think I may bite the bullet and hit the ‘Reset Default Keychains’ in Keychain Access (after unchecking the Keychains item in the iCloud sync setting in the preferences, and making a backup of them).
Side note: I also noticed in the generate script that there is a typo in the certificate sentinel filename. https://gist.github.com/javiercn/d04855b7a3581bf97d1ab9597935413f#file-generate-sh-L33
It should be
~/.dotnet/certificates.${certificateSha256Hash}.sentinel
rather than~/.dotnet/certificate.${certificateSha256Hash}.sentinel
. Seems like the cert tool expects it to be ‘certificates’.See: https://github.com/dotnet/aspnetcore/blob/3accbd6abe9701c431855a5c4ab5b6098841cf5d/src/Shared/CertificateGeneration/MacOSCertificateManager.cs#L92
To workaround this issue follow these steps:
Open Keychain Access
Delete all the localhost certificates in the login and system keychain (that were created by ASP.NET Core).
Download the following script generate.sh
Open a bash terminal.
chmod 555 generate.sh
./generate.sh
If it’s not working make sure to delete all the localhost certificates in the login keychain. Then on bash terminal
dotnet dev-certs https --trust
@ardaozceviz I’m not exactly sure how to do that without risking removing other localhost certificates, that’s why I didn’t do it. On the same gist there are instructions to remove the certs manually using keychain.
@jdelano does the script described here not fix the issue for you? https://gist.github.com/javiercn/d04855b7a3581bf97d1ab9597935413f#file-generate-sh
run the script by @javiercn in his batch file and the problem will go away. then just wait for a proper fix.
@XiaroanZhang the step that is failing is the last one, the set-key-partition-list one, so you should be fine if you try to run an app (you’ll have to close and reopen the browser)
There are many reports on this thread, so I’m going to try and give some manual steps on how to potentially address/mitigate this issue while we investigate: See here for instructions on how to remove, make accessible across partitions and trust certificates manually.
For those affected, I suggest you do as follows:
dotnet dev-certs https
certificate.<<sha256>>.sentinel
inside ~/.dotnet/security add-trusted-cert
as described in the document.Important details for this issue
In order for us to help investigate this issue, the following information will help us: