{"id":20,"date":"2009-11-30T19:54:00","date_gmt":"2009-11-30T18:54:00","guid":{"rendered":"\/post\/2009\/11\/30\/Finding-the-Private-Key-File-of-Certificates.aspx"},"modified":"2014-02-22T19:27:54","modified_gmt":"2014-02-22T18:27:54","slug":"finding-the-private-key-file-of-certificates","status":"publish","type":"post","link":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/","title":{"rendered":"Finding the Private Key File of Certificates"},"content":{"rendered":"

At work, I have created multiple tools which we used to analyse and fix issues related to certificates that we use with Office Communications Server and their respective private key files. To summarize, a user\/service who wants to use the certificate for authentication needs to have read access on the private key. If it doesn’t, you’ll typically see a strange error which many people don’t relate to missing ACLs on the private key file.<\/p>\n

Now these days, you don’t need to write such tools anymore. PowerShell allows you to pretty much do everything you need in this area. Let’s look at the following PS script (let’s call it FindPrivateKey.ps1<\/em>) which accepts a parameter of type System.Security.Cryptography.X509Certificates.X509Certificate2<\/em>, i.e. a reference to the certificate you want to analyze.<\/p>\n

\r\nparam(\r\n    [Parameter(Mandatory=$true)]\r\n    [System.Security.Cryptography.X509Certificates.X509Certificate2]\r\n    $Certificate\r\n)\r\n\r\necho "Looking for private key file of certificate"\r\necho $Certificate\r\necho ""\r\necho "The private key file is '$($Certificate.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName)'"\r\necho ""\r\n\r\n$file = ls $env:userprofile -Filter $Certificate.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName -Recurse -Force -EA SilentlyContinue\r\necho "It is located at '$($file.FullName)'."\r\n<\/pre>\n

I guess I do not need to mention that you can easily find the certificate you’re interested in by running something like<\/p>\n

\r\npushd cert:\\CurrentUser\\My\r\nls\r\n$cert = gci 0DAC31905AEB722D8561BFAF3F3BFD2F551AA197\r\npopd\r\n.\\FindPrivateKey.ps1 $cert\r\n<\/pre>\n

where ‘0DAC31905AEB722D8561BFAF3F3BFD2F551AA197’ is simply the thumbprint of the certificate we’re interested in. From here on it should be easy to check what ACLs the file has (run $file.GetAccessControl()<\/em>) and to modify them (run $file.SetAccessControl()<\/em>).<\/p><\/p>\n

<\/p>","protected":false},"excerpt":{"rendered":"

At work, I have created multiple tools which we used to analyse and fix issues related to certificates that we use with Office Communications Server and their respective private key files. To summarize, a user\/service who wants to use the certificate for authentication needs to have read access on the private key. If it doesn’t, … Continue reading “Finding the Private Key File of Certificates”<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[61],"tags":[35,13,26,32,33,24],"yoast_head":"\nFinding the Private Key File of Certificates - Tales of a Code Monkey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Finding the Private Key File of Certificates - Tales of a Code Monkey\" \/>\n<meta property=\"og:description\" content=\"At work, I have created multiple tools which we used to analyse and fix issues related to certificates that we use with Office Communications Server and their respective private key files. To summarize, a user\/service who wants to use the certificate for authentication needs to have read access on the private key. If it doesn’t, … Continue reading "Finding the Private Key File of Certificates"\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/\" \/>\n<meta property=\"og:site_name\" content=\"Tales of a Code Monkey\" \/>\n<meta property=\"article:published_time\" content=\"2009-11-30T18:54:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-02-22T18:27:54+00:00\" \/>\n<meta name=\"author\" content=\"roger\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"roger\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/\",\"url\":\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/\",\"name\":\"Finding the Private Key File of Certificates - Tales of a Code Monkey\",\"isPartOf\":{\"@id\":\"https:\/\/cymbeline.ch\/#website\"},\"datePublished\":\"2009-11-30T18:54:00+00:00\",\"dateModified\":\"2014-02-22T18:27:54+00:00\",\"author\":{\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916\"},\"breadcrumb\":{\"@id\":\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cymbeline.ch\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Finding the Private Key File of Certificates\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cymbeline.ch\/#website\",\"url\":\"https:\/\/cymbeline.ch\/\",\"name\":\"Tales of a Code Monkey\",\"description\":\"... the adventures of a guy making software.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cymbeline.ch\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916\",\"name\":\"roger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g\",\"caption\":\"roger\"},\"sameAs\":[\"https:\/\/www.cymbeline.ch\"],\"url\":\"https:\/\/cymbeline.ch\/author\/roger\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Finding the Private Key File of Certificates - Tales of a Code Monkey","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/","og_locale":"en_US","og_type":"article","og_title":"Finding the Private Key File of Certificates - Tales of a Code Monkey","og_description":"At work, I have created multiple tools which we used to analyse and fix issues related to certificates that we use with Office Communications Server and their respective private key files. To summarize, a user\/service who wants to use the certificate for authentication needs to have read access on the private key. If it doesn’t, … Continue reading \"Finding the Private Key File of Certificates\"","og_url":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/","og_site_name":"Tales of a Code Monkey","article_published_time":"2009-11-30T18:54:00+00:00","article_modified_time":"2014-02-22T18:27:54+00:00","author":"roger","twitter_misc":{"Written by":"roger","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/","url":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/","name":"Finding the Private Key File of Certificates - Tales of a Code Monkey","isPartOf":{"@id":"https:\/\/cymbeline.ch\/#website"},"datePublished":"2009-11-30T18:54:00+00:00","dateModified":"2014-02-22T18:27:54+00:00","author":{"@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916"},"breadcrumb":{"@id":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cymbeline.ch\/2009\/11\/30\/finding-the-private-key-file-of-certificates\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cymbeline.ch\/"},{"@type":"ListItem","position":2,"name":"Finding the Private Key File of Certificates"}]},{"@type":"WebSite","@id":"https:\/\/cymbeline.ch\/#website","url":"https:\/\/cymbeline.ch\/","name":"Tales of a Code Monkey","description":"... the adventures of a guy making software.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cymbeline.ch\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916","name":"roger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g","caption":"roger"},"sameAs":["https:\/\/www.cymbeline.ch"],"url":"https:\/\/cymbeline.ch\/author\/roger\/"}]}},"_links":{"self":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":3,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/20\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}