I need to securely store certain secret in my app using biometry. I wanted to use BiometricPrompt to obtain CryptoObject which will be used to cipher and decipher this secret (e.g. like described here: https://medium.com/androiddevelopers/using-biometricprompt-with-cryptoobject-how-and-why-aace500ccdb7).
val promptCrypto = BiometricPrompt.CryptoObject(cipher)
biometricPrompt.authenticate(promptInfo, promptCrypto)
But is there any known vulnerabilities in this mechanism? Is there any option to obtain this CryptoObject without using biometry (e.g. on rooted device)? Is it secure on all devices or are there any differences?
Thank you for your response.
Your topic questions
If it is Software then it may be possible to hack it. It's just a question of time, knowledge and effort.
Not that I am aware off, but I am not an expert in reverse engineering, just someone knowledgeably enough to tell you that an attacker doesn't need to bypass this security mechanism to extract the secret from your mobile app.
Just keep reading to understand how it's possible...
Secrets in a mobile app are public
The use of the CryptoObject and BiometricPrompt will securely encrypt the secret and store it with the underline mechanism known by the Android Hardware-backed Keystore:
While this may be very hard to hack, an intelligent attacker will not waste his time in trying to break it, instead, the attacker will download your mobile app binary, perform some static analysis on it to find the function in your code that uses the secret after it has been decrypted, and then use an instrumentation framework to hook to this function at runtime and extract the secret to a command and control server he controls, from where he will then be able to automate attacks using the extracted secret. The reach of this type of attacks will be limited if the secret is scoped to the current user of the mobile app.
One of the most popular instrumentation frameworks is Frida:
The bottom line here is that no matter how safely you store your secrets in the mobile app, they must be considered public from the moment your release the mobile app.
Delegate access to third party services and API's
I often see third-party APIs being accessed directly from within a mobile app, thus the mobile app will need to have the secrets to access them.
The problem with this approach is that once you cannot guarantee that an attacker will not steal your secrets, then you may only know that they have been compromised when your bill usage for this services goes to the roof. Worst, you may only find the secrets have been compromised after you are made aware that you have suffered a data breach, but now the reputation of your business is severely affected or damaged beyond repair, to not mention the huge fines that the business may have to pay due to breaches of laws, like the GDPR in Europe.
So my advice is to always delegate to a backend that you control the access to third party services/APIs, and you can read more about in my article Using a Reverse Proxy to Protect Third Party APIs:
Now you may say that you still need a secret to access this Reverse proxy, and that is true, but now you are only including one secret in the mobile app for a backend that you have total control off, where you can apply all defence measures you see fit to monitor abuse, throttle it or completely block it. So no more surprise bills in your third party services/APIs, because now they are accessed through this backend you control.
The bottom line is that a mobile app should only communicate with a backend that is under your control and any access to third-party APIs services must be done by this same backend you control. This way you limit the attack surface to only one place, where you will employ as many layers of defence as what you are protecting is worth.
Possible Solutions to defend your backend
I mention above that you can apply defences measures you see fit, and I recommend you to read this answer I gave to the question How to secure an API REST for mobile app?, especially the sections Securing the API Server and A Possible Better Solution to understand some of your options.
Do You Want To Go The Extra Mile?
In any response to a security question I always like to reference the excellent work from the OWASP foundation.
For APIS
OWASP API Security Top 10
For Mobile Apps
OWASP Mobile Security Project - Top 10 risks
OWASP - Mobile Security Testing Guide: