<?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; Security</title>
	<atom:link href="http://huddledmasses.org/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>How to Import Binary Modules from Network Shares</title>
		<link>http://huddledmasses.org/how-to-import-binary-modules-from-network-shares/</link>
		<comments>http://huddledmasses.org/how-to-import-binary-modules-from-network-shares/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 06:15:04 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[.Net4]]></category>
		<category><![CDATA[CAS]]></category>
		<category><![CDATA[FileShare]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[Policy]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerUser]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[UNC]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1506</guid>
		<description><![CDATA[Note: This is from a wiki page I just wrote on Importing Binary Modules from Network Shares which discusses not just the solution below that works for .Net 2.0 but also how to solve the problem on .Net 4.0 (e.g.: in PoshConsole). I will most likely not keep this page up to date, so you [...]]]></description>
			<content:encoded><![CDATA[	<p><strong>Note:</strong> This is from a wiki page I just wrote on <a href="http://wiki.poshcode.org/FAQ/Problems_and_Gotchas/Importing_Binary_Modules_from_Network_Shares">Importing Binary Modules from Network Shares</a> which discusses not just the solution below that works for .Net 2.0 but also how to solve the problem on .Net 4.0 (e.g.: in PoshConsole).  I will most likely <em>not</em> keep this page up to date, so you should refer to that wiki if you need more information.</p>

	<p>Almost every author of a binary module has probably had someone ask about this at some point, because there&#8217;s always someone who has their user profiles stored on a network location, and therefore installed their modules on that network path and can&#8217;t get them to load because they get a warning that .Net &#8220;Failed to grant minimum permission requests.&#8221;</p>

	<p>Before we get into this any further let me just say: <strong>by far</strong> the simplest thing to do is to create a local folder on your local hard drive, add that to your environment PSPathModules variable, and just install your modules there.</p>

	<p>Other than that, the solution depends on the version of .Net that you&#8217;re using (you can tell by checking the $PSVersionTable.CLRVersion</p>

	<h3>The .Net 2.0 framework (and 3.0 and 3.5 and 3.5 SP1)</h3>

	<p>The problem is not a PowerShell problem at all, it&#8217;s a .Net problem. The .Net framework 2.0 (remember that PowerShell targets 2.0, and is actually based on .Net 1.1) didn&#8217;t trust assemblies loaded from network shares. You can fix that for an individual assembly or for a whole share using the <a title="http://msdn.microsoft.com/en-us/library/cb6t8dtz(VS.80).aspx" class=" external" rel="external nofollow" href="http://msdn.microsoft.com/en-us/library/cb6t8dtz%28VS.80%29.aspx" target="_blank">Caspol</a> tool.</p>

	<p>A complete discussion of that tool and it&#8217;s myriad command-line options is beyond me, but for a simple solution, you can run this command specifying the server and share you want to load from (in my example the &#8220;Modules&#8221; share on the &#8220;ProfileServer&#8221; server).</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Alias</span></span> CasPol <span style="color: #009900;">&quot;$([Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())CasPol.exe&quot;</span> <br />
CasPol <span style="color: #000066;">-pp</span> off <span style="color: #000066;">-machine</span> <span style="color: #000066;">-addgroup</span> <span style="color: #cc66cc;">1.2</span> <span style="color: #000066;">-url</span> file:<span style="color: #66cc66;">//</span>\ProfileServer\Modules\<span style="color: #66cc66;">*</span> FullTrust</div>

	<p>Hopefully the only thing that needs explaning there is that 1.2 is the default &#8220;Local Intranet&#8221; group, and that CasPol.exe is in your Framework Runtime directory. Once you&#8217;ve run that, you&#8217;ll be able to import any modules that are in subdirectories of that share.</p>

	<p><b>Note:</b> You <em>must</em> run the version of CasPol.exe which is in the lcation defined by the GetRuntimeDirectory() command (it&#8217;s important to use the same version as the runtime you want to be affected).</p>

	<p>You can read more about <a href="http://wiki.poshcode.org/FAQ/Problems_and_Gotchas/Importing_Binary_Modules_from_Network_Shares">importing binary modules from network shares</a>, including how it changed in .Net 3.5 SP1 and why it&#8217;s not automatically fixed in .Net 4 over on the PoshCode wiki.  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/how-to-import-binary-modules-from-network-shares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Better Get-Credential in one line of code</title>
		<link>http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/</link>
		<comments>http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 21:14:54 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[Credentials]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/</guid>
		<description><![CDATA[For too long I have ignored the deficiencies in Get-Credential, so now I am going to fix them. Ready? function Get-Credential&#40;$caption,$msg,$domain,$name&#41;&#123;$Host.UI.PromptForCredential&#40;$caption,$msg,$name,$domain&#41;&#125; Ok, that&#8217;s better than the default, whew! At least you can specify the prompt text and the domain and default user name &#8230; but there are so many other options that are missing from [...]]]></description>
			<content:encoded><![CDATA[	<p>For too long I have ignored the deficiencies in Get-Credential, so now I am going to fix them. Ready?</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Credential</span></span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$caption</span>,<span style="color: #660033; font-weight: bold;">$msg</span>,<span style="color: #660033; font-weight: bold;">$domain</span>,<span style="color: #660033; font-weight: bold;">$name</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$Host</span>.<span style="color: #003366;">UI</span>.<span style="color: #003366;">PromptForCredential</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$caption</span>,<span style="color: #660033; font-weight: bold;">$msg</span>,<span style="color: #660033; font-weight: bold;">$name</span>,<span style="color: #660033; font-weight: bold;">$domain</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#125;</span></div>

	<p>Ok, that&#8217;s better than the default, whew!  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' />  At least you can specify the prompt text and the domain and default user name &#8230; but there are so many other options that are missing from that dialog &#8212;like remembering my credentials for goodness sakes. I know many places forbid using the &#8220;remember&#8221; option for credentials, but why is that decision not up to me?</p>

	<p>Well, I can&#8217;t make all of those options appear (at least, not without compiling a pinvoke function to call the Win32 <span class="caps">API</span>) nor can I force PowerShell to use the <a href="http://msdn.microsoft.com/en-us/library/aa375178(VS.85).aspx">new Vista/2008 Credential function</a> (which is Common Criteria compliant in Vista) instead of the older <a href="http://msdn.microsoft.com/en-us/library/aa375177(VS.85).aspx">CredUIPromptForCredentials</a> ... but I can give you the <a href="https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=370658&#38;SiteID=99">most requested feature</a> for Get-Credential: a -Console option to force the prompt to happen in the console instead of in a &#8220;CredUI&#8221; pop up.  </p>

	<p> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Note:</strong> I kind-of messed up here, this will break if you&#8217;re used to using the -Credential parameter for Get-Credential to provide a default user name.  I&#8217;ll fix it shortly.</p>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/681"></script></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/a-better-get-credential-in-one-line-of-code/feed/</wfw:commentRss>
		<slash:comments>0</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>

