improve identity announcements (#198)

* improve identity announcements

* touches

* signing noise id

* panic mode delete signing key
This commit is contained in:
callebtc
2025-07-31 06:26:41 +02:00
committed by GitHub
parent 34d00839b2
commit 4cb5932fd0
15 changed files with 302 additions and 113 deletions
@@ -303,18 +303,19 @@ private fun PrivateChatHeader(
modifier = Modifier.align(Alignment.Center)
) {
// Reactive Noise session status icon
NoiseSessionIcon(
sessionState = sessionState,
modifier = Modifier.size(14.dp)
)
Spacer(modifier = Modifier.width(4.dp))
Text(
text = peerNickname,
style = MaterialTheme.typography.titleMedium,
color = Color(0xFFFF9500) // Orange
)
Spacer(modifier = Modifier.width(4.dp))
NoiseSessionIcon(
sessionState = sessionState,
modifier = Modifier.size(14.dp)
)
}
// Favorite button - positioned on the right
@@ -25,6 +25,10 @@ class ChatViewModel(
val meshService: BluetoothMeshService
) : AndroidViewModel(application), BluetoothMeshDelegate {
companion object {
private const val TAG = "ChatViewModel"
}
// State management
private val state = ChatState()
@@ -37,7 +41,7 @@ class ChatViewModel(
private val noiseSessionDelegate = object : NoiseSessionDelegate {
override fun hasEstablishedSession(peerID: String): Boolean = meshService.hasEstablishedSession(peerID)
override fun initiateHandshake(peerID: String) = meshService.initiateNoiseHandshake(peerID)
override fun sendIdentityAnnouncement() = meshService.sendKeyExchangeToDevice()
override fun broadcastNoiseIdentityAnnouncement() = meshService.broadcastNoiseIdentityAnnouncement()
override fun sendHandshakeRequest(targetPeerID: String, pendingCount: UByte) = meshService.sendHandshakeRequest(targetPeerID, pendingCount)
override fun getMyPeerID(): String = meshService.myPeerID
}
@@ -394,21 +398,71 @@ class ChatViewModel(
// MARK: - Emergency Clear
fun panicClearAllData() {
// Clear all managers
Log.w(TAG, "🚨 PANIC MODE ACTIVATED - Clearing all sensitive data")
// Clear all UI managers
messageManager.clearAllMessages()
channelManager.clearAllChannels()
privateChatManager.clearAllPrivateChats()
dataManager.clearAllData()
// Clear all mesh service data
clearAllMeshServiceData()
// Clear all cryptographic data
clearAllCryptographicData()
// Clear all notifications
notificationManager.clearAllNotifications()
// Reset nickname
val newNickname = "anon${Random.nextInt(1000, 9999)}"
state.setNickname(newNickname)
dataManager.saveNickname(newNickname)
Log.w(TAG, "🚨 PANIC MODE COMPLETED - All sensitive data cleared")
// Note: Mesh service restart is now handled by MainActivity
// This method now only clears data, not mesh service lifecycle
}
/**
* Clear all mesh service related data
*/
private fun clearAllMeshServiceData() {
try {
// Request mesh service to clear all its internal data
meshService.clearAllInternalData()
Log.d(TAG, "✅ Cleared all mesh service data")
} catch (e: Exception) {
Log.e(TAG, "❌ Error clearing mesh service data: ${e.message}")
}
}
/**
* Clear all cryptographic data including persistent identity
*/
private fun clearAllCryptographicData() {
try {
// Clear encryption service persistent identity (Ed25519 signing keys)
meshService.clearAllEncryptionData()
// Clear secure identity state (if used)
try {
val identityManager = com.bitchat.android.identity.SecureIdentityStateManager(getApplication())
identityManager.clearIdentityData()
Log.d(TAG, "✅ Cleared secure identity state")
} catch (e: Exception) {
Log.d(TAG, "SecureIdentityStateManager not available or already cleared: ${e.message}")
}
Log.d(TAG, "✅ Cleared all cryptographic data")
} catch (e: Exception) {
Log.e(TAG, "❌ Error clearing cryptographic data: ${e.message}")
}
}
// MARK: - Navigation Management
fun showAppInfo() {
@@ -13,7 +13,7 @@ import android.util.Log
interface NoiseSessionDelegate {
fun hasEstablishedSession(peerID: String): Boolean
fun initiateHandshake(peerID: String)
fun sendIdentityAnnouncement()
fun broadcastNoiseIdentityAnnouncement()
fun sendHandshakeRequest(targetPeerID: String, pendingCount: UByte)
fun getMyPeerID(): String
}
@@ -342,7 +342,7 @@ class PrivateChatManager(
} else {
// They should initiate, we send a Noise identity announcement
Log.d(TAG, "Our peer ID lexicographically >= target peer ID, sending Noise identity announcement to prompt handshake from $peerID")
noiseSessionDelegate.sendIdentityAnnouncement()
noiseSessionDelegate.broadcastNoiseIdentityAnnouncement()
// Also send handshake request to this peer
noiseSessionDelegate.sendHandshakeRequest(peerID, 1u) // 1 pending message (the chat we're trying to start)
}
@@ -414,12 +414,12 @@ class PrivateChatManager(
/**
* Send Noise identity announcement to prompt other peer to initiate handshake
* This follows the same pattern as sendKeyExchangeToDevice() in BluetoothMeshService
* This follows the same pattern as broadcastNoiseIdentityAnnouncement() in BluetoothMeshService
*/
private fun sendNoiseIdentityAnnouncement(meshService: Any) {
try {
// Call sendKeyExchangeToDevice which sends a NoiseIdentityAnnouncement
val method = meshService::class.java.getDeclaredMethod("sendKeyExchangeToDevice")
// Call broadcastNoiseIdentityAnnouncement which sends a NoiseIdentityAnnouncement
val method = meshService::class.java.getDeclaredMethod("broadcastNoiseIdentityAnnouncement")
method.invoke(meshService)
Log.d(TAG, "Successfully sent Noise identity announcement")
} catch (e: Exception) {