am c6eb6288: Merge "Split key origin into TEE/not and generated/imported."
* commit 'c6eb62882b09cf06e1e70c14e7878593d1a76477': Split key origin into TEE/not and generated/imported.
This commit is contained in:
@@ -31,7 +31,7 @@ public abstract class KeyStoreKeyCharacteristics {
|
|||||||
private KeyStoreKeyCharacteristics() {}
|
private KeyStoreKeyCharacteristics() {}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({Origin.GENERATED_INSIDE_TEE, Origin.GENERATED_OUTSIDE_OF_TEE, Origin.IMPORTED})
|
@IntDef({Origin.GENERATED, Origin.IMPORTED})
|
||||||
public @interface OriginEnum {}
|
public @interface OriginEnum {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,14 +40,11 @@ public abstract class KeyStoreKeyCharacteristics {
|
|||||||
public static abstract class Origin {
|
public static abstract class Origin {
|
||||||
private Origin() {}
|
private Origin() {}
|
||||||
|
|
||||||
/** Key was generated inside a TEE. */
|
/** Key was generated inside AndroidKeyStore. */
|
||||||
public static final int GENERATED_INSIDE_TEE = 1;
|
public static final int GENERATED = 1 << 0;
|
||||||
|
|
||||||
/** Key was generated outside of a TEE. */
|
/** Key was imported into AndroidKeyStore. */
|
||||||
public static final int GENERATED_OUTSIDE_OF_TEE = 2;
|
public static final int IMPORTED = 1 << 1;
|
||||||
|
|
||||||
/** Key was imported. */
|
|
||||||
public static final int IMPORTED = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
@@ -55,9 +52,7 @@ public abstract class KeyStoreKeyCharacteristics {
|
|||||||
public static @OriginEnum int fromKeymaster(int origin) {
|
public static @OriginEnum int fromKeymaster(int origin) {
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case KeymasterDefs.KM_ORIGIN_HARDWARE:
|
case KeymasterDefs.KM_ORIGIN_HARDWARE:
|
||||||
return GENERATED_INSIDE_TEE;
|
return GENERATED;
|
||||||
case KeymasterDefs.KM_ORIGIN_SOFTWARE:
|
|
||||||
return GENERATED_OUTSIDE_OF_TEE;
|
|
||||||
case KeymasterDefs.KM_ORIGIN_IMPORTED:
|
case KeymasterDefs.KM_ORIGIN_IMPORTED:
|
||||||
return IMPORTED;
|
return IMPORTED;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.util.Date;
|
|||||||
public class KeyStoreKeySpec implements KeySpec {
|
public class KeyStoreKeySpec implements KeySpec {
|
||||||
private final String mKeystoreAlias;
|
private final String mKeystoreAlias;
|
||||||
private final int mKeySize;
|
private final int mKeySize;
|
||||||
|
private final boolean mTeeBacked;
|
||||||
private final @KeyStoreKeyCharacteristics.OriginEnum int mOrigin;
|
private final @KeyStoreKeyCharacteristics.OriginEnum int mOrigin;
|
||||||
private final Date mKeyValidityStart;
|
private final Date mKeyValidityStart;
|
||||||
private final Date mKeyValidityForOriginationEnd;
|
private final Date mKeyValidityForOriginationEnd;
|
||||||
@@ -46,6 +47,7 @@ public class KeyStoreKeySpec implements KeySpec {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
KeyStoreKeySpec(String keystoreKeyAlias,
|
KeyStoreKeySpec(String keystoreKeyAlias,
|
||||||
|
boolean teeBacked,
|
||||||
@KeyStoreKeyCharacteristics.OriginEnum int origin,
|
@KeyStoreKeyCharacteristics.OriginEnum int origin,
|
||||||
int keySize,
|
int keySize,
|
||||||
Date keyValidityStart,
|
Date keyValidityStart,
|
||||||
@@ -60,6 +62,7 @@ public class KeyStoreKeySpec implements KeySpec {
|
|||||||
@KeyStoreKeyConstraints.UserAuthenticatorEnum int teeEnforcedUserAuthenticators,
|
@KeyStoreKeyConstraints.UserAuthenticatorEnum int teeEnforcedUserAuthenticators,
|
||||||
int userAuthenticationValidityDurationSeconds) {
|
int userAuthenticationValidityDurationSeconds) {
|
||||||
mKeystoreAlias = keystoreKeyAlias;
|
mKeystoreAlias = keystoreKeyAlias;
|
||||||
|
mTeeBacked = teeBacked;
|
||||||
mOrigin = origin;
|
mOrigin = origin;
|
||||||
mKeySize = keySize;
|
mKeySize = keySize;
|
||||||
mKeyValidityStart = keyValidityStart;
|
mKeyValidityStart = keyValidityStart;
|
||||||
@@ -82,6 +85,14 @@ public class KeyStoreKeySpec implements KeySpec {
|
|||||||
return mKeystoreAlias;
|
return mKeystoreAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the key is TEE-backed. Key material of TEE-backed keys is available
|
||||||
|
* in plaintext only inside the TEE.
|
||||||
|
*/
|
||||||
|
public boolean isTeeBacked() {
|
||||||
|
return mTeeBacked;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the origin of the key.
|
* Gets the origin of the key.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ public class KeyStoreSecretKeyFactorySpi extends SecretKeyFactorySpi {
|
|||||||
+ " Keystore error: " + errorCode);
|
+ " Keystore error: " + errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@KeyStoreKeyCharacteristics.OriginEnum Integer origin;
|
boolean teeBacked;
|
||||||
|
@KeyStoreKeyCharacteristics.OriginEnum int origin;
|
||||||
int keySize;
|
int keySize;
|
||||||
@KeyStoreKeyConstraints.PurposeEnum int purposes;
|
@KeyStoreKeyConstraints.PurposeEnum int purposes;
|
||||||
@KeyStoreKeyConstraints.AlgorithmEnum int algorithm;
|
@KeyStoreKeyConstraints.AlgorithmEnum int algorithm;
|
||||||
@@ -80,11 +81,17 @@ public class KeyStoreSecretKeyFactorySpi extends SecretKeyFactorySpi {
|
|||||||
@KeyStoreKeyConstraints.UserAuthenticatorEnum int userAuthenticators;
|
@KeyStoreKeyConstraints.UserAuthenticatorEnum int userAuthenticators;
|
||||||
@KeyStoreKeyConstraints.UserAuthenticatorEnum int teeEnforcedUserAuthenticators;
|
@KeyStoreKeyConstraints.UserAuthenticatorEnum int teeEnforcedUserAuthenticators;
|
||||||
try {
|
try {
|
||||||
origin = KeymasterUtils.getInt(keyCharacteristics, KeymasterDefs.KM_TAG_ORIGIN);
|
if (keyCharacteristics.hwEnforced.containsTag(KeymasterDefs.KM_TAG_ORIGIN)) {
|
||||||
if (origin == null) {
|
teeBacked = true;
|
||||||
|
origin = KeyStoreKeyCharacteristics.Origin.fromKeymaster(
|
||||||
|
keyCharacteristics.hwEnforced.getInt(KeymasterDefs.KM_TAG_ORIGIN, -1));
|
||||||
|
} else if (keyCharacteristics.swEnforced.containsTag(KeymasterDefs.KM_TAG_ORIGIN)) {
|
||||||
|
teeBacked = false;
|
||||||
|
origin = KeyStoreKeyCharacteristics.Origin.fromKeymaster(
|
||||||
|
keyCharacteristics.swEnforced.getInt(KeymasterDefs.KM_TAG_ORIGIN, -1));
|
||||||
|
} else {
|
||||||
throw new InvalidKeySpecException("Key origin not available");
|
throw new InvalidKeySpecException("Key origin not available");
|
||||||
}
|
}
|
||||||
origin = KeyStoreKeyCharacteristics.Origin.fromKeymaster(origin);
|
|
||||||
Integer keySizeInteger =
|
Integer keySizeInteger =
|
||||||
KeymasterUtils.getInt(keyCharacteristics, KeymasterDefs.KM_TAG_KEY_SIZE);
|
KeymasterUtils.getInt(keyCharacteristics, KeymasterDefs.KM_TAG_KEY_SIZE);
|
||||||
if (keySizeInteger == null) {
|
if (keySizeInteger == null) {
|
||||||
@@ -144,6 +151,7 @@ public class KeyStoreSecretKeyFactorySpi extends SecretKeyFactorySpi {
|
|||||||
KeymasterUtils.getInt(keyCharacteristics, KeymasterDefs.KM_TAG_AUTH_TIMEOUT);
|
KeymasterUtils.getInt(keyCharacteristics, KeymasterDefs.KM_TAG_AUTH_TIMEOUT);
|
||||||
|
|
||||||
return new KeyStoreKeySpec(entryAlias,
|
return new KeyStoreKeySpec(entryAlias,
|
||||||
|
teeBacked,
|
||||||
origin,
|
origin,
|
||||||
keySize,
|
keySize,
|
||||||
keyValidityStart,
|
keyValidityStart,
|
||||||
|
|||||||
Reference in New Issue
Block a user