<?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>g3gg0.de &#187; reversing</title>
	<atom:link href="http://www.g3gg0.de/wordpress/category/reversing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g3gg0.de/wordpress</link>
	<description>g3gg0.de blog</description>
	<lastBuildDate>Mon, 05 Apr 2010 22:18:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[reciva] Encryption on Reciva Barracuda</title>
		<link>http://www.g3gg0.de/wordpress/reversing/reciva-encryption-on-reciva-barracuda/</link>
		<comments>http://www.g3gg0.de/wordpress/reversing/reciva-encryption-on-reciva-barracuda/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 01:52:07 +0000</pubDate>
		<dc:creator>geggo</dc:creator>
				<category><![CDATA[reversing]]></category>

		<guid isPermaLink="false">http://www.g3gg0.de/wordpress/?p=31</guid>
		<description><![CDATA[I helped a friend in reversing the firmware of some reciva internet radio module. Here are the results, explained in a few words he wrote down for interested readers.
Downloading from the Reciva Servers
Reciva has extended the open-source curl program for doing firmware downloads
(and possibly more) from its servers. They do not offer the source code [...]]]></description>
			<content:encoded><![CDATA[<p>I helped a friend in reversing the firmware of some reciva internet radio module. Here are the results, explained in a few words he wrote down for interested readers.</p>
<p><strong>Downloading from the Reciva Servers</strong></p>
<p>Reciva has extended the open-source curl program for doing firmware downloads<br />
(and possibly more) from its servers. They do not offer the source code which<br />
is probably ok because curl is covered by an MIT/X derivate license.</p>
<p>If you log into the Linux system which is running on the Barracuda radios,<br />
you can use curl to do downloads from the Reciva servers. e.g.:</p>
<pre>curl reciva://copper.reciva.com:6000/service-pack/sp255-c-106.bin &gt; sp255-c-106.bin</pre>
<p>When looking at the communication, it appears to be encrypted. So your radio<br />
talks home and you don&#8217;t know what it&#8217;s talking which isn&#8217;t exactly very<br />
polite for hardware you own. When looking at the exchanged data more exactly,<br />
the first 8 bytes transmitted to the Reciva server is the serial number, so<br />
Reciva knows which radio has downloaded which software. The first answer<br />
sent by the Reciva server are also 8 bytes which change every time that<br />
something has been successfully downloaded. These 8 bytes seem to be random,<br />
but they are not the encryption key. Instead, the encryption key is calculated<br />
from the random bytes. This is where the sernum daemon comes into play.</p>
<p><strong>The sernum daemon</strong></p>
<p>If you look at the process list, you&#8217;ll notice a program named &#8220;sernum&#8221;. It<br />
is responsible for reading the serial number and for handling encryption<br />
keys (see the next chapter on how this is done). Both curl and the main<br />
radio application (named &#8220;ir&#8221;) are talking to this daemon via a unix socket<br />
(/tmp/sernum).</p>
<p>The protocol is simple: sernum clients issue requests on the socket, and the<br />
sernum server responds. The following requests are known:</p>
<p>(&#8220;&gt;&#8221; means client to server, &#8220;&lt;&#8221; means server to client)</p>
<p>Read radio serial number.</p>
<p>&gt; \x03<br />
&lt; \x00\x01\x23\x45</p>
<p>Give encryption keys:</p>
<p>&gt; \x01\x8c\xe3\xbe\xb8\x6e\x2c\x26\x7f<br />
&lt; \x1e\xc9\x50\xc1\x66\xfa\xae\x84       // Download authorization token<br />
&gt; \x00\x1e\xc9\x50\xc1\x66\xfa\xae\x84<br />
&lt; \xab\x81\x64\x5e\x21\xaf\xaa\xf1       // DES keys<br />
&gt; \x00\xab\x81\x64\x5e\x21\xaf\xaa\xf1<br />
&lt; \xb2\x47\x30\x32\x87\x13\x98\x3a    // 3DES key, 1st part<br />
&gt; \x00\xb2\x47\x30\x32\x87\x13\x98\x3a<br />
&lt; \x45\x31\x39\xd9\xcd\x9f\x8e\x11     // 3DES key, 2nd part<br />
&gt; \x00\x45\x31\x39\xd9\xcd\x9f\x8e\x11<br />
&lt; \x61\x38\xb8\xc1\xde\x1e\x33\x4a     // 3DES key, 3rd part</p>
<p>Read version (probably the sernum protocol version):</p>
<p>&gt; \x04<br />
&lt; \x02</p>
<p>The sernum daemon doesn&#8217;t contain the serial number, nor does it perform the<br />
actual encryption. This is done by the Atmel MCU instead.</p>
<p><strong>The Atmel MCU</strong></p>
<p>The sernum daemon talks to the Atmel CPU via a three wire serial protocol<br />
(data, clock, acknowledge) by directly accessing the S3C2410 GPIO registers<br />
(via mmap()). The protocol used is similar to the /tmp/sernum one, but<br />
different command bytes are used. The algorithm used is probably XTEA, but<br />
the encryption key is unknown and probably depends on the serial number.</p>
<p><strong>The reciva protocol</strong></p>
<p>Now, back to the download process. As already mentioned above, the client<br />
sends its 8 byte serial number (ASCII encoded) to the server, which responds<br />
with an 8 byte challenge. From this challenge, the client calculates 3 byte<br />
sequences (download authorization token, DES key, 3DES key) with the help of<br />
the sernum daemon (which in turn uses the Atmel MCU).</p>
<p>The rest of the protocol is based on fixed size blocks with 3 types of blocks:<br />
Type 1: Download request block (256 bytes, DES-CBC encryption)<br />
Type 2: Data block (256 bytes, DES-CBC encryption)<br />
Type 3: Check block (192 bytes, 3DES-ECB encryption)</p>
<p>After the two initial PDUs (serial number, challenge), the client requests<br />
a file by sending a download request block. This block contains:<br />
8 byte authorization token + filename (&#8216;\0&#8242; terminated) + pad + checksum</p>
<p>The whole 256 byte block is then DES encrypted.</p>
<p>The checksum is the last byte of the block and contains the modulo 256 sum<br />
of the first 255 bytes. The pad seems to be random data, but does never<br />
contain an 0&#215;00 byte.</p>
<p>Now, the server sends the file contents in data blocks. After every 20th data<br />
block, a check block is sent.</p>
<p>The first data block contains an 8 byte header which contains the file size<br />
(4 bytes) and an unknown (maybe fixed) value (also 4 bytes). The header<br />
is followed by 246 bytes of payload, a single 0&#215;00 byte and a checksum<br />
(again, a simple modulo 256 sum).</p>
<p>All further (i.e. non-first) data blocks contain 254 bytes of payload,<br />
a single 0&#215;00 byte and a checksum.</p>
<p>All data blocks are DES encrypted, but note that the data block DES stream is<br />
encrypted independently of the download request block.</p>
<p>The check blocks do not contain any actual data. Instead, they repeat the<br />
last 192 bytes of the encrypted (!) preceding data block, with a 3DES-ECB<br />
encryption applied. In other words, the last 192 bytes of the already DES<br />
encrypted preceding data block is encrypted again (with 3DES-ECB this time)<br />
and then sent as some sort of check.</p>
<p>The DES and 3DES ciphers use fixed initialization vectors which are as<br />
follows:<br />
For DES:  \xbd\xe7\x32\x66\xb9\x46\xf3\xab<br />
For 3DES: \xed\x9e\xa8\x97\x7c\xee\xc8\xac</p>
]]></content:encoded>
			<wfw:commentRss>http://www.g3gg0.de/wordpress/reversing/reciva-encryption-on-reciva-barracuda/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
