MuntashirAkon / MuntashirAkon/AppManager

Backup fails with "GCM cipher cannot be reused for encryption" on large apps when encryption is enabled

Open
#1,958 1 comment 0 reactions 0 assignees View on GitHub
Bug Feature: Backup Priority: 2 Severity: 1 Status: Accepted
Dominant language
Java
Stars
9k
Forks
518
PR merge metrics
No merged PRs in 30d

Description

### Please check before submitting an issue

- [x] I know what my device, OS and App Manager versions are
- [x] I know how to take logs
- [x] I know that generating a report, in whole part or in part, using AI/LLM is prohibited
- [x] I know how to reproduce the issue which may not be specific to my device

### Describe the bug

When attempting to back up a very large application (specifically, obb, the game Injustice, package `com.wb.goog.injustice`) with backup encryption enabled, the backup process fails. The log shows an `IllegalStateException: GCM cipher cannot be reused for encryption`. This only happens with this specific large app; other smaller apps back up successfully with encryption enabled.

### To Reproduce

1. Enable backup AES encryption in App Manager.
2. Select a very large application/game for backup (e.g., Injustice - `com.wb.goog.injustice`).
3. Start the backup process.

### Expected behavior

The application should be backed up and encrypted successfully without throwing a cipher reuse exception, regardless of the app's large size.

### Screenshots

_No response_

### Logs

====> op=BACKUP_RESTORE, mode=BACKUP pkg=(com.wb.goog.injustice, 0)
io.github.muntashirakon.AppManager.backup.BackupException: Unknown error occurred.
at io.github.muntashirakon.AppManager.backup.BackupOp.runBackup(BackupOp.java:228)
at io.github.muntashirakon.AppManager.backup.BackupManager.backup(BackupManager.java:105)
at io.github.muntashirakon.AppManager.batchops.BatchOpsManager.lambda$backup$1$io-github-muntashirakon-AppManager-batchops-BatchOpsManager(BatchOpsManager.java:353)
at io.github.muntashirakon.AppManager.batchops.BatchOpsManager$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.IllegalStateException: GCM cipher cannot be reused for encryption
at org.bouncycastle.crypto.modes.GCMBlockCipher.checkStatus(Unknown Source:12)
at org.bouncycastle.crypto.modes.GCMBlockCipher.processBytes(Unknown Source:0)
at org.bouncycastle.crypto.io.CipherOutputStream.write(Unknown Source:38)
at android.os.FileUtils.copyInternalUserspace(FileUtils.java:692)
at android.os.FileUtils.copy(FileUtils.java:410)
at io.github.muntashirakon.io.IoUtils$$ExternalSyntheticApiModelOutline0.m(D8$$SyntheticClass:0)
at io.github.muntashirakon.io.IoUtils.copy(IoUtils.java:101)
at io.github.muntashirakon.io.IoUtils.copy(IoUtils.java:88)
at io.github.muntashirakon.AppManager.crypto.AESCrypto.handleFiles(AESCrypto.java:190)
at io.github.muntashirakon.AppManager.crypto.AESCrypto.encrypt(AESCrypto.java:127)
at io.github.muntashirakon.AppManager.backup.BackupOp.encrypt(BackupOp.java:521)
at io.github.muntashirakon.AppManager.backup.BackupOp.backupData(BackupOp.java:310)
at io.github.muntashirakon.AppManager.backup.BackupOp.runBackup(BackupOp.java:179)
... 8 more
Suppressed: org.bouncycastle.crypto.io.CipherIOException: Error closing stream:
at org.bouncycastle.crypto.io.CipherOutputStream.close(Unknown Source:59)
at io.github.muntashirakon.AppManager.crypto.AESCrypto.handleFiles(AESCrypto.java:189)
... 12 more
Caused by: java.lang.IllegalStateException: GCM cipher cannot be reused for encryption
at org.bouncycastle.crypto.modes.GCMBlockCipher.checkStatus(Unknown Source:12)
at org.bouncycastle.crypto.modes.GCMBlockCipher.doFinal(Unknown Source:0)
at org.bouncycastle.crypto.io.CipherOutputStream.close(Unknown Source:31)
... 13 more

### Device info

- Device: Xiaomi A2 Lite
- OS Version: Android 14 (LineageOS 21)
- App Manager Version: 4.0.5
- Mode: Root (APatch)

### Additional context

note that this app includes OBB files, and its total backup size should be approximately 1.7gb

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.