Merge branch 'master-ghc8107' into master-android

This commit is contained in:
Evgeny Poberezkin 2023-11-16 18:55:17 +00:00
commit 80ddb50e1c
18 changed files with 69 additions and 19 deletions

View File

@ -165,6 +165,8 @@ struct CIRcvDecryptionError: View {
message = Text("\(msgCount) messages failed to decrypt.") + Text("\n") + why message = Text("\(msgCount) messages failed to decrypt.") + Text("\n") + why
case .other: case .other:
message = Text("\(msgCount) messages failed to decrypt.") + Text("\n") + why message = Text("\(msgCount) messages failed to decrypt.") + Text("\n") + why
case .ratchetSync:
message = Text("Encryption re-negotiation failed.")
} }
return message return message
} }

View File

@ -2676,6 +2676,7 @@ public enum MsgDecryptError: String, Decodable {
case tooManySkipped case tooManySkipped
case ratchetEarlier case ratchetEarlier
case other case other
case ratchetSync
var text: String { var text: String {
switch self { switch self {
@ -2683,6 +2684,7 @@ public enum MsgDecryptError: String, Decodable {
case .tooManySkipped: return NSLocalizedString("Permanent decryption error", comment: "message decrypt error item") case .tooManySkipped: return NSLocalizedString("Permanent decryption error", comment: "message decrypt error item")
case .ratchetEarlier: return NSLocalizedString("Decryption error", comment: "message decrypt error item") case .ratchetEarlier: return NSLocalizedString("Decryption error", comment: "message decrypt error item")
case .other: return NSLocalizedString("Decryption error", comment: "message decrypt error item") case .other: return NSLocalizedString("Decryption error", comment: "message decrypt error item")
case .ratchetSync: return NSLocalizedString("Encryption re-negotiation error", comment: "message decrypt error item")
} }
} }
} }

View File

@ -35,7 +35,12 @@ actual fun shareFile(text: String, fileSource: CryptoFile) {
val tmpFile = File(tmpDir, fileSource.filePath) val tmpFile = File(tmpDir, fileSource.filePath)
tmpFile.deleteOnExit() tmpFile.deleteOnExit()
ChatModel.filesToDelete.add(tmpFile) 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) getAppFileUri(tmpFile.absolutePath)
} else { } else {
getAppFileUri(fileSource.filePath) getAppFileUri(fileSource.filePath)
@ -96,15 +101,21 @@ fun saveImage(ciFile: CIFile?) {
val outputStream = BufferedOutputStream(stream) val outputStream = BufferedOutputStream(stream)
if (ciFile.fileSource?.cryptoArgs != null) { if (ciFile.fileSource?.cryptoArgs != null) {
createTmpFileAndDelete { tmpFile -> 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) } tmpFile.inputStream().use { it.copyTo(outputStream) }
showToast(generalGetString(MR.strings.image_saved))
} }
outputStream.close() outputStream.close()
} else { } else {
File(filePath).inputStream().use { it.copyTo(outputStream) } File(filePath).inputStream().use { it.copyTo(outputStream) }
outputStream.close() outputStream.close()
showToast(generalGetString(MR.strings.image_saved))
} }
showToast(generalGetString(MR.strings.image_saved))
} }
} }
} else { } else {

View File

@ -2106,13 +2106,15 @@ enum class MsgDecryptError {
@SerialName("ratchetHeader") RatchetHeader, @SerialName("ratchetHeader") RatchetHeader,
@SerialName("tooManySkipped") TooManySkipped, @SerialName("tooManySkipped") TooManySkipped,
@SerialName("ratchetEarlier") RatchetEarlier, @SerialName("ratchetEarlier") RatchetEarlier,
@SerialName("other") Other; @SerialName("other") Other,
@SerialName("ratchetSync") RatchetSync;
val text: String get() = when (this) { val text: String get() = when (this) {
RatchetHeader -> generalGetString(MR.strings.decryption_error) RatchetHeader -> generalGetString(MR.strings.decryption_error)
TooManySkipped -> generalGetString(MR.strings.decryption_error) TooManySkipped -> generalGetString(MR.strings.decryption_error)
RatchetEarlier -> generalGetString(MR.strings.decryption_error) RatchetEarlier -> generalGetString(MR.strings.decryption_error)
Other -> generalGetString(MR.strings.decryption_error) Other -> generalGetString(MR.strings.decryption_error)
RatchetSync -> generalGetString(MR.strings.encryption_renegotiation_error)
} }
} }

