Welcome to TechNet Blogs Sign in | Join | Help

Granting IIS Access to a Certificate's Private Key

When you install an X.509 certificate into a cert store on your machine, only you end up having access to the private key. It turns out the private key is stored as nothing else than a file under the Documents and Settings folder. In order to give others permission to read the key (for example, an ASP.NET worker process when your WCF service is hosted), you simply have to modify the file's ACL appropriately.

I had to do this a long time ago when I first set up our secure RM interop endpoints. Back then, it was just a manual task and I ended up using WseCertificate2.exe - the WSE X.509 Certificate Tool. We recently automated the deployment and I needed a way to do this on the command line. I found out we shipped a tool in the WCF SDK called FindPrivateKey.exe just for this purpose. The tool quickly revealed the location of any private key belonging to any installed X.509 certificate. For example, I found the private key belonging to the OASIS Bob certificate with:

C:\FindPrivateKey.exe My LocalMachine -t "35 03 34 20 1b ee a6 50 2d 11 34 2f 93 ee a0 9f c0 b5 df 01"
Private key directory:
C:\Documents and Settings\onhrebic\Application Data\Microsoft\Crypto\RSA\S-1-5-21-2127521184-1604012920-1887927527-1660115
Private key file name:
7208e197d6e40f342b5e8c2629794d61_8bb36650-2933-4945-8ecb-e3c2f7042931

"35 03 34 20 1b ee a6 50 2d 11 34 2f 93 ee a0 9f c0 b5 df 01" is the key's thumbprint - for some reason I couldn't get -n "CN=Bob" to work. Combined with cacls.exe, the job was easy enough - as all the security SDK samples show:

for /f "delims='' %%i in ('FindPrivateKey.exe My LocalMachine -t "35 03 34 20 1b ee a6 50 2d 11 34 2f 93 ee a0 9f c0 b5 df 01" -a') do set PRIVATE_KEY_FILE=%%i
set WP_ACCOUNT=NT AUTHORITY\NETWORK SERVICE
(ver | findstr "5.1") && set WP_ACCOUNT=%COMPUTERNAME%\ASPNET
echo Y|cacls.exe "%PRIVATE_KEY_FILE%" /E /G "%WP_ACCOUNT%":R

It turns out there's another tool that's freely and more broadly available and even easier to use - WinHttpCertCfg.exe. The tool comes with the Windows Server 2003 Resource Kit Tools together with many other surprisingly useful utilities. The tool is specifically designed to work with ACLs. For example, I was able to view Bob's security list with this simple command:

C:\Program Files (x86)\Windows Resource Kits\Tools>winhttpcertcfg.exe -l -c LOCAL_MACHINE\My -s Bob
Microsoft (R) WinHTTP Certificate Configuration Tool
Copyright (C) Microsoft Corporation 2001.

Matching certificate:
CN=Bob
OU=OASIS Interop Test Cert
O=OASIS

Additional accounts and groups with access to the private key include:
    DOMAIN\onhrebic
    NT AUTHORITY\SYSTEM
    BUILTIN\Administrators

I was than able to easily give the ASP.NET worker process permissions with:

set WP_ACCOUNT=NETWORK SERVICE
(ver | findstr "5.1") && set WP_ACCOUNT=%COMPUTERNAME%\ASPNET
C:\Program Files (x86)\Windows Resource Kits\Tools\winhttpcertcfg.exe -g -c LOCAL_MACHINE\My -s Bob -a "%WP_ACCOUNT%"

Published Monday, October 31, 2005 8:57 AM by onhrebic

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Wednesday, November 30, 2005 3:41 PM by laimis

# re: Granting IIS Access to a Certificate's Private Key

sweet tools ...
Wednesday, November 21, 2007 7:39 AM by Nick

# love position

Sunday, January 13, 2008 10:36 AM by gesseicex

# Incest

Hi people!!! I want introduce my [url=http://www.xrum.977mb.com]new year foto.[/url]

Friday, February 29, 2008 6:21 PM by zxevil135

# re: Granting IIS Access to a Certificate's Private Key

YOxFVI r u crazzy? I told u! I can't read!

Friday, February 29, 2008 6:22 PM by zxevil135

# re: Granting IIS Access to a Certificate's Private Key

oXrgw3 r u crazzy? I told u! I can't read!

Saturday, March 01, 2008 4:03 PM by zxevil136

# re: Granting IIS Access to a Certificate's Private Key

Rqc3Ou r u crazzy? I told u! I can't read!

Thursday, March 06, 2008 5:40 PM by zxevil134

# re: Granting IIS Access to a Certificate's Private Key

mY0QYM r u crazzy? I told u! I can't read, man!

Thursday, March 06, 2008 8:43 PM by zxevil141

# re: Granting IIS Access to a Certificate's Private Key

ki04Qf r u crazzy? I told u! I can't read!

Friday, March 07, 2008 2:31 PM by zxevil150

# re: Granting IIS Access to a Certificate's Private Key

C2k9Cu r u crazzy? I told u! I can't read!

Friday, March 07, 2008 5:30 PM by zxevil151

# re: Granting IIS Access to a Certificate's Private Key

A5saVb r u crazzy? I told u! I can't read!

Friday, March 07, 2008 8:44 PM by zxevil152

# re: Granting IIS Access to a Certificate's Private Key

8qR7Zt r u crazzy? I told u! I can't read!

Friday, March 07, 2008 11:56 PM by zxevil153

# re: Granting IIS Access to a Certificate's Private Key

B20zYc r u crazzy? I told u! I can't read!

Saturday, March 08, 2008 2:29 AM by zxevil154

# re: Granting IIS Access to a Certificate's Private Key

FSHvCq r u crazzy? I told u! I can't read!

Saturday, March 08, 2008 4:58 AM by zxevil155

# re: Granting IIS Access to a Certificate's Private Key

pVMceo r u crazzy? I told u! I can't read!

Saturday, March 29, 2008 5:14 AM by Katherine

# Katherine,Good site

nations, and which are obliged to carry on foreign wars, and to <a href= http://idisk.mac.com/dukebluedevilsfreewe/Public/0/scrapbook-layouts-with-family-pets.html >scrapbook layouts with family pets</a>    production of European commodities, and consequently the real jevbuaumpp

Saturday, March 29, 2008 5:29 PM by Linda

# Good site

In such a work as this, however, it may sometimes be of use to compare the <a href= http://idisk.mac.com/dukebluedevilsfreewe/Public/0/myspace-animated-layout-generator.html >myspace animated layout generator</a>    have been, and probably was, employed in carrying on the late pkkqjxvgcf

Friday, April 18, 2008 12:49 AM by captivity

# re: Granting IIS Access to a Certificate's Private Key

A u see

<a href="http://abramovies1.110mb.com/?">Captivity</a>?">http://abramovies1.110mb.com/?">Captivity</a>?

Give me url to download [url=http://abramovies1.110mb.com/?]Captivity[/url].

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker