<?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>Daniel Hall&#039;s Website</title>
	<atom:link href="http://www.danielhall.me/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danielhall.me</link>
	<description>Because the Internet doesn&#039;t have enough opinions already</description>
	<lastBuildDate>Wed, 17 Feb 2010 11:19:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Fingerprint readers and PC security</title>
		<link>http://www.danielhall.me/2010/02/fingerprint-readers-and-pc-security/</link>
		<comments>http://www.danielhall.me/2010/02/fingerprint-readers-and-pc-security/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 11:16:34 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Biometrics]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=508</guid>
		<description><![CDATA[How fingerprint readers work
The user sees
<p>You register your fingerprint using the built in reader and it saves it as your password. Next time you go to login you choose your username, swipe your finger and the PC verifies it against the one you scanned last time. If it matches then the computer logs you in.</p>
What [...]]]></description>
			<content:encoded><![CDATA[<h1>How fingerprint readers work</h1>
<h3>The user sees</h3>
<p>You register your fingerprint using the built in reader and it saves it as your password. Next time you go to login you choose your username, swipe your finger and the PC verifies it against the one you scanned last time. If it matches then the computer logs you in.</p>
<h3>What actually happens</h3>
<ol>
<li>You open up the fingerprint reader application on your laptop, it adds hooks into the Windows login system (Credential Providers).</li>
<li>You scan in one or more fingers and register them to your account.</li>
<li>The application stores the fingerprints for later use, some will even <a href="http://www.pcworld.com/article/124978/researcher_hacks_microsoft_fingerprint_reader.html">store them unencrypted</a>.</li>
<li>When the user goes to login next time they select their username and scans a finger.</li>
<li>The fingerprint reader takes the scan and compares it to the previous scan</li>
<li>If the scan matches one of the stored scans then the user is authenticated</li>
</ol>
<h1>Why its not secure</h1>
<p>How often do you write down your password? If you do where would you leave it? Now think about your fingerprint. Where would you leave your fingerprint? In general people don&#8217;t constantly where gloves and end up leaving fingerprints all over the place, on glasses, door handles, keyboards, touch screens and mobiles. It is a little bit harder to copy a fingerprint but security by obscurity is not an excuse. So it can be argued that a password is more secure (in that its harder to obtain) than a fingerprint.</p>
<p>Most fingerprint authentications allow you to use either your fingerprint, or your password. This effectively doubles the possible attack vectors for trying to get into the system. A malicious attacker can now either use a dictionary attack against your password, a fingerprint based attack against the fingerprint reader, or look for holes in either system.</p>
<h1>Why it may actually endanger you</h1>
<p>Do you know how the fingerprint reader is storing your fingerprints? Is it storing them as bitmaps, as a collection of swirls and whorls or as a md5 hash or some key identifiable features? If you can&#8217;t answer that question with 100% certainty then you should be concerned. If someone managed to hack your machine and retrieve bitmaps of your fingerprints then they could use them to open any other fingerprint locks you have, or implicate you in a crime.</p>
<p>Finally if someone is determined enough to break a law to hack your computer they could simply cut off your fingers to gain access to your PC. Of course if the fingerprint sensor has a warmth sensor they might need to microwave them first. I would hope though that you keep something that sensitive or valuable under all sorts on encryption and armed guards.</p>
<p>Don&#8217;t rely on fingerprint readers for added security, that is quite simply not the case. Fingerprint readers are primarily for convenience, and they could put your security and your wellbeing in danger.</p>
<p><strong>Random Thought:</strong> What is this obsession with altering perfectly fine machines to remove an component that never bothers anyone? Dyson has the bladeless fan, and recently we&#8217;re seeing the spokeless bike. Have you ever looked at a fan and said: &#8220;Those blades really make that fan so annoying!&#8221;?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2010/02/fingerprint-readers-and-pc-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a Daemon in C</title>
		<link>http://www.danielhall.me/2010/01/writing-a-daemon-in-c/</link>
		<comments>http://www.danielhall.me/2010/01/writing-a-daemon-in-c/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 12:14:35 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Daemon]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=466</guid>
		<description><![CDATA[What is a Daemon?
<p>A daemon is a program that runs in the background. A daemon will usually be started at system startup and end at system shutdown. The exceptions to this rule are programs like the Bluetooth SDP daemon, which is activated when a new Bluetooth HCI is found,, and ends when it is removed. [...]]]></description>
			<content:encoded><![CDATA[<h2>What is a Daemon?</h2>
<p>A daemon is a program that runs in the background. A daemon will usually be started at system startup and end at system shutdown. The exceptions to this rule are programs like the Bluetooth SDP daemon, which is activated when a new Bluetooth HCI is found,, and ends when it is removed. Daemons run transparently and do not normally interact with the user directly.</p>
<p>Daemons start as ordinary processes but they eventually &#8216;fork and die&#8217; to start running in the background. Some daemons do only the &#8216;fork and die&#8217; step but ignore other important steps. Here is a list of what a daemon should do:</p>
<ol>
<li>Fork to create a child, and exit the parent process.</li>
<li>Change the umask so that we aren&#8217;t relying on the one set in the parent.</li>
<li>Open logs to write to in the case of an error.</li>
<li>Create a new session id and detach from the current session.</li>
<li>Change the working directory to somewhere that won&#8217;t get unmounted.</li>
<li>Close STDIN, STDOUT and STDERR.</li>
</ol>
<p>These steps ensure that our association with the calling environment is destroyed and our daemon is now free to run as a completely separate process.</p>
<p>Lastly before writing the daemon you should make sure the code is written securely and in a way that fails gracefully. If your daemon crashes it will not be able to prompt the user about what action to take. The user may not even notice until it is too late.</p>
<h2>Forking a child process</h2>
<p>In Unix fork() is the only system call with two return values. When you call fork a child process is created which is a near copy of its parent (some things will be different in the child eg. process id). The fork command then returns a 0 in the child and the childs process id in the parent, on failure a -1 is sent to the parent. Generally a program will then check whether it is the child or parent by these return values (just like in movies when a cloned character will check to see if he has a belly button and hence is the original). Here is a snippet of code to do this:</p>
<pre class="brush: cpp;">
pid_t pid;

/* Clone ourselves to make a child */
pid = fork(); 

/* If the pid is less than zero,
   something went wrong when forking */
if (pid &lt; 0) {
    exit(EXIT_FAILURE);
}

/* If the pid we got back was greater
   than zero, then the clone was
   successful and we are the parent. */
if (pid &gt; 0) {
    exit(EXIT_SUCCESS);
}

/* If execution reaches this point we are the child */
</pre>
<h2>Changing the umask</h2>
<p>Because we are a clone of our parent we&#8217;ve inherited its umask. This means the child doesn&#8217;t know what permissions files will end up with when it tries to create them. We do this by simply calling umask like this:</p>
<pre class="brush: cpp;">
/* Set the umask to zero */
umask(0);
</pre>
<h2>Open logs to write to</h2>
<p>This part can be done in several different ways. You could open text files, log to a database or use syslog. The method I&#8217;m going to demonstrate here is to log using syslog. Syslog sends your log messages to a system wide logger, where they can be configured to be written to a file, send to a network server or filtered away entirely.</p>
<pre class="brush: cpp;">
/* Open a connection to the syslog server */
openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER); 

/* Sends a message to the syslog daemon */
syslog(LOG_NOTICE, &quot;Successfully started daemon\n&quot;); 

/* this is optional and only needs to be done when your daemon exits */
closelog();
</pre>
<h2>Create a new session id</h2>
<p>Each process on a Unix system is a member of a process group (or session). The id of each group is the process id of its owner. When we forked from our parent earlier we will have inherited its process group, and our process group leader will still be its parent process. We want to create our own process group and become our own process leader otherwise we will look like an orphan. We can do this easily as follows:</p>
<pre class="brush: cpp;">
pid_t sid;

/* Try to create our own process group */
sid = setsid();
if (sid &lt; 0) {
    syslog(LOG_ERR, &quot;Could not create process group\n&quot;);
    exit(EXIT_FAILURE);
}
</pre>
<h2>Changing the working directory</h2>
<p>At the moment we have the working directory we inherited from our parent. This working directory could be a network mount, a removable drive or somewhere the administrator may want to unmount at some point. To unmount any of these the system will have to kill any processes still using them, which would be unfortunate for our daemon. For this reason we set our working directory to the root directory, which we are sure will always exist and can&#8217;t be unmounted.</p>
<pre class="brush: cpp;">
/* Change the current working directory */
if ((chdir(&quot;/&quot;)) &lt; 0) {
    syslog(LOG_ERR, &quot;Could not change working directory to /\n&quot;);
    exit(EXIT_FAILURE);
}
</pre>
<h2>Closing the standard file descriptors</h2>
<p>A daemon doesn&#8217;t interact with the user directly it has no use for STDIN, STDOUT and STDERR and we really have no idea where these are connected or where anything we write to them will end up. As these file descriptors are not required and effectively useless we should close them to save some system resources and prevent any related security problems. We close these descriptors like this:</p>
<pre class="brush: cpp;">
/* Close the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
</pre>
<h2>Writing the payload</h2>
<p>Now you have a C program that is capable of becoming a daemon, but its a pretty useless daemon if it exits immediately. Payload code is really up to you to design. I&#8217;ll offer you a few tips on designing your payload.</p>
<ul>
<li>Put your payload in a loop. Generally in a daemon you want to perform the same action over and over again until you&#8217;re killed. If you have to cleanup (such as closing syslog) when the daemon is about to be killed you should add an exit clause that will be activated by a SIGTERM signal handler.</li>
<li>Make your code as fast an efficient as possible. This is something you should do with any program, but with daemons it is important that you do not hamper the performance of the rest of the system. This is especially true if you&#8217;re going to be running this daemon on desktop systems.</li>
<li>Be aware that your code may be preempted very often. As your daemon is going to be running for the amount of time the system is up, it is likely that its execution will be preempted.</li>
<li>Be paranoid about security. Daemons are common attack vectors and can be used to gain privileged access to a system. You should consider dropping any privileges that you don&#8217;t require.</li>
</ul>
<h2>Conclusion</h2>
<p>So if we take all the code I&#8217;ve mentioned in this post and put it all together you have a simple daemon. You can download the source from the link here: <a href='http://www.danielhall.me/wp-content/uploads/2010/01/daemon.c'>daemon.c</a>.<br />
If your daemon is only going to be run on Linux and not on a System V style system such as Solaris you can use the <a href="http://www.manpagez.com/man/3/daemon/">daemon</a> function to do a lot of this work for you.</p>
<h2>References</h2>
<p><a href="http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html">Linux Daemon Writing HOWTO in C</a><br />
<a href="http://blog.emptycrate.com/node/219">Linux Daemon writing in C++</a></p>
<p><strong>Random Thought:</strong> It appears the <a href="http://objectiveministries.org/creation/propaganda.html#">devil uses a Unix</a> based OS, probably OSX.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2010/01/writing-a-daemon-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crazy Melbourne Weather</title>
		<link>http://www.danielhall.me/2009/11/crazy-melbourne-weather/</link>
		<comments>http://www.danielhall.me/2009/11/crazy-melbourne-weather/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 04:12:55 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Weather]]></category>
		<category><![CDATA[Weather Station]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=451</guid>
		<description><![CDATA[<p>We just had a huge thunderstorm pass over Melbourne. For anyone watching from home it meant a temperature drop of 7 degrees in about 30 seconds! Here are the logs from my weather station:
mysql&#62; SELECT time, temp, humidity FROM sensor_outside
&#160;&#160;&#160;&#160;&#160;&#160; WHERE time &#62; &#039;2009-11-26 14:39&#039;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AND time &#60; &#039;2009-11-26 14:53&#039;;

+---------------------+------+----------+
&#124; time&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#124; temp &#124; humidity &#124;
+---------------------+------+----------+
&#124; [...]]]></description>
			<content:encoded><![CDATA[<p>We just had a huge thunderstorm pass over Melbourne. For anyone <a href="http://www.danielhall.me/WeatherMon/">watching from home</a> it meant a temperature drop of 7 degrees in about 30 seconds! Here are the logs from my weather station:<br />
<pre><pre>mysql&gt; SELECT time, temp, humidity FROM sensor_outside
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE time &gt; &#039;2009-11-26 14:39&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND time &lt; &#039;2009-11-26 14:53&#039;;

+---------------------+------+----------+
| time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| temp | humidity |
+---------------------+------+----------+
| 2009-11-26 14:39:02 |&nbsp;&nbsp; 30 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40 |
| 2009-11-26 14:39:39 | 29.6 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40 |
| 2009-11-26 14:40:16 | 28.9 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40 |
| 2009-11-26 14:40:53 | 28.4 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 41 |
| 2009-11-26 14:41:30 | 27.9 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45 |
| 2009-11-26 14:50:08 |&nbsp;&nbsp; 20 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 83 |
| 2009-11-26 14:50:45 |&nbsp;&nbsp; 20 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 84 |
| 2009-11-26 14:51:22 | 19.9 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 85 |
| 2009-11-26 14:51:59 | 19.8 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 85 |
| 2009-11-26 14:52:36 | 19.7 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 86 |
+---------------------+------+----------+
10 rows in set (0.00 sec)
</pre></pre><br />
<strong>Random Thought:</strong> We now return you to your regular programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/11/crazy-melbourne-weather/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why do you have to be like the others?</title>
		<link>http://www.danielhall.me/2009/10/why-do-you-have-to-be-like-the-others/</link>
		<comments>http://www.danielhall.me/2009/10/why-do-you-have-to-be-like-the-others/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 12:40:47 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Inspiration]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=442</guid>
		<description><![CDATA[<p>Bad news, It seems with the assignment rush and the exam cram time coming I&#8217;m finding it hard to find time to study. This means the lowest priority things get pushed off my TODO list. Sadly this means I won&#8217;t be blogging until mid November. Thanks for understanding.</p>
<p>To play me out, this commercial. Try to [...]]]></description>
			<content:encoded><![CDATA[<p>Bad news, It seems with the assignment rush and the exam cram time coming I&#8217;m finding it hard to find time to study. This means the lowest priority things get pushed off my TODO list. Sadly this means I won&#8217;t be blogging until mid November. Thanks for understanding.</p>
<p>To play me out, this commercial. Try to guess what product they&#8217;re advertising.<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/J7X_X1zdH8k&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/J7X_X1zdH8k&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<strong>Random Thought:</strong> I know this sounds crazy, but if anyone wants to write an article during the hiatus just check me an email. You&#8217;ll get full credit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/10/why-do-you-have-to-be-like-the-others/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Subversion for Assignments</title>
		<link>http://www.danielhall.me/2009/10/using-subversion-for-assignments/</link>
		<comments>http://www.danielhall.me/2009/10/using-subversion-for-assignments/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 11:50:28 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[School Work]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=359</guid>
		<description><![CDATA[<p>If you&#8217;ve never heard of subversion before then you are in for a pleasant surprise. Subversion is a version control tool, which means it will keep track of several files and all their old versions. Normally subversion is used to help multiple people work together on a single project. It tracks all their changes and [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve never heard of subversion before then you are in for a pleasant surprise. Subversion is a version control tool, which means it will keep track of several files and all their old versions. Normally subversion is used to help multiple people work together on a single project. It tracks all their changes and combines them all, even flagging when conflicts occur and assists in resolving them. It is also useful when working alone on a school assignment. Here&#8217;s a few dot points that capture the essence of why Subversion is useful with assignments:</p>
<ul>
<li>Subversion allows you to work on the same assignment on multiple computers.</li>
<li>Subversion can email you with changes you&#8217;ve made, allowing to review them.</li>
<li>Subversion allows you to show a teacher that you&#8217;ve been working on an assignment over the whole time available and not just in the last few days. this gives you greater leverage when asking for an extension.</li>
<li>Subversion can help you prove in a disciplinary hearing that you did not plagiarise any code from others showing the natural growth your code had.</li>
<li>Subversion can get back that file you just accidentally emptied out of the trash.</li>
<li>Subversion can show you all the changes you made between the time you fixed that annoying bug, and now, when you just reintroduced it.</li>
</ul>
<p>The first step to making an assignment in is to build your repository. If you didn&#8217;t do this first that&#8217;s okay, you can easily import an existing project into a subversion repository. To create a repository you simply use the &#8217;svnadmin create&#8217; command. You should then create some folders that should be in every subversion repository (trunk, tags and branches). This next block of commands will show you how to create the initial project. If you&#8217;re using these instructions to import an existing project just copy your files into the trunk folder before you run the &#8217;svn import&#8217; command.</p>
<pre class="brush: bash;">mkdir -p /home/daniel/svn/newproject
svnadmin create /home/daniel/svn/newproject
mkdir -p /tmp/newrepo/{trunk,branches,tags}
svn import /tmp/newrepo file:///home/daniel/svn/newproject -m &quot;Create Initial Structure&quot;
rm -rf /tmp/newproject</pre>
<p>The trunk, tags and branches folders aren&#8217;t strictly required but can be very useful in certain circumstances. The trunk folder is where you main copy sits, it should be the latest stable version of the software. In an assignment though this is where you will probably be doing all your work, you generally don&#8217;t have the need or the time to make and merge branches. Which leads us to branches. Generally you branch software when you are about to make a major change that may break other developers work. You most likely don&#8217;t have other developers on your assignment and if you do you&#8217;ve probably all decided on what parts you will work on. Finally tags are for labelling certain versions with a specific tag. For example if you have to submit your assignment weekly you could tag each week as you submit, or you could tag as you finish each requirement. To populate these folders you just copy whatever it is you want into them. Subversion will only use a minuscule amount of space as the copy will be stored internally to the repository.</p>
<p>Before you can edit the files in the repository you need to check it out. You can check it out to the same machine, you can <a href="http://www.danielhall.me/2009/09/using-subversion-over-ssh/">use SSH</a> or you could check it out over WebDAV depending how you&#8217;ve set it up. The following command checks out the trunk folder into a folder called newproject. This is one of the few times you have to type the full path to the repository. Subversion remembers this for you so that next time you use a subversion command its pre filled.</p>
<pre class="brush: bash;">svn checkout file:///home/daniel/svn/newproject/trunk newproject</pre>
<p>What you&#8217;ve just checked out is called a &#8216;working copy&#8217;. This is where you make your changes before uploading them again in to the repository. Your working copy also includes copies of the versions you originally checked out so that if you want to revert back to them you can. Because they are stored in the working copy you don&#8217;t need access to the repository to revert. To revert back to the version you checked out from the repository you simply run &#8217;svn revert &lt;filename&gt;&#8217;. You can also find the differences between these versions and the current ones by using &#8217;svn diff &lt;filename&gt;&#8217;. The filename is optional and if omitted will print all the changes in the current directories and below.</p>
<p>Part 2 to come&#8230;<br />
<strong>Random Thought:</strong> I&#8217;ve just redesigned my website, I&#8217;d love to know what my readers think. If you could post your comment on the new design, I&#8217;d appreciate it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/10/using-subversion-for-assignments/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Paramaterized Java Classes</title>
		<link>http://www.danielhall.me/2009/10/paramaterized-java-classes/</link>
		<comments>http://www.danielhall.me/2009/10/paramaterized-java-classes/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 03:01:22 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Type Safety]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=364</guid>
		<description><![CDATA[<p>One of the biggest features of Java 1.5 was generics. In particular all the collection classes had been extended to use parametrized classes. Normally the collection classes accepted and returned Objects which is the class all other Java classes descend from. Unfortunately this meant that you had to cast everything you got back out of [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest features of Java 1.5 was generics. In particular all the collection classes had been extended to use parametrized classes. Normally the collection classes accepted and returned Objects which is the class all other Java classes descend from. Unfortunately this meant that you had to cast everything you got back out of a collection to what you expected it to be. and until you did you would only be able to call methods that were provided by Object. You also had to be ready to catch an exception in case the class could not be cast because it was the wrong object.</p>
<p>Generics and parametrized classes allow Java programmers to place a type on a class and have that type inherited by its methods. For example you can now declare an ArrayList class with a type String. This alters the ArrayList class so that its add method now only accepts objects of type String, the get method now also returns objects of type String. This makes everything type safe which means you don&#8217;t have to cast anything and your code won&#8217;t compile if you try to put something in the ArrayList that doesn&#8217;t match its class.</p>
<p>Java uses parametrized classes to build its collections and you&#8217;ll want to use them too if you&#8217;re making your own collection class. For example if you were implementing a stack, a queue or a multi-priority FIFO queue are good cases for parametrized classes. Be careful though of the lure parametrized classes can have. They are not a replacement for polymorphism and shouldn&#8217;t be used when polymorphism would make more sense. For example if your multi-priority queue gets the priority out of the object itself then you&#8217;d need an interface that provides a method to get the priority. Then your class will only be able to accept items that implement that interface, which makes sense in this case as we need to priority to be able to store it.</p>
<p>A parametrized class is really simple to use. Here is an example implementation of a stack collection backed by an ArrayList:</p>
<pre class="brush: java;">import java.util.ArrayList;
import java.util.Collection;

/**
 * This class acts as a stack. Items can be 'pushed' which adds them to the top
 * of the stack. items can also be 'popped' which removes and returns the top
 * item on the stack and removes it. This means only the most recently added
 * item is available at the current time. To get to older items you need to
 * first remove the others.
 *
 * Note: Java already has a stack object that should probably be used in
 *       preference to this one. This is only an example implementation.
 *
 * @author Daniel Hall &lt;daniel@danielhall.me&gt;
 *
 * @param &lt;T&gt; The type of items that can be stored in the Stack.
 */
public class Stack&lt;T&gt; {
	/* Uses the same type as this class to store the items */
	private ArrayList&lt;T&gt; array = new ArrayList&lt;T&gt;();

	/**
	 * Creates a Stack containing items already in a collection. The collection
	 * must have the same parameterized type as this class to ensure that we get
	 * the right objects.
	 * @param c The Collection to initialize with
	 */
	public Stack(Collection&lt;T&gt; c) {
		array.addAll(c);
	}

	/**
	 * Creates an empty Stack object
	 */
	public Stack() {

	}

	/**
	 * Adds an item to the top of the stack.
	 * @param item The item which will be added to the top of the stack.
	 */
	public void push(T item) {
		array.add(item);
	}

	/**
	 * Removes the first item from the stack
	 * @return The item that was on the top of the stack.
	 */
	public T pop() {
		/* This gets the size so we don't have to do it twice. */
		int count = array.size();

		/* If the stack is empty return null, note that the Java implementation
		 * of stack throws an Exception instead.
		 */
		if (count == 0) {
			return null;
		}

		/* Remove the last added object (which will have index count - 1) */
		return array.remove(count - 1);
	}
}</pre>
<p><strong>Random thought: </strong><a href="http://www.cse.unsw.edu.au/JohnLions/">John Lions</a> wrote a book about the Unix source code, in the seventies, which because it also included some code, was blocked from being published until 1996.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/10/paramaterized-java-classes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cryptographically Secure Random Numbers in Java</title>
		<link>http://www.danielhall.me/2009/09/cryptographically-secure-random-numbers-in-java/</link>
		<comments>http://www.danielhall.me/2009/09/cryptographically-secure-random-numbers-in-java/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 20:58:06 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=367</guid>
		<description><![CDATA[The Random Class
<p>Most people wanting to generate random numbers in Java do something similar to the following:</p>
public static void main(String[] args) {
  Random generator = new Random();
  int randomnumber = generator.nextInt(5) + 1;
  System.out.println(&#34;Dice rolled: &#34; + randomnumber);
}
<p>This is perfectly fine for a simple dice rolling application where there isn&#8217;t going to [...]]]></description>
			<content:encoded><![CDATA[<h1>The Random Class</h1>
<p>Most people wanting to generate random numbers in Java do something similar to the following:</p>
<pre class="brush: java;">public static void main(String[] args) {
  Random generator = new Random();
  int randomnumber = generator.nextInt(5) + 1;
  System.out.println(&quot;Dice rolled: &quot; + randomnumber);
}</pre>
<p>This is perfectly fine for a simple dice rolling application where there isn&#8217;t going to be much effort put into cracking it. For example in this application the only real reason you would bother cracking it would be to show off a neat party trick to your geeky friends. No doubt though the effort wouldn&#8217;t be worth it.</p>
<p>Java states that the Random class and its subclasses must produce predictable results when seeded with the same data. This however is not why this is insecure, and it is useful when testing. The reason that this class is predictable though is the way in which it is seeded. The Random class, in the absence of a seed in its constructor it will seed its random number generator with the current time in milliseconds. This means that if somebody knows the time that the Random object was seeded and has several consecutive bytes of output then they can reasonably predict the next numbers. Once somebody has discovered the seed for the generator all number produced from it can be seen as compromised.</p>
<h1>The SecureRandom Class</h1>
<p>The SecureRandom class is different, it again uses algorithms that when seeded will produce predictable results, but the algorithm is much more complex. It uses a digest algorithm such as SHA-1 on the seed and a counter to generate random data. SHA-1 is much more costly than the simple algorithm used in the Random class and as such it is much harder to brute force.</p>
<p>Its true strength however lies in the method in which it is seeded. The SecureRandom class is seeded using true random data gathered by the operating system. This is data gathered by the OS from sources of true randomisation, such as mouse movements, network packet arrival times, IO statistics and interrupts. On Linux the data is gathered from /dev/random and on Windows via the CryptGenRandom() call in Windows.</p>
<p>When using SecureRandom though you should be aware of a few things:</p>
<ul>
<li>The more random numbers some can get a hold of the more likely they can figure out the seed. You should either throw away the SecureRandom object every now and then or reseed it. Keeping in mind the next point though.</li>
<li>The seeding the generator takes entropy out of the system, if it cannot get any entropy it will block until the system has some. This means if you&#8217;re reseeding the generator too often your program will hang along with anything else on the system requiring entropy.</li>
<li>Don&#8217;t seed the SecureRandom class yourself, unless you are 100% absolutely sure you are seeding it with purely random data, or you are testing and need repeatable results. Whatever you do, don&#8217;t let your testing code leak into a production system.</li>
</ul>
<h1>How to decide</h1>
<p>Generally when you&#8217;re coding you don&#8217;t need secure random numbers. For example if you&#8217;re writing a number guessing game, or a quiz generating program then high quality random numbers aren&#8217;t required. It should be noted though that if money is involved people will often go to greater lengths and a more secure generator will be required, such as in a slot machine.</p>
<p>Again generally if what you are generating is a security token of some sort then you will need a secure generator. For example a session id, a one time password or an encryption key. The exception here is a salt for a password, salts can be generated using predictable entropy sources, even a simple time stamp would work here (especially if your also storing the time stamp to measure password expiry).</p>
<p><strong>Random Thought:</strong> For those of you who don&#8217;t know <a href="http://en.wikipedia.org/wiki/Bruce_Schneier">Bruce Schneier</a> is the <a href="http://www.schneierfacts.com/">Chuck Norris</a> of cryptography.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/09/cryptographically-secure-random-numbers-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google C&amp;Ds CyanogenMod</title>
		<link>http://www.danielhall.me/2009/09/google-cds-cyanogenmod/</link>
		<comments>http://www.danielhall.me/2009/09/google-cds-cyanogenmod/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 03:23:16 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=371</guid>
		<description><![CDATA[<p>In an act that appears to contradict both the &#8216;do no evil&#8217; and the &#8216;android is open&#8217; mantras of Google they sent a Cease and Desist to CyanogenMod creator Cyanogen. This effectively means that all cooked versions can now no longer include and Google applications, sync with Google services or the many other closed source [...]]]></description>
			<content:encoded><![CDATA[<p>In an act that appears to contradict both the &#8216;do no evil&#8217; and the &#8216;android is open&#8217; mantras of Google they sent a Cease and Desist to CyanogenMod creator Cyanogen. This effectively means that all cooked versions can now no longer include and Google applications, sync with Google services or the many other closed source parts of the ROM. I use Cyanogen&#8217;s mod and this effectively cripples it to a worthless Linux phone distribution. Google have essentially said to me &#8220;You know that T-Mobile G1 you brought that was supposed to be completely open? Well we never made all the good bits open, and now we&#8217;re taking them away.&#8221;. I can&#8217;t use the Official ROM because I live in Australia and it constantly sends text messages to T-Mobiles myFaves which costs me a fortune. So Google has removed my ability to use their services on my &#8216;Google&#8217; phone. So now wherever you read a press release where Google claims that Android is open you know what they really mean is they made the stuff they had to open and closed the rest.</p>
<p>I see only one way out of this mess, we need developers to replace all the closed source parts of Android with free software solutions. This means Android will be free and fully open source. Why stop there though? Lets make Google&#8217;s decision into one they will regret! As the open source community is replacing the closed source apps we should build in functionality to allow the phone to work with Google&#8217;s competitors. When you first used the G1 you had to sign in using your Google account. What if that same box let you sing in with your Live Id, your Yahoo account or even OpenID? Imagine the Android phone being written in completely open source to work on any operator! It wouldn&#8217;t be hard either, most are beginning to provide APIs to their accounts and I&#8217;m sure they&#8217;d love to help.</p>
<p>Edit: According the the Save Cyanogen Petition application on the market it is impossible to even run the ROMs that Google claim to support without the Google binaries.</p>
<p><strong>Random Thought:</strong> Did you know the <a href="http://www.csse.unimelb.edu.au/dept/about/csirac/">first Australian computer</a> was built by <a href="http://www.csse.unimelb.edu.au/dept/about/csirac/designer.html">Trevor Pearcey</a> and <a href="http://www.csse.unimelb.edu.au/dept/about/csirac/designer.html">Maston Beard</a> in 1947-1951.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/09/google-cds-cyanogenmod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Subversion over SSH</title>
		<link>http://www.danielhall.me/2009/09/using-subversion-over-ssh/</link>
		<comments>http://www.danielhall.me/2009/09/using-subversion-over-ssh/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 08:19:38 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=356</guid>
		<description><![CDATA[Few people don't realise that subversion has the ability to connect to a remote repository via SSH. Its extremely simple and can give you all the advantages of storing your important files on a server while still having them readily accessible on your [...]]]></description>
			<content:encoded><![CDATA[<p>Subversion is an amazing tool that you can use to keep track of all the changes you make to a group of files. If you haven&#8217;t used it before, or have never heard of &#8216;version control&#8217; then you should probably read the <a href="http://svnbook.red-bean.com/">Subversion Book</a>.</p>
<p>Few people don&#8217;t realise that subversion has the ability to connect to a remote repository via SSH. Its extremely simple and can give you all the advantages of storing your important files on a server while still having them readily accessible on your desktop. This means that for example you could have your files (and every old version of your files) stored on a RAID device on a server while working with them locally on your desktop.</p>
<p>To set this up its actually rather simple. First you create your repository and perform the initial import of the files. I usually make it in my home directory as follows:</p>
<pre class="brush: bash;">mkdir -p /home/daniel/svn/newproject
svnadmin create /home/daniel/svn/newproject
mkdir -p /tmp/newrepo/{trunk,branches,tags}
svn import /tmp/newrepo file:///home/daniel/svn/newproject -m &quot;Create Initial Structure&quot;
rm -rf /tmp/newproject</pre>
<p>These commands are basically what you&#8217;d use to create any subversion repository and people familiar with it require no explanation. Most people probably even have is scripted to make it just that much easier. Here comes the fun part though. Next we (on our local machine) check the files out. To checkout subversion repositories over ssh you simply use the following command:</p>
<pre class="brush: bash;">svn checkout svn+ssh://username@servername/home/daniel/svn/newproject/trunk newproject</pre>
<p>All going well you will now see a password prompt and upon successful authentication the files will be checked out. This is all that is required and from now on you can simply use the ordinary svn commands.</p>
<p><strong>Random Thought:</strong> &#8230; and I says to the kernel developer, I says &#8220;git this!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/09/using-subversion-over-ssh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The T-Mobile G1 Phone</title>
		<link>http://www.danielhall.me/2009/09/the-t-mobile-g1-phone/</link>
		<comments>http://www.danielhall.me/2009/09/the-t-mobile-g1-phone/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 07:54:57 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=354</guid>
		<description><![CDATA[<p>The T-Mobile G1 Phone goes by a few names. HTC Dream and Google Android Development phone are two more. Essentially they are the same hardware and the only change is the software. The Android Development phone unlike the others comes with an unlocked bootloader allowing you to flash any software image you want where the [...]]]></description>
			<content:encoded><![CDATA[<p>The T-Mobile G1 Phone goes by a few names. HTC Dream and Google Android Development phone are two more. Essentially they are the same hardware and the only change is the software. The Android Development phone unlike the others comes with an unlocked bootloader allowing you to flash any software image you want where the other two will only allow software signed by either HTC or T-Mobile.</p>
<p>I bought mine two weeks ago and it has completely replaced my Windows Mobile phone to the point where I actually gave it away. The main issues that I have with Windows Mobile was the instability and the difficult to use interface. This new phone was a breath of fresh air. Amazingly when I was testing it out with the seller it received a weeks worth of SMSes indicating that my Windows Mobile phone had stopped accepting them.</p>
<p>I opted for the T-Mobile option. Mainly because I found one cheap on eBay but also because I knew of an exploit to easily get root, flash a new bootloader and install whatever OS I wanted. I knew with almost absolute certainty that I would want to be able to play with root access to the OS. I could have went with the HTC Hero or Magic (the successors to the G1) but I liked the idea of the flip out keyboard way too much.</p>
<p>The G1 is easy to use without a stylus, in fact it won&#8217;t work with a stylus as is uses a capacitive touch screen. This means all the applications, the keyboard and the core OS are designed with that in mind. While I could use my old phone with my thumbs many of the controls were impossible to use without perfect precision. Generally all the controls on the Andriod are larger and easier to manipulate, where the Windows Mobile controls are clunky and small.</p>
<p>The Android marketplace is also something that Windows Mobile could certainly have done with. It is an almost perfect image of the iPhone App Store, except that in the culture of open source most of the applications are free. The applications are easier to search for, review and download making the Android Marketplace a much easier to use and more polished tool.</p>
<p>One thing this phone and my last one have in common was the hacker community around them. Both have multiple ROMs available and its relatively easy to flash a new one. I&#8217;m currently running the latest stable CyanogenMod (4.0.4) which was extremely easy to flash courtesy of the latest kernel vulnerability and some specially designed tools.</p>
<p><strong>Random Thought:</strong> I thought Androids could make breakfast for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/09/the-t-mobile-g1-phone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