View File

@ -894,7 +894,7 @@ fun BoxWithConstraintsScope.ChatItemsList(
@Composable @Composable
fun ChatItemViewShortHand(cItem: ChatItem, range: IntRange?) { fun ChatItemViewShortHand(cItem: ChatItem, range: IntRange?) {
ChatItemView(chat.chatInfo, cItem, composeState, provider, useLinkPreviews = useLinkPreviews, linkMode = linkMode, revealed = revealed, range = range, deleteMessage = deleteMessage, deleteMessages = deleteMessages, receiveFile = receiveFile, cancelFile = cancelFile, joinGroup = { _, _ -> }, acceptCall = acceptCall, acceptFeature = acceptFeature, openDirectChat = openDirectChat, updateContactStats = updateContactStats, updateMemberStats = updateMemberStats, syncContactConnection = syncContactConnection, syncMemberConnection = syncMemberConnection, findModelChat = findModelChat, findModelMember = findModelMember, scrollToItem = scrollToItem, setReaction = setReaction, showItemDetails = showItemDetails, developerTools = developerTools) ChatItemView(chat.chatInfo, cItem, composeState, provider, useLinkPreviews = useLinkPreviews, linkMode = linkMode, revealed = revealed, range = range, deleteMessage = deleteMessage, deleteMessages = deleteMessages, receiveFile = receiveFile, cancelFile = cancelFile, joinGroup = joinGroup, acceptCall = acceptCall, acceptFeature = acceptFeature, openDirectChat = openDirectChat, updateContactStats = updateContactStats, updateMemberStats = updateMemberStats, syncContactConnection = syncContactConnection, syncMemberConnection = syncMemberConnection, findModelChat = findModelChat, findModelMember = findModelMember, scrollToItem = scrollToItem, setReaction = setReaction, showItemDetails = showItemDetails, developerTools = developerTools)
} }
@Composable @Composable

View File

@ -214,7 +214,13 @@ fun rememberSaveFileLauncher(ciFile: CIFile?): FileChooserLauncher =
if (filePath != null && to != null) { if (filePath != null && to != null) {
if (ciFile?.fileSource?.cryptoArgs != null) { if (ciFile?.fileSource?.cryptoArgs != null) {
createTmpFileAndDelete { tmpFile -> 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) {} copyFileToFile(tmpFile, to) {}
tmpFile.delete() tmpFile.delete()
} }

View File

@ -218,5 +218,7 @@ private fun alertMessage(msgDecryptError: MsgDecryptError, msgCount: UInt): Stri
MsgDecryptError.Other -> String.format(generalGetString(MR.strings.alert_text_decryption_error_n_messages_failed_to_decrypt), msgCount.toLong()) + "\n" + MsgDecryptError.Other -> String.format(generalGetString(MR.strings.alert_text_decryption_error_n_messages_failed_to_decrypt), msgCount.toLong()) + "\n" +
generalGetString(MR.strings.alert_text_fragment_encryption_out_of_sync_old_database) generalGetString(MR.strings.alert_text_fragment_encryption_out_of_sync_old_database)
MsgDecryptError.RatchetSync -> generalGetString(MR.strings.alert_text_encryption_renegotiation_failed)
} }
} }

View File

