tlambertz / seedvault_backup_parser

Decrypt, Modify and Reencrypt Seedvault Android Backups
Apache License 2.0
103 stars 15 forks source link

InvalidKeyException thrown when attempting to restore from re-encrypted backup #9

Closed crass closed 3 years ago

crass commented 3 years ago

I followed the instructions in the section Wifi Key Import and copied the same wifi config from the successful decryption. I used the same key to re-encrypt as I used to decrypt. Any ideas on what might be going on?

Here's the relevant logcat:

03-10 12:36:27.673  8573  8573 D AndroidRuntime: Calling main entry com.android.commands.bmgr.Bmgr
--------- beginning of system
03-10 12:36:27.675  8573  8573 V Bmgr    : Running restore for user:0
03-10 12:36:27.675  1454  6073 V BackupManagerService: [UserID:0] beginRestoreSession: pkg=null transport=null
03-10 12:36:27.677  1454  6073 V BackupManagerService: [UserID:0] Acquired wakelock:*backup*-0-3379
03-10 12:36:27.681  7839  7839 D ConfigurableBackupTransportService: Service created.
03-10 12:36:27.682  7839  7839 D ConfigurableBackupTransportService: Transport bound.
03-10 12:36:27.683  1454  1454 I TransportClient: ConfigurableBackupTransportService#316: Notifying [BH/MSG_RUN_GET_RESTORE_SETS] transport = IBackupTransport
03-10 12:36:28.734  7839  7968 E JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
03-10 12:36:28.734  7839  7968 E JavaBinder: java.security.InvalidKeyException: Keystore operation failed
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1378)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1388)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:54)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:265)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:148)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2980)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at javax.crypto.Cipher.tryCombinations(Cipher.java:2891)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2796)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at javax.crypto.Cipher.chooseProvider(Cipher.java:773)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at javax.crypto.Cipher.init(Cipher.java:1288)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at javax.crypto.Cipher.init(Cipher.java:1223)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.crypto.CipherFactoryImpl.createDecryptionCipher(CipherFactory.kt:29)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.crypto.CryptoImpl.decryptSegment(Crypto.kt:210)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.crypto.CryptoImpl.decryptMultipleSegments(Crypto.kt:191)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.metadata.MetadataReaderImpl.readMetadata(MetadataReader.kt:51)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.transport.restore.RestoreCoordinator.getAvailableRestoreSets(RestoreCoordinator.kt:73)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.transport.ConfigurableBackupTransport$getAvailableRestoreSets$1.invokeSuspend(ConfigurableBackupTransport.kt:200)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:270)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.stevesoltys.seedvault.transport.ConfigurableBackupTransport.getAvailableRestoreSets(ConfigurableBackupTransport.kt:199)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.app.backup.BackupTransport$TransportImpl.getAvailableRestoreSets(BackupTransport.java:719)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at com.android.internal.backup.IBackupTransport$Stub.onTransact(IBackupTransport.java:657)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.os.Binder.execTransactInternal(Binder.java:1159)
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.os.Binder.execTransact(Binder.java:1123)
03-10 12:36:28.734  7839  7968 E JavaBinder: Caused by: android.security.KeyStoreException: Device locked
03-10 12:36:28.734  7839  7968 E JavaBinder:    at android.security.KeyStore.getKeyStoreException(KeyStore.java:1301)
03-10 12:36:28.734  7839  7968 E JavaBinder:    ... 30 more
03-10 12:36:28.739  1454  6073 D RestoreSession: endRestoreSession
03-10 12:36:28.741  8573  8573 D AndroidRuntime: Shutting down VM
03-10 12:36:28.747  7839  7839 D ConfigurableBackupTransportService: Service destroyed.
03-10 12:36:28.753  1454  3379 V BackupManagerService: [UserID:0] Released wakelock:*backup*-0-3379
03-10 12:36:28.753  1454  3379 V BackupManagerService: [UserID:0] Clearing restore session and halting timeout
crass commented 3 years ago

Missed the line with Caused by: android.security.KeyStoreException: Device locked ... perhaps this should be mentioned in the readme