mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-27 15:25:22 +00:00
Merge remote-tracking branch 'origin/main' into harden/radio-metadata
This commit is contained in:
@@ -63,7 +63,13 @@ jobs:
|
||||
echo "#"
|
||||
echo "# Verify a checkout of this ref with:"
|
||||
echo "# shasum -a 256 -c files.sha256"
|
||||
echo "# The git tree hash above is the single value that covers all of it:"
|
||||
echo "# Hash checking alone ignores files this manifest does not list, and"
|
||||
echo "# the Xcode project compiles any source file present in the tree. So"
|
||||
echo "# also confirm nothing extra is present:"
|
||||
echo "# git status --porcelain --ignored # git checkout: must print nothing"
|
||||
echo "# or, for a tarball, diff this manifest's path list against find(1)."
|
||||
echo "# Full instructions: docs/VERIFYING-A-BUILD.md"
|
||||
echo "# The git tree hash above is the single value covering all tracked content:"
|
||||
echo "# git rev-parse HEAD^{tree}"
|
||||
echo "#"
|
||||
} > SOURCE-MANIFEST.txt
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
# Security policy
|
||||
|
||||
bitchat is a security-focused messenger, and reports about its security are taken seriously. This page says how to report, what counts as a vulnerability here, and what to expect.
|
||||
|
||||
## Reporting a vulnerability
|
||||
|
||||
**Use GitHub's private vulnerability reporting:** [Report a vulnerability](https://github.com/permissionlesstech/bitchat/security/advisories/new) (Security tab → "Report a vulnerability").
|
||||
|
||||
Please do not open a public issue for anything that could put people at risk before a fix ships. bitchat is used by people in hostile network environments; a public proof-of-concept can be acted on faster than a patch can reach them.
|
||||
|
||||
A useful report says what an attacker can do, against which build (App Store version or commit hash), and how to reproduce it. A failing test or a packet capture is worth more than speculation about impact.
|
||||
|
||||
## What to expect
|
||||
|
||||
This is a volunteer-maintained project. The aim is to acknowledge reports within a week and to move on confirmed vulnerabilities immediately — historically, confirmed protocol and key-handling issues have been fixed within days. You'll be kept in the loop in the advisory thread, and credited in the fix unless you'd rather not be. There is no bug bounty.
|
||||
|
||||
## Supported versions
|
||||
|
||||
Fixes ship to the latest App Store release and `main`. Older releases are not patched; the fix is to update.
|
||||
|
||||
## Scope
|
||||
|
||||
In scope — the properties the app promises:
|
||||
|
||||
- Confidentiality and integrity of private messages and media (Noise sessions over BLE; over Nostr, bitchat's own ephemeral private-envelope format — a proprietary scheme, *not* NIP-17/NIP-44/NIP-59, see `WHITEPAPER.md`)
|
||||
- Identity: key handling, verification, impersonation, session binding
|
||||
- The panic wipe actually destroying what it claims to destroy
|
||||
- Metadata exposure beyond what the documentation already discloses (see `PRIVACY_POLICY.md` and `docs/privacy-assessment.md`)
|
||||
- Downgrade paths: anything that silently moves traffic from an encrypted path to a plaintext one
|
||||
- Tor routing: anything that makes traffic bypass Tor while the Tor preference is on
|
||||
- Supply-chain integrity of the source and its vendored binaries (see `docs/VERIFYING-A-BUILD.md`)
|
||||
|
||||
Out of scope — documented design properties, not vulnerabilities:
|
||||
|
||||
- Public visibility of mesh announces and geohash channels: broadcast content, nicknames, and public keys are public by design
|
||||
- Bluetooth proximity being observable: anyone in radio range can tell a BLE device is present
|
||||
- Mesh flooding/relay behavior inherent to a broadcast mesh (rate limits exist; the topology is what it is)
|
||||
- Behavior of third-party Nostr relays
|
||||
- Denial of service requiring physical proximity, and battery-drain attacks in general
|
||||
|
||||
If you're unsure whether something is in scope, report it privately anyway — a false alarm costs a few minutes; a real issue reported publicly can cost much more.
|
||||
|
||||
## Verifying what you're running
|
||||
|
||||
If your concern is that the app or source you have has been tampered with, that has its own document: `docs/VERIFYING-A-BUILD.md`.
|
||||
@@ -848,6 +848,9 @@ final class NostrRelayManager: ObservableObject {
|
||||
}
|
||||
}
|
||||
messageQueueLock.unlock()
|
||||
// A relay queued while Tor bootstraps would otherwise reconnect when
|
||||
// the queue drains, overriding the explicit removal.
|
||||
pendingTorConnectionURLs.subtract(urls)
|
||||
relays.removeAll { urls.contains($0.url) }
|
||||
updateConnectionStatus()
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ extension ChatViewModel {
|
||||
@objc func handleTorBootstrapDidStall() {
|
||||
Task { @MainActor in
|
||||
guard TorManager.shared.torEnforced else { return }
|
||||
// torEnforced is a compile-time constant in release builds; the
|
||||
// runtime preference is what says whether anyone is waiting on
|
||||
// Tor. Turning Tor off mid-bootstrap must not read as blocking.
|
||||
guard NetworkActivationService.persistedTorPreference() else { return }
|
||||
guard !self.torStallAnnounced else { return }
|
||||
self.torStallAnnounced = true
|
||||
self.addGeohashOnlySystemMessage(
|
||||
|
||||
@@ -73,7 +73,14 @@ struct ContentComposerView: View {
|
||||
.textInputAutocapitalization(.sentences)
|
||||
#endif
|
||||
.submitLabel(.send)
|
||||
.onSubmit(onSendMessage)
|
||||
.onSubmit {
|
||||
onSendMessage()
|
||||
// Only the return-key path: it steals focus on iOS, so
|
||||
// every message would cost a tap to reopen the keyboard.
|
||||
// The send button must not reopen a deliberately
|
||||
// dismissed keyboard, so it stays out of this.
|
||||
isTextFieldFocused.wrappedValue = true
|
||||
}
|
||||
.padding(.vertical, theme.usesGlassChrome ? 8 : 4)
|
||||
.padding(.horizontal, 6)
|
||||
.themedInputBackground()
|
||||
|
||||
@@ -1374,3 +1374,37 @@ private func makeImageData() throws -> Data {
|
||||
return data
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - Tor Extension Tests
|
||||
|
||||
struct ChatViewModelTorExtensionTests {
|
||||
|
||||
/// Turning Tor off mid-bootstrap must not read as "the network is
|
||||
/// blocking tor": `torEnforced` is a compile-time constant, so the stall
|
||||
/// handler has to consult the runtime preference before announcing.
|
||||
@Test @MainActor
|
||||
func bootstrapStall_withTorPreferenceOff_announcesNothing() async {
|
||||
let key = NetworkActivationService.torPreferenceKey
|
||||
let previous = UserDefaults.standard.object(forKey: key)
|
||||
defer {
|
||||
if let previous {
|
||||
UserDefaults.standard.set(previous, forKey: key)
|
||||
} else {
|
||||
UserDefaults.standard.removeObject(forKey: key)
|
||||
}
|
||||
}
|
||||
let (viewModel, _) = makeTestableViewModel()
|
||||
|
||||
UserDefaults.standard.set(false, forKey: key)
|
||||
viewModel.handleTorBootstrapDidStall()
|
||||
try? await Task.sleep(nanoseconds: 50_000_000)
|
||||
#expect(viewModel.torStallAnnounced == false)
|
||||
|
||||
// The same stall with the preference on (the persisted default) is
|
||||
// exactly what must still be announced.
|
||||
UserDefaults.standard.set(true, forKey: key)
|
||||
viewModel.handleTorBootstrapDidStall()
|
||||
try? await Task.sleep(nanoseconds: 50_000_000)
|
||||
#expect(viewModel.torStallAnnounced == true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,46 @@ final class NostrRelayManagerTests: XCTestCase {
|
||||
XCTAssertTrue(context.sessionFactory.allConnections.allSatisfy { $0.cancelCallCount >= 1 })
|
||||
}
|
||||
|
||||
/// A relay removed while its connection is queued behind Tor bootstrap
|
||||
/// must stay removed: draining the pending set used to resurrect it,
|
||||
/// because `dropRelays` never touched `pendingTorConnectionURLs` and a
|
||||
/// custom relay is in neither the default set nor the allow-list filter.
|
||||
func test_relayRemovedWhileWaitingForTor_staysRemovedWhenTorBecomesReady() async {
|
||||
let customURL = "wss://custom-removed.example"
|
||||
let center = NotificationCenter()
|
||||
let customRelays = MutableRelayList(urls: [customURL])
|
||||
let context = makeContext(
|
||||
permission: .authorized,
|
||||
userTorEnabled: true,
|
||||
torEnforced: true,
|
||||
torIsReady: false,
|
||||
notificationCenter: center,
|
||||
customRelays: customRelays
|
||||
)
|
||||
|
||||
// Defaults plus the custom relay all queue while Tor bootstraps.
|
||||
context.manager.connect()
|
||||
XCTAssertTrue(context.sessionFactory.requestedURLs.isEmpty)
|
||||
XCTAssertEqual(context.torWaiter.awaitCallCount, 1)
|
||||
|
||||
// The relay is removed by hand before Tor is ready.
|
||||
customRelays.urls = []
|
||||
center.post(name: NostrRelaySettings.didChangeNotification, object: nil)
|
||||
// The settings sink hops through the main queue; let it land.
|
||||
try? await Task.sleep(nanoseconds: 20_000_000)
|
||||
|
||||
context.torWaiter.resolve(true)
|
||||
|
||||
let defaultsConnected = await waitUntil {
|
||||
context.sessionFactory.requestedURLs.count == self.expectedDefaultRelayCount
|
||||
}
|
||||
XCTAssertTrue(defaultsConnected)
|
||||
XCTAssertFalse(
|
||||
context.sessionFactory.requestedURLs.contains(customURL),
|
||||
"a relay removed while Tor was bootstrapping must not reconnect when the pending queue drains"
|
||||
)
|
||||
}
|
||||
|
||||
func test_connect_waitsForTorReadinessBeforeCreatingSessions() async {
|
||||
let context = makeContext(permission: .authorized, userTorEnabled: true, torEnforced: true, torIsReady: false)
|
||||
|
||||
|
||||
@@ -18,26 +18,43 @@ In order of how much verification is possible:
|
||||
|
||||
Every tagged release has a `SOURCE-MANIFEST.txt` produced by `.github/workflows/source-manifest.yml`. It records the tag, the commit, the git tree hash, and a SHA-256 for every tracked file.
|
||||
|
||||
Check a copy of the source against it:
|
||||
Keep the downloaded manifest *outside* the source tree (say, `/tmp`) — a stray copy inside the checkout would itself trip the completeness checks below. Then check a copy of the source against it:
|
||||
|
||||
```sh
|
||||
# From the root of the source you obtained
|
||||
grep -v '^#' SOURCE-MANIFEST.txt > /tmp/files.sha256
|
||||
# From the root of the source you obtained, with the manifest at /tmp
|
||||
grep -v '^#' /tmp/SOURCE-MANIFEST.txt > /tmp/files.sha256
|
||||
shasum -a 256 -c /tmp/files.sha256
|
||||
```
|
||||
|
||||
Any `FAILED` line means that file differs from the released source. Investigate before building.
|
||||
|
||||
That check alone is not enough. `shasum -c` verifies the files the manifest lists and says nothing about files it does not list — and the Xcode project compiles every source file present in the tree automatically, so a hostile mirror can pass the hash check by leaving every listed file intact and *adding* one. Confirm nothing extra is present:
|
||||
|
||||
```sh
|
||||
# The manifest's path list must match the tree exactly — no missing files, no extras
|
||||
grep -v '^#' /tmp/SOURCE-MANIFEST.txt | sed 's/^[0-9a-f]* //' | LC_ALL=C sort > /tmp/manifest-paths
|
||||
find . -type f ! -path './.git/*' | sed 's|^\./||' | LC_ALL=C sort > /tmp/actual-paths
|
||||
diff /tmp/manifest-paths /tmp/actual-paths # must print nothing
|
||||
```
|
||||
|
||||
In a git checkout the same assurance is one command — it also catches extra files, because they show as untracked. `--ignored` matters: `.gitignore` covers paths like `build/`, plain `git status` would not report a planted file there, and Xcode compiles it all the same:
|
||||
|
||||
```sh
|
||||
git status --porcelain --ignored # must print nothing before you build
|
||||
```
|
||||
|
||||
The single value that covers the whole tree is the git tree hash in the manifest header:
|
||||
|
||||
```sh
|
||||
git rev-parse HEAD^{tree} # must equal the "tree:" line in the manifest
|
||||
```
|
||||
|
||||
Note the tree hash covers tracked content only; it does not see untracked files sitting in the working directory, which is why the emptiness checks above come first.
|
||||
|
||||
The manifest itself carries a provenance attestation tying it to the workflow run that produced it, so a manifest handed to you along with a mirror is checkable too:
|
||||
|
||||
```sh
|
||||
gh attestation verify SOURCE-MANIFEST.txt --repo permissionlesstech/bitchat
|
||||
gh attestation verify /tmp/SOURCE-MANIFEST.txt --repo permissionlesstech/bitchat
|
||||
```
|
||||
|
||||
That last step is what makes this resistant to a hostile mirror. Without it, whoever gives you the source can give you a matching manifest.
|
||||
|
||||
@@ -84,6 +84,10 @@ public final class TorManager: ObservableObject {
|
||||
private var shutdownsInFlight = 0
|
||||
private var startPendingAfterShutdown = false
|
||||
private var bootstrapMonitorStarted = false
|
||||
// Fences the detached poll loop: shutdown, dormancy, and restart each bump
|
||||
// this, so a loop from a previous attempt cannot run out its deadline and
|
||||
// report a stall over state that a newer lifecycle event already owns.
|
||||
private var bootstrapGeneration = 0
|
||||
private var pathMonitor: NWPathMonitor?
|
||||
private var isAppForeground: Bool = true
|
||||
private var lastRestartAt: Date? = nil
|
||||
@@ -268,24 +272,25 @@ public final class TorManager: ObservableObject {
|
||||
private func startBootstrapMonitor() {
|
||||
guard !bootstrapMonitorStarted else { return }
|
||||
bootstrapMonitorStarted = true
|
||||
bootstrapGeneration += 1
|
||||
let generation = bootstrapGeneration
|
||||
Task.detached(priority: .utility) { [weak self] in
|
||||
await self?.bootstrapPollLoop()
|
||||
await self?.bootstrapPollLoop(generation: generation)
|
||||
}
|
||||
}
|
||||
|
||||
private func bootstrapPollLoop() async {
|
||||
private func bootstrapPollLoop(generation: Int) async {
|
||||
let deadline = Date().addingTimeInterval(75)
|
||||
var didComplete = false
|
||||
while Date() < deadline {
|
||||
guard generation == bootstrapGeneration else { return }
|
||||
let progress = Int(arti_bootstrap_progress())
|
||||
let summary = getBootstrapSummary()
|
||||
|
||||
await MainActor.run {
|
||||
self.bootstrapProgress = progress
|
||||
self.bootstrapSummary = summary
|
||||
if progress >= 100 { self.isStarting = false }
|
||||
self.recomputeReady()
|
||||
}
|
||||
self.bootstrapProgress = progress
|
||||
self.bootstrapSummary = summary
|
||||
if progress >= 100 { self.isStarting = false }
|
||||
self.recomputeReady()
|
||||
|
||||
if progress >= 100 {
|
||||
didComplete = true
|
||||
@@ -296,17 +301,17 @@ public final class TorManager: ObservableObject {
|
||||
|
||||
// Running out the deadline is a reportable outcome, not silence. The
|
||||
// loop previously just ended, leaving `isStarting` true forever, so a
|
||||
// blocked network was indistinguishable from a slow one.
|
||||
// blocked network was indistinguishable from a slow one. A deliberate
|
||||
// shutdown mid-bootstrap is not a stall, hence the generation check.
|
||||
if !didComplete {
|
||||
await MainActor.run {
|
||||
self.isStarting = false
|
||||
self.bootstrapDidStall = true
|
||||
SecureLogger.warning(
|
||||
"TorManager: bootstrap did not complete within its deadline (progress=\(self.bootstrapProgress)); network may be blocking Tor",
|
||||
category: .session
|
||||
)
|
||||
NotificationCenter.default.post(name: .TorBootstrapDidStall, object: nil)
|
||||
}
|
||||
guard generation == bootstrapGeneration else { return }
|
||||
self.isStarting = false
|
||||
self.bootstrapDidStall = true
|
||||
SecureLogger.warning(
|
||||
"TorManager: bootstrap did not complete within its deadline (progress=\(self.bootstrapProgress)); network may be blocking Tor",
|
||||
category: .session
|
||||
)
|
||||
NotificationCenter.default.post(name: .TorBootstrapDidStall, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +357,7 @@ public final class TorManager: ObservableObject {
|
||||
// Clear isStarting so foreground recovery can proceed if bootstrap was interrupted.
|
||||
SecureLogger.debug("TorManager: goDormantOnBackground() called", category: .session)
|
||||
Task { @MainActor in
|
||||
self.bootstrapGeneration += 1
|
||||
self.isReady = false
|
||||
self.socksReady = false
|
||||
self.isStarting = false
|
||||
@@ -361,6 +367,7 @@ public final class TorManager: ObservableObject {
|
||||
public func shutdownCompletely() {
|
||||
SecureLogger.debug("TorManager: shutdownCompletely() called", category: .session)
|
||||
startPendingAfterShutdown = false
|
||||
bootstrapGeneration += 1
|
||||
shutdownsInFlight += 1
|
||||
Task.detached { [weak self] in
|
||||
guard let self = self else { return }
|
||||
@@ -398,6 +405,7 @@ public final class TorManager: ObservableObject {
|
||||
SecureLogger.debug("TorManager: restartArti() starting", category: .session)
|
||||
await MainActor.run {
|
||||
NotificationCenter.default.post(name: .TorWillRestart, object: nil)
|
||||
self.bootstrapGeneration += 1
|
||||
self.isReady = false
|
||||
self.socksReady = false
|
||||
self.bootstrapProgress = 0
|
||||
|
||||
Reference in New Issue
Block a user