<?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; openssl</title>
	<atom:link href="http://langui.sh/tag/openssl/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, 24 Aug 2010 17:40:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Parsing A CRL With OpenSSL</title>
		<link>http://langui.sh/2010/01/10/parsing-a-crl-with-openssl/</link>
		<comments>http://langui.sh/2010/01/10/parsing-a-crl-with-openssl/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 02:29:47 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crl]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=952</guid>
		<description><![CDATA[Short and sweet. This command will give you a list of revoked serial numbers: openssl crl -inform DER -text -noout -in mycrl.crl Most CRLs are DER encoded, but you can use -inform PEM if your CRL is not binary. If you&#8217;re unsure if it is DER or PEM open it with a text editor. If [...]]]></description>
			<content:encoded><![CDATA[<p>Short and sweet.  This command will give you a list of revoked serial numbers:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl crl <span style="color: #660033;">-inform</span> DER <span style="color: #660033;">-text</span> <span style="color: #660033;">-noout</span> <span style="color: #660033;">-in</span> mycrl.crl</pre></div></div>

<p>Most CRLs are DER encoded, but you can use -inform PEM if your CRL is not binary.  If you&#8217;re unsure if it is DER or PEM open it with a text editor.  If you see &#8212;&#8211;BEGIN X509 CRL&#8212;&#8211; then it&#8217;s PEM and if you see strange binary-looking garbage characters it&#8217;s DER.</p>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2010/01/10/parsing-a-crl-with-openssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSSL and IDN Certificates</title>
		<link>http://langui.sh/2010/01/03/openssl-and-idn-certificates/</link>
		<comments>http://langui.sh/2010/01/03/openssl-and-idn-certificates/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 17:34:46 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[idn]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=946</guid>
		<description><![CDATA[As internationalized domain names (IDN) proliferate more people need to test with, and ultimately purchase, IDN certificates. If you need to generate a CSR or even a self-signed certificate for an internationalized domain follow these steps: Take the UTF-8 characters and paste them into a punycode converter (also known as ASCII compatible encoding, or ACE). [...]]]></description>
			<content:encoded><![CDATA[<p>As internationalized domain names (IDN) proliferate more people need to test with, and ultimately purchase, IDN certificates.  If you need to generate a CSR or even a self-signed certificate for an internationalized domain follow these steps:</p>
<ol>
<li>Take the UTF-8 characters and paste them into a <a href="http://idnaconv.phlymail.de/" target="_blank">punycode converter</a> (also known as ASCII compatible encoding, or ACE).</li>
<li>The resulting converted text will be a fairly long string that starts with &#8220;xn--&#8221;.  Copy the entire thing.</li>
<li>Now run this command.</li>
</ol>
<p>For CSR generation<sup class='footnote'><a href='#fn-946-1' id='fnref-946-1'>1</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;">-nodes</span> <span style="color: #660033;">-out</span> mycsr.csr <span style="color: #660033;">-keyout</span> mykey.pem <span style="color: #660033;">-newkey</span> rsa:<span style="color: #000000;">2048</span></pre></div></div>

<p>For self-signed certificate generation<sup class='footnote'><a href='#fn-946-2' id='fnref-946-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;">-nodes</span> <span style="color: #660033;">-x509</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">3650</span> <span style="color: #660033;">-out</span> mycert.cer <span style="color: #660033;">-keyout</span> mykey.pem <span style="color: #660033;">-newkey</span> rsa:<span style="color: #000000;">2048</span></pre></div></div>

<p>Either way, follow the prompts and when you reach Common Name paste the text you copied from the punycode converter.  Now you can submit your CSR to a certification authority or install the self-signed certificate for testing.
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-946-1'>We are generating a <a href="/2009/10/31/create-a-2048-bit-key-via-openssl/">2048-bit CSR</a> <span class='footnotereverse'><a href='#fnref-946-1'>&#8617;</a></span></li>
<li id='fn-946-2'>This will generate a 10 year self-signed certificate. <span class='footnotereverse'><a href='#fnref-946-2'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2010/01/03/openssl-and-idn-certificates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find A Matching Certificate And Key Pair</title>
		<link>http://langui.sh/2009/11/08/find-a-matching-certificate-and-key-pair/</link>
		<comments>http://langui.sh/2009/11/08/find-a-matching-certificate-and-key-pair/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 02:49:21 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=806</guid>
		<description><![CDATA[If you have a list of keys and SSL certs and don&#8217;t know which cert belongs with which key, here&#8217;s a script for you. It&#8217;s not efficient (nested for loop!), but it gets the job done quickly.1 #!/bin/bash for i in `ls *.key` do key_mod=`openssl rsa -noout -in $i -modulus` for j in `ls *.cer` [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a list of keys and SSL certs and don&#8217;t know which cert belongs with which key, here&#8217;s a script for you.  It&#8217;s not efficient (nested for loop!), but it gets the job done quickly.<sup class='footnote'><a href='#fn-806-1' id='fnref-806-1'>1</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.key<span style="color: #000000; font-weight: bold;">`</span> 
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #007800;">key_mod</span>=<span style="color: #000000; font-weight: bold;">`</span>openssl rsa <span style="color: #660033;">-noout</span> <span style="color: #660033;">-in</span> <span style="color: #007800;">$i</span> -modulus<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">for</span> j <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.cer<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #007800;">x509_mod</span>=<span style="color: #000000; font-weight: bold;">`</span>openssl x509 <span style="color: #660033;">-noout</span> <span style="color: #660033;">-in</span> <span style="color: #007800;">$j</span> -modulus<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$x509_mod</span>&quot;</span> == <span style="color: #ff0000;">&quot;<span style="color: #007800;">$key_mod</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$j</span> matches <span style="color: #007800;">$i</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span> 
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-806-1'>If bash allowed multidimensional or associative arrays this would be trivial to optimize. <span class='footnotereverse'><a href='#fnref-806-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/11/08/find-a-matching-certificate-and-key-pair/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create A 2048-bit Key Via OpenSSL</title>
		<link>http://langui.sh/2009/10/31/create-a-2048-bit-key-via-openssl/</link>
		<comments>http://langui.sh/2009/10/31/create-a-2048-bit-key-via-openssl/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 16:32:37 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=741</guid>
		<description><![CDATA[We are fast approaching the date where NIST has recommended that end entities stop utilizing 1024-bit private keys. OpenSSL, however, currently defaults to creating 1024-bit keypairs. To create a 2048-bit private key and corresponding CSR (which you can send to a certificate authority to obtain your SSL certificate): openssl req -new -nodes -newkey rsa:2048 -keyout [...]]]></description>
			<content:encoded><![CDATA[<p>We are fast approaching the date where <a href="http://www.nist.gov">NIST</a> has recommended that end entities stop utilizing 1024-bit private keys.  OpenSSL, however, currently defaults to creating 1024-bit keypairs. To create a 2048-bit private key and corresponding CSR (which you can send to a certificate authority to obtain your SSL certificate):</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;">-newkey</span> rsa:<span style="color: #000000;">2048</span> <span style="color: #660033;">-keyout</span> mydomain.key <span style="color: #660033;">-out</span> mydomain.csr</pre></div></div>

<p>This command will make a 2048-bit key, run the interactive prompt to populate the fields of the certificate signing request, and leave the private key unencrypted (-nodes).  You can remove -nodes if you wish, but encrypting the private key will require you to type the password every time you start an application (like apache) that uses it.</p>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/10/31/create-a-2048-bit-key-via-openssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check If A Certificate &amp; Private Key Match</title>
		<link>http://langui.sh/2009/10/05/check-if-a-certificate-private-key-match/</link>
		<comments>http://langui.sh/2009/10/05/check-if-a-certificate-private-key-match/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 14:52:30 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[x509]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=678</guid>
		<description><![CDATA[Check if an SSL certificate and private key match in two simple commands. The OpenSSL commands below will require you to replace &#60;file&#62; with your file&#8217;s name. For your SSL certificate:1 openssl x509 -noout -modulus -in &#60;file&#62; &#124; md5sum For your RSA private key: openssl rsa -noout -modulus -in &#60;file&#62; &#124; md5sum The output of [...]]]></description>
			<content:encoded><![CDATA[<p>Check if an SSL certificate and private key match in two simple commands.  The OpenSSL commands below will require you to replace &lt;file&gt; with your file&#8217;s name.</p>
<p>For your SSL certificate:<sup class='footnote'><a href='#fn-678-1' id='fnref-678-1'>1</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl x509 <span style="color: #660033;">-noout</span> <span style="color: #660033;">-modulus</span> <span style="color: #660033;">-in</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">|</span> md5sum</pre></div></div>

<p>For your RSA private key:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl rsa <span style="color: #660033;">-noout</span> <span style="color: #660033;">-modulus</span> <span style="color: #660033;">-in</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">|</span> md5sum</pre></div></div>

<p>The output of these commands should be identical.  If it isn&#8217;t, your keys do not match. </p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-678-1'>The pipe to md5sum is solely to make the output shorter and easier to visually compare <span class='footnotereverse'><a href='#fnref-678-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/10/05/check-if-a-certificate-private-key-match/feed/</wfw:commentRss>
		<slash:comments>1</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[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 and pull the /index.php file. You can specify whatever file you&#8217;d like to download, or [...]]]></description>
			<content:encoded><![CDATA[<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;.
<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[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 [...]]]></description>
			<content:encoded><![CDATA[<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[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 [...]]]></description>
			<content:encoded><![CDATA[<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[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.1 First let&#8217;s do a standard webserver connection (-showcerts dumps the PEM encoded certificates [...]]]></description>
			<content:encoded><![CDATA[<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.
<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>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[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.1 You can fill in almost all the [...]]]></description>
			<content:encoded><![CDATA[<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!
<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>
