<?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>i.n.s.i.g.h.t.s &#187; Uncategorized</title>
	<atom:link href="http://intuitinnovations.com/blog/archives/category/uncategorized/feed" rel="self" type="application/rss+xml" />
	<link>http://intuitinnovations.com/blog</link>
	<description>intuit teamlog, pictures, videos</description>
	<lastBuildDate>Fri, 02 Jul 2010 07:05:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>openVPN easyrsa batch em &#8220;build-key&#8221;</title>
		<link>http://intuitinnovations.com/blog/archives/100</link>
		<comments>http://intuitinnovations.com/blog/archives/100#comments</comments>
		<pubDate>Fri, 04 Sep 2009 06:18:02 +0000</pubDate>
		<dc:creator>Sanjay Willie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[build-key]]></category>
		<category><![CDATA[openVPN]]></category>
		<category><![CDATA[pfsense]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://intuitinnovations.com/blog/archives/100</guid>
		<description><![CDATA[We were deploying a solution for our customer which deploy pfSense as a VPN gateway and firewall to a little under 300 outlets in Malaysia.
Each outlet has a unique “storeID” which is then required to run OpenVPN daemon at the background and fires a connection whenever a layer 2 link is established.
To create under 300 [...]]]></description>
			<content:encoded><![CDATA[<p>We were deploying a solution for our customer which deploy pfSense as a VPN gateway and firewall to a little under 300 outlets in Malaysia.</p>
<p>Each outlet has a unique “storeID” which is then required to run OpenVPN daemon at the background and fires a connection whenever a layer 2 link is established.</p>
<p>To create under 300 certificates using OpenVPN’s (v2.x.x) easyrsa scripts on a CentOS clients isn’t funny. So being a lazy ass, i wrote a simple way to help to create these files fast!</p>
<p>Assuming you’ve got the whole works with OpenVPN and pfSense sorted. If not read this great document <a href="http://doc.pfsense.org/index.php/VPN_Capability_OpenVPN" target="_blank">here</a>. Once you’ve got the server side done on pfSense, you will need to generate more keys for (in this case, Pizza Hut’s) 300 branches peer certificates.</p>
<p>Snail factor</p>
<ul>
<li>Build-key prompts amongst other things the commonName or server name each time a certificate is to be generated</li>
</ul>
<p>What is needed?</p>
<ul>
<li><strong>To create store certificates that automatically creates the certificates without prompt and also using a $variable$ to “insert” the commonName value. This means, a certificate will be created with the storeID.key and storeID.crt and the storeID.csr</strong></li>
</ul>
<p>How &#8211; Conceptually?</p>
<ol>
<li>Automate the build-key file to disable prompts</li>
<li>Fire a variable into the system to pickup the $variable$ which then will be the filename and the commonName</li>
</ol>
<p>How – Technically</p>
<p>(Assumptions – easyrsa is in<em> /etc/openvpn/easyrsa</em> and keys are in <em>/etc/openvpn/easyrsa/keys</em>. In /easyrsa, you have all the scripts like build-ca, build-key)</p>
<p>Create a file called<em> </em><span style="font-family: 'Courier New'">build_batch</span> into<em> /etc/openvpn/easyrsa</em> with the following lines. Make the file executable <span style="font-family: 'Courier New'">chmod +x build_batch</span></p>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td width="400" valign="top"><span style="font-family: 'Courier New'">#!/bin/sh</span></p>
<p><span style="font-family: 'Courier New'">if test $# -ne 1; then<br />
echo &#8220;usage: batch-build &lt;name&gt;&#8221;;<br />
exit 1<br />
else<br />
export KEY_CNAME=$1<br />
./build-key $1<br />
fi</span></td>
</tr>
</tbody>
</table>
<p>Now, edit (nano/vi) the openssl.cnf file in the <em>/etc/openvpn/easyrsa</em> look for the following lines</p>
<table border="1" cellspacing="0" cellpadding="2" width="486">
<tbody>
<tr>
<td width="484" valign="top"><span style="font-family: 'Courier New'"><span style="font-size: xx-small">commonName            = Common Name (eg, your name or your server\&#8217;s hostname)<br />
commonName_max            = 64</span> </span></td>
</tr>
</tbody>
</table>
<p>Add a new line like below and save the file.</p>
<table border="1" cellspacing="0" cellpadding="2" width="486">
<tbody>
<tr>
<td width="484" valign="top"><span style="font-family: 'Courier New';font-size: xx-small">commonName            = Common Name (eg, your name or your server\&#8217;s hostname)<br />
commonName_max            = 64 </span></p>
<p><span style="font-size: xx-small"><span style="font-family: 'Courier New'"># Add this line below<br />
<strong>commonName_default        = $ENV::KEY_CNAME</strong></span></span></td>
</tr>
</tbody>
</table>
<p>Now, edit (nano/vi) the <em>build-key </em>in that same directory. At the end of the <span style="font-family: 'Courier New'">openssl –req and openssl ca</span> statements, add the <span style="font-family: 'Courier New'">–batch</span> argument.</p>
<p>This is how part of the original file look like</p>
<table border="1" cellspacing="0" cellpadding="2" width="533">
<tbody>
<tr>
<td width="531" valign="top"><span style="font-family: 'Courier New';font-size: xx-small">openssl req -days 3650 -nodes -new -keyout $1.key -out $1.csr -config $KEY_CONFIG &amp;&amp; \<br />
openssl ca -days 3650 -out $1.crt -in $1.csr -config $KEY_CONFIG &amp;&amp; \</span></td>
</tr>
</tbody>
</table>
<p>We modify to add <span style="font-family: 'Courier New'">–batch</span> at some part of the line like below and save the file</p>
<table border="1" cellspacing="0" cellpadding="2" width="571">
<tbody>
<tr>
<td width="569" valign="top"><span style="font-family: 'Courier New';font-size: xx-small">openssl req -days 3650 -nodes -new -keyout $1.key -out $1.csr <strong>-batch</strong> -config $KEY_CONFIG &amp;&amp; \<br />
openssl ca -days 3650 -out $1.crt -in $1.csr <strong>-batch</strong> -config $KEY_CONFIG &amp;&amp; \</span></td>
</tr>
</tbody>
</table>
<p>Now you’re ready to run in batch. But before that, please feed the vars in the environment like below in <em>/etc/openvpn/easyrsa</em></p>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td width="400" valign="top"><span style="font-family: 'Courier New'">source ./vars</span></td>
</tr>
</tbody>
</table>
<p>Run a sample like below</p>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td width="400" valign="top"><span style="font-family: 'Courier New'">./build_batch test01</span></td>
</tr>
</tbody>
</table>
<p>This will build the test01.crt, test01.csr and test01.key automatically in <em>/etc/openvpn/easyrsa/keys </em>with the commonName test01 also <img src='http://intuitinnovations.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Done.</p>
<p>Now, if you want to do lots of these, use this Excel below</p>
<div class="wlWriterEditableSmartContent" style="padding-bottom: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;float: none;padding-top: 0px">
<div>Excel<a href="http://intuitinnovations.com/blog/wp-content/uploads/2009/09/easyrsalinemaker3.xls" target="_blank">easy-rsa-linemaker.xls</a></div>
</div>
<p>Use the Excel file (build-cert sheet) to generate script lines (see the excel sample) so you can copy and paste into a SSH remote session in the appropriate directory.</p>
<p>Copy in batch up to 50 lines (within buffer) from the copypaster column and paste via a SSH session into the /etc/openvpn/easyrsa and it will generate without prompting anything. Quick and easy.</p>
<p><a href="http://intuitinnovations.com/blog/wp-content/uploads/2009/09/image1.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" src="http://intuitinnovations.com/blog/wp-content/uploads/2009/09/image_thumb2.png" border="0" alt="image" width="464" height="173" /></a></p>
<p>To remove/revoke certs, do the same but use the Excel’s revoke-cert sheet.</p>
<p><a href="http://intuitinnovations.com/blog/wp-content/uploads/2009/09/image2.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" src="http://intuitinnovations.com/blog/wp-content/uploads/2009/09/image_thumb3.png" border="0" alt="image" width="473" height="125" /></a></p>
<p>If you get issues where the script says it can&#8217;t find certificates (but have removed the commonName out of its database) simply go to /keys and manually delete the relevant keys e.g. store1.csr, store1.key and store1.crt.</p>
<p>If things mess up a lot, just run. Source ./vars again loads env variables properly.</p>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td width="400" valign="top"><span style="font-family: 'Courier New';">source ./vars</span><span style="font-family: 'Courier New'; ">./clean-all</span></td>
</tr>
</tbody>
</table>
<p>Warning, this will remove your CA, server and dh information which you then need to repopulate inside pfSense.</p>
<p>So, if you want to save those, simply do not remove all ca.* &lt;server&gt;.* dh*. Copy them somewhere safe and place them back into /keys to &#8220;restore&#8221;.</p>
<p>But, if you want to start all over again, you can run the above ./clean-all but and that should remove everything in /keys and reset the database appropriately. Then you must recreate all below</p>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td width="400" valign="top"><span style="font-family: 'Courier New';">source ./vars</span></p>
<p><span style="font-family: 'Courier New'">./build-ca<br />
./build-key-server<br />
./build-dh</span></td>
</tr>
</tbody>
</table>
<p>Then re run the above stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://intuitinnovations.com/blog/archives/100/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
