Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net core keep using the expired certificate

Recently, my localhost certificate is expired, I have gone to "sertmgr.msc" remove all localhost certificate and restart the VS and add a new localhost certificate to windows. But when am I running my application again, still use the old expired certificate not the new one, does anyone know how to fix that? I have already run the command show below.

dotnet dev-certs https --clean
dotnet dev-certs https --trust

Expired Cert Cert In Cert Manage

like image 868
笑问苍天 Avatar asked Oct 31 '20 03:10

笑问苍天


People also ask

Can you use an expired certificate?

When using an expired certificate, you risk your encryption and mutual authentication. As a result, both your website and users are susceptible to attacks and viruses. For example, a hacker can take advantage of a website with an expired SSL certificate and create a fake website identical to it.

How do you fix this certificate has expired or is not yet valid?

Removing Cookies in Google Chrome It will load all cookies for the website. Now use Remove All Shown to delete all cookies or use the Trash bin icon to delete one by one. This should fix the error, This certificate has expired or is not yet a valid error.

How do I stop my SSL certificate from expiring?

You might have to distribute the updated certificates to other client/server systems as well, depending on the type of SSL negotiation being used. To avoid this, take actions to renew certificates before they expire. Renewal updates are much simpler and less disruptive to process.

Do you need to remove expired SSL certificate?

Answer. If you use S/MIME to sign or encrypt email messages, you should not delete your personal certificate, even after it expires. Doing so would cause you to permanently lose access to those messages.


3 Answers

I managed to hack my way around this issue:

  1. Before you do anything, clean the old certificate and generate a new trusted one.

    dotnet dev-certs https --clean
    dotnet dev-certs https --trust
    
  2. And if the process above fails, manually remove the certificates before retrying the clean/trust commands.

  3. Get the User Secrets ID of the Web Application you're having trouble with. Search for UserSecrets.UserSecretsIdAttribute(" in your project folder and take the GUID.

  4. Go to %APPDATA%\Microsoft\UserSecrets and open the folder containing the GUID of the problematic project you are struggling with and leave it open.

  5. Create a new Asp .Net Core project, get its secrets GUID, go to the corresponding secret folder (%APPDATA%\Microsoft\UserSecrets\GUID), and open the file secrets.json. You should see something like this

    {
      "Kestrel:Certificates:Development:Password": "8353f2ec-3cc0-4052-9776-9585b6abd346"
    }
    
  6. Copy that setting from the newly created project secrets.json and use it to override the development password on the secrets.json of the broken project

This way, I've managed to get my old project to use the newly generated certificate. It is hacky, but it works

like image 93
Pedro Yan Ornelas Avatar answered Oct 10 '22 13:10

Pedro Yan Ornelas


I assume you're using IIS Express to host your application. If so, it sounds like you're missing linking the certificate to your application(s) as described in this blog post:

Go to C:\Program Files (x86)\IIS Express and run the following from the command line, entering the proper port number and the new certificate thumbprint:

IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:PORT/ -CertHash:THUMB
like image 1
Xerillio Avatar answered Oct 10 '22 13:10

Xerillio


Based on Pedro's answer,

I used:

dotnet dev-certs https --clean
dotnet dev-certs https --trust

to clean/replace the old certs.

Then I went to:

%APPDATA%\Microsoft\UserSecrets

And deleted all the folders found there.

Now my application runs without complaining. Creating a new .net core 6 application and running it didn't create a new folder, so I don't know if it's no-longer required.

like image 1
Kinetic Avatar answered Oct 10 '22 14:10

Kinetic