Client Certificate and HttpWebRequest - asp.net

I have two keys
a .PEM-file and a .KEY file.
The pem key is in X509-format.
I have got the the pem-file from a provider (I have sent to the provider the .csr).
I am about to send a client certificate by using the HttpWebRequest and HttpWebResponse classes in Microsoft Visual C# .NET.
For that I have registret the pem-file at the 2003-windows-server by using the mmc-tool in windows:
1) Click Start, click Run, type mmc, and then click OK.
2) On the File menu, click Add/Remove Snap-in.
3) In the Add/Remove Snap-in dialog box, click Add.
4) In the Add Standalone Snap-in dialog box, click Certificates, and then click Add.
5) In the Certificates Snap-in dialog box, click Computer account, and then click Next
6) In the Select Computer dialog box, click Finish.
7) In the Add Standalone Snap-in dialog box, click Close, and then click OK.
8) Expand Certificates (Local Computer), expand Personal, and then click Certificates.
I have then imported the pem-file (also with mmc).
The Question is:
How do I give permission to the certificate?
I have tried this (WinHttpCertCfg.exe tool):
winhttpcertcfg -l -c LOCAL_MACHINE\Root -s NON-Production.pem
And what about the .key-file?

Download XCA. It is a n application built on top of openssl that will help you make a p12 file from your .key-file and .pem-file. It is simple. Import .key-file on Private Keys tab. Import .pem-file on Certificates tab. Then on Certificates tab export the certificate as PKCS#12 (combo box Export Format). Set a password if you wish or leave blank. Then you can import this .p12 file using mmc as you wrote.
Now you can use winhttpcertcfg to set permissions on private key. This documentation will help you. (parameter -s means subject. In mmc open the imported certificate and look for CN=something in the subject field. Then add this something with -s parameter).

Related

Domain user can't be logged in after binding host name IIS

My web site is perfectly working on 8081 port in localhost, In order to provide host name I had to set IIS bindings,
Bindings are set correctly. Additionally I set the host name in host file as well. When I browse website via hostname I am getting below error
"Error Message - HTTP Error 401.0 - Unauthorized"
Please note that I am using IIS 10
You have to whitelist a domain specified in the hosts file in order for windows authentication to work. Try these steps:
Click Start, click Run, type regedit, and then click OK.
In Registry Editor, locate the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Right-click Parameters, click New, and then click DWORD (32-bit) Value.
Type DisableStrictNameChecking and press ENTER.
Double-click the DisableStrictNameChecking registry value and type 1 in the Value data box, click OK
In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
Right-click MSV1_0, point to New, and then click Multi-String Value.
Type BackConnectionHostNames, and then press ENTER.
Right-click BackConnectionHostNames, and then click Modify.
In the Value data box, type the host name or the host names for the
sites that are on the local computer, and then click OK.
Quit Registry Editor, and then restart the IISAdmin service.
I was able to resolve the issue by following this reference: Getting windows authentication to work through local IIS

SSL certificate problem: unable to get local issuer certificate (in R/Shiny)

In a R/shiny project, I have to bring data from endpoint and often use RCurl to do it.
But in this case, the console prints a error about local certificate.
library(RCurl)
data = getURL("https://corporatewebsite.kl/ProyectosTD/getData/dfs32b98565sd65dfkjswfr8J")
Error in function (type, msg, asError = TRUE) : SSL certificate problem: unable to get local issuer certificate
So, I did some test. For example, using Mac computer this problem does not appear, however in shinyapps.io it does.
The problem is that RCurl doesn't get the certificate from the website, then we need to add this certificate like a parameter.
In order to get the certificate you need to follow this steps:
Open the broswer (I used firefox), then go to endpoint (or API) URL and click on the padlock icon.
Broswer + click on padlock icon
Then choose "More information" option, and you will find a button called "View Certificate" in the window that pops up, then click it!
Button Called "View Certificate" in website indetify window
In the new tab will open on your browser there is a section called "Miscellaneous" where you will find the links to download the pem files. Download them!
Miscellaneousd and links of pem files
Finally, add this files in your R project "Working directory" and add one of them like a parameter into getURL command (it is one of two).
library(RCurl)
data =getURL("https://corporatewebsite.kl/ProyectosTD/getData/dfs32b98565sd65dfkjswfr8J", cainfo="file.pem")

