Mike's Musings

Do you want code with that mongoose?

0

Ch-ch-changes

It appears that it is a time of change for me at the moment so I thought I’d take a moment and let you all know what’s going on. The first and perhaps the most obvious is the theme for the site has been updated, after close to two years I felt the old design needed a bit of a refresh. The new site is using a lot of HTML 5 and is all semantically marked up with sections, articles and such, I’ve got to say HTML 5 is makes a lot of sense for a site like mine allowing a lot more meaning to generated from the code itself. I’ve also increased my ‘social presence’ in the sidebar adding in links to my github, Google+ and Stackoverflow profiles.

Now I’ve mentioned github I think that it’s worth noting that from now on I’m primarily going to be using that for hosting my source control, I’m by no means an expert with git but I’m learning and enjoying using it so far. The only legacy codebase of mine that I’ve migrated to github currently is gIDE which can be found here. Thinking about projects going forward I have two projects which I haven’t mentioned on this blog, I’ll briefly mention them here and later provide a more indepth post about each of them.

CRAPI – One of the projects I have worked on in the past was a REST API for Coldfusion, during which I found CF to be a bit lacking in what I wanted it to do. So to remedy this I have started CRAPI which stands for a Coldfusion REST API. This framework is inspired by the various MVC frameworks that I have toyed with (though it supplies no ORM functionality) and I like to think that it is reasonably easy to use. The name is only a placeholder at the moment and I will most likely be changing it to CFRest before I make a post about it.

MarkPDF – I like markdown, I think it is fantastic for a quickly written document to get some formatting. Recently I have been playing around with taking a document formatted with markdown and transforming it into a PDF, MarkPDF is my progress so far it’s a small commandline app written in C#. I’m working on adding more functionality to it at the moment (mostly around metadata) before I make ‘proper’ post about it.

Finally I’m going to end this post on a bit of a downer. February the 10th marked my last day working for LayerX, unfortunately I was made redundant. I started at LayerX on the 6th of July in 2009 and I enjoyed my time with the company, I’m looking forward to what the future has instore for me and I’ll update this blog when I find as things progress.

0

Fun with strings and hashes in ColdFusion

At work we do a bit of web development using ColdFusion and earlier this week I got stumped by a problem which I thought I would share.  We are currently working on a RESTful API which requires an API signature similar to how flickr does. When it came to writing my unit tests I created a signature grabbing a private key out of the database to test against. I ran the test and BAM! it failed, now this was half expected it was the first time I’d run the test. So it turned out that the code was syntactically fine, then I thought  maybe I had made a mistake in the process of creating a signature.

With that ins mind the next step I took was comparing the raw pre-hashed version of both signatures, to my surprise I found that the test passed.  This was beginning to not make sense, it wasn’t until I altered the test to fail that I saw what the issue was: when I retrieved the key from the database all of the characters were uppercase however when coldfusion retrieved the key all of the characters were lower case. After updating the test to use a lower case version of the key it passed successfully.

So it turns out that ColdFusion is not case sensitive when it does string comparisons, but the hash function does care what case the characters are, as you can lead to a frustrating situation.  Now I’m not expecting you to take my word for it so I have quickly coded up some example code showing the issue.

<cfset original = "secret-key" />
<cfset upperCase = "SECRET-KEY" />
<cfset match = "secret-key" />
<cfset random = "5q2up0awet530" />

<cfset originalHash = Hash(original) />
<cfset upperCaseHash = Hash(upperCase) />
<cfset matchHash = Hash(match) />
<cfset randomHash = Hash(random) />

<cfoutput>
	<h1>String Matching</h1>
	<table border="1" style="width: 30%">
		<tr><th></th><th>Upper case</th><th>Match</th><th>Random</th></tr>
		<tr>
			<th style="text-align: left">Original</th>
			<td style="text-align: center">#original eq upperCase#</td>
			<td style="text-align: center">#original eq match#</td>
			<td style="text-align: center">#original eq random#</td>
		</tr>
	</table>

	<h1>Hash Matching</h1>
	<table border="1" style="width: 30%">
		<tr><th></th><th>Upper case</th><th>Match</th><th>Random</th></tr>
		<tr>
			<th style="text-align: left">Original</th>
			<td style="text-align: center">#originalHash eq upperCaseHash#</td>
			<td style="text-align: center">#originalHash eq matchHash#</td>
			<td style="text-align: center">#originalHash eq randomHash#</td>
		</tr>
	</table>
</cfoutput>

When you run the code this is the output you should get.

As I found the hard way when ColdFusion says two strings are the same it may not necessarily be true.