<?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>Jabbering Giraffe &#187; security</title>
	<atom:link href="http://happygiraffe.net/blog/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Wed, 19 Oct 2011 10:40:06 +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>sandbox(7)</title>
		<link>http://happygiraffe.net/blog/2009/06/02/sandbox7/</link>
		<comments>http://happygiraffe.net/blog/2009/06/02/sandbox7/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 20:12:06 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1524</guid>
		<description><![CDATA[Like a lot of people, most of my Unix knowledge comes from an early reading of Advanced Programming in the UNIX Environment. This is an excellent tome on the interfaces provided by the kernel to programs on a Unix system. &#8230; <a href="http://happygiraffe.net/blog/2009/06/02/sandbox7/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Like a lot of people, most of my Unix knowledge comes from an early reading of <a href="http://www.kohala.com/start/apue.html">Advanced Programming in the UNIX Environment</a>.  This is an <em>excellent</em> tome on the interfaces provided by the kernel to programs on a Unix system.</p>
<p>Unfortunately, it&#8217;s over 15 years old now, and things have moved on.  Naturally, I haven&#8217;t quite kept up.  So I&#8217;ve just been pleasantly surprised to see that OS X has grown a sandbox system (<a href="http://blog.chromium.org/2009/06/google-chrome-sandboxing-and-mac-os-x.html">via</a>).  There is scant documentation available:</p>
<ul>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/sandbox-exec.1.html#//apple_ref/doc/man/1/sandbox-exec">sandbox-exec(1)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man3/sandbox_init.3.html">sandbox_init(3)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man7/sandbox.7.html#//apple_ref/doc/man/7/sandbox">sandbox(7)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man8/sandbox-compilerd.8.html#//apple_ref/doc/man/8/sandbox-compilerd">sandbox-compilerd(8)</a></li>
</ul>
<p>Also, if you poke around, you&#8217;ll find <code>/usr/include/sandbox.h</code> and <code>/usr/share/sandbox</code>.  The latter is interesting — it contains lisp-like definitions of access control lists for various processes.</p>
<p>What&#8217;s interesting to me is <code>sandbox-exec</code> though.  This can be used with one of the builtin profiles to easily restrict access.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ sandbox-exec <span style="color: #660033;">-n</span> nowrite <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>foo
<span style="color: #c20cb9; font-weight: bold;">touch</span>: <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>foo: Operation not permitted</pre></div></div>

<p>After using <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/strings.1.html">strings(1)</a> on apple&#8217;s libc (<code>/usr/lib/libSystem.dylib</code>), I managed to get these builtin profile names out:</p>
<dl>
<dt><em>nointernet</em></dt>
<dd>TCP/IP networking is prohibited</dd>
<dt><em>nonet</em></dt>
<dd>All sockets-based networking is prohibited.</dd>
<dt><em>pure-computation</em></dt>
<dd>All operating system services are prohibited.</dd>
<dt><em>nowrite</em></dt>
<dd>File system writes are prohibited.</dd>
<dt><em>write-tmp-only</em></dt>
<dd>File system writes are restricted to the temporary folder <code>/var/tmp</code> and the folder specified by the <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man3/confstr.3.html#//apple_ref/doc/man/3/confstr">confstr(3)</a> configuration variable <code>_CS_DARWIN_USER_TEMP_DIR</code>.</dd>
</dl>
<p>They&#8217;re only documented as internal constants for C programs, but it&#8217;s quite handy to have them available for <code>sandbox-exec</code>.  It would be nice to know in more detail what they actually <em>did</em>, though.</p>
<p>Of course, this still isn&#8217;t really getting down to how the sandbox is implemented.  Is it done inside the kernel or on the userland side?  I don&#8217;t really know.  And I don&#8217;t yet have enough dtrace-fu to figure it out.</p>
<p>See also:</p>
<ul>
<li><a href="http://www.318.com/techjournal/security/a-brief-introduction-to-mac-os-x-sandbox-technology/">A brief introduction to Mac OS X SandBox Technology</a></li>
<li><a href="http://www.usefulsecurity.com/2007/11/apple-sandboxes-part-1/">Apple Sandboxes Part 1</a></li>
<li><a href="http://www.usefulsecurity.com/2007/11/apple-sandboxes-part-2/">Apple Sandboxes Part 2</a></li>
<li><a href="http://www.matasano.com/log/981/a-roundup-of-leopard-security-features/">A Roundup Of Leopard Security Features</a></li>
</ul>
<p>Anyway, this seems like a fun toy.  And of course, it&#8217;s reminded me that I need to try out <a href="http://build.chromium.org/buildbot/snapshots/sub-rel-mac/">chromium on the mac</a>…  Drat, no PPC support.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/02/sandbox7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cross Site Scripting, again</title>
		<link>http://happygiraffe.net/blog/2009/04/14/cross-site-scripting-again/</link>
		<comments>http://happygiraffe.net/blog/2009/04/14/cross-site-scripting-again/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 22:21:18 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1505</guid>
		<description><![CDATA[Twitter all clear after worm wave Twitter has been given the all clear after a worm infected &#8220;tens of thousands of users&#8221;. But experts say the attack could have been much worse. Another day, another XSS hole. It reminds me &#8230; <a href="http://happygiraffe.net/blog/2009/04/14/cross-site-scripting-again/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>
<a href="http://news.bbc.co.uk/1/hi/technology/7997732.stm">Twitter all clear after worm wave</a></p>
<p>Twitter has been given the all clear after a worm infected &#8220;tens of thousands of users&#8221;. But experts say the attack could have been much worse.
</p></blockquote>
<p>Another day, another <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">XSS</a> hole.  It reminds me of something (probably apocryphal) that I heard about lung cancer research.  There&#8217;s no real need for it.  We know what causes lung cancer — smoking.</p>
<p>True or not, we know what causes XSS holes.  It&#8217;s poor tools.  Now given a choice between:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;c:out</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${userName}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${userName}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Guess which one is going to be picked, every single time.  And guess which one doesn&#8217;t escape HTML properly.  Lest you think I&#8217;m picking on JSPs, most templating systems have the same flaw.</p>
<p>This is why I was immensely pleased to see <a href="http://googleonlinesecurity.blogspot.com/2009/03/reducing-xss-by-way-of-automatic.html">Reducing XSS by way of Automatic Context-Aware Escaping in Template Systems</a> from Google.  Unfortunately, their solution isn&#8217;t universally available yet, but it really serves the purpose of showing how this can be done correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/04/14/cross-site-scripting-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jasypt++</title>
		<link>http://happygiraffe.net/blog/2008/11/08/jasypt-2/</link>
		<comments>http://happygiraffe.net/blog/2008/11/08/jasypt-2/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 19:18:38 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1406</guid>
		<description><![CDATA[Once again, jasypt (&#8220;Java Simplified Encryption&#8221;) makes me smile. Java comes with a comprehensive set of encryption utilities: JCE. I had to do some decryption the other day and ended up with this code. public class Decryptor &#123; private static &#8230; <a href="http://happygiraffe.net/blog/2008/11/08/jasypt-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Once <a href="http://happygiraffe.net/blog/2008/07/22/jasypt/">again</a>, <a href="http://jasypt.org/">jasypt</a> (&#8220;Java Simplified Encryption&#8221;) makes me smile.</p>
<p>Java comes with a comprehensive set of encryption utilities: <a href="http://java.sun.com/j2se/1.5.0/docs/guide/security/jce/JCERefGuide.html">JCE</a>.  I had to do some decryption the other day and ended up with this code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decryptor <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> ALGORITHM <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PBEWithMD5AndDES&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Base64 base64 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Base64<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Cipher cipher<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Decryptor<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            cipher <span style="color: #339933;">=</span> Cipher.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>ALGORITHM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Just generate an empty salt as we don't want to use one.</span>
            <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> salt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span>cipher.<span style="color: #006633;">getBlockSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span>salt, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Set up the cipher.</span>
            PBEKeySpec pbeKeySpec <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PBEKeySpec<span style="color: #009900;">&#40;</span>password.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            SecretKeyFactory factory <span style="color: #339933;">=</span> SecretKeyFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>ALGORITHM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            SecretKey key <span style="color: #339933;">=</span> factory.<span style="color: #006633;">generateSecret</span><span style="color: #009900;">&#40;</span>pbeKeySpec<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            PBEParameterSpec parameterSpec <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PBEParameterSpec<span style="color: #009900;">&#40;</span>salt, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            cipher.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>Cipher.<span style="color: #006633;">DECRYPT_MODE</span>, key, parameterSpec<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NoSuchAlgorithmException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>NoSuchPaddingException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvalidKeySpecException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvalidKeyException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvalidAlgorithmParameterException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> decrypt<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> cipherText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// cipherText is base64, so will always be ASCII.</span>
            <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> cipherBytes <span style="color: #339933;">=</span> base64.<span style="color: #006633;">decode</span><span style="color: #009900;">&#40;</span>cipherText.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;US-ASCII&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> decryptedMessage <span style="color: #339933;">=</span> cipher.<span style="color: #006633;">doFinal</span><span style="color: #009900;">&#40;</span>cipherBytes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">// Assume encrypted text is UTF-8.</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>decryptedMessage, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">UnsupportedEncodingException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>IllegalBlockSizeException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>BadPaddingException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This does also include conversion from base64 using Apache <a href="http://commons.apache.org/codec/">commons-codec</a>, but it&#8217;s a lot of code.  Even though I&#8217;ve tried to make things simpler (attempting to not use a salt [and I <em>am</em> aware of the consequences]), there&#8217;s still a lot of baggage.</p>
<p>Which is why I&#8217;m so grateful to have found jasypt.  Essentially, all the above code is wrapped up for you in a nice little API.  The above comes down to:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  SimplePBEConfig config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePBEConfig<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  config.<span style="color: #006633;">setPassword</span><span style="color: #009900;">&#40;</span>password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  config.<span style="color: #006633;">setSaltGenerator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ZeroSaltGenerator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  StandardPBEStringEncryptor encryptor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StandardPBEStringEncryptor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  encryptor.<span style="color: #006633;">decrypt</span><span style="color: #009900;">&#40;</span>cipherText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So why did I have to write the code in the first place?  Well, we need to get a 3rd party to implement it, and I can&#8217;t enforce dependencies upon them.  But the difference in the amount of code is shocking.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/11/08/jasypt-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postfix 2.5.1 TLS on FreeBSD</title>
		<link>http://happygiraffe.net/blog/2008/07/26/postfix-2-5-1-tls-on-freebsd/</link>
		<comments>http://happygiraffe.net/blog/2008/07/26/postfix-2-5-1-tls-on-freebsd/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 22:05:45 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2008/07/26/postfix-2-5-1-tls-on-freebsd/</guid>
		<description><![CDATA[This is one of those things that I have to put up there in case anybody else has the same obscure setup that I do&#8230; I run postfix on FreeBSD, using the ports system. This means I have a tendency &#8230; <a href="http://happygiraffe.net/blog/2008/07/26/postfix-2-5-1-tls-on-freebsd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is one of those things that I <em>have</em> to put up there in case anybody else has the same obscure setup that I do&#8230;</p>
<p>I run <a href="http://www.postfix.org/">postfix</a> on <a href="http://www.freebsd.org/">FreeBSD</a>, using the <a href="http://www.freebsd.org/ports/">ports system</a>.  This means I have a tendency to just use <a href="http://wiki.freebsd.org/portupgrade">portupgrade</a> to upgrade to the latest version of anything I happen to have installed.  Normally, this works just fine.  I usually check the output to see if any warnings about upgrading pop out and that&#8217;s about it.  Slightly seat-of-the-pants, I know.</p>
<p>Anyway, I recently upgraded to postfix 2.5.1 and started seeing these messages in the logs.</p>
<blockquote>
<p>Jul 26 21:29:44 gimli postfix/tlsmgr[7789]: fatal: tls_prng_exch_open: cannot open <span class="caps">PRNG</span> exchange file /var/lib/postfix/prng_exch: Permission denied</p>
</blockquote>
<p>tlsmgr is the bit of postfix that handles <a href="http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol"><span class="caps">SMTP</span></a> over <a href="http://en.wikipedia.org/wiki/Transport_Layer_Security"><span class="caps">SSL</span></a>.</p>
<p>The first port of call is to look through the postfix release notes.  This seemed relevant.</p>
<blockquote>
<p>[Incompat 20071206] The tlsmgr(8) and verify(8) servers no longer use root privileges when opening the address_verify_map, *_tls_session_cache_database, and tls_random_exchange_name cache files.  This avoids a potential security loophole where the ownership of a file (or directory) does not match the trust level of the content of that file (or directory).</p>
</blockquote>
<p>So, what&#8217;s the problem?</p>
<pre>
  % sudo -u postfix ls -l /var/lib/postfix
  Password:
  ls: /var/lib/postfix: Permission denied
  % sudo -u postfix ls -l /var/lib
  total 0
  ls: lib: Permission denied
  % sudo -u postfix ls -ld /var/lib
  drwxr-x---  5 root  wheel  512 26 Jul 08:14 /var/lib
</pre>
<p>So, it&#8217;s basically a permissions problem.  Postfix can&#8217;t see the directory it&#8217;s trying to use.  Previously it wasn&#8217;t a problem, as postfix was doing things as root, and root sidesteps permissions checks.</p>
<p>What to do?  The simplest is to change the permissions.  But I don&#8217;t <em>particularly</em> like doing that on systems directories, as they may well get reset in the future (e.g. nightly runs of <a href="http://www.freebsd.org/cgi/man.cgi?query=mtree&#38;sektion=8">mtree</a>).   So the simplest option is probably to reconfigure postfix to use a different directory.  One that it actually has permission to access, like <code>/var/db/postfix</code>.</p>
<p>Annoyingly, when I look at the port to understand this problem (<a href="http://www.FreeBSD.org/cgi/query-pr.cgi?pr=121236">PR#121236</a>), it was fixed in April.  I wonder why I didn&#8217;t get the fix?</p>
<p>As it turns out a reinstall of postfix (<code>portupgrade -f postfix-2.5.1_2,1</code>) completely fixes the problem, and the directory it uses is now <code>/var/db/postfix</code> by default.  I wonder what caused it to go wrong in the first place though?</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/07/26/postfix-2-5-1-tls-on-freebsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jasypt</title>
		<link>http://happygiraffe.net/blog/2008/07/22/jasypt/</link>
		<comments>http://happygiraffe.net/blog/2008/07/22/jasypt/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 15:30:40 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2008/07/22/jasypt/</guid>
		<description><![CDATA[One more little library that I&#8217;ve come to love: jasypt. It&#8217;s a simplified veneer over the top of the gargantuan java security apparatus. All I wanted to do was encrypt a String before putting it in a Cookie. BasicTextEncryptor encryptor &#8230; <a href="http://happygiraffe.net/blog/2008/07/22/jasypt/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One more little library that I&#8217;ve come to love: <a href="http://www.jasypt.org/">jasypt</a>.  It&#8217;s a simplified veneer over the top of the gargantuan <a href="http://java.sun.com/j2se/1.5.0/docs/guide/security/index.html">java security apparatus</a>.  All I wanted to do was encrypt a <code>String</code> before putting it in a <code>Cookie</code>.</p>
<pre>
  BasicTextEncryptor encryptor = new BasicTextEncryptor();
  encryptor.setPassword(key);
  String cipherText = encryptor.encrypt(clearText);
</pre>
<p>It nicely base64 encodes the result, which is ideal for <code>Cookie</code> stuffing.</p>
<p>The reverse operation is just as simple.</p>
<pre>
  BasicTextEncryptor encryptor = new BasicTextEncryptor();
  encryptor.setPassword(key);
  String recoveredText = encryptor.decrypt(cipherText);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/07/22/jasypt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross Site Scripting</title>
		<link>http://happygiraffe.net/blog/2007/04/09/cross-site-scripting/</link>
		<comments>http://happygiraffe.net/blog/2007/04/09/cross-site-scripting/#comments</comments>
		<pubDate>Mon, 09 Apr 2007 20:42:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2007/04/09/cross-site-scripting/</guid>
		<description><![CDATA[I&#8217;ve just been listening to Security Now about Cross-Site Scripting. It makes my blood boil. No, not all the ads and endless, aimless waffling. The talk about Cross-Site Scripting (aka XSS) being a problem because code and data can be &#8230; <a href="http://happygiraffe.net/blog/2007/04/09/cross-site-scripting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just been listening to <a href="http://www.twit.tv/sn86">Security Now</a> about <a href="http://en.wikipedia.org/wiki/Cross_site_scripting">Cross-Site Scripting</a>.  It makes my blood boil.  No, not all the ads and endless, aimless waffling.  The talk about Cross-Site Scripting (aka <span class="caps">XSS</span>) being a problem because code and data can be intermingled in the page.</p>
<p>No, it&#8217;s not.</p>
<p><span class="caps">XSS</span> is a problem because we have dumb programmers using even dumber tools<sup><a href="#fn1">1</a></sup>.</p>
<p>I&#8217;ve railed <a href="http://happygiraffe.net/blog/archives/2005/11/26/the-wrong-defaults">before</a> about the fact that if you&#8217;re outputting <span class="caps">HTML</span>, then your tool should do <span class="caps">HTML</span> escaping for you <em>by default</em>.</p>
<p>It&#8217;s kind of understandable in systems like <a href="http://www.template-toolkit.org/">Template Toolkit</a>, which are not specifically aimed at the web, but it&#8217;s completely inexcusable in <span class="caps">PHP</span>.  It&#8217;s designed to create web pages.  You&#8217;d think it&#8217;d be able to do it safely and easily.  No chance.</p>
<p>But lest you think I rant at <span class="caps">PHP</span>, most other systems I&#8217;ve seen (in Java, Perl and Ruby) make it nearly as hard to do correctly.  Let me rephrase:</p>
<blockquote>
<p> If you have to think about where to apply escaping, then your tool is letting you down.</p>
</blockquote>
<p>This isn&#8217;t to say <span class="caps">XSS</span> is the only problem.  There are plenty of other problems to be aware of.  <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery"><span class="caps">CSRF</span></a> appears to be garnering lots of attention these days.</p>
<p>One really useful link did come out of the Security Now show: <a href="http://www.owasp.org/"><span class="caps">OWASP</span></a> (Open Web Application Security Project).  It&#8217;s really worth checking out the <a href="http://www.owasp.org/index.php/OWASP_Guide_Project"><span class="caps">OWASP</span> Guide</a> in order to educate yourself about security on the web.</p>
<p id="fn1"><sup>1</sup>  Before you start to feel offended about being called a &#8220;dumb programmer&#8221;, I most certainly include myself in this category too.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2007/04/09/cross-site-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mod_security now switched off</title>
		<link>http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/</link>
		<comments>http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/#comments</comments>
		<pubDate>Sat, 02 Dec 2006 17:42:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/12/02/mod_security-now-switched-off/</guid>
		<description><![CDATA[Last night, I spent a long while trying to get mod_security working on this web server. Installation was simple, thanks to the FreeBSD ports system. Configuration was another matter entirely. Not having much experience of web application firewalls, I opted &#8230; <a href="http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last night, I spent a long while trying to get <a href="http://www.modsecurity.org/">mod_security</a> working on this web server.  Installation was simple, thanks to the FreeBSD ports system.  Configuration was another matter entirely.</p>
<p>Not having much experience of web application firewalls, I opted for the <a href="http://www.modsecurity.org/projects/rules/">ModSecurity Core Rules</a> to give me a head start.  These are essentially some pre-provided Apache configs that you can include into your existing config files.  It seems like a good idea, although some of the rules are questionable&#8212;I don&#8217;t really think that &#8220;googlebot visited&#8221; is a security event.</p>
<p>After configuring minor details like the audit log file, I deployed it.  Hmmm, front page still comes up, so let&#8217;s commit the configs to subversion.  <strong>Booom</strong>.</p>
<p>It turns out that the Core Rules don&#8217;t interact well with subversion in a number of minor, but irritating ways.  For example, they expect every request to come with an Accept header.  And only certain Content-Types can be submitted to the web server.  It&#8217;s all minor stuff, and relatively easy to work out how to fix.  This gave me a good feel for what&#8217;s involved in properly customizing mod_security.</p>
<p>This afternoon, I came back and inspected the logs.  There are nearly 400 events from mod_security.  Quite a lot of these were people trying to spam my <a href="http://happygiraffe.net/trac">trac instance</a> (which I&#8217;ve now finally gotten under control) and blog.  Importantly however, I noticed that it had blocked a legitimate user of an <span class="caps">RSS</span> feed.</p>
<p>At this point, I realised the problem.  mod_security needs a lot of work to set up and maintain.  You customize it towards a specific purpose&#8212;your application.  But I&#8217;m running lots of applications.  So it becomes harder and harder to customize correctly (particularly as I&#8217;m not running everything on it&#8217;s own virtualhost), because a rule that&#8217;s correct for subversion might well not be correct for trac.  Or more to the point, it&#8217;s going to take me a very long time to get it configured correctly.  So I&#8217;ve switched off mod_security for now.</p>
<p>Don&#8217;t take this as a slur on mod_security.  It&#8217;s a useful tool, and I will be using it again.  But it&#8217;s far easier to configure when you&#8217;re covering a single application running inside that Apache.  And you&#8217;ll still need to invest a good chunk of time to get it set up correctly (a very iterative process).</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/12/02/mod_security-now-switched-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System Keychain</title>
		<link>http://happygiraffe.net/blog/2006/08/23/system-keychain/</link>
		<comments>http://happygiraffe.net/blog/2006/08/23/system-keychain/#comments</comments>
		<pubDate>Wed, 23 Aug 2006 07:27:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/08/23/system-keychain/</guid>
		<description><![CDATA[This morning I was trying to add a new machine to my wireless network. Unfortunately, I&#8217;d forgotten the password&#8230; To the Keychain Access batcave! Unfortunately, the &#8220;Airport network password&#8221; is stored in the system keychain, instead of my login keychain. &#8230; <a href="http://happygiraffe.net/blog/2006/08/23/system-keychain/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This morning I was trying to add a new machine to my wireless network.  Unfortunately, I&#8217;d forgotten the password&#8230;  To the <a href="http://en.wikipedia.org/wiki/Keychain_Access">Keychain Access</a> batcave!</p>
<p>Unfortunately, the &#8220;Airport network password&#8221; is stored in the system keychain, instead of my login keychain.  Whilst I can unlock the system keychain, when I ask it to show me the password for my wireless network, it prompts for a password.  Not my password, as it happens.  Oh no.  System keychain is protected by a 48 random bytes stored in <code>/var/db/SystemKey</code>. It&#8217;s created by the <code>systemkeychain</code> utility the first time your mac is booted. More to the point, there&#8217;s absolutely no way I can type those bytes.</p>
<p>So, let&#8217;s be cunning I thought.  I dropped down to the command line and ran:</p>
<pre>
  % sudo cat /var/db/SystekMey | pbcopy
</pre>
<p>Then went back to keychain access only to discover that you can&#8217;t paste passwords in <span class="caps">OS X</span>.</p>
<p>A bit more googling turned up the <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/security.1.html">security</a> command.  In particular, the <code>dump-keychain</code> command.  Finally, running this spat out the password I was after:</p>
<pre>
  % security dump-keychain -d ~/Library/Keychains/login.keychain
</pre>
<p>At this point, I found out that it was the password for my <em>old</em> wireless network, which I&#8217;d just stopped using.  A closer inspection of my login keychain revealed another &#8220;AirPort network password&#8221; which just happened to be for the <em>new</em> network.  Ah well, at least it surrendered itself willingly.</p>
<p>From googling, it appears that <a href="http://www.macfixitforums.com/showflat.php?Cat=&#38;Board=Forum35&#38;Number=773270&#38;page=0&#38;view=collapsed&#38;sb=5&#38;o=31&#38;fpart=1">many</a> <a href="http://scotfl.ca/2005/12/01/lost-system-keychain-password-fix/">other</a> <a href="http://animoller.com/article/166/system-keychain-error-message">people</a> have been unable to recover stuff in their system keychain.  So this is good stuff to know.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/08/23/system-keychain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Security Hole</title>
		<link>http://happygiraffe.net/blog/2006/08/10/rails-security-hole/</link>
		<comments>http://happygiraffe.net/blog/2006/08/10/rails-security-hole/#comments</comments>
		<pubDate>Thu, 10 Aug 2006 19:29:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[svk]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/08/10/rails-security-hole/</guid>
		<description><![CDATA[Working round the Rails showstopper. (pdcawley)++ (svk)++ I now have the fixed version of typo (soon to be 4.0.2), around an hour after it was committed. As to the whole &#8220;full disclosure&#8221; thing by the rails team? They handled it &#8230; <a href="http://happygiraffe.net/blog/2006/08/10/rails-security-hole/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.bofh.org.uk/articles/2006/08/10/working-round-the-rails-showstopper">Working round the Rails showstopper</a>.</p>
<ul>
<li>(pdcawley)++</li>
<li>(svk)++</li>
</ul>
<p>I now have the fixed version of typo (soon to be 4.0.2), around an hour after it was committed.</p>
<p>As to the whole &#8220;full disclosure&#8221; thing by the rails team?  They handled it pretty badly.  As somebody else <a href="http://blog.evanweaver.com/articles/2006/08/10/explanation-of-the-rails-security-vulnerability-in-1-1-4-others">commented</a>, it <a href="http://www.openssh.com/txt/preauth.adv">didn&#8217;t work</a> for OpenBSD a while back and if anybody could do that, OpenBSD could.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/08/10/rails-security-hole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails gets sane</title>
		<link>http://happygiraffe.net/blog/2006/03/16/rails-gets-sane/</link>
		<comments>http://happygiraffe.net/blog/2006/03/16/rails-gets-sane/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 09:06:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/03/16/rails-gets-sane/</guid>
		<description><![CDATA[Some time ago, I wrote about The Wrong Defaults, explaining how nearly all templating systems for the web default to &#8220;insecure&#8221;. Well, it looks like some rails people are paying attention: Auto sanitized templates with Erubis]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I wrote about <a href="http://happygiraffe.net/blog/archives/2005/11/26/the-wrong-defaults">The Wrong Defaults</a>, explaining how nearly all templating systems for the web default to &#8220;insecure&#8221;.</p>
<p>Well, it looks like some rails people are paying attention: <a href="http://weblog.rubyonrails.com/articles/2006/03/16/auto-sanitized-templates-with-erubis">Auto sanitized templates with Erubis</a></p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/03/16/rails-gets-sane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