IIS 7 Error "A specified logon session does not exist. It may already have been terminated." when using https

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:
Any suggestions?
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:
Next, I imported the *.pfx file into the certs snap-in in MMC, placing it in the Local Computer\Personal node:
Right-click the Certificates node under Personal (under Local Computer as the root)
All Tasks -> Import
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.
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:
(thanks to this post!)
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.
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.
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.
Instead of importing the cert from IIS, do it from MMC.
Then goto IIS for binding.
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.
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.
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.
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.
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
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
Verify your pfx cert is healthy with correct private key
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
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
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...
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.
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.
Closed any localhost dev site i had openned.
Stopped my IIS server and closed the manager
run the manager as Admin
Added all my https bindings, no errors or issues this time.
restarted iis
Everything seems to work after that.
I was getting same error whilst binding the certificate, but fixed after deleting the certificate and importing again through mmc console.
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.
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
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
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".
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.
I was able to fix this problem by removing the then importing it by double clicking the certificate.
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.
What's the difference between the Personal and Web Hosting certificate store?
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.
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
Try :
Go into IIS and delete "VSTS Dev Router" web site and "VSTS Dev Router Pool" application pool.
Run “certlm.msc” and open Personal/Certificates
Delete any cert named “*.vsts.me” and "vsts.me"
Re-deploy

Online Certification Authority, cannot Select.

I am trying to create a domain server and when I reach to specify the online certification Authority, the select button is grayed out.I wish to select the same computer as its the certification authority.Any help is appreciated.
My AD CS was running fine but my IIS server just wouldn't let me select it. To doublecheck that my Certificate Authority server is up I run certutil.exe from CMD and I could see my CA server up and running.
I fixed it in the most canon Windows troubleshooting way. IIS restart.
Refer to this page:
http://social.technet.microsoft.com/Forums/en-US/winserversecurity/thread/e3e43894-30d5-4064-93d1-96d46ef3de14/
The answer from that thread:
note that you can enroll certificates from IIS only from default V1 WebServer template. This template must be added to your issuing CA server.
I had same problem and the answer "V1 WebServer template. This template must be added to your issuing CA server." did not resolve it.
But, after I ran the following in command prompt:
certreq -submit -attrib “CertificateTemplate:WebServer” request.req
my request was processes and I was issued my certificate.
In addition, I got Select button is worked fine.
Another way to resolve this problem, from here: https://www.experts-exchange.com/questions/27758425/Windows-2008R2-IIS-7-Domain-Certficate-problem-select-button-is-greyed-out.html
You could try enrolling the certificate through the certificates MMC
snap-in instead and see if you have better luck:
Start -> Run -> type 'mmc' -> Press enter
(MMC console should open)
File -> Add/Remove Snap-in -> Select 'Certificates' -> Add -> Computer
Account -> Local Computer -> Click OK out of the Add/Remove Snap-ins
window.
Expand certificates -> Expand Personal -> Right click in an empty
space in the main pane -> All tasks -> Request new certificate.
You should be able to run through that wizard and enroll based on your
CA enrollment policies. Any certs that you enroll here and are
applicable for securing websites will appear in IIS.
A couple more checks for those facing this issue:
Use a domain user and not a local user
Check if your CA is an enterprise CA

SSL Certificate will not save

I am trying to install an SSL Certificate (from GoDaddy.com) onto IIS 7. I can add the certificate following the directions found here and it shows up in my list of Server Certificates but once I leave the Server Certificates page and return to it, the certificate no longer shows up in the list.
This certificate is also used on an Apache box to authenticate our website (I am using IIS for a WCF Service API). The certificate is assigned to *.mydomain.com so I thought I could use it for the Apache website server (www.mydomain.com) as well as my API (services.mydomain.com). Am I incorrect in this assumption? Do I need to do something different then the instructions I referenced above to install?
Brian,
I assume you just grabbed the .cer file and imported this onto your IIS box. Sadly this is not possible as your certificate will not contain a private key so it won't be an option in IIS.
The GlobalSign instruction you referenced are fine but that is if you created the CSR on the IIS server itself.
What you will have to do is to create a PFX from from your .key and .cer files from the Apache server and then you can import this PFX onto your IIS Server followed by assigning it for use.
So use this to create your PFX file;
https://support.globalsign.com/customer/portal/articles/1229676-back-up-certificate---apache-openssl
Followed by;
https://support.globalsign.com/customer/portal/articles/1217281
As for everyone else if you just have a .CER file you and did not create the request you need a private key. So create a new CSR and request a reissue from your relevant CA.
The fact you cannot assign a certificate in IIS is because you do not have a private key that corresponds to the certificate.
You have two options:
If you have access to the old machine you first created the certificate just go to that and export ".pfx" file from the certificate, then in the new machine you could easily import it and Done.
If you don't have access to the old machine, so you must reissue the SSL certificate with the help of the seller company.
Hope this help.
See how godaddy response for this case:
https://sg.godaddy.com/community/SSL-And-Security/completing-certificate-request-disappears-from-server/td-p/36299
But it doesn't work.
I tried in my way :
- Use https://www.sslshopper.com/ssl-converter.html to convert my CRT file to PFX file.
- Then go to the IIS -> Server certificates -> Import -> Choose the generated PFX file in previous step.
It worked with me.

Resources