mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 09:25:19 +00:00
fix(security): apply iOS audit parity fixes (#709)
Co-authored-by: CC <cc@ggg.local>
This commit is contained in:
@@ -539,6 +539,7 @@ class LocationChannelManager private constructor(private val context: Context) {
|
||||
fun clearPersistedChannel() {
|
||||
dataManager?.clearLastGeohashChannel()
|
||||
_selectedChannel.value = ChannelID.Mesh
|
||||
_teleported.value = false
|
||||
Log.d(TAG, "Cleared persisted channel selection")
|
||||
}
|
||||
|
||||
|
||||
@@ -572,7 +572,12 @@ class NoiseSession(
|
||||
}
|
||||
|
||||
val (extractedNonce, ciphertext) = nonceAndCiphertext
|
||||
|
||||
|
||||
if (ciphertext.size < receiveCipher!!.macLength) {
|
||||
Log.w(TAG, "Ciphertext too short: ${ciphertext.size} < ${receiveCipher!!.macLength}")
|
||||
throw SessionError.DecryptionFailed
|
||||
}
|
||||
|
||||
// Validate nonce with sliding window replay protection
|
||||
if (!isValidNonce(extractedNonce, highestReceivedNonce, replayWindow)) {
|
||||
Log.w(TAG, "Replay attack detected: nonce $extractedNonce rejected for $peerID")
|
||||
|
||||
@@ -73,14 +73,24 @@ object NostrProtocol {
|
||||
}
|
||||
|
||||
Log.v(TAG, "Successfully unwrapped gift wrap from: ${seal.pubkey.take(16)}...")
|
||||
|
||||
|
||||
if (seal.kind != NostrKind.SEAL || !seal.isValidSignature()) {
|
||||
Log.w(TAG, "❌ Invalid NIP-17 seal signature")
|
||||
return null
|
||||
}
|
||||
|
||||
// 2. Open the seal
|
||||
val rumor = openSeal(seal, recipientIdentity.privateKeyHex)
|
||||
?: run {
|
||||
Log.w(TAG, "❌ Failed to open seal")
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
if (seal.pubkey != rumor.pubkey) {
|
||||
Log.w(TAG, "❌ NIP-17 seal pubkey does not match rumor pubkey")
|
||||
return null
|
||||
}
|
||||
|
||||
Log.v(TAG, "Successfully opened seal")
|
||||
|
||||
Triple(rumor.content, rumor.pubkey, rumor.createdAt)
|
||||
@@ -227,7 +237,7 @@ object NostrProtocol {
|
||||
content = encrypted
|
||||
)
|
||||
|
||||
// Sign with the ephemeral key
|
||||
// NIP-17 requires the seal to be signed by the sender identity key.
|
||||
return seal.sign(senderPrivateKey)
|
||||
}
|
||||
|
||||
|
||||
@@ -938,6 +938,11 @@ class ChatViewModel(
|
||||
store.clearAll()
|
||||
} catch (_: Exception) { }
|
||||
|
||||
try {
|
||||
val locationManager = com.bitchat.android.geohash.LocationChannelManager.getInstance(getApplication())
|
||||
locationManager.clearPersistedChannel()
|
||||
} catch (_: Exception) { }
|
||||
|
||||
geohashViewModel.panicReset()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to reset Nostr/geohash: ${e.message}")
|
||||
|
||||
Reference in New Issue
Block a user