<?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 Lucia Lenz on Medium]]></title>
        <description><![CDATA[Stories by Lucia Lenz on Medium]]></description>
        <link>https://medium.com/@lenz.lucia?source=rss-e6c5b9fb825c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eKnt7nGAfX9YNRw-O1NOBg.jpeg</url>
            <title>Stories by Lucia Lenz on Medium</title>
            <link>https://medium.com/@lenz.lucia?source=rss-e6c5b9fb825c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:39:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lenz.lucia/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[Creating a white-label app with Compose Multiplatform]]></title>
            <link>https://medium.com/@lenz.lucia/creating-a-white-label-app-with-compose-multiplatform-2088368c9b5b?source=rss-e6c5b9fb825c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2088368c9b5b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <dc:creator><![CDATA[Lucia Lenz]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 08:40:10 GMT</pubDate>
            <atom:updated>2025-09-16T17:53:48.255Z</atom:updated>
            <content:encoded><![CDATA[<p>This article discusses the challenge of building a white-label mobile app that can be compiled into multiple branded clients for both iOS and Android. The product must incorporate native iOS and Android SDKs and remain configurable per client — a demanding setup for any cross-platform approach. Although Google recommends Flutter for apps that need a shared UI, we explore the more challenging option of using Compose Multiplatform. This choice could be justified if there is an existing Android codebase with a lot of reusable Kotlin and Compose code, and if the team has experience with native Android and iOS development but not with Flutter.<br>Compose Multiplatform still has some shortcomings when it comes to complex architectures, which we have to overcome. The most challenging aspect of this setup involves using Compose and Compose Resources, as well as integrating an iOS SDK. This is because the available technologies that would assist with the SDK, such as CocoaPods integration via Gradle-Plugin, are incompatible with Compose Resources. Also the fact that we should consume only one CMP Library with iOS has to be taken into account. In this article, I will explain an arichitecture that works and is real world proven in one of my projects.</p><p>Let’s imagine we have this fictional project: A white-label flower app that can be compiled with either a dahlia or forget-me-not theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tg6dE2qtCYtbx-FR4q2OOQ.png" /><figcaption>White-lable app diagramm</figcaption></figure><p>First, let’s review the native approaches to developing white-label apps.</p><p><strong>Android</strong></p><p>A good approach for Android would be to use multiple app modules for clients that depend on the white-label library module and are responsible for theming and setting environment-parameters. This is what such an approach would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*7h2Jz8XH1Hf8efJwIKukXg.png" /><figcaption>Example white-label android app using modules</figcaption></figure><p>In order to set environment-parameters, we provide an interface in the white-label module that the clients implement, and which we then inject wherever necessary using a dependency injection library (Koin, for example). This approach is scalable, and we will use it for the Compose-Multiplatform project as it does not rely on Android-specific features such as flavours.</p><p><strong>iOS</strong></p><p>Now let’s look at how an iOS app would implement a white-label architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*lQQGI_BzQzj0kKfr_5LhwQ.png" /><figcaption>Example iOS project using targets</figcaption></figure><p>In iOS it is common to use targets.<a href="https://www.paleblueapps.com/rockandnull/how-to-create-a-white-label-ios-app/"> (See this article for more information.) </a>This example project has two targets: ‘dahlia’ and ‘forgetmenot’. Each class is assigned to a specific target, or to both. The app is ultimately compiled to the targets. Therefore, there will be two apps: ‘Dahlia’ and ‘Forgetmenot’. <br>In the above example, I assigned the Flower class in the Dahlia folder to the Dahlia target and the Flower class in the Forgetmenot folder to the Forgetmenot target. This allows the behaviour of ‘Flower’ to be completely switched depending on the target. Of course, if ‘Flower’ is used in common code, the ‘Flower’ classes have to be polymorphic.</p><p><strong>Compose-Multiplatform</strong></p><p>Before I bring all the approaches together, let’s look at the approach we chose for implementing the Compose-Multiplatform part, since there are several options. The only approach that will work with Compose Resources is the ‘direct integration’ approach. <a href="https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-ios-integration-overview.html">(Please refer to the official documentation for more information.)</a> This means that our Compose app is built into a .framework that is used in the Xcode build. Furthermore, in this approach, the Compose resources are provided to the Xcode project. As far as I know, this is the only integration method that provides resources. However, since CMP is a hot topic, this could change at any time.</p><p>This is what a standard Compose Multiplatform Project with direct integration will look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gp0tt2H6ok_HG8fEiq89iw.png" /><figcaption>Example CMP project</figcaption></figure><p>In the picture, on the left-hand side you can see the composeApp. This is the Compose Multiplatform app that will compile to Android and be included in the iOS App. The iOS App is an Xcode project that utilises a custom build phase to include the Compose App. On the right-hand side, we can see the custom build phase utilising the ‘embedAndSignAppleFrameworkForXcode’ command, which performs the entire integration process. Note that build phases are target-specific in iOS.</p><p><strong>White-label Compose Multiplatform</strong></p><p>We finally have the foundation to build our white-label Compose-Multiplatform app. Here is what our project looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5gogM2cVuQpZ9KGCr31NQ.png" /><figcaption>Structure of a white label cmp project</figcaption></figure><p>We have one Compose Multiplatform library module called ‘whitelabelApp’ and two Compose Multiplatform app modules called ‘dahlia’ and ‘forgetmenot’. There is also an iOS app, which is a white-label app. The Compose Multiplatform whitelabelApp library provides everything that can be shared, plus interfaces that have to be implemented by clients. The client Compose Multiplatform app modules provide the implementations and theming, as shown on the right-hand side. For Android, MainActivity resides in androidMain, and the Forgetmenot Android app can be built directly with this setup. In contrast, the iosMain module in forgetmenot only provides the MainViewController.</p><p>This MainViewController can be used in the usual way in the Xcode project. However, to use the correct Compose Multiplatform module for our specific target, we must configure this in the build phases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4JiZCf6tFKqW9Rg2v654Zg.png" /><figcaption>ios integration of the themed cmp module</figcaption></figure><p>Since the build phases are target-specific, we build the Forgetmenot Compose Multiplatform module for Xcode for the Forgetmenot target, and the Dahlia module for the Dahlia target. This allows us to use all the benefits of targets for iOS together with an already branded CMP library. In the common code of the iOS project, we call the MainViewController prepared by the CMP library. We must ensure that the MainViewController provided by Forgetmenot is polymorphic with the MainViewController provided by Dahlia, since both will be called in the common code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdQuLx0_9dAo8971P6gMdA.png" /><figcaption>MainViewController is called in common code in the iosApp</figcaption></figure><p>Let’s look at a diagram to make the setup clearer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdjhAsEwF5XZJMXfBFm4pA.png" /><figcaption>Detailed diagram of a white-label cmp app</figcaption></figure><p>In the Gradle world, we use modules to achieve a white label solution. We have a whitelabelApp that is consumed by our two client CMP modules. In Xcode, we use targets to represent the clients. These targets depend on the themed CMP modules. For example, the dahlia target depends on the dahlia CMP module.</p><p>This is a rather complex setup, especially since you have to watch out for polymorphism in the classes used for both targets. However, at least the build will fail for the other target if you make a mistake. This is why you should definitely have a pipeline that at least builds all targets and clients before merging changes. There is also a significant advantage to this approach. It makes it easy to use iOS SDKs. Here’s why:</p><p><strong>Integration of iOS SKDs</strong></p><p>To integrate an iOS SDK, we can simply use the package manager in Xcode. To use the iOS SDK in the whitelabelApp CMP library, we simply need to provide the relevant interfaces in the whitelabelApp module (written in Kotlin). We implement these interfaces with the help of the SDK using Swift in the common part of the Xcode project. Therefore, no Objective-C bridge is required. We use the Kotlin-to-Swift bridge, which is created during the Gradle build. This is much easier and faster than using C-interop. <a href="https://medium.com/@andriiseredenko/writing-ios-code-in-kotlin-multiplatform-part-4-swift-bdaef8f69d94">(See this reference for a more detailed description of this approach.)</a></p><p><strong>Final thoughts</strong></p><p>This is definitely not the most elegant architecture, but it works. It circumvents several issues like the one with Compose Resources and iOS SDKS or the inability to include multiple Kotlin frameworks with common dependencies (like dahlia and whitelabelApp, where dahlia contains whitelableApp) in an iOS project <a href="https://touchlab.co/multiple-kotlin-frameworks-in-application/">without causing problems</a>. Furthermore the easy iOS SDK integration is a relief. However, if you are planning to implement something similar, consider whether Flutter is the better choice for you. And of course, check the official documentation. Maybe by the time you read this article there are easier ways to go.</p><p><strong>References</strong></p><ul><li><a href="https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-ios-integration-overview.html">iOS integration methods | Kotlin Multiplatform</a></li><li><a href="https://www.paleblueapps.com/rockandnull/how-to-create-a-white-label-ios-app/">How to create a white label iOS app (Part 1)</a></li><li><a href="https://medium.com/@andriiseredenko/writing-ios-code-in-kotlin-multiplatform-part-4-swift-bdaef8f69d94">Writing iOS code in Kotlin Multiplatform. Part 4 — Swift</a></li><li><a href="https://sujanpoudel.me/blogs/managing-configurations-for-different-environments-in-kmp/">Managing configurations for the different environments (eg: staging, prod) in Kotlin Multiplatform</a></li><li><a href="https://touchlab.co/multiple-kotlin-frameworks-in-application/">Multiple Kotlin Frameworks in an Application</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2088368c9b5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication with a MIFARE DESFire Light card using a key stored in the Android Keystore]]></title>
            <link>https://proandroiddev.com/authentication-with-a-mifare-desfire-light-card-using-a-key-stored-in-the-android-keystore-eeffdfe2abda?source=rss-e6c5b9fb825c------2</link>
            <guid isPermaLink="false">https://medium.com/p/eeffdfe2abda</guid>
            <category><![CDATA[mifare-desfire]]></category>
            <category><![CDATA[android-keystore]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Lucia Lenz]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 10:16:41 GMT</pubDate>
            <atom:updated>2024-03-06T12:45:22.447Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5DmDB0Ud0QZwX6rZ" /><figcaption>Photo by <a href="https://unsplash.com/@dizzydizz?utm_source=medium&amp;utm_medium=referral">Muhammad Zaqy Al Fattah</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To authenticate with MIFARE DESFire Light cards a pre-shared AES-key is needed. This key needs to be stored safely. On Android the safest place for the key is in the secure hardware of the device using the Android Keystore. The Android Keystore is very restrictive. The key is imported into the keystore together with a list, which specifies which operations are permitted. Since the key can not leave the secure hardware, it can only be used with algorithms available inside the keystore. These features have two challenging consequences. I will discuss how to solve them in the following.</p><p>This article will not discuss any details about distributing AES-keys from a server to the devices and importing them into the Android Keystore. This is a quite advanced topic on its own. I will assume you already have that mechanism in place.</p><p><strong>MIFARE DESFire Light authentication and the Android Keystore challenge</strong></p><p>Let us recap which steps are needed in order to establish encrypted communication. We’re going to look at <em>AuthenticateEV2First</em> only. Which is the default way for authentication with these type of cards. Please refer to the <a href="https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf">official nxp documentation</a> or <a href="https://www.nxp.com/docs/en/application-note/AN12343.pdf">nxp developement hints</a> if you need further details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MDrTX6to4pJFD1a_DsFnsw.png" /><figcaption>Simplified process to start communication in CommunicationMode.Full</figcaption></figure><p>The phone proves to the card that it posesses the AES-key without exposing it and vise versa. The process consists of the following steps:</p><ol><li>The phone initiates authentication and receives a random number RndB, which was encrypted by the card. An AES/CBC cipher is used with the pre-shared AES-key and a fixed zero initialisation vector (IV).</li><li>The phone decrypts RndB and returns the proof, together with an encrypted random number RndA.</li><li>The card proves in turn that it was able to decrypt RndA by returning the proof together with the initial session data.</li><li>With the initial session data the session keys are calculated using a CMAC algorithm. All consecutive communication with the card will be encrypted with these session keys, which mutate with each call.</li></ol><p>When going through this process with an Android Keystore key, the first challenge is that an IV set by the caller is not permitted by default but is needed for steps 1 to 3. The second challenge is, that the CMAC algorithm needed for step 4 is not available in the Android Keystore. Let’s look at the two problems one after the other.</p><p><strong>Solving the “caller-provided IV not permitted” challenge</strong></p><p>The Android Keystore does not permit setting an IV for a cipher by the caller by default. Instead the cipher generates its own IV randomly to make sure same input does not yield same output. Therefore trying to set the zero IV for our AES/CBC cipher will result in an exception like this:</p><pre>java.security.InvalidAlgorithmParameterException: <br>  Caller-provided IV not permitted</pre><p>This is good when you use the key for encryption. But when using it for authentication, it is crucial that the phone and the card do the same steps. Therefore we will allow a caller provided IV for this key.</p><p>Distributing secret keys to Android and importing them into the Android Keystore is explained in the <a href="https://developer.android.com/training/articles/keystore#ImportingEncryptedKeys">Android docs</a>. Roughly, the AES-key is encrypted server-side with a public key created in the Android Keystore. Then the encrypted AES-key, together with its metadata, is sent back to the device in ASN.1 format. On the device the key is imported into the keystore where it is decrypted in turn.</p><p>The ASN.1 for the key and its metadata looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d340b266b5777d0887979f16b1a6c3ba/href">https://medium.com/media/d340b266b5777d0887979f16b1a6c3ba/href</a></iframe><p>For our challenge the interesting part is the AuthorizationList. This property is explained in <a href="https://source.android.com/docs/security/features/keystore/attestation">this android reference</a>. There we also find the ASN.1 description of the AuthorizationList itself:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85e4f8e7da7229efb9c1ce4a1394f241/href">https://medium.com/media/85e4f8e7da7229efb9c1ce4a1394f241/href</a></iframe><p>The property which we have to set in order to provide a custom IV is called <a href="https://source.android.com/docs/security/features/keystore/tags#caller_nonce">CALLER_NONCE</a> and is omitted in the documentation, but it is implemented in the <a href="https://android.googlesource.com/platform/hardware/interfaces/+/master/keymaster/4.0/types.hal">android keymaster hal</a>. There we learn that it is enumerated with 7. We also need the block mode, which is enumerated with 4. Here I include it into the ASN.1 definition of the AuthorizationList:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a9e7f50c723cac2ddcb033a16214bce/href">https://medium.com/media/1a9e7f50c723cac2ddcb033a16214bce/href</a></iframe><p>Now we have to add this property in our implementation that constructs the ASN.1 bytearray. We add callerNonce only for the AES-key where it is necessary. Providing an IV for a cipher is bad practice as mentioned above. We only enable it for the AES-key used for authentication. Also, you should only set the needed algorithm and block mode to be sure that the key is not used with insecure algorithms. Here ist the snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53ebdd820b4b9d8c0fdbbae9be404614/href">https://medium.com/media/53ebdd820b4b9d8c0fdbbae9be404614/href</a></iframe><p>We use Bouncy Castle to create the bytearray. If you want to understand ASN.1, read this great <a href="https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/">article</a>. There is, of course, much more code required to create the SecureKeyWrapper, but here we just concentrate on the steps required to communicate with the MIFARE card. After you set the key properties correctly, the encrypted AES-key should be distributed to the devices and imported in the keystore as usual.</p><p><strong>Solving the “CMAC algorithm” challenge</strong></p><p>The second challenge is, that there is no CMAC algorithm available in the Android Keystore. It is impossible to use an Android Keystore key outside of the Android Keystore (this is the main reason why it is so safe). Therefore we can not use e.g. Bouncy Castles CMAC implementation.</p><p>The good news is: the only moment we need the AES-key is when we encrypt something with an AES/CBC/NoPadding cipher. In other words: we can write the Android Keystore compatible CMAC function independent of the key itself:</p><pre>fun cmac(message: ByteArray, cipher: () -&gt; Cipher): ByteArray </pre><p>The AES/CBC cipher is available in the Android Keystore, actually we use it in the authentication process. So we just have to implement the rest of the CMAC algorithm ourselves. The <a href="http://www.nuee.nagoya-u.ac.jp/labs/tiwata/omac/omac.html">original CMAC paper</a> looks very challenging, but luckily there are many implementations already. I refer to the implementation of<a href="https://github.com/krzyzanowskim/CryptoSwift/blob/main/Sources/CryptoSwift/CMAC.swift"> crypto swift</a> to understand how this works. In the end it boils down to chopping the message into blocksized parts, some bitshifting, encryption and xor’ing. If you implemented the <em>AuthenticateEV2First</em> process up to this point, it’s easy as pancakes.</p><p><strong>Wrap up</strong></p><p>Finally, we are able to do steps 1 to 3 proving to the card that the phone is authorised to establish encrypted communication. And we are even able to calculate the session keys in step 4 and communicate encrypted in <em>CommunicationMode.Full</em>. All in all it is not easy to implement the process using an Android Keystore key. But in the end it works and the AES-key is as safe as possible!</p><p>Thanks to <a href="https://medium.com/u/c5033ffa517d">Stefan Schrass</a> and my team at Deutsche Bahn who made this work possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eeffdfe2abda" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/authentication-with-a-mifare-desfire-light-card-using-a-key-stored-in-the-android-keystore-eeffdfe2abda">Authentication with a MIFARE DESFire Light card using a key stored in the Android Keystore</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>