<?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>MagicalTux in Japan &#187; security</title>
	<atom:link href="http://blog.magicaltux.net/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.magicaltux.net</link>
	<description>Geekness brought me to Japan!</description>
	<lastBuildDate>Mon, 26 Jul 2010 21:31:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Registrars and authcodes</title>
		<link>http://blog.magicaltux.net/2010/03/11/registrars-and-authcodes/</link>
		<comments>http://blog.magicaltux.net/2010/03/11/registrars-and-authcodes/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 14:29:35 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Geek Attitude]]></category>
		<category><![CDATA[Authcode]]></category>
		<category><![CDATA[Ethics]]></category>
		<category><![CDATA[GoDaddy]]></category>
		<category><![CDATA[OVH]]></category>
		<category><![CDATA[Registrar]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=458</guid>
		<description><![CDATA[Many registrars out there have found different ways to implement Verisign&#8217;s requirement of harder-to-guess authcodes for domains by asking to have at least one symbol character (non letter, non number) in the authcode. This had different effect on different registrars. For example french registrar OVH have implemented it a bit too well, resulting in authcodes [...]]]></description>
			<content:encoded><![CDATA[<p>Many registrars out there have found different ways to implement Verisign&#8217;s requirement of harder-to-guess authcodes for domains by asking to have at least one symbol character (non letter, non number) in the authcode.</p>
<p>This had different effect on different registrars. For example french registrar OVH have implemented it a bit too well, resulting in authcodes like &#8220;d*zuW.;2t/!&gt;pHbU&#8221;, while others have decided that it wasn&#8217;t their problem, and just added a prefix to their authcodes. This is the case for example of GoDaddy, whose authcodes are limited in randomness. An authcode will look like: &#8220;S1-AF94C9510BA1C&#8221;. Yeah right, &#8220;S1-&#8221; followed by an uppercase hexadecimal string. I&#8217;m pretty sure Verisign wasn&#8217;t expecting this when they published the new requirement.</p>
<p>Anyway conditions to steal a domain are pretty much complex (you need to have it unlocked, need to know the authcode, and once transfer is started, the current registrant must not ask his registrar to cancel the transfer for 5 days, and even after the domain is transferred, there are ways to get it back &#8211; it&#8217;s just more expensive). Stealing a domain is a complex operation which will most likely be followed by legal repercussions.</p>
<p>Best thing to do is to <a href="http://whois.nf/" target="_blank">check from times to times in a whois</a> that your domain is really showing your name and address. If not, you might need to do something about it before it&#8217;s too late. You might want to consider transferring your domain to <a href="http://www.kalyhost.com/" target="_blank">a company which cares about you</a> <img src='http://blog.magicaltux.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  (we&#8217;ll even fight your old provider if troubles arise, they can refuse transfer only in some specified cases, as long as you are owner of your domain).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2010/03/11/registrars-and-authcodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Port knocking, how would I do?</title>
		<link>http://blog.magicaltux.net/2009/03/02/port-knocking-how-would-i-do/</link>
		<comments>http://blog.magicaltux.net/2009/03/02/port-knocking-how-would-i-do/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 20:28:08 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Port knocking]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=254</guid>
		<description><![CDATA[As I saw some articles which seems rather unexact relating port knocking, I would like to add some parts of my own idea about this. First, port knocking is not meant to be used alone&#8230; Even if you use your daemon&#8217;s default port (let&#8217;s say port 22 for sshd), port knocking can protect you more [...]]]></description>
			<content:encoded><![CDATA[<p>As I saw <a href="http://www.linux.com/articles/37888" target="_blank">some articles which seems rather unexact relating port knocking</a>, I would like to add some parts of my own idea about this.</p>
<p>First, port knocking is <em>not</em> meant to be used alone&#8230;</p>
<p>Even if you use your daemon&#8217;s default port (let&#8217;s say port 22 for sshd), port knocking can protect you more than you can even imagine. Let&#8217;s take the following setup:</p>
<ul>
<li>SSHd running on port 65122</li>
<li>Connections to port 65122 are replied with &#8220;connection refused&#8221; (via an icmp target rule)</li>
<li>In order to &#8220;open&#8221; port 65122, connection attempts must be made to ports 22448, 44228 and 22884 in this order. Any other order will blacklist the IP attempting to connect for 1 hour</li>
<li>More than 5 attempts to connect to port 65122 within 20 minutes will result in 1 hour blacklist</li>
</ul>
<p>Now, if you&#8217;re that smart, just try to find your way in without the &#8220;passphrase&#8221; (which is 22448-44228-22884-65122). If you do too many attempts, you&#8217;ll end blacklisted. Let&#8217;s say you found out that port 65122 gets you banned when you connect, and have determined that you can make up to 5 attempts in 20 minutes. Let&#8217;s also say you know you have to knock exactly 3 ports to be able to connect.<br />
You then have to test 65536^3 = 281474976710656 combinations, and can only test 5 in 20 minutes, that would require 70368744177660 minutes (133882694 years or so).</p>
<p>I can assume no decent system will be up for 133882694 years without any shift into security settings. You can parallelize that with different source IPs, but it will still last too long against people shifting every 3~6 months.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/03/02/port-knocking-how-would-i-do/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using SSL keys for client authentification</title>
		<link>http://blog.magicaltux.net/2009/02/09/using-ssl-keys-for-client-authentification/</link>
		<comments>http://blog.magicaltux.net/2009/02/09/using-ssl-keys-for-client-authentification/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 21:08:49 +0000</pubDate>
		<dc:creator>MagicalTux</dc:creator>
				<category><![CDATA[Geek Attitude]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[authentification]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.magicaltux.net/?p=224</guid>
		<description><![CDATA[As you may have seen on services such as MyOpenId, you can either login on your account with a password, or you can generate a client identification SSL certificate and let your users identify with one of the most secure way (as long as they don&#8217;t get their keys stolen). SSL identification? The idea is [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have seen on services such as <a href="http://www.myopenid.com/">MyOpenId</a>, you can either login on your account with a password, or you can generate a client identification SSL certificate and let your users identify with one of the most secure way (as long as they don&#8217;t get their keys stolen).</p>
<h3>SSL identification?</h3>
<p>The idea is pretty simple. Usually communications between a SSL client and server are done via a public/private key system. While I never checked in depth, I assume it&#8217;s pretty much like for mails: the client generates a client certificate, connects to the server, gets the server&#8217;s public key, sends its public key to the server, then use its own private key and the server&#8217;s public key to exchange data.<br />
SSL identification happens there: instead of generating a key, the client will use a previously generated private key, and send its public key alongside a certificate previously obtained from the server. The server will be able to check the certificate, which proves that the client&#8217;s key has been signed by the server CA (another private certificate held by the server, only used to make client certificates).</p>
<p>This way, the server will know that the key used by the client was signed by him and can be <em>trusted</em>.</p>
<p><em>How did this happen? Who gave its key to the client? How can you do the same on your website with PHP? What? Why are you talking about PHP 5.3.1?</em></p>
<p><span id="more-224"></span></p>
<h3>Client certificate generation process</h3>
<p style="padding-left: 30px;">Before doing anything, you&#8217;ll need a certificate authority (CA). OpenSSL is bundled with a script for this, however the default config (at least on gentoo) will mark CA as being &#8220;not a CA&#8221;.</p>
<p style="padding-left: 30px;">In order to achieve this, here are the few steps you&#8217;ll need to follow:</p>
<ol>
<li>Edit /etc/ssl/openssl.conf (or whatever your openssl file is) and change CA:FALSE to CA:TRUE (if you use vi, type :%s/CA:FALSE/CA:TRUE/). Save.</li>
<li>Choose a location for your CA. You will most likely want to choose a directory the webserver will be able to access, but without putting it in the website&#8217;s root (don&#8217;t be stupid!)</li>
<li>Generate your CA. For this, OpenSSL made things easy. Type: /etc/ssl/misc/CA.sh -newca and follow direction</li>
<li>Edit back your openssl.conf file to replace CA:TRUE with CA:FALSE, or you will be making LOTS of CA certificates.</li>
<li>Decrypt your CA key. While it&#8217;s <strong>not</strong> recommanded, avoiding the trouble of providing your CA key&#8217;s passphrase each time you do something might be nice. Just ensure you keep it safe, or anyone will be able to make certificates your webserver will trust.<br />
$ openssl rsa -in demoCA/private/cakey.pem -out demoCA/private/cakey.pem<br />
This will ask for  the passphrase, and will save the  key without any passphrase. Personally I use <a href="http://pecl.php.net/package/ssh2" target="_blank">libssh2</a>, and have the webserver login as a &#8220;casign&#8221; user, which is allowed to sudo as the CA user, but only with the command to sign a single key. This way, if anything happens, I&#8217;ll still have the signed keys in my CA index and will be able to revoke them.</li>
</ol>
<p>As the client certificate generation process on MSIE is too much troubles (you&#8217;ll need to invoke ActiveX elements such as Xenroll.cab) I&#8217;ll only speak about the process made by Netscape, and compatible with both Firefox and Opera according to documentation found on internet (maybe also compatible with google chrome, or webkit, didn&#8217;t test yet).</p>
<p>So, on Netscape (and compatible browers), you have an not really common HTML tag: <em>&lt;keygen&gt;</em>. This tag will make the browser display a select box, typically with the encryption level choice. As High Grade certificates are generated within seconds on most recent systems, it&#8217;s usually the best choices. You can even make the element invisible (display: none) to avoid to the visitor the trouble of choosing.</p>
<p>Tag example:</p>
<pre>&lt;keygen name="spkac"/&gt;</pre>
<p>So, nothing fancy, however just having this tag in a form will cause the variable &#8220;spkac&#8221; being posted with a bunch of base64-encoded data. <em>SPKAC</em> is a netscape standard for a &#8220;signing request&#8221;, for the private key the browser just generated. It contains informations such as a public key and a signature. What we need to do is to provide the browser with a certificate, made by our CA.</p>
<p>While signing the key, we are able to customize parts of the final certificate, making it easier for the user to choose a certificate when the time comes. A certificate typically contains the following fields:</p>
<ul>
<li><em>commonName</em>: This is the &#8220;main&#8221; name for the certificate, which will be displayed in the browser&#8217;s dropdown box.</li>
<li><em>emailAddress</em>: An email address. I personally use it to store &lt;uuid&gt;@mydomain.tld. The uuid is unique to the key, and when the user comes back, I can identify him by looking up the uuid part in my database.</li>
<li><em>organizationName</em>: The name of your company (usually the same as the CA)</li>
<li><em>organizationalUnitName</em>: just put whatever you want</li>
<li><em>localityName</em>: a city, typically the same as your CA, as for the rest too&#8230;</li>
<li><em>stateOrProvinceName</em></li>
<li><em>countryName</em></li>
</ul>
<p>To make OpenSSL like you, you will have to create a text file containing on each line one of those elements, followed by the equal symbol, then the value you wish to give to this property. Finally, add a line &#8220;SPKAC = &#8221; followed by the base64 data previously sent by the browser (remember to strip linebreaks, or OpenSSL won&#8217;t be happy).</p>
<p>Once the text file is ready, you can generate the key!</p>
<pre>openssl ca -spkac my_spkac_file -out certificate_file -days 365</pre>
<p>This will create a certificate valid for 365 days, certifying your CA acknowledges the browser&#8217;s key as genuine. Now that you got a &#8220;certificate_file&#8221;, you need to send it back to the browser. This is done easily with PHP, just don&#8217;t forget this before sending the content of the file to the browser:</p>
<pre>header('Content-Type: application/x-x509-user-cert');</pre>
<p>As you are most likely targetting firefox/opera, you can probably use data URI by encoding the gibberish generated by OpenSSL in base64 and inserting something like:</p>
<pre>&lt;iframe width="1" height="1" style="display: none;"
  src="data:application/x-x509-user-cert;base64,MII..."&gt;&lt;/iframe&gt;</pre>
<p>Firefox displays a &#8220;certificate installed&#8221; alert box when this happens, dunno about Opera.</p>
<p>Anyway, you have now installed a certificate on your client browser, now you will maybe want to ask for authentication&#8230;</p>
<h3>Client authentication part</h3>
<p>As on most configurations, the client will be asked to choose a certificate each time he loads a page, we usually make only one path to use SSL authentification, and store the information in session once the user is identified. It might also not be a good idea to always force the user to identify as it might bother him to see his browser asking for a key.</p>
<p>Before anything, you need to make sure your website is protected with SSL. Asking for an SSL key exchange without SSL is like asking for a kebab without meat.</p>
<p>You&#8217;ll also have to tell Apache about your CA. Copy the demoCA/cacert.pem file in a directory accessible to apache, and create a special symlink with the certificate&#8217;s hash. In order to know exactly how you should do your symlink, OpenSSL provides a nice tool.</p>
<pre>$ /etc/ssl/misc/c_hash cacert.pem
8aafa88f.0 =&gt; cacert.pem
$ <strong>ln -s cacert.pem 8aafa88f.0</strong></pre>
<p>You can have more than one CA if you wish to. The folder where you put those is to be provided to Apache&#8217;s mod_ssl with directive  <a href="http://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslcacertificatepath" target="_blank">SSLCACertificatePath</a>.</p>
<p>Now that apache is able to recognize an SSL certificate, you just need to create a directory for openssl authentification, and put the following in the .htaccess file :</p>
<pre><a href="http://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslverifyclient" target="_blank">SSLVerifyClient</a> optional</pre>
<p>This will force apache to renegociate the SSL link when a request to your directory is done, and ask if the browser is able to provide a certificate. You can then check data from $_SERVER (in PHP) to find details from the certificate (phpinfo() is a good way to find out what&#8217;s stored there. Basically you can get back all the data you stored previously).</p>
<p>Once you verified data provided there, you can store in session details about the user, and direct him back to a normal part of your website.</p>
<h3>What&#8217;s next?</h3>
<p>Now that you&#8217;re (in theory) able to manage authentification for your Firefox/Opera visitors, you could start looking at MSIE (and its pkcs#10 keys), and improve visitor experience on your website using SSL keys.</p>
<p>Right now I&#8217;m trying to see how hard it would be to give the ability to sign SPKAC keys via the PHP&#8217;s OpenSSL ext with the help of <a href="http://thepimp.net/" target="_blank">Pierre</a>. This is not going to be easy, and won&#8217;t be available anyway before PHP 5.3.1 (this is just a personal hope), but once provided/made easy for both Netscape-based browsers and MSIE, we might start seeing software made in PHP taking advantage of this kind of ability.</p>
<h3>Troubleshooting</h3>
<ul>
<li>I double-checked the apache config, but I still get to choose any of the certificates installed on the brower, even ones I didn&#8217;t generate.<br />
You forgot to edit your openssl config to put CA:TRUE. Remember to put it back to CA:FALSE once you generated your SSL key.</li>
<li>I have a problem not mentionned here.<br />
Just <a href="mailto:mark@hell.ne.jp">contact me</a>, we might be able to fix this&#8230;</li>
<li>I have too many beers in my fridge.<br />
Just <a href="mailto:mark@hell.ne.jp">contact me</a>, I might be able to fix this&#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.magicaltux.net/2009/02/09/using-ssl-keys-for-client-authentification/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
