Remove unnecessary logging statements across various components to clean up code and improve readability. This includes removing debug, error, and warning logs from attachment handling, image processing, media loading, and profile management functionalities. Additionally, a script has been added to automate the removal of log statements from Kotlin files.

This commit is contained in:
2026-01-31 05:20:32 +05:00
parent 430c7d9007
commit c249278421
28 changed files with 0 additions and 506 deletions

View File

@@ -437,16 +437,13 @@ object MessageCrypto {
cipher.init(Cipher.DECRYPT_MODE, aesKey, IvParameterSpec(iv))
val decryptedUtf8Bytes = cipher.doFinal(encryptedKey)
android.util.Log.d("MessageCrypto", "🔓 AES decrypted raw bytes: ${decryptedUtf8Bytes.size}, hex=${decryptedUtf8Bytes.toHex()}")
// ⚠️ КРИТИЧНО: Обратная конвертация UTF-8 → Latin1!
// Desktop: decrypted.toString(crypto.enc.Utf8) → Buffer.from(str, 'binary')
// Это декодирует UTF-8 в строку, потом берёт charCode каждого символа
val utf8String = String(decryptedUtf8Bytes, Charsets.UTF_8)
android.util.Log.d("MessageCrypto", "🔓 UTF-8 string length: ${utf8String.length}, chars: ${utf8String.take(20).map { it.code }}")
val originalBytes = utf8String.toByteArray(Charsets.ISO_8859_1)
android.util.Log.d("MessageCrypto", "🔓 Latin1 bytes: ${originalBytes.size}, hex=${originalBytes.toHex().take(80)}...")
return originalBytes
}
@@ -527,8 +524,6 @@ object MessageCrypto {
chachaKeyPlain: ByteArray
): String? {
return try {
android.util.Log.d("MessageCrypto", "🔐 decryptAttachmentBlobWithPlainKey(bytes): data length=${encryptedData.length}, key=${chachaKeyPlain.size} bytes")
android.util.Log.d("MessageCrypto", "🔑 Raw key bytes hex: ${chachaKeyPlain.toHex()}")
// Desktop использует key.toString('binary') → encrypt → decrypt → toString('utf-8') → PBKDF2
// Это эквивалентно: raw bytes → Latin1 string → UTF-8 encode → шифрование →
@@ -545,91 +540,60 @@ object MessageCrypto {
// Вариант 1: UTF-8 decode (как Node.js Buffer.toString('utf-8'))
val password1 = bytesToJsUtf8String(chachaKeyPlain)
val passwordBytes1 = password1.toByteArray(Charsets.UTF_8)
android.util.Log.d("MessageCrypto", "🔑 V1 (UTF-8 decode → string → UTF-8 encode): ${passwordBytes1.size} bytes")
android.util.Log.d("MessageCrypto", "🔑 V1 hex: ${passwordBytes1.toHex().take(60)}...")
// Вариант 2: Latin1 decode (каждый byte = char 0-255)
val password2 = String(chachaKeyPlain, Charsets.ISO_8859_1)
val passwordBytes2 = password2.toByteArray(Charsets.UTF_8)
android.util.Log.d("MessageCrypto", "🔑 V2 (Latin1 → string → UTF-8 encode): ${passwordBytes2.size} bytes")
android.util.Log.d("MessageCrypto", "🔑 V2 hex: ${passwordBytes2.toHex().take(60)}...")
// Вариант 3: Raw bytes напрямую (без string conversion)
android.util.Log.d("MessageCrypto", "🔑 V3 (raw bytes): ${chachaKeyPlain.size} bytes")
android.util.Log.d("MessageCrypto", "🔑 V3 hex: ${chachaKeyPlain.toHex().take(60)}...")
// Пробуем расшифровать с КАЖДЫМ вариантом
android.util.Log.d("MessageCrypto", "🔓 Trying V1 (UTF-8 roundtrip)...")
val pbkdf2Key1 = generatePBKDF2Key(password1)
android.util.Log.d("MessageCrypto", "🔑 V1 PBKDF2 key: ${pbkdf2Key1.toHex()}")
val result1 = decryptWithPBKDF2Key(encryptedData, pbkdf2Key1)
if (result1 != null) {
android.util.Log.d("MessageCrypto", "✅ V1 SUCCESS!")
return result1
}
android.util.Log.d("MessageCrypto", "❌ V1 failed")
android.util.Log.d("MessageCrypto", "🔓 Trying V2 (Latin1 → UTF-8)...")
val pbkdf2Key2 = generatePBKDF2Key(password2)
android.util.Log.d("MessageCrypto", "🔑 V2 PBKDF2 key: ${pbkdf2Key2.toHex()}")
val result2 = decryptWithPBKDF2Key(encryptedData, pbkdf2Key2)
if (result2 != null) {
android.util.Log.d("MessageCrypto", "✅ V2 SUCCESS!")
return result2
}
android.util.Log.d("MessageCrypto", "❌ V2 failed")
android.util.Log.d("MessageCrypto", "🔓 Trying V3 (raw bytes for PBKDF2)...")
val pbkdf2Key3 = generatePBKDF2KeyFromBytes(chachaKeyPlain)
android.util.Log.d("MessageCrypto", "🔑 V3 PBKDF2 key: ${pbkdf2Key3.toHex()}")
val result3 = decryptWithPBKDF2Key(encryptedData, pbkdf2Key3)
if (result3 != null) {
android.util.Log.d("MessageCrypto", "✅ V3 SUCCESS!")
return result3
}
android.util.Log.d("MessageCrypto", "❌ V3 failed")
// V4: Стандартный Java PBKDF2 (PBEKeySpec с char[]) - для совместимости с Android encryptReplyBlob
android.util.Log.d("MessageCrypto", "🔓 Trying V4 (Java SecretKeyFactory with Latin1 password)...")
val pbkdf2Key4 = generatePBKDF2KeyJava(password2)
val result4 = decryptWithPBKDF2Key(encryptedData, pbkdf2Key4)
if (result4 != null) {
android.util.Log.d("MessageCrypto", "✅ V4 SUCCESS!")
return result4
}
android.util.Log.d("MessageCrypto", "❌ V4 failed")
// V5: Стандартный Java PBKDF2 с UTF-8 password
android.util.Log.d("MessageCrypto", "🔓 Trying V5 (Java SecretKeyFactory with UTF-8 password)...")
val pbkdf2Key5 = generatePBKDF2KeyJava(password1)
val result5 = decryptWithPBKDF2Key(encryptedData, pbkdf2Key5)
if (result5 != null) {
android.util.Log.d("MessageCrypto", "✅ V5 SUCCESS!")
return result5
}
android.util.Log.d("MessageCrypto", "❌ V5 failed")
// V6: Java CharsetDecoder with REPLACE для UTF-8 (может отличаться от bytesToJsUtf8String)
android.util.Log.d("MessageCrypto", "🔓 Trying V6 (Java CharsetDecoder REPLACE)...")
val decoder = java.nio.charset.StandardCharsets.UTF_8.newDecoder()
decoder.onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE)
decoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE)
val password6 = decoder.decode(java.nio.ByteBuffer.wrap(chachaKeyPlain)).toString()
val passwordBytes6 = password6.toByteArray(Charsets.UTF_8)
android.util.Log.d("MessageCrypto", "🔑 V6 password bytes: ${passwordBytes6.size}, hex: ${passwordBytes6.toHex().take(60)}...")
val pbkdf2Key6 = generatePBKDF2Key(password6)
android.util.Log.d("MessageCrypto", "🔑 V6 PBKDF2 key: ${pbkdf2Key6.toHex()}")
val result6 = decryptWithPBKDF2Key(encryptedData, pbkdf2Key6)
if (result6 != null) {
android.util.Log.d("MessageCrypto", "✅ V6 SUCCESS!")
return result6
}
android.util.Log.d("MessageCrypto", "❌ V6 failed")
android.util.Log.d("MessageCrypto", "❌ All variants failed!")
null
} catch (e: Exception) {
android.util.Log.e("MessageCrypto", "❌ decryptAttachmentBlobWithPlainKey failed: ${e.message}", e)
null
}
}
@@ -650,25 +614,20 @@ object MessageCrypto {
passwordLatin1: String
): String? {
return try {
android.util.Log.d("MessageCrypto", "🔐 decryptAttachmentBlobWithPassword: data length=${encryptedData.length}, password=${passwordLatin1.length} chars")
// Конвертируем Latin1 string → bytes → UTF-8 string (эмулируем Desktop)
// Desktop: Buffer.from(str, 'binary').toString('utf-8')
val passwordBytes = passwordLatin1.toByteArray(Charsets.ISO_8859_1)
val passwordUtf8 = bytesToJsUtf8String(passwordBytes)
android.util.Log.d("MessageCrypto", "🔑 Password UTF-8: ${passwordUtf8.length} chars")
// Генерируем PBKDF2 ключ (salt='rosetta', 1000 iterations, sha1)
// Crypto-js конвертирует passwordUtf8 string в UTF-8 bytes для PBKDF2
val pbkdf2Key = generatePBKDF2Key(passwordUtf8)
android.util.Log.d("MessageCrypto", "🔑 PBKDF2 key: ${pbkdf2Key.toHex()}")
// Расшифровываем AES-256-CBC + zlib decompress
val result = decryptWithPBKDF2Key(encryptedData, pbkdf2Key)
android.util.Log.d("MessageCrypto", "✅ Decryption: ${if (result != null) "success (${result.length} chars)" else "FAILED"}")
result
} catch (e: Exception) {
android.util.Log.e("MessageCrypto", "❌ decryptAttachmentBlobWithPassword failed: ${e.message}", e)
null
}
}
@@ -684,16 +643,13 @@ object MessageCrypto {
myPrivateKey: String
): String? {
return try {
android.util.Log.d("MessageCrypto", "🔐 decryptAttachmentBlob: data length=${encryptedData.length}, key length=${encryptedKey.length}")
// 1. Расшифровываем ChaCha ключ+nonce (56 bytes) через ECDH
val keyAndNonce = decryptKeyFromSender(encryptedKey, myPrivateKey)
android.util.Log.d("MessageCrypto", "🔑 Decrypted keyAndNonce: ${keyAndNonce.size} bytes, hex=${keyAndNonce.toHex().take(40)}...")
// 2. Используем ВСЕ 56 байт как password для PBKDF2
decryptAttachmentBlobWithPlainKey(encryptedData, keyAndNonce)
} catch (e: Exception) {
android.util.Log.e("MessageCrypto", "❌ decryptAttachmentBlob failed: ${e.message}", e)
null
}
}
@@ -791,20 +747,14 @@ object MessageCrypto {
*/
private fun decryptWithPBKDF2Key(encryptedData: String, pbkdf2Key: ByteArray): String? {
return try {
android.util.Log.d("MessageCrypto", "🔓 decryptWithPBKDF2Key: data length=${encryptedData.length}")
android.util.Log.d("MessageCrypto", "🔓 First 100 chars: ${encryptedData.take(100)}")
android.util.Log.d("MessageCrypto", "🔓 Contains colon: ${encryptedData.contains(":")}")
val parts = encryptedData.split(":")
android.util.Log.d("MessageCrypto", "🔓 Split parts: ${parts.size}")
if (parts.size != 2) {
android.util.Log.e("MessageCrypto", "❌ Invalid format: expected 2 parts, got ${parts.size}")
return null
}
val iv = android.util.Base64.decode(parts[0], android.util.Base64.DEFAULT)
val ciphertext = android.util.Base64.decode(parts[1], android.util.Base64.DEFAULT)
android.util.Log.d("MessageCrypto", "🔓 IV: ${iv.size} bytes, Ciphertext: ${ciphertext.size} bytes")
// AES-256-CBC расшифровка
val cipher = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding")
@@ -812,7 +762,6 @@ object MessageCrypto {
val ivSpec = javax.crypto.spec.IvParameterSpec(iv)
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, secretKey, ivSpec)
val decrypted = cipher.doFinal(ciphertext)
android.util.Log.d("MessageCrypto", "🔓 AES decrypted: ${decrypted.size} bytes")
// Zlib декомпрессия
val inflater = java.util.zip.Inflater()
@@ -826,10 +775,8 @@ object MessageCrypto {
inflater.end()
val result = String(outputStream.toByteArray(), Charsets.UTF_8)
android.util.Log.d("MessageCrypto", "🔓 Decompressed: ${result.length} chars")
result
} catch (e: Exception) {
android.util.Log.e("MessageCrypto", "❌ decryptWithPBKDF2Key failed: ${e.message}", e)
null
}
}