<?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>langui.sh &#187; codesign</title>
	<atom:link href="http://langui.sh/tag/codesign/feed/" rel="self" type="application/rss+xml" />
	<link>http://langui.sh</link>
	<description>Fun hacks, WP plugins, photography, and PKI junk.  Languishing since 2008.</description>
	<lastBuildDate>Sat, 19 May 2012 01: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>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Code Signing for Mac OS X and Windows</title>
		<link>http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/</link>
		<comments>http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 00:07:57 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[codesign]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=112</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/" title="Code Signing for Mac OS X and Windows"></a>Code signing is rapidly becoming an important part of application deployment on many platforms. On OS X it suppresses the keychain warnings when you update your application and on Windows it can bypass numerous UAC notifications as well as the &#8230;<p class="read-more"><a href="http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/" title="Code Signing for Mac OS X and Windows"></a><p>Code signing is rapidly becoming an important part of application deployment on many platforms.  On OS X it suppresses the keychain warnings when you update your application and on Windows it can bypass numerous UAC notifications as well as the initial application launch dialog.  This can (sometimes drastically) improve the customer experience and reduce friction associated with your application.  But how do you actually do it?</p>
<p>You can purchase a code signing certificate from any major CA, but for today we&#8217;re going to use the <a href="/2009/01/18/openssl-self-signed-ca/">OpenSSL Self-Signed CA</a> we created in a previous article.</p>
<p>First let&#8217;s create a code signing certificate (if you purchased a certificate you will not need to perform these steps):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> openssl req <span style="color: #660033;">-newkey</span> rsa:<span style="color: #000000;">1024</span> <span style="color: #660033;">-nodes</span> <span style="color: #660033;">-out</span> codesign.csr <span style="color: #660033;">-keyout</span> codesign.key</pre></div></div>

<p>This will write out a codesign.key and codesign.csr after you choose the fields you desire.  Since we are making a code signing certificate the common name should be your company name.  You can also leave the challenge password blank.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">Generating a 1024 bit RSA private key
..........++++++
..................++++++
writing new private key to 'req.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:US
State or Province Name (full name) [Berkshire]:Illinois
Locality Name (eg, city) [Newbury]:Chicago
Organization Name (eg, company) [My Company Ltd]:End Entity, Inc.
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:End Entity, Inc.
Email Address []:
&nbsp;
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:</pre></div></div>

<p>Now that we&#8217;ve created the CSR, we need to modify the myca.conf file to flag certificates for code signing.  Find this line</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">extendedKeyUsage = serverAuth</pre></div></div>

<p>and change it to</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">extendedKeyUsage = codeSigning</pre></div></div>

<p>Now we&#8217;re all set to sign the certificate.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> openssl ca <span style="color: #660033;">-batch</span> <span style="color: #660033;">-config</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>myca.conf <span style="color: #660033;">-notext</span> <span style="color: #660033;">-in</span> codesign.csr <span style="color: #660033;">-out</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>codesign.cer</pre></div></div>

<p>At this point we should have a codesign.cer and a codesign.key file and we&#8217;re ready for the actual signing process.</p>
<h3>Code Signing on OS X</h3>
<p>In OS X the codesign binary is used to sign applications.  Codesign cannot accept the private key/certificate pair as a command line parameter, so you must place them in your Keychain.  To do this you need to convert your CER + RSA private key into a PKCS12 (PFX) file.  Luckily there&#8217;s already a post here about that, so check out <a href="/2009/01/24/generating-a-pkcs12-pfx-via-openssl/">Generating a PKCS12 (PFX) Via OpenSSL</a> for more information.<br />
Once you have it in the proper format, simply double click to import.  Now to sign your application:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">codesign <span style="color: #660033;">-s</span> <span style="color: #ff0000;">'End Entity, Inc.'</span> Whatever.app</pre></div></div>

<p>Inside the single quotes you&#8217;ll want to choose the name (CN) of the certificate as seen in Keychain Access.<br />
If you chose to sign the application with a self-signed cert, please note that OS X won&#8217;t trust it unless you add the created root to your Keychain.  If you do not you will receive this warning:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">Whatever.app/: CSSMERR_TP_NOT_TRUSTED</pre></div></div>

<h3>Code Signing XP/Vista/Windows 7</h3>
<p>To code sign in Windows you should have an SPC (aka PKCS7/P7B) or CER file along with a pvk formatted private key.  To take a standard RSA private key and convert to PVK you should use <a href="http://www.drh-consultancy.demon.co.uk/pvk.html" target="_blank">PVK Tool</a> (Download link is under the conversion tools heading)<br />
Convert your private key to PVK format</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pvk.exe <span style="color: #660033;">-topvk</span> <span style="color: #660033;">-nocrypt</span> <span style="color: #660033;">-in</span> codesign.key <span style="color: #660033;">-out</span> codesign.pvk</pre></div></div>

<p>Once you have the files in the format you require execute <a href="http://msdn.microsoft.com/en-us/library/aa387764.aspx" target="_blank">SignTool</a> from a windows command prompt.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> signtool.exe signwizard</pre></div></div>

<p>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard1/' title='Welcome'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard1-150x150.png" class="attachment-thumbnail" alt="Welcome" title="Welcome" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard2/' title='Select File'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard2-150x150.png" class="attachment-thumbnail" alt="Select File" title="Select File" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard3/' title='wizard3'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard3-150x150.png" class="attachment-thumbnail" alt="Choose Custom" title="wizard3" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard4/' title='wizard4'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard4-150x150.png" class="attachment-thumbnail" alt="Select from File..." title="wizard4" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard5/' title='wizard5'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard5-150x150.png" class="attachment-thumbnail" alt="Change files of type and select your cert" title="wizard5" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard6/' title='wizard6'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard6-150x150.png" class="attachment-thumbnail" alt="View Cert Info/Click Next" title="wizard6" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard7/' title='wizard7'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard7-150x150.png" class="attachment-thumbnail" alt="Click Browse" title="wizard7" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard8/' title='wizard8'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard8-150x150.png" class="attachment-thumbnail" alt="Select the PVK" title="wizard8" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard9/' title='wizard9'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard9-150x150.png" class="attachment-thumbnail" alt="Click Next" title="wizard9" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard10/' title='wizard10'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard10-150x150.png" class="attachment-thumbnail" alt="Choose SHA1" title="wizard10" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard11/' title='wizard11'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard11-150x150.png" class="attachment-thumbnail" alt="Select Intermediates If Required" title="wizard11" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard12/' title='wizard12'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard12-150x150.png" class="attachment-thumbnail" alt="Click Next" title="wizard12" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard13/' title='wizard13'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard13-150x150.png" class="attachment-thumbnail" alt="Timestamp URL (if you have one)" title="wizard13" /></a>
<a href='http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/wizard14/' title='wizard14'><img width="150" height="150" src="http://cdn.langui.sh/2009/02/wizard14-150x150.png" class="attachment-thumbnail" alt="All Done" title="wizard14" /></a>
<br />
And we&#8217;re done!  If you chose to sign the application with a self-signed cert, please note that Windows won&#8217;t trust it unless you add the created root to your certificate store.</p>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/02/22/code-signing-for-mac-os-x-and-windows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Database Caching 8/10 queries in 0.004 seconds using memcached
Object Caching 1467/1467 objects using memcached

Served from: langui.sh @ 2012-05-21 12:51:03 -->
