96

I am trying to create Client Certificates Authentication for my asp.net Website.

In order to create client certificates, I need to create a Certificate Authority first:

makecert.exe -r -n “CN=My Personal CA” -pe -sv MyPersonalCA.pvk -a sha1 -len 2048 -b 01/01/2013 -e 01/01/2023 -cy authority MyPersonalCA.cer

Then, I have to import it to IIS 7, but since it accepts the .pfx format, i convert it first

pvk2pfx.exe -pvk MyPersonalCA.pvk -spc MyPersonalCA.cer -pfx MyPersonalCA.pfx

After importing MyPersonalCA.pfx, I try to add the https site binding to my Web Site and choose the above as SSL Certificate, but I get the following error:

enter image description here

Any suggestions?

enb081
  • 3,831
  • 11
  • 43
  • 66

24 Answers24

92

I ran across this same issue, but fixed it a different way. I believe the account I was using changed from the time I initially attempted to set up the certificate to the time where I returned to finish the work, thus creating the issue. What the issue is, I don't know, but I suspect it has to do with some sort of hash from the current user and that is inconsistent in some scenarios as the user is modified or recreated, etc.

To fix it, I ripped out of both IIS and the Certificates snap-in (for Current User and Local Computer) all references of the certificate in question:

IIS certificates

mmc.exe --> add/remove snap-ins, choose certificates then local computer or current user

Next, I imported the *.pfx file into the certs snap-in in MMC, placing it in the Local Computer\Personal node:

  1. Right-click the Certificates node under Personal (under Local Computer as the root)
  2. All Tasks -> Import
  3. Go through the Wizard to import your *.pfx

From that point, I was able to return to IIS and find it in the Server Certificates. Finally, I went to my site, edited the bindings and selected the correct certificate. It worked because the user was consistent throughout the process.

To the point mentioned in another answer, you shouldn't have to resort to marking it as exportable as that's a major security issue. You're effectively allowing anyone who can get to the box with a similar set of permissions to take your cert with them and import it anywhere else. Obviously that's not optimal.

Mike L
  • 4,693
  • 5
  • 33
  • 52
  • 1
    In my case the problem was that I imported a *.cer file into the certificate store. Make sure to import a *.pfx file into the certificate store. – MarioVW Mar 18 '16 at 19:04
  • 2
    It seems as though following these steps (rather than importing directly into Server Certificates) brings in the intermediary certs as well, which seems significant. – Katstevens Jul 11 '16 at 09:34
  • All I can say is thanks @Mike L -- this is literally the only thing that worked for me. – pim Mar 16 '17 at 21:00
  • I used this solution. However, GoDaddy only gave us a *.crt* file for our new certificate, so to extract the private key from the previous certificate (using openssl) and then create a *.pfx* from this (and the *.crt*) and import that. – Jonathan Williams Aug 22 '18 at 10:13
  • 1
    Adding another possible solution. For me it was because I imported the certificate within IIS instead of from the Windows Certificate Manager. – ryanulit Feb 06 '20 at 15:33
79

Security warning: what the checkbox really means is that the certificate can be read by users that shouldn't be able to read it. Such as the user running the IIS worker process. In production use the other answer instead.

Happened to me too, and was fixed by ensuring that "Allow this certificate to be exported" is checked when you import it:

                                            enter image description here

(thanks to this post!)

Community
  • 1
  • 1
Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
  • 13
    Isn't that a security risk? – lanoxx Oct 26 '13 at 22:18
  • I first had to remove the certificate under the MMC snap-in certificate store "Certificates (Local Computer)/Personal" and the in the same store, I right clicked and selected import and then imported the certificate marking it as exportable. – Jonathan Oliver Dec 15 '13 at 02:26
  • @lanoxx you still need the password in order to export the certificate, so it's not totally without security. – aboy021 Jan 20 '14 at 01:53
  • 2
    @aboy021: No you don't. The password which you enter will be used to encrypt the certificate again, but you can choose any password and it does not need to match the original one that was used to import the certificate. – lanoxx Jan 20 '14 at 14:12
  • @lanoxx ouch, thanks for clarifying that. Now I just need a way to get this to work without "Allow this certificate to be exported" checked. – aboy021 Jan 20 '14 at 22:52
  • You also can't grant the IIS Application Pool access to the private key without marking the certificate as exportable – WhiteKnight Aug 18 '14 at 11:43
  • 7
    This is a major security risk. Anyone with administrative access can export your private key. Use Mike L's answer instead. – Steven De Kock Dec 16 '14 at 16:52
  • 3
    @romkyns You're right, but you'd need third party tools to do it. When the key is exportable, non-administrative users with read permissions (can be managed with MMC) can also export the private key. In this case it would include the IIS worker process ... – Steven De Kock Dec 24 '14 at 14:08
