<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Category: security | Sebastian Wilzbach]]></title>
  <link href="https://seb.wilzba.ch/categories/security/atom.xml" rel="self"/>
  <link href="https://seb.wilzba.ch/"/>
  <updated>2023-12-18T00:13:39+01:00</updated>
  <id>https://seb.wilzba.ch/</id>
  <author>
    <name><![CDATA[]]></name>
    <email><![CDATA[admin@wilzbach.me]]></email>
  </author>

  
  <entry>
    <title type="html"><![CDATA[Decrypting Threema's Android database]]></title>
    <link href="https://seb.wilzba.ch/b/2016/02/decrypting-threema/"/>
    <updated>2016-02-01T22:08:53+01:00</updated>
    <id>https://seb.wilzba.ch/b/2016/02/decrypting-threema</id>
    <content type="html"><![CDATA[<p>Most people probably enjoy New Year’s eve beneath a lovely firework with some
sparkling wine. Notwithstanding here is my New Year’s eve story.</p>

<h2 id="my-story">My story</h2>

<p>After I upgraded from Android M dev to Android M stable, I experienced a lot
of unknown issues with the app Threema. Eventually I managed to resolve them,
however I had to encrypt their Android database and as this is quite a complicated
task without given instructions, I wanted to share my insights.</p>

<p>You can find all detailed instructions and some helper scripts on <a href="https://github.com/wilzbach/threema-decrypt">github</a>.
These instructions should be straightfoward, so let me present some interesting
results that I obtained.</p>

<h2 id="contacts">Contacts</h2>

<p>By looking at the decrypted database, one can verify what information Threema
actually saves.
As you can see below the public key of every contact is stored and Threema internally only saves information that you expected it to save e.g. first and last name or the AndroidContactId when given.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sqlite&gt; .schema contacts
CREATE TABLE `contacts` (`identity` VARCHAR , `publicKey` BLOB , `firstName` VARCHAR , `lastName` VARCHAR , `publicNickName` VARCHAR , `verificationLevel` INTEGER , `state` VARCHAR DEFAULT 'ACTIVE' NOT NULL , `androidContactId` VARCHAR , `threemaAndroidContactId` VARCHAR , `isSynchronized` SMALLINT DEFAULT 0 , `featureLevel` INTEGER DEFAULT 0 NOT NULL , `color` INTEGER , `avatarExpires` BIGINT , PRIMARY KEY (`identity`) );
</code></pre></div></div>

<h2 id="messages">Messages</h2>

<p>Messages just contain their connected <code class="language-plaintext highlighter-rouge">apiMessageId</code>, <code class="language-plaintext highlighter-rouge">identity</code>, <code class="language-plaintext highlighter-rouge">body</code> and their interaction status (sent, delievered, read) - nothing more is tracked.
However I know that since March 2014 until 2015 I sent 16304 personal messages and received 13852 messages.</p>

<h2 id="groups">Groups</h2>

<p>Group messages are according to Threema’s <a href="https://threema.ch/press-files/cryptography_whitepaper.pdf">whitepaper</a> implemented with End-to-End encryption.</p>

<blockquote>
  <p>In Threema, groups are managed without any involvement of the servers. That is, the servers do not know which groups exist and which users are members of which groups</p>
</blockquote>

<p>If this being true, why is there an apiGroupId saved in the local database?</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>CREATE TABLE `m_group` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `apiGroupId` VARCHAR , `name` VARCHAR , `creatorIdentity` VARCHAR , `createdAt` VARCHAR , `synchronizedAt` BIGINT , `deleted` SMALLINT );
</code></pre></div></div>

<p><strong>Update</strong> The developer of Threema wrote a clarification (Thanks!)</p>

<blockquote>
  <p>The apiGroupId is a randomly generated unique id provided by the creator of the group and not the server (the name of the column might be a little misleading).
A group is uniquely identified by the combination of apiGroupId and creatorIdentity.</p>
</blockquote>

<h2 id="ballots-aka-surveys">Ballots (aka surveys)</h2>

<p>Ballots seem also to be implemented in End-to-End - so remember that all your friends can see
your vote. I personally had a couple of unclosed ballots (the owner already closed them
on his phone), just set them to closed and your annoyance has an end.</p>

<h2 id="media-files">Media files</h2>

<p>All locally stored media files are encrypted with one’s static key phase. 
With this <a href="https://github.com/wilzbach/threema-decrypt">code</a> you can decrypt them.</p>

<h2 id="acknowledgment">Acknowledgment</h2>

<p>A big thanks goes to the Threema developer for building this convenient end-to-end encrypted
cross-platform messenger and letting me publish the decompiled <a href="https://github.com/wilzbach/threema-decrypt">instructions</a>.</p>

<h2 id="next">Next</h2>

<p>Don’t forget to read Threema’s excellent <a href="https://threema.ch/press-files/cryptography_whitepaper.pdf">whitepaper</a> about their used
cryptography.</p>

<p>What do you plan to with your gained access to your Threema database?
Converting your message history to csv for archiving purposes? Extracting
the identities of your Threema friends? Let me know in the comments or on github!</p>

]]></content>
  </entry>
  
</feed>