@ -45,6 +45,7 @@
<string name="invalid_chat">invalid chat</string> <string name="invalid_chat">invalid chat</string>
<string name="invalid_data">invalid data</string> <string name="invalid_data">invalid data</string>
<string name="decryption_error">Decryption error</string> <string name="decryption_error">Decryption error</string>
<string name="encryption_renegotiation_error">Encryption re-negotiation error</string>
<!-- PendingContactConnection - ChatModel.kt --> <!-- PendingContactConnection - ChatModel.kt -->
<string name="connection_local_display_name">connection %1$d</string> <string name="connection_local_display_name">connection %1$d</string>
@ -866,6 +867,7 @@
<string name="alert_text_decryption_error_n_messages_failed_to_decrypt">%1$d messages failed to decrypt.</string> <string name="alert_text_decryption_error_n_messages_failed_to_decrypt">%1$d messages failed to decrypt.</string>
<string name="alert_text_decryption_error_too_many_skipped">%1$d messages skipped.</string> <string name="alert_text_decryption_error_too_many_skipped">%1$d messages skipped.</string>
<string name="alert_text_fragment_encryption_out_of_sync_old_database">It can happen when you or your connection used the old database backup.</string> <string name="alert_text_fragment_encryption_out_of_sync_old_database">It can happen when you or your connection used the old database backup.</string>
<string name="alert_text_encryption_renegotiation_failed">Encryption re-negotiation failed.</string>
<string name="alert_text_fragment_please_report_to_developers">Please report it to the developers.</string> <string name="alert_text_fragment_please_report_to_developers">Please report it to the developers.</string>
<!-- Privacy settings --> <!-- Privacy settings -->

View File

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

View File

@ -27,7 +27,11 @@ actual fun shareFile(text: String, fileSource: CryptoFile) {
FileChooserLauncher(false) { to: URI? -> FileChooserLauncher(false) { to: URI? ->
if (to != null) { if (to != null) {
if (fileSource.cryptoArgs != 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 { } else {
copyFileToFile(File(fileSource.filePath), to) {} 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 filePath: String = if (fileSource.cryptoArgs != null) {
val tmpFile = File(tmpDir, fileSource.filePath) val tmpFile = File(tmpDir, fileSource.filePath)
tmpFile.deleteOnExit() 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 tmpFile.absolutePath
} else { } else {
getAppFilePath(fileSource.filePath) getAppFilePath(fileSource.filePath)

View File

@ -94,9 +94,14 @@ actual fun getAppFileUri(fileName: String): URI =
actual fun getLoadedImage(file: CIFile?): Pair<ImageBitmap, ByteArray>? { actual fun getLoadedImage(file: CIFile?): Pair<ImageBitmap, ByteArray>? {
val filePath = getLoadedFilePath(file) val filePath = getLoadedFilePath(file)
return if (filePath != null) { return if (filePath != null) {
val data = if (file?.fileSource?.cryptoArgs != null) readCryptoFile(filePath, file.fileSource.cryptoArgs) else File(filePath).readBytes() try {
val bitmap = getBitmapFromByteArray(data, false) val data = if (file?.fileSource?.cryptoArgs != null) readCryptoFile(filePath, file.fileSource.cryptoArgs) else File(filePath).readBytes()
if (bitmap != null) bitmap to data else null 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 { } else {
null null
} }

View File

@ -9,7 +9,7 @@ constraints: zip +disable-bzip2 +disable-zstd
source-repository-package source-repository-package
type: git type: git
location: https://github.com/simplex-chat/simplexmq.git location: https://github.com/simplex-chat/simplexmq.git
tag: 897001efbf0155f2954f6e051b08e12ceccb9a15 tag: 20d9767c5474de083b711cc034c871af3b57f6f7
source-repository-package source-repository-package
type: git type: git

View File

@ -25,7 +25,7 @@ Using the same profile as on mobile device is not yet supported you need to
**Mac**: [x86_64](https://github.com/simplex-chat/simplex-chat/releases/download/v5.3.2/simplex-desktop-macos-x86_64.dmg) (Intel), [aarch64](https://github.com/simplex-chat/simplex-chat/releases/download/v5.3.1/simplex-desktop-macos-aarch64.dmg) (Apple Silicon). **Mac**: [x86_64](https://github.com/simplex-chat/simplex-chat/releases/download/v5.3.2/simplex-desktop-macos-x86_64.dmg) (Intel), [aarch64](https://github.com/simplex-chat/simplex-chat/releases/download/v5.3.1/simplex-desktop-macos-aarch64.dmg) (Apple Silicon).
**Windows**: [x86_64](https://github.com/simplex-chat/simplex-chat/releases/download/v5.4.0-beta.0/simplex-desktop-windows-x86-64.msi) (BETA). **Windows**: [x86_64](https://github.com/simplex-chat/simplex-chat/releases/download/v5.4.0-beta.3/simplex-desktop-windows-x86-64.msi) (BETA).
## Mobile apps ## Mobile apps

View File

@ -1,5 +1,5 @@
{ {
"https://github.com/simplex-chat/simplexmq.git"."897001efbf0155f2954f6e051b08e12ceccb9a15" = "0spjv7yqdd49kxh5vf14n7wnvyas37nclwigxq705cx2radjs9z9"; "https://github.com/simplex-chat/simplexmq.git"."20d9767c5474de083b711cc034c871af3b57f6f7" = "13lyrd9q3qa1b2sfar1gbwxx9bmwramqqry7zj5pnr2ll2xg67s2";
"https://github.com/simplex-chat/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38"; "https://github.com/simplex-chat/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38";
"https://github.com/kazu-yamamoto/http2.git"."f5525b755ff2418e6e6ecc69e877363b0d0bcaeb" = "0fyx0047gvhm99ilp212mmz37j84cwrfnpmssib5dw363fyb88b6"; "https://github.com/kazu-yamamoto/http2.git"."f5525b755ff2418e6e6ecc69e877363b0d0bcaeb" = "0fyx0047gvhm99ilp212mmz37j84cwrfnpmssib5dw363fyb88b6";
"https://github.com/simplex-chat/direct-sqlcipher.git"."34309410eb2069b029b8fc1872deb1e0db123294" = "0kwkmhyfsn2lixdlgl15smgr1h5gjk7fky6abzh8rng2h5ymnffd"; "https://github.com/simplex-chat/direct-sqlcipher.git"."34309410eb2069b029b8fc1872deb1e0db123294" = "0kwkmhyfsn2lixdlgl15smgr1h5gjk7fky6abzh8rng2h5ymnffd";

View File

@ -1248,7 +1248,7 @@ processChatCommand = \case
connectionStats <- withAgent $ \a -> abortConnectionSwitch a connId connectionStats <- withAgent $ \a -> abortConnectionSwitch a connId
pure $ CRGroupMemberSwitchAborted user g m connectionStats pure $ CRGroupMemberSwitchAborted user g m connectionStats
_ -> throwChatError CEGroupMemberNotActive _ -> throwChatError CEGroupMemberNotActive
APISyncContactRatchet contactId force -> withUser $ \user -> do APISyncContactRatchet contactId force -> withUser $ \user -> withChatLock "syncContactRatchet" $ do
ct <- withStore $ \db -> getContact db user contactId ct <- withStore $ \db -> getContact db user contactId
case contactConnId ct of case contactConnId ct of
Just connId -> do Just connId -> do
@ -1256,7 +1256,7 @@ processChatCommand = \case
createInternalChatItem user (CDDirectSnd ct) (CISndConnEvent $ SCERatchetSync rss Nothing) Nothing createInternalChatItem user (CDDirectSnd ct) (CISndConnEvent $ SCERatchetSync rss Nothing) Nothing
pure $ CRContactRatchetSyncStarted user ct cStats pure $ CRContactRatchetSyncStarted user ct cStats
Nothing -> throwChatError $ CEContactNotActive ct 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 (g, m) <- withStore $ \db -> (,) <$> getGroupInfo db user gId <*> getGroupMember db user gId gMemberId
case memberConnId m of case memberConnId m of
Just connId -> do Just connId -> do
@ -3627,6 +3627,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
RATCHET_HEADER -> (MDERatchetHeader, 1) RATCHET_HEADER -> (MDERatchetHeader, 1)
RATCHET_EARLIER _ -> (MDERatchetEarlier, 1) RATCHET_EARLIER _ -> (MDERatchetEarlier, 1)
RATCHET_SKIPPED n -> (MDETooManySkipped, n) RATCHET_SKIPPED n -> (MDETooManySkipped, n)
RATCHET_SYNC -> (MDERatchetSync, 0)
mdeUpdatedCI :: (MsgDecryptError, Word32) -> CChatItem c -> Maybe (ChatItem c 'MDRcv, CIContent 'MDRcv) mdeUpdatedCI :: (MsgDecryptError, Word32) -> CChatItem c -> Maybe (ChatItem c 'MDRcv, CIContent 'MDRcv)
mdeUpdatedCI (mde', n') (CChatItem _ ci@ChatItem {content = CIRcvDecryptionError mde n}) mdeUpdatedCI (mde', n') (CChatItem _ ci@ChatItem {content = CIRcvDecryptionError mde n})
@ -3635,6 +3636,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
MDETooManySkipped -> r n' -- the numbers are not added as sequential MDETooManySkipped will have it incremented by 1 MDETooManySkipped -> r n' -- the numbers are not added as sequential MDETooManySkipped will have it incremented by 1
MDERatchetEarlier -> r (n + n') MDERatchetEarlier -> r (n + n')
MDEOther -> r (n + n') MDEOther -> r (n + n')
MDERatchetSync -> r 0
| otherwise = Nothing | otherwise = Nothing
where where
r n'' = Just (ci, CIRcvDecryptionError mde n'') r n'' = Just (ci, CIRcvDecryptionError mde n'')

View File

@ -150,7 +150,12 @@ ciMsgContent = \case
CIRcvMsgContent mc -> Just mc CIRcvMsgContent mc -> Just mc
_ -> Nothing _ -> Nothing
data MsgDecryptError = MDERatchetHeader | MDETooManySkipped | MDERatchetEarlier | MDEOther data MsgDecryptError
= MDERatchetHeader
| MDETooManySkipped
| MDERatchetEarlier
| MDEOther
| MDERatchetSync
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
instance ToJSON MsgDecryptError where instance ToJSON MsgDecryptError where
@ -460,6 +465,7 @@ msgDecryptErrorText err n =
MDETooManySkipped -> Just $ "too many skipped messages" <> counter MDETooManySkipped -> Just $ "too many skipped messages" <> counter
MDERatchetEarlier -> Just $ "earlier message" <> counter MDERatchetEarlier -> Just $ "earlier message" <> counter
MDEOther -> counter_ MDEOther -> counter_
MDERatchetSync -> Just "synchronization error"
counter_ = if n == 1 then Nothing else Just $ tshow n <> " messages" counter_ = if n == 1 then Nothing else Just $ tshow n <> " messages"
counter = maybe "" (", " <>) counter_ counter = maybe "" (", " <>) counter_
@ -555,7 +561,7 @@ jsonCIContent = \case
CIRcvChatFeatureRejected feature -> JCIRcvChatFeatureRejected {feature} CIRcvChatFeatureRejected feature -> JCIRcvChatFeatureRejected {feature}
CIRcvGroupFeatureRejected groupFeature -> JCIRcvGroupFeatureRejected {groupFeature} CIRcvGroupFeatureRejected groupFeature -> JCIRcvGroupFeatureRejected {groupFeature}
CISndModerated -> JCISndModerated CISndModerated -> JCISndModerated
CIRcvModerated -> JCISndModerated CIRcvModerated -> JCIRcvModerated
CIInvalidJSON json -> JCIInvalidJSON (toMsgDirection $ msgDirection @d) json CIInvalidJSON json -> JCIInvalidJSON (toMsgDirection $ msgDirection @d) json
aciContentJSON :: JSONCIContent -> ACIContent aciContentJSON :: JSONCIContent -> ACIContent

View File

@ -49,7 +49,7 @@ extra-deps:
# - simplexmq-1.0.0@sha256:34b2004728ae396e3ae449cd090ba7410781e2b3cefc59259915f4ca5daa9ea8,8561 # - simplexmq-1.0.0@sha256:34b2004728ae396e3ae449cd090ba7410781e2b3cefc59259915f4ca5daa9ea8,8561
# - ../simplexmq # - ../simplexmq
- github: simplex-chat/simplexmq - github: simplex-chat/simplexmq
commit: 897001efbf0155f2954f6e051b08e12ceccb9a15 commit: 20d9767c5474de083b711cc034c871af3b57f6f7
- github: kazu-yamamoto/http2 - github: kazu-yamamoto/http2
commit: f5525b755ff2418e6e6ecc69e877363b0d0bcaeb commit: f5525b755ff2418e6e6ecc69e877363b0d0bcaeb
# - ../direct-sqlcipher # - ../direct-sqlcipher