11

This must be some kind of IIS bug, but I found the solution.

1- Export MyPersonalCA.pfx from IIS.

2- Convert it to .pem:

openssl pkcs12 -in MyPersonalCA.pfx -out MyPersonalCA.pem -nodes

3- Convert it back to .pfx:

openssl pkcs12 -export -in MyPersonalCA.pem -inkey MyPersonalCA.pem -out MyPersonalCA.pfx

4- Import it back to IIS.

enb081
  • 3,831
  • 11
  • 43
  • 66
10

We had the same issue due to incorrectly importing the certificate into the Current User Personal certificate store. Removing it from the Current User Personal store and importing it into the Local Machine Personal certificate store solved the problem.

  • 2
    I would say this is generally the right answer because it is such an easy mistake to make. If you start the certificate manager using Certmgr.msc you get the personal store rather than the computer store. That means the logons are different. Instead you have to use mmc and then add the snap-in which allows you to select computer store. – OnceUponATimeInTheWest Oct 19 '17 at 09:27
7

Nobody probably cares about this anymore, but I just faced this issue with my IIS 7 website binding. The way I fixed it was going to the Certificate Authority and finding the certificate issued to the server with the issue. I verified the user account that requested the certificate. I Then logged into the IIS server using RDP with that account. I was able to rebind the https protocol using that account only. No exports, reissuing, or extension changing hacks were needed.

SkankyMidget
  • 71
  • 1
  • 1
7

Instead of importing the cert from IIS, do it from MMC. Then goto IIS for binding.

6

According to the MSDN blog post, this can happen when the current user account doesn't have permission to access the private key file which is under the folder "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys". Apparently this can be resolved by granting the user account / user group Full Access permission to the above folder.

I've come across the same issue, and was able to resolve it by simply re-importing the .pfx file with the Allow this certificate ti be exported checkbox selected.

Import Certificate

However, this method imposes a security risk - as any user who has access to your IIS server will be able to export your certificate with the private key.

In my case, only I have access to my IIS server - therefore it was not a huge risk.

5

In our case this problem occurred because we have installed the certificate in a Virtual Machine and made an image of it for further use.

When creating another VM from the image previously created the certificate sends the message.

To avoid this be sure to install the certificate on every new VM installed.

Paulo Dinis
  • 76
  • 1
  • 2
5

We found another cause for this. If you are scripting the certificate install using PowerShell and used the Import-PfxCertificate command. This will import the certificate. However, the certificate imported cannot be bound to a website in IIS with the same error as this question mentions. You can list certificates using this command and see why:

certutil -store My

This lists the certificates in your Personal store and you will see this property:

Provider = Microsoft Software Key Storage Provider

This storage provider is a newer CNG provider and is not supported by IIS or .NET. You cannot access the key. Therefore you should use certutil.exe to install certificates in your scripts. Importing using the Certificate Manager MMC snap-in or IIS also works but for scripting, use certutil as follows:

certutil -f -p password -importpfx My .\cert.pfx NoExport

See this article for more information: https://windowsserver.uservoice.com/forums/295065-security-and-assurance/suggestions/18436141-import-pfxcertificate-needs-to-support-legacy-priv

Ed Greaves
  • 4,807
  • 2
  • 22
  • 19
4

In my case it was because the World Wide Publishing Service user didn't have permissions to the certificate. After installing the certificate, access the certificates module in MMC and right-click the certificate with the issue. Select "Manage Private Keys..." from the "All Tasks" menu and add the above user. This was SYSTEM user in my case.

3

I got this error due to wrong openssl command-line during export PKCS #12 certificate. -certfile key was wrong. I exported certificate again and it was imported successfully.

Der_Meister
  • 4,771
  • 2
  • 46
  • 53
3

Guys after trying almost every single solution to no avail i ended up finding my solution to '“A specified logon session does not exist. It may already have been terminated.” when using https" below

  1. Verify your pfx cert is healthy with correct private key

  2. Run certutil and locate the certs 'unique Container name' - i used certutil -v -store my

3.Navigate to C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys and locate the system file that corresponds to your Container name found above

  1. Check permissions and ensure 'system' has full control to file.

Once applied i then checked IIS and was able to apply to https without error

opieo69
  • 31
  • 1
2

