Skip to content

Commit

Permalink
Merge pull request #56 from PhilKes/feat/encrypt-backups
Browse files Browse the repository at this point in the history
Add Backup Password preference + encrypt ZIP Backups
  • Loading branch information
PhilKes authored Oct 25, 2024
2 parents a0e09ae + 7deb374 commit a17d6bf
Show file tree
Hide file tree
Showing 31 changed files with 884 additions and 559 deletions.
31 changes: 0 additions & 31 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Bug Report
description: Create a report to help us improve
labels: ["bug"]
projects: []
body:
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: input
id: version
attributes:
label: App Version
description: What version of the app are you running?
validations:
required: true
- type: input
id: android-version
attributes:
label: Android Version
description: What Android version are you using?
- type: textarea
id: logs
attributes:
label: (Optional) Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {
implementation "net.zetetic:android-database-sqlcipher:4.5.3"
implementation "androidx.sqlite:sqlite-ktx:2.4.0"
implementation "androidx.security:security-crypto:1.1.0-alpha06"
implementation 'net.lingala.zip4j:zip4j:2.11.5'

implementation "androidx.work:work-runtime:2.9.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.lifecycle.Observer
import com.philkes.notallyx.presentation.view.misc.BiometricLock.enabled
import com.philkes.notallyx.presentation.view.misc.Theme
import com.philkes.notallyx.utils.backup.scheduleAutoBackup
import com.philkes.notallyx.utils.backup.Export.scheduleAutoBackup
import com.philkes.notallyx.utils.security.UnlockReceiver

class NotallyXApplication : Application() {
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/philkes/notallyx/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package com.philkes.notallyx
import android.app.Application
import android.os.Build
import android.preference.PreferenceManager
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import com.philkes.notallyx.presentation.view.misc.AutoBackup
import com.philkes.notallyx.presentation.view.misc.AutoBackupMax
import com.philkes.notallyx.presentation.view.misc.AutoBackupPeriodDays
import com.philkes.notallyx.presentation.view.misc.BackupPassword
import com.philkes.notallyx.presentation.view.misc.BetterLiveData
import com.philkes.notallyx.presentation.view.misc.BiometricLock
import com.philkes.notallyx.presentation.view.misc.DateFormat
Expand Down Expand Up @@ -40,6 +43,15 @@ class Preferences private constructor(app: Application) {
private val preferences = PreferenceManager.getDefaultSharedPreferences(app)
private val editor = preferences.edit()

private val encryptedPreferences =
EncryptedSharedPreferences.create(
app,
"secret_shared_prefs",
MasterKey.Builder(app).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM,
)

// Main thread (unfortunately)
val view = BetterLiveData(getListPref(View))
val theme = BetterLiveData(getListPref(Theme))
Expand All @@ -56,6 +68,7 @@ class Preferences private constructor(app: Application) {
val autoBackupPath = BetterLiveData(getTextPref(AutoBackup))
var autoBackupPeriodDays = BetterLiveData(getSeekbarPref(AutoBackupPeriodDays))
var autoBackupMax = getSeekbarPref(AutoBackupMax)
var backupPassword = BetterLiveData(getEncryptedTextPref(BackupPassword))

val biometricLock = BetterLiveData(getListPref(BiometricLock))
var iv: ByteArray?
Expand Down Expand Up @@ -105,6 +118,9 @@ class Preferences private constructor(app: Application) {
private fun getTextPref(info: TextInfo) =
requireNotNull(preferences.getString(info.key, info.defaultValue))

private fun getEncryptedTextPref(info: TextInfo) =
requireNotNull(encryptedPreferences.getString(info.key, info.defaultValue))

private fun getSeekbarPref(info: SeekbarInfo) =
requireNotNull(preferences.getInt(info.key, info.defaultValue))

Expand Down Expand Up @@ -176,10 +192,12 @@ class Preferences private constructor(app: Application) {
}

fun savePreference(info: TextInfo, value: String) {
val editor = if (info is BackupPassword) encryptedPreferences.edit() else this.editor
editor.putString(info.key, value)
editor.commit()
when (info) {
AutoBackup -> autoBackupPath.postValue(getTextPref(info))
BackupPassword -> backupPassword.postValue(getEncryptedTextPref(info))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import com.philkes.notallyx.R
import com.philkes.notallyx.data.model.Attachment
import com.philkes.notallyx.data.model.Audio
import com.philkes.notallyx.data.model.FileAttachment
import com.philkes.notallyx.utils.IO
import com.philkes.notallyx.utils.IO.getExternalAudioDirectory
import com.philkes.notallyx.utils.IO.getExternalFilesDirectory
import com.philkes.notallyx.utils.IO.getExternalImagesDirectory
import com.philkes.notallyx.utils.isImage
import java.io.File
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -65,9 +67,9 @@ class AttachmentDeleteService : Service() {

scope.launch {
withContext(Dispatchers.IO) {
val imageRoot = IO.getExternalImagesDirectory(application)
val audioRoot = IO.getExternalAudioDirectory(application)
val fileRoot = IO.getExternalFilesDirectory(application)
val imageRoot = application.getExternalImagesDirectory()
val audioRoot = application.getExternalAudioDirectory()
val fileRoot = application.getExternalFilesDirectory()
do {
val attachments = channel.receive()
attachments.forEachIndexed { index, attachment ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ interface BaseNoteDao {

@Query("SELECT * FROM BaseNote") fun getAll(): LiveData<List<BaseNote>>

@Query("SELECT * FROM BaseNote WHERE id IN (:ids)") fun getByIds(ids: LongArray): List<BaseNote>

@Query("SELECT B.id FROM BaseNote B") fun getAllIds(): List<Long>

@Query("SELECT * FROM BaseNote WHERE id = :id") fun get(id: Long): BaseNote?

@Query("SELECT images FROM BaseNote WHERE id = :id") fun getImages(id: Long): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.philkes.notallyx.presentation.view.misc.View
import com.philkes.notallyx.presentation.view.note.listitem.ListItemListener
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
import com.philkes.notallyx.presentation.widget.WidgetProvider
import com.philkes.notallyx.utils.IO
import com.philkes.notallyx.utils.IO.getExternalImagesDirectory
import java.util.Collections
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -54,7 +54,7 @@ class ConfigureWidgetActivity : LockedActivity<ActivityConfigureWidgetBinding>()
maxItems,
maxLines,
maxTitle,
IO.getExternalImagesDirectory(application),
application.getExternalImagesDirectory(),
this@ConfigureWidgetActivity,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class MainActivity : LockedActivity<ActivityMainBinding>() {
private fun deleteForever() {
MaterialAlertDialogBuilder(this)
.setMessage(R.string.delete_selected_notes)
.setPositiveButton(R.string.delete) { _, _ -> model.deleteBaseNotes() }
.setPositiveButton(R.string.delete) { _, _ -> model.deleteSelectedBaseNotes() }
.setNegativeButton(R.string.cancel, null)
.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeletedFragment : NotallyFragment() {
private fun deleteAllNotes() {
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.delete_all_notes)
.setPositiveButton(R.string.delete) { _, _ -> model.deleteAllBaseNotes() }
.setPositiveButton(R.string.delete) { _, _ -> model.deleteAllTrashedBaseNotes() }
.setNegativeButton(R.string.cancel, null)
.show()
}
Expand Down
Loading

0 comments on commit a17d6bf

Please sign in to comment.