<?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; ssl</title>
	<atom:link href="http://langui.sh/tag/ssl/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>Tue, 17 Jan 2012 20:23:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>SNI in iOS 4.0</title>
		<link>http://langui.sh/2010/06/08/sni-in-ios-4-0/</link>
		<comments>http://langui.sh/2010/06/08/sni-in-ios-4-0/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 04:08:05 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=1160</guid>
		<description><![CDATA[<a href="http://langui.sh/2010/06/08/sni-in-ios-4-0/" title="SNI in iOS 4.0"></a>iOS 4.0 supports SNI, which makes it the first mobile OS to support the server_name TLS extension. Hopefully Android, WebOS, WM7, et al follow suit! (Oh, and I&#8217;m not dead. WP 3.0 comes out shortly so expect a major CDN &#8230;<p class="read-more"><a href="http://langui.sh/2010/06/08/sni-in-ios-4-0/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2010/06/08/sni-in-ios-4-0/" title="SNI in iOS 4.0"></a><p>iOS 4.0 supports SNI, which makes it the first mobile OS to support the server_name TLS extension.  Hopefully Android, WebOS, WM7, et al follow suit!</p>
<p>(Oh, and I&#8217;m not dead. WP 3.0 comes out shortly so expect a major CDN Tools update as well as a brand new plugin!)</p>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2010/06/08/sni-in-ios-4-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SNI Support in Chromium OS X</title>
		<link>http://langui.sh/2010/02/24/sni-support-in-chromium-os-x/</link>
		<comments>http://langui.sh/2010/02/24/sni-support-in-chromium-os-x/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 01:16:59 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[chromium]]></category>
		<category><![CDATA[sni]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=1111</guid>
		<description><![CDATA[<a href="http://langui.sh/2010/02/24/sni-support-in-chromium-os-x/" title="SNI Support in Chromium OS X"></a>As of r39934 Chromium now supports the server_name TLS extension (server name indication) in OS X (latest build). This support requires OS X 10.5.7 or later. Hopefully it&#8217;ll make its way into a dev/beta/stable release of Google Chrome itself soon. &#8230;<p class="read-more"><a href="http://langui.sh/2010/02/24/sni-support-in-chromium-os-x/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2010/02/24/sni-support-in-chromium-os-x/" title="SNI Support in Chromium OS X"></a><p>As of <a href="http://src.chromium.org/viewvc/chrome?view=rev&#038;revision=39934" target="_blank">r39934</a> Chromium now supports the server_name TLS extension (server name indication) in OS X (<a href="http://build.chromium.org/buildbot/continuous/mac/LATEST/" target="_blank">latest build</a>).  This support requires OS X 10.5.7 or later.  Hopefully it&#8217;ll make its way into a dev/beta/stable release of Google Chrome itself soon.</p>
<p>For those who are more curious than they ought to be about how I wrote this patch&#8230; Apple added support in their Secure Transport library for the server_name TLS extension, but has not updated their <a href="http://developer.apple.com/mac/library/DOCUMENTATION/Security/Reference/secureTransportRef/Reference/reference.html" target="_blank">documentation</a>.  As of 10.5.7 (or possibly 10.5.6) the SSLSetPeerDomainName function &#8212; which is ostensibly used for OS level certificate verification &#8212; causes OS X to send the server_name extension in the TLS client hello.  However, since Chromium doesn&#8217;t use OS X&#8217;s built-in verification it wasn&#8217;t passing this data through prior to the patch.</p>
<p>To test you can hit up my IDN SNI site <a href="https://☣.ws/" target="_blank">https://☣.ws/</a> or <a href="https://alice.sni.velox.ch/" target="_blank">https://alice.sni.velox.ch/</a>. The former will throw a certificate error if you are on a non-SNI enabled browser and the latter will have text stating that the SNI extension is missing.</p>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2010/02/24/sni-support-in-chromium-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSL VHosting On The Same IP (aka SNI)</title>
		<link>http://langui.sh/2009/11/03/ssl-vhosting-on-the-same-ip-aka-sni/</link>
		<comments>http://langui.sh/2009/11/03/ssl-vhosting-on-the-same-ip-aka-sni/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 21:01:54 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sni]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=747</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/11/03/ssl-vhosting-on-the-same-ip-aka-sni/" title="SSL VHosting On The Same IP (aka SNI)"></a>Server Name Indication (SNI), an extension to TLS, allows browsers that support it to connect to SSL hosts that do not have dedicated IPs (much like standard http virtual hosting has worked for years). This extension, however, must be supported &#8230;<p class="read-more"><a href="http://langui.sh/2009/11/03/ssl-vhosting-on-the-same-ip-aka-sni/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/11/03/ssl-vhosting-on-the-same-ip-aka-sni/" title="SSL VHosting On The Same IP (aka SNI)"></a><p>Server Name Indication (SNI), an extension to TLS, allows browsers that support it to connect to SSL hosts that do not have dedicated IPs (much like standard http virtual hosting has worked for years).  This extension, however, must be supported on both the server and client side.  Microsoft has not yet chosen to support it (maybe IIS 8?), but the Apache project did with the 2.2.12 release.  Recently, Ubuntu 9.10 Server became the first server distribution to ship with Apache and OpenSSL built with the appropriate flags, so if you&#8217;d like to follow along you can use a 9.10 VM.</p>
<p>In the ideal case everything is the same as a regular vhost, but you&#8217;ll first need to enable SSL.  On Ubuntu this requires you to run <b>a2enmod</b> and type &#8220;ssl&#8221;.  After that you&#8217;ll need to add</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">443</span></pre></div></div>

<p>to the root conf, then make your VirtualHost much like a normal one.  A very basic pair of vhosts is seen below.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">443</span>&gt;
	<span style="color: #00007f;">ServerAdmin</span> webmaster@localhost
&nbsp;
	<span style="color: #00007f;">DocumentRoot</span> /my/doc/root
	<span style="color: #00007f;">ServerName</span> mydomain.com
	<span style="color: #00007f;">SSLEngine</span> <span style="color: #0000ff;">On</span>
	<span style="color: #00007f;">SSLCertificateFile</span> /path/to/domain.crt 
	<span style="color: #00007f;">SSLCertificateKeyFile</span> /path/to/domain.key
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">443</span>&gt;
	<span style="color: #00007f;">ServerAdmin</span> webmaster@localhost
&nbsp;
	<span style="color: #00007f;">DocumentRoot</span> /my/doc/root
	<span style="color: #00007f;">ServerName</span> mydomain2.com
	<span style="color: #00007f;">SSLEngine</span> <span style="color: #0000ff;">On</span>
	<span style="color: #00007f;">SSLCertificateFile</span> /path/to/domain2.crt 
	<span style="color: #00007f;">SSLCertificateKeyFile</span> /path/to/domain2.key
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>These vhosts should be placed in different includes ideally, but it isn&#8217;t required.  If you just want to test with a self-signed certificate you can create one with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-nodes</span> <span style="color: #660033;">-keyout</span> mykey.key <span style="color: #660033;">-out</span> mycert.cer <span style="color: #660033;">-days</span> <span style="color: #000000;">3650</span> <span style="color: #660033;">-x509</span></pre></div></div>

<p>You&#8217;ll need to specify the domain name you want in the &#8220;Common Name&#8221; section.</p>
<p>Once you&#8217;ve got all this done you can restart apache and test it out!  If you test on a browser that doesn&#8217;t support SNI (IE on XP) you&#8217;ll get the SSL cert for the first vhost apache parses.  To disable accessing it on non-SNI hosts you can add</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">SSLStrictSNIVHostCheck <span style="color: #0000ff;">on</span></pre></div></div>

<p>to the root conf.  This will cause a 403 error for those browsers.</p>
<p>If you&#8217;d like to see an example implementation of SNI you can check out my IDN domains <a href="http://xn--j4h.ws">https://☢.ws/</a> and <a href="https://xn--k4h.ws/">https://☣.ws/</a>.  These sites are hosted on the same IP with different SSL certificates.  I have strict host checking turned on so visiting them with a non-SNI capable browser will result in a 403 error.<sup class='footnote'><a href='#fn-747-1' id='fnref-747-1'>1</a></sup></p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-747-1'>See the Wikipedia article about <a href="http://en.wikipedia.org/wiki/Server_Name_Indication">Server Name Indication</a> for more information on supported browsers. <span class='footnotereverse'><a href='#fnref-747-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/11/03/ssl-vhosting-on-the-same-ip-aka-sni/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Firefox Autoenrollment With A Microsoft CA</title>
		<link>http://langui.sh/2009/04/12/firefox-autoenrollment-with-a-microsoft-ca/</link>
		<comments>http://langui.sh/2009/04/12/firefox-autoenrollment-with-a-microsoft-ca/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 00:43:46 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=471</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/04/12/firefox-autoenrollment-with-a-microsoft-ca/" title="Firefox Autoenrollment With A Microsoft CA"></a>If you&#8217;re running a Microsoft CA and you want to be able to accept enrollment requests from clients supporting keygen (Firefox, Safari, Opera, et cetera) you&#8217;ve probably found that the /certsrv/ page allows enrollment, but the requests fail when you &#8230;<p class="read-more"><a href="http://langui.sh/2009/04/12/firefox-autoenrollment-with-a-microsoft-ca/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/04/12/firefox-autoenrollment-with-a-microsoft-ca/" title="Firefox Autoenrollment With A Microsoft CA"></a><p>If you&#8217;re running a Microsoft CA and you want to be able to accept enrollment requests from clients supporting keygen (Firefox, Safari, Opera, et cetera) you&#8217;ve probably found that the /certsrv/ page allows enrollment, but the requests fail when you attempt to issue the certificate.  This is because the server is not parsing the subject attributes from the request.  To fix this, run the following on your server as administrator on the command line.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">certutil -setreg ca\CRLFlags +CRLF_ALLOW_REQUEST_ATTRIBUTE_SUBJECT</pre></div></div>

<p>You can also set your server to auto-issue on request for certain certificate profiles.  To do this add the CA snap-in and get properties of your CA.  Under the policy module tab click properties again and click the &#8220;Follow the settings..&#8221; radio button.<br />
<a href="http://cdn.langui.sh/2009/03/add-snapin.png"><img class="size-thumbnail wp-image-474  alignleft" title="add-snapin" src="http://cdn.langui.sh/2009/03/add-snapin-150x150.png" alt="add-snapin" width="150" height="150" /></a><a href="http://cdn.langui.sh/2009/04/mmc.png"><img class="alignnone size-thumbnail wp-image-478" title="mmc" src="http://cdn.langui.sh/2009/04/mmc-150x150.png" alt="mmc" width="150" height="150" /></a></p>
<p><a href="http://cdn.langui.sh/2009/04/mmc.png"></a><a href="http://cdn.langui.sh/2009/03/properties.png"><img class="alignnone size-thumbnail wp-image-476" title="properties" src="http://cdn.langui.sh/2009/03/properties-150x150.png" alt="properties" width="150" height="150" /></a><a href="http://cdn.langui.sh/2009/03/requesthandling.png"><img class="alignnone size-thumbnail wp-image-477" title="requesthandling" src="http://cdn.langui.sh/2009/03/requesthandling-150x150.png" alt="requesthandling" width="150" height="150" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/04/12/firefox-autoenrollment-with-a-microsoft-ca/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using OpenSSL s_time</title>
		<link>http://langui.sh/2009/03/28/using-openssl-s_time/</link>
		<comments>http://langui.sh/2009/03/28/using-openssl-s_time/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 20:28:28 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=431</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/28/using-openssl-s_time/" title="Using OpenSSL s_time"></a>Recently I needed to do some performance testing of an SSL instance on a VM. I considered using JMeter, but decided to use OpenSSL to get a rudimentary picture instead. To obtain a basic result, we connect to the server &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/28/using-openssl-s_time/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/28/using-openssl-s_time/" title="Using OpenSSL s_time"></a><p>Recently I needed to do some performance testing of an SSL instance on a VM.  I considered using JMeter, but decided to use OpenSSL to get a rudimentary picture instead.</p>
<p>To obtain a basic result, we connect to the server and pull the /index.php file.  You can specify whatever file you&#8217;d like to download, or none at all if you simply want to test connections.<sup class='footnote'><a href='#fn-431-1' id='fnref-431-1'>1</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_time <span style="color: #660033;">-www</span> <span style="color: #000000; font-weight: bold;">/</span>index.php <span style="color: #660033;">-new</span> <span style="color: #660033;">-connect</span> www.trustwave.com:<span style="color: #000000;">443</span></pre></div></div>

<p>Your result will look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">No CIPHER specified
Collecting connection statistics for 30 seconds
ttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
159 connections in 5.82s; 27.32 connections/user sec, bytes read 62328
159 connections in 31 real seconds, 392 bytes read per connection</pre></div></div>

<p>If you&#8217;d like to get more specific with performance testing you can even use the -ciphers parameter to explicitly choose the negotiated cipher.  You can obtain a list of available ciphers with &#8220;openssl ciphers&#8221;.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-431-1'>If you would prefer to reuse connections rather than create a new one for each request replace -new with -reuse. <span class='footnotereverse'><a href='#fnref-431-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/28/using-openssl-s_time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSA Encryption and Signing</title>
		<link>http://langui.sh/2009/03/21/rsa-encryption-and-signing/</link>
		<comments>http://langui.sh/2009/03/21/rsa-encryption-and-signing/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 04:02:51 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[aes]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=440</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/21/rsa-encryption-and-signing/" title="RSA Encryption and Signing"></a>OpenSSL provides several tools that allow you to RSA encrypt/sign arbitrary data files. Of course, directly RSA encrypting large volumes of data is impractical because the encrypted/signed data cannot exceed the size of the key material. This is one of &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/21/rsa-encryption-and-signing/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/21/rsa-encryption-and-signing/" title="RSA Encryption and Signing"></a><p>OpenSSL provides several tools that allow you to RSA encrypt/sign arbitrary data files.  Of course, directly RSA encrypting large volumes of data is impractical because the encrypted/signed data cannot exceed the size of the key material.  This is one of the reasons why SSL connections typically handshake and then pass an AES (or RC4, et cetera) key to do symmetric encryption thereafter.<sup class='footnote'><a href='#fn-440-1' id='fnref-440-1'>1</a></sup></p>
<p>Generate a private key. You can change the last number to the preferred modulus size.  Keys greater than 4096-bit will take a long time to generate.<sup class='footnote'><a href='#fn-440-2' id='fnref-440-2'>2</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-out</span> private.pem <span style="color: #000000;">4096</span></pre></div></div>

<p>With the private key we can now encrypt the data.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-encrypt</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> publicfile <span style="color: #660033;">-out</span> privatefile</pre></div></div>

<p>To decrypt just reverse it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-decrypt</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> privatefile <span style="color: #660033;">-out</span> publicfile</pre></div></div>

<p>If you would rather sign the data&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-sign</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> filetosign <span style="color: #660033;">-out</span> signed_data</pre></div></div>

<p>To verify the signature just use -verify.<sup class='footnote'><a href='#fn-440-3' id='fnref-440-3'>3</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsautl <span style="color: #660033;">-verify</span> <span style="color: #660033;">-inkey</span> private.pem <span style="color: #660033;">-in</span> signed_data</pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-440-1'>Another big reason is speed.  AES is much, much faster than RSA. <span class='footnotereverse'><a href='#fnref-440-1'>&#8617;</a></span></li>
<li id='fn-440-2'>If you attempt to encrypt or sign data larger than your key length allows, you will receive an error similar to this: 23465:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151: <span class='footnotereverse'><a href='#fnref-440-2'>&#8617;</a></span></li>
<li id='fn-440-3'>You can also use -hexdump or -raw to view the data in those forms. <span class='footnotereverse'><a href='#fnref-440-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/21/rsa-encryption-and-signing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a PKCS7 (P7B) Using OpenSSL</title>
		<link>http://langui.sh/2009/03/20/creating-a-pkcs7-p7b-using-openssl/</link>
		<comments>http://langui.sh/2009/03/20/creating-a-pkcs7-p7b-using-openssl/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 23:08:53 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=435</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/20/creating-a-pkcs7-p7b-using-openssl/" title="Creating a PKCS7 (P7B) Using OpenSSL"></a>Continuing the howto nature of this blog (and its peculiar obsession with OpenSSL), here&#8217;s a primer on packaging an arbitrary number of certificates into a single PKCS7 container. These files are quite useful for installing multiple certificates on Windows servers. &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/20/creating-a-pkcs7-p7b-using-openssl/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/20/creating-a-pkcs7-p7b-using-openssl/" title="Creating a PKCS7 (P7B) Using OpenSSL"></a><p>Continuing the howto nature of this blog (and its peculiar obsession with OpenSSL), here&#8217;s a primer on packaging an arbitrary number of certificates into a single PKCS7 container.  These files are quite useful for installing multiple certificates on Windows servers.  They differ from PKCS12 (PFX) files in that they can&#8217;t store private keys.  If you need to <a href="http://langui.sh/2009/01/24/generating-a-pkcs12-pfx-via-openssl/">generate a PKCS12</a> then head to that article instead.</p>
<p>This example assumes that you have 2 different certificate files, each in PEM (Base64) format.  You can add as many -certfile elements as you want to package in the file.  Additionally, concatenated certificate chains are supported.  <sup class='footnote'><a href='#fn-435-1' id='fnref-435-1'>1</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl crl2pkcs7 <span style="color: #660033;">-nocrl</span> <span style="color: #660033;">-certfile</span> cert1.cer <span style="color: #660033;">-certfile</span> cert2.cer <span style="color: #660033;">-out</span> outfile.p7b</pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-435-1'>If you wish to provide DER encoded input files (or have DER output) you can use the -inform DER or -outform DER directives. <span class='footnotereverse'><a href='#fnref-435-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/20/creating-a-pkcs7-p7b-using-openssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking A Remote Certificate Chain With OpenSSL</title>
		<link>http://langui.sh/2009/03/14/checking-a-remote-certificate-chain-with-openssl/</link>
		<comments>http://langui.sh/2009/03/14/checking-a-remote-certificate-chain-with-openssl/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 15:26:13 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=398</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/14/checking-a-remote-certificate-chain-with-openssl/" title="Checking A Remote Certificate Chain With OpenSSL"></a>If you deal with SSL/TLS long enough you will run into situations where you need to examine what certificates are being presented by a server to the client. The best way to examine the raw output is via (what else &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/14/checking-a-remote-certificate-chain-with-openssl/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/14/checking-a-remote-certificate-chain-with-openssl/" title="Checking A Remote Certificate Chain With OpenSSL"></a><p>If you deal with SSL/TLS long enough you will run into situations where you need to examine what certificates are being presented by a server to the client.  The best way to examine the raw output is via (what else but) OpenSSL.<sup class='footnote'><a href='#fn-398-1' id='fnref-398-1'>1</a></sup></p>
<p>First let&#8217;s do a standard webserver connection (-showcerts dumps the PEM encoded certificates themselves for more extensive parsing if you desire.  The output below snips them for readability.):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_client <span style="color: #660033;">-showcerts</span> <span style="color: #660033;">-connect</span> www.domain.com:<span style="color: #000000;">443</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">CONNECTED(00000003)
--snip--
---
Certificate chain
 0 s:/C=US/ST=Texas/L=Carrollton/O=Woot Inc/CN=*.woot.com
   i:/C=US/O=SecureTrust Corporation/CN=SecureTrust CA
-----BEGIN CERTIFICATE-----
--snip--
-----END CERTIFICATE-----
 1 s:/C=US/O=SecureTrust Corporation/CN=SecureTrust CA
   i:/C=US/O=Entrust.net/OU=www.entrust.net/CPS incorp. by ref. (limits liab.)/OU=(c) 1999 Entrust.net Limited/CN=Entrust.net Secure Server Certification Authority
-----BEGIN CERTIFICATE-----
--snip--
-----END CERTIFICATE-----
---
Server certificate
subject=/C=US/ST=Texas/L=Carrollton/O=Woot Inc/CN=*.woot.com
issuer=/C=US/O=SecureTrust Corporation/CN=SecureTrust CA
---
No client certificate CA names sent
---
SSL handshake has read 2123 bytes and written 300 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-MD5
Server public key is 1024 bit
--snip--</pre></div></div>

<p>There&#8217;s a lot of data here so I have truncated several sections to increase readability.  Points of interest:</p>
<ol>
<li>The certificate chain consists of two certificates.  At level 0 there is the server certificate with some parsed information.  s: is the subject line of the certificate and i: contains information about the issuing CA.</li>
<li>This particular server (www.woot.com) has sent an intermediate certificate as well.  Subject and issuer information is provided for each certificate in the presented chain.  Chains can be much longer than 2 certificates in length.</li>
<li>The server certificate section is a duplicate of level 0 in the chain.  If you&#8217;re only looking for the end entity certificate then you can rapidly find it by looking for this section.</li>
<li>No client certificate CAs were sent.  If the server was configured to potentially accept client certs the returned data would include a list of &#8220;acceptable client CAs&#8221;.</li>
<li>Connection was made via TLSv1/SSLv3  and the chosen cipher was RC4-MD5. Incidentally, this typically means that the server you&#8217;re connecting to is IIS.</li>
</ol>
<p>But what if you want to connect to something other than a bog standard webserver on port 443?  Well, if you need to use starttls that is also available.  As of OpenSSL 0.9.8 you can choose from smtp, pop3, imap, and ftp as starttls options.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_client <span style="color: #660033;">-showcerts</span> <span style="color: #660033;">-starttls</span> imap <span style="color: #660033;">-connect</span> mail.domain.com:<span style="color: #000000;">139</span></pre></div></div>

<p>If you need to check using a specific SSL version (perhaps to verify if that method is available) you can do that as well.  -ssl2, -ssl3, -tls1, and -dtls1 are all choices here.<sup class='footnote'><a href='#fn-398-2' id='fnref-398-2'>2</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_client <span style="color: #660033;">-showcerts</span> <span style="color: #660033;">-ssl2</span> <span style="color: #660033;">-connect</span> www.domain.com:<span style="color: #000000;">443</span></pre></div></div>

<p>You can also present a client certificate if you are attempting to debug issues with a connection that requires one.<sup class='footnote'><a href='#fn-398-3' id='fnref-398-3'>3</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_client <span style="color: #660033;">-showcerts</span> <span style="color: #660033;">-cert</span> cert.cer <span style="color: #660033;">-key</span> cert.key <span style="color: #660033;">-connect</span> www.domain.com:<span style="color: #000000;">443</span></pre></div></div>

<p>And for those who really enjoy playing with SSL handshakes, you can even specify acceptable ciphers.<sup class='footnote'><a href='#fn-398-4' id='fnref-398-4'>4</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_client <span style="color: #660033;">-showcerts</span> <span style="color: #660033;">-cipher</span> DHE-RSA-AES256-SHA <span style="color: #660033;">-connect</span> www.domain.com:<span style="color: #000000;">443</span></pre></div></div>

<p>The cipher used above should work for almost any Apache server, but will fail on IIS since it doesn&#8217;t support 256-bit AES encryption.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-398-1'>The s_client command we&#8217;re using opens an interactive socket and does not automatically return to the shell prompt, so remember you will have to hit control-c or type something and hit return to terminate the process. <span class='footnotereverse'><a href='#fnref-398-1'>&#8617;</a></span></li>
<li id='fn-398-2'>This example shows an attempted SSLv2 only connection.  SSLv2 should be disabled on any web server you control.  It has a variety of flaws and has been superseded by SSLv3/TLSv1 for over a decade. <span class='footnotereverse'><a href='#fnref-398-2'>&#8617;</a></span></li>
<li id='fn-398-3'>This example expects the certificate and private key in PEM form.  You can provide them in DER if you add -certform DER and -keyform DER (OpenSSL 0.9.8 or newer only) <span class='footnotereverse'><a href='#fnref-398-3'>&#8617;</a></span></li>
<li id='fn-398-4'>A list of available ciphers can be found by typing &#8220;openssl ciphers&#8221;, but there are also myriad ways to sort by type and strength.  See the <a href="http://www.openssl.org/docs/apps/ciphers.html" target="_blank">ciphers</a> man page for more details. <span class='footnotereverse'><a href='#fnref-398-4'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/14/checking-a-remote-certificate-chain-with-openssl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generating (Very) Large Primes</title>
		<link>http://langui.sh/2009/03/07/generating-very-large-primes/</link>
		<comments>http://langui.sh/2009/03/07/generating-very-large-primes/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 01:02:09 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=167</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/07/generating-very-large-primes/" title="Generating (Very) Large Primes"></a>Have you ever wondered how big the &#8220;large primes&#8221; that RSA encryption is based on really are? What exactly does a &#8220;1024-bit&#8221; key mean anyway? And if the difficulty of RSA is partially based on factoring large numbers, how do &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/07/generating-very-large-primes/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/07/generating-very-large-primes/" title="Generating (Very) Large Primes"></a><p>Have you ever wondered how big the &#8220;large primes&#8221; that RSA encryption is based on really are?  What exactly does a &#8220;1024-bit&#8221; key mean anyway?  And if the difficulty of RSA is partially based on <a href="http://en.wikipedia.org/wiki/Integer_factorization" target="_blank">factoring large numbers</a>, how do we create these large primes without determining primality via factorization?</p>
<p>The easiest way to demonstrate these concepts is with a simple script, so let&#8217;s take a look at a large random number generator I wrote<sup class='footnote'><a href='#fn-167-1' id='fnref-167-1'>1</a></sup> using Python.  As is typical for this blog, you&#8217;ll note that the random numbers are not cryptographically secure.  To make these examples simple I don&#8217;t want to introduce external dependencies, but please keep that issue in mind for any serious applications of the code presented here.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> rabinMiller<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
     s = n-<span style="color: #ff4500;">1</span>
     t = <span style="color: #ff4500;">0</span>
     <span style="color: #ff7700;font-weight:bold;">while</span> s<span style="color: #66cc66;">&amp;</span><span style="color: #ff4500;">1</span> == <span style="color: #ff4500;">0</span>:
         s = s/<span style="color: #ff4500;">2</span>
         t +=<span style="color: #ff4500;">1</span>
     k = <span style="color: #ff4500;">0</span>
     <span style="color: #ff7700;font-weight:bold;">while</span> k<span style="color: #66cc66;">&lt;</span><span style="color: #ff4500;">128</span>:
         a = <span style="color: #dc143c;">random</span>.<span style="color: black;">randrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>,n-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
         <span style="color: #808080; font-style: italic;">#a^s is computationally infeasible.  we need a more intelligent approach</span>
         <span style="color: #808080; font-style: italic;">#v = (a**s)%n</span>
         <span style="color: #808080; font-style: italic;">#python's core math module can do modular exponentiation</span>
         v = <span style="color: #008000;">pow</span><span style="color: black;">&#40;</span>a,s,n<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#where values are (num,exp,mod)</span>
         <span style="color: #ff7700;font-weight:bold;">if</span> v <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">1</span>:
             i=<span style="color: #ff4500;">0</span>
             <span style="color: #ff7700;font-weight:bold;">while</span> v <span style="color: #66cc66;">!</span>= <span style="color: black;">&#40;</span>n-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
                 <span style="color: #ff7700;font-weight:bold;">if</span> i == t-<span style="color: #ff4500;">1</span>:
                     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
                 <span style="color: #ff7700;font-weight:bold;">else</span>:
                     i = i+<span style="color: #ff4500;">1</span>
                     v = <span style="color: black;">&#40;</span>v<span style="color: #66cc66;">**</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">%</span>n
         k+=<span style="color: #ff4500;">2</span>
     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> isPrime<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
     <span style="color: #808080; font-style: italic;">#lowPrimes is all primes (sans 2, which is covered by the bitwise and operator) </span>
     <span style="color: #808080; font-style: italic;">#under 1000. taking n modulo each lowPrime allows us to remove a huge chunk </span>
     <span style="color: #808080; font-style: italic;">#of composite numbers from our potential pool without resorting to Rabin-Miller</span>
     lowPrimes =   <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">11</span>,<span style="color: #ff4500;">13</span>,<span style="color: #ff4500;">17</span>,<span style="color: #ff4500;">19</span>,<span style="color: #ff4500;">23</span>,<span style="color: #ff4500;">29</span>,<span style="color: #ff4500;">31</span>,<span style="color: #ff4500;">37</span>,<span style="color: #ff4500;">41</span>,<span style="color: #ff4500;">43</span>,<span style="color: #ff4500;">47</span>,<span style="color: #ff4500;">53</span>,<span style="color: #ff4500;">59</span>,<span style="color: #ff4500;">61</span>,<span style="color: #ff4500;">67</span>,<span style="color: #ff4500;">71</span>,<span style="color: #ff4500;">73</span>,<span style="color: #ff4500;">79</span>,<span style="color: #ff4500;">83</span>,<span style="color: #ff4500;">89</span>,<span style="color: #ff4500;">97</span>
                   ,<span style="color: #ff4500;">101</span>,<span style="color: #ff4500;">103</span>,<span style="color: #ff4500;">107</span>,<span style="color: #ff4500;">109</span>,<span style="color: #ff4500;">113</span>,<span style="color: #ff4500;">127</span>,<span style="color: #ff4500;">131</span>,<span style="color: #ff4500;">137</span>,<span style="color: #ff4500;">139</span>,<span style="color: #ff4500;">149</span>,<span style="color: #ff4500;">151</span>,<span style="color: #ff4500;">157</span>,<span style="color: #ff4500;">163</span>,<span style="color: #ff4500;">167</span>,<span style="color: #ff4500;">173</span>,<span style="color: #ff4500;">179</span>
                   ,<span style="color: #ff4500;">181</span>,<span style="color: #ff4500;">191</span>,<span style="color: #ff4500;">193</span>,<span style="color: #ff4500;">197</span>,<span style="color: #ff4500;">199</span>,<span style="color: #ff4500;">211</span>,<span style="color: #ff4500;">223</span>,<span style="color: #ff4500;">227</span>,<span style="color: #ff4500;">229</span>,<span style="color: #ff4500;">233</span>,<span style="color: #ff4500;">239</span>,<span style="color: #ff4500;">241</span>,<span style="color: #ff4500;">251</span>,<span style="color: #ff4500;">257</span>,<span style="color: #ff4500;">263</span>,<span style="color: #ff4500;">269</span>
                   ,<span style="color: #ff4500;">271</span>,<span style="color: #ff4500;">277</span>,<span style="color: #ff4500;">281</span>,<span style="color: #ff4500;">283</span>,<span style="color: #ff4500;">293</span>,<span style="color: #ff4500;">307</span>,<span style="color: #ff4500;">311</span>,<span style="color: #ff4500;">313</span>,<span style="color: #ff4500;">317</span>,<span style="color: #ff4500;">331</span>,<span style="color: #ff4500;">337</span>,<span style="color: #ff4500;">347</span>,<span style="color: #ff4500;">349</span>,<span style="color: #ff4500;">353</span>,<span style="color: #ff4500;">359</span>,<span style="color: #ff4500;">367</span>
                   ,<span style="color: #ff4500;">373</span>,<span style="color: #ff4500;">379</span>,<span style="color: #ff4500;">383</span>,<span style="color: #ff4500;">389</span>,<span style="color: #ff4500;">397</span>,<span style="color: #ff4500;">401</span>,<span style="color: #ff4500;">409</span>,<span style="color: #ff4500;">419</span>,<span style="color: #ff4500;">421</span>,<span style="color: #ff4500;">431</span>,<span style="color: #ff4500;">433</span>,<span style="color: #ff4500;">439</span>,<span style="color: #ff4500;">443</span>,<span style="color: #ff4500;">449</span>,<span style="color: #ff4500;">457</span>,<span style="color: #ff4500;">461</span>
                   ,<span style="color: #ff4500;">463</span>,<span style="color: #ff4500;">467</span>,<span style="color: #ff4500;">479</span>,<span style="color: #ff4500;">487</span>,<span style="color: #ff4500;">491</span>,<span style="color: #ff4500;">499</span>,<span style="color: #ff4500;">503</span>,<span style="color: #ff4500;">509</span>,<span style="color: #ff4500;">521</span>,<span style="color: #ff4500;">523</span>,<span style="color: #ff4500;">541</span>,<span style="color: #ff4500;">547</span>,<span style="color: #ff4500;">557</span>,<span style="color: #ff4500;">563</span>,<span style="color: #ff4500;">569</span>,<span style="color: #ff4500;">571</span>
                   ,<span style="color: #ff4500;">577</span>,<span style="color: #ff4500;">587</span>,<span style="color: #ff4500;">593</span>,<span style="color: #ff4500;">599</span>,<span style="color: #ff4500;">601</span>,<span style="color: #ff4500;">607</span>,<span style="color: #ff4500;">613</span>,<span style="color: #ff4500;">617</span>,<span style="color: #ff4500;">619</span>,<span style="color: #ff4500;">631</span>,<span style="color: #ff4500;">641</span>,<span style="color: #ff4500;">643</span>,<span style="color: #ff4500;">647</span>,<span style="color: #ff4500;">653</span>,<span style="color: #ff4500;">659</span>,<span style="color: #ff4500;">661</span>
                   ,<span style="color: #ff4500;">673</span>,<span style="color: #ff4500;">677</span>,<span style="color: #ff4500;">683</span>,<span style="color: #ff4500;">691</span>,<span style="color: #ff4500;">701</span>,<span style="color: #ff4500;">709</span>,<span style="color: #ff4500;">719</span>,<span style="color: #ff4500;">727</span>,<span style="color: #ff4500;">733</span>,<span style="color: #ff4500;">739</span>,<span style="color: #ff4500;">743</span>,<span style="color: #ff4500;">751</span>,<span style="color: #ff4500;">757</span>,<span style="color: #ff4500;">761</span>,<span style="color: #ff4500;">769</span>,<span style="color: #ff4500;">773</span>
                   ,<span style="color: #ff4500;">787</span>,<span style="color: #ff4500;">797</span>,<span style="color: #ff4500;">809</span>,<span style="color: #ff4500;">811</span>,<span style="color: #ff4500;">821</span>,<span style="color: #ff4500;">823</span>,<span style="color: #ff4500;">827</span>,<span style="color: #ff4500;">829</span>,<span style="color: #ff4500;">839</span>,<span style="color: #ff4500;">853</span>,<span style="color: #ff4500;">857</span>,<span style="color: #ff4500;">859</span>,<span style="color: #ff4500;">863</span>,<span style="color: #ff4500;">877</span>,<span style="color: #ff4500;">881</span>,<span style="color: #ff4500;">883</span>
                   ,<span style="color: #ff4500;">887</span>,<span style="color: #ff4500;">907</span>,<span style="color: #ff4500;">911</span>,<span style="color: #ff4500;">919</span>,<span style="color: #ff4500;">929</span>,<span style="color: #ff4500;">937</span>,<span style="color: #ff4500;">941</span>,<span style="color: #ff4500;">947</span>,<span style="color: #ff4500;">953</span>,<span style="color: #ff4500;">967</span>,<span style="color: #ff4500;">971</span>,<span style="color: #ff4500;">977</span>,<span style="color: #ff4500;">983</span>,<span style="color: #ff4500;">991</span>,<span style="color: #ff4500;">997</span><span style="color: black;">&#93;</span>
     <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>n <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>:
         <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>n<span style="color: #66cc66;">&amp;</span><span style="color: #ff4500;">1</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
             <span style="color: #ff7700;font-weight:bold;">for</span> p <span style="color: #ff7700;font-weight:bold;">in</span> lowPrimes:
                 <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>n <span style="color: #66cc66;">%</span> p == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
                     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
             <span style="color: #ff7700;font-weight:bold;">return</span> rabinMiller<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>
     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> generateLargePrime<span style="color: black;">&#40;</span>k<span style="color: black;">&#41;</span>:
     <span style="color: #808080; font-style: italic;">#k is the desired bit length</span>
     r=<span style="color: #ff4500;">100</span><span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">math</span>.<span style="color: black;">log</span><span style="color: black;">&#40;</span>k,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#number of attempts max</span>
     r_ = r
     <span style="color: #ff7700;font-weight:bold;">while</span> r<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">0</span>:
        <span style="color: #808080; font-style: italic;">#randrange is mersenne twister and is completely deterministic</span>
        <span style="color: #808080; font-style: italic;">#unusable for serious crypto purposes</span>
         n = <span style="color: #dc143c;">random</span>.<span style="color: black;">randrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: #66cc66;">**</span><span style="color: black;">&#40;</span>k-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>,<span style="color: #ff4500;">2</span><span style="color: #66cc66;">**</span><span style="color: black;">&#40;</span>k<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
         r-=<span style="color: #ff4500;">1</span>
         <span style="color: #ff7700;font-weight:bold;">if</span> isPrime<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> == <span style="color: #008000;">True</span>:
             <span style="color: #ff7700;font-weight:bold;">return</span> n
     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Failure after &quot;</span>+<span style="color: #66cc66;">`</span>r_<span style="color: #66cc66;">`</span> + <span style="color: #483d8b;">&quot; tries.&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> generateLargePrime<span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This code is very slow, but does not represent an entirely naïve approach.<sup class='footnote'><a href='#fn-167-2' id='fnref-167-2'>2</a></sup>  To generate a prime we first create a random integer in the range (2<sup>k-1</sup>,2<sup>k</sup>), then the following rules are applied:</p>
<ol>
<li>The number (n) must be &gt;=3.  While 2 is a prime number, for our purposes we have no interest in numbers less than 3.</li>
<li>Do a bitwise and (n&amp;1).  If the result is not 0 then we know the number is even and can throw it out.</li>
<li>Check that n%p is 0 (in other words, that n is not divisible evenly by p) for all primes &lt;1000.  This check will eliminate a large quantity of composite numbers and prevent the expense of the next test.</li>
<li>Finally we reach the core test: <a href="http://en.wikipedia.org/wiki/Miller–Rabin_primality_test">Rabin-Miller</a>.  This algorithm, if it returns true, states that there is a 75% chance that the number is prime (for the randomly chosen basis a).  To obtain a 2<sup>-128</sup> chance that the number is not prime, we must repeatedly run the Rabin-Miller test choosing different number bases.  Since each iteration of the test increases our probability by a power of 2 we must iterate 64 times to reach this confidence level.</li>
</ol>
<p> <br />
If the number passes all these tests it is returned as a valid prime number.  Of course, if you don&#8217;t trust the output from this script you can always check it with openssl&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl prime <span style="color: #000000;">7337488745629403488410174275830423641502142554560856136484326749638755396267050319392266204256751706077766067020335998122952792559058552724477442839630133</span>
8C18E5DC98684E2A15B84535635A95C4A192B73B40A780AB4CB0C58BDB9C31EF970C3AC6D804712B830FB6F1B140693A251E989F89B687EBA62781AD031D5135 is prime</pre></div></div>

<p> <a href="http://cdn.langui.sh/2009/03/8192_prime.txt" target="_blank">Click</a> for an example of an 8192-bit prime created with the generateLargePrime() function.  You can also check out a <a href="http://cdn.langui.sh/2009/03/1024_prime.txt" target="_blank">1024-bit prime</a> as well.  1024-bit keys are the minimum size recommended for end entity certificates using RSA (SSL certificates) at this time.<sup class='footnote'><a href='#fn-167-3' id='fnref-167-3'>3</a></sup></p>
<p>Of course, a large prime is nice, but it isn&#8217;t necessarily an RSA prime.  Look for another entry soon explaining the additional restrictions imposed by RSA.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-167-1'>This code is based on the pseudocode provided in <a href="http://www.amazon.com/Practical-Cryptography-Niels-Ferguson/dp/0471223573/ref=pd_bbs_sr_4?ie=UTF8&#038;s=books&#038;qid=1236471581&#038;sr=8-4" target="_blank">Practical Cryptography</a>. <span class='footnotereverse'><a href='#fnref-167-1'>&#8617;</a></span></li>
<li id='fn-167-2'>Generation of a 1024-bit prime using this script takes 5-10 seconds, whereas OpenSSL takes 0.1-0.2 seconds. <span class='footnotereverse'><a href='#fnref-167-2'>&#8617;</a></span></li>
<li id='fn-167-3'>NIST guidelines suggest migration to 2048-bit keys by 31 Dec 2010) <span class='footnotereverse'><a href='#fnref-167-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/07/generating-very-large-primes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Re-Signing An Expired CA Certificate</title>
		<link>http://langui.sh/2009/03/05/re-signing-an-expired-ca-certificate/</link>
		<comments>http://langui.sh/2009/03/05/re-signing-an-expired-ca-certificate/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 04:24:25 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=330</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/03/05/re-signing-an-expired-ca-certificate/" title="Re-Signing An Expired CA Certificate"></a>On rare occasions you may find yourself with a self-signed internal CA that has expired while you are still using certificates issued from the CA. One potential solution to this problem is to self-sign a new cert with identical fields &#8230;<p class="read-more"><a href="http://langui.sh/2009/03/05/re-signing-an-expired-ca-certificate/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/03/05/re-signing-an-expired-ca-certificate/" title="Re-Signing An Expired CA Certificate"></a><p>On rare occasions you may find yourself with a self-signed internal CA that has expired while you are still using certificates issued from the CA.  One potential solution to this problem is to self-sign a new cert with identical fields using the private key from the old certificate.<sup class='footnote'><a href='#fn-330-1' id='fnref-330-1'>1</a></sup></p>
<p>You can fill in almost all the fields using the interactive prompt, but to ensure maximum compatibility be sure every field matches exactly.  You will also need to set the serial number of the certificate via the -set_serial parameter (openssl takes this argument in decimal form, not hex)<sup class='footnote'><a href='#fn-330-2' id='fnref-330-2'>2</a></sup>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-x509</span> <span style="color: #660033;">-key</span> previousprivatekey.pem -set_serial 0000 <span style="color: #660033;">-out</span> newroot.cer</pre></div></div>

<p>You now have a new root certificate that will work with your previously issued certificates!</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-330-1'>In general this is <b>very bad practice</b>, but this article presupposes that you recognize this and it is still necessary. <span class='footnotereverse'><a href='#fnref-330-1'>&#8617;</a></span></li>
<li id='fn-330-2'>If you fail to set the serial identically Microsoft OSes will chain the certificate correctly but OpenSSL will fail. <span class='footnotereverse'><a href='#fnref-330-2'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/03/05/re-signing-an-expired-ca-certificate/feed/</wfw:commentRss>
		<slash:comments>0</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 39/53 queries in 0.020 seconds using memcached
Object Caching 1401/1419 objects using memcached

Served from: langui.sh @ 2012-02-04 13:08:14 -->
