From 745d2c98f9467f1befb7ec3a6c485333d4f1b437 Mon Sep 17 00:00:00 2001 From: Dmitry Dementyev Date: Fri, 13 Apr 2018 14:10:05 -0700 Subject: [PATCH] Remove implementation of deprecated RecoveryController methods. Bug: 78021839 Test: manual Change-Id: I8a8a23f1cc14e7b9ffe1e758b6f35906d1a5cf2f --- .../keystore/recovery/KeyChainSnapshot.java | 10 ++-- .../keystore/recovery/RecoveryController.java | 22 +++------ .../keystore/recovery/RecoverySession.java | 57 ++-------------------- .../keystore/recovery/WrappedApplicationKey.java | 4 +- .../com/android/internal/widget/ILockSettings.aidl | 6 --- .../server/locksettings/LockSettingsService.java | 27 +--------- .../RecoverableKeyStoreManager.java | 47 ++---------------- .../KeyChainSnapshotSerializerTest.java | 17 +------ 8 files changed, 23 insertions(+), 167 deletions(-) diff --git a/core/java/android/security/keystore/recovery/KeyChainSnapshot.java b/core/java/android/security/keystore/recovery/KeyChainSnapshot.java index 54f82f9410b6..c748c87e0805 100644 --- a/core/java/android/security/keystore/recovery/KeyChainSnapshot.java +++ b/core/java/android/security/keystore/recovery/KeyChainSnapshot.java @@ -71,7 +71,6 @@ public final class KeyChainSnapshot implements Parcelable { 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 mKeyChainProtectionParams; private List mEntryRecoveryData; @@ -123,7 +122,7 @@ public final class KeyChainSnapshot implements Parcelable { */ @Deprecated public @NonNull byte[] getTrustedHardwarePublicKey() { - return mPublicKey; + throw new UnsupportedOperationException(); } /** @@ -228,12 +227,11 @@ public final class KeyChainSnapshot implements Parcelable { * * @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 @@ public final class KeyChainSnapshot implements Parcelable { out.writeInt(mMaxAttempts); out.writeLong(mCounterId); out.writeByteArray(mServerParams); - out.writeByteArray(mPublicKey); out.writeTypedObject(mCertPath, /* no flags */ 0); } @@ -328,7 +325,6 @@ public final class KeyChainSnapshot implements Parcelable { 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 fa4964df48cc..70054fc2d71e 100644 --- a/core/java/android/security/keystore/recovery/RecoveryController.java +++ b/core/java/android/security/keystore/recovery/RecoveryController.java @@ -309,17 +309,7 @@ public class RecoveryController { 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 @@ public class RecoveryController { @Deprecated @RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE) public @Nullable KeyChainSnapshot getRecoveryData() throws InternalRecoveryServiceException { - return getKeyChainSnapshot(); + throw new UnsupportedOperationException(); } /** @@ -457,7 +447,7 @@ public class RecoveryController { @RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE) public List getAliases(@Nullable String packageName) throws InternalRecoveryServiceException { - return getAliases(); + throw new UnsupportedOperationException(); } /** @@ -484,7 +474,7 @@ public class RecoveryController { public void setRecoveryStatus( @NonNull String packageName, String alias, int status) throws NameNotFoundException, InternalRecoveryServiceException { - setRecoveryStatus(alias, status); + throw new UnsupportedOperationException(); } /** @@ -518,7 +508,7 @@ public class RecoveryController { @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 @@ public class RecoveryController { @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 dc2961b303d3..3bb64219cdca 100644 --- a/core/java/android/security/keystore/recovery/RecoverySession.java +++ b/core/java/android/security/keystore/recovery/RecoverySession.java @@ -89,24 +89,7 @@ public class RecoverySession implements AutoCloseable { @NonNull byte[] vaultChallenge, @NonNull List 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 @@ public class RecoverySession implements AutoCloseable { @NonNull byte[] vaultChallenge, @NonNull List 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 @@ public class RecoverySession implements AutoCloseable { @NonNull List applicationKeys) throws SessionExpiredException, DecryptionFailedException, InternalRecoveryServiceException { - try { - return (Map) 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 7f81d0473491..187a671c57cb 100644 --- a/core/java/android/security/keystore/recovery/WrappedApplicationKey.java +++ b/core/java/android/security/keystore/recovery/WrappedApplicationKey.java @@ -80,7 +80,7 @@ public final class WrappedApplicationKey implements Parcelable { */ @Deprecated public Builder setAccount(@NonNull byte[] account) { - return this; + throw new UnsupportedOperationException(); } /** @@ -139,7 +139,7 @@ public final class WrappedApplicationKey implements Parcelable { */ @Deprecated public @NonNull byte[] getAccount() { - return new byte[0]; + throw new UnsupportedOperationException(); } public static final Parcelable.Creator CREATOR = diff --git a/core/java/com/android/internal/widget/ILockSettings.aidl b/core/java/com/android/internal/widget/ILockSettings.aidl index ae7ba1948c00..7e63adc27c9e 100644 --- a/core/java/com/android/internal/widget/ILockSettings.aidl +++ b/core/java/com/android/internal/widget/ILockSettings.aidl @@ -57,7 +57,6 @@ interface ILockSettings { // 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 @@ interface ILockSettings { 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 secrets); byte[] startRecoverySessionWithCertPath(in String sessionId, in String rootCertificateAlias, in RecoveryCertPath verifierCertPath, in byte[] vaultParams, in byte[] vaultChallenge, in List secrets); - Map/**/ recoverKeys(in String sessionId, in byte[] recoveryKeyBlob, - in List applicationKeys); Map/**/ 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 4b58d537e844..fb1874c165b7 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 @@ public class LockSettingsService extends ILockSettings.Stub { } @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 @@ public class LockSettingsService extends ILockSettings.Stub { } @Override - public byte[] startRecoverySession(@NonNull String sessionId, - @NonNull byte[] verifierPublicKey, @NonNull byte[] vaultParams, - @NonNull byte[] vaultChallenge, @NonNull List 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 @@ public class LockSettingsService extends ILockSettings.Stub { } @Override - public void closeSession(@NonNull String sessionId) throws RemoteException { - mRecoverableKeyStoreManager.closeSession(sessionId); - } - - @Override public Map recoverKeyChainSnapshot( @NonNull String sessionId, @NonNull byte[] recoveryKeyBlob, @@ -2067,10 +2046,8 @@ public class LockSettingsService extends ILockSettings.Stub { } @Override - public @NonNull Map recoverKeys(@NonNull String sessionId, - @NonNull byte[] recoveryKeyBlob, @NonNull List 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 c484251cc1fc..f6001eb1def6 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 @@ public class RecoverableKeyStoreManager { } /** - * @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(); @@ -436,7 +437,8 @@ public class RecoverableKeyStoreManager { * * @hide */ - public @NonNull byte[] startRecoverySession( + @VisibleForTesting + @NonNull byte[] startRecoverySession( @NonNull String sessionId, @NonNull byte[] verifierPublicKey, @NonNull byte[] vaultParams, @@ -552,45 +554,6 @@ public class RecoverableKeyStoreManager { * 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 recoverKeys( - @NonNull String sessionId, - @NonNull byte[] encryptedRecoveryKey, - @NonNull List 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 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 07c620371868..a23ac0fce6ab 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 @@ public class KeyChainSnapshotSerializerTest { } @Test - public void serialize_doesNotThrowForNullPublicKey() throws Exception { + public void serialize_doesNotThrowForTestSnapshot() throws Exception { KeyChainSnapshotSerializer.serialize( - createTestKeyChainSnapshotNoPublicKey(), new ByteArrayOutputStream()); + createTestKeyChainSnapshot(), new ByteArrayOutputStream()); } private static List roundTripKeys() throws Exception { @@ -198,19 +198,6 @@ public class KeyChainSnapshotSerializerTest { .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 createKeys() { ArrayList keyList = new ArrayList<>(); keyList.add(createKey(TEST_KEY_1_ALIAS, TEST_KEY_1_BYTES)); -- 2.11.0