<?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>David Verhasselt</title>
	<atom:link href="http://www.davidverhasselt.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidverhasselt.com</link>
	<description>Web Application gun for hire</description>
	<lastBuildDate>Sun, 13 May 2012 10:25:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to: Migrate passwords from legacy systems to Devise</title>
		<link>http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise/</link>
		<comments>http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise/#comments</comments>
		<pubDate>Sun, 13 May 2012 10:24:24 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.davidverhasselt.com/?p=430</guid>
		<description><![CDATA[When you&#8217;re migrating from a custom authentication solution to Devise, it&#8217;s highly likely your users&#8217; passwords are hashed or stored differently from how Devise does it. If the legacy system has a sane, secure solution then you can implement a custom &#8230; <a href="http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re migrating from a custom authentication solution to Devise, it&#8217;s highly likely your users&#8217; passwords are hashed or stored differently from how Devise does it.</p>
<p>If the legacy system has a sane, secure solution then you can <a title="How To: Create a custom encryptor" href="https://github.com/plataformatec/devise/wiki/How-To:-Create-a-custom-encryptor">implement a custom encryptor</a> for Devise. However if that&#8217;s not the case or if you want to migrate to the Devise default way-of-life following convention over configuration and reducing maintenance headaches in the future, you should convert the passwords so that Devise can use them.</p>
<p>Since hopefully you stored hashes of your user&#8217;s passwords instead of encrypted or plaintext, the only moment you can retrieve the plaintext password for rehashing is when the user tries to log in.  At that point we&#8217;ll convert it to Devise. This way when a user logs in his legacy password will be automatically converted to the new system.</p>
<p>First, add the <strong>legacy_password</strong> boolean attribute to User. This is to mark the passwords that have already been converted. Make sure to set it to true for the existing (legacy) records.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rails g migration AddLegacyPasswordToUser legacy_password:boolean
      invoke  active_record
      create    db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20120508083355</span>_add_legacy_password_to_users.rb
$ rake db:migrate</pre></div></div>

<p>Devise creates the method User#<a href="https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb#L40">valid_password?</a> to check the password. Let&#8217;s override it and add our legacy password check or fall through to the default <em>valid_password</em>? if the password was already converted.  This code assumes the old password is stored in the same field as the converted password — <em>encrypted_password</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
&nbsp;
...
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> valid_password?<span style="color:#006600; font-weight:bold;">&#40;</span>password<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">legacy_password</span>?
      <span style="color:#008000; font-style:italic;"># Use Devise's secure_compare to avoid timing attacks</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> Devise.<span style="color:#9900CC;">secure_compare</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">encrypted_password</span>, User.<span style="color:#9900CC;">legacy_password</span><span style="color:#006600; font-weight:bold;">&#40;</span>password<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
        <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">password</span> = password
        <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">password_confirmation</span> = password
        <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">legacy_password</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
        <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">save</span>!
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span>password<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Put your legacy password hashing method here</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">legacy_password</span><span style="color:#006600; font-weight:bold;">&#40;</span>password<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#6666ff; font-weight:bold;">Digest::MD5</span>.<span style="color:#9900CC;">hexdigest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{password}-salty-herring&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Supporting two different systems like this could soon become a maintenance nightmare After a couple of months, when the most active users have logged in at least once and converted their passwords, you can easily remove the extra code. Legacy users will be forced to reset their password since it won&#8217;t match anymore. Using the <strong>legacy_user</strong> attribute you could send them a targeted mail or alert them of the fact that they won&#8217;t be able to log in anymore with their old password.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Distributed Mutex and Semaphore using Redis</title>
		<link>http://www.davidverhasselt.com/2011/08/06/a-distributed-mutex-and-semaphore-using-redis/</link>
		<comments>http://www.davidverhasselt.com/2011/08/06/a-distributed-mutex-and-semaphore-using-redis/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 11:26:21 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Code Poetry]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.davidverhasselt.com/?p=419</guid>
		<description><![CDATA[Redis has some really neat atomic multi-operation commands that can be used to create a distributed mutex. Check out the documentation for the SETNX command for an example. This example is based on polling and unfair: waiting processes are not &#8230; <a href="http://www.davidverhasselt.com/2011/08/06/a-distributed-mutex-and-semaphore-using-redis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Redis has some really neat atomic multi-operation commands that can be used to create a distributed <a title="Wikipedia on Mutex" href="http://en.wikipedia.org/wiki/Mutual_exclusion">mutex</a>. Check out the <a title="SETNX documentation" href="http://redis.io/commands/setnx">documentation for the SETNX command</a> for an example.</p>
<p>This example is based on polling and unfair: waiting processes are not guaranteed to be served on a first-come, first-served basis.</p>
<h2>redis-semaphore</h2>
<p>Using the pretty cool <a title="BLPOP" href="http://redis.io/commands/blpop">BLPOP command</a> I&#8217;ve created the simple <a title="redis-semaphore on Github" href="https://github.com/dv/redis-semaphore">redis-semaphore gem</a> which implements a blocking and fair semaphore and mutex. Here&#8217;s some pseudocode to explain how it works:</p>
<pre><code>if GETSET(my_mutex_start, 1) != 1
  LPUSH(my_mutex, token)

BLPOP(my_mutex)
# Work here
work()
LPUSH(my_mutex, token)
</code></pre>
<p>The first two lines make sure the mutex is initialized only once. Using the atomic <a title="GETSET command" href="http://redis.io/commands/getset">GETSET operation</a> we set the key <strong>my_mutex_start</strong> to 1, and check to see if it already was 1 before we set it. If it was then another process already initialized the mutex (or is busy doing so). If it wasn&#8217;t, it&#8217;s up to us to initialize it: we push an element &#8220;token&#8221; to the <strong>my_mutex</strong> list.</p>
<p>This token is the <em>key</em> to the mutex: the process that removes the token from the list has locked the mutex. If the token is back on the list, the mutex is unlocked and another process can claim it and start working. This is accomplished in the next three lines.</p>
<p>BLPOP tries to pop the token off the <strong>my_mutex</strong> list. If the list is empty, it will block until another process pushes the token on it. Redis puts multiple BLPOP&#8217;s in a FIFO queue, so whoever calls BLPOP first, will be the first to actually get the token once it arrives.</p>
<p>Once the BLPOP returns, it means we have the token so we can do some work. Afterwards we push the token back on the list, unlocking the mutex.</p>
<p>Creating a <a title="Semaphore (Wikipedia)" href="http://en.wikipedia.org/wiki/Semaphore_(programming)">semaphore</a> instead of a mutex is as simple as pushing multiple tokens on the list during initialization. If you push on five then five processes will be able to lock the semaphore at a time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2011/08/06/a-distributed-mutex-and-semaphore-using-redis/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>5 Ways to set Attributes in ActiveRecord</title>
		<link>http://www.davidverhasselt.com/2011/06/28/5-ways-to-set-attributes-in-activerecord/</link>
		<comments>http://www.davidverhasselt.com/2011/06/28/5-ways-to-set-attributes-in-activerecord/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 13:10:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=362</guid>
		<description><![CDATA[Rails 3 allows the developer to change ActiveRecord attributes in various ways. I describe five methods, each with its own unique side-effects. Includes handy cheat sheet. <a href="http://www.davidverhasselt.com/2011/06/28/5-ways-to-set-attributes-in-activerecord/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Rails 3 allows the developer to change ActiveRecord attributes in various ways. Each one does it slightly differently with sometimes unique side-effects. It&#8217;s important you understand which method to use, so here&#8217;s a short list (<em>and a neat cheat table at the end!</em>)</p>
<h2>user.name = &#8220;Rob&#8221;</h2>
<p>This regular assignment is the most common and easiest to use. It is the default write accessor generated by Rails. The <strong>name</strong> attribute will be marked as dirty and the change will not be sent to the database yet.</p>
<p>You can undo the change by calling <strong>reload!</strong> or save the change to the database by calling <strong>save</strong>.</p>
<h2>user.write_attribute(:name, &#8220;Rob&#8221;)</h2>
<p>This is the method that is called by the default accessor above. A synonym for this function is <strong>user[:name] = &#8220;Rob&#8221;</strong>. It also has a <strong>read_attribute</strong> counterpart.</p>
<p>Just like above, this method does not yet change the attribute in the database. Use this method anywhere you need to bypass the default write accessor above, for example when you want to write a custom <strong>attribute=</strong> writer.</p>
<h2>user.update_attribute(:name, &#8220;Rob&#8221;)</h2>
<p>This method will change the attribute in the model and pass it straight to the database, without running any validations.</p>
<p>Two gotchas:</p>
<ul>
<li>Any <em>other</em> changed attributes are also saved to the database.</li>
<li>Validations are skipped so you could end up with invalid data.</li>
</ul>
<p><span style="font-size: 16px; font-family: Georgia, 'Bitstream Charter', serif; line-height: 24px;">Because of that last quirk it&#8217;s a good practice to use <strong>update_attributes</strong> instead.</span></p>
<h2>user.attributes = {:name =&gt; &#8220;Rob&#8221;}</h2>
<p>This method will set all the attributes you pass it, except those who are protected from mass assignment if you&#8217;re using <strong>attr_protected</strong> or <strong>attr_accessible</strong>. The changes are not saved to the database.</p>
<p>You can override the mass assignment protection by passing false:</p>
<pre>user.send(:attributes=, {:name =&gt; "Rob"}, false)</pre>
<p><span style="color: #000000; font-size: 23px; line-height: 35px;">user.update_attributes(:name =&gt; &#8220;Rob&#8221;)</span></p>
<p>This method changes the attributes of the model, checks the validations, and updates the record in the database if it validates. Since it uses the above <strong>attributes=</strong> method, attributes protected from mass assignment are not changed.</p>
<p>Note that just like <strong>update_attribute</strong> this method also saves other changed attributes to the database.</p>
<h2>Handy Cheat Sheet Table</h2>
<table>
<tbody>
<tr>
<th>Method</th>
<th>Uses Default Accessor</th>
<th>Mass Assignment Protection</th>
<th>Saved to Database</th>
<th>Validations</th>
</tr>
<tr>
<td><a href="http://apidock.com/rails/ActiveRecord/AttributeMethods/Write/attribute%3D">attribute=</a></td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td><span style="color: #c0c0c0;">n/a</span></td>
</tr>
<tr>
<td><a href="http://apidock.com/rails/ActiveRecord/AttributeMethods/Write/write_attribute">write_attribute</a></td>
<td>No</td>
<td>No</td>
<td>No</td>
<td><span style="color: #c0c0c0;">n/a</span></td>
</tr>
<tr>
<td><a href="http://apidock.com/rails/ActiveRecord/Persistence/update_attribute">update_attribute</a></td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td><a href="http://apidock.com/rails/ActiveRecord/Base/attributes%3D">attributes=</a></td>
<td>Yes</td>
<td>Yes<sup><a href="http://www.davidverhasselt.com/2011/06/28/5-ways-to-set-attributes-in-activerecord/#footnote_0_362" id="identifier_0_362" class="footnote-link footnote-identifier-link" title="Mass Assignment Protection for attributes= is overridable.">1</a></sup></td>
<td>No</td>
<td><span style="color: #c0c0c0;">n/a</span></td>
</tr>
<tr>
<td><a href="http://apidock.com/rails/v3.0.0/ActiveRecord/Persistence/update_attributes">update_attributes</a></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<p>If you want to understand more about these methods I suggest you check out their source code. Each time it&#8217;s only a couple of lines and it will really broaden your understanding of how Rails works!</p>
<ol class="footnotes"><li id="footnote_0_362" class="footnote">Mass Assignment Protection for attributes= is overridable.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2011/06/28/5-ways-to-set-attributes-in-activerecord/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git How-To: Remove Your Password from a Repository</title>
		<link>http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/</link>
		<comments>http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 22:58:50 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=277</guid>
		<description><![CDATA[When you&#8217;re making an app that uses credentials to access some service, in the early stages of development before any code to access a config-file is written, a username and password are occasionally hard-coded in the source. Since you use version &#8230; <a href="http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re making an app that uses credentials to access some service, in the early stages of development before any code to access a config-file is written, a username and password are occasionally hard-coded in the source.</p>
<p>Since you use version control like all good developers, it&#8217;s possible these hardcoded credentials get committed. This poses a grave security risk, especially if you want to open source the code including the repository.</p>
<p>Here&#8217;s how to remove a password from any file, in all revisions, in a git repository:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git</span> filter-branch <span style="color: #660033;">--tree-filter</span> <span style="color: #ff0000;">&quot;find . -type f -exec sed -i -e 's/originalpassword/newpassword/g' {} \;&quot;</span></pre></div></div>

<p>Just replace <strong>originalpassword</strong> with the word you want to replace, and <strong>newpassword</strong> with the word you want to replace it with<sup><a href="http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/#footnote_0_277" id="identifier_0_277" class="footnote-link footnote-identifier-link" title="Here&amp;#8217;s another handy one, deleting all the lines containing word.
678ce731f50186a34a78d73901d4cefa009
">1</a></sup>.</p>
<p>After you&#8217;re done, you can check if your password really isn&#8217;t in any of the files anymore by <em>grepping</em> every revision<sup><a href="http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/#footnote_1_277" id="identifier_1_277" class="footnote-link footnote-identifier-link" title="By OR-ing with true we make sure the command is run in any revision, because if it returns false (e.g. originalpassword isn&amp;#8217;t found in any of the files of a specific revision), git will think the filter failed and it won&amp;#8217;t check the other revisions. You&amp;#8217;ll notice if this happens since you&amp;#8217;ll get a &amp;#8220;tree filter failed&amp;#8221; error on the first nonmatching revision.">2</a></sup>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> filter-branch <span style="color: #660033;">--tree-filter</span> <span style="color: #ff0000;">&quot;grep -r originalpassword * || true&quot;</span></pre></div></div>

<p>If you&#8217;re positive the changes were done correctly, make sure to remove the automatically created backupfiles in refs/original/<sup><a href="http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/#footnote_2_277" id="identifier_2_277" class="footnote-link footnote-identifier-link" title="If you don&amp;#8217;t, sooner or later you&amp;#8217;ll get the following error message:
678ce731f50186a34a78d73901d4cefa011
">3</a></sup>.</p>
<p>Now enjoy a fine glass of wine, safe in the knowledge that your repository won&#8217;t reveal any of your secrets.</p>
<ol class="footnotes"><li id="footnote_0_277" class="footnote">Here&#8217;s another handy one, deleting all the <em>lines</em> containing <strong>word</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git</span> filter-branch <span style="color: #660033;">--tree-filter</span> <span style="color: #ff0000;">&quot;find . -type f -exec sed -i -e '/$*word/d' {} \;&quot;</span></pre></div></div>

<p></li><li id="footnote_1_277" class="footnote">By OR-ing with true we make sure the command is run in any revision, because if it returns false (e.g. originalpassword isn&#8217;t found in any of the files of a specific revision), git will think the filter failed and it won&#8217;t check the other revisions. You&#8217;ll notice if this happens since you&#8217;ll get a &#8220;tree filter failed&#8221; error on the first nonmatching revision.</li><li id="footnote_2_277" class="footnote">If you don&#8217;t, sooner or later you&#8217;ll get the following error message:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Cannot create a new backup.
A previous backup already exists <span style="color: #000000; font-weight: bold;">in</span> refs<span style="color: #000000; font-weight: bold;">/</span>original<span style="color: #000000; font-weight: bold;">/</span>
Force overwriting the backup with <span style="color: #660033;">-f</span></pre></div></div>

<p></li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2010/09/14/git-how-to-remove-your-password-from-a-repository/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>On the Redundancy of the Password Inputbox: eToro</title>
		<link>http://www.davidverhasselt.com/2010/07/17/on-the-redundancy-of-the-password-inputbox-etoro/</link>
		<comments>http://www.davidverhasselt.com/2010/07/17/on-the-redundancy-of-the-password-inputbox-etoro/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 22:33:43 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=335</guid>
		<description><![CDATA[As a case study relating to my previous post on password input-boxes, I present eToro, a social foreign exchange trading service. Here&#8217;s what you see if you want to sign up: As you can see, a standard sign-up screen. All &#8230; <a href="http://www.davidverhasselt.com/2010/07/17/on-the-redundancy-of-the-password-inputbox-etoro/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As a case study relating to my <a href="/2009/05/28/on-the-redundancy-of-the-password-inputbox/">previous post on password input-boxes</a>, I present <a href="http://www.etoro.com">eToro</a>, a social foreign exchange trading service. Here&#8217;s what you see if you want to sign up:<br />
<div id="attachment_336" class="wp-caption aligncenter" style="width: 500px"><img src="http://blog.crowdway.com/wp-content/uploads/2010/07/etorro_signup1.png" alt="Standard Sign Up Dialog" title="eToro Sign Up" width="490" height="458" class="size-full wp-image-336" /><p class="wp-caption-text">Standard Sign Up Dialog</p></div><br />
As you can see, a standard sign-up screen. All is well in the world, and look, they even did away with the confirmation boxes for password and e-mail. Innovative!</p>
<p>But maybe a password confirmation box would be useful for if you made a typo? Oh, not to worry! Right as you press the &#8220;Sign-Up&#8221; button, you get this security disaster:<br />
<div id="attachment_337" class="wp-caption aligncenter" style="width: 500px"><img src="http://blog.crowdway.com/wp-content/uploads/2010/07/etorro_signup2.png" alt=";Let&#039;s render the previous user effort totally void!" title="eToro Post Sign Up" width="490" height="401" class="size-full wp-image-337" /><p class="wp-caption-text">&#8220;Let's render the previous user effort totally void!&#8221;</p></div></p>
<p>Your password, which you previously painstakingly entered blind, is now completely visible, <em>right after you pressed Sign-Up</em>. This obviously makes the previous masked password-box totally useless. The negative usability experience caused by the password-box was for nothing.</p>
<p><em>Of course</em> they also send your password in an e-mail, just to make absolutely sure any bystander has seen your password, and if someone ever gets into your mail account, he or she also has access to your eToro account.</p>
<p>Here&#8217;s how to fix it, eToro:</p>
<ul>
<li>If you&#8217;re of the opinion that you should use a password inputbox, make sure the user&#8217;s password is never visible anywhere on your site. Any security you might have gained by masking the user&#8217;s password would be lost. <strong>Remember why password boxes were invented in the first place!</strong></li>
<li>Don&#8217;t send the user his password in an e-mail! If a bad person ever gains access to the user&#8217;s mail account, he also gains access to the user&#8217;s eToro account by searching for any mails containing the word &#8220;password&#8221;. Just make sure you have a &#8220;Password Recovery&#8221; feature which is both fast and secure to replace.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2010/07/17/on-the-redundancy-of-the-password-inputbox-etoro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expanding a leading tilde in C/C++</title>
		<link>http://www.davidverhasselt.com/2009/09/16/expanding-a-leading-tilde-in-cc/</link>
		<comments>http://www.davidverhasselt.com/2009/09/16/expanding-a-leading-tilde-in-cc/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 13:33:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Poetry]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[tilde]]></category>
		<category><![CDATA[userdir]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=289</guid>
		<description><![CDATA[If you&#8217;re writing an app that accepts a path to a filename as user-input or in config-files, you&#8217;ll have to be able to parse the famous leading tilde and expand it to the correct home directory of the correct user. &#8230; <a href="http://www.davidverhasselt.com/2009/09/16/expanding-a-leading-tilde-in-cc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re writing an app that accepts a path to a filename as user-input or in config-files, you&#8217;ll have to be able to parse the famous leading tilde and expand it to the correct home directory of the correct user. For example, if I enter <strong>&#8220;~/.vimrc&#8221;</strong> it needs to be expanded to the file in my userdir <strong>&#8220;/home/david/.vimrc&#8221;</strong> before you can do anything with it. You can use &#8220;word expand&#8221; or wordexp to accomplish this.</p>
<p>Here&#8217;s a sample application showing how:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;wordexp.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> argv<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	wordexp_t exp_result<span style="color: #008080;">;</span>
	wordexp<span style="color: #008000;">&#40;</span>arv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>exp_result, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span>exp_result.<span style="color: #007788;">we_wordv</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>That should pretty much tell you everything you need to know. Here are some of the results output by this app:</p>
<p><strong>~/.vimrc</strong> becomes <strong>/home/david/.vimrc</strong><br />
<strong>.vimrc</strong> becomes <strong>.vimrc</strong><br />
<strong>~.vimrc</strong> becomes <strong>~.vimrc</strong><br />
<strong>~blacky/.vimrc</strong> becomes <strong>/home/admin/blacky/.vimrc</strong>  (blacky&#8217;s homedir is /home/admin/blacky)</p>
<p>As you can see, it handles pretty much every situation correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2009/09/16/expanding-a-leading-tilde-in-cc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gmail Carbon Copy</title>
		<link>http://www.davidverhasselt.com/2009/08/26/gmail-carbon-copy/</link>
		<comments>http://www.davidverhasselt.com/2009/08/26/gmail-carbon-copy/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 12:38:04 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Poetry]]></category>
		<category><![CDATA[Gmailcc]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=293</guid>
		<description><![CDATA[Today I&#8217;d like to introduce Gmail Carbon Copy, an application I&#8217;ve coded during the last couple of months. The latest version is stable and works, so I&#8217;m deeming it fit for public consumption. Gmail Carbon Copy, or Gmailcc simply creates &#8230; <a href="http://www.davidverhasselt.com/2009/08/26/gmail-carbon-copy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;d like to introduce <strong><a href="http://gmailcc.crowdway.com">Gmail Carbon Copy</a></strong>, an application I&#8217;ve coded during the last couple of months. The latest version is stable and works, so I&#8217;m deeming it fit for public consumption.</p>
<p>Gmail Carbon Copy, or Gmailcc simply creates a back-up of your Gmail. It differs from <a href="http://www.gmail-backup.com/">existing</a> <a href="http://www.mattcutts.com/blog/backup-gmail-in-linux-with-getmail/">alternatives</a> because of two clever tricks: each mail is downloaded <em>only once</em> instead of once for every label while still saving the labels, and they&#8217;re stored in an actually usable, <em>sparse Maildir</em> format.</p>
<p>Gmail&#8217;s IMAP implementation is unique in that it maps labels to folders. The same mail will appear in different folders for every label attached to it. Regular IMAP clients like Thunderbird or getmail think each copy of the mail in a different folder is a new mail, and will download it again, even though it might just be a copy of a mail it downloaded earlier. Gmailcc detects &#8220;doubles&#8221; and will download each mail just once. Backups, especially the initial one, will finish much faster because of this and will take far less traffic.</p>
<p>Saving it in a usable Maildir format has the advantage that any regular mailserver like Courier can access your backup. It&#8217;s very practical: I&#8217;m using Gmailcc and Roundcube to access my mails on a webinterface if Gmail is down. It&#8217;s sparse because every mail is saved only once, while for every label a sizeless link is created instead of a true copy. This minimizes the space used to store the backup.</p>
<p>There are still some <a href="http://code.crowdway.com/projects/gmailcc/issues">issues</a> but it shouldn&#8217;t make your PC explode or kill your Gmail account. If you encounter bugs or would like to have features added, I encourage you to <a href="http://code.crowdway.com/account/register">sign up</a> and add a ticket.</p>
<p>Gmail Carbon Copy is open source (C++), licensed under the MIT license and works only on Linux at this time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2009/08/26/gmail-carbon-copy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Munin and Apache: Can&#8217;t locate object method</title>
		<link>http://www.davidverhasselt.com/2009/07/08/munin-and-apache-cant-locate-object-method/</link>
		<comments>http://www.davidverhasselt.com/2009/07/08/munin-and-apache-cant-locate-object-method/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 15:10:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sysadmin]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=254</guid>
		<description><![CDATA[If you&#8217;re using Munin to track statistics on your server and you&#8217;re trying to use any of the Apache plugins, you might have some trouble getting it working. If Munin won&#8217;t display any statistics on Apache, and the munin-node.log logfile &#8230; <a href="http://www.davidverhasselt.com/2009/07/08/munin-and-apache-cant-locate-object-method/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using <a href="http://munin.projects.linpro.no/">Munin</a> to track statistics on your server and you&#8217;re trying to use any of the Apache plugins, you might have some trouble getting it working. If Munin won&#8217;t display any statistics on Apache, and the munin-node.log logfile is filled with lines like these:</p>
<pre><code>Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_processes line 152.
2009/07/08-17:00:02 Plugin "apache_processes" exited with status 512. ----
Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_accesses line 130.
2009/07/08-17:00:03 Plugin "apache_accesses" exited with status 512. ----
Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_volume line 130.
2009/07/08-17:00:03 Plugin "apache_volume" exited with status 512. ----</code></pre>
<p>then the solution is to install the package <strong>libwww-perl</strong> which includes the required <em>LWP:UserAgent</em> package.</p>
<p>Make sure to restart munin-node afterwards:</p>
<pre><code>$ /etc/init.d/munin-node restart</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2009/07/08/munin-and-apache-cant-locate-object-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On the Redundancy of the Password Inputbox</title>
		<link>http://www.davidverhasselt.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/</link>
		<comments>http://www.davidverhasselt.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/#comments</comments>
		<pubDate>Thu, 28 May 2009 18:21:24 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=216</guid>
		<description><![CDATA[We all know and love the password inputbox. It hides all the characters you type with stars, and encrypts the contents stored in memory. It&#8217;s about the only constant in the potpourri of user registration pages. It&#8217;s the part no &#8230; <a href="http://www.davidverhasselt.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We all know and love the password inputbox. It hides all the characters you type with stars, and encrypts the contents stored in memory. It&#8217;s about the only constant in the potpourri of user registration pages. It&#8217;s the part no site ever gets wrong â€” use a password inputbox when asking the user for their password. But what function does it serve? It&#8217;s simple:</p>
<p><strong>To hide your password from bystanders</strong>, innocent or otherwise.</p>
<p>That&#8217;s the one and only reason why we obscure the characters with stars. That co-worker sitting next to you, or the coffee-lady casually walking by, if it weren&#8217;t for the trusty password field they could have spotted and accidentally memorized your password while you&#8217;re entering it. It&#8217;s a great solution to a very real problem.</p>
<div id="attachment_238" class="wp-caption alignright" style="width: 210px"><img class="size-full wp-image-238" title="Redundancy @ WordPress.com" src="http://blog.crowdway.com/wp-content/uploads/2009/05/password-screen-wordpresscom1.png" alt="Redundancy @ WordPress.com" width="200" height="180" /><p class="wp-caption-text">Redundancy at WordPress.com</p></div>
<p>All this is common knowledge, of course. So why am I repeating it? Because surprisingly, for most sites it&#8217;s redundant. All the websites out there that send your password by email, or show it when you&#8217;ve clicked the &#8220;activate account&#8221;-link are nullifying the sole reason of existence for the password field.</p>
<p>Since the user&#8217;s password is displayed on the screen in an e-mail, that coffee-lady can look at the password anyway. Worse: oft-times the user doesn&#8217;t know what&#8217;s coming when opening the mail or clicking the activation-link. He can&#8217;t pre-emptively check if anyone is in his vicinity before unknowingly revealing the password on his screen, which <em>is</em> an option when entering the password in a regular inputbox.</p>
<p>The conclusion is simple: if you think you can send the user his password by mail or show it in clear text on his profile, stop using the password inputbox. <strong>It won&#8217;t increase the level of security</strong>. By then, it only serves to annoy the user who has to enter his password blindly, twice even, possibly making an error along the way and having to try again. It&#8217;ll also tell the user the real degree of security you&#8217;re using, instead of fooling him with the asterisks.</p>
<p><span style="font-size: smaller">(The real conclusion is of course to never show the password in cleartext, anywhere)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hide Data in Bad Blocks</title>
		<link>http://www.davidverhasselt.com/2009/04/22/hide-data-in-bad-blocks/</link>
		<comments>http://www.davidverhasselt.com/2009/04/22/hide-data-in-bad-blocks/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 15:51:51 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Hide Data]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=81</guid>
		<description><![CDATA[This is part 3 in a series on how to hide your data. First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell thereâ€™s hidden data when looking at &#8230; <a href="http://www.davidverhasselt.com/2009/04/22/hide-data-in-bad-blocks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>This is part 3 in a <a href="/tag/hide-data/">series on how to hide your data</a>.</em></p>
<p><em>First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell thereâ€™s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. <a href="http://www.truecrypt.org/">TrueCrypt</a> is an excellent way to do this.</em></p>
<h3>Introduction</h3>
<p>When a sector on a disk gets damaged, it becomes unusable.Â  Modern disks have spare sectors that are used to replace these bad sectors, so they&#8217;re handled and fixed automatically. If you&#8217;re young enough, you might never have witnessed these bad sectors, because modern hardware handles them transparently.</p>
<p>When the disk runs out of spare sectors, or never had any in the first place (like 3.5&#8243; disks, or very old hard disks), the filesystem is the second line of defense. Inside the filesystem a list of known bad blocksâ€”<em>blocks on bad sectors</em>â€”is stored. The filesystem takes care not to use these blocks and just skips them.</p>
<p>We can&#8217;t force the disk to remap certain blocks to spare sectors, but we <em>can</em> tell the filesystem which blocks have (supposedly) gone bad. If the blocks aren&#8217;t really damaged, any data we put there will never be touched, because the filesystem thinks it&#8217;s garbage anyway. That, is exactly what we&#8217;re going to do.</p>
<h3>Practical</h3>
<p>To keep it simple and fast, we&#8217;ll hide a whole partition inside a burst of bad blocks. The partition we&#8217;ll create has to be small and reside somewhere in the middle of the disk. We can&#8217;t put the partition at the beginning or the end of the disk, because most likely the filesystem requires an intact header at the start and end of the partition.</p>
<p><img class="aligncenter size-full wp-image-182" title="Partition inside Bad Blocks" src="http://blog.crowdway.com/wp-content/uploads/2009/04/bad_blocks.png" alt="Partition inside Bad Blocks" width="490" height="280" /></p>
<p>The partition has to be small enough to be able to fit inside the non-secret partition while not arousing suspicion. Some operating systems mark bad blocks as used blocks, which means if we put a 100MB partition inside bad blocks, the &#8220;parent&#8221; filesystem will always have at least 100MB in use. This could arouse suspicion when there aren&#8217;t any files on it.</p>
<p>I&#8217;ll be using my trusty 256MB Compactflash card for this, which is excellent for illustratory purposes.</p>
<p>Here&#8217;s what sfdisk has to say about it:</p>
<pre><code>$ sudo sfdisk -l /dev/sde

Disk /dev/sde: 1009 cylinders, 9 heads, 56 sectors/track
Units = cylinders of 258048 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sde1          0       -       0          0    0  Empty
/dev/sde2          0       -       0          0    0  Empty
/dev/sde3          0       -       0          0    0  Empty
/dev/sde4          0       -       0          0    0  Empty
</code></pre>
<p>We can see the card is comprised of 1009 cylinders. I want to create a partition of about 20MB, which is about 82 cylinders on this disk (see the second line of <em>sfdisk -l</em>). Because we can&#8217;t create the partition at the start of the disk, let&#8217;s put it 214 cylinders in:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
214,82,6
EOF
</code></pre>
<p>Just like before, put FAT16 on it and transfer your secret data.</p>
<pre><code>$ sudo mkfs.vfat -F16 /dev/sde1
mkfs.vfat 2.11 (12 Mar 2005)
</code></pre>
<p>If you want, you can copy the current partition table to the back of the disk for easy restoring, just like in the <a href="/2009/04/20/hide-data-in-invisible-partitions/">previous article</a>.</p>
<p>Unmount it, and remove the partition:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
0,0,0
EOF
</code></pre>
<p>Now create the parent partition. This should at least encompass the whole secret partition. If you&#8217;ve copied the partition table to the back of the disk, make sure to leave at least the last cylinder free.</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
,,6
EOF
</code></pre>
<h3>Creating Bad Blocks</h3>
<p>We need to calculate what blocks our secret partition resides on so we can mark them as <em>bad</em>. We know it starts at cylinder 214 and is 82 cylinders in size. Since on this disk, a cylinder is 258048 bytes big, the secret partition starts at byte 55222272. Divide this by the size of one block, which is 1024 bytes, and we get block 53928. Do the same for the size of the partition, and we find that 82 cylinders equal 20664 blocks. Now we know our partition starts at block 53928 and ends at block 74592. We&#8217;ll use a margin of 10 blocks on each side just in case our calculations aren&#8217;t precise.</p>
<p>Since we&#8217;re putting a FAT16 filesystem on it, we need to tell <em>mkfs.vfat</em> what blocks have supposedly gone bad. This is done by using a <strong>bad blocks file</strong>, which is a text-file with the address of each bad block on a new line. Let&#8217;s create our bad blocks file:</p>
<pre><code>$ seq 53918 74602 > /tmp/badblocks
</code></pre>
<p>If you open /tmp/badblocks, you should see something like this:</p>
<pre><code>53918
53919
53920
53921
...
</code></pre>
<p>To create the filesystem, we pass the bad blocks file using the <strong>-l</strong> parameter:</p>
<pre><code>$ sudo mkfs.vfat -n "Camera" -l /tmp/badblocks /dev/sde1
mkdosfs 2.11 (12 Mar 2005)
20685 bad blocks
</code></pre>
<p>That&#8217;s it! You can now use your disk to your heart&#8217;s delight, nothing will touch your secret partition. One awesome way is to put the card in your camera and take some pictures with it. Your data will remain safe, and there&#8217;ll be nothing suspicious about a 4GB card &#8220;missing&#8221; some megabytes.</p>
<h3>Revert</h3>
<p>If you&#8217;ve smuggled your secret data across state borders, you&#8217;re ready to recover the secret partition. Just recreate the partition table to contain the secret partition:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
214,82,6
EOF
</code></pre>
<p>That&#8217;s it! You can even reuse the setup: by switching partition tables you&#8217;re effectively changing which partition is &#8220;active&#8221; on your card, and changing data in either partition won&#8217;t affect the other.</p>
<h4>Advantages</h4>
<ul>
<li>Pretty much <strong>undetectable</strong></li>
<li>Infinitely <strong>reusable</strong></li>
<li><strong>Bad blocks</strong> are less suspicious than unallocated space</li>
</ul>
<h4>Disadvantages</h4>
<ul>
<li>Quite <strong>complex</strong> to set up</li>
<li>Possibly suspicious <strong>size discrepancy</strong> in empty filesystems</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.davidverhasselt.com/2009/04/22/hide-data-in-bad-blocks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

