<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[On Cryptography and Security]]></title><description><![CDATA[Some thoughts I've actually managed to put into words.]]></description><link>https://blog.susanka.eu/</link><image><url>https://blog.susanka.eu/favicon.png</url><title>On Cryptography and Security</title><link>https://blog.susanka.eu/</link></image><generator>Ghost 2.5</generator><lastBuildDate>Wed, 29 Dec 2021 15:03:19 GMT</lastBuildDate><atom:link href="https://blog.susanka.eu/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Types of Bitcoin transactions - Part I]]></title><description><![CDATA[<p><em>This article assumes you have some knowledge how Bitcoin transactions work. If you're new into the world of cryptocurrencies I suggest you this <a href="https://lopp.net/bitcoin.html">starting page</a> or this awesome <a href="https://www.youtube.com/watch?v=bBC-nXj3Ng4">video</a> to kick it off.</em></p>
<h5 id="terminology">Terminology</h5>
<p>Let's assume Alice already received some coins from a previous transaction and she now wants to</p>]]></description><link>https://blog.susanka.eu/types-of-bitcoin-transactions-part-i/</link><guid isPermaLink="false">5be6dfff3b2d940001e81686</guid><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Tue, 15 Oct 2019 21:02:17 GMT</pubDate><content:encoded><![CDATA[<p><em>This article assumes you have some knowledge how Bitcoin transactions work. If you're new into the world of cryptocurrencies I suggest you this <a href="https://lopp.net/bitcoin.html">starting page</a> or this awesome <a href="https://www.youtube.com/watch?v=bBC-nXj3Ng4">video</a> to kick it off.</em></p>
<h5 id="terminology">Terminology</h5>
<p>Let's assume Alice already received some coins from a previous transaction and she now wants to send some to Bob.</p>
<p>In Bitcoin, each transaction has two important attributes. The <strong>scriptPubKey</strong> (also output or locking script) and the <strong>scriptSig</strong> (input/unlocking script). Alice decides at her sole discression what the scriptPubKey looks like. She uses a stack-based, Turing incomplete, Forth-like language called <a href="https://en.bitcoin.it/wiki/Script"><em>Script</em></a> to define conditions that Bob needs to fulfill in order to spend these coins at another occasion. Original name for a scripting language, right?</p>
<p>Alice usually creates the scriptPubKey based on some data Bob sends her. We call that data an <em>address</em> and in a simple transaction you may think of it as a bank account number. This address is usually the main part of the scriptPubKey accompanied by some other <em>Script</em> instructions.</p>
<p>When the transaction's output is about to be spent, the other script – scriptSig – is the proof that the previous transaction's scriptPubKey conditions were met.</p>
<p>As the Bitcoin network evolved, number of standard scriptPubKey/scriptSig pairs occured and that's exactly what we will look into in this article.</p>
<h4 id="p2pkpaytopublickey">P2PK (Pay-to-Public-Key)</h4>
<p>Once a upon time when the original Bitcoin <a href="https://bitcoin.org/bitcoin.pdf">paper</a> was drafted in 2008, there was only one single transaction type. The scriptPubKey is equal to the receiver's public key and the scriptSig is only a signature. The signature corresponds to a previous transaction's scriptPubKey's public key. The signature always corresponds to the previous transaction's scriptPubKey – that's how you prove you can spend it.</p>
<p>ScriptPubKey: <code>&lt;Bob's PublicKey&gt; OP_CHECKSIG</code><br>
ScriptSig: <code>&lt;Alice's Signature&gt;</code></p>
<p>During the validation this is concatenated to <strong>&lt; Signature &gt;</strong> <strong>&lt; Public Key &gt;</strong> OP_CHECKSIG and executed<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>. The OP_CHECKSIG checks the signature against the public key. If evaluted to <em>true</em> the transaction is valid.</p>
<p><em>The P2PK type is currently deprecated.</em></p>
<h4 id="p2pkhpaytopublickeyhash">P2PKH (Pay-to-Public-Key-Hash)</h4>
<p>In the previous P2PK transaction money are &quot;send to a public key&quot;. This public key is therefore visible in the blockchain and the defence that prevents Eve to steal Bob's money is the ECDSA signature algorithm, the infeasibility of deriving a private key from the public key, in particular.</p>
<p>What happens though when cryptography fails us in future? The quantum computers are coming and the ECDSA's underlying discrete logarithm problem doesn't hold on quantum computers (see <a href="https://en.wikipedia.org/wiki/Shor%27s_algorithm">Shor's algorithm</a>). The ones with posession of quantum computers would be theoretically able to derive private keys from the public keys visible in the blockchain. That sucks.</p>
<p>To mitigate this, Bitcoin creators came up with a simple improvement. Alice is provided only with a hash of Bob's public key. There are no known quantum algorithms defeating SHA-256 as of the moment. The scripts look as follows:</p>
<p>ScriptPubKey: <code>OP_DUP OP_HASH160 &lt;PublicKeyHash&gt; OP_EQUALVERIFY OP_CHECKSIG</code><br>
ScriptSig: <code>&lt;Signature&gt; &lt;PublicKey&gt;</code></p>
<p>As you can see the public key is actually still visible on the blockchain (in the scriptSig). It needs to be, becuase the bitcoin nodes couldn't validate the signature otherwise. The major improvement is that the public key is in the scriptSig, meaning that it is published only if the coins are spent but not when received.</p>
<p>If you would like to understand why the script looks this way, have a look on how it gets evaluated. The book <a href="https://www.bitcoinbook.info/"><em>Mastering Bitcoin</em></a> offers a nice step-by-step <a href="http://chimera.labs.oreilly.com/books/1234000001802/ch05.html#P2PubKHash1">visualisation</a>.</p>
<p>P2PKH is the most popular transaction type as up to date and represents the typical &quot;Alice pays Bob&quot; situation. If you've ever tried bitcoin, this is most likely what you have used. Bitcoin, however, offers more options and is not limited to such scenarios.</p>
<p>P2PKH addresses start with &quot;1&quot;.</p>
<h4 id="p2pshpaytoscripthash">P2PSH (Pay-to-Script-Hash)</h4>
<p>One of the more complicated scenario is the P2SH introduced in 2012 (<a href="https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki">BIP 16</a>). P2PSH addresses start with &quot;3&quot;.</p>
<p>ScriptPubKey: <code>OP_HASH160 &lt;redeemScriptHash&gt; OP_EQUAL</code><br>
ScriptSig: <code>&lt;Signature&gt; &lt;PubKey&gt; &lt;redeemScript&gt;</code></p>
<p>A redeem script is yet another <em>Script</em> script. It defines the conditions instead of the scriptPubKey and is then incorporated into the scriptSig. Bob is responsible for creating the script but does not send it to Alice in full. He rather hashes it and sends the hash to Alice. Alice then includes the hash in the scriptPubKey.</p>
<p>Only during the spending Bob reveals the script in scriptSig. The redeem script can look in any way, an example of it is:</p>
<p>redeemScript: <code>2 &lt;PubKey1&gt; &lt;PubKey2&gt; &lt;PubKey3&gt; &lt;PubKey4&gt; &lt;PubKey5&gt; 5 OP_CHECKMULTISIG</code></p>
<p>This is also very common usage of P2SH, the multisig. Even though P2SH != multisig, it is its most popular usage today.</p>
<p>Note, that <strong>the terminology here gets really confusing</strong>. Suddenly, the scriptPubKey doesn't have a public key, but some weird hash instead and there is yet another script - the redeem script. The name scriptPubKey is a historic one (made sense with P2PK, didn't it?), <em>input</em> or <em>locking</em> script would be a better choice.</p>
<p>That being said, I'm sticking with scriptPubKey and scriptSig for clarity.</p>
<h4 id="multisig">Multisig</h4>
<p>Multisig transactions were a different type on its own, but were depracted and multisig transactions are currently done using P2SH.</p>
<h4 id="op_return">OP_RETURN</h4>
<p>Return transactions are used for dumping arbitrary data on the blockchain. It is not covered here further.</p>
<h4 id="yourown">Your own</h4>
<p>Note, that theoretically the scriptPubKey can be anything within the scripting limits. If you wish to create a transaction with some silly condition, you can! We could totally create a scriptPubKey with a condition <code>1 OP_EQUAL</code>. The corresponding <code>scriptSig</code> is then just a number <code>1</code> to validate to true. With that scriptPubKey any user could then spend the coins by just providing <code>1</code>, which doesn't seem very useful. In a similar manner, you could provide a script <code>1 2 OP_EQUAL</code> forbiding anyone to further spend the money, therefore making it unspendable.</p>
<p>Although you can create such transaction you still have to wrap it in a redeem script and use a P2SH. Currently, only a set of standard transactions are allowed, most of them listed in this or the following article<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup>.</p>
<h4 id="segwit">Segwit</h4>
<p>Segwit is covered in the following <a href="https://blog.susanka.eu/p/a41227e4-372d-4cea-a107-bcc8c078d47f/">article</a>.</p>
<hr>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p>For security reasons the two scripts are actually executed seperately with the stack transferred, but that's an implementation detail we can omit. <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
<li id="fn2" class="footnote-item"><p>Historically, there was no such thing as a standard transaction and the scriptPubKey could indeed be arbitrary. Then Bitcoin decided to implement some restrictions and introduced standard transactions where the P2SH redeem scripts were also checked if they're standard or not. In 2014, this was <a href="https://github.com/bitcoin/bitcoin/pull/4365">relaxed</a> allowing redeem script to be any script (there are still some limits). <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
]]></content:encoded></item><item><title><![CDATA[Types of Bitcoin transactions - Part II Segwit]]></title><description><![CDATA[<p>In a <a href="https://blog.susanka.eu/types-of-bitcoin-transactions-part-ii-segwit/previous">previous</a> article we documented what some of the standard Bitcoin transactions are. In 2015, the Bitcoin developers came up with a number of improvements commonly referred to as a Segregated Witness – <em>SegWit</em>. The overall process was standardized mostly in  <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki">BIP141</a>, <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki">BIP143</a> and few others.</p>
<p>SegWit's main intention was</p>]]></description><link>https://blog.susanka.eu/types-of-bitcoin-transactions-part-ii-segwit/</link><guid isPermaLink="false">5be6dfff3b2d940001e81687</guid><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Tue, 15 Oct 2019 21:02:05 GMT</pubDate><content:encoded><![CDATA[<p>In a <a href="https://blog.susanka.eu/types-of-bitcoin-transactions-part-ii-segwit/previous">previous</a> article we documented what some of the standard Bitcoin transactions are. In 2015, the Bitcoin developers came up with a number of improvements commonly referred to as a Segregated Witness – <em>SegWit</em>. The overall process was standardized mostly in  <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki">BIP141</a>, <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki">BIP143</a> and few others.</p>
<p>SegWit's main intention was to remove transaction's signature out of the scriptSig (for a number of <a href="https://programmingblockchain.gitbooks.io/programmingblockchain/content/other_types_of_ownership/p2wpkh_pay_to_witness_public_key_hash.html">reasons</a>) and move it to another designated field, called <em>witness</em>. This led to the introduction of two new types, which we cover in this second article.</p>
<h4 id="segwittransactions">SegWit transactions</h4>
<p>A scriptPubKey that consists of a 1-byte push opcode followed by a data push between 2 and 40 bytes gets a special meaning. In another words, if a number between 0 to 16 is pushed onto the stack<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> and then some more data between 2 and 40 bytes are, the upgraded nodes recognize this as a SegWit transaction.</p>
<p>A general native SegWit transaction looks like this:</p>
<p>ScriptPubKey: <code>&lt;1 byte witness version&gt; &lt;2-40 bytes witness program&gt;</code><br>
ScriptSig:   <code>(empty)</code><br>
Witness:     <code>&lt;witness items&gt;</code></p>
<p>A non-upgraded node sees this as a ANYONE_CAN_SPEND transaction, because the scriptPubKey is just a push of some data and doesn't lay any conditions on the reciever. That's why the scriptSig can be empty and it is a valid tranaction on older nodes.</p>
<p>In SegWit world, the first value in the scriptPubKey is interpreted as a <strong>witness version</strong> and the second is a witness protected program, or just a <strong>witness program</strong> for short. The version flag denotes, how the witness program is evaluated. If a node encounters a witness version that it is unfamiliar with, it considers the transaction again as a ANYONE_CAN_SPEND, which allows further soft-fork compatible upgrades. As of today, there is only one witness version – version 0, so we are solely devoted to this version in this article.</p>
<p>When SegWit-aware node recognizes a witness version it supports, it interprets its witness program. In version 0 this starts of by checking the length of the witness program. If it is equal to 20 bytes, it is interpreted as a P2WPKH; if 32 bytes, it is a P2WSH. If it is neither 20 nor 32 bytes, it aborts. This is a version 0 convention hardcoded in the standard and the <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/standard.cpp#L66-L86">code</a> itself.</p>
<h4 id="p2wpkhpaytowitnesspublickeyhash">P2WPKH (Pay-to-Witness-Public-Key-Hash)</h4>
<p>This is the P2PKH described <a href="https://blog.susanka.eu/types-of-bitcoin-transactions-part-ii-segwit/todo">earlier</a>, only SegWit upgraded.</p>
<p>ScriptPubKey: <code>0 &lt;20-byte-PublicKeyHash&gt;</code><br>
ScriptSig:   <code>(empty)</code><br>
Witness:     <code>&lt;Signature&gt; &lt;PublicKey&gt;</code></p>
<p>In P2WPKH the verification goes as follows:</p>
<ul>
<li>Check that the witness contains exactly two items</li>
<li>Verify that HASH160 of the witness' public key is equal to the one present in the witness program</li>
<li>Verify the signature as <code>&lt;Signature&gt; &lt;PublicKey&gt; OP_CHECKSIG</code></li>
</ul>
<p>The length of the witness program (20 bytes) indicates that it is a P2WPKH type. Again, this is an arbitrary definition, hardcoded into the standard. There is no OP_CHECKSIG operand in neither scriptPubKey nor witness, it is implicit by the definition of P2WPKH.</p>
<h4 id="p2wshpaytowitnessscripthash">P2WSH (Pay-to-Witness-Script-Hash)</h4>
<p>Now, remember <a href="https://blog.susanka.eu/types-of-bitcoin-transactions-part-ii-segwit/todo">P2SH</a>? There is a native version of the very same principle for SegWit.</p>
<p>ScriptPubKey: <code>0 &lt;32-byte-redeemScriptHash&gt;</code><br>
ScriptSig:   <code>(empty)</code><br>
Witness:     <code>&lt;witness items&gt; &lt;redeemScript&gt;</code></p>
<p>RedeemScript: <code>(any)</code></p>
<p>The first 0 indicates a witness version 0. The following 32 bytes indicates that this is a P2WSH type. The last item in the witness is the redeemScript. It is hashed with SHA256, compared against the 32-byte redeemScriptHash in the scriptPubKey, and then executed alongside with the witness items.</p>
<p>If this seems a little bit too abstract, have a look at the BIP141 <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wsh">example</a>, which is a 1-of-2 multi-signature P2WSH.</p>
<p>Both P2WPKH and P2WSH are not using the traditional base58 addresses, but a new <em>bech32</em> format as defined in <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki">BIP173</a>. The format is not covered in the scope of this article, see the standard for more information.</p>
<hr>
<p>Those two represent so called <em>native</em> SegWit transaction types. To allow non-SegWit wallets to generate a SegWit transaction two additional types were introduced. It uses a P2SH transaction as the cornerstone and includes either P2WPKH or P2WSH inside it. If a SegWit-aware node sees a P2SH which contains P2WPKH or P2WSH it interprets it in the native way.</p>
<h4 id="p2wpkhnestedinp2sh">P2WPKH nested in P2SH</h4>
<p>ScriptPubKey: <code>OP_HASH160 &lt;20-byte-redeemScriptHash&gt; OP_EQUAL</code><br>
ScriptSig:   <code>&lt;0 &lt;20-byte-PublicKeyHash&gt;&gt;</code><br>
Witness:     <code>&lt;Signature&gt; &lt;PublicKey&gt;</code></p>
<p>RedeemScript: <code>0 &lt;20-byte-PublicKeyHash&gt;</code></p>
<p>The P2SH redeem script is equal to <code>0 &lt;20-byte-PublicKeyHash&gt;</code> which is exactly the same as P2WPKH scriptPubKey. The scriptSig is somewhat confusing, it is a canonical push of data, which contain another canonical push of data.</p>
<p>Let's have a look how this evalutes on older nodes. They see the scriptSig as a push of some data – <code>0014{20-byte-PublicKeyHash}</code>. Older nodes consider it as a simple redeemScript, which contains only a push of some data, weird redeemScript right? Then the scriptPubKey is concatenated and it does a HASH160 of the redeemScript and compares the result against the redeemScriptHash. Hurray, they match! So older nodes see this as a wierd P2SH ANYONE_CAN_SPEND transaction with no signature, where two hashes are compared and that's it.</p>
<p>As far as the upgraded nodes are concerned, they see this as as a P2SH transaction as well, but they recognize the meaning of the pushed data (<code>0014{20-byte-PublicKeyHash}</code>) and they interpret it as a P2WPKH.</p>
<h4 id="p2wshnestedinp2sh">P2WSH nested in P2SH</h4>
<p>This is quite similar to P2WPKH in P2SH. It just doesn't nest a P2WPKH but a P2WSH.</p>
<p>ScriptPubKey: <code>OP_HASH160 &lt;20-byte-P2SH-RedeemScriptHash&gt; OP_EQUAL</code><br>
ScriptSig:   <code>&lt;0 &lt;32-byte-P2WSH-RedeemScriptHash&gt;&gt;</code><br>
Witness:     <code>&lt;witness items&gt; &lt;P2WSH-RedeemScript&gt;</code></p>
<p>P2SH RedeemScript: <code>&lt;0 &lt;32-byte-P2WSH-RedeemScriptHash&gt;&gt;</code><br>
P2WSH RedeemScript: <code>(any)</code></p>
<p>The redeem script can be any valid Script script, the very same concept as in P2SH.</p>
<hr>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p>OP_x where x &lt;= 16 is a Script command that pushes the value of x onto the stack. That is exactly what is used here. OP_0 for a witness version 0, OP_1 for future version 1 etc. In another words, we can specify the witness version in one single opcode. <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
]]></content:encoded></item><item><title><![CDATA[Installing Manjaro on Lenovo IdeaPad 720s]]></title><description><![CDATA[<p><em>This is probably far from an ideal installation tutorial. It's more of a dump of how I've done this.</em></p>
<ul>
<li><code>dd</code> the install iso to a usb disk, you may follow a tutorial on the <a href="https://wiki.manjaro.org/index.php?title=Burn_an_ISO_File">Manjaro wiki</a>
<ul>
<li>don't forget to type sd[letter] without a partion name, e.g. /dev/sdX</li></ul></li></ul>]]></description><link>https://blog.susanka.eu/installing-manjaro-on-lenovo-ideapad-720s/</link><guid isPermaLink="false">5be6dfff3b2d940001e81688</guid><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Thu, 14 Dec 2017 23:38:44 GMT</pubDate><content:encoded><![CDATA[<p><em>This is probably far from an ideal installation tutorial. It's more of a dump of how I've done this.</em></p>
<ul>
<li><code>dd</code> the install iso to a usb disk, you may follow a tutorial on the <a href="https://wiki.manjaro.org/index.php?title=Burn_an_ISO_File">Manjaro wiki</a>
<ul>
<li>don't forget to type sd[letter] without a partion name, e.g. /dev/sdX not /dev/sdX1</li>
</ul>
</li>
<li>enter Lenovo's &quot;BIOS&quot; utility by pressing F2 during startup</li>
<li>set SATA Controller to ACHI in Configuration tab</li>
<li>set Boot Mode to Legacy Support in Boot tab</li>
<li>save settings</li>
<li>plug in your USB and press F12 during startup to enter Boot Manager</li>
<li>select EFI USB Device</li>
</ul>
<p>The Manjaro linux on the USB should boot up.</p>
]]></content:encoded></item><item><title><![CDATA[What are TLS extensions?]]></title><description><![CDATA[<p>The widespread Transport Layer Security protocol (TLS), a successor of the better-known SSL protocol, includes a very thoughtful mechanism to add an additional functionality to the protocol. Using the so-called extensions we can extend the TLS capabilities as we desire without actually modifying the protocol itself.</p>
<p>The extensions were firstly</p>]]></description><link>https://blog.susanka.eu/what-are-tls-extensions/</link><guid isPermaLink="false">5be6dfff3b2d940001e81683</guid><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Tue, 19 Sep 2017 15:23:40 GMT</pubDate><content:encoded><![CDATA[<p>The widespread Transport Layer Security protocol (TLS), a successor of the better-known SSL protocol, includes a very thoughtful mechanism to add an additional functionality to the protocol. Using the so-called extensions we can extend the TLS capabilities as we desire without actually modifying the protocol itself.</p>
<p>The extensions were firstly introduced in the <a href="https://tools.ietf.org/html/rfc3546">RFC 3456</a> and later fully incorporated into the TLS itself. The client states which extensions it supports during the handshake (in the ClientHello message) and the server chooses which extensions to use at its sole discretion.</p>
<p>Many extensions are commonly used in the wild. In this article, I'm picking just a few out of many to introduce the concept and describe one of the most popular extensions today.</p>
<h4 id="servernameindicationserver_name">Server Name Indication [server_name]</h4>
<p>This extension enables browsers to send the destination hostname as a part of a TLS handshake. Because of the shortage of IPv4 addresses, it's very common that multiple hosts are on the same IP address. In plain HTTP this is solved via the Host request header, which includes the same thing - the hostname.</p>
<p>Let's assume you want to make a HTTPS connection to www.susanka.eu. This website sits at IP 88.90.30.48 as does www.tsusanka.cz. The handshake starts and the server needs to provide a certificate, which is bound to the domain name. Since both tsusanka.cz and susanka.eu sit at the same machine with the same IP, how can it know which certificate to present?</p>
<p>And that's exactly where the Server Name Indication comes in handy. The client simply includes the hostname in the TLS handshake and the server knows right away which certificate to present.</p>
<h4 id="ellipticcurvescapabilitieselliptic_curves">Elliptic Curves capabilities [elliptic_curves]</h4>
<p>This extension helps the client to specify what elliptic curves it supports. For example, the Elliptic Curves Key Exchange (ECDH) operates on some particular elliptic curve, where the mathematical voodoo occurs.</p>
<p>Let's spin up a TLS connection inside Firefox by simply visiting a HTTPS website. When inspected in Wireshark you can see that the ClientHello includes this extension and specifies which ECs it supports.</p>
<p><img src="https://blog.susanka.eu/content/images/2017/09/Selection_015.png" alt=""></p>
<p>We can read from the image that our browser supports four elliptic curves. Let's dig a little bit more into the first one.</p>
<p>The ecdh_x25519 stands for the widely used Curve25519. On <a href="https://en.wikipedia.org/wiki/Curve25519">wikipedia</a> and in the official <a href="https://tools.ietf.org/html/rfc7748">RFC 7748</a> we can find that the curve is specified by the formula:</p>
<p>$$ y_2 = x_3 + 486662 x_2 + x $$</p>
<p>That it is a Montgomery curve, over the quadratic extension of the prime field defined by the prime number $$2^{255} − 19$$ and it uses the base point $$x=9$$</p>
<p>I always had a little bit of trouble understanding why it is this arbitrary curve and not another one. Why this prime number? Why multiply by 486662 and not another number that fit as well? Well, the answer to that is somewhat unsatisfactory. The choice of those constants and the form of the curve is simply to allow some performance tricks to achieve faster computations. Researchers simply found out that we can do some very specific tricks on this curve which makes it a nice fast curve to be used for cryptography. That's it, I'm afraid. Feel free to dive into the <a href="https://cr.yp.to/ecdh/curve25519-20060209.pdf">official paper</a>.</p>
<h4 id="sessionticketssession_ticket">Session tickets [session_ticket]</h4>
<p>The TLS handshake is a costly operation. It requires two round-trips and on top of that, the cryptographic operations are CPU-exhaustive. TLS itself incorporates a mechanism called <em>session resumption</em> to abbreviate the handshake. The server assigns the session a unique ID and both the client and the server store the session details under such ID. During the next handshake, both sides simply state the ID and the connection is resumed using the stored data.</p>
<p>This mechanism, however, contains one big caveat – the server needs to store the session details for every client. That can add up to a lot of data! For that reason session tickets extension delegates the data-storing exclusively to the client.</p>
<p>The server sends all the session data (encrypted) to the client and the client stores it and sends it back to the server on resumption. No server-side storage is then needed whatsoever.</p>
<hr>
<p>This was just a brief introduction into the extensions mechanism. I wanted to demonstrate that using the extensions you can extend or modify the TLS protocol as you desire.</p>
]]></content:encoded></item><item><title><![CDATA[My DEF CON talk on Telegram]]></title><description><![CDATA[<p>Articles about Telegram:<br>
<a href="https://blog.susanka.eu/tag/telegram/">https://blog.susanka.eu/tag/telegram/</a></p>
<p>Shortend version of my master thesis on Telegram:<br>
<a href="https://www.susanka.eu/files/telegram-article.pdf">https://www.susanka.eu/files/telegram-article.pdf</a></p>
<p>And the full thing:<br>
<a href="https://www.susanka.eu/files/master-thesis-final.pdf">https://www.susanka.eu/files/master-thesis-final.pdf</a></p>
<p>Slides from DEF CON 25:<br>
<a href="https://www.susanka.eu/files/telegram-defcon-slides.pdf">https://www.susanka.eu/files/telegram-defcon-slides.pdf</a></p>
<p>Video from DEF</p>]]></description><link>https://blog.susanka.eu/defcon25/</link><guid isPermaLink="false">5be6dfff3b2d940001e8167f</guid><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Sun, 23 Jul 2017 21:12:36 GMT</pubDate><content:encoded><![CDATA[<p>Articles about Telegram:<br>
<a href="https://blog.susanka.eu/tag/telegram/">https://blog.susanka.eu/tag/telegram/</a></p>
<p>Shortend version of my master thesis on Telegram:<br>
<a href="https://www.susanka.eu/files/telegram-article.pdf">https://www.susanka.eu/files/telegram-article.pdf</a></p>
<p>And the full thing:<br>
<a href="https://www.susanka.eu/files/master-thesis-final.pdf">https://www.susanka.eu/files/master-thesis-final.pdf</a></p>
<p>Slides from DEF CON 25:<br>
<a href="https://www.susanka.eu/files/telegram-defcon-slides.pdf">https://www.susanka.eu/files/telegram-defcon-slides.pdf</a></p>
<p>Video from DEF CON 25 CryptoVillage:<br>
<a href="https://www.youtube.com/watch?v=hvGyog57gwI">https://www.youtube.com/watch?v=hvGyog57gwI</a></p>
<p>Slides from ROOTS 2017:<br>
<a href="https://www.susanka.eu/files/telegram-roots-slides.pdf">https://www.susanka.eu/files/telegram-roots-slides.pdf</a></p>
<p>Tools available on GitHub:<br>
<a href="https://github.com/tsusanka/telegram-deobfuscator">https://github.com/tsusanka/telegram-deobfuscator</a><br>
<a href="https://github.com/tsusanka/telegram-extractor">https://github.com/tsusanka/telegram-extractor</a></p>
]]></content:encoded></item><item><title><![CDATA[Replay attack vulnerability in Telegram for Android]]></title><description><![CDATA[<p>In November 2016 I've discovered a vulnerability in the Telegram Instant Messenger for Android. This post will describe the discovery, responsible disclosure and Telegram's response.</p>
<h3 id="replayattack">Replay attack</h3>
<p>A replay attack is an attack where an attacker sniffs data sent by the application and then resends them at a different time</p>]]></description><link>https://blog.susanka.eu/telegram-replay-attack-vulnerability-on-android/</link><guid isPermaLink="false">5be6dfff3b2d940001e8167e</guid><category><![CDATA[Telegram]]></category><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Mon, 24 Apr 2017 17:43:21 GMT</pubDate><content:encoded><![CDATA[<p>In November 2016 I've discovered a vulnerability in the Telegram Instant Messenger for Android. This post will describe the discovery, responsible disclosure and Telegram's response.</p>
<h3 id="replayattack">Replay attack</h3>
<p>A replay attack is an attack where an attacker sniffs data sent by the application and then resends them at a different time with a malicious intent. By doing so, the attacker can repeat any message without the user noticing. Curiously, the attacker does not actually know the message. A protection might be realized by implementing a message counter to keep track of the order the messages appear in.</p>
<p>To provide an example let's assume two parties: Alice and Bob (suprisingly) are exchanging messages in an encrypted manner. Alice asks a lot of questions and Bob answers lazily. Finally, Eve, an eavesdropper, listens to the encrypted communication. Eve is unable to read the messages, however, is able to take one of the Bob's answer and resends it later on.</p>
<p>If we further assume that Eve is able to identify Bob's <em>&quot;yes&quot;</em> answer (e.g. using social engineering, length of the encrypted message etc.), she is able to send the message anytime she desires and therefore respond to all Alice questions possitively!</p>
<h3 id="replayattackontelegram">Replay attack on Telegram</h3>
<p>During my analysis of the official Android Telegram app (more articles on that <a href="https://blog.susanka.eu/tag/telegram/">here</a>) I've examined some parts of the code in an attempt to discover potential vulnerabilities to exploit.</p>
<p>Amongst others I've analyzed how Telegram deals with the Replay attack issue outlined above. Telegram sends sequence numbers included in each message which should be later validated. The concerned code responsible for checking these numbers (file <code>ConnectionsManager.cpp</code>, line 728) is depicted in the following listing:</p>
<pre><code class="language-clike">if (connection-&gt;isMessageIdProcessed(messageId)) {
	doNotProcess = true;
}
if (!doNotProcess) {
	// process
	addProcessedMessageId(messageId);
}
</code></pre>
<p>After the message decryption this block of code checks if the message was already processed. The class <code>ConnectionSession</code> holds an internal array of the already processed messages. If the message is accepted and processed, the message ID is then added into the array.</p>
<p>The behavior I believed might be exploitable concerns the <code>addProcessedMessageId()</code> function (<code>ConnectionSession.cpp</code>, line 55). The function checks the size of the array and if it exceeds 300, it erases the first 100 messages:</p>
<pre><code class="language-clike">void addProcessedMessageId(messageId)
{
	if (processedMessageIds.size() &gt; 300) {
		processedMessageIds.erase(processedMessageIds.begin(),
		processedMessageIds.begin() + 100);
	}
	processedMessageIds.push_back(messageId);
}
</code></pre>
<p>I came to a conclusion that after processing 300 messages, Telegram could accept older one again. I drafted the attack scenario as follows:</p>
<ol>
<li>Sniff a message</li>
<li>Wait for 300 other messages</li>
<li>Replace the next message with the first one</li>
<li>Telegram processes the first message again</li>
</ol>
<p>If Telegram would not provide any additional checks and actually delete the first 100 IDs, the message would be accepted twice.</p>
<h4 id="responsibledisclosure">Responsible Disclosure</h4>
<p>The findings were reported to the Telegram security team on December 7th, 2016 with a kind request for comments. The first response from Telegram was received on 12th December 2016 and Telegram actually accepted my remarks.</p>
<p>According to the Telegram team the Android application (as opposed, allegedly, to the other clients, such as Telegram for iOS, Telegram Desktop etc.) does not perform one of the the security checks as is required by the protocol, defined in the <a href="https://core.telegram.org/mtproto/security_guidelines#checking-msg-id">Security Guidelines for Client Developers</a> in particular.</p>
<p>Among other checks, the Security Guidelines require the message ID to be checked against the stored ones and Telegram performs that. However, it requires one more additional check – if the incoming message has an ID lower than all or equal to any of the stored IDs, such message is to be discarded. This action does indeed diminish the risk but Telegram for Android did not carry out this check.</p>
<p>The Telegram team further commented that this vulnerability does not allow the attacker to cause any severe damage because of the additional protection on the side of the Telegram API. Message actions (sending, editing, deleting, and changing read status), group membership, secret chats, and<br>
other important areas are not affected <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>.</p>
<p>Nevertheless, the Telegram team confirmed the attack would work for nonessential service updates like online or typing statuses. For example, the scenario would allow the attacker to alter the statuses of victim’s friends (as seen in the Android application, not in the Telegram network) or spoof the victim to see typing statuses from contacts not performing such action in reality.</p>
<p>I briefly reviewed these claims and concluded that the Java part of the Telegram application does indeed deal with additional identifiers, such as <code>qts</code>, <code>pts</code> and others. These values do seem to provide additional protection. It is important to mention that I did not perform any deeper research. Telegram promised this will be fixed in the next Android update – most likely in the 3.16 version which was released in early January 2017. Telegram also offered a financial reward for my findings.</p>
<h4 id="fix">Fix</h4>
<p>I'm releasing this post quite late after the discovery. The reason is (besides me being lazy) that I wanted to see how Telegram will fix this. I was unfortunately unable to do so, because Telegram didn't update its GitHub repository since October 2016. That finally changed at the end of March 2017.</p>
<p>The developers indeed modified the <code>addProcessedMessageId()</code> and more  importantly the <code>isMessageIdProcessed()</code> functions, you can see the code directly on <a href="https://github.com/DrKLO/Telegram/blob/6a1cf64f6f45ba0d0e7ff898e8a6c677ddc3ef33/TMessagesProj/jni/tgnet/ConnectionSession.cpp#L51-L62">GitHub</a>.</p>
<p>The <code>addProcessedMessageId()</code> function now saves <code>minProcessedMessageId</code> value. This variable is set when the array of message IDs exceeds its 300 items capacity. It is set to the current lowest message ID stored in the array. All processed IDs have lower ID than this value and the check correctly asserts that the  examines that.</p>
<p>I've reviewed the code and it seems correct. Great to hear Telegram fixed this properly.</p>
<h4 id="conclusion">Conclusion</h4>
<p>The code quality is, to say it gently, very very doubtful. I think another article might follow on that, but it took me about a month just to familiarize myself with the code base. And it took a lot more effort to find the <a href="https://blog.susanka.eu/how-telegram-obfuscates-its-mtproto-traffic/">obfuscation method</a> and this bug.</p>
<p>That being said, the Telegram security team took my report seriously and in a very professional manner (and let's be honest, this ain't no Heartbleed) and the communication was realized in a reasonable time frame. I'm not a Telegram fan, but they dealt with this issue with grace.</p>
<hr>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p>According to Telegram, this is because of the checks done in the MessagesController.java class on lines 5731, 5561, 5765, 5817 and others. <a href="#fnref1" class="footnote-backref">↩︎</a></p>
</li>
</ol>
</section>
]]></content:encoded></item><item><title><![CDATA[How to modify general TCP/IP traffic on the fly with Trudy]]></title><description><![CDATA[<p>There are several great tools available to intercept network traffic. <em>Scapy</em> and <em>Wireshark</em> are great tools for passive sniffing and Scapy is also capable of sending additional packets.</p>
<p>In case you want to intercept traffic as a Man-in-the-Middle intermediary we can use many popular tools such as <em>Fiddler</em>, <em>Burp Suite</em></p>]]></description><link>https://blog.susanka.eu/how-to-modify-general-tcp-ip-traffic-on-the-fly-with-trudy/</link><guid isPermaLink="false">5be6dfff3b2d940001e8167d</guid><category><![CDATA[Telegram]]></category><category><![CDATA[Trudy]]></category><category><![CDATA[MiM]]></category><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Wed, 22 Mar 2017 14:12:16 GMT</pubDate><content:encoded><![CDATA[<p>There are several great tools available to intercept network traffic. <em>Scapy</em> and <em>Wireshark</em> are great tools for passive sniffing and Scapy is also capable of sending additional packets.</p>
<p>In case you want to intercept traffic as a Man-in-the-Middle intermediary we can use many popular tools such as <em>Fiddler</em>, <em>Burp Suite</em> or <em>OWASP ZAP</em>. These are great tools which are, however, built for the HTTP(S) protocol only. What software to use if you need to modify general non-HTTP traffic?</p>
<p>This was exactly my issue when I've analyzed the Telegram IM (see <a href="https://blog.susanka.eu/tag/telegram/">more articles</a>). Telegram uses its own homebrew protocol <em>MTProto</em> directly on top of the TCP/IP suite. Since HTTP or HTTPS is not used at all, the tools mentioned above are not applicable.</p>
<p>The first tool I've found with similar capabilities was <em>Ettercap</em>, which I've already used to perform the MiM setup itself. It provides a simple filtering interface allowing to modify the data routed through. Unfortunately, Ettercap requires the filters to be written in its own language which is quite limiting and was insufficient for my needs at that time.</p>
<p>I finally came across two tools that seemed to solve my problems: <em>Mallory</em> and <em>Trudy</em>. The Mallory software may be found on <a href="https://github.com/intrepidusgroup/mallory">github</a> and there is a talk about it on <a href="https://www.youtube.com/watch?v=0ZquG1p0eKA">youtube</a> from the Black Hat USA conference in 2010. Some time passed since and the project seems to be abandoned. Let's have a look closer look on Trudy, which I've finally successfully used. Trudy was written by <a href="https://twitter.com/kelbyludwig">@kelbyludwig</a> and its source code is available on <a href="https://github.com/praetorian-inc/trudy">github</a> as well.</p>
<h3 id="trudy">Trudy</h3>
<p>The Trudy software can modify any TCP traffic and it is most likely inspired by the Mallory software mentioned in the previous section. As its documentation states, Trudy is <em>&quot;a transparent proxy that can modify and drop traffic for arbitrary TCP connections&quot;</em>. All traffic is routed through Trudy which then applies so called modules to alter it.</p>
<p>Trudy modules are bulks of preprogrammed code to perform modifications desired by the user. Trudy provides an <a href="https://github.com/praetorian-inc/trudy/blob/master/module/module.go">example stub</a> of such a module, and users are encouraged to implement it. Because Trudy is written in Go, all modules are to be written in Go as well. To route the traffic and setup the environment properly, a <a href="https://github.com/praetorian-inc/mitm-vm">prepared virtual machine</a> is available.</p>
<h4 id="virtualmachinesetup">Virtual machine setup</h4>
<p>The VM installs all the required software and Trudy itself as well. Then it routes all the traffic in and out of Trudy using <em>iptables</em>. Trudy receives all the traffic, modifies it based on the used module and sends it back to internet as seen in the following Figure:</p>
<p><img src="https://blog.susanka.eu/content/images/2017/03/setup-trudy.svg" alt=""></p>
<h4 id="trudymodule">Trudy module</h4>
<p>The implementation of a module for Trudy is quite straightforward. Trudy<br>
calls specific methods in fixed order, each designed for one particular action.<br>
The methods of a single module are as follows:</p>
<ul>
<li><strong>Deserialize()</strong> converts the raw payload into a known structure of data<br>
(e.g. HTTP)</li>
<li><strong>Drop()</strong> if true is returned, the whole packet is discarded</li>
<li><strong>DoMangle()</strong> if true is returned, Mangle() is called</li>
<li><strong>Mangle()</strong> alters the payload</li>
<li><strong>DoIntercept()</strong> if true is returned, the data are sent to the Trudy in-<br>
terceptor 19</li>
<li><strong>DoPrint()</strong> if true is returned, PrettyPrint() is called</li>
<li><strong>PrettyPrint()</strong> prints data in a human friendly format</li>
<li><strong>Serialize()</strong> converts the data back to raw payload if it were previously<br>
deserialized</li>
<li><strong>BeforeWriteTo()</strong> actions taken before the data are written to one side<br>
or the other</li>
<li><strong>AfterWriteTo()</strong> actions taken after the data are written to one side or<br>
the other</li>
</ul>
<h4 id="example">Example</h4>
<p>This dead simple example of a module cripples all incoming traffic received from an IP address 139.59.129.86 on port 80. It does so by rewriting the whole TCP/IP payload to zeros.</p>
<p>The main part of the module uses the <code>DoMangle()</code> and <code>Mangle()</code> functions:</p>
<pre><code class="language-go">func (input Data) DoMangle() bool {
	if input.ServerAddr.String() == &quot;139.59.129.86:80&quot; {
		return true
	}
	return false
}

func (input *Data) Mangle() {
	for i := range input.Bytes {
		input.Bytes[i] = 0x00
	}
}
</code></pre>
<p>The <code>DoMangle()</code> function limits the mangling to our specified IP address and <code>Mangle()</code> does the actual work.</p>
<p>Our test IP address was not chosen randomly, but rather corresponds to a domain of mine - <a href="http://nohttps.susanka.eu">nohttps.susanka.eu</a>. After setting up Trudy with this example module, we can try to access the site via regular browser. The request will work fine but the response will get rewritten with zeros. The browser is obviously unable to parse the response and will eventually time out.</p>
<p>We may confirm this behaviour using WireShark. The picture below shows the modified response. The blue box is the TCP/IP payload - full of zeros as anticipated. The TCP/IP headers are left untouched (before the blue box).</p>
<p><img src="https://blog.susanka.eu/content/images/2017/03/blog1.png" alt=""></p>
<p>You may find the whole module on my <a href="https://gist.github.com/tsusanka/8ce41c64f80836500410e490075b1df8">gist</a>. It additionally enables console printing to give you an idea what's going on.</p>
<p>You can use Trudy for a numerous different use cases, it provides an easy interface to alter generic TCP/IP traffic on the air.</p>
]]></content:encoded></item><item><title><![CDATA[How Telegram obfuscates its traffic to allegedly circumvent censorship]]></title><description><![CDATA[<p>The Signal messenger recently incorporated an interesting mechanism to circumvent censorship in some troubled countries, such as Egypt or the UAE. The technique called <em>domain fronting</em> uses popular cloud services like the ones from Google or Amazon as a middle man to route all traffic. You can read more on</p>]]></description><link>https://blog.susanka.eu/how-telegram-obfuscates-its-mtproto-traffic/</link><guid isPermaLink="false">5be6dfff3b2d940001e8167c</guid><category><![CDATA[Telegram]]></category><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Fri, 20 Jan 2017 10:37:08 GMT</pubDate><content:encoded><![CDATA[<p>The Signal messenger recently incorporated an interesting mechanism to circumvent censorship in some troubled countries, such as Egypt or the UAE. The technique called <em>domain fronting</em> uses popular cloud services like the ones from Google or Amazon as a middle man to route all traffic. You can read more on that on the Signal creators' <a href="https://whispersystems.org/blog/doodles-stickers-censorship/">blog</a> or see the <a href="https://www.bamsoftware.com/papers/fronting/">original paper</a>.</p>
<p>During my security analysis of the Telegram IM (full text available <a href="https://susanka.eu/files/master-thesis-final.pdf">here</a>) I've discovered Telegram obfuscates its traffic by re-encrypting everything with a prepended key. When I've prompted the Telegram Security team for comments, they responded that this measure is used to <em>&quot;counter some of the less sophisticated attempts at banning our service in certain countries&quot;</em>. MTProto has a fixed structure where the <strong>auth_key_id</strong> value is always present at the beginning of the packet and therefore easily recognizable.</p>
<p>Let's have a look how the official Telegram for Android application obfuscates the traffic and why this is quite a naive idea.</p>
<p>When I started the analysis I wanted to check the network traffic Telegram produces. I've expected the data to correspond with the official documentation and to be in a form of:</p>
<p><img src="https://blog.susanka.eu/content/images/2017/01/sniffed-expected-2.svg" alt=""></p>
<p>I've extracted my own <em>auth_key_id</em> and I expected to see it amongst the sniffed data. However, the whole traffic seemed random and therefore likely encrypted, and no sign of the expected structure was present.</p>
<p>I've examined the code and after a few weeks of pain and despair I've discovered that the function responsible for this behavior is the <a href="https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/jni/tgnet/Connection.cpp#L288">Connection::sendData</a> function. Before sending the data in the expected manner, Telegram encrypts them one more time with a random key attached in front of the data. Interestingly, the Counter block mode is used instead of the IGE endorsed by Telegram.</p>
<h3 id="technicaldetails">Technical details</h3>
<p>To properly explain the obfuscation method I need to introduce my own terminology first to add a little more clarity because Telegram does not practise a great job in naming variables. Since the variables are explained in more detail in the following sections, reader may skip this list and use it as a reference later on.</p>
<ul>
<li><strong>obf_enc_key_bytes</strong> 64 random bytes storing <strong>obf_enc_key</strong> and <strong>obf_enc_iv</strong> used for obfuscation. Telegram calls this simply <em>bytes</em>.</li>
<li><strong>obf_enc_key</strong> The key used for encryption to obfuscate data.</li>
<li><strong>obf_enc_iv</strong> The IV used for encryption to obfuscate data.</li>
<li><strong>obf_dec_key_bytes</strong> 64 bytes derived from <strong>obf_enc_key_bytes</strong> storing the server's encryption key and IV. Labeled in Telegram as <em>temp</em>.</li>
</ul>
<h4 id="temporaryencryptionkeys">Temporary encryption keys</h4>
<p>The obfuscation process starts by generating 64 random bytes <strong>obf_enc_key_bytes</strong>. The first 8 bytes are unused. Bytes 8 – 39 are used as an encryption key and bytes 40 – 55 as an IV. Bytes 56 – 63 are composed of the last 8 bytes of <strong>obf_enc_key_bytes</strong> encryption of itself. It is unclear what are those bytes used for. The final <strong>obf_enc_key_bytes</strong> to be sent:</p>
<p><img src="https://blog.susanka.eu/content/images/2017/01/bytes-sent-2.svg" alt=""></p>
<p>The length of the packet, yet again encrypted, and the real data to be transmitted as expected from the official documentation are then AES-CTR encrypted using the <strong>obf_enc_key</strong> and <strong>obf_enc_iv</strong>, and sent. All the other data in this TCP stream are encrypted using the same obfuscation key. When another connection is established, a new <strong>obf_enc_key_bytes</strong> is generated and the process repeats itself.</p>
<p>Besides the <strong>obf_enc_key_bytes</strong> setup, the very same function deals with setting up the <strong>obf_dec_key_bytes</strong>. This temporary key is used for decrypting the incoming traffic.</p>
<p>The <strong>obf_dec_key_bytes</strong> is derived from the <strong>obf_enc_key_bytes</strong>. 48 bytes are reversed from <strong>obf_enc_key_bytes</strong>, starting at position 8. This may be seen in the code snippet below. The first 32 bytes are then used as a key and the next 16 bytes as an IV for the incoming traffic decryption.</p>
<pre><code class="language-clike">for (int a = 0; a &lt; 48; a++) {
    obf_dec_key_bytes[a] = obf_enc_key_bytes[55 - a];
}
</code></pre>
<p>I believe Telegram server receives the <strong>obf_enc_key_bytes</strong>, tampers with them in a way described in this section and finally encrypts the response with <strong>obf_dec_key_bytes</strong>.</p>
<h3 id="deobfuscationprogram">Deobfuscation program</h3>
<p>As a part of the analysis I've written a simple C software, which removes the obfuscation. The program does not sniff the network data so you have to provide it with a file of sniffed data. I've used Wireshark to do this.</p>
<p>The program is also capable of describing the real MTProto traffic in case you use  the master secret key <em>auth_key</em> as an argument. The key is obviously not available to an attacker rather this functionality is meant for study purposes if you want to examine what Telegram sends from your own device.</p>
<p>You may check it out on <a href="https://github.com/tsusanka/telegram-deobfuscator">github</a>. A readme file and an example is available there.</p>
<h3 id="whynottls">Why not TLS?</h3>
<p>The obfuscation method is not officially documented, which makes sense if Telegram uses it to circumvent censorship. However, the reality of its functionality is doubtful at best. A more conventional approach would be much appreciated, such as the usage of SSL/TLS. If Telegram would use TLS, the traffic would then be indistinguishable from any other protocols using it, such as HTTPS.</p>
<p>Finishing on a personal note; I wasn't sure whether I should publish or not. Obviously, I don't want to make things easier for any oppressive regimes, on the other hand if a non-paid student can find this in a month or two does anyone actually believe the agencies can't or didn't already?</p>
<p>I came to a conclusion that I should publish these findings with a hope that Telegram might come up with a finer idea on how to do this or may get inspired by the Signal's technique.</p>
]]></content:encoded></item><item><title><![CDATA[IGE Block Cipher Mode]]></title><description><![CDATA[<p>Infinite Garble Extension (IGE) is a lesser-known block cipher mode. OpenSSL implemented IGE back in 2006 as described in its <a href="http://www.links.org/files/openssl-ige.pdf">official paper</a>. I came across IGE because of my analysis of Telegram IM and I'm currently not aware of any other software actually using it in the wild.</p>
<p>IGE can</p>]]></description><link>https://blog.susanka.eu/ige-block-cipher-mode/</link><guid isPermaLink="false">5be6dfff3b2d940001e8167b</guid><category><![CDATA[Telegram]]></category><category><![CDATA[cryptography]]></category><dc:creator><![CDATA[Tomas Susanka]]></dc:creator><pubDate>Thu, 01 Dec 2016 19:43:00 GMT</pubDate><content:encoded><![CDATA[<p>Infinite Garble Extension (IGE) is a lesser-known block cipher mode. OpenSSL implemented IGE back in 2006 as described in its <a href="http://www.links.org/files/openssl-ige.pdf">official paper</a>. I came across IGE because of my analysis of Telegram IM and I'm currently not aware of any other software actually using it in the wild.</p>
<p>IGE can be defined easily by the following formula:</p>
<p>$$ c_i = f_K(m_i \oplus c_{i-1}) \oplus m_{i-1} $$</p>
<p>where \(f_K\) stands for the encrypting function (like AES) with key \(K\)<br>
and \(i\) goes from 1 to \(n\) – the number of plaintext blocks. Since picture is worth a thousand words here goes a diagram as well:<br>
<img src="https://blog.susanka.eu/content/images/2016/12/ige.svg" alt="IGE mode"></p>
<p>You may notice that for the first output block we need two ini-<br>
tialisation values \(c_0\) and \(m_0\). Both are taken from the IV values described earlier. The original paper described \(m_0\) as a random block and \(c_0\) as its encrypted counterpart. The OpenSSL implementation however, uses a more general implementation where both \(m_0\) and \(c_0\) are provided by the user.</p>
]]></content:encoded></item></channel></rss>