feat: Add direct encrypted key testing for password in decryptAttachmentBlob function

This commit is contained in:
k1ngsterr1
2026-01-24 17:57:40 +05:00
parent 8c87b12c5f
commit 8fe0afea20
3 changed files with 155 additions and 42 deletions

View File

@@ -192,11 +192,16 @@ fun ImageAttachment(
downloadStatus = DownloadStatus.DECRYPTING
Log.d(TAG, "🔓 Decrypting image...")
// Расшифровываем
val decrypted = MessageCrypto.decryptAttachmentBlob(
// КРИТИЧНО: chachaKey ЗАШИФРОВАН в БД (как в Desktop)
// Сначала расшифровываем его: Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8')
val decryptedKeyAndNonce = MessageCrypto.decryptKeyFromSender(chachaKey, myPrivateKey)
val decryptKeyString = String(decryptedKeyAndNonce, Charsets.UTF_8)
Log.d(TAG, "🔑 Decrypted chacha_key: ${decryptKeyString.length} chars")
// Теперь используем расшифрованный ключ как password для PBKDF2
val decrypted = MessageCrypto.decryptAttachmentBlobWithPassword(
encryptedContent,
chachaKey,
privateKey
decryptKeyString
)
downloadProgress = 0.8f
@@ -390,10 +395,14 @@ fun FileAttachment(
downloadStatus = DownloadStatus.DECRYPTING
val decrypted = MessageCrypto.decryptAttachmentBlob(
// КРИТИЧНО: chachaKey ЗАШИФРОВАН в БД (как в Desktop)
// Сначала расшифровываем его
val decryptedKeyAndNonce = MessageCrypto.decryptKeyFromSender(chachaKey, myPrivateKey)
val decryptKeyString = String(decryptedKeyAndNonce, Charsets.UTF_8)
val decrypted = MessageCrypto.decryptAttachmentBlobWithPassword(
encryptedContent,
chachaKey,
privateKey
decryptKeyString
)
downloadProgress = 0.9f
@@ -581,10 +590,14 @@ fun AvatarAttachment(
val encryptedContent = TransportManager.downloadFile(attachment.id, downloadTag)
downloadStatus = DownloadStatus.DECRYPTING
val decrypted = MessageCrypto.decryptAttachmentBlob(
// КРИТИЧНО: chachaKey ЗАШИФРОВАН в БД (как в Desktop)
// Сначала расшифровываем его
val decryptedKeyAndNonce = MessageCrypto.decryptKeyFromSender(chachaKey, myPrivateKey)
val decryptKeyString = String(decryptedKeyAndNonce, Charsets.UTF_8)
val decrypted = MessageCrypto.decryptAttachmentBlobWithPassword(
encryptedContent,
chachaKey,
privateKey
decryptKeyString
)
if (decrypted != null) {