Keystore 2.0 SPI: Fix various CTS failures.

* Add missing purpose to HMAC operations.
* Pass correct key descriptor to wrapped key import.
* Corrected error message on Import wrapped key failure due to missing
  wrapping key.
* Do not bail out on missing attestation challenge when device
  properties are requested.
* Fix AndroidKeyStoreKey.equals(). It is sufficient to compare the
  unique key ID.

Test: Keystore CTS tests.
Change-Id: Id3b93b18486e3a818ae8e91be6344294ec592e68
This commit is contained in:
Janis Danisevskis
2021-02-07 16:30:15 -08:00
parent 84da5781da
commit 19cd93f603
4 changed files with 6 additions and 12 deletions

View File

@@ -190,7 +190,7 @@ public class KeyStoreSecurityLevel {
keyDescriptor.blob = wrappedKey;
keyDescriptor.domain = wrappedKeyDescriptor.domain;
return handleExceptions(() -> mSecurityLevel.importWrappedKey(wrappedKeyDescriptor,
return handleExceptions(() -> mSecurityLevel.importWrappedKey(keyDescriptor,
wrappingKeyDescriptor, maskingKey,
args.toArray(new KeyParameter[args.size()]), authenticatorSpecs));
}

View File

@@ -163,6 +163,9 @@ public abstract class AndroidKeyStoreHmacSpi extends MacSpi implements KeyStoreC
}
List<KeyParameter> parameters = new ArrayList<>();
parameters.add(KeyStore2ParameterUtils.makeEnum(
KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_SIGN
));
parameters.add(KeyStore2ParameterUtils.makeEnum(
KeymasterDefs.KM_TAG_ALGORITHM, KeymasterDefs.KM_ALGORITHM_HMAC
));

View File

@@ -21,7 +21,6 @@ import android.security.KeyStoreSecurityLevel;
import android.system.keystore2.Authorization;
import android.system.keystore2.Domain;
import android.system.keystore2.KeyDescriptor;
import android.util.Log;
import java.security.Key;
@@ -127,15 +126,6 @@ public class AndroidKeyStoreKey implements Key {
return false;
}
// If the key ids are equal and the class matches all the other fields cannot differ
// unless we have a bug.
if (!mAlgorithm.equals(other.mAlgorithm)
|| !mAuthorizations.equals(other.mAuthorizations)
|| !mDescriptor.equals(other.mDescriptor)) {
Log.e("AndroidKeyStoreKey", "Bug: key ids are identical, but key metadata"
+ "differs.");
return false;
}
return true;
}
}

View File

@@ -866,7 +866,8 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi {
try {
response = mKeyStore.getKeyEntry(wrappingkey);
} catch (android.security.KeyStoreException e) {
throw new KeyStoreException("Failed to load wrapping key.", e);
throw new KeyStoreException("Failed to import wrapped key. Keystore error code: "
+ e.getErrorCode(), e);
}
KeyDescriptor wrappedKey = makeKeyDescriptor(alias);