Skip to content

Commit

Permalink
Merge branch 'release/2.9.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Apr 13, 2021
2 parents 33beb57 + 11aae77 commit 123288e
Show file tree
Hide file tree
Showing 62 changed files with 867 additions and 469 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
KeePassDX(2.9.17)
* Import / Export app properties #839
* Force twofish padding compatibility #955
* Better timeout preference #579

KeePassDX(2.9.16)
* Fix small bugs #948

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.kunzisoft.keepass"
minSdkVersion 15
targetSdkVersion 30
versionCode = 70
versionName = "2.9.16"
versionCode = 71
versionName = "2.9.17"
multiDexEnabled true

testApplicationId = "com.kunzisoft.keepass.tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class EntryEditActivity : LockingActivity(),
entryEditFragment?.icon = icon
}

mExternalFileHelper?.onActivityResultCallback(requestCode, resultCode, data) { uri ->
mExternalFileHelper?.onOpenDocumentResult(requestCode, resultCode, data) { uri ->
uri?.let { attachmentToUploadUri ->
UriUtil.getFileData(this, attachmentToUploadUri)?.also { documentFile ->
documentFile.name?.let { fileName ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class FileDatabaseSelectActivity : SpecialModeActivity(),
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data)
}

mExternalFileHelper?.onActivityResultCallback(requestCode, resultCode, data) { uri ->
mExternalFileHelper?.onOpenDocumentResult(requestCode, resultCode, data) { uri ->
if (uri != null) {
launchPasswordActivityWithPath(uri)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class IconPickerActivity : LockingActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

mExternalFileHelper?.onActivityResultCallback(requestCode, resultCode, data) { uri ->
mExternalFileHelper?.onOpenDocumentResult(requestCode, resultCode, data) { uri ->
addCustomIcon(uri)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ open class PasswordActivity : SpecialModeActivity(), AdvancedUnlockFragment.Buil

var keyFileResult = false
mExternalFileHelper?.let {
keyFileResult = it.onActivityResultCallback(requestCode, resultCode, data
keyFileResult = it.onOpenDocumentResult(requestCode, resultCode, data
) { uri ->
if (uri != null) {
mDatabaseKeyFileUri = uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class AssignMasterKeyDialogFragment : DialogFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

mExternalFileHelper?.onActivityResultCallback(requestCode, resultCode, data) { uri ->
mExternalFileHelper?.onOpenDocumentResult(requestCode, resultCode, data) { uri ->
uri?.let { pathUri ->
UriUtil.getFileData(requireContext(), uri)?.length()?.let { lengthFile ->
keyFileSelectionView?.error = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ class ExternalFileHelper {
/**
* To use in onActivityResultCallback in Fragment or Activity
* @param keyFileCallback Callback retrieve from data
* @return true if requestCode was captured, false elsechere
* @param onFileSelected Callback retrieve from data
* @return true if requestCode was captured, false elsewhere
*/
fun onActivityResultCallback(requestCode: Int, resultCode: Int, data: Intent?,
keyFileCallback: ((uri: Uri?) -> Unit)?): Boolean {
fun onOpenDocumentResult(requestCode: Int, resultCode: Int, data: Intent?,
onFileSelected: ((uri: Uri?) -> Unit)?): Boolean {
when (requestCode) {
FILE_BROWSE -> {
Expand All @@ -118,7 +118,7 @@ class ExternalFileHelper {
if (filename != null) {
keyUri = UriUtil.parse(filename)
}
keyFileCallback?.invoke(keyUri)
onFileSelected?.invoke(keyUri)
}
return true
}
Expand All @@ -138,7 +138,7 @@ class ExternalFileHelper {
} catch (e: Exception) {
// nop
}
keyFileCallback?.invoke(uri)
onFileSelected?.invoke(uri)
}
}
}
Expand Down Expand Up @@ -190,11 +190,16 @@ class ExternalFileHelper {
return null
}
/**
* To use in onActivityResultCallback in Fragment or Activity
* @param onFileCreated Callback retrieve from data
* @return true if requestCode was captured, false elsewhere
*/
fun onCreateDocumentResult(requestCode: Int, resultCode: Int, data: Intent?,
action: (fileCreated: Uri?)->Unit) {
onFileCreated: (fileCreated: Uri?)->Unit) {
// Retrieve the created URI from the file manager
if (fileRequestCodes.contains(requestCode) && resultCode == RESULT_OK) {
action.invoke(data?.data)
onFileCreated.invoke(data?.data)
fileRequestCodes.remove(requestCode)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ object Stylish {
* Initialize the class with a theme preference
* @param context Context to retrieve the theme preference
*/
fun init(context: Context) {
fun load(context: Context) {
Log.d(Stylish::class.java.name, "Attatching to " + context.packageName)
themeString = PreferencesUtil.getStyle(context)
}

private fun retrieveEquivalentSystemStyle(context: Context, styleString: String): String {
fun retrieveEquivalentSystemStyle(context: Context, styleString: String): String {
val systemNightMode = when (PreferencesUtil.getStyleBrightness(context)) {
context.getString(R.string.list_style_brightness_light) -> false
context.getString(R.string.list_style_brightness_night) -> true
Expand Down Expand Up @@ -84,12 +84,16 @@ object Stylish {
}
}

fun defaultStyle(context: Context): String {
return context.getString(R.string.list_style_name_light)
}

/**
* Assign the style to the class attribute
* @param styleString Style id String
*/
fun assignStyle(context: Context, styleString: String) {
themeString = retrieveEquivalentSystemStyle(context, styleString)
PreferencesUtil.setStyle(context, styleString)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/kunzisoft/keepass/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class App : MultiDexApplication() {
override fun onCreate() {
super.onCreate()

Stylish.init(this)
Stylish.load(this)
PRNGFixes.apply()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ abstract class CipherEngine {
return 16
}

// Used only with padding workaround
var forcePaddingCompatibility = false

@Throws(NoSuchAlgorithmException::class, NoSuchPaddingException::class, InvalidKeyException::class, InvalidAlgorithmParameterException::class)
abstract fun getCipher(opmode: Int, key: ByteArray, IV: ByteArray): Cipher

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TwofishEngine : CipherEngine() {

@Throws(NoSuchAlgorithmException::class, NoSuchPaddingException::class, InvalidKeyException::class, InvalidAlgorithmParameterException::class)
override fun getCipher(opmode: Int, key: ByteArray, IV: ByteArray): Cipher {
return CipherFactory.getTwofish(opmode, key, IV)
return CipherFactory.getTwofish(opmode, key, IV, forcePaddingCompatibility)
}

override fun getEncryptionAlgorithm(): EncryptionAlgorithm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ class DatabaseInputKDBX(cacheDirectory: File,
val cipher: Cipher
try {
engine = EncryptionAlgorithm.getFrom(mDatabase.cipherUuid).cipherEngine
engine.forcePaddingCompatibility = true
mDatabase.setDataEngine(engine)
mDatabase.encryptionAlgorithm = engine.getEncryptionAlgorithm()
cipher = engine.getCipher(Cipher.DECRYPT_MODE, mDatabase.finalKey!!, header.encryptionIV)
engine.forcePaddingCompatibility = false
} catch (e: Exception) {
throw InvalidAlgorithmDatabaseException(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.TimeoutHelper
import kotlinx.coroutines.*

class AdvancedUnlockNotificationService : NotificationService() {

private lateinit var mTempCipherDao: ArrayList<CipherDatabaseEntity>

private var mActionTaskBinder = AdvancedUnlockBinder()

private var notificationTimeoutMilliSecs: Long = 0
private var mTimerJob: Job? = null

inner class AdvancedUnlockBinder: Binder() {
fun getCipherDatabase(databaseUri: Uri): CipherDatabaseEntity? {
return mTempCipherDao.firstOrNull { it.databaseUri == databaseUri.toString()}
Expand Down Expand Up @@ -80,23 +76,11 @@ class AdvancedUnlockNotificationService : NotificationService() {

when (intent?.action) {
ACTION_TIMEOUT -> {
notificationTimeoutMilliSecs = PreferencesUtil.getAdvancedUnlockTimeout(this)
val notificationTimeoutMilliSecs = PreferencesUtil.getAdvancedUnlockTimeout(this)
// Not necessarily a foreground service
if (mTimerJob == null && notificationTimeoutMilliSecs != TimeoutHelper.NEVER) {
mTimerJob = CoroutineScope(Dispatchers.Main).launch {
val maxPos = 100
val posDurationMills = notificationTimeoutMilliSecs / maxPos
for (pos in maxPos downTo 0) {
notificationBuilder.setProgress(maxPos, pos, false)
startForeground(notificationId, notificationBuilder.build())
delay(posDurationMills)
if (pos <= 0) {
stopSelf()
}
}
notificationManager?.cancel(notificationId)
mTimerJob = null
cancel()
defineTimerJob(notificationBuilder, notificationTimeoutMilliSecs) {
stopSelf()
}
} else {
startForeground(notificationId, notificationBuilder.build())
Expand All @@ -118,7 +102,6 @@ class AdvancedUnlockNotificationService : NotificationService() {

override fun onDestroy() {
mTempCipherDao.clear()
mTimerJob?.cancel()
super.onDestroy()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
override val notificationId = 485
private var mEntryInfo: EntryInfo? = null
private var clipboardHelper: ClipboardHelper? = null
private var notificationTimeoutMilliSecs: Long = 0
private var cleanCopyNotificationTimerTask: Thread? = null
private var mNotificationTimeoutMilliSecs: Long = 0

override fun retrieveChannelId(): String {
return CHANNEL_CLIPBOARD_ID
Expand Down Expand Up @@ -70,15 +69,15 @@ class ClipboardEntryNotificationService : LockNotificationService() {
mEntryInfo = intent?.getParcelableExtra(EXTRA_ENTRY_INFO)

//Get settings
notificationTimeoutMilliSecs = PreferencesUtil.getClipboardTimeout(this)
mNotificationTimeoutMilliSecs = PreferencesUtil.getClipboardTimeout(this)

when {
intent == null -> Log.w(TAG, "null intent")
ACTION_NEW_NOTIFICATION == intent.action -> {
newNotification(mEntryInfo?.title, constructListOfField(intent))
}
ACTION_CLEAN_CLIPBOARD == intent.action -> {
stopTask(cleanCopyNotificationTimerTask)
mTimerJob?.cancel()
cleanClipboard()
stopNotificationAndSendLockIfNeeded()
}
Expand Down Expand Up @@ -121,7 +120,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
}

private fun newNotification(title: String?, fieldsToAdd: ArrayList<ClipboardEntryNotificationField>) {
stopTask(cleanCopyNotificationTimerTask)
mTimerJob?.cancel()

val builder = buildNewNotification()
.setSmallIcon(R.drawable.notification_ic_clipboard_key_24dp)
Expand All @@ -147,7 +146,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
}

private fun copyField(fieldToCopy: ClipboardEntryNotificationField, nextFields: ArrayList<ClipboardEntryNotificationField>) {
stopTask(cleanCopyNotificationTimerTask)
mTimerJob?.cancel()

try {
var generatedValue = fieldToCopy.getGeneratedValue(mEntryInfo)
Expand All @@ -170,40 +169,23 @@ class ClipboardEntryNotificationService : LockNotificationService() {
this, 0, cleanIntent, PendingIntent.FLAG_UPDATE_CURRENT)
builder.setDeleteIntent(cleanPendingIntent)

val myNotificationId = notificationId

if (notificationTimeoutMilliSecs != NEVER) {
cleanCopyNotificationTimerTask = Thread {
val maxPos = 100
val posDurationMills = notificationTimeoutMilliSecs / maxPos
for (pos in maxPos downTo 0) {
val newGeneratedValue = fieldToCopy.getGeneratedValue(mEntryInfo)
// New auto generated value
if (generatedValue != newGeneratedValue) {
generatedValue = newGeneratedValue
clipboardHelper?.copyToClipboard(fieldToCopy.label, generatedValue)
}
builder.setProgress(maxPos, pos, false)
notificationManager?.notify(myNotificationId, builder.build())
try {
Thread.sleep(posDurationMills)
} catch (e: InterruptedException) {
break
}
if (pos <= 0) {
stopNotificationAndSendLockIfNeeded()
}
if (mNotificationTimeoutMilliSecs != NEVER) {
defineTimerJob(builder, mNotificationTimeoutMilliSecs, {
val newGeneratedValue = fieldToCopy.getGeneratedValue(mEntryInfo)
// New auto generated value
if (generatedValue != newGeneratedValue) {
generatedValue = newGeneratedValue
clipboardHelper?.copyToClipboard(fieldToCopy.label, generatedValue)
}
stopTask(cleanCopyNotificationTimerTask)
notificationManager?.cancel(myNotificationId)
}) {
stopNotificationAndSendLockIfNeeded()
// Clean password only if no next field
if (nextFields.size <= 0)
cleanClipboard()
}
cleanCopyNotificationTimerTask?.start()
} else {
// No timer
notificationManager?.notify(myNotificationId, builder.build())
notificationManager?.notify(notificationId, builder.build())
}

} catch (e: Exception) {
Expand All @@ -228,10 +210,6 @@ class ClipboardEntryNotificationService : LockNotificationService() {

override fun onDestroy() {
cleanClipboard()

stopTask(cleanCopyNotificationTimerTask)
cleanCopyNotificationTimerTask = null

super.onDestroy()
}

Expand Down
Loading

0 comments on commit 123288e

Please sign in to comment.