Merge "Remove implementation of deprecated RecoveryController methods." into pi-dev
am: 5291268754
Change-Id: Ic390d4b001ec63db78e5f8effc59a1c445153c6a
diff --git a/core/java/android/security/keystore/recovery/KeyChainSnapshot.java b/core/java/android/security/keystore/recovery/KeyChainSnapshot.java
index 54f82f9..c748c87 100644
--- a/core/java/android/security/keystore/recovery/KeyChainSnapshot.java
+++ b/core/java/android/security/keystore/recovery/KeyChainSnapshot.java
@@ -71,7 +71,6 @@
private int mMaxAttempts = DEFAULT_MAX_ATTEMPTS;
private long mCounterId = DEFAULT_COUNTER_ID;
private byte[] mServerParams;
- private byte[] mPublicKey; // The raw public key bytes used
private RecoveryCertPath mCertPath; // The cert path including necessary intermediate certs
private List<KeyChainProtectionParams> mKeyChainProtectionParams;
private List<WrappedApplicationKey> mEntryRecoveryData;
@@ -123,7 +122,7 @@
*/
@Deprecated
public @NonNull byte[] getTrustedHardwarePublicKey() {
- return mPublicKey;
+ throw new UnsupportedOperationException();
}
/**
@@ -228,12 +227,11 @@
*
* @param publicKey The public key
* @return This builder.
- * @deprecated Use {@link #setTrustedHardwareCertPath} instead.
+ * @removed Use {@link #setTrustedHardwareCertPath} instead.
*/
@Deprecated
public Builder setTrustedHardwarePublicKey(byte[] publicKey) {
- mInstance.mPublicKey = publicKey;
- return this;
+ throw new UnsupportedOperationException();
}
/**
@@ -313,7 +311,6 @@
out.writeInt(mMaxAttempts);
out.writeLong(mCounterId);
out.writeByteArray(mServerParams);
- out.writeByteArray(mPublicKey);
out.writeTypedObject(mCertPath, /* no flags */ 0);
}
@@ -328,7 +325,6 @@
mMaxAttempts = in.readInt();
mCounterId = in.readLong();
mServerParams = in.createByteArray();
- mPublicKey = in.createByteArray();
mCertPath = in.readTypedObject(RecoveryCertPath.CREATOR);
}
diff --git a/core/java/android/security/keystore/recovery/RecoveryController.java b/core/java/android/security/keystore/recovery/RecoveryController.java
index fa4964d..70054fc 100644
--- a/core/java/android/security/keystore/recovery/RecoveryController.java
+++ b/core/java/android/security/keystore/recovery/RecoveryController.java
@@ -309,17 +309,7 @@
public void initRecoveryService(
@NonNull String rootCertificateAlias, @NonNull byte[] signedPublicKeyList)
throws CertificateException, InternalRecoveryServiceException {
- try {
- mBinder.initRecoveryService(rootCertificateAlias, signedPublicKeyList);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- } catch (ServiceSpecificException e) {
- if (e.errorCode == ERROR_BAD_CERTIFICATE_FORMAT
- || e.errorCode == ERROR_INVALID_CERTIFICATE) {
- throw new CertificateException("Invalid certificate for recovery service", e);
- }
- throw wrapUnexpectedServiceSpecificException(e);
- }
+ throw new UnsupportedOperationException();
}
/**
@@ -379,7 +369,7 @@
@Deprecated
@RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE)
public @Nullable KeyChainSnapshot getRecoveryData() throws InternalRecoveryServiceException {
- return getKeyChainSnapshot();
+ throw new UnsupportedOperationException();
}
/**
@@ -457,7 +447,7 @@
@RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE)
public List<String> getAliases(@Nullable String packageName)
throws InternalRecoveryServiceException {
- return getAliases();
+ throw new UnsupportedOperationException();
}
/**
@@ -484,7 +474,7 @@
public void setRecoveryStatus(
@NonNull String packageName, String alias, int status)
throws NameNotFoundException, InternalRecoveryServiceException {
- setRecoveryStatus(alias, status);
+ throw new UnsupportedOperationException();
}
/**
@@ -518,7 +508,7 @@
@RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE)
public int getRecoveryStatus(String packageName, String alias)
throws InternalRecoveryServiceException {
- return getRecoveryStatus(alias);
+ throw new UnsupportedOperationException();
}
/**
@@ -623,7 +613,7 @@
@RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE)
public Key generateKey(@NonNull String alias, byte[] account)
throws InternalRecoveryServiceException, LockScreenRequiredException {
- return generateKey(alias);
+ throw new UnsupportedOperationException();
}
/**
diff --git a/core/java/android/security/keystore/recovery/RecoverySession.java b/core/java/android/security/keystore/recovery/RecoverySession.java
index dc2961b..3bb6421 100644
--- a/core/java/android/security/keystore/recovery/RecoverySession.java
+++ b/core/java/android/security/keystore/recovery/RecoverySession.java
@@ -89,24 +89,7 @@
@NonNull byte[] vaultChallenge,
@NonNull List<KeyChainProtectionParams> secrets)
throws CertificateException, InternalRecoveryServiceException {
- try {
- byte[] recoveryClaim =
- mRecoveryController.getBinder().startRecoverySession(
- mSessionId,
- verifierPublicKey,
- vaultParams,
- vaultChallenge,
- secrets);
- return recoveryClaim;
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- } catch (ServiceSpecificException e) {
- if (e.errorCode == RecoveryController.ERROR_BAD_CERTIFICATE_FORMAT
- || e.errorCode == RecoveryController.ERROR_INVALID_CERTIFICATE) {
- throw new CertificateException("Invalid certificate for recovery session", e);
- }
- throw mRecoveryController.wrapUnexpectedServiceSpecificException(e);
- }
+ throw new UnsupportedOperationException();
}
/**
@@ -121,28 +104,7 @@
@NonNull byte[] vaultChallenge,
@NonNull List<KeyChainProtectionParams> secrets)
throws CertificateException, InternalRecoveryServiceException {
- // Wrap the CertPath in a Parcelable so it can be passed via Binder calls.
- RecoveryCertPath recoveryCertPath =
- RecoveryCertPath.createRecoveryCertPath(verifierCertPath);
- try {
- byte[] recoveryClaim =
- mRecoveryController.getBinder().startRecoverySessionWithCertPath(
- mSessionId,
- /*rootCertificateAlias=*/ "", // Use the default root cert
- recoveryCertPath,
- vaultParams,
- vaultChallenge,
- secrets);
- return recoveryClaim;
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- } catch (ServiceSpecificException e) {
- if (e.errorCode == RecoveryController.ERROR_BAD_CERTIFICATE_FORMAT
- || e.errorCode == RecoveryController.ERROR_INVALID_CERTIFICATE) {
- throw new CertificateException("Invalid certificate for recovery session", e);
- }
- throw mRecoveryController.wrapUnexpectedServiceSpecificException(e);
- }
+ throw new UnsupportedOperationException();
}
/**
@@ -210,20 +172,7 @@
@NonNull List<WrappedApplicationKey> applicationKeys)
throws SessionExpiredException, DecryptionFailedException,
InternalRecoveryServiceException {
- try {
- return (Map<String, byte[]>) mRecoveryController.getBinder().recoverKeys(
- mSessionId, recoveryKeyBlob, applicationKeys);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- } catch (ServiceSpecificException e) {
- if (e.errorCode == RecoveryController.ERROR_DECRYPTION_FAILED) {
- throw new DecryptionFailedException(e.getMessage());
- }
- if (e.errorCode == RecoveryController.ERROR_SESSION_EXPIRED) {
- throw new SessionExpiredException(e.getMessage());
- }
- throw mRecoveryController.wrapUnexpectedServiceSpecificException(e);
- }
+ throw new UnsupportedOperationException();
}
/**
diff --git a/core/java/android/security/keystore/recovery/WrappedApplicationKey.java b/core/java/android/security/keystore/recovery/WrappedApplicationKey.java
index 7f81d04..187a671 100644
--- a/core/java/android/security/keystore/recovery/WrappedApplicationKey.java
+++ b/core/java/android/security/keystore/recovery/WrappedApplicationKey.java
@@ -80,7 +80,7 @@
*/
@Deprecated
public Builder setAccount(@NonNull byte[] account) {
- return this;
+ throw new UnsupportedOperationException();
}
/**
@@ -139,7 +139,7 @@
*/
@Deprecated
public @NonNull byte[] getAccount() {
- return new byte[0];
+ throw new UnsupportedOperationException();
}
public static final Parcelable.Creator<WrappedApplicationKey> CREATOR =
diff --git a/core/java/com/android/internal/widget/ILockSettings.aidl b/core/java/com/android/internal/widget/ILockSettings.aidl
index ae7ba19..7e63adc 100644
--- a/core/java/com/android/internal/widget/ILockSettings.aidl
+++ b/core/java/com/android/internal/widget/ILockSettings.aidl
@@ -57,7 +57,6 @@
// Keystore RecoveryController methods.
// {@code ServiceSpecificException} may be thrown to signal an error, which caller can
// convert to {@code RecoveryManagerException}.
- void initRecoveryService(in String rootCertificateAlias, in byte[] signedPublicKeyList);
void initRecoveryServiceWithSigFile(in String rootCertificateAlias,
in byte[] recoveryServiceCertFile, in byte[] recoveryServiceSigFile);
KeyChainSnapshot getKeyChainSnapshot();
@@ -71,14 +70,9 @@
Map getRecoveryStatus();
void setRecoverySecretTypes(in int[] secretTypes);
int[] getRecoverySecretTypes();
- byte[] startRecoverySession(in String sessionId,
- in byte[] verifierPublicKey, in byte[] vaultParams, in byte[] vaultChallenge,
- in List<KeyChainProtectionParams> secrets);
byte[] startRecoverySessionWithCertPath(in String sessionId, in String rootCertificateAlias,
in RecoveryCertPath verifierCertPath, in byte[] vaultParams, in byte[] vaultChallenge,
in List<KeyChainProtectionParams> secrets);
- Map/*<String, byte[]>*/ recoverKeys(in String sessionId, in byte[] recoveryKeyBlob,
- in List<WrappedApplicationKey> applicationKeys);
Map/*<String, String>*/ recoverKeyChainSnapshot(
in String sessionId,
in byte[] recoveryKeyBlob,
diff --git a/services/core/java/com/android/server/locksettings/LockSettingsService.java b/services/core/java/com/android/server/locksettings/LockSettingsService.java
index 4b58d53..fb1874c 100644
--- a/services/core/java/com/android/server/locksettings/LockSettingsService.java
+++ b/services/core/java/com/android/server/locksettings/LockSettingsService.java
@@ -1980,13 +1980,6 @@
}
@Override
- public void initRecoveryService(@NonNull String rootCertificateAlias,
- @NonNull byte[] signedPublicKeyList) throws RemoteException {
- mRecoverableKeyStoreManager.initRecoveryService(rootCertificateAlias,
- signedPublicKeyList);
- }
-
- @Override
public void initRecoveryServiceWithSigFile(@NonNull String rootCertificateAlias,
@NonNull byte[] recoveryServiceCertFile, @NonNull byte[] recoveryServiceSigFile)
throws RemoteException {
@@ -2033,15 +2026,6 @@
}
@Override
- public byte[] startRecoverySession(@NonNull String sessionId,
- @NonNull byte[] verifierPublicKey, @NonNull byte[] vaultParams,
- @NonNull byte[] vaultChallenge, @NonNull List<KeyChainProtectionParams> secrets)
- throws RemoteException {
- return mRecoverableKeyStoreManager.startRecoverySession(sessionId, verifierPublicKey,
- vaultParams, vaultChallenge, secrets);
- }
-
- @Override
public @NonNull byte[] startRecoverySessionWithCertPath(@NonNull String sessionId,
@NonNull String rootCertificateAlias, @NonNull RecoveryCertPath verifierCertPath,
@NonNull byte[] vaultParams, @NonNull byte[] vaultChallenge,
@@ -2053,11 +2037,6 @@
}
@Override
- public void closeSession(@NonNull String sessionId) throws RemoteException {
- mRecoverableKeyStoreManager.closeSession(sessionId);
- }
-
- @Override
public Map<String, String> recoverKeyChainSnapshot(
@NonNull String sessionId,
@NonNull byte[] recoveryKeyBlob,
@@ -2067,10 +2046,8 @@
}
@Override
- public @NonNull Map<String, byte[]> recoverKeys(@NonNull String sessionId,
- @NonNull byte[] recoveryKeyBlob, @NonNull List<WrappedApplicationKey> applicationKeys)
- throws RemoteException {
- return mRecoverableKeyStoreManager.recoverKeys(sessionId, recoveryKeyBlob, applicationKeys);
+ public void closeSession(@NonNull String sessionId) throws RemoteException {
+ mRecoverableKeyStoreManager.closeSession(sessionId);
}
@Override
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
index 335da50..09906e4 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
@@ -167,9 +167,10 @@
}
/**
- * @deprecated Use {@link #initRecoveryServiceWithSigFile(String, byte[], byte[])} instead.
+ * Used by {@link #initRecoveryServiceWithSigFile(String, byte[], byte[])}.
*/
- public void initRecoveryService(
+ @VisibleForTesting
+ void initRecoveryService(
@NonNull String rootCertificateAlias, @NonNull byte[] recoveryServiceCertFile)
throws RemoteException {
checkRecoverKeyStorePermission();
@@ -444,7 +445,8 @@
*
* @hide
*/
- public @NonNull byte[] startRecoverySession(
+ @VisibleForTesting
+ @NonNull byte[] startRecoverySession(
@NonNull String sessionId,
@NonNull byte[] verifierPublicKey,
@NonNull byte[] vaultParams,
@@ -560,45 +562,6 @@
* service.
* @param applicationKeys The encrypted key blobs returned by the remote vault service. These
* were wrapped with the recovery key.
- * @return Map from alias to raw key material.
- * @throws RemoteException if an error occurred recovering the keys.
- */
- public @NonNull Map<String, byte[]> recoverKeys(
- @NonNull String sessionId,
- @NonNull byte[] encryptedRecoveryKey,
- @NonNull List<WrappedApplicationKey> applicationKeys)
- throws RemoteException {
- checkRecoverKeyStorePermission();
- Preconditions.checkNotNull(sessionId, "invalid session");
- Preconditions.checkNotNull(encryptedRecoveryKey, "encryptedRecoveryKey is null");
- Preconditions.checkNotNull(applicationKeys, "encryptedRecoveryKey is null");
- int uid = Binder.getCallingUid();
- RecoverySessionStorage.Entry sessionEntry = mRecoverySessionStorage.get(uid, sessionId);
- if (sessionEntry == null) {
- throw new ServiceSpecificException(ERROR_SESSION_EXPIRED,
- String.format(Locale.US,
- "Application uid=%d does not have pending session '%s'", uid, sessionId));
- }
-
- try {
- byte[] recoveryKey = decryptRecoveryKey(sessionEntry, encryptedRecoveryKey);
- return recoverApplicationKeys(recoveryKey, applicationKeys);
- } finally {
- sessionEntry.destroy();
- mRecoverySessionStorage.remove(uid);
- }
- }
-
- /**
- * Invoked by a recovery agent after a successful recovery claim is sent to the remote vault
- * service.
- *
- * @param sessionId The session ID used to generate the claim. See
- * {@link #startRecoverySession(String, byte[], byte[], byte[], List)}.
- * @param encryptedRecoveryKey The encrypted recovery key blob returned by the remote vault
- * service.
- * @param applicationKeys The encrypted key blobs returned by the remote vault service. These
- * were wrapped with the recovery key.
* @throws RemoteException if an error occurred recovering the keys.
*/
public @NonNull Map<String, String> recoverKeyChainSnapshot(
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/serialization/KeyChainSnapshotSerializerTest.java b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/serialization/KeyChainSnapshotSerializerTest.java
index 07c6203..a23ac0f 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/serialization/KeyChainSnapshotSerializerTest.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/serialization/KeyChainSnapshotSerializerTest.java
@@ -164,9 +164,9 @@
}
@Test
- public void serialize_doesNotThrowForNullPublicKey() throws Exception {
+ public void serialize_doesNotThrowForTestSnapshot() throws Exception {
KeyChainSnapshotSerializer.serialize(
- createTestKeyChainSnapshotNoPublicKey(), new ByteArrayOutputStream());
+ createTestKeyChainSnapshot(), new ByteArrayOutputStream());
}
private static List<WrappedApplicationKey> roundTripKeys() throws Exception {
@@ -198,19 +198,6 @@
.build();
}
- private static KeyChainSnapshot createTestKeyChainSnapshotNoPublicKey() throws Exception {
- return new KeyChainSnapshot.Builder()
- .setCounterId(COUNTER_ID)
- .setSnapshotVersion(SNAPSHOT_VERSION)
- .setServerParams(SERVER_PARAMS)
- .setMaxAttempts(MAX_ATTEMPTS)
- .setEncryptedRecoveryKeyBlob(KEY_BLOB)
- .setKeyChainProtectionParams(createKeyChainProtectionParamsList())
- .setWrappedApplicationKeys(createKeys())
- .setTrustedHardwareCertPath(CERT_PATH)
- .build();
- }
-
private static List<WrappedApplicationKey> createKeys() {
ArrayList<WrappedApplicationKey> keyList = new ArrayList<>();
keyList.add(createKey(TEST_KEY_1_ALIAS, TEST_KEY_1_BYTES));