feat: Integrate AccountManager to retrieve last logged account in AuthFlow and update MainActivity
This commit is contained in:
@@ -606,15 +606,10 @@ object MessageCrypto {
|
||||
*/
|
||||
fun encryptReplyBlob(replyJson: String, plainKeyAndNonce: ByteArray): String {
|
||||
return try {
|
||||
android.util.Log.d("ReplyDebug", "🔐 encryptReplyBlob called:")
|
||||
android.util.Log.d("ReplyDebug", " - plainKeyAndNonce size: ${plainKeyAndNonce.size}")
|
||||
android.util.Log.d("ReplyDebug", " - plainKeyAndNonce hex: ${plainKeyAndNonce.joinToString("") { "%02x".format(it) }}")
|
||||
|
||||
// Convert plainKeyAndNonce to string - simulate JS Buffer.toString('utf-8') behavior
|
||||
// which replaces invalid UTF-8 sequences with U+FFFD
|
||||
val password = bytesToJsUtf8String(plainKeyAndNonce)
|
||||
android.util.Log.d("ReplyDebug", " - password length: ${password.length}")
|
||||
android.util.Log.d("ReplyDebug", " - password bytes (first 20): ${password.toByteArray(Charsets.UTF_8).take(20).joinToString(",")}")
|
||||
|
||||
// Compress with pako (deflate)
|
||||
val deflater = java.util.zip.Deflater()
|
||||
@@ -817,37 +812,25 @@ object MessageCrypto {
|
||||
*/
|
||||
fun decryptReplyBlob(encryptedBlob: String, plainKeyAndNonce: ByteArray): String {
|
||||
return try {
|
||||
android.util.Log.d("ReplyDebug", "🔓 decryptReplyBlob called:")
|
||||
android.util.Log.d("ReplyDebug", " - Input length: ${encryptedBlob.length}")
|
||||
android.util.Log.d("ReplyDebug", " - plainKeyAndNonce size: ${plainKeyAndNonce.size}")
|
||||
android.util.Log.d("ReplyDebug", " - plainKeyAndNonce hex: ${plainKeyAndNonce.joinToString("") { "%02x".format(it) }}")
|
||||
|
||||
// Check if it's encrypted format (contains ':')
|
||||
if (!encryptedBlob.contains(':')) {
|
||||
android.util.Log.d("ReplyDebug", " - No ':' found, returning as-is")
|
||||
return encryptedBlob
|
||||
}
|
||||
|
||||
// Parse ivBase64:ciphertextBase64
|
||||
val parts = encryptedBlob.split(':')
|
||||
if (parts.size != 2) {
|
||||
android.util.Log.d("ReplyDebug", " - Invalid format (not 2 parts), returning as-is")
|
||||
return encryptedBlob
|
||||
}
|
||||
|
||||
android.util.Log.d("ReplyDebug", " - IV part length: ${parts[0].length}")
|
||||
android.util.Log.d("ReplyDebug", " - Ciphertext part length: ${parts[1].length}")
|
||||
|
||||
val iv = Base64.decode(parts[0], Base64.DEFAULT)
|
||||
val ciphertext = Base64.decode(parts[1], Base64.DEFAULT)
|
||||
|
||||
android.util.Log.d("ReplyDebug", " - Decoded IV size: ${iv.size}")
|
||||
android.util.Log.d("ReplyDebug", " - Decoded ciphertext size: ${ciphertext.size}")
|
||||
|
||||
// Password from plainKeyAndNonce - use same JS-like UTF-8 conversion
|
||||
val password = bytesToJsUtf8String(plainKeyAndNonce)
|
||||
android.util.Log.d("ReplyDebug", " - Password length: ${password.length}")
|
||||
android.util.Log.d("ReplyDebug", " - Password bytes hex: ${password.toByteArray(Charsets.UTF_8).joinToString("") { "%02x".format(it) }}")
|
||||
|
||||
// PBKDF2 key derivation
|
||||
// CRITICAL: Must use SHA256 to match React Native (not SHA1!)
|
||||
@@ -861,7 +844,6 @@ object MessageCrypto {
|
||||
val secretKey = factory.generateSecret(spec)
|
||||
val keyBytes = secretKey.encoded
|
||||
|
||||
android.util.Log.d("ReplyDebug", " - Derived key size: ${keyBytes.size}")
|
||||
|
||||
// AES-CBC decryption
|
||||
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||
@@ -870,7 +852,6 @@ object MessageCrypto {
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec)
|
||||
val decompressed = cipher.doFinal(ciphertext)
|
||||
|
||||
android.util.Log.d("ReplyDebug", " - Decrypted (compressed) size: ${decompressed.size}")
|
||||
|
||||
// Decompress with inflate
|
||||
val inflater = java.util.zip.Inflater()
|
||||
@@ -880,14 +861,9 @@ object MessageCrypto {
|
||||
inflater.end()
|
||||
val plaintext = String(outputBuffer, 0, outputSize, Charsets.UTF_8)
|
||||
|
||||
android.util.Log.d("ReplyDebug", " - Decompressed plaintext length: ${plaintext.length}")
|
||||
android.util.Log.d("ReplyDebug", " - Plaintext preview: ${plaintext.take(100)}")
|
||||
android.util.Log.d("ReplyDebug", "✅ decryptReplyBlob success")
|
||||
|
||||
plaintext
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("ReplyDebug", "❌ decryptReplyBlob failed:", e)
|
||||
android.util.Log.e("ReplyDebug", " - Exception: ${e.javaClass.simpleName}: ${e.message}")
|
||||
// Return as-is, might be plain JSON
|
||||
encryptedBlob
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user