public InvalidKeyException getInvalidKeyException( String keystoreKeyAlias, int uid, KeyStoreException e) { switch (e.getErrorCode()) { case OP_AUTH_NEEDED: { .... // We now need to determine whether the key/operation can become usable if user // authentication is performed, or whether it can never become usable again. // User authentication requirements are contained in the key's characteristics. We // need to check whether these requirements can be be satisfied by asking the user // to authenticate. KeyCharacteristicskeyCharacteristics=newKeyCharacteristics(); intgetKeyCharacteristicsErrorCode= getKeyCharacteristics(keystoreKeyAlias, null, null, uid, keyCharacteristics); if (getKeyCharacteristicsErrorCode != NO_ERROR) { returnnewInvalidKeyException( "Failed to obtained key characteristics", getKeyStoreException(getKeyCharacteristicsErrorCode)); } List<BigInteger> keySids = keyCharacteristics.getUnsignedLongs(KeymasterDefs.KM_TAG_USER_SECURE_ID); if (keySids.isEmpty()) { // Key is not bound to any SIDs -- no amount of authentication will help here. returnnewKeyPermanentlyInvalidatedException(); } ...
// None of the key's SIDs can ever be authenticated returnnewKeyPermanentlyInvalidatedException(); } case UNINITIALIZED: returnnewKeyPermanentlyInvalidatedException(); default: returnnewInvalidKeyException("Keystore operation failed", e); } }
/** * Per operation authentication is needed before this operation is valid. * This is returned from {@link #begin} when begin succeeds but the operation uses * per-operation authentication and must authenticate before calling {@link #update} or * {@link #finish}. */ publicstaticfinalintOP_AUTH_NEEDED=15;