<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses &#187; Certificates</title>
	<atom:link href="http://huddledmasses.org/tag/certificates/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>PowerShell Authenticode Signatures and trust&#8230;</title>
		<link>http://huddledmasses.org/powershell-authenticode-signatures-and-trust/</link>
		<comments>http://huddledmasses.org/powershell-authenticode-signatures-and-trust/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 03:44:55 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Apt-Get]]></category>
		<category><![CDATA[Authenticode]]></category>
		<category><![CDATA[Certificates]]></category>
		<category><![CDATA[Code Signing]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Repository]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/powershell-authenticode-signatures-and-trust/</guid>
		<description><![CDATA[The cool thing about the way authenticode signatures are implemented is that even if a script is signed with a self-issued certificate, you can still tell if the script has been tampered with&#8230; Check this out: [1]:ls SCRIPTS:\UnknownCert\Sample*.ps1,SCRIPTS:\TrustedCert\Sample*.ps1 &#124; gas Directory: SCRIPTS:\UnknownCert\ SignerCertificate Status Path &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212; 0DA3A2A2189CD74AE371E6C57504FEB9A59BB22E UnknownError Sample.ps1 0DA3A2A2189CD74AE371E6C57504FEB9A59BB22E HashMismatch SampleBAD.ps1 Directory: [...]]]></description>
			<content:encoded><![CDATA[	<p>The cool thing about the way authenticode signatures are implemented is that even if a script is signed with a self-issued certificate, you can still tell if the script has been tampered with&#8230; Check this out:</p>

<div class="code posh" style="background: black; color: #ccc; font-weight:bold; line-height:0.5em;">
<span style="color:#ffcc00;">[1]:</span>ls SCRIPTS:\UnknownCert\Sample*.ps1,SCRIPTS:\TrustedCert\Sample*.ps1 | gas<br />
<br />

    Directory: SCRIPTS:\UnknownCert\<br />
<br />

SignerCertificate                         Status        Path<br />

&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-                         &#8212;&#8212;&#8212;        &#8212;&#8212;<br />

0DA3A2A2189CD74AE371E6C57504FEB9A59BB22E  UnknownError  Sample.ps1<br />

0DA3A2A2189CD74AE371E6C57504FEB9A59BB22E  HashMismatch  SampleBAD.ps1<br />
<br />

    Directory: SCRIPTS:\TrustedCert\<br />
<br />

SignerCertificate                         Status        Path<br />

&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-                         &#8212;&#8212;&#8212;        &#8212;&#8212;<br />

B658C20AAD070B9FF105C69BBC47ADCF56FD5576  Valid         Sample.ps1<br />

B658C20AAD070B9FF105C69BBC47ADCF56FD5576  HashMismatch  SampleBAD.ps1
</div>

	<p>As you can see, in the case of a <span class="caps">UNTRUSTED</span>, but correct, signature, you get the <strong>UnknownError</strong> status. If you checked the output object, it has a <code>StatusMessage</code> which says <em>&#8220;A certificate chain could not be built to a trusted root authority&#8221;</em>. If the script has been altered (as in my SampleBAD.ps1 scripts) then the signature is incorrect, you get the <strong>HashMismatch</strong> status, and the corresponding <code>StatusMessage</code> is: <em>&#8220;The contents of file SCRIPTS:\TrustedCert\SampleBAD.ps1 may have been tampered because the hash of the file does not match the hash stored in the digital signature. The script will not execute on the system&#8230;&#8221;</em></p>

	<p>One odd thing is that the messages are inaccurate about not executing the script: if you have your execution policy set to Unrestricted, the signatures aren&#8217;t checked at all, and if you have it set to RemoteSigned they are only checked for remote scripts. Furthermore: if you do have your execution policy set to AllSigned, neither the <strong>UnknownError</strong> nor the <strong>HashMismatch</strong> script will execute &#8212; only the one <strong>Valid</strong> scripts will.</p>

	<h3>So what?</h3>

	<p>The bottom line is: you can verify that nothing has happened to the script &#8212; even if you don&#8217;t trust the person who signed it <em>nor</em> the person, group, or company that issued a certificate to them.  Why does this matter? Well, I recently wrote a post about <a href="http://huddledmasses.org/code-signing-with-openssl-and-powershell/">generating self-signed code-signing certificates</a> which can be used for signing PowerShell scripts, and if you chose to distribute scripts signed with one of those certificates, nobody would be able to verify the root CA(Certificate Authority) and so the signatures would never come out as valid.</p>

	<p>Is there any usefulness in this? Well, I guess that depends on your perspective, but basically, <span style="font-size: 1.1em; font-weight: bold; color:#cc3399;">I think that if I published my scripts signed and tell you on my blog what my certificate thumbprint is &#8230; that you&#8217;d be more able to trust those scripts than you are now (when they&#8217;re not signed at all)</span>.  Of course, I could go one step further, and publish my own self-signed root CA certificate so you could choose to trust that &#8230;</p>

	<p>I was recently having a conversation about the future of the <a href="http://PowerShellCentral.com/scripts/">PowerShell Script Repository</a> and it involved some discussion of whether it would be safe to use the <a href="http://huddledmasses.org/automating-the-powershell-script-repository/">Repository Scripts</a> to download dependencies automatically&#8230; The answer, obviously, is <strong>no</strong>. </p>

	<p>But it started me thinking again about scripts being signed. If you had already chosen to run a script provided by me (which was signed by a certificate you couldn&#8217;t verify), maybe you&#8217;d be willing to trust other scripts signed by the same certificate, so we <em>could</em> automatically download them.  Well, maybe even then you wouldn&#8217;t want to trust it, but lets assume that you were running a copy of the PowerShell Script Repository internally at your company &#8230;</p>

	<h3>Would you use automatic dependency downloading?</h3>

	<p>We could easily have a function that takes the script name and verifies that you have that script available &#8212; and if not, it could fetch the script from your designated repository and verify that the signature is valid even if the certificate isn&#8217;t signed by a root certificate authority you trust.</p>

	<p>Of course, such automatically downloaded scripts would need to be marked as &#8220;Remote&#8221; so if you had your Execution Policy set to AllSigned or Remote Signed, then the script would only run if you had trusted it&#8217;s author (and you wouldn&#8217;t even be offered the option if you hadn&#8217;t trusted the CA(Certificate Authority) that issued his script.  In that case you would need to review the script and re-sign it yourself &#8212; or manually remove the &#8220;remote&#8221; bit.</p>

	<p>Imagine something like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;"># Get-Paste.ps1</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Paste</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">Dependency</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Webfile</span></span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># lots of code here that uses the Get-Webfile function ...</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Webfile</span></span> http:<span style="color: #66cc66;">//</span>HuddledMasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>When you tried to execute Get-Paste, it would check for Get-Webfile, and if it couldn&#8217;t find it, would attempt to download it (presumably this would involve asking your permission, and placing it in some specific location that was in your <span class="caps">PATH</span>, so that the script could find it when it tried to execute it on the next line).</p>

	<h4>Or maybe, an Apt-Get?</h4>

	<p>Perhaps instead of this mechanism, we could use the new embeddable &#8220;Data Language&#8221; to provide a list of dependencies, like: <code>DATA Dependencies { scripts = Get-WebFile }</code> and run a <code>Resolve-Dependencies</code> function against each script before trying to execute it &#8212; this way, if you downloaded a script from the repository using <code>Get-Paste</code>, it could automatically <code>Resolve-Dependencies</code> and offer to download the other scripts at the same time.</p>

	<p>The fact is that doing this <em>correctly</em> will require some major reworking of the script repository to allow tracking new versions of scripts better, and to let the script repository track dependencies explicitly so that you don&#8217;t have to download the whole script to find out what it&#8217;s dependencies are, but this could be done, if people are actually interested in it.</p>

	<h3>A web of trust?</h3>

	<p>Ad I&#8217;m thinking about this, I&#8217;m wondering again about the possibility of creating an informal web-of-trust style code-signing certificate tree.  The idea would be that <span style="font-size: 1.05em; font-weight: bold; color:#cc3399;">the Script Repository would have a CA certificate of it&#8217;s own, and would issue code-signing certificates to PowerShell developers</span> <em>cheaply</em> (free?) by skipping over some of the usual verification steps. In an ideal world, Microsoft would issue the PowerShell Community a &#8220;SubCA&#8221; certificate signed by their root &#8212; in the interests of promoting code signing for PowerShell &#8230; </p>

	<p>However, if we couldn&#8217;t get a SubCA certificate for &#8220;free&#8221; or cheap, we could simply generate and self-sign our own, and publish it on the Script Repository website, requiring users to download and import it into their trusted roots if they wanted to use trust permissions. Regardless of whether they chose to trust it or not, they could still verify the scripts were valid, which is better than what we have now &#8212; the rest would be up to the user.</p>

	<p>Of course, if we were issuing certificates that were self-signed anyway, we could go a step further and sign SubCAs and distribute them to, say, the Microsoft PowerShell MVPs and trusted community leaders after verifying email addresses and physical mailing addresses etc &#8230; trusting <strong>them</strong> further to issue (less trusted) code-signing certificates to additional developers.</p>

	<h4>Call to action</h4>

	<p>All of this is extra work for the people maintaining the script repository web site (right now, that&#8217;s me), but it might be worth it if it makes it easier to use the script repository, easier to trust the scripts on it, and easier to verify that an author <strong>is</strong> who he says he is &#8230; what do <em>you</em> think?</p>

	<ol>
		<li>Should we put in the work to set up a web of trust or should we leave it up to individual developers to self-sign and generate their certificates (and publish their public roots on their websites <em>or something</em>)?
		<li>Should we just leave it at that (scripters can sign their scripts if they feel like it), or should we push and promote script signing? As an incomplete example of <em>promoting</em> code-signing, I mean:
	<ol>
		<li>We can use certificates as the primary (or only) way for authors to identify themselves (that is: no log-ins, unsigned scripts are marked &#8220;anonymous&#8221; ... but we track the thumbprints and allow you to browse scripts signed by the same author, etc).</li>
		<li>We can include the signature thumbprint with the short descriptions output on the search results and from the scripts which interact with repository.</li>
	</ol></li>
	<ol>
		<li>We can restrict &#8220;latest version&#8221; updates to only scripts which are signed, and optionally to new versions signed by the same certificate.</li>
	</ol></li>
	</ol>
	<ol>
		<li>Is there any point (or hope) in trying to get a <em>signed</em> CA certificate? Can Microsoft help us out? Do any of you work at a certificate authority?</li>
	</ol>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-authenticode-signatures-and-trust/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Signing with OpenSSL and PowerShell</title>
		<link>http://huddledmasses.org/code-signing-with-openssl-and-powershell/</link>
		<comments>http://huddledmasses.org/code-signing-with-openssl-and-powershell/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 04:17:17 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Certificates]]></category>
		<category><![CDATA[CodeSigning]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=551</guid>
		<description><![CDATA[One of the major security features of PowerShell is the support for code signing of scripts, so that you can set an execution policy that requires scripts to be signed before they can be run. Of course, it goes a bit further than that. When a script has been signed by a certificate with a [...]]]></description>
			<content:encoded><![CDATA[	<p>One of the major security features of PowerShell is the support for code signing of scripts, so that you can set an execution policy that requires scripts to be signed before they can be run. Of course, it goes a bit further than that. When a script has been signed by a certificate with a root Certificate Authority (CA) that you don&#8217;t already &#8220;know&#8221; or trust it can&#8217;t be run at all until you add the root CA to the system&#8217;s certificate store.</p>

	<p>Even after you trust a specific authority, you haven&#8217;t trusted a script author &#8212; so any signed script you run will prompt you whether you want to allow it or not, like so:</p>

<div class="code posh" style="background: black; color: #ccc; font-weight:bold; ">
<span style="color:#ffcc00;">[19]:</span> .\test-script.ps1<br />
<br />

<span style="color:#fff;">Do you want to run software from this untrusted publisher?</span><br />

File C:\Users\Joel\Documents\WindowsPowerShell\test-script.ps1 is published by<br />

E=NoUser@HuddledMasses.org, O=Huddled Masses, L=Rochester, S=New York, C=US<br />

and is not trusted on your system. Only run scripts from trusted publishers.<br />

<span style="color:#fff;">[V] Never run  </span><span style="color:#ffcc00;">[D] Do not run</span><span style="color:#fff;">  [R] Run once  [A] Always run  [?] Help (default is &#8220;D&#8221;):</span><br />

</div>

	<p>The important thing to note here is that you&#8217;re really being asked not about the script, but about the author.  If you choose the <b>Ne<u>v</u>er</b> or <b><u>A</u>lways</b> options, the certificate that was used to sign the script is added to the appropriate certificate store (&#8220;Untrusted Certificates&#8221; or &#8220;Trusted Publishers&#8221;, respectively).  To be clear: this happens for each every new author certificate, regardless of whether it&#8217;s signed by a self-signed cert (where you&#8217;ve already installed the root certificate in your root store) or a certificate issued by a commercial CA &#8212; there&#8217;s no loophole, no matter what anyone may have said <a href="http://blogs.technet.com/industry_insiders/pages/software-restriction-policies-and-powershell-code-signing.aspx">in the past</a>.  </p>

	<p>So, you see &#8230; the support for code signing is built into the core of PowerShell &#8212; and it&#8217;s really a shame not to <a href="http://technetmagazine.com/issues/2008/01/PowerShell">take advantage of it</a>.  There are plenty of articles out there about <a href="http://technet.microsoft.com/en-us/magazine/cc434702.aspx">how to sign your scripts</a>, and more, so I&#8217;m not going to get into that much &#8212; I want to address the question of how hard it is to create the certificates in the first place (and finish by giving you a sample script which will generate and import them to your dev box with a single line command).</p>

	<p><span id="more-551"></span></p>

	<h3>Generating Code Signing Certificates with OpenSSL</h3>

	<p>I&#8217;ve been talking up automatic code-signing for awhile now &#8212; basically, I think that any script editor that pretends to be a PowerShell script editor should be able to sign scripts at the push of a button, even every time you save the file.  On top of that, I think that (like Microsoft&#8217;s <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=fad62198-220c-4717-b044-829ae4f7c125&#38;displaylang=en">Speech Macros</a> app) they should be able to generate a self-signed code-signing script for you.</p>

	<p>Someone emailed me the other day to ask how I proposed to do this, since <a href="http://msdn.microsoft.com/en-us/library/aa386968(VS.85">MakeCert</a>).aspx isn&#8217;t redistributable, and can&#8217;t be counted on to be installed&#8230; Well, as an answer I wrote a script which I&#8217;ll share here, using the open source <a href="http://www.openssl.org/">OpenSSL</a> <a href="http://www.slproweb.com/products/Win32OpenSSL.html">for Windows</a> to generate the certificates.  It&#8217;s a bit more complicated than using MakeCert, but still not a huge thing. Basically, it&#8217;s six lines of code &#8212; each calling the OpenSSL executable.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;"># Generate the private root CA key and convert it into a self-signed certificate (crt)</span><br />
OpenSsl genrsa <span style="color: #000066;">-out</span> <span style="color: #009900;">&quot;CA.key&quot;</span> <span style="color: #000066;">-des3</span> <span style="color: #cc66cc;">4096</span><br />
OpenSsl req <span style="color: #000066;">-new</span> <span style="color: #000066;">-x509</span> <span style="color: #000066;">-days</span> <span style="color: #cc66cc;">3650</span> <span style="color: #000066;">-key</span> <span style="color: #009900;">&quot;CA.key&quot;</span> <span style="color: #000066;">-out</span> <span style="color: #009900;">&quot;CA.crt&quot;</span><br />
<span style="color: #666666; font-style: italic;"># Generate the private code-signing key and a certificate signing request (csr)</span><br />
OpenSsl genrsa <span style="color: #000066;">-out</span> <span style="color: #009900;">&quot;signing.key&quot;</span> <span style="color: #000066;">-des3</span> <span style="color: #cc66cc;">4096</span><br />
OpenSsl req <span style="color: #000066;">-new</span> <span style="color: #000066;">-key</span> <span style="color: #009900;">&quot;signing.key&quot;</span> <span style="color: #000066;">-out</span> <span style="color: #009900;">&quot;signing.csr&quot;</span><br />
<span style="color: #666666; font-style: italic;"># Use the root CA key to process the CSR and sign the code-signing key in one step...</span><br />
OpenSsl x509 <span style="color: #000066;">-req</span> <span style="color: #000066;">-days</span> <span style="color: #cc66cc;">365</span> <span style="color: #000066;">-in</span> <span style="color: #009900;">&quot;signing.csr&quot;</span> <span style="color: #000066;">-CA</span> <span style="color: #009900;">&quot;CA.crt&quot;</span> <span style="color: #000066;">-CAcreateserial</span> <span style="color: #000066;">-CAkey</span> <span style="color: #009900;">&quot;CA.key&quot;</span> <span style="color: #000066;">-out</span> <span style="color: #009900;">&quot;signing.crt&quot;</span><br />
<span style="color: #666666; font-style: italic;"># Combine the signed certificate and the private key into a single file </span><br />
OpenSsl pkcs12 <span style="color: #000066;">-export</span> <span style="color: #000066;">-out</span> <span style="color: #009900;">&quot;signing.pfx&quot;</span> <span style="color: #000066;">-inkey</span> <span style="color: #009900;">&quot;signing.key&quot;</span> <span style="color: #000066;">-in</span> <span style="color: #009900;">&quot;signing.crt&quot;</span></div>

	<p>There are two problems: first, half of those lines actually cause interactive prompts: asking you for your country and state, and email address, various passwords, etc.  On top of that, the default OpenSSL.cnf file distributed with Windows doesn&#8217;t really give you a way to create certificates that can code sign, so if you went through all of those steps &#8212; you <em>still</em> wouldn&#8217;t be able to sign scripts  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> </p>

	<p>My solution to both problems is pretty straight-forward: customize the config file and run the <code>req</code> requests in <code>-batch</code> mode.  Normally that would mean creating a custom OpenSSL.cnf config file with the specific values necessary &#8212; but in this case, I&#8217;ve made a PowerShell script to do it.</p>

	<p><code>New-CodeSigningCert.ps1</code> can generate both the CA certificate and the code-signing certificate, and you can set it up to prompt you as little as possible, however, the point of this isn&#8217;t really to provide a <em>solution</em>, but to provide an <em>example</em> for the developers of editors and IDEs &#8212; so it&#8217;s still a bit rough, and it doesn&#8217;t try to guess your user name, email, and organization information from the environment.</p>

	<h3>Importing Certificates</h3>

	<p>Importing certificates into the Windows Certificate Store can be done with the graphical &#8220;CertMgr.msc&#8221;, but also with any of several command-line tools including <a href="http://msdn.microsoft.com/en-us/library/aa384088.aspx">WinHttpCertCfg.exe</a> from the Windows Server Resource Kit, and <a href="http://msdn.microsoft.com/en-us/library/aa376553.aspx">CertMgr.exe</a> from the Windows <span class="caps">SDK</span>... which of course, aren&#8217;t redistributable. Someone really needs to tell Microsoft to get on the ball with this stuff.</p>

	<p> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  I actually realized recently that you can use System.Security.Cryptography.X509certificates.X509Store to load certificates, rather than the old <span class="caps">COM</span> object, which makes this even easier. The most basic step is to just import the new <code>CA.crt</code> certificate into the Root Store.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$lm</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Security</span>.<span style="color: #003366;">Cryptography</span>.<span style="color: #003366;">X509certificates</span>.<span style="color: #003366;">X509Store</span> <span style="color: #009900;">&quot;root&quot;</span>, <span style="color: #009900;">&quot;LocalMachine&quot;</span><br />
<span style="color: #660033; font-weight: bold;">$lm</span>.<span style="color: #003366;">Open</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;ReadWrite&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$lm</span>.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">PfxCertificate</span></span> <span style="color: #009900;">&quot;$pwd\CA.crt&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span>$?<span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Successfully imported root certificate to trusted root store&quot;</span> <span style="color: #000066;">-fore</span> green<br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #660033; font-weight: bold;">$lm</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span></div>

	<p>You no longer need to use the <a href="http://msdn.microsoft.com/en-us/library/aa388127.aspx"><span class="caps">CAPICOM</span>.Store</a> <span class="caps">COM</span> object even though it&#8217;s basically available everywhere now, and <a href="http://go.microsoft.com/fwlink/?linkid=84567">is redistributable</a> &#8230; </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;"># This is the COM way, if you can't get X509Store to work...</span><br />
<span style="color: #660033; font-weight: bold;">$Store</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> <span style="color: #000066;">-COM</span> CAPICOM.<span style="color: #003366;">Store</span><br />
<span style="color: #666666; font-style: italic;"># Open the LocalMachine Root store in ReadWrite mode</span><br />
<span style="color: #660033; font-weight: bold;">$Store</span>.<span style="color: #003366;">Open</span><span style="color: #333;">&#40;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #009900;">&quot;Root&quot;</span>, <span style="color: #cc66cc;">129</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #666666; font-style: italic;"># Import the crt file</span><br />
<span style="color: #660033; font-weight: bold;">$Store</span>.<span style="color: #003366;">Load</span><span style="color: #333;">&#40;</span> <span style="color: #009900;">&quot;$pwd\CA.crt&quot;</span>, <span style="color: #660033; font-weight: bold;">$Null</span>, <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span></div>

	<p>In either case, after that, you can sign PowerShell scripts using the <code>Get-PfxCertificate</code> cmdlet on the pfx file we generated earlier&#8230;</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$cert</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">PfxCertificate</span></span> <span style="color: #009900;">&quot;signing.pfx&quot;</span><br />
<span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">AuthenticodeSignature</span></span> <span style="color: #000066;">-Cert</span> <span style="color: #660033; font-weight: bold;">$cert</span> <span style="color: #000066;">-File</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">Script</span></span>.<span style="color: #003366;">ps1</span><br />
&nbsp;</div>

	<p>Of course, you could also use the <span class="caps">CAPICOM</span>.Store method to import the pfx certificate into the CurrentUser&#8217;s &#8220;My&#8221; store.  In either case, if you try to execute a signed script, you can choose <strong>always</strong> from the prompt and the certificate will be imported to the current user&#8217;s &#8220;trusted publisher&#8221; store. Alternatively, you could import the certificate to the local machine&#8217;s &#8220;trusted publisher&#8221; store using the <span class="caps">CAPICOM</span>.Store again and now you won&#8217;t receive a prompt at all.</p>

	<h3>Using New-CodeSigningCert</h3>

	<p>I&#8217;ve <del>attached</del> uploaded the <a href="http://poshcode.org/1049">New-CodeSigningCert</a> script to PoshCode.org, which includes all the features mentioned so far.  It&#8217;s about 111 lines of code, and 41 lines of the config file, plus 69 and 56 lines of comments in each &#8230; all wrapped up into a single file so you can hopefully figure it out, learn it, and modify as you see fit.</p>

	<p>I had also attached the script packaged with the OpenSSL,  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  but as this post has aged, that seems like not so great an idea, since you really want the newer releases with bug fixes, particularly if you have a 64bit machine &#8230; the script needs to be stored in the same folder with OpenSSL.exe, and you can just unpack OpenSSL (there&#8217;s no need for an installer), but I just can&#8217;t be trusted to keep my local copy here up to date, sorry. :&#8217;(</p>

	<p>Once you&#8217;ve got it installed, and have customized the default parameters in the script, you should be able to easily generate scripts for multiple developers, and/or import those certificates to thousands of computers using PowerShell Remoting  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## Because I have hard-coded the company information</span><br />
<span style="color: #666666; font-style: italic;">## I can use this to generate certs for all my devs (using the same CA root)</span><br />
<span style="color: #660033; font-weight: bold;">$CertsFolder</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;\Server\PoshCerts\CodeSigningCerts&quot;</span><br />
<br />
\Server\PoshCerts\<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">CodeSigningCert</span></span>.<span style="color: #003366;">ps1</span> <span style="color: #660033; font-weight: bold;">$CertsFolder</span> <span style="color: #009900;">&quot;FirstName Last&quot;</span> User1@Domain.<span style="color: #003366;">com</span> <span style="color: #000066;">-CAPassword</span> MyCleverRootPassword <span style="color: #000066;">-CodeSignPassword</span> SimplePassword<br />
\Server\PoshCerts\<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">CodeSigningCert</span></span>.<span style="color: #003366;">ps1</span> <span style="color: #660033; font-weight: bold;">$CertsFolder</span> <span style="color: #009900;">&quot;First LastName&quot;</span> User2@Domain.<span style="color: #003366;">com</span> <span style="color: #000066;">-CAPassword</span> MyCleverRootPassword <span style="color: #000066;">-CodeSignPassword</span> AnotherPassword<br />
\Server\PoshCerts\<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">CodeSigningCert</span></span>.<span style="color: #003366;">ps1</span> <span style="color: #660033; font-weight: bold;">$CertsFolder</span> <span style="color: #009900;">&quot;User LastName&quot;</span> User3@Domain.<span style="color: #003366;">com</span> <span style="color: #000066;">-CAPassword</span> MyCleverRootPassword <span style="color: #000066;">-CodeSignPassword</span> LastPassword<br />
<br />
<span style="color: #666666; font-style: italic;">## And then I can import the scripts on end-user PCs:</span><br />
<span style="color: #009900;">&quot;FirstName Last&quot;</span>,<span style="color: #009900;">&quot;First LastName&quot;</span>,<span style="color: #009900;">&quot;User LastName&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;\Server\PoshCerts\<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">CodeSigningCert</span></span>.<span style="color: #003366;">ps1</span> <span style="color: #660033; font-weight: bold;">$CertsFolder</span> <span style="color: #000066;">-import</span> <br />
<span style="color: #333;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/code-signing-with-openssl-and-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