I had the same issue. Solved by removing the certificate from de personal store (somebody put in it) and from the webhosting. All done through the IIS manager. Then I added again to the webhosting store (with everything checked) and I can use HTTPS again...

Edgar
  • 21
  • 1
2

I recieved this error message when trying to use the following powershell command:

(Get-WebBinding -Port 443 -Name
"WebsiteName").AddSslCertificate("<CertificateThumbprint>", "My")

The solution for me was to go into certificate manager and give IIS_IUSRS user permission to see the certificate.

These are the steps I followed:

  • Move the certificate into [Personal > Certificates]
  • Right click [All Tasks > Manage Private Keys]
  • Add the IIS_IUSRS user (which is located on the local computer not in your domain if you're attached to one)
  • Give read permission
Angrist
  • 147
  • 1
  • 9
2

Here's what worked for me:

Step 1: Open up a Run window and type "mmc"

Step 2: Click File > Add/Remove Snap In

Step 3: Add > Certificates, Click OK

Step 4: Choose "Computer Account", then "Local Computer" and proceed.

Step 5: Hit OK

Step 6: Right click the Certificates folder on: Console Root > Certificates (Local Computer) > Personal > Certificates

Step 7: Select All Tasks > Import (Please note that the "Local Machine" is selected on the next window)

Step 8: Browse your .pfx file

Step 9: Then go to the IIS and create https binding

kapitan
  • 2,008
  • 3
  • 20
  • 26
1

I was getting a this error when trying to bind localhost pfx cert for my development machine. Before i tried any of this above, tried something simpler first.

  1. Closed any localhost dev site i had openned.
  2. Stopped my IIS server and closed the manager
  3. run the manager as Admin
  4. Added all my https bindings, no errors or issues this time.
  5. restarted iis

Everything seems to work after that.

Yogurt The Wise
  • 4,379
  • 4
  • 34
  • 42
1

I was getting same error whilst binding the certificate, but fixed after deleting the certificate and importing again through mmc console.

Ram
  • 91
  • 4
1

In my case, it has been fixed by using certutil -repairstore command. I was getting following error, when trying to add certificate to Web Binding on IIS using powershell:

A specified logon session does not exist. It may already have been terminated.

I fixed it by running:

certutil.exe -repairstore $CertificateStoreName $CertThumbPrint

where CertificateStoreName is store name, and CertThumbPrint is the thumbprint of imported certificate.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
naimadswdn
  • 11
  • 1
0

I managed to fix this problem by importing the SSL certificate PFX file using Windows Certificate Manager.

http://windows.microsoft.com/en-us/windows-vista/view-or-manage-your-certificates

jorel
  • 808
  • 7
  • 15
0

I just had this issue today and feel compelled to post my solution in the hope that you will lose less hair than I've just done.

After trying the solutions above, we had to re-issue the SSL certificate from the SSL provider (RapidSSL issuing as a reseller for GeoTrust).

There was no cost with this process, just the five minute wait while the confirmation emails (admin@) arrived, and we gained access again.

Once we had the response, we used IIS > Server Certificates to install it. We did not need the MMC snap-in.

https://knowledge.rapidssl.com/support/ssl-certificate-support/index?page=content&id=SO5757

We kept a remote desktop window to the server open throughout, to avoid any issues with differing login accounts/sessions, etc. I do believe it is an IIS bug as another expert believes, as we only have one RDC account. What is most infuriating is that the very same certificate has been working perfectly for two months before suddenly "breaking".

EvilDr
  • 8,943
  • 14
  • 73
  • 133
0

In my case I imported a newer version of a certificate (PFX for IIS) from StartSSL just recently and forgot to remove the old one, which somehow caused this error (now two certs sort of the same). I removed both of them, imported the proper one, and now it works.

James Wilkins
  • 6,836
  • 3
  • 48
  • 73
0

I was able to fix this problem by removing the then importing it by double clicking the certificate.

0

For me, the fix was to delete the cert from IIS and re-import it, but into the "personal" certificate store instead of "web hosting"

According to the below, this is fine, at least for my own circumstances.

Also, should it make any difference, I imported the certificate via the wizard after double clicking on it on the local machine, instead of via the IIS import method. After this the certificate was available in IIS automatically.

-1

Try :

  1. Go into IIS and delete "VSTS Dev Router" web site and "VSTS Dev Router Pool" application pool.
  2. Run “certlm.msc” and open Personal/Certificates
  3. Delete any cert named “*.vsts.me” and "vsts.me"
  4. Re-deploy
Vikas Gupta
  • 10,779
  • 4
  • 35
  • 42