Compare commits

...

4 Commits

Author SHA1 Message Date
Avently
391892bd64 ui: chatitem header 2023-11-13 10:29:22 -08:00
Evgeny Poberezkin
a2fe5cfb66 core: fix incorrect JSON serialization (#3361) 2023-11-13 17:45:10 +00:00
Stanislav Dmitrenko
338417d963 desktop: catch unreadable crypto file (#3359) 2023-11-13 14:06:01 +00:00
spaced4ndy
5beeff5cb6 core: take chat lock when synchronizing ratchet (#3349) 2023-11-12 12:41:41 +00:00
10 changed files with 46 additions and 12 deletions

View File

@@ -2665,6 +2665,7 @@ public enum CIContent: Decodable, ItemContent {
case .rcvDecryptionError: return true
case .rcvGroupInvitation: return true
case .rcvModerated: return true
case .sndModerated: return true
case .invalidJSON: return true
default: return false
}

View File

@@ -35,7 +35,12 @@ actual fun shareFile(text: String, fileSource: CryptoFile) {
val tmpFile = File(tmpDir, fileSource.filePath)
tmpFile.deleteOnExit()
ChatModel.filesToDelete.add(tmpFile)
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs, tmpFile.absolutePath)
try {
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs, tmpFile.absolutePath)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
return
}
getAppFileUri(tmpFile.absolutePath)
} else {
getAppFileUri(fileSource.filePath)
@@ -96,15 +101,21 @@ fun saveImage(ciFile: CIFile?) {
val outputStream = BufferedOutputStream(stream)
if (ciFile.fileSource?.cryptoArgs != null) {
createTmpFileAndDelete { tmpFile ->
decryptCryptoFile(filePath, ciFile.fileSource.cryptoArgs, tmpFile.absolutePath)
try {
decryptCryptoFile(filePath, ciFile.fileSource.cryptoArgs, tmpFile.absolutePath)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
return@createTmpFileAndDelete
}
tmpFile.inputStream().use { it.copyTo(outputStream) }
showToast(generalGetString(MR.strings.image_saved))
}
outputStream.close()
} else {
File(filePath).inputStream().use { it.copyTo(outputStream) }
outputStream.close()
showToast(generalGetString(MR.strings.image_saved))
}
showToast(generalGetString(MR.strings.image_saved))
}
}
} else {

View File

@@ -2078,6 +2078,7 @@ sealed class CIContent: ItemContent {
is RcvDecryptionError -> true
is RcvGroupInvitation -> true
is RcvModerated -> true
is SndModerated -> true
is InvalidJSON -> true
else -> false
}

View File

@@ -214,7 +214,13 @@ fun rememberSaveFileLauncher(ciFile: CIFile?): FileChooserLauncher =
if (filePath != null && to != null) {
if (ciFile?.fileSource?.cryptoArgs != null) {
createTmpFileAndDelete { tmpFile ->
decryptCryptoFile(filePath, ciFile.fileSource.cryptoArgs, tmpFile.absolutePath)
try {
decryptCryptoFile(filePath, ciFile.fileSource.cryptoArgs, tmpFile.absolutePath)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
tmpFile.delete()
return@createTmpFileAndDelete
}
copyFileToFile(tmpFile, to) {}
tmpFile.delete()
}

View File

@@ -59,6 +59,7 @@ actual object AudioPlayer: AudioPlayerInterface {
}
}.onFailure {
Log.e(TAG, it.stackTraceToString())
fileSource.deleteTmpFile()
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
return null
}

View File

@@ -27,7 +27,11 @@ actual fun shareFile(text: String, fileSource: CryptoFile) {
FileChooserLauncher(false) { to: URI? ->
if (to != null) {
if (fileSource.cryptoArgs != null) {
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs, to.path)
try {
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs, to.path)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
}
} else {
copyFileToFile(File(fileSource.filePath), to) {}
}

View File

@@ -48,7 +48,12 @@ actual fun copyItemToClipboard(cItem: ChatItem, clipboard: ClipboardManager) {
val filePath: String = if (fileSource.cryptoArgs != null) {
val tmpFile = File(tmpDir, fileSource.filePath)
tmpFile.deleteOnExit()
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs, tmpFile.absolutePath)
try {
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs, tmpFile.absolutePath)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
return
}
tmpFile.absolutePath
} else {
getAppFilePath(fileSource.filePath)

View File

@@ -94,9 +94,14 @@ actual fun getAppFileUri(fileName: String): URI =
actual fun getLoadedImage(file: CIFile?): Pair<ImageBitmap, ByteArray>? {
val filePath = getLoadedFilePath(file)
return if (filePath != null) {
val data = if (file?.fileSource?.cryptoArgs != null) readCryptoFile(filePath, file.fileSource.cryptoArgs) else File(filePath).readBytes()
val bitmap = getBitmapFromByteArray(data, false)
if (bitmap != null) bitmap to data else null
try {
val data = if (file?.fileSource?.cryptoArgs != null) readCryptoFile(filePath, file.fileSource.cryptoArgs) else File(filePath).readBytes()
val bitmap = getBitmapFromByteArray(data, false)
if (bitmap != null) bitmap to data else null
} catch (e: Exception) {
Log.e(TAG, "Unable to read crypto file: " + e.stackTraceToString())
null
}
} else {
null
}

View File

@@ -1256,7 +1256,7 @@ processChatCommand = \case
connectionStats <- withAgent $ \a -> abortConnectionSwitch a connId
pure $ CRGroupMemberSwitchAborted user g m connectionStats
_ -> throwChatError CEGroupMemberNotActive
APISyncContactRatchet contactId force -> withUser $ \user -> do
APISyncContactRatchet contactId force -> withUser $ \user -> withChatLock "syncContactRatchet" $ do
ct <- withStore $ \db -> getContact db user contactId
case contactConnId ct of
Just connId -> do
@@ -1264,7 +1264,7 @@ processChatCommand = \case
createInternalChatItem user (CDDirectSnd ct) (CISndConnEvent $ SCERatchetSync rss Nothing) Nothing
pure $ CRContactRatchetSyncStarted user ct cStats
Nothing -> throwChatError $ CEContactNotActive ct
APISyncGroupMemberRatchet gId gMemberId force -> withUser $ \user -> do
APISyncGroupMemberRatchet gId gMemberId force -> withUser $ \user -> withChatLock "syncGroupMemberRatchet" $ do
(g, m) <- withStore $ \db -> (,) <$> getGroupInfo db user gId <*> getGroupMember db user gId gMemberId
case memberConnId m of
Just connId -> do

View File

@@ -555,7 +555,7 @@ jsonCIContent = \case
CIRcvChatFeatureRejected feature -> JCIRcvChatFeatureRejected {feature}
CIRcvGroupFeatureRejected groupFeature -> JCIRcvGroupFeatureRejected {groupFeature}
CISndModerated -> JCISndModerated
CIRcvModerated -> JCISndModerated
CIRcvModerated -> JCIRcvModerated
CIInvalidJSON json -> JCIInvalidJSON (toMsgDirection $ msgDirection @d) json
aciContentJSON :: JSONCIContent -> ACIContent