Add a unit test for checking word list integrity
Also does minor clean-ups
This commit is contained in:
parent
74aa62a264
commit
683268a15f
9 changed files with 20 additions and 28 deletions
|
@ -48,7 +48,7 @@
|
|||
android:parentActivityName="com.stevesoltys.backup.activity.MainActivity" />
|
||||
|
||||
<service
|
||||
android:name="com.stevesoltys.backup.transport.ConfigurableBackupTransportService"
|
||||
android:name=".transport.ConfigurableBackupTransportService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.backup.TRANSPORT_HOST" />
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.stevesoltys.backup
|
||||
|
||||
import android.Manifest
|
||||
import android.Manifest.permission.READ_PHONE_STATE
|
||||
import android.app.Application
|
||||
import android.app.backup.IBackupManager
|
||||
|
@ -13,12 +12,7 @@ import com.stevesoltys.backup.crypto.KeyManager
|
|||
import com.stevesoltys.backup.crypto.KeyManagerImpl
|
||||
import com.stevesoltys.backup.settings.getDeviceName
|
||||
import com.stevesoltys.backup.settings.setDeviceName
|
||||
import io.github.novacrypto.hashing.Sha256
|
||||
import io.github.novacrypto.hashing.Sha256.sha256
|
||||
import io.github.novacrypto.hashing.Sha256.sha256Twice
|
||||
import java.lang.AssertionError
|
||||
|
||||
const val JOB_ID_BACKGROUND_BACKUP = 1
|
||||
|
||||
private val TAG = Backup::class.java.simpleName
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static com.stevesoltys.backup.settings.SettingsManagerKt.getBackupPassword;
|
||||
import static com.stevesoltys.backup.settings.SettingsManagerKt.setBackupPassword;
|
||||
|
||||
/**
|
||||
* @author Steve Soltys
|
||||
|
@ -116,7 +115,6 @@ class CreateBackupActivityController {
|
|||
String password = passwordTextView.getText().toString();
|
||||
|
||||
if (originalPassword.equals(password)) {
|
||||
setBackupPassword(parent, password);
|
||||
backupService.backupPackageData(selectedPackages, parent);
|
||||
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.stevesoltys.backup.settings
|
||||
|
||||
import android.app.Application
|
||||
import android.util.ByteStringUtils.toHexString
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import com.stevesoltys.backup.Backup
|
||||
import com.stevesoltys.backup.LiveEvent
|
||||
|
@ -21,7 +20,6 @@ class RecoveryCodeViewModel(application: Application) : AndroidViewModel(applica
|
|||
|
||||
internal val wordList: List<CharSequence> by lazy {
|
||||
val items: ArrayList<CharSequence> = ArrayList(WORD_NUM)
|
||||
// TODO factor out entropy generation
|
||||
val entropy = ByteArray(Words.TWELVE.byteLength())
|
||||
SecureRandom().nextBytes(entropy)
|
||||
MnemonicGenerator(English.INSTANCE).createMnemonic(entropy) {
|
||||
|
@ -50,9 +48,6 @@ class RecoveryCodeViewModel(application: Application) : AndroidViewModel(applica
|
|||
val seed = SeedCalculator(JavaxPBKDF2WithHmacSHA512.INSTANCE).calculateSeed(mnemonic, "")
|
||||
Backup.keyManager.storeBackupKey(seed)
|
||||
|
||||
// TODO remove once encryption/decryption uses key from KeyStore
|
||||
setBackupPassword(getApplication(), toHexString(seed))
|
||||
|
||||
mRecoveryCodeSaved.setEvent(true)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,18 +32,6 @@ fun getDeviceName(context: Context): String? {
|
|||
return getDefaultSharedPreferences(context).getString(PREF_KEY_DEVICE_NAME, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* This is insecure and not supposed to be part of a release,
|
||||
* but rather an intermediate step towards a generated passphrase.
|
||||
*/
|
||||
@Deprecated("Replaced by KeyManager#storeBackupKey()")
|
||||
fun setBackupPassword(context: Context, password: String) {
|
||||
getDefaultSharedPreferences(context)
|
||||
.edit()
|
||||
.putString(PREF_KEY_BACKUP_PASSWORD, password)
|
||||
.apply()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced by KeyManager#getBackupKey()")
|
||||
fun getBackupPassword(context: Context): String? {
|
||||
return getDefaultSharedPreferences(context).getString(PREF_KEY_BACKUP_PASSWORD, null)
|
||||
|
|
|
@ -110,6 +110,7 @@ class ConfigurableBackupTransport internal constructor(private val context: Cont
|
|||
}
|
||||
|
||||
override fun performFullBackup(targetPackage: PackageInfo, fileDescriptor: ParcelFileDescriptor): Int {
|
||||
Log.w(TAG, "Warning: Legacy performFullBackup() method called.")
|
||||
return backupCoordinator.performFullBackup(targetPackage, fileDescriptor, 0)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ class DocumentsProviderFullBackup(
|
|||
|
||||
@Throws(IOException::class)
|
||||
override fun getOutputStream(targetPackage: PackageInfo): OutputStream {
|
||||
// TODO test file-size after overwriting bigger file
|
||||
val file = storage.defaultFullBackupDir?.createOrGetFile(targetPackage.packageName)
|
||||
?: throw IOException()
|
||||
return storage.getOutputStream(file)
|
||||
|
|
|
@ -46,7 +46,6 @@ class DocumentsProviderKVBackup(private val storage: DocumentsStorage) : KVBacku
|
|||
override fun getOutputStreamForRecord(packageInfo: PackageInfo, key: String): OutputStream {
|
||||
val packageFile = this.packageFile ?: throw AssertionError()
|
||||
packageFile.assertRightFile(packageInfo)
|
||||
// TODO check what happens if we overwrite a bigger file
|
||||
val keyFile = packageFile.createOrGetFile(key)
|
||||
return storage.getOutputStream(keyFile)
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue