From 033187198090982f1793b954d7879c5825a5e342 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 31 Mar 2026 21:12:09 +0200 Subject: [PATCH] fix: missing file broadcast and leave message signatures + allow local development (#1078) * add signatures to file transfers and LEAVE messages * chore: setup project for local development and signing --------- Co-authored-by: jack <212554440+jackjackbits@users.noreply.github.com> --- Configs/Release.xcconfig | 1 + bitchat/Info.plist | 10 ++++++---- bitchat/Services/BLE/BLEService.swift | 15 +++++++++++++-- bitchat/bitchat-macOS.entitlements | 2 +- bitchat/bitchat.entitlements | 2 +- bitchatShareExtension/Info.plist | 2 ++ bitchatShareExtension/ShareViewController.swift | 2 +- .../bitchatShareExtension.entitlements | 2 +- 8 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Configs/Release.xcconfig b/Configs/Release.xcconfig index e6ee5009..988ce02d 100644 --- a/Configs/Release.xcconfig +++ b/Configs/Release.xcconfig @@ -9,3 +9,4 @@ DEVELOPMENT_TEAM = L3N5LHJD5Y CODE_SIGN_STYLE = Automatic PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat +APP_GROUP_ID = group.chat.bitchat diff --git a/bitchat/Info.plist b/bitchat/Info.plist index c7d9e3dd..f949ecee 100644 --- a/bitchat/Info.plist +++ b/bitchat/Info.plist @@ -2,6 +2,8 @@ + AppGroupID + $(APP_GROUP_ID) CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName @@ -37,12 +39,12 @@ bitchat uses Bluetooth to discover and connect with other bitchat users nearby. NSCameraUsageDescription bitchat uses the camera to scan QR codes to verify peers. - NSPhotoLibraryUsageDescription - bitchat lets you pick images from your photo library to share with nearby peers. - NSMicrophoneUsageDescription - bitchat uses the microphone to record voice notes that relay across the mesh. NSLocationWhenInUseUsageDescription bitchat uses your approximate location to compute local geohash channels for optional public chats. Exact GPS is never shared. + NSMicrophoneUsageDescription + bitchat uses the microphone to record voice notes that relay across the mesh. + NSPhotoLibraryUsageDescription + bitchat lets you pick images from your photo library to share with nearby peers. UIBackgroundModes bluetooth-central diff --git a/bitchat/Services/BLE/BLEService.swift b/bitchat/Services/BLE/BLEService.swift index 0ba5a753..908086ec 100644 --- a/bitchat/Services/BLE/BLEService.swift +++ b/bitchat/Services/BLE/BLEService.swift @@ -525,7 +525,7 @@ final class BLEService: NSObject { func stopServices() { // Send leave message synchronously to ensure delivery - let leavePacket = BitchatPacket( + var leavePacket = BitchatPacket( type: MessageType.leave.rawValue, senderID: myPeerIDData, recipientID: nil, @@ -535,6 +535,10 @@ final class BLEService: NSObject { ttl: messageTTL ) + if let signed = noiseService.signPacket(leavePacket) { + leavePacket = signed + } + // Send immediately to all connected peers (synchronized access to BLE state) if let data = leavePacket.toBinaryData(padding: false) { let leavePriority = priority(for: leavePacket, data: data) @@ -731,7 +735,7 @@ final class BLEService: NSObject { return } - let packet = BitchatPacket( + var packet = BitchatPacket( type: MessageType.fileTransfer.rawValue, senderID: self.myPeerIDData, recipientID: nil, @@ -742,6 +746,13 @@ final class BLEService: NSObject { version: 2 ) + if let signed = self.noiseService.signPacket(packet) { + packet = signed + } else { + SecureLogger.error("❌ Failed to sign file broadcast packet", category: .security) + return + } + let senderHex = packet.senderID.hexEncodedString() let dedupID = "\(senderHex)-\(packet.timestamp)-\(packet.type)" self.messageDeduplicator.markProcessed(dedupID) diff --git a/bitchat/bitchat-macOS.entitlements b/bitchat/bitchat-macOS.entitlements index b47c8475..2369c18b 100644 --- a/bitchat/bitchat-macOS.entitlements +++ b/bitchat/bitchat-macOS.entitlements @@ -6,7 +6,7 @@ com.apple.security.application-groups - group.chat.bitchat + $(APP_GROUP_ID) com.apple.security.device.bluetooth diff --git a/bitchat/bitchat.entitlements b/bitchat/bitchat.entitlements index 610b08cb..725336c1 100644 --- a/bitchat/bitchat.entitlements +++ b/bitchat/bitchat.entitlements @@ -6,7 +6,7 @@ com.apple.security.application-groups - group.chat.bitchat + $(APP_GROUP_ID) com.apple.security.device.bluetooth diff --git a/bitchatShareExtension/Info.plist b/bitchatShareExtension/Info.plist index caa4c793..a9c29c8d 100644 --- a/bitchatShareExtension/Info.plist +++ b/bitchatShareExtension/Info.plist @@ -2,6 +2,8 @@ + AppGroupID + $(APP_GROUP_ID) CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName diff --git a/bitchatShareExtension/ShareViewController.swift b/bitchatShareExtension/ShareViewController.swift index 07a369c9..a777720a 100644 --- a/bitchatShareExtension/ShareViewController.swift +++ b/bitchatShareExtension/ShareViewController.swift @@ -13,7 +13,7 @@ import UniformTypeIdentifiers /// Avoids deprecated Social framework and SLComposeServiceViewController. final class ShareViewController: UIViewController { // Bundle.main.bundleIdentifier would get the extension's bundleID - private static let groupID = "group.chat.bitchat" + private static let groupID = Bundle.main.object(forInfoDictionaryKey: "AppGroupID") as? String ?? "group.chat.bitchat" private enum Strings { static let nothingToShare = String(localized: "share.status.nothing_to_share", comment: "Shown when the share extension receives no content") diff --git a/bitchatShareExtension/bitchatShareExtension.entitlements b/bitchatShareExtension/bitchatShareExtension.entitlements index 80566616..745123f2 100644 --- a/bitchatShareExtension/bitchatShareExtension.entitlements +++ b/bitchatShareExtension/bitchatShareExtension.entitlements @@ -6,7 +6,7 @@ com.apple.security.application-groups - group.chat.bitchat + $(APP_GROUP_ID) \ No newline at end of file