<?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>Chirashi Security &#187; BlackBerry</title>
	<atom:link href="http://chirashi.zenconsult.net/category/blackberry/feed/" rel="self" type="application/rss+xml" />
	<link>http://chirashi.zenconsult.net</link>
	<description>A blog with scattered thoughts on security</description>
	<lastBuildDate>Sun, 16 Oct 2011 17:26:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Puttering around with BlackBerry forensics &#8212; Part 2</title>
		<link>http://chirashi.zenconsult.net/2011/09/puttering-around-with-blackberry-forensics-part-2/</link>
		<comments>http://chirashi.zenconsult.net/2011/09/puttering-around-with-blackberry-forensics-part-2/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 14:53:29 +0000</pubDate>
		<dc:creator>chopstick</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Forensics]]></category>

		<guid isPermaLink="false">http://chirashi.zenconsult.net/?p=637</guid>
		<description><![CDATA[Okay then. It apparently takes me a while between posts. I&#8217;ve been keeping a bit busy with several projects and it has been difficult to find the time to conduct much research or write blog posts. I do have an upcoming white-paper that I will release somewhere in November. It includes source code to the toolkit that [...]]]></description>
			<content:encoded><![CDATA[<p>Okay then. It apparently takes me a while between posts. I&#8217;ve been keeping a bit busy with several projects and it has been difficult to find the time to conduct much research or write blog posts. I do have an upcoming white-paper that I will release somewhere in November. It includes source code to the toolkit that I will release as well. The topic is loosely based on BlackBerry forensics and malware. In this case, however, it won&#8217;t be on how to find data, but will instead focus on how you can destroy or introduce large quantities of misleading data to frustrate and annoy malware controllers and forensic analysts. Probably not going to win many friends in certain circles with this, but at least I can force everyone to change their analysis methods.</p>
<p>Today, girls and boys, we&#8217;re going to look at the second utility I released that helps with analyzing BlackBerry data. Behold! <a href="https://github.com/sheran/ConParse">ConParse</a>!</p>
<h2>ConParse</h2>
<p>ConParse is a utility that helps you take a look inside a BlackBerry .con file. The .con file is generated when you choose to backup your BBM contacts on your device. These days, RIM allows you to back your BlackBerry Messenger (5 and above) contacts up to some remote location that we will henceforth refer to as the cloud. But if you fancied, you could also back up your BBM contact list to your device memory or SD Card. I present the obligatory screenshots below, thereby providing you with both hands and a flashlight. Access the screens by selecting Options from your BlackBerry messenger application.</p>
<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2011/09/mgmt.png"><img class="alignnone size-medium wp-image-642" style="border-width: 1px; border-color: black; border-style: solid;" title="mgmt" src="http://chirashi.zenconsult.net/wp-content/uploads/2011/09/mgmt-225x300.png" alt="" width="225" height="300" /></a>      <a href="http://chirashi.zenconsult.net/wp-content/uploads/2011/09/backup.png"><img class="alignnone size-medium wp-image-641" style="border-width: 1px; border-color: black; border-style: solid;" title="backup" src="http://chirashi.zenconsult.net/wp-content/uploads/2011/09/backup-225x300.png" alt="" width="225" height="300" /></a></p>
<p>Now then. If we take a quick peek inside the .con file it looks a right mess of randomly placed hexadecimal characters and readable text, much like most other binary files. Since not everyone is able to grok raw hex data when they look at it and because no prior documentation existed for it, I set out to make sense of this beast. If prior documentation did exist, then will the person who wrote it please speak with their SEO provider? Because you&#8217;re getting ripped off big time. If you care to dig through my source code, you may find some details on the file structure itself. If looking at badly written source code gives you hives, then I will try to explain it here.</p>
<p>The .con file header is interesting. The first byte tells you the size of a unique string of bytes to follow. So far it has always been 32 bytes. This 32 byte string is a signature or hash of your .con file. Its sole purpose is to ensure that you do not import .con files belonging to other devices. I haven&#8217;t bothered <a href="http://chirashi.zenconsult.net/2010/07/everything-can-be-reversed-everything/">reverse engineering</a> the .cod files yet to see what they use to generate this signature. In the tests I did, however, it is evident that the signature differs each time you generate a backup file and swapping signatures from other devices will render your backup file invalid.</p>
<pre>20 C3DCA86024DCCC531A96199327B7F4E7224EF4FF52E7C0978C02C9E5F347D87F 7F80 00 00 70 05</pre>
<p>In the byte sequence above (all hex), the first byte indicates the size of the signature (32 bytes), then the signature of 32 bytes follows.</p>
<p>Now that the signature is out of the way, the actual file header begins. The bytes 0x7F 0&#215;80 indicate the start of the .con file. After this, the next 4 bytes indicate the size of the remaining data in the file. In this case it is 28677 bytes.</p>
<p>Immediately after this, the records start. You can find some of the following types of records in a .con file:</p>
<ul>
<li>Your name and device PIN</li>
<li>All your contacts and groups (their PINS, names, custom names you&#8217;ve chosen for them, status messages, etc)</li>
<li>Your profile picture</li>
<li>Timezone and Country flag image filename</li>
<li>Base64 Code and Hex Code (Haven&#8217;t looked at these extensively yet, but could have something to do with an authorization code and/or the string used to generate your <a href="http://chirashi.zenconsult.net/2009/10/blackberry-qrcodes-a-look-inside/">QR Code</a>)</li>
</ul>
<div>I&#8217;m not going to break down each record here, but will just give you the basic structure which is quite simple:</div>
<pre>00 08 0A 32 31 30 30 30 30 41</pre>
<p>The record above is a device PIN record. The first two bytes indicate the size of the record, then third byte indicates the record type and the remaining bytes (up to the record size) contain the data. RIM follows the same principle of storing size and type before data as it did in the IPD databases.</p>
<p>That&#8217;s it. You&#8217;re now a .con file expert. Go forth and dissect the crap out of the file. Use ConParse as a guideline or just use it to parse out .con files at your next party &#8212; guaranteed to get you laid.</p>
<p>Here&#8217;s another screenshot of the type of output you can expect from ConParse. Admittedly, it is just a couple of steps away from raw hex.</p>
<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2011/09/theshizz.png"><img class="alignnone size-medium wp-image-646" style="border-width: 1px; border-color: black; border-style: solid;" title="theshizz" src="http://chirashi.zenconsult.net/wp-content/uploads/2011/09/theshizz-300x151.png" alt="" width="300" height="151" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2011/09/puttering-around-with-blackberry-forensics-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Puttering around with BlackBerry forensics &#8212; Part 1</title>
		<link>http://chirashi.zenconsult.net/2011/07/puttering-around-with-blackberry-forensics-part-1/</link>
		<comments>http://chirashi.zenconsult.net/2011/07/puttering-around-with-blackberry-forensics-part-1/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 16:29:38 +0000</pubDate>
		<dc:creator>chopstick</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Forensics]]></category>
		<category><![CDATA[bbt]]></category>
		<category><![CDATA[conparse]]></category>
		<category><![CDATA[event logs]]></category>
		<category><![CDATA[evt2sqlite]]></category>

		<guid isPermaLink="false">http://chirashi.zenconsult.net/?p=603</guid>
		<description><![CDATA[ I&#8217;m guilty of sitting on source code which I should have released a long time ago.  I make excuses to myself that I didn&#8217;t release any of it because I was waiting for someone to come along and prove to me that there was a better way of doing things.  I guess the bottom line [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/514914659_220e004fd41.jpg"><img class="alignnone size-medium wp-image-605" title="Mag glass" src="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/514914659_220e004fd41-300x221.jpg" alt="" width="210" height="155" /></a> I&#8217;m guilty of sitting on source code which I should have released a long time ago.  I make excuses to myself that I didn&#8217;t release any of it because I was waiting for someone to come along and prove to me that there was a better way of doing things.  I guess the bottom line was that I was just lazy and procrastinating.</p>
<p>Today, I&#8217;m releasing source code to three of my projects that I&#8217;ve been incubating.  1) <a href="https://github.com/sheran/bbt">bbt</a> 2) <a href="https://github.com/sheran/evt2sqlite">evt2sqlite</a>  3) <a href="https://github.com/sheran/ConParse">ConParse</a> Take! Build! Enjoy! <del>At some point or another, I may just split them up into their own repos.  For now, they all live in the <a href="https://github.com/sheran/bb-tools">bb-tools</a> repository down at github.</del> <strong>Update:</strong><em> I&#8217;ve split them up now</em></p>
<p>In today&#8217;s post, I&#8217;ll cover the first tool, bbt.</p>
<h3>bbt</h3>
<p>bbt is a python script that analyzes the thumbnail cache from a BlackBerry.  The purpose of a thumbnail cache in any system, is generally to speed up the browsing of large numbers of graphic or video files.  Instead of presenting a static icon to the user, a small thumbnail of the picture or frame of the video file is shown.  Apparently this is a good thing, because  you can see an icon of the image that you&#8217;re clicking on and will hopefully be able to find the file you&#8217;re looking for quicker.  Typically, the Operating System will find and shrink pictures found in directories of the filesystem.  These shrunk pictures will then be placed inside the thumbnail cache.</p>
<p>When conducting a digital forensics analysis of a computer, looking for these thumbnail caches often provide clues as to what files may have existed before they were deleted off the file system.  The thumbnail cache is important enough to warrant its <a href="http://www.forensicswiki.org/wiki/Thumbs.db">own entry</a> on the Forensics Wiki (albeit only the Windows thumbnail cache is spoken about).  The principle generally remains the same when extended to the BlackBerry device as well.  So, bottom line: being able to analyze this file is useful.</p>
<p>bbt will do just that for thumbnail cache files found on BlackBerry devices.  There are two types of thumbnail caches on the BlackBerry device: 1) BBThumbs.dat format 2) key/dat format.</p>
<p>Format 1 is pre OS 5.0 and the key/dat format is post OS 5.0  The key/dat combination is interesting because it uses two files to keep track of thumbnails.  They look something like thumbs86x86.key and thumbs86x86.dat (the 86&#215;86 indicates the size of the thumbnail &#8211; 86 pixels by 86 pixels).  I&#8217;ve noticed quite a few interesting things in these files and no doubt, you will too after you look through the source or play around with them long enough:</p>
<ol>
<li>The BBThumbs.dat header is 0&#215;24052003 (which is a hex number)</li>
<li>The thumbs.dat file header is 0&#215;22062009 (hex again)</li>
<li>The thumbs.key file header is 0&#215;08062009 (hex)</li>
</ol>
<p>This is pure speculation, but if you took those hexadecimal representations and looked at just the numbers, don&#8217;t they look like dates?</p>
<ul>
<li>0&#215;24052003 &#8211;&gt; 24 05 2003</li>
<li>0&#215;22062009 &#8211;&gt; 22 06 2009</li>
<li>0&#215;08062009 &#8211;&gt; 08 06 2009</li>
</ul>
<p>Maybe birth dates of the file format itself or someone significant to someone who wrote it? Dunno.</p>
<p>Another interesting observation of the key/dat thumbnail cache is that it not only stores image thumbnails, but also stores details of all types of media including &#8216;wav&#8217;, &#8216;mp3&#8242;, and &#8216;mid&#8217;.  It doesn&#8217;t store any content inside it though.  The only content stored inside the files is image data.</p>
<p>I&#8217;m not actually going to tell you what is found inside the thumbs files in this post, but instead, I am going to tell you how to run bbt.  bbt is a python script and as such will require that you have python installed on your system.  I&#8217;d always recommend cloning my <a href="https://github.com/sheran/bb-tools">repository on github</a> so that you can easily pull any updates.  You may also want to sign up for a <a href="http://github.com">github</a> account and watch the repository so that you will be notified of any commits I make.  You could also fork the project and get to work on it yourself.</p>
<pre>azazel:Device sheran$ ~/github/bb-tools/bbt/bbt.py
Usage: bbt.py [options]
  -h, --help: This cruft
  -k, --key &lt;bbthumbs key file&gt;: Process post OS5 thumbs.key file (requires thumbs.dat file in same directory)
  -b, --bbthumbs &lt;old bbthumbs file&gt;: Process pre OS5 BBThumbs.dat file
  -x, --extract: Extracts the thumbnails into directory specified by -o
  -o, --output &lt;output directory&gt;: Directory to extract thumbs to (used only with -x)
azazel:Device sheran$</pre>
<p>The output above is what you will receive if you run bbt without options.  As of the latest release (0.3b), the most magical thing you can do with this tool is to extract the thumbs into a specific output directory.  Additionally, bbt will parse out information about 1) What thumbnails are stored in the file (filename) for BBThumbs.dat files or 2) Where at what offset in a &#8216;dat&#8217; file a specific record id is stored.  Here&#8217;s some example output when parsing a key/dat pair:</p>
<pre>azazel:Device sheran$ ~/github/bb-tools/bbt/bbt.py -k thumbs116x116.key -x -o out
*** Processing thumbs116x116.key on 2011-07-22 21:50:48.156899
Record ID C620B80A is at offset 7 in 'dat' file // [1306132653179.jpeg]
Record ID DB0B7CA3 is at offset 25930 in 'dat' file // [1306492410606.jpeg]
Record ID D2EC23E3 is at offset 52123 in 'dat' file // [1306732433796.jpeg]
*** thumbs116x116.key has 9 records
*** Processed 3 records
azazel:Device sheran$</pre>
<p>When you parse a key/dat file combination, you need to make sure that both the &#8216;key&#8217; and &#8216;dat&#8217; file are in the same directory.  When you run bbt, you will point it to the location of the &#8216;key&#8217; file.  From the output above, you can see that it has discovered 3 records, corresponding record ids and offsets where they are stored in the &#8216;dat&#8217; file.  Also, the filename of the thumbnail is provided.  What do the offsets mean?  Well, if you were to take the numbers and open up the &#8216;dat&#8217; file in a hex editor, then you would land on the location where that specific record began.  This is what it looks like:</p>
<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/Screen-shot-2011-07-22-at-9.51.50-PM.png"><img class="alignnone size-medium wp-image-617" title="inside the dat file" src="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/Screen-shot-2011-07-22-at-9.51.50-PM-300x154.png" alt="" width="300" height="154" /></a></p>
<p>The highlighted portion is the first part of the record with the correct starting offset.  You may also notice that the &#8216;key&#8217; file supposedly has 9 records but only 3 were processed.  This happens because the &#8216;key&#8217; file holds 9 record ids and 9 offsets, but only 3 of those actually match up in the &#8216;dat&#8217; file.  One assumption that can be made is that the files were deleted from the &#8216;dat&#8217; file, but the ids and offsets still remained in the &#8216;key&#8217; file.</p>
<p>bbt also has the &#8216;-x&#8217; option which allows you to extract the thumbnails that are inside either the BBThumbs.dat file or the key/dat files.  You do this by specifying the &#8216;-x&#8217; option along with the &#8216;-o&#8217; option to tell bbt where to extract the thumbnails to.  You will need to make sure that the output directory specified by the &#8216;-o&#8217; option does not already exist.</p>
<p>For now, that&#8217;s as much as you&#8217;re going to get out of bbt.  Some features that are planned in the roadmap for bbt are:</p>
<ul>
<li>HTML Reporting</li>
<li>Identification of Exif data within thumbnails</li>
<li>Completely parsing some of the header and record bytes that are as yet unknown</li>
</ul>
<p>I&#8217;ll cover the other tools in subsequent posts.  For now, though, the tools are all live in the github repository.  All of the tools contain a basic README doc that tells you how to get started with each of the tools.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2011/07/puttering-around-with-blackberry-forensics-part-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Comparing JTR compiled on GCC and Clang</title>
		<link>http://chirashi.zenconsult.net/2011/07/comparing-jtr-compiled-on-gcc-and-clang/</link>
		<comments>http://chirashi.zenconsult.net/2011/07/comparing-jtr-compiled-on-gcc-and-clang/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 14:50:58 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Non Security]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Blowfish]]></category>
		<category><![CDATA[Clang]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[John the Ripper]]></category>
		<category><![CDATA[JtR]]></category>
		<category><![CDATA[LLVM]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=562</guid>
		<description><![CDATA[I bought the new XCode 4 recently and it is a pretty awesome IDE. I only recently got into Objective-C coding, but I have VERY quickly fallen in love with the language and the IDE.  I generally regarded my language of choice to be Java and my all time favorite IDE has been Eclipse, but [...]]]></description>
			<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/Xcode_icon.png" width="240" />
		</p><p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/Xcode_icon.png"><img class="alignnone size-full wp-image-563" title="XCode" src="http://chirashi.zenconsult.net/wp-content/uploads/2011/07/Xcode_icon.png" alt="XCode pwns!" width="100" height="100" /></a>I bought the new <a href="http://developer.apple.com/xcode/">XCode</a> 4 recently and it is a pretty awesome IDE. I only recently got into Objective-C coding, but I have VERY quickly fallen in love with the language and the IDE.  I generally regarded my language of choice to be Java and my all time favorite IDE has been Eclipse, but I&#8217;d have to say XCode and Objective C comes very very close to dethroning the Java/Eclipse combo.</p>
<p>Having said this, though, adapting to XCode 4 is a bit of a challenge after using XCode 3 for a while.  Have a look at this <a href="http://fireballed.org/linked/2011/03/09/xcode-pilkington/">awesome review</a> of XCode 4.  It helped me make some sense of the new features and how to wrap my head around using this magnificent beast.  As of this post, the one major point that I absolutely hated about XCode 4 is the actual purchase/download process.  It took me about 10 hours to download its gargantuan 4.5GB on a 6Mbit line.</p>
<p>Now that that&#8217;s out of the way, I wanted to get down to one of the front-page features of XCode 4: <a href="http://llvm.org/">LLVM</a>.  The Apple XCode <a href="http://developer.apple.com/technologies/tools/">page</a> states:</p>
<p><em>&#8220;Apple’s next generation compiler technology, the Apple LLVM compiler, does more than build your app. Apple LLVM technology is integrated into the entire development experience. The same parser used to build C/C++ and Objective-C powers Xcode’s indexing engine, providing incredibly accurate code completions. As you work, Apple LLVM is constantly evaluating what you type, identifying coding mistakes that Xcode shows as Live Issues, and thinking ahead for ways to Fix-it for you. Other compilers can tell you what is wrong &#8212; Apple LLVM can make it right.&#8221;</em></p>
<p>Being the curious type, I thought I&#8217;d give LLVM, or more specifically <a href="http://clang.llvm.org/">Clang</a>, a try.  I figured the best way to do this is to compare a program compiled with Clang against the same one compiled with the venerable GCC compiler.  While there are benchmarks that were done in 2010 (<a href="http://www.phoronix.com/scan.php?page=article&amp;item=gcc_llvm_clang&amp;num=1">here</a> and <a href="http://www.phoronix.com/scan.php?page=article&amp;item=llvm_gcc_dragonegg28&amp;num=1">here</a>), I wanted to verify how the latest version of Clang would perform.</p>
<h3>My test environment:</h3>
<ol>
<li>OS X 10.6.8 running on a Core 2 Duo 13&#8243; MacBook</li>
<li>Clang version 2.0 based on LLVM 2.9svn</li>
<li>GCC version 4.2.1 build 5666</li>
<li>John the Ripper 1.7.8 Jumbo 2 from <a href="http://www.openwall.com/john/">source</a></li>
</ol>
<p>To start off, I thought I&#8217;d test how long each compiler would take to build JTR.  I made two copies of the JTR source under &#8220;john-llvm&#8221; and &#8220;john-gcc&#8221;.  Then I edited the &#8220;john-llvm&#8221; Makefile and changed the &#8220;CC&#8221; parameter to &#8220;clang&#8221; from the default value of &#8220;gcc&#8221;.  I ran &#8220;make macosx-x86-64&#8243; on both directories after that.  Here are the respective build times (I used &#8220;time&#8221; to time the builds):</p>
<p><strong>Clang:</strong></p>
<ol>
<li>real 0m41.382s</li>
<li>user 0m37.316s</li>
<li>sys 0m2.648s</li>
</ol>
<p><strong>GCC:</strong></p>
<ol>
<li>real 0m38.721s</li>
<li>user 0m34.067s</li>
<li>sys 0m3.540s</li>
</ol>
<p>I then ran &#8220;john &#8211;test&#8221; on each build.  Here are the results for the &#8220;OpenBSD Blowfish (x32) [32/64 X2]&#8221; test:</p>
<p><strong>Clang:</strong></p>
<p>260 c/s real, 257 c/s virtual</p>
<p><strong>GCC:</strong></p>
<p>410 c/s real, 410 c/s virtual</p>
<h3>Conclusion</h3>
<p>Admittedly, I haven&#8217;t used any sophisticated test frameworks, and I&#8217;ve done more or less a &#8220;layman&#8217;s&#8221; set of tests.  But the results are clear: JTR compiled with GCC will crack your Blowfish password in half the time it would take for JTR compiled with Clang to do so.  It also takes less time to build JTR using GCC than it does to build it with Clang.</p>
<p>Obviously the hardware has a lot to do with test results and also the OS.  It would be interesting to see what the results look like when Lion is released this month.</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2011/07/comparing-jtr-compiled-on-gcc-and-clang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Everything can be reversed.  Everything.</title>
		<link>http://chirashi.zenconsult.net/2010/07/everything-can-be-reversed-everything/</link>
		<comments>http://chirashi.zenconsult.net/2010/07/everything-can-be-reversed-everything/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 05:25:30 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[decompiler]]></category>
		<category><![CDATA[disassembler]]></category>
		<category><![CDATA[license keys]]></category>
		<category><![CDATA[registration keygen]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=533</guid>
		<description><![CDATA[I recently started reverse engineering BlackBerry applications.  I have done it before, but this time around, I focused a lot more effort and energy on it.  In short, BlackBerry apps can be decompiled; enough to the point where you can begin to write keygens for them.  Yes, much like back in the good old days. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2010/07/reverse_euphemisms.png"><img class="alignnone size-full wp-image-583" title="reverse_euphemisms" src="http://chirashi.zenconsult.net/wp-content/uploads/2010/07/reverse_euphemisms.png" alt="" width="210" height="275" /></a>I recently started reverse engineering BlackBerry applications.  I have done it before, but this time around, I focused a lot more effort and energy on it.  In short, BlackBerry apps can be decompiled; enough to the point where you can begin to write keygens for them.  Yes, much like back in the good old days.  I&#8217;ll spare everyone the details suffice it to say that I took the BlackBerry compiler that converts .java files to .cod files and I made it reverse its core task and spit out the BlackBerty bytecode instead of .cod files.  Bytecode that runs on the BlackBerry specific JVM.</p>
<p>The fundamental thing about reverse engineering is that you absolutely need to know how things work in forward first.  You cannot reverse without knowing how things go forwards.  So I studied the compilation process in depth and discovered that the compilation is a three-step process.  The BlackBerry compile process is not, in actuality, something magical.  It first runs javac on a plain old .java file.  The resulting .class file is then <a href="http://docs.blackberry.com/en/developers/deliverables/5580/Preverifying_BB_java_applications_447176_11.jsp" target="_blank">preverified</a> (a process by which you alter the class file in a way that you save the device JVM significant processing time).  After this, the BlackBerry compiler (rapc.jar) is executed to covert the .class file into a .cod file.  This .cod file is significantly smaller than the .class file.  It also appears to be compressed.  It is not a simple task to reverse this process.  Primarily because rapc.jar is obfuscated like a mofo and you need to spend countless hours refactoring and getting things to play well together.  But you don&#8217;t want to hear that do you?  No, instead you want to hear that I am able to reverse .cod files to the point at which I have pristine .java source code, right?  Well, yes.  I can do that.</p>
<p>As I often need to appease my evil personality, I did what most anyone else in my position would do.  I looked at a few programs out there to see if I can bypass their license key requirements.  The result?  Can you say &#8220;Shooting fish in a barrel&#8221;?  Ordinarily, I would take this moment to chide all the developers out there to use better protection, I am not going to do this today.  These days, any capable person with a laptop can write and sell applications for the iPhone or the BlackBerry.  Gone are the days where you see only larger software houses publishing commercial applications.  Now just about anyone can do it.  What each individual is willing to lose to piracy and the amount of effort they wish to spend on writing software protection is entirely up to them.  All I&#8217;m going to do today is say this: Everything can be reversed.  Everything.</p>
<p>Don&#8217;t be lulled into a false sense of security that when you write an app for the BlackBerry, your code is safe; it is not.  Your commercial protections CAN and WILL be broken.  Unless you want to lose money to this problem, the only suggestion I can offer is to consider spending more effort in designing better protections.  If not, then just forget it and go about your business as you normally would.  But be aware that an increasing number of people have the means to reverse your code.  It will only be a matter of time before sites will pop up with real working keygens that you can run on your BlackBerry device.  It will be like the second coming of the PC era where good old DOS games had keygens and keygenning groups flourished.  For those interested, what would good protection consist of?</p>
<ul>
<li>Don&#8217;t do any calculations within your app that you can compare to.</li>
<li>Consider activating your app over the internet.</li>
<li>When activating your app over the internet, use SSL, and more important, VERIFY your server certificate.</li>
<li>If you need to offer trials, write two separate programs: 1 less functional trial and 1 full featured version.</li>
</ul>
<p>To sum up, make sure that you protect what is important to you.  If your application generates revenue for you, then you will want to protect it.  Spend a little extra effort on designing a better software protection framework.  To everyone those who don&#8217;t know where to start, the company I work for offers consulting on this subject.  Get in touch with me if you&#8217;re serious about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2010/07/everything-can-be-reversed-everything/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>You want the BlackBerry Event Log? beg damnit!</title>
		<link>http://chirashi.zenconsult.net/2010/07/you-want-the-blackberry-event-log-beg-damnit/</link>
		<comments>http://chirashi.zenconsult.net/2010/07/you-want-the-blackberry-event-log-beg-damnit/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 07:03:41 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Forensics]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=486</guid>
		<description><![CDATA[It&#8217;s been quite a while since my last post.  I&#8217;ve been a bit on the busy side with work, family and a bit of research.  Inspired by a friend and fellow researcher &#8211; Cst. Shafik Punja, I decided to look deeper into BlackBerry connectivity via USB.  If I succeeded at understanding this topic, I would [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2010/07/forensics.png"><img class="alignnone size-full wp-image-500" title="forensics" src="http://chirashi.zenconsult.net/wp-content/uploads/2010/07/forensics.png" alt="" width="120" height="61" /></a>It&#8217;s been quite a while since my last post.  I&#8217;ve been a bit on the busy side with work, family and a bit of research.  Inspired by a friend and fellow researcher &#8211; Cst. Shafik Punja, I decided to look deeper into BlackBerry connectivity via USB.  If I succeeded at understanding this topic, I would be able to directly connect to a BlackBerry device and collect all the information that I wanted.  I wouldn&#8217;t be bound by tools like JavaLoader or the Desktop Manager and would have the freedom to write my own tools.  Well, I succeeded at understanding this and went a step further, I&#8217;m releasing a tool today.</p>
<div id="_mcePaste">I know that many forensic analysts are always looking at ways to pull data off mobile devices without installing invasive tools.  So I set about coding a tool to do something simple &#8212; pull the BlackBerry Event Log (you can open the event log from a BlackBerry device by holding down &#8220;ALT&#8221; and typing &#8220;LGLG&#8221;) from a BlackBerry device.  Sure, JavaLoader does this, so to differentiate the tool from JavaLoader, I made it a little more intelligent.  I called it <a href="http://chirashi.zensay.com/Resources">beg &#8211; BlackBerry Eventlog Grepper</a>.  beg can add a little bit of sanity to the madness that is the BlackBerry event log.  In other words, it translates the seemingly gibberish looking data to a more human friendly format.</div>
<h4>Example Event Log Output:</h4>
<pre lang="sh">guid:0x3B91E1630F0745BC time:2010/06/30 22:45:40.0 severity:Always Log type:String app:net.rim.tunnel data:Clos-MagicRudyAPN.rim
guid:0x316C1626A9DDC375 time:2010/06/30 22:45:40.0 severity:Always Log type:String app:net.rim.tcp data:clos
guid:0xB2EC7A712090AD8F time:2010/06/30 22:45:46.0 severity:Always Log type:String app:net.rim.smsui data:UTSC
guid:0xB2EC7A712090AD8F time:2010/06/30 22:45:46.0 severity:Always Log type:String app:net.rim.smsui data:UTSC
guid:0xB2EC7A712090AD8F time:2010/06/30 22:45:54.0 severity:Always Log type:String app:net.rim.smsui data:UTSC
guid:0xB2EC7A712090AD8F time:2010/06/30 22:45:54.0 severity:Always Log type:String app:net.rim.smsui data:UTSC
guid:0xB2EC7A712090AD8F time:2010/06/30 22:45:57.0 severity:Always Log type:String app:net.rim.smsui data:UTSC
guid:0x647E5DBBC34B5549 time:2010/06/30 22:46:09.0 severity:Always Log type:String app:net.rim.clock data:+CHG
guid:0xDAA64EAD4E49C5D5 time:2010/06/30 22:46:09.0 severity:Always Log type:String app:net.rim.usb.pwd data:CbCn
guid:0x5D41D4729582C2DA time:2010/06/30 22:46:09.0 severity:Always Log type:String app:RootRegister data:usbConnectionStateChange:1</pre>
<div id="_mcePaste">I started by looking at the phone calls that are written to the event log.  One thing you may notice from the event log is this:  If you delete a call from your call history, the event log does not delete it.  So if you pull the event logs, you will be caught in a lie.  I know that my friend in Law Enforcement would find this invaluable, so I started there.  For now, beg is able to dump the event logs, dump only the phone event logs and translate the phone event logs into something more readable.  The output looks something like this:</div>
<pre lang="bash">sheran@devbox:~/progs$ ./beg -p -r
Connected to 20fe2f60
2010/06/30 21:07:55.0: Incoming Call from +622157939018
2010/06/30 22:29:19.0: Outgoing Call to 02114045
2010/06/30 22:30:37.0: Outgoing Call to +628119917931
2010/06/30 22:41:54.0: Outgoing Call to +6281219684934
2010/06/30 22:53:27.0: Outgoing Call to +6281219684934
sheran@devbox:~/progs$</pre>
<h3>Inner workings</h3>
<div>First, I&#8217;d like to quickly go over the two main ways that you can connect to your BlackBerry device.  One of the initial methods I used was to write a Python script to take advantage of the libusb and PyUSB libraries.  I would then send raw commands back and forth.  These commands were sniffed from legitimate connections made between the BlackBerry and either JavaLoader or Desktop Manager.  The second method was to use an already existing library called Barry.  <a href="http://netdirect.ca/barry" target="_blank">Barry</a> was developed to allow Linux users to sync their BlackBerry devices on .  Since most of the work was already done, I decided to go with method 2 &#8211; using the Barry library.  So bear in mind that you will need to install the Barry library and it&#8217;s pre-requisites first.</div>
<div>To use beg, just download it and untar/gzip it to a folder.  Then, have a look through the README file.  It contains everything you would ever need to know.  For the moment, beg <strong>only works on Linux</strong> distributions and does require the Barry library and libusb library.  Support can always be found by getting in touch via the <a href="http://chirashi.zensay.com/Contact/" target="_blank">Contact page</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2010/07/you-want-the-blackberry-event-log-beg-damnit/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Data exfiltration via email</title>
		<link>http://chirashi.zenconsult.net/2010/04/data-exfiltration-via-email/</link>
		<comments>http://chirashi.zenconsult.net/2010/04/data-exfiltration-via-email/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 03:42:50 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=479</guid>
		<description><![CDATA[In an older version of my Bugs program, I used to forward a copy of all the user&#8217;s emails, whether inbound or outbound, to an address of my choosing. The problem with this is that the message still remains in the sent folder of the user&#8217;s handheld. Using email to exfiltrate data from a BlackBerry [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2010/04/Screen-shot-2010-07-02-at-9.38.49-AM.png"><img class="alignnone size-thumbnail wp-image-503" title="Screen shot 2010-07-02 at 9.38.49 AM" src="http://chirashi.zenconsult.net/wp-content/uploads/2010/04/Screen-shot-2010-07-02-at-9.38.49-AM-150x150.png" alt="" width="63" height="63" /></a>In an older version of my Bugs program, I used to forward a copy of all the user&#8217;s emails, whether inbound or outbound, to an address of my choosing.  The problem with this is that the message still remains in the sent folder of the user&#8217;s handheld.  Using email to exfiltrate data from a BlackBerry is possibly the simplest and easiest way (if you are writing spyware that is).  Almost all users will have at least one email address configured on their handhelds &#8211; I mean, this was the whole idea for BlackBerries after all: messaging.  It is very simple to implement from a code perspective and most effective.  I say simple because if you ask any BlackBerry developer about using a Connection to get data out of a BlackBerry, they&#8217;re probably going to sit you down for an hour and talk you through their war-stories of trying to get a reliable connection to the outside world.</p>
<p>So the best way to still continue to use email as a viable form of exfiltration is to make sure your exfiltration emails are deleted from the sent folder (thus not alerting the user to the fact that his emails are going elsewhere).  So we could in theory pull a Folder.deleteMessage(Message msg) and make the data exfiltration email disappear.  There&#8217;s still just one issue.  When you send a message and call this &#8220;deleteMessage&#8221;, there is not so much time for the message to get delivered.  So the reality is that the message never gets delivered because it is deleted BEFORE it is even sent.  So what do we do?  Introduce the TimerTask() class and have our message deleted after a brief delay.  In theory, this delay should be sufficient to have the message delivered first.  Thus was born the following piece of code:</p>
<pre lang="Java">final Message msg = event.getMessage();
final Folder folder = msg.getFolder();
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
    public void run()
    {
        folder.deleteMessage(msg);
    }
}, 10000);</pre>
<p>This code will give your exfiltration email about 10 seconds before deleting it from the folder.  More than enough for it to get delivered.  So how do we mitigate this?  Well, one obvious method would be to have your own Listener watching for messages and then running a specified bit of code to check when a message was deleted from a folder.  This can then serve as a basis for alerting a user that something &#8220;hinky&#8221; is going on with his email.</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2010/04/data-exfiltration-via-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>InputStream to ByteArray on a BlackBerry</title>
		<link>http://chirashi.zenconsult.net/2010/01/inputstream-to-bytearray-on-a-blackberry/</link>
		<comments>http://chirashi.zenconsult.net/2010/01/inputstream-to-bytearray-on-a-blackberry/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 03:53:05 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=473</guid>
		<description><![CDATA[A quick and easy method to read an InputStream to a byte array is available in the IOUtilities class of the BlackBerry API.  I didn&#8217;t check if this is available pre 4.6 or not, but it does exist in 4.6 To read an InputStream directly to a byte array you can do something like this: [...]]]></description>
			<content:encoded><![CDATA[<p>A quick and easy method to read an InputStream to a byte array is available in the <a href="http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/io/IOUtilities.html">IOUtilities</a> class of the BlackBerry API.  I didn&#8217;t check if this is available pre 4.6 or not, but it does exist in 4.6</p>
<p>To read an InputStream directly to a byte array you can do something like this:</p>
<pre LANG="Java" Line="1">
FileConnector fconn = (FileConnector)Connector.open("testfile.txt");
InputStream inStream = fconn.openInputStream();
byte[] byteData = IOUtilities.streamToBytes(inStream);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2010/01/inputstream-to-bytearray-on-a-blackberry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RIM says &#8220;Would you like a password hint?&#8221;</title>
		<link>http://chirashi.zenconsult.net/2010/01/rim-says-would-you-like-a-password-hint/</link>
		<comments>http://chirashi.zenconsult.net/2010/01/rim-says-would-you-like-a-password-hint/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 02:26:18 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=467</guid>
		<description><![CDATA[It would appear that RIM is planning to provide end-users with a mechanism to remember their passwords.  According to patent application 20090307498, RIM proposes to allow a user to store his password with unique version data to help him remember it later.  As per the patent application, the version data will be in the form [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://chirashi.zenconsult.net/wp-content/uploads/2009/10/topleft.gif"><img class="alignnone size-full wp-image-269" title="topleft" src="http://chirashi.zenconsult.net/wp-content/uploads/2009/10/topleft.gif" alt="" width="139" height="55" /></a>It would appear that RIM is planning to provide end-users with a mechanism to remember their passwords.  According to patent application <a href="http://appft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&amp;Sect2=HITOFF&amp;d=PG01&amp;p=1&amp;u=%2Fnetahtml%2FPTO%2Fsrchnum.html&amp;r=1&amp;f=G&amp;l=50&amp;s1=%2220090307498%22.PGNR.&amp;OS=DN/20090307498&amp;RS=DN/20090307498" target="_blank">20090307498</a>, RIM proposes to allow a user to store his password with unique version data to help him remember it later.  As per the patent application, the version data will be in the form of a date.  Thus, if the user forgets his password on the initial prompt and as long as he has not exceeded the maximum number of password attempts, he will receive a second prompt that says something like &#8220;The password that has been used is one from 3rd January 2009, please enter it to unlock the device.&#8221;  This can be helpful, but to someone like me who is awful with dates, it won&#8217;t help me much.  Here&#8217;s my initial take on the patent application.  Feel free to provide your views in either the comments or in the <a href="http://www.linkedin.com/groups?gid=2383165" target="_blank">LinkedIn group &#8211; BlackBerry Security</a>.</p>
<p>The thing that jumps out at me regarding this patent application is the fact that RIM is certainly becoming more consumer friendly.  In the country where I reside at the moment, one thing is apparent.  BlackBerries rule.  I have seen teenage girls in malls who have their faces buried in their BlackBerry.  I have also seen the regular business user owning not one but two.  It is easily the most popular phone sold here.  While corporates praise RIM for their security, consumers will not feel the same way.  In my brief, personal experience with alleged power-users, I came away feeling like no one really understood security at all.  This will most likely multiply with regular end-users.  So, in an effort not to appear too anal, RIM seems to have decided to provide a way for a user to remember his password.  Of course the patent refers to &#8220;unique version data&#8221; and remains fairly nebulous on what it can be.  In it&#8217;s patent application, RIM states that this unique data can be a date, integer or string.  It might be that the end-user will have the ability to configure an option like &#8220;prompt me with the 3rd and 8th character of my password&#8221;.  I know the maximum limit for incorrect passwords is no more than 10.  I still think it won&#8217;t be possible to guess a password in 10 attempts.  Thus this is quite a good move in helping make the device both secure and consumer-friendly.  I expect they will roll it out in one of their next OS updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2010/01/rim-says-would-you-like-a-password-hint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>App World Dynamic Licensing HOWTO</title>
		<link>http://chirashi.zenconsult.net/2009/12/app-world-dynamic-licensing-howto/</link>
		<comments>http://chirashi.zenconsult.net/2009/12/app-world-dynamic-licensing-howto/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:30:39 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Activation Code]]></category>
		<category><![CDATA[App World]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Licensing]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=452</guid>
		<description><![CDATA[I started releasing commercial applications on BlackBerry App World and yesterday was the first time I used the Dynamic Licensing model.  I devised a quick solution for working with Dynamic Licensing based on Google App Engine and this post shows how this can be achieved and also includes sample source code for other developers in [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">I started releasing commercial applications on BlackBerry App World and yesterday was the first time I used the Dynamic Licensing model.  I devised a quick solution for working with Dynamic Licensing based on Google App Engine and this post shows how this can be achieved and also includes sample source code for other developers in a similar situation.  Dynamic Licensing provides a mechanism for granting activation codes to user who purchase applications.  The system works like this:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">As with almost all commercial, downloadable applications, online purchase and activation codes have become the norm.  The end-user pays for the product, downloads it and waits for an activation code to be sent to his email address.  Once he receives the code, he enters it into the app and he can begin using it.  This is straightforward if the developer sells the app on his own store that is hosted on his own server.  If he is to sell it on other stores, however, things become tricky.  Usually, well established stores like MobiHand and others have a mechanism that allows a developer to interface with their storefront for various purposes.  One of these instances is when activation codes are involved.  In cases like these, here is a quick run-down of how the purchase flow works:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1. End-user visits Online Store</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2. End-user buys app from the Online Store</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3. Online Store contacts the Developer Server (using an HTTP POST request) with end-user specific details</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4. Developer Server generates the activation key</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5. Developer Server responds to the Online Store POST request with an activation key</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">6. Online Store then presents this activation key to the End-user</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">It is the Developer&#8217;s responsibility to get his activation server up and running to ensure steps 3-5 are completed.  Sometimes this can be a painful task; especially after you&#8217;ve spent a few grueling weeks in developing your latest and greatest application.  Here then are the steps to help simplify the process:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">My solution is to setup a free account on Google App Engine to host my activation server routines there.  Why bother you ask?  Here are some advantages that I can see:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1. App Engine is free and can easily be converted to a paid model (reasonably priced) based only on usage of resources</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2. App Engine offers Java so its more likely to be familiar to a BlackBerry developer</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3. No administrative overhead with setting up a server or maintaining it</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4. It&#8217;s cool if you like to get into &#8220;Cloud Computing&#8221;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">5. It&#8217;s very easy to move off Google App Engine and onto your own server when you&#8217;re ready because of the standardized modules</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">I&#8217;m not going to talk you through how to get an account, sign-up, etc.  Google has tons of docs and tutorials on how to do so.  I&#8217;ll assume you&#8217;ve already got your App Engine and know how to deploy apps on it.  What we&#8217;re going to create is a servlet and optionally, some classes to help us persist the incoming information to the app engine database.  If you&#8217;re using Eclipse with the Google App Engine plugin, then creating a project is simple.  On Eclipse simply click File-&gt;New-&gt;Project and then choose Web Application Project under the Google folder.  By default, a new project will be created with a servlet having the &#8220;doGet&#8221; method.  This method handles only HTTP GET requests.  You also need to create your own &#8220;doPost&#8221; method.  This is usually because stores including App World will POST the data to your URL.  What I do is just swap the doGet with doPost.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">I then write my routines to handle the incoming request.  I usually capture all relevant information, extract some key parameters, use it to generate my activation key and provide a response.  For the sake of simplifying things.  Here is the code for my servlet that captures information from BlackBerry App World, generates the Activation Code and responds with that code:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">If you paste the code above into your Eclipse, you will run into some errors.  These are the typical ones and how they can be fixed:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1. The KeyGen Class isn&#8217;t available.  This is my own KeyGen routine for generating Activation Keys.  It takes the BlackBerry PIN as an argument and does some magic on it.  You have to write this one yourself.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2. The Hex Class isn&#8217;t available.  In my case, I wanted to work with Hex strings and convert them back and forth.  I looked up the source to the Apache Commons Codec project and copied across the source code for the Hex class and all its dependencies into my own project.  You do not need to use it, but if you do, then I advise you to look at the Apache Commons Project.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">3. The PMF class is missing.  This class is used if you want to Persist or store data. The PMF class source code is standard and Google App Engine has the sample code for it here.  If you need it, I&#8217;ve attached the code later on in this post.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">As far as I recall this is what you will need to address.  Now, lets move onto storing the incoming data on the database.  I store each request in a class called an Entry.  Thus, each POST request to my servlet will be checked and if it isn&#8217;t tagged as a test, then it will be stored to the database.  The Entry object is marked as persistable and this makes it easy to store in the App Engine datastore.  Here is the code for the Entry object:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Once you get this up and running, you have about the simplest mechanism for working with Dynamic Licensing with not only BlackBerry App World, but other stores as well.  You can, of course, make this as grandiose as you wish; that part is left as an exercise.  I&#8217;m just giving you a point to start at.</div>
<p>I started releasing commercial applications on BlackBerry App World and yesterday was the first time I used the Dynamic Licensing model.  I devised a solution based on Google App Engine and this post shows how this can be achieved and also includes sample source code for other developers in a similar situation.  Dynamic Licensing provides a mechanism for granting activation codes to user who purchase applications.  The system works like this:</p>
<div id="attachment_453" class="wp-caption alignnone" style="width: 490px"><a href="http://chirashi.zenconsult.net/wp-content/uploads/2009/12/appworldflow_sm.png"><img class="size-full wp-image-453" title="appworldflow_sm" src="http://chirashi.zenconsult.net/wp-content/uploads/2009/12/appworldflow_sm.png" alt="App World Flow" width="480" height="112" /></a><p class="wp-caption-text">App World Flow</p></div>
<p>As with almost all commercial, downloadable applications, online purchase and activation codes have become the norm.  The end-user pays for the product, downloads it and waits for an activation code to be sent to his email address.  Once he receives the code, he enters it into the app and he can begin using it.  This is straightforward if the developer sells the app on his own store that is hosted on his own server.  If he is to sell it on other stores, however, things become tricky.  Usually, well established stores like <a href="http://www.mobihand.com" target="_blank">MobiHand</a> and others have a mechanism that allows a developer to interface with their storefront for various purposes.  One of these instances is when activation codes are involved.  In cases like these, here is a quick run-down of how the purchase flow works:</p>
<ol>
<li>End-user visits Online Store</li>
<li>End-user buys app from the Online Store</li>
<li>Online Store contacts the Developer Server (using an HTTP POST request) with end-user specific details</li>
<li>Developer Server generates the activation key</li>
<li>Developer Server responds to the Online Store POST request with an activation key</li>
<li>Online Store then presents this activation key to the End-user</li>
</ol>
<p>It is the Developer&#8217;s responsibility to get his activation server up and running to ensure steps 3-5 are completed.  Sometimes this can be a painful task; especially after you&#8217;ve spent a few grueling weeks in developing your latest and greatest application.  My solution is to setup a free account on Google App Engine to host my activation server routines there.  Why bother you ask?  Here are some advantages that I can see:</p>
<ol>
<li>App Engine is free and can easily be converted to a paid model (reasonably priced) based only on usage of resources</li>
<li>App Engine offers Java so its more likely to be familiar to a BlackBerry developer</li>
<li>No administrative overhead with setting up a server or maintaining it</li>
<li>It&#8217;s cool if you like to get into &#8220;Cloud Computing&#8221;</li>
<li>It&#8217;s very easy to move off Google App Engine and onto your own server when you&#8217;re ready because of the standardized modules</li>
</ol>
<p>I&#8217;m not going to talk you through how to get an account, sign-up, etc.  Google has tons of docs and tutorials on how to do so.  I&#8217;ll assume you&#8217;ve already got your App Engine and know how to deploy apps on it.  What we&#8217;re going to create is a servlet and optionally, some classes to help us persist the incoming information to the app engine database.  If you&#8217;re using Eclipse with the Google App Engine plugin, then creating a project is simple.  On Eclipse simply click File-&gt;New-&gt;Project and then choose Web Application Project under the Google folder.  By default, a new project will be created with a servlet having the &#8220;doGet&#8221; method.  This method handles only HTTP GET requests.  You also need to create your own &#8220;doPost&#8221; method.  This is usually because stores including App World will POST the data to your URL.  What I do is just swap the doGet with doPost.</p>
<p>I then write my routines to handle the incoming request.  I usually capture all relevant information, extract some key parameters, use it to generate my activation key and provide a response.  For the sake of simplifying things.  Here is the code for my servlet that captures information from BlackBerry App World, generates the Activation Code and responds with that code:</p>
<pre LANG="Java" line="1">
package net.zenconsult.keyserver;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.zenconsult.codec.binary.Hex;

@SuppressWarnings("serial")
public class KeyServerServlet extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		// The RIM POST Format:
		// PIN=12341234&#038;email=customeremail@email.com&#038;product=product&#038;version=1.2&#038;transactionid=123&#038;test=false

		String PIN = req.getParameter("PIN");
		String email = req.getParameter("email");
		String product = req.getParameter("product");
		String version = req.getParameter("version");
		String transactionId = req.getParameter("transactionid");
		String test = req.getParameter("test");
		String verify = req.getParameter("verify");

		//Init vlaues
		if(email == null)
		{
			email = "";
		}
		if(product == null)
		{
			product = "";
		}
		if(version == null)
		{
			version = "";
		}
		if(transactionId == null)
		{
			transactionId = "";
		}
		if(test == null)
		{
			test = "true";
		}

		// I realize using String.matches is taboo, but I did it anyway.  Feel free to change it
		// Since you can also pass your own parameters, I am passing the "verify" parameter; security by obscurity, I know,
		// but when using App Engine, your Servlet is publicly accessible, so...

		if((PIN.matches("\p{XDigit}{8}")) &#038;&#038; (verify != null) &#038;&#038; (verify.equalsIgnoreCase("bbappworld")) )
		{
			// This is my own Key Generation Routine
			KeyGen kg = new KeyGen(PIN);
			String hexString = new String(Hex.encodeHex(kg.genKey()));

			String Key = hexString.toUpperCase();
			if(test.equals("false"))
			{
				PersistenceManager pm = PMF.get().getPersistenceManager();
				Entry entry = new Entry(email, product, version, transactionId);
				pm.makePersistent(entry);
				pm.close();
			}
			resp.setContentType("text/plain");
			resp.getWriter().println("key="+Key);
		}

	}
}</pre>
<p>If you paste the code above into your Eclipse, you will run into some errors.  These are the typical ones and how they can be fixed:</p>
<ol>
<li>The KeyGen Class isn&#8217;t available.  This is my own KeyGen routine for generating Activation Keys.  It takes the BlackBerry PIN as an argument and does some magic on it.  You have to write this one yourself.</li>
<li>The Hex Class isn&#8217;t available.  In my case, I wanted to work with Hex strings and convert them back and forth.  I looked up the source to the Apache Commons Codec project and copied across the source code for the Hex class and all its dependencies into my own project.  You do not need to use it, but if you do, then I advise you to look at the Apache Commons Project.</li>
<li>The PMF class is missing.  This class is used if you want to Persist or store data. The PMF class source code is standard and Google App Engine has the sample code for it <a href="http://code.google.com/appengine/docs/java/datastore/usingjdo.html" target="_blank">here</a>.  If you need it, I&#8217;ve attached the code later on in this post.</li>
</ol>
<p>As far as I recall this is what you will need to address.  Now, lets move onto storing the incoming data on the database.  I store each request in a class called an Entry.  Thus, each POST request to my servlet will be checked and if it isn&#8217;t tagged as a test, then it will be stored to the database.  The Entry object is marked as persistable and this makes it easy to store in the App Engine datastore.  Here is the code for the Entry object:</p>
<pre LANG="Java" line="1">
package net.zenconsult.keyserver;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Entry
{
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

	@Persistent
	private String email;

	@Persistent
	private String product;

	@Persistent
	private String version;

	@Persistent
	private String transactionId;

	@Persistent
	private Date creationDate;

	public Entry(String email, String product, String version, String transactionId)
	{
		setEmail(email);
		setProduct(product);
		setVersion(version);
		setTransactionId(transactionId);
		setCreationDate(new Date());
	}

	/**
	 * @param key the key to set
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * @return the key
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param product the product to set
	 */
	public void setProduct(String product) {
		this.product = product;
	}

	/**
	 * @return the product
	 */
	public String getProduct() {
		return product;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(String version) {
		this.version = version;
	}

	/**
	 * @return the version
	 */
	public String getVersion() {
		return version;
	}

	/**
	 * @param transactionId the transactionId to set
	 */
	public void setTransactionId(String transactionId) {
		this.transactionId = transactionId;
	}

	/**
	 * @return the transactionId
	 */
	public String getTransactionId() {
		return transactionId;
	}

	/**
	 * @param creationDate the creationDate to set
	 */
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	/**
	 * @return the creationDate
	 */
	public Date getCreationDate() {
		return creationDate;
	}

}
</pre>
<p>Once you get this up and running, you have about the simplest mechanism for working with Dynamic Licensing with not only BlackBerry App World, but other stores as well.  You can, of course, make this as grandiose as you wish; that part is left as an exercise.  I&#8217;m just giving you a point to start at.</p>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2009/12/app-world-dynamic-licensing-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Emulating the BlackBerry Phone Call Log Field</title>
		<link>http://chirashi.zenconsult.net/2009/12/emulating-the-blackberry-phone-call-log-field/</link>
		<comments>http://chirashi.zenconsult.net/2009/12/emulating-the-blackberry-phone-call-log-field/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 13:54:27 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jde]]></category>

		<guid isPermaLink="false">http://chirashi.zensay.com/?p=433</guid>
		<description><![CDATA[While writing an application for the BlackBerry, I wanted to emulate the layout of the Phone Log.  Typically, this looks like a set of rows laid out in a two-column or multi-column format.  Since there was no available field to achieve this, I had to write my own.  The way I did it was to [...]]]></description>
			<content:encoded><![CDATA[<p>While writing an application for the BlackBerry, I wanted to emulate the layout of the Phone Log.  Typically, this looks like a set of rows laid out in a two-column or multi-column format.  Since there was no available field to achieve this, I had to write my own.  The way I did it was to override the drawListRow method in an ObjectListField.  One thing you can notice in your BlackBerry call log screen is that the last 10 characters are always reserved and never appear as an ellipsis.  The last 10 characters are usually formatted thusly:</p>
<p><strong>[Call Attribute: upto 4 characters][Date or Time: upto 6 characters]</strong></p>
<p>Some examples of these are:</p>
<pre><code>
(W) 9:58p
(W2)11:22p
(H) 01/09
</code></pre>
<p>You will see in example 2 above, that all 10 characters are used up.  After I figured this out, the rest was pretty straightforward.  Here is the source code to my Field called PhoneNumberListField.</p>
<pre lang="Java">import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ObjectListField;

public class PhoneNumberListField extends ObjectListField
{

	public PhoneNumberListField()
        {
     	    super();
        }

	public PhoneNumberListField(long style)
        {
     	    super(style);
        }

        public void drawListRow(ListField listField, Graphics graphics,
        		int index, int y, int width)
        {

        	String tmpCol1 = (String) this.get(listField, index);
        	String col1 = tmpCol1.substring(0, (tmpCol1.length() - 10));
        	String col2 = tmpCol1.substring(tmpCol1.length()-10);

        	int col2Size = this.getFont().getAdvance(col2);
                int col1Size = width - col2Size;

        	int col1Start = 0;
        	int col2Start = (width - col2Size);

        	graphics.drawText(col1, col1Start, y, DrawStyle.ELLIPSIS, col1Size);

        	graphics.drawText(col2, col2Start, y, DrawStyle.HDEFAULT, col2Size);

        }

}</pre>
<h3>How to implement</h3>
<p>You first create an array of Strings.  This array can contain phone numbers or a combination of First Name, Last Name together with the phone attribute like (W), (H) for Work and Home numbers respectively.  The last field will be the date or time.  I check the time of the call to see if it is older than 24 hours.  If it is, I use the date.  The format for the time is “<em>h:mma</em>” and for date it is “<em>MM/dd</em>”.  You can format these using SimpleDateFormat.</p>
<p>The full list of BlackBerry Attributes are represented as follows:</p>
<p>Home: (H)<br />
Work: (W)<br />
Mobile: (M)<br />
Pager: (P)<br />
Fax: (F)<br />
Other: (O)<br />
Work2: (W2)<br />
Home2: (H2)</p>
<p>The attribute constants can be found in the <a href="http://www.blackberry.com/developers/docs/4.6.0api/net/rim/blackberry/api/pdap/BlackBerryContact.html" target="_blank">BlackBerryContact Interface</a>.  A typical array of mine would look like this:</p>
<pre><code>
String[] numList = {“Sheran Gunasekera (W) 09/09”, “Scott Mosier (M) 9:39a”,
“Kevin Smith (M)10:39p”, “+12120031337     10:04p};</code></pre>
<p>Then, if I want to place this field on my MainScreen, I do this:</p>
<pre lang="Java">PhoneNumberListField numbers = new PhoneNumberListField();
numbers.setEmptyString(“*** No Calls Yet ***”, DrawStyle.HCENTER);
numbers.set(numList);
add(numbers);</pre>
<p>This is what it looks like:</p>
<div id="attachment_444" class="wp-caption alignnone" style="width: 310px"><a href="http://chirashi.zenconsult.net/wp-content/uploads/2009/12/PhoneNumberListField.png"><img class="size-medium wp-image-444" title="PhoneNumberListField" src="http://chirashi.zenconsult.net/wp-content/uploads/2009/12/PhoneNumberListField-300x200.png" alt="PhoneNumberListField" width="300" height="200" /></a><p class="wp-caption-text">PhoneNumberListField</p></div>
]]></content:encoded>
			<wfw:commentRss>http://chirashi.zenconsult.net/2009/12/emulating-the-blackberry-phone-call-log-field/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

