How I Found a P2 Cryptographic Vulnerability in Android’s KeyMa
An unprivileged Android app could use Java reflection to modify the global cryptographic provider registry, inserting a malicious KeyManager at highest priority. This allowed interception of private keys, weakening of cipher selection, or disabling of mutual TLS for any app using the standard TLS stack.
Published on medium.com
I discovered that a global cryptographic registry in Android — specifically the KeyManager component responsible for managing TLS/SSL key material — could be silently modified by an unprivileged application using Java reflection to bypass access controls. An attacker who exploited this could substitute a malicious…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The internal provider list in java.security.Security was mutable and accessible via reflection, and Android's hidden API restrictions did not block setAccessible on this field.
Impact
A malicious app could intercept private keys, substitute weak keys, downgrade ciphers, or disable mutual TLS for any app using the standard TLS stack, with no permissions or user interaction required.
What the attacker needed
Ability to install an app on the device; no special permissions required
The fix
The providers field should be made immutable, reflection access to it should be blocked, and modifications should require a privileged permission.
How it was found
- Obtain a reference to the Security class and its private providers field via reflection.
- Call setAccessible(true) to bypass private access.
- Retrieve the live provider list.
- Insert a malicious provider at index 0 (highest priority).
- Verify that the malicious provider is now first in the list.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Android apps use a shared list of cryptographic providers to handle secure connections (TLS). The report shows that a malicious app could secretly add its own provider to this list, which would then be used by other apps. This lets the attacker steal encryption keys or weaken security without the user noticing.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.