<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marc Obrador Sureda on Medium]]></title>
        <description><![CDATA[Stories by Marc Obrador Sureda on Medium]]></description>
        <link>https://medium.com/@marcobrador?source=rss-acd2bbe98123------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nEgr27TG1JW_q4X32TFNdA.jpeg</url>
            <title>Stories by Marc Obrador Sureda on Medium</title>
            <link>https://medium.com/@marcobrador?source=rss-acd2bbe98123------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:41:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcobrador/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[On the Deprecation of JetSec Crypto]]></title>
            <link>https://marcobrador.medium.com/on-the-deprecation-of-jetsec-crypto-dea9205d5076?source=rss-acd2bbe98123------2</link>
            <guid isPermaLink="false">https://medium.com/p/dea9205d5076</guid>
            <category><![CDATA[mobile-app-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Marc Obrador Sureda]]></dc:creator>
            <pubDate>Mon, 12 Aug 2024 08:59:23 GMT</pubDate>
            <atom:updated>2024-08-12T08:59:23.655Z</atom:updated>
            <content:encoded><![CDATA[<p>As the Android community might have heard, recently the Jetpack Security team at Google deprecated the “JetSec Crypto” SDK androidx.security:security-crypto. Some things have been written already about this, and one of the articles that (in my opinion) best describes the situation Android dev’s are left with is <a href="https://www.spght.dev/articles/28-05-2024/jetsec-deprecation">this one</a> by Ed Holloway-George. Ed is a Google Developer Expert for Android and a well-known speaker, oftentimes about Mobile App Security. Today, I want to take a close look at the article and dig a bit deeper in some of the topics he touches on, either to complement them or, also, challenge them (a bit).</p><p>But, before we get the ball rolling, let’s use his words to explain what JetSec Crypto Crypto is (or was):</p><blockquote>JetSec Crypto consists of only a small handful of classes, primarily wrappers around popular storage mechanisms, (i.e. EncryptedSharedPreferences and EncryptedFile) that offer convenient methods to encrypt/decrypt the data held within them. The library also provides a wrapper around Google’s cryptography library <a href="https://developers.google.com/tink">Tink</a> through the MasterKeys class which, via a straightforward API, allows developers to create secure keysets for the encryption process utilising best practices for Android.</blockquote><p><strong>Storing Data Locally</strong></p><p>Let’s go with the first point I wanted to share my view on:</p><blockquote>To some extent, using EncryptedSharedPreferences should be seen as a red flag that perhaps your app isn’t following security best practices in the first place 🚩</blockquote><blockquote>Ask yourself, are you using the library for storing data locally on a device that’s <strong>sensitive</strong>? This would include data such as personally identifiable information, financial data, credentials, etc. If you are, should you be? Chances are, <strong>no</strong> <strong>— you shouldn’t</strong>. Any sensitive data should ideally be server-side, only fetched when required, and require some form of authentication to access.</blockquote><p>Besides the philosophical debate of whether (backend-)centralized storage of sensitive user data is more secure than (device-)distributed storage of it (which I certainly don’t want to go into right now), as he rightfully points out later in the article, there are certain situations in which you might <strong>need</strong> to store data on the end user device. He mentions regulation as an example, but it’s certainly not the only one: another example would be the usage of such data in offline scenarios.</p><p>Even if we assume that not all developers will face this situation, what can those developers that do face it do? Certainly, using a deprecated lib is far from ideal — more so in the security space, where unpatched security software will result in… insecure software! As Ed points out as well, implementing it yourself is a bad idea, as it might end up just like before: an insecure implementation. In this situation, turning to security professionals and ready-made solutions is not only a guarantee, but a necessity to ensure things are done properly.</p><p><strong>Dealing with Crypto</strong></p><p>Another idea he drops in the article that I’d like to expand on is the following:</p><blockquote>Another often-overlooked reason why JetSec Crypto is so popular is the APIs are straightforward and follow the best practices for cryptography in Android. […] This won’t change with deprecation and I’d always prefer (and recommend) to use this over rolling my own solution. That’s never a good idea…</blockquote><p>Couldn’t agree more on that. And let me tell you why this is critical: cryptography is done by hardcore mathematicians. It is insanely complex. And, what is worse, it is extremely easy to get wrong: initialise a random array the wrong way and, all of a sudden, all your encryption scheme might fall apart. The distance between mathematicians and software developers is, unfortunately, too big, which means that, historically, Crypto APIs have been developed with the wrong user in mind (i.e. crypto experts rather than regular developers). Looking at you, <a href="https://en.wikipedia.org/wiki/Java_Cryptography_Extension">JCE</a> 😉</p><p>But, in the Android ecosystem, this gets even worse: the fragmentation in the device base makes things even harder for the suffered Android Developers. As I wrote a few years back in <a href="https://medium.com/proandroiddev/android-keystore-what-is-the-difference-between-strongbox-and-hardware-backed-keys-4c276ea78fd0">this article</a>, there are several different “categories” of Android Devices when we look at them from the point of view of their capabilities in storing cryptographic keys. This means that Android Developers willing to implement some sort of cryptographic system by themselves need to either a) handle all this complexity on their own or b) fall back to the mechanism that is supported by all devices — which is, unfortunately, the less secure of all.</p><p>And last, but not least, we have the topic of key distribution and management. See, a cryptographic system is only as secure as the security with which their keys are protected. If we just need to create and AES (symmetric) key for encrypting locally stored data, then there is not much complication: you generate the key locally and store it with whatever mechanism the OS provides you. But, what if we want to use this key for encrypting the communication with our backend? Or what if we need to share the public counter part of a private key so that we can use it to authenticate against our backend? This is where it gets tricky, because you need a high level of assurance that they are transmitted securely (both in terms of confidentiality but also integrity), as they will represent the cornerstone on top of which your security system will be built upon.</p><p>As you can see, relying on professional solutions that take away all the complexity and provide robust and fail-safe implementations proves to be, again, of the utmost importance to implement secure and reliable systems.</p><p><strong>Are Rooted Devices Safe?</strong></p><p>And, finally, one last statement to be commented on:</p><blockquote>[…] A common rebuttal to this is “Well, what about rooted users?” and yes, a user with root access would be able to read cleartext SharedPreferences but once the device’s integrity is compromised is anything really safe, EncryptedSharedPreferences included? Many experts (and I), would argue that it isn’t. 🥲 Some food for thought there!</blockquote><p>Again, fully agree: when a device is rooted, nothing is really safe anymore. Basically, in a rooted device all the security mechanisms provided by the OS (Android, in this case) are no longer present (or, at least, they are no longer applying to those apps or software that runs with root privileges). Unfortunately, however, rooted devices are a reality in the Android ecosystem. Not only because users might consciously and willingly root their devices (for whatever reason they might have), but also because all sorts of malware exist that exploit vulnerabilities in unpatched versions of Android which grant their authors root privileges on the target’s device with the user not even being aware of it.</p><p>Data collected by <a href="https://build38.com/">Build38</a> shows that between 1% and 2% of the device base is or might be rooted (please take this numbers with a pinch of salt — there are huge variations depending on markets and geographical regions). So, should we just ignore those millions of users out there with rooted devices? Of course, that is not an option — and here’s where root detection (and reaction!) comes in.</p><p>In terms of root detection, unfortunately, it is a cat and mouse game: when a piece of software has root access, it has such privileged access that it can (theoretically speaking) disguise any third party software that is trying to detect whether someone has root privileges. This is why trivial root detection techniques (such as trying to read directories that would, in a “secure” OS, not be accessible) will not even stand the first round, and also the reason why popular tools (hello, <a href="https://developer.android.com/google/play/integrity">Play Integrity API</a>) are often defeated within weeks of their updates.</p><p>Reaction is also a tricky matter, as there is no right or wrong here: either you assume your app will run on insecure devices, or you deny access to (all or part of) your app to a relevant chunk of your users. Of course, neither option is ideal, but at least having the capability to strongly and reliably detect rooted devices is a starting point. On top of this, if you can have an app that is capable of operating in such compromised environments, even better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dea9205d5076" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing strong Device Binding]]></title>
            <link>https://marcobrador.medium.com/implementing-strong-device-binding-22e44ff0ccc?source=rss-acd2bbe98123------2</link>
            <guid isPermaLink="false">https://medium.com/p/22e44ff0ccc</guid>
            <category><![CDATA[fraud-prevention]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[fraud-detection]]></category>
            <category><![CDATA[mobile-security]]></category>
            <dc:creator><![CDATA[Marc Obrador Sureda]]></dc:creator>
            <pubDate>Sat, 01 May 2021 19:02:29 GMT</pubDate>
            <atom:updated>2021-05-01T19:02:29.034Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published </em><a href="https://build38.com/implement-strong-device-identification/"><em>here</em></a><em>.</em></p><p>Some weeks ago, <a href="https://securityintelligence.com/posts/massive-fraud-operation-evil-mobile-emulator-farms/">IBM Trusteer reported</a> a massive fraud operation against banks, which lead to losses in the order of millions of dollars. In a nutshell, attackers managed to 1) steal end user credentials and 2) bypass the fraud management scheme of the banks in order to automate millions of small transactions, which would go through unnoticed by the banks’ risk assessment infrastructure (and, potentially, also by the users).</p><p>The first step (stealing the bank customer’s credentials) was apparently done using some sort of social engineering attack (that involved installing malware in the end-user’s device). Whereas in the second step attackers used emulators to “trick” the fraud management system of the different banks. We believe it is fair to say that, in this case, the fraud management system failed to do its job, which is, precisely, to protect against situations like this one, where users have been tricked or deceived. So, let’s dig a bit more into this.</p><h3>Identifying the weak spot</h3><p>Let’s first try to understand what the anti-fraud system was supposed to be doing. From the reading, one can understand that it was supposed to detect situations where a user account was being used in a device other than the legitimate user’s one. This is a typical scenario for fraud management: if we see the user is using an iPhone, whereas normally they are connecting from a Samsung… Well, that is strange, isn’t it? So, this is why the hackers used emulators: because emulators gave them the ability to “trick” the anti-fraud solution to believe that they were using the end user’s device, when in fact they were not.</p><p>So, how might have this worked out? And let’s be clear here, we are entering the land of speculation as the researchers didn’t give enough details to know <em>exactly</em> how it worked. But it is safe to assume that attackers:</p><ol><li>Somehow managed to plant malware into the user’s device (e.g., via a phishing scam)</li><li>Used this malware to steal credentials, device information and get access to SMS</li><li>With the information harvested, set up an automated scheme that<br>a) set up an emulator that looked (to the eyes of the anti-fraud system) exactly like a user’s device.<br>b) logged in to the banking app using the stolen credentials. Since the device <em>seemed</em> to be the end user’s one, the anti-fraud system didn’t react.<br>c) performed a small transaction, that would not raise any suspicious in the banks’ system (and, likely, would go unnoticed by the user), and, finally<br>d) was able to repeat these steps millions of times in a matter of days, effectively stealing millions of dollars.</li></ol><p>There are multiple things that could have been done differently in this scenario, but here we want to focus on how the attackers managed to “spoof” the device. Or, in other words, how <em>strong</em> was the device identification (a.k.a. device binding) mechanism. In order to answer this question, let’s first put ourselves in the shoes of the attacker and let’s try to understand how they would go about “spoofing” an end user device.</p><p>The relevant step here is not so much 3.b, but rather step 2: collecting the right device information to be used later on. Because the most important thing the attacker needs to know is which information does the fraud management system use to identify a device. At the end, this is the information the hackers need to extract (using the malware) from the end user device to be able to spoof it.</p><p>Most likely, the fraud management system uses many different values to identify a device: some of them are obvious, but other ones not so much. Among the obvious ones we can find things like the device manufacturer, the device model, the operating system version, the Android ID (for Android devices) or the IDFV (for iOS ones) … But these are not really interesting, as any device identification system would use them.</p><p>The real <em>strength</em> of the device identification system resides on the not-so-obvious device identifiers, especially how many of them are used and, also, how well protected are they. Notice that it is not that important <em>which</em> parameter is being used, but <em>how difficult</em> it is for an attacker to know that it is being used. At the end, the ultimate goal of the attacker is to write a piece of malware that will gather it later on — and this is what we want to prevent.</p><h3>Exploiting the weakness</h3><p>So: how could an attacker know the device identifiers that are being used?</p><ul><li>The easiest approach would likely be to sniff the information transmitted from the app to the backend, using a MITM attack. By analyzing the traffic, the attacker would get a good understanding of which identifiers are being used.</li><li>Another option would be to read through the source code of the application, in order to find the routines that gather this information and send it to the backend systems. Since the source code is likely to not be available to the attacker, the alternative will be the decompiled binary. It is not as useful as the source code, but a good amount of information can be extracted from a decompiled binary performing static analysis.</li><li>Finally, the last option available (because it’s the most difficult one) to the hacker would be to use dynamic analysis. Examples of dynamic analysis include debugging the application while it is executing, using a hooking framework (like Frida), etc.</li></ul><p>Notice that the options listed above are not mutually exclusive: the attacker needs to succeed in only one of them in order to succeed in the whole attack. So, solutions that prevent only one of the scenarios will make the attacker’s life difficult but will not, ultimately, prevent them from succeeding.</p><h3>Protecting your app</h3><p>Considering all of this, we could say that a <em>strong </em>device identification scheme should:</p><ol><li>Use many, non-obvious, device identifiers. The more device identifiers, the better.</li><li>Protect against MITM attacks. Sniffing network traffic yields a lot of information, so a good protection on this front is a must.</li><li>Obfuscate the sensitive parts of the binary. In the case of mobile apps, attackers will always have access to the binary, so proper obfuscation to prevent static analysis is crucial.</li><li>Prevent against dynamic analysis. When static analysis is not enough, attackers will fall back to dynamic analysis: debugging, instrumenting, modifying the app, etc. This means that preventing against debuggers, hooking frameworks (such as Frida) and code injection, among others, is also important.</li></ol><p>Taking a broader perspective, we can conclude that proper endpoint protection is a must for fraud-prevention solutions based on end-user device identification. Otherwise, attackers will manage to feed “fake” data that will bypass the protections implemented in the backend.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22e44ff0ccc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Doing AES/GCM in Android: adventures in the field]]></title>
            <link>https://levelup.gitconnected.com/doing-aes-gcm-in-android-adventures-in-the-field-72617401269d?source=rss-acd2bbe98123------2</link>
            <guid isPermaLink="false">https://medium.com/p/72617401269d</guid>
            <category><![CDATA[keystore]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-security]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[Marc Obrador Sureda]]></dc:creator>
            <pubDate>Fri, 27 Mar 2020 09:27:36 GMT</pubDate>
            <atom:updated>2020-03-30T18:35:51.037Z</atom:updated>
            <content:encoded><![CDATA[<p>Does the Android dev ecosystem need <em>yet another</em> blog post about doing AES encryption and decryption? Probably not, but just this week I stumbled with a series of problems that caught me with my guard down, so I decided to share my experience in case it helps someone else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*-4OFZu0nsnWDKbN1EpOx5g.png" /></figure><blockquote>TL;DR: <a href="https://gist.github.com/marcobrador/9077f89bca7ac5b72a608eb9347b78e5">this</a> is how you do it. If you need to specify the IV and AAD as inputs, <a href="https://gist.github.com/marcobrador/75b7164c7315e25db163bc04b9b9dfc2">here’s</a> a workaround (and the tweak needed when <a href="https://gist.github.com/marcobrador/7fb741eb0c0c20840d59f4cc8164b29c">generating the key</a>) — but be extremely careful with this approach!</blockquote><h3>The problem</h3><p>Just this week I had to design a crypto API that would allow us to use a pre-existing crypto library together with the Android KeyStore API. The idea would be that, in devices that have a hardware crypto processor, our software would rely on it for encryption and decryption; whereas in the rest of the devices it would fall back to the existing library. That called for a common, abstract, API that would allow the rest of the software to not need to know which crypto environment was being used. Encryption and decryption would be done using AES in GCM mode.</p><p>So far, so good. Right?</p><h4>What I saw on the Internet</h4><p>So, as any other developer would do, I took to the Internet and searched for the Android KeyStore API definition and examples on how to use it. In a nutshell, the summary of what I found would be something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47a24ff08d99aef0b2aff77f1c9aaf54/href">https://medium.com/media/47a24ff08d99aef0b2aff77f1c9aaf54/href</a></iframe><p>Seems ok, doesn’t it?</p><p>Well, the problem was that the input and output parameters did not match the ones our pre-existing library was using. According to our pre-existing crypto engine:</p><ul><li>The encryption routine should also take an iv and aad as input parameters.</li><li>The encryption routine should also return a tag as output.</li><li>The decryption routine should take aad and tag as input parameters.</li></ul><p>Wasn’t AES GCM a <em>standard</em>? How were these differences possible?</p><h3><strong>A bit of theory</strong></h3><p><em>Skip this section if you know what the </em><em>iv, </em><em>aad and </em><em>tag are. If you need a refresher, you should probably read it.</em></p><p>The first step was investigation. I wasn’t unfamiliar with these parameters, but to be honest I didn’t know exactly how they should be generated and used. So let’s take a step back and try to fully understand them:</p><p>The iv (short for <a href="https://en.wikipedia.org/wiki/Initialization_vector">Initialization Vector</a>) is a common parameter when using <a href="https://en.wikipedia.org/wiki/Block_cipher">block ciphers</a>. It is used to make sure that encrypting twice the same data with the same key results in different outputs, which is why it is very important that ivs are never reused.</p><p>On the other hand, aad and tag are only used in <a href="https://en.wikipedia.org/wiki/Authenticated_encryption">Authenticated Encryption</a> ciphers (sometimes also referred to as “AEAD”, short for “Authenticated Encryption with Associated Data”), such as AES in GCM mode:</p><ul><li>The tag is an output of the encryption routine, which is then provided to the decryption routine to verify that the ciphertext has not been tampered with (that is: to <em>authenticate</em> that the ciphertext had been generated with the same key being used to decrypt).</li><li>aad stands for “Additional Authentication Data”, and is an input to the encryption and decryption routines which is used for computing the tag.</li></ul><h3>The solution(s)</h3><p>Unfortunately, there is no single solution to all the differences I explained above. Instead, there is a different thing to be done for each parameter:</p><h4>Returning the tag</h4><p>Let’s start with the easy one. After some looking around, I found the answer in the <a href="https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html#doFinal()">Java docs</a>:</p><blockquote>If an AEAD mode such as GCM/CCM is being used, the authentication tag is appended in the case of encryption, or verified in the case of decryption.</blockquote><p>In plain words: the Cipher.doFinal() method (in GCM mode) appends the tag at the end of the ciphertext when encrypting, and verifies it (reading it from the end of the ciphertext) when decrypting. Which means that I could now write something like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3bbcd3604b89c5ddd5110d0bb174cff/href">https://medium.com/media/b3bbcd3604b89c5ddd5110d0bb174cff/href</a></iframe><h4>What about the aad?</h4><p>According to the theory, the aad should also be provided when encrypting and decrypting data, but it doesn’t appear at all in the code snippets above. The answer, again, lies in the <a href="https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html#updateAAD(byte[])">Java docs</a>, where we find the method Cipher.updateAAD(byte[] src).</p><p>To be completely honest, I am not sure if I understand the description of the method. What I can confirm (because I tried it) is that it actually affects the aad used: if you try to change it in encryption or decryption, decryption will fail with an AEADBadTagException, which means that authentication failed.</p><p>If we use the Cipher.updateAAD(byte[] src) method to define the aad, our code would now look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d01064442f4637978fed03656867cd7/href">https://medium.com/media/2d01064442f4637978fed03656867cd7/href</a></iframe><p>Notice that I’ve set aad to be an <em>output</em> of the encryption routine, rather than an input. There is one reason for doing it like that, which I’ll explain a bit later. The important thing here is that <strong>the code above shows the approach that I would recommend to anyone looking for a safe API to implement AES GCM encryption and decryption in Android</strong>.</p><h4>The IV</h4><p>But we still have one more thing that does not fit with our other crypto library: the initialisation vector is supposed to be an <em>input</em> to the encryption method, and not an output.</p><p>Looks like using the <a href="https://docs.oracle.com/javase/7/docs/api/javax/crypto/spec/GCMParameterSpec.html">GCMParameterSpec</a> class we could do it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9803c77849af4a6bd2493d752402e476/href">https://medium.com/media/9803c77849af4a6bd2493d752402e476/href</a></iframe><p>Unfortunately, if we try to execute it we will end up with an exception: java.security.InvalidAlgorithmParameterException: Caller-provided IV not permitted — which is, I believe, quite self-explanatory: Android does not allow us to specify and IV. Period.</p><p>But, why? Well, this is a behaviour introduced in API 23 and is meant to make sure that the caller is not reusing IVs, since this could break the security of the block cipher (as I explained before). The bottom line is: you should not reuse IVs with the same key, and in order to make sure of that Android is generating a random one internally.</p><p>For a similar reason I think it’s best to generate the aad inside the encryption routine: to avoid a caller that doesn’t know what he is doing providing fixed values. By generating it internally we can make sure that it is random.</p><p>But if you <em>really </em>need (like I needed) to provide the iv (and aad) as input parameters, there’s one thing you can do. When the AES key is being created, you can use the setRandomizedEncryptionRequired() method to explicitly ask Android to allow you to provide the iv as an input. The key generation method would then be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec10d3b0620ac7d2423c99e6b82e351b/href">https://medium.com/media/ec10d3b0620ac7d2423c99e6b82e351b/href</a></iframe><p>Needless to say, <strong>do this only if you really know what you are doing</strong>! Especially, if you go down that road, make sure that your iv (and aad) are generated in a proper way and are random enough for your use case.</p><h3>Closing thoughts</h3><p>I think it is fair to say that the Java and Android APIs don’t make it easy to implement an AES GCM that is interoperable with other crypto systems. But, why? Shouldn’t that be the main point anyway?</p><p>In case anybody is interested, here are my thoughts on why the designers of these APIs decided to implement them that way:</p><ul><li>Regarding the tag being included in the result of Cipher.doFinal(), I think it is clear that here the main point was not to break the JCE API. Cipher.doFinal() has returned a byte[] for years, regardless of the encryption primitive, so they decided for it to stay like that.</li><li>With respect to the aad, I believe it would be nicer if it was part of the GCMParameterSpec constructor, but I guess there is a reason (which remains unknown to me) for having it as a method in the Cipher class. What I <em>can </em>say is that the documentation is far from clear, and more importantly it should be more specific about which aad value is used when the caller does not specify it.</li><li>And, finally, the IV: I like the approach of Android (and iOS, to be fair) to provide safe-defaults for their crypto APIs. For non-crypto experts the amount of choices provided by other APIs (such as JCE) might be daunting, so it is good to provide as default the choices that are most secure.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72617401269d" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/doing-aes-gcm-in-android-adventures-in-the-field-72617401269d">Doing AES/GCM in Android: adventures in the field</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Security through obscurity: why not?]]></title>
            <link>https://marcobrador.medium.com/security-through-obscurity-why-not-5580ddc6bdb0?source=rss-acd2bbe98123------2</link>
            <guid isPermaLink="false">https://medium.com/p/5580ddc6bdb0</guid>
            <dc:creator><![CDATA[Marc Obrador Sureda]]></dc:creator>
            <pubDate>Thu, 19 Sep 2019 17:51:27 GMT</pubDate>
            <atom:updated>2019-09-19T17:51:27.435Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published </em><a href="https://build38.com/security-through-obscurity/"><em>here</em></a><em>.</em></p><p>Wired magazine recently published <a href="https://www.wired.com/story/what-is-application-shielding/">an article</a> with the following statement:</p><blockquote>Think of shielding code like hiding a safe behind a painting. If you have a secure enough lock, it shouldn’t matter who can see it.</blockquote><p>Well… I have to say that I (somehow) disagree. As with everything in life, the right wording is “it depends”. In this case, it depends on the execution environment.</p><p>But let’s back up for a moment. What is app shielding? <a href="https://www.owasp.org/index.php/Application_Hardening_and_Shielding">OWASP</a>, a global non-profit organisation focused on improving the security of software, describes app shielding as “a <em>set of technologies that typically modify an application’s binary code to make it more resistant to reverse-engineering, tampering, invasive monitoring and intrusion”.</em></p><p>Which kind of relates to a broader topic known as “security through obscurity”. From <a href="https://en.wikipedia.org/wiki/Security_through_obscurity">Wikipedia</a>: “<em>Security through obscurity (or security by obscurity) is the reliance in security engineering on design or implementation secrecy as the main method of providing security to a system or component. Security experts have rejected this view as far back as 1851, and advise that obscurity should never be the only security mechanism.”</em></p><p>[Spoiler alert] The right answer is in the last sentence: “[…] <em>should never be </em><strong><em>the only</em></strong><em> security mechanism.</em>”</p><p><strong>An analogy</strong></p><p>Let’s try to find a more specific scenario. The example of the safe proposed in Wired’s article is a good analogy of a cryptographic protocol: the safe would be the protocol itself, the safe’s key (either physical or a passcode) would be the cryptographic key, and the content of the safe would be the data to be protected with encryption. In both cases, the security of the system relies on the assumption that the key is kept in a safe place. But what if this is not possible? What if we had to store the key close to the safe?</p><p>This is exactly what happens in mobile apps. If we want to use cryptography (and we <em>need</em> to), we also need to store the keys somewhere in the smartphone so we can use them. Even if we use the latest cryptographic engines (available only in new, high-end devices; such as the hardware-backed KeyStore in Android or the Secure Enclave in iOS), this only solves the problem for a fraction of our user base — and that’s not good enough.</p><p>So, what do we do? We hide the safe behind a painting. And we hide the key behind a different painting. Additionally, we implement as many mechanisms as possible, in order to make it very time consuming for a thief to find both the key and the safe — so much time consuming, that the police will be there before he can find both of them.</p><p>Can you see the analogy? This is the goal of app shielding: we put as many hurdles as possible in order to force the hacker to spend a lot of time finding the key and knowing how to use it. So much time that we have time to react. And “react” means, for example, that we crash the app process (which makes it very difficult to keep searching), or we delete the user data (emptying the safe, in case it is ever open), or we even change the key itself (frustrating an otherwise successful search).</p><p><strong>Mobile Apps need more than just App Shielding!</strong></p><p>Of course, app shielding on its own is not enough: we need well-known and tested primitives and protocols behind. But this is also true the other way around: if we don’t protect the key it doesn’t matter which protocol we use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5580ddc6bdb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android KeyStore: what is the difference between “StrongBox” and “hardware-backed” keys?]]></title>
            <link>https://proandroiddev.com/android-keystore-what-is-the-difference-between-strongbox-and-hardware-backed-keys-4c276ea78fd0?source=rss-acd2bbe98123------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c276ea78fd0</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-security]]></category>
            <dc:creator><![CDATA[Marc Obrador Sureda]]></dc:creator>
            <pubDate>Tue, 06 Nov 2018 20:17:22 GMT</pubDate>
            <atom:updated>2018-11-08T10:07:15.867Z</atom:updated>
            <content:encoded><![CDATA[<p>Together with the announcement of the Pixel 3 and 3 XL phones came a bunch of other announcements, one of them being the “Titan” security chips. It turns out that the new phones from Google are equipped with a security-dedicated chip, called Titan M, which is used by the OS (and lower level components) to e.g. verify the integrity of the images that are loaded at system’s boot or to verify your lock screen passcode. You can read more about the Titan M chips in this <a href="https://blog.google/products/pixel/titan-m-makes-pixel-3-our-most-secure-phone-yet/">blog post</a> by Google.</p><p>An interesting bit of information that can be read in there is the following:</p><blockquote>With Android 9, apps can now take advantage of <a href="https://developer.android.com/training/articles/keystore#HardwareSecurityModule">StrongBox KeyStore APIs</a> to generate and store their private keys in Titan M.</blockquote><p>Okay, so… “StrongBox Keystore APIs”, huh? The provided link brings you to the Android KeyStore documentation, with a section that reads as follows:</p><blockquote>Supported devices running Android 9 (API level 28) or higher installed can have a <em>StrongBox Keymaster</em>, an implementation of the Keymaster HAL that resides in a hardware security module. The module contains the following:</blockquote><blockquote>- Its own CPU.</blockquote><blockquote>- Secure storage.</blockquote><blockquote>- A true random-number generator.</blockquote><blockquote>- Additional mechanisms to resist package tampering and unauthorized sideloading of apps.</blockquote><h3>The Question</h3><p>But… haven’t we had the “hardware-backed” KeyStore implementation for a several Android releases already? Looking into the docs, we see that <a href="https://developer.android.com/reference/android/security/keystore/KeyInfo#isInsideSecureHardware()">KeyInfo.isInsideSecureHardware()</a> has been around since API level 23 (that is, Marshmallow — or, for what it’s worth, 3 major releases of Android ago).</p><p>So… what is the difference between a key generated using the new StrongBox API (more precisely, by calling <a href="https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder#setIsStrongBoxBacked(boolean)">KeyGenParameterSpec.Builder.setIsStrongBoxBacked(true)</a>) and a key generated with the “old” API but that is still “hardware-backed” (i.e., which returns truewhenKeyInfo.isInsideSecureHardware() is called)?</p><h3>The Answer</h3><p>Reading through the officials docs did not answer the question, so I decided to ask directly to the people at Google responsible for Android Security. It turns out, I was lucky enough to get an answer:</p><h3>Marc Obrador Sureda on Twitter</h3><p>@DaveKSecure @rene_mobile what&#39;s the difference between keys stored in Android P&#39;s &quot;StrongBox&quot; versus the ones stored in the old &quot;HW-backed keystore&quot;? StrongBox = Secure Element // HW-backed = TEE? Can&#39;t find a clear statement in the docs... Thanks!</p><h3>Rene Mayrhofer on Twitter</h3><p>@marcobrador @DaveKSecure Yes, that&#39;s exactly the distinction. Before the explicit specification of StrongBox, HW-backed could refer to various different ways of storing these keys where a Linux kernel compromise would not reveal them. The standard implementation is in a TEE. 1/2</p><h3>Rene Mayrhofer on Twitter</h3><p>@marcobrador @DaveKSecure So HW-backed still allows various implementations (most commonly in TrustZone), but StrongBox is much more strictly defined as a discrete separate hardware and allows guarantees such as Insider Attack Resistance, but may be slower. Both can exist on a device in parallel. 2/2</p><p>Long story short: “StrongBox” means that the keys are stored in a Secure Element (“Titan M” chip in the Pixel 3 phones), whereas “hardware-backed” means something more generic like “somewhere outside of the Android OS” (the standard implementation of it being in a TEE).</p><p>Ok, but… What is a TEE? And a Secure Element?</p><p><strong>Note:</strong> short detour to explain the concepts of SE and TEE. If you already know them, you can skip it and go directly to the “conclusion”.</p><p><a href="https://en.wikipedia.org/wiki/Trusted_execution_environment">According to Wikipedia</a>:</p><blockquote>A <strong>trusted execution environment</strong> (<strong>TEE</strong>) is a secure area of a main processor.</blockquote><p>More precisely, a TEE runs its own OS, and communicates with the “main” OS only through a “restricted” interface (generally a shared memory region which both OS’s use to exchange data). In the case of Android, this means that compromising the Android OS (or its kernel) would not result in compromising the processes running in the TEE.</p><p>Android phones have been equipped with TEEs for some time now, and it is common that the biometric sensors of the phone (e.g. the fingerprint scanner) are directly connected to the TEE, meaning that the end user’s biometric data lives only within the TEE and never in the Android OS.</p><p>A <strong>Secure Element</strong> (SE) goes one step further: it is a separate microchip, with its own CPU, storage, RAM, etc. which is designed specifically for security-relevant purposes. SEs are resistant to a wider variety of attacks, both logical and physical, such as <a href="https://en.wikipedia.org/wiki/Side-channel_attack">side-channel attacks</a>. Interestingly enough, you are probably using SEs in your daily life without knowing it: your SIM card’s chip is a SE, and also is your credit card’s.</p><h3>The Conclusion</h3><p>SEs provide the strongest security level available in the industry as of today, so you should use the new “StrongBox” API for generating your cryptographic material whenever it is available. If it is not, but your key info’s isInsideSecureHardware() returns true (which would mean that your keys are protected -at least- by a TEE), then you can also rest assured that your keys are protected by a “good enough” combination of software and hardware.</p><p>Unfortunately, there will be <em>lots</em> of devices where neither StrongBox nor hardware-backed keys will be available (do I hear <em>fragmentation</em>?), so… what is the solution for those devices? The answer is: it depends. In such devices, the security of the key material relies solely on software measures, which means that a compromise of the Android OS (such as a root exploit) might end up revealing you user’s keys. What are the implications that this would have on you <em>and</em> your users? Is it acceptable from a business perspective? You’ll first need to answer those questions before making any decision.</p><p>If this is acceptable for you, then great! You can stop reading. If not, you still have a few options left. The easiest and cheapest one is to leave the users of such devices behind, disabling the feature that requires the crypto material if the required protection level is not available. In cases were this is not possible, <a href="http://www.whiteboxcrypto.com/">WhiteBox Cryptography</a> (WBC) libraries offer a good compromise between security and device support.</p><h3>The Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-PUsS8MdSceW1AtkHE4AHQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c276ea78fd0" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/android-keystore-what-is-the-difference-between-strongbox-and-hardware-backed-keys-4c276ea78fd0">Android KeyStore: what is the difference between “StrongBox” and “hardware-backed” keys?</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>