isUserAuthenticationRequirementEnforcedBySecureHardware() is simply a logical AND of isInsideSecureHardware() and isUserAuthenticationRequired().
I think that's not true (see methods below) it comes via the key
from KeyChain
.
Is there something more to it than that?
KeyInfo.java
is a container class for key
info from a KeyChain
.
Whether the key
is bound to the secure hardware is known only once the key
has been imported.
To find out, use:
{
PrivateKey key = ...; // private key from KeyChain
KeyFactory keyFactory =
KeyFactory.getInstance(key.getAlgorithm(), "AndroidKeyStore");
KeyInfo keyInfo = keyFactory.getKeySpec(key, KeyInfo.class);
if (keyInfo.isInsideSecureHardware())
{
// The key is bound to the secure hardware of this Android
}
}
From KeyInfo.java:
/**
* Returns {@code true} if the key resides inside secure hardware (e.g., Trusted Execution
* Environment (TEE) or Secure Element (SE)). Key material of such keys is available in
* plaintext only inside the secure hardware and is not exposed outside of it.
*/
public boolean isInsideSecureHardware()
{
return mInsideSecureHardware;
}
/**
* Returns {@code true} if the requirement that this key can only be used if the user has been
* authenticated is enforced by secure hardware (e.g., Trusted Execution Environment (TEE) or
* Secure Element (SE)).
*
* @see #isUserAuthenticationRequired()
*/
public boolean isUserAuthenticationRequirementEnforcedBySecureHardware()
{
return mUserAuthenticationRequirementEnforcedBySecureHardware;
}
/**
* Returns {@code true} if the key is authorized to be used only if the user has been
* authenticated.
*
* <p>This authorization applies only to secret key and private key operations. Public key
* operations are not restricted.
*
* @see #getUserAuthenticationValidityDurationSeconds()
* @see KeyGenParameterSpec.Builder#setUserAuthenticationRequired(boolean)
* @see KeyProtection.Builder#setUserAuthenticationRequired(boolean)
*/
public boolean isUserAuthenticationRequired()
{
return mUserAuthenticationRequired;
}
See also:
KeyStore.java
isUserAuthenticationRequirementEnforcedBySecureHardware
not simply being a logical AND ofisInsideSecureHardware
andisUserAuthenticationRequired
. – Quickly