Skip to content

Replace mobile native private key storage with Secure Enclave / StrongBox #81912

Closed

Description

@rafecolton

Problem

Coming from Group-IB's feedback, using the SecureStore for private key storage is generally safe but subject to potentially vulnerability due to the private key being generated in the app and stored briefly in memory.

Why is this important?

It's possible that the private key contents could be leaked via logs or copied out of memory by malicious code running in userspace - either something we added without realizing or 3rd party code on a jailbroken device.

Solution

High Level

Group-IB recommended solution is to use the device's hardware security module (called "Secure Enclave" on iOS and "StrongBox" on Android) to generate the key pair. Similar to how passkey works under the hood, the HSM would generate the key pair and return only the public key and an ID to the client. The client could request that data be signed with that key, gated by successful face / fingerprint / passcode authentication, but never has access to the private key itself. That eliminates all risk of the private key being stolen or leaked.

Detailed

This is broken down into several steps. After each step, let's discuss in #ecuk-eu in Slack to determine the best path forward, as priorities and timing may shift.

  1. Select a library - The library we use today to access biometric features from react native, expo-secure-store, does not support the HSM. To add support for it would amount to writing a whole new library, so it's better to look for existing libraries that implement it, which we could then modify to suit our needs.
  2. Add missing features - We had to implement several patches to expo-secure-store to ensure it behaved as we needed. For example, we need to know what type of authentication was used, and we need to ensure it authenticates the user every time, even if the user recently authenticated. Full details of these patches can be found in [No QA] [Expensify Cards EU/UK] Split up expo-secure-store patches  #76288
    • The same features will need to be supported by our chosen library. If they are not already, we'll need to implement them and anything else that's missing.
    • We'll have to discuss internally and with the developer of the chosen package to determine the best path for implementing these changes. Ideally, we want to optimize for moving as quickly as possible and not supporting the library long-term. Some options are:
      • Implement the changes ourselves and create a patch while we wait for changes to be merged upstream
      • Fork the library and use the fork if the maintainer is unresponsive
      • Sponsor the project and ask the maintainer to implement the features themselves
      • Bring the author into our open source program as an expert contributor and have them implement the changes as part of their work for us
      • Hire the maintainer (they'd have to go through the normal process) and have them implement the changes as part of their work as an employee 😄
    • Once we decide on the library and determine which features are missing, I will help coordinate with the maintainer
  3. Update code flows to use the new library - This should be done in partnership with @JakubKorytko and @dariusz-biela, as they have the most context on the current code.
  4. Test, test, test! - myself, @joekaufmanexpensify, @chuckdries, and @DylanDylann will assist with this. This change will be implemented after the core flows are already live in production, so mistakes carry a high risk. Likely we will want to add it as another authentication provider, similar to mobile native and passkey, so we can test it in the troubleshooting and pin management flows before rolling it out to transaction authorization.
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. mrejdak commented on Feb 13, 2026

    @mrejdak
    Contributor

    Reviewed and tested the library and overall it looks solid.
    On Android, it defaults to TEE instead of StrongBox (it’s still hardware-backed security, slightly weaker than Strongbox, but much more widely available on Android devices).
    On iOS, it enforces Secure Enclave for EC256 and fails if unavailable. In practice, most devices support Secure Enclave.

    There are a few limitations that would require a patch and some other features (like returning the used authentication type) that weren’t supported in expo-secure-store are also missing or are only partially supported here (details in the next comment).

    Overall, it would need a few patches, but it still seems like a better and more efficient option than building the whole solution from scratch.

  2. mrejdak commented on Feb 13, 2026

    @mrejdak
    Contributor

    Findings and Issues:

    General:

    • On Android: it does not use StrongBox, defaults to TEE when available. This still provides hardware-level protection, slightly weaker than StrongBox, but is much more widely available - as of 2023, only about 45% of devices supported StrongBox (according to data from https://arxiv.org/html/2507.07927v1). It also has a fallback to software-based security in case hardware-based one is unavailable, which might be something we would want to disable via a patch.
    • On Android: mostly requires using Class 3 biometrics (formerly known as Strong) which include almost all fingerprint sensors and some more advanced face/iris scanners.
    • On iOS: it enforces the use of Secure Enclave and fails if unavailable - this should not pose a problem as the majority of devices support it. (According to the same source as above, about 96% of iPhones supported it as of 2023)

    Security concerns:

    • On Android, if biometrics are not configured, key creation falls back to creating a key without requiring user authentication

    Missing functionalities (that were introduced as patches to expo-secure-store):

    • enableDeviceFallback: partially supported:
      • iOS: currently not implemented
      • Android: available by using a disableDeviceFallback set to false (however it also has one problem - more about this later)
    • returnAuthType:
      • Android: currently only returns information whether a fallback was used, but can be patched to return more specific information about method used
      • iOS: does not return any information about authentication type used, as the iOS API doesn’t provide this information (however it can be inferred similarly to how it was done in a patch to expo-secure-store)
    • forceAuthenticationOnSave: not supported
    • failOnUpdate:
      • not supported, currently in case of a key alias collision it removes the previous one and creates a new one
    • forceReadAuthenticationOnSimulators:
      • also not supported

    Other problems:

    • validateKeyIntegrity - on Android it works only for RSA due to some hardcoded values (thus always fails for EC256)
    • signWithOptions - has disableDeviceFallback flag (Android only), however, regardless of its value, it does not allow fallback to device credentials.
  3. rafecolton commented on Feb 24, 2026

    @rafecolton
    MemberAuthor

    Latest update here

  4. self-assigned this
    on Feb 24, 2026
  5. rafecolton commented on Mar 17, 2026

    @rafecolton
    MemberAuthor

    Not overdue, see the comment above

  6. 29 remaining items

  7. changed the title [-][Due for payment 2026-04-14] [Due for payment 2026-04-14] Replace mobile native private key storage with Secure Enclave / StrongBox[/-] [+][Due for payment 2026-04-17] [Due for payment 2026-04-14] [Due for payment 2026-04-14] Replace mobile native private key storage with Secure Enclave / StrongBox[/+] on Apr 10, 2026
  8. melvin-bot commented on Apr 10, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  9. melvin-bot commented on Apr 10, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.57-1 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-04-17. 🎊

    For reference, here are some details about the assignees on this issue:

    • @heekinho does not require payment (Contractor)
    • @KioCoan does not require payment (Contractor)
    • @mrejdak does not require payment (Contractor)
  10. changed the title [-][Due for payment 2026-04-17] [Due for payment 2026-04-14] [Due for payment 2026-04-14] Replace mobile native private key storage with Secure Enclave / StrongBox[/-] [+]Replace mobile native private key storage with Secure Enclave / StrongBox[/+] on Apr 16, 2026
  11. removed their assignment
    on Apr 16, 2026
  12. rafecolton commented on Apr 20, 2026

    @rafecolton
    MemberAuthor

    This is done! Thanks @mrejdak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

DailyKSv2ImprovementItem broken or needs improvement.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions