Ответ 1
isUserAuthenticationRequirementEnforcedBySecureHardware() является просто логическим И из isInsideSecureHardware() и isUserAuthenticationRequired().
Я думаю, что это не так (см. методы ниже), он приходит через key
из KeyChain
.
Есть ли что-то еще для этого?
KeyInfo.java
является классом контейнера для key
информации от KeyChain
.
Независимо от того, привязан ли key
к защищенному оборудованию, только один раз, когда был импортирован key
.
Чтобы узнать, используйте:
{
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
}
}
От 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;
}
См. также: KeyStore.java