Code Monkey home page Code Monkey logo

celzero / rethink-app Goto Github PK

View Code? Open in Web Editor NEW
2.4K 48.0 122.0 48.59 MB

DNS over HTTPS / DNS over Tor / DNSCrypt client, WireGuard proxifier, firewall, and connection tracker for Android.

Home Page: https://rethinkfirewall.com/

License: Apache License 2.0

Kotlin 99.71% Java 0.29%
android-app firewall android-firewall dns-over-https internet-freedom anti-surveillance anti-censorship censorship-circumvention censorship-resistance android-application

rethink-app's Introduction

Rethink DNS + Firewall + VPN for Android

A WireGuard client, an OpenSnitch-inspired firewall and network monitor + a pi-hole-inspired DNS over HTTPS client with blocklists.

In other words, Rethink DNS + Firewall has three primary modes, VPN, DNS, and Firewall. The VPN (proxifier) mode supports multiple WireGuard upstreams in a split-tunnel configuration. The DNS mode routes all DNS traffic generated by apps to any user chosen DNS-over-HTTPS or DNSCrypt resolver. The Firewall mode lets the user deny internet-access to entire applications based on events like screen-on / screen-off, app-foreground / app-background, unmetered-connection / metered-connection; or based on play-store defined categories like Social, Games, Utility, Productivity; or additionally, based on user-defined denylists.

Get it on F-Droid Get it on Google Play

VPN / Proxifier

Rethink supports forwarding TCP and UDP connections over SOCKS5, HTTP CONNECT, and WireGuard tunnels. Split-tunneling further helps run multiple such tunnels at the same time and lets users route different apps over different tunnels. For example, one could route Firefox over SOCKS5 connecting to Tor, Netflix over WireGuard connecting through any popular VPN provider, and Telegram or WhatsApp over censorship-resistant HTTP CONNECT endpoints at the same time.

Firewall

The firewall doesn't really care about the connections per se rather what's making those connections. This is different from the traditional firewalls but in-line with Little Snitch, LuLu, Glasswire and others.

Currently, per-app connection mapping is implemented by capturing udp and tcp connections managed by firestack (written in golang) and asking ConnectivityService for the owner, an API available only on Android 10 or higher. procfs (/proc/net/tcp and /proc/net/udp) is read on-demand to track per-app connections like NetGuard or OpenSnitch do, on Android 9 and lower versions.

Network Monitor

A network monitor is a per-app report-card of sorts on when connections were made, how many were made, and to where. Tracking TCP has turned out to be so far straight-forward. DNS packets are trickier to track, and so a rough heuristic is used for now, which may not hold good in all cases.

DNS over HTTPS client

Almost all of the network related code (firestack), including DNS over HTTPS split-tunnel, is a hard fork of Jigsaw-Code/outline-go-tun2socks written in golang. The UI is vastly different but borrows minimally from Jigsaw-Code/Intra. A split-tunnel traps requests sent to the VPN's DNS endpoint and relays it to a DNS-over-HTTPS / DNSCrypt endpoint of the user's choosing, logging the end-to-end latency, time of request, the dns request query itself and its answer.

The Rethink DNS Resolver

A malware and ad-blocking DNS over HTTPS resolver at https://sky.rethinkdns.com/1:IAAgAA== (deployed to 300+ locations world-wide via Cloudflare Workers) is the default DNS endpoint on the app, though the user is free to change that. A configurable DNS resolver that lets users add or remove denylists and allowlists, add rewrites, analyse DNS requests is launching late 2023. Right now, a free-to-use DNS over HTTPS endpoint with custom blocklists can be setup here: rethinkdns.com/configure.

The resolver is deployed to Fly.io at max.rethinkdns.com and Deno Deploy at rdns.deno.dev too, apart from the default deployment on Cloudflare Workers.

The resolver is open source software: serverless-dns.

The Rethink Proxy Network

Routing TCP connections over a serverless proxy (hosted on Cloudflare Workers) will soon be part of Rethink. Users would be able to self-host these or use the ones run by us for $1 month of unlimited bandwidth. This service is expected to be launching late 2023.

The proxy is open source software: serverless-proxy.

Community

GitHub Sponsors

  • The telegram community is super active and full of crypto-bros. Kidding. We are generally a welcoming bunch. Feel free to get in touch: t.me/rethinkdns.
  • Or, if you prefer Matrix (which is bridged to Telegram).
  • Or, email us: [email protected] (we read all emails immediately and reply once we fix the issues being reported).
  • We regularly hangout in our subreddit: r/rethinkdns.
  • We're also kind of active on the bird app, mostly nerd-sniping other engs or shit-posting about our tech stack: twitter/rethinkdns.

Translation

Help translate Rethink DNS + Firewall on Weblate:

What Rethink DNS + Firewall is not

Rethink is not an anonymity tool: It helps users tackle unabated censorship and surveillance but doesn't lay claim to protecting a user's identity at all times, if ever.

Rethink doesn't aim to be a feature-rich traditional firewall: It is more in-line with Little Snitch than IP tables, say.

Rethink is not an anti-virus: Rethink may stop users from phishing attacks, malware, scareware websites through its DNS-based blocklists, but it doesn't actively mitigate threats or even look for them or act on them, otherwise.

What Rethink DNS + Firewall aspires to be

To turn Android devices into user-agents: Something that users can control as they please without requiring root-access. A big part of this, for an always-on, always-connected devices, is capturing network traffic and reporting it in a way that makes sense to the end-users who can then take a series of actions to limit their exposure but not necessarily eliminate it. Take DNS for example-- for most if not all connections, apps send out a DNS request first, and by tracking just those one can glean a lot of intelligence about what's happening with the phone and which app's responsible.

To deliver the promise of open-internet for all: With the inevitable ESNI standardization and the imminent adoption of DNS over HTTPS and DNS over TLS across operating systems, we're that much closer to an open internet. Of course, Deep Packet Inspection remains a credible threat that can't be mitigated with this, but it is one example of delivering maximum impact (circumvent internet censorship in most countries) with minimal effort (not requiring use of a VPN or access via IPFS, for example). Rethink would continue to make these technologies accessible in the most simplest way possible, especially the ones that get 90% of the way there with 10% effort.

Development

OpenSSF Scorecard

  1. Feel free to fork and send along a pull request for any reproducible bug fixes.
  2. The codebase is raw and is lacking documentation and comprehensive tests. If you need help, feel free to create a Wikipage to highlight the pain with building, testing, writing, committing code.
  3. Write descriptive commit messages that explain concisely the changes made.
  4. Each commit must reference an open issue on the project. This is to make sure there isn't duplicated effort more than anything else.
  5. If you plan to work on a feature, please create a github issue on the project first to kickstart the discussion before committing to doing any work. Again, this is to avoid duplicate work more than anything else.
  6. Prod releases are usually once every 2 months, while betas are released bi-weekly.

Tenets (unless you know better ones)

We aren't there yet, may never will be but these are some tenets for the project for the foreseeable future.

  • Make it right, make it secure, make it resilient, make it fast. In that order.
  • Easy to use, no-root, no-gimmicks features that are anti-censorship and anti-surveillance.
    • Easy to use: Any of the 3B+ Android users must be able to use it. Think CleanMaster / Instagram levels of ease-of-use.
    • no-root: Shouldn't require root-access for any functionality added to it.
    • no-gimmicks: Misleading material bordering on scareware, for example.
    • anti-censorship: Features focused on helping bring an open internet to everyone, preferably in the most efficient way possible (both monetarily and technically).
  • Anti-surveillance: As above, but features that further limit (may not necessarily eliminate) surveillance by apps.
  • Incremental changes in balance with newer features.
    • For example, work on nagging UI issues or OEM specific bugs, must be taken up on equal weight to newer features, and a release must probably establish a good balance between the two. However; working on only incremental changes for a release is fine.
  • Opinionated. Chip-away complexity. Do not expect users to require a PhD in Computer Science to use the app.
    • No duplicate functionality.
    • A concerted effort to not provide too many tunable knobs and settings. To err on the side of easy over simple.
  • Ignore all tenets.
    • Common sense always takes over when tenets get in the way.
  • Must be distributable on the PlayStore, at least some toned down version of it.
    • This unfortunately means on-device blocklists aren't possible; however, Cloudflare Gateway-esque cloud-based per-user blocklists get us the same functionality.
  • Practice what you preach: Be obsessively private and secure.

Backstory

FOSS UnitedOSOM Products IncMozilla Builders

Internet censorship (sometimes ISP-enforced and often times government-enforced), unabated dragnet surveillance (by pretty much every company and app) stirred us upon this path. The three of us university classmates, Mohammed, Murtaza, Santhosh got together in late 2019 in the sleepy town of Coimbatore, India to do something about it. Our main gripe was there were all these wonderful tools that people could use but couldn't, either due to cost or due to inability to grok Computer-specific jargon. A lot has happened since we started and a lot has changed but our focus has always been on Android and its 2B+ unsuspecting users. The current idea has been in the works for since May 2020, with the pandemic derailing a bit of progress, and a bit of snafu with abandoning our previous version in favour of the current fork, which we aren't proud of yet, but it is a start. All's good now that we've won a grant from the Mozilla Builders MVP program to go ahead and build this thing that we wanted to... do so faster... and not simply sleep our way through the execution. I hope you're excited but not as much as us that you quit your jobs for this like we did.

rethink-app's People

Contributors

70h avatar 8itlew7r avatar atalanttore avatar ch4t4r avatar cocklemon avatar comradekingu avatar fnogcps avatar gfhk-sdgm avatar hrbdev avatar hussainmohd-a avatar ignoramous avatar laralem avatar magicalalchemist avatar manuel-senpai avatar mistercosta96 avatar mygod avatar oersen avatar pjammo avatar poneyclairdelune avatar rix-x avatar rodoma92 avatar t1011 avatar thejenja avatar thepsychobuck avatar uldiniad avatar weblate avatar xiaomifighter avatar ysard avatar yurtpage avatar zivsimchoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rethink-app's Issues

User feedback: Auto-start behaviour and VPN state

On a restart, BraveDNS starts-up to resume VPN services, but it so happens that on ocassion another app takes the VPN over and BraveDNS continues to show "protected/waiting" ("running"), when in fact it wasn't.

Also, add ability for end-users to choose whether BraveDNS must auto-start on reboots.

User feedback: Proxy mode

The app should be able to:

  1. Listen on localhost:port.
  2. Forward packets outgoing to host:port.
  3. Forward packets to remote or local SOCKS5 or HTTPS proxies. This would enable BraveDNS to forward connections to some VPNs (that support SOCKS5) and Orbot.

Also see: #37 #44

Ref: Proxy mode in InviZible.

ConnTrack

Track and log an app's incoming and outgoing connections, show consolidated reports to the user.

ConnTrack for DNS UDP would be a heuristic:

  1. Track DNS queries and answers.
  2. See if any app within the next 400ms or so makes a connection to an IP answered by DNS.
  3. If so, it is likely (not certainly) that app sent the DNS request in the first place.

Need a new alerts screen? This is likely going involve adding a new screen and so, see also: Refactor the current Firewall screen to rid of two different app lists and possibly merge them into one single list.

User feedback: DNS Stats

  1. Total connections per app per week. #98

  2. Domain requests blocked grouped by
    a. category (gambling, social media, family etc)
    b. list-name (stevenblack, adguard, disconnect etc)
    c. per-app

  3. transport+port to protocol mapping, for example: UDP/53 -> DNS, TCP/443 -> HTTPS (these aren't really guaranteed to be accurate especially for apps that don't respect reserved ports, but are useful nonetheless). Ref.

See also: #3 and #308

Android 6+ Support

Currently, due to ill-explored (androidx?) limitations, the app builds for up to Android 8.

We could go as low as Android 4, but it is decent to aim for Android 6+. And that's what we should do. Probably a week's worth of effort?

DNS log filters (ui)

Currently, there's no way to filter just the blocked traffic on the app. Provide a way to filter blocked traffic vs all traffic on the DNS log page.

Add an indicator to the entry against blocked DNS traffic (with a "red" border or some such) to distinguish it from allowed DNS traffic.

User request: Scheduled-based Firewall

Figure out a way to selectively block certain apps either on a schedule or for the next few user-chosen minutes / hours.

The UX is going to be a real challenge for this one.

See: #63

Bypass Private DNS

Private DNS (supported on Android 9+), when set causes the system to ignore's VPN's DNS endpoint. This means, the app cannot effectively run or capture or block DNS requests at all.

Either find a way to bypass Private DNS, or disable the DNS option in the homescreen when Private DNS is set.

Private DNS is detectable through LinkProperties#isPrivateDnsActive and could be fetched either from LinkProperties#getPrivateDnsServerName or LinkProperties#getDnsServers.

LinkProperities are updated on private dns changes as seen in the log below. Check if there's a broadcast or for Vpn to find out when such changes happen.

08-14 19:05:19.633  2588  3648 D QCNEJ/WlanStaInfoRelay: Updating link properties: {InterfaceName: wlan0 LinkAddresses: [ 0000::0000:0000:0000:1ac4/64,192.168.1.5/24 ] DnsAddresses: [ /1.1.1.1,/176.103.130.130 ] UsePrivateDns: true PrivateDnsServerName: dns.adguard.com ValidatedPrivateDnsAddresses: [176.103.130.130] Domains: null MTU: 0 TcpBufferSizes: 524288,1048576,4194304,524288,1048576,4194304 Routes: [ fe80::/64 -> :: wlan0,::/0 -> 0000::0000:0000:0000:1ac4 wlan0,192.168.1.0/24 -> 0.0.0.0 wlan0,0.0.0.0/0 -> 192.168.1.1 wlan0 ]}

Refactor the Firewall Screen

Refactor the current Firewall screen to rid of two different app lists and possibly merge them into one single list. This has been a source of lot of pain in terms of handling Category-wise allow/disallow. Merging the lists would simplify the confusing UI and as a bonus simplify the existing business logic.

Crash on screen on / screen off

Crash log:

08-09 04:23:35.661 11049 13207 F libc    : Fatal signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xf2ff004000000001 in tid 13207 (Thread-18), pid 11049 (elzero.bravedns)
08-09 04:23:35.984 14998 14998 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-09 04:23:35.984 14998 14998 F DEBUG   : Revision: '0'
08-09 04:23:35.984 14998 14998 F DEBUG   : ABI: 'arm64'
08-09 04:23:35.985 14998 14998 F DEBUG   : Timestamp: 2020-08-09 04:23:35+0530
08-09 04:23:35.985 14998 14998 F DEBUG   : pid: 11049, tid: 13207, name: Thread-18  >>> com.celzero.bravedns <<<
08-09 04:23:35.985 14998 14998 F DEBUG   : uid: 10416
08-09 04:23:35.985 14998 14998 F DEBUG   : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xf2ff004000000001
08-09 04:23:35.985 14998 14998 F DEBUG   :     x0  0000007d913d5b08  x1  0000007d998ee7e0  x2  0000007e8ddd0600  x3  0000007d918f9a2c
08-09 04:23:35.985 14998 14998 F DEBUG   :     x4  000000000000076c  x5  0000007d918f9a44  x6  000000000000076c  x7  f2ff004000000001
08-09 04:23:35.985 14998 14998 F DEBUG   :     x8  00000000076c0000  x9  00000000076c0000  x10 0000000000000066  x11 000000000000007a
08-09 04:23:35.985 14998 14998 F DEBUG   :     x12 0000000000000001  x13 0000007d90e09c40  x14 0000000000000000  x15 0000007d91487475
08-09 04:23:35.985 14998 14998 F DEBUG   :     x16 0000007e8af068f0  x17 0000007e8aef8070  x18 0000007d54be6000  x19 0000007e8ddd0600
08-09 04:23:35.985 14998 14998 F DEBUG   :     x20 0000000000000014  x21 0000007d918f9630  x22 0000000000000000  x23 0000007d918f9a08
08-09 04:23:35.985 14998 14998 F DEBUG   :     x24 0000004000436c00  x25 0000007d918f9630  x26 0000007d9158b250  x27 0000000000000010
08-09 04:23:35.985 14998 14998 F DEBUG   :     x28 0000004000082f00  x29 0000007d90e09c00
08-09 04:23:35.985 14998 14998 F DEBUG   :     sp  0000007d90e09bc0  lr  0000007d913e50ac  pc  f2ff004000000001
08-09 04:23:35.986 14998 14998 F DEBUG   :
08-09 04:23:35.986 14998 14998 F DEBUG   : backtrace:
08-09 04:23:35.986 14998 14998 F DEBUG   :       #00 pc f2ff004000000001  <unknown>
08-09 04:23:35.987 14998 14998 F DEBUG   :       #01 pc 00000000005d70a8  /data/app/com.celzero.bravedns-spvz9uRBb9GpyyDC9xqYkA==/base.apk (offset 0x214000) (ip4_input+476)
08-09 04:24:56.036 15136 15136 E AndroidRuntime: FATAL EXCEPTION: main
08-09 04:24:56.036 15136 15136 E AndroidRuntime: Process: com.celzero.bravedns, PID: 15136
08-09 04:24:56.036 15136 15136 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.SCREEN_OFF flg=0x58200010 } in com.celzero.bravedns.service.BraveScreenStateReceiver@a18c932
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1575)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args.run(Unknown Source:2)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:883)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:100)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:214)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7682)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
08-09 04:24:56.036 15136 15136 E AndroidRuntime: Caused by: m.a
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at com.celzero.bravedns.service.BraveScreenStateReceiver.onReceive(:14)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1560)
08-09 04:24:56.036 15136 15136 E AndroidRuntime:    ... 8 more
--------- beginning of system

And this log may be relevant which precedes the crash log:

08-09 21:19:44.968  1310  1878 D ConnectivityService: Removing iface tun0 from network 118
08-09 21:19:44.968   730  1281 D NetlinkEvent: Unknown ifindex 109 in RTM_DELADDR
08-09 21:19:44.991  1310  1878 E ConnectivityService: Exception in removeRoute: java.lang.IllegalStateException: android.os.ServiceSpecificException: No such device (code 19)
08-09 21:19:44.992  1310  1878 I chatty  : uid=1000(system) ConnectivitySer identical 1 line
08-09 21:19:44.993  1310  1878 E ConnectivityService: Exception in removeRoute: java.lang.IllegalStateException: android.os.ServiceSpecificException: No such device (code 19)
08-09 21:19:44.993  1310  1878 I Nat464Xlat: Android Xlat enabled is doXlat = true
08-09 21:19:45.082  1310  1878 D ConnectivityService: Adding iface tun0 to network 118
08-09 21:19:45.170  1310  1878 D ConnectivityService: Removing iface tun1 from network 118
08-09 21:19:45.170   730  1281 D NetlinkEvent: Unknown ifindex 110 in RTM_DELADDR
08-09 21:19:45.196  1310  1878 E ConnectivityService: Exception in removeRoute: java.lang.IllegalStateException: android.os.ServiceSpecificException: No such device (code 19)
08-09 21:19:45.196  1310  1878 I chatty  : uid=1000(system) ConnectivitySer identical 1 line
08-09 21:19:45.197  1310  1878 E ConnectivityService: Exception in removeRoute: java.lang.IllegalStateException: android.os.ServiceSpecificException: No such device (code 19)
08-09 21:19:45.197  1310  1878 I Nat464Xlat: Android Xlat enabled is doXlat = true
08-09 21:19:45.598  1310  3078 E OPBF    : mImportantUids change mLastImportantUids =[10416, 10086, 10169, 10107, 10109] mImportantUids = [10416, 10086, 10107, 10109]
08-09 21:19:45.628  1310  3078 E OPBF    : mImportantUids change mLastImportantUids =[10416, 10086, 10107, 10109] mImportantUids = [10416, 10107, 10109]
08-09 21:19:45.754  1310  3078 E OPBF    : mImportantUids change mLastImportantUids =[10416, 10107, 10109] mImportantUids = [10416, 10109]
08-09 21:19:45.766  1310  1878 D ConnectivityService: Blocked status changed to true for 10107(168) on netId 118
08-09 21:19:45.766  1310  1878 D ConnectivityService: Blocked status changed to true for 10107(169) on netId 118
08-09 21:19:45.766  1310  1878 D ConnectivityService: Blocked status changed to true for 10107(170) on netId 118
08-09 21:19:45.767  1310  1878 D ConnectivityService: Blocked status changed to true for 10107(171) on netId 118
08-09 21:19:47.474  1310  1415 D ExtBatteryStatsService: @@@@ awaitUninterruptibly in 80 ms
08-09 21:19:47.476  1310  1415 D ExtBatteryStatsService: ext-flush too soon, skip
08-09 21:19:48.650 29985 30518 F libc    : Fatal signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xedca004000000001 in tid 30518 (Thread-23), pid 29985 (elzero.bravedns)

Integrate AWS Amplify

Required for users of BraveDNS, the resolver, for:

  1. Sign-in / Sign-up.
  2. User-specific configuration.
  3. User-specific metadata.

Firewall and Shared UIDs

BraveVPNService#isUidBlocked needs to account for the fact that there can be multiple packages (apps) with the same uid. See: PackageManager#getPackagesForUid.

A consistent behaviour would be:

  1. Show all apps with shared-uid together on the firewall screen. If they are across different categories then show the group once each across those categories.
  2. When blocking any one app with shared-uid, block all, and make that much clear to the user.
  3. In ConnTrack #3 make sure to bunch these apps together in the report.

Block other DNS over HTTPS providers?

Apps may bypass DNS blocks by using a DNS over HTTPS (DoH) provider of their own choosing. Block those ONLY on user-prompt. A UI can be reactive: Show an alert on home-screen that use of foreign DNS provider has been detected and that the user can choose to stop that from happening so in the future.

Apps relying on plain old-DNS are already trapped since VPN blanket relays all traffic on port 53 (unlike Intra) to DoH servers. There's a small matter of #33 (VPN bypass too).

Incomplete list: github/curl/wiki/DNS-over-HTTPS.

OkHttp3: okhttp3/dnsoverhttps/DohProviders.java.

Also see: #25

Advance VPN Settings

A VPN settings screen to:

  1. Exclude apps from the VPN tunnel.
  2. Exclude certain IP ranges (like LAN IPs, for example, #26).
  3. Allow / disallow VPN bypass. See also: #33
  4. Enable / disable Auto-start on reboot. See also: #41
  5. Enable / disable supervisor / watchdog. See also: #20
  6. Low battery modes. See also: #48

Vpn allowBypass conundrum

For a VPN masking as a firewall, it is suicidal to let apps bypass it: BraveVPNService.kt#L178.

  • May be provide an "Advanced Setting" to let users to not allow bypass?
  • May be never allow bypass when the device is locked and the universal firewall rule is set?
  • May be never allow bypass at all at the risk of breaking web-rtc apps?

DNS change delay

Prevent changing the DNS for a second or two.

One way would be to disable the DNS changer drop-down (spinner) for a second or so.

Temporary respite from all the blocking

Come up with a way to let users disable the firewall and DNS temporarily for up to a pre-determined time limit.

  1. From the home-screen.

  2. Via the notifications bar actions, if possible.

Round-robin DNS

Round-robin DNS requests to a list of servers (grouped by categories: Family, Security, No filter etc) instead of just one.

Use LiveData to track live counters

May be LiveData make our lives easier?

The live counters appears on the homescreen and show total dns queries, percentage queries blocked, number of apps blocked and so on... May be there's a use for LiveData elsewhere too, like in the Firewall screen with ConnTrack?

LwIP consistently hits SIGSEGVs

At least two crashes in space of 12 hours, both in the LwIP stack of gotun2socks presumably because some tcp state has gone whack.

I am starting to think that we do not terminate the connection like we normally should (Android's implementation indicates it relies on PROHIBIT response from the Kernel to terminate connections). A gentle tcpConn.Close might not be enough and a tcpConn.Abort might be of order.

The implementation differences in go-tun2socks for tcpConn.Close and tcpConn.Abort do reveal stark differences, the primary is that conn.state isn't updated in the former case whilst it is set to tcpAborting in the latter case.

Further more, tcpConn.Abort is what go-tun2socks uses to rid of connection when there's any err reported by the registeredTCPHandler.

Crashes (both happened after firewall was relaxed after a screen-on event):

No. 1

08-16 08:10:03.576 23934 23934 E chromium: [0816/081003.575374:ERROR:elf_dynamic_array_reader.h(61)] tag not found
08-16 08:10:03.584 15668 16890 E GoLog   : [0816/081003.575374:ERROR:elf_dynamic_array_reader.h(61)] tag not found
08-16 08:10:03.594 15668 16867 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x31f000001b9 in tid 16867 (Thread-24), pid 15668 (elzero.bravedns)
08-16 08:10:03.736  2152  2152 E ndroid.systemu: Invalid ID 0x00000000.
08-16 08:10:03.797 23937 23937 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
08-16 08:10:03.800  1259  1259 I /system/bin/tombstoned: received crash request for pid 16867
08-16 08:10:03.802 23937 23937 I crash_dump64: performing dump of process 15668 (target tid = 16867)
08-16 08:10:03.809 23937 23937 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-16 08:10:03.809 23937 23937 F DEBUG   : Build fingerprint: 'OnePlus/OnePlus6/OnePlus6:10/QKQ1.190716.003/2005052051:user/release-keys'
08-16 08:10:03.809 23937 23937 F DEBUG   : Revision: '0'
08-16 08:10:03.809 23937 23937 F DEBUG   : ABI: 'arm64'
08-16 08:10:03.809 23937 23937 F DEBUG   : Timestamp: 2020-08-16 08:10:03+0530
08-16 08:10:03.809 23937 23937 F DEBUG   : pid: 15668, tid: 16867, name: Thread-24  >>> com.celzero.bravedns <<<
08-16 08:10:03.809 23937 23937 F DEBUG   : uid: 10421
08-16 08:10:03.809 23937 23937 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x31f000001b9
08-16 08:10:03.809 23937 23937 F DEBUG   :     x0  0000006f1a6ea600  x1  0000000000000000  x2  00000040004bfea0  x3  0000000000000003
08-16 08:10:03.809 23937 23937 F DEBUG   :     x4  0000000000000160  x5  0000004000297e90  x6  000000700c853000  x7  0000000000f421c2
08-16 08:10:03.809 23937 23937 F DEBUG   :     x8  0000006f1a7aac14  x9  000000000000000c  x10 0000000000000002  x11 0000000000000030
08-16 08:10:03.809 23937 23937 F DEBUG   :     x12 0000000000a56b80  x13 00000003e8000000  x14 00044460ac096168  x15 0000a507849446f3
08-16 08:10:03.809 23937 23937 F DEBUG   :     x16 000000700870f8f0  x17 0000007008701070  x18 0000006ec0bea000  x19 0000006f1a6ea600
08-16 08:10:03.809 23937 23937 F DEBUG   :     x20 0000031f000001a4  x21 0000006f27239aa0  x22 0000006f27239ab0  x23 0000006f1a7aaa00
08-16 08:10:03.809 23937 23937 F DEBUG   :     x24 0000006f27239aa0  x25 0000006f26d1d394  x26 0000000000000000  x27 0000000000000010
08-16 08:10:03.809 23937 23937 F DEBUG   :     x28 0000004000182900  x29 0000006ec2837b90
08-16 08:10:03.809 23937 23937 F DEBUG   :     sp  0000006ec2837b70  lr  0000006f26d16418  pc  0000006f26d197b4
08-16 08:10:03.809 23937 23937 F DEBUG   :
08-16 08:10:03.809 23937 23937 F DEBUG   : backtrace:
08-16 08:10:03.809 23937 23937 F DEBUG   :       #00 pc 00000000005d47b4  /data/app/com.celzero.bravedns-S0OlU-rPT9myMvnoLKv6fQ==/base.apk (offset 0xb000) (tcp_process_refused_data+32)

No. 2

08-16 02:55:23.658 19089 19580 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d80003e7e0000 in tid 19580 (Thread-24), pid 19089 (elzero.bravedns)
08-16 02:55:24.004  4726  4726 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-16 02:55:24.004  4726  4726 F DEBUG   : Build fingerprint: 'OnePlus/OnePlus6/OnePlus6:10/QKQ1.190716.003/2005052051:user/release-keys'
08-16 02:55:24.004  4726  4726 F DEBUG   : Revision: '0'
08-16 02:55:24.004  4726  4726 F DEBUG   : ABI: 'arm64'
08-16 02:55:24.004  4726  4726 F DEBUG   : Timestamp: 2020-08-16 02:55:24+0530
08-16 02:55:24.005  4726  4726 F DEBUG   : pid: 19089, tid: 19580, name: Thread-24  >>> com.celzero.bravedns <<<
08-16 02:55:24.005  4726  4726 F DEBUG   : uid: 10419
08-16 02:55:24.005  4726  4726 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d80003e7e0000
08-16 02:55:24.005  4726  4726 F DEBUG   :     x0  0000004000410000  x1  0000006f080e9e30  x2  000000400040fab0  x3  0000004000183980
08-16 02:55:24.005  4726  4726 F DEBUG   :     x4  0000000000000550  x5  0000004000293a10  x6  0000000000000001  x7  3e6d80003e7e0000
08-16 02:55:24.005  4726  4726 F DEBUG   :     x8  3e6d80003e7e0000  x9  000000400040fb38  x10 0000000000000001  x11 0000000000000000
08-16 02:55:24.005  4726  4726 F DEBUG   :     x12 0000000000000001  x13 0000006f753b49f0  x14 0000000000000000  x15 0000006f08185352
08-16 02:55:24.005  4726  4726 F DEBUG   :     x16 0000000000000028  x17 00000070087018b8  x18 0000006f068e6000  x19 000000400040fb38
08-16 02:55:24.005  4726  4726 F DEBUG   :     x20 0000004000410000  x21 000000400040fe68  x22 3e6d80003e7e0000  x23 0000000000000000
08-16 02:55:24.005  4726  4726 F DEBUG   :     x24 ffffffffff01ef34  x25 ffffffffdd15b299  x26 0000006f753b4a78  x27 0000000000000010
08-16 02:55:24.005  4726  4726 F DEBUG   :     x28 0000004000183980  x29 0000006f753b49e0
08-16 02:55:24.005  4726  4726 F DEBUG   :     sp  0000006f753b49c0  lr  0000006f080e9e48  pc  0000006f080e9e50
08-16 02:55:24.005  4726  4726 F DEBUG   :
08-16 02:55:24.005  4726  4726 F DEBUG   : backtrace:
08-16 02:55:24.005  4726  4726 F DEBUG   :       #00 pc 00000000005e3e50  /data/app/com.celzero.bravedns-5afKeEOsjeGWhPeagQnD6Q==/base.apk (offset 0x218000) (_cgo_00fc4845cc21_Cfunc_get_conn_key_val+32)

See #19 #26

Firewall may be shouldn't block all TCP and UDP conns

The firewall mode shouldn't block localhost TCP and UDP.

May be it also shouldn't block connections on the private IPv4 (v6 isn't supported) space? May be it should.

Interestingly, some folks want to block all LAN traffic. So, that should be an option too?

Discuss.

Implement "block domain" action in the DNS logs view

This is very pi-hole-esque feature request. May or may not be in-line with PlayStore's terms of use.

Basically, add a block / unblock action next to every DNS log entry; and build a local blocklist that way. This feature might be confusing, since a user can't really "unblock" a domain blocked by AdGuard DNS, for example.

  1. #279
  2. #208

ANR in ScreenLockService

anr_2020-08-14-00-46-01-940.txt

08-14 00:46:01.835  1202  1411 W ActivityManager: Timeout executing service: ServiceRecord{f4bea7d u0 com.celzero.bravedns/.receiver.ScreenLockService}

From ANR report:

  1. The ANR happens when ScreenLockService tries to GoVpnAdapter#close but couldn't get the lock (the method is synchronized on the instance object:
"main" prio=5 tid=1 Blocked
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x72f59a78 self=0x700b406c00
  | sysTid=17118 nice=0 cgrp=default sched=0/0 handle=0x700c974ed0
  | state=S schedstat=( 22272983905 2779119802 17008 ) utm=2004 stm=223 core=6 HZ=100
  | stack=0x7ffd049000-0x7ffd04b000 stackSize=8192KB
  | held mutexes=
  at com.celzero.bravedns.net.go.GoVpnAdapter.close(GoVpnAdapter.java:-1)
  - waiting to lock <0x056e5b6f> (a com.celzero.bravedns.net.go.GoVpnAdapter) held by thread 46
  at com.celzero.bravedns.service.BraveVPNService.restartVpn(BraveVPNService.kt:511)
  - locked <0x06b2f07c> (a com.celzero.bravedns.service.VpnController)
  at com.celzero.bravedns.service.BraveVPNService.blockTraffic(BraveVPNService.kt:90)
  at com.celzero.bravedns.receiver.ScreenLockService.checkLock(ScreenLockService.kt:69)
  at com.celzero.bravedns.receiver.ScreenLockService.onStartCommand(ScreenLockService.kt:32)
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4204)
  at android.app.ActivityThread.access$2100(ActivityThread.java:231)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1984)
  at android.os.Handler.dispatchMessage(Handler.java:107)
  at android.os.Looper.loop(Looper.java:214)
  at android.app.ActivityThread.main(ActivityThread.java:7682)
  at java.lang.reflect.Method.invoke(Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
  1. But the lock is held by tid 46 stuck at GoVpnAdapter#updateDohUrl -> Tun2Socks#newDoHTransport run in response to NETWORK_CONNECTED broadcast:
"startVpn-onNetworkConnected" prio=5 tid=46 Native
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x12f4f118 self=0x700b58a000
  | sysTid=19256 nice=0 cgrp=default sched=0/0 handle=0x6f26af9d50
  | state=S schedstat=( 748333 2309063 5 ) utm=0 stm=0 core=6 HZ=100
  | stack=0x6f269f7000-0x6f269f9000 stackSize=1039KB
  | held mutexes=
  kernel: (couldn't read /proc/self/task/19256/stack)
  native: #00 pc 00000000002ae47c  /data/app/com.celzero.bravedns-u5kHoa7fG6gUWrYWidCctA==/base.apk (offset 1f3000) (???)
  at tun2socks.Tun2socks.newDoHTransport(Native method)
  at com.celzero.bravedns.net.go.GoVpnAdapter.makeDohTransport(GoVpnAdapter.java:220)
  at com.celzero.bravedns.net.go.GoVpnAdapter.updateDohUrl(GoVpnAdapter.java:255)
  - locked <0x056e5b6f> (a com.celzero.bravedns.net.go.GoVpnAdapter)
  at com.celzero.bravedns.service.BraveVPNService.updateServerConnection(BraveVPNService.kt:364)
  at com.celzero.bravedns.service.BraveVPNService.access$updateServerConnection(BraveVPNService.kt:55)
  at com.celzero.bravedns.service.BraveVPNService$onNetworkConnected$1.run(BraveVPNService.kt:541)
  at java.lang.Thread.run(Thread.java:919)

One probable solution (a workaround really) is to use a android.os.Handler to deal with communication happen from a service-thread aloof from BraveVPNService, like in androidxref.com/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java.

User feedback: IP and Port blocklists

Blacklist IP addresses (ranges) and ports (ranges).

  1. Let users block IPs and Ports they see in the Network Monitor screen.

  2. Provide a dedicated interface to choose IPs and Ports and show the existing rules, too, in addition to it.

  3. Consequently, an IPs and Ports whitelist is also required. This will be fun.

Also see: #38 #13 #39

Network Monitor

Like the DNS log screen, there needs to be an indicator of how many apps are blocked, connections blocked, and so on in the main configure firewall screen. Also, may be, arrange the list to keep blocked apps at the top, and the rest at the bottom (See: Glasswire)?

#42

User feedback: Whitelists for Universal Firewall

User's want a whitelist feature for universal firewall, that is, they want to exclude certain apps from it. A decent ask. Requires a UI change, probably, even moving the Universal Firewall to its own window, separate from the current lone "Firewall" window.

Crash: fdsan complains of a use-after-free / double-free PracelFileDescriptor

Device was connected to WiFi without internet connectivity when this happened:

tombstone_05.txt
logcat.txt (enc)

08-14 00:48:32.879 20806 20806 F DEBUG   : * * * * * * * * * * * * * * * *
08-14 00:48:32.879 20806 20806 F DEBUG   : Build fingerprint: 'OnePlus/OnePlus6/OnePlus6:10/QKQ1.190716.003/2005052051:user/release-keys'
08-14 00:48:32.879 20806 20806 F DEBUG   : Revision: '0'
08-14 00:48:32.879 20806 20806 F DEBUG   : ABI: 'arm64'
08-14 00:48:32.879 20806 20806 F DEBUG   : Timestamp: 2020-08-14 00:48:32+0530
08-14 00:48:32.879 20806 20806 F DEBUG   : pid: 20422, tid: 20794, name: magnifier pixel  >>> com.celzero.bravedns <<<
08-14 00:48:32.879 20806 20806 F DEBUG   : uid: 10417
08-14 00:48:32.879 20806 20806 F DEBUG   : signal 35 (<debuggerd signal>), code -1 (SI_QUEUE), fault addr --------
08-14 00:48:32.879 20806 20806 F DEBUG   : Abort message: 'failed to exchange ownership of file descriptor: fd 66 is owned by ParcelFileDescriptor 0x2543d17, was expected to be unowned'
08-14 00:48:32.879 20806 20806 F DEBUG   :     x0  0000000000000000  x1  000000000000513a  x2  0000000000000023  x3  0000006f2725ea90
08-14 00:48:32.879 20806 20806 F DEBUG   :     x4  786520736177202c  x5  786520736177202c  x6  786520736177202c  x7  7420646574636570
08-14 00:48:32.879 20806 20806 F DEBUG   :     x8  00000000000000f0  x9  9d11563a70905f72  x10 0000000000000000  x11 000000700863a1ef
08-14 00:48:32.879 20806 20806 F DEBUG   :     x12 6562206f74206465  x13 64656e776f6e7520  x14 0000006f2725e657  x15 0000000000000000
08-14 00:48:32.879 20806 20806 F DEBUG   :     x16 000000700870f8c0  x17 00000070086eb900  x18 0000006ece35a000  x19 0000000000004fc6
08-14 00:48:32.879 20806 20806 F DEBUG   :     x20 000000000000513a  x21 0000006f27260020  x22 000000700c9648f4  x23 0000000000000001
08-14 00:48:32.879 20806 20806 F DEBUG   :     x24 0000006f2725e880  x25 0000006f2725e800  x26 0000006f2725e7c0  x27 0000000000000000
08-14 00:48:32.879 20806 20806 F DEBUG   :     x28 0000000000000000  x29 0000006f2725eb70
08-14 00:48:32.879 20806 20806 F DEBUG   :     sp  0000006f2725e740  lr  00000070086a06d8  pc  00000070086a06f8

Android's fdsan documentation says this could be due to a double-free (ParcelFileDescriptor#close called twice or more) or use-after-free (PraceFileDescriptor was closed yet used elsewhere) bug.

Low battery mode

Currently, the battery consumption is uber high. Power consumption hasn't been analyzed but it highly likely it is due to all the traffic filtering that occurs in the name of Firewall and the full-tunnel VPN in-use (routing 0.0.0.0).

Split-tunnel DNS:

If the user needs just the DNS (without firewall), probably it is best to add only port 53 (split-tunnel) to the routes when vpn-service is built / started / re-started. This might be a preferable default, too?

VPN Blackhole:

If the user just needs Firewall (without connection tracking #3 and #16 and DNS), VPN could be run as a blackhole (without creating a forwarding tunnel) wherein all incoming packets from allowed apps end up going exactly no where.

App Kill:

Kill apps that are firewalled. The connections from the app are blocked anyway and so if those apps aren't in the foreground they only end up draining extra power by retrying repeatedly to connect.

The UI might be tricky to get right, I am thinking, probably a user preference in the DNS and Firewall screen to enable low battery mode, with a prompt on the homescreen with a clickable chip to enable it (when device battery is low).

User feedback: Custom blocklists on-device

This goes against Google Play Store policies so might need two versions if we implement this.

Blokada does this quite successfully: a lite version for the play store and a full version on f-droid.

This likely involves syncing lists from remote, making sure memory usage is kept under control (some lists have a million or more entries), showing related statistics (which lists blocked an endpoint, which lists are more effective), and offering counter actions (whitelists).

A lot of work.

Firewall and System Apps

We left out system apps because they end up causing more confusion (there are too many and some even critical), but that has meant leaving out other pre-installed apps too.

Users want to firewall those pre-installed System Apps predominantly because they can't be uninstalled (in some cases, can't even be disabled). Probably show as a separate category? Or, show only when a specific UI is toggled to view System Apps (like in NetGuard)?

Feedback on Connect/Disconnect button on the homescreen

the connect / disconnect on the home-screen is confusing given the not-so-aptly worded toast message shown ("Firewall mode is not enabled" / "DNS mode is not enabled") when in "disconnected" state to the the user when they click on "Configure firewall" or "View logs".

Find a way to be consistent about it.

Also, some find "Disconnect / Connect" misleading since there's no real "connection" to anything anywhere, at least in the traditional VPN sense.

ScreenLockService stop self

ScreenLockService responsible for enforcing universal-firewall rule "block all apps on device locked" is started in response to ACTION_SCREEN_OFF broadcast and never goes away after that:

08-16 01:45:34.834  1202  1411 W ActivityManager: Stopping service due to app idle: u0a419 -53m32s838ms com.celzero.bravedns/.receiver.ScreenLockService

stopSelf the service once ScreenLockService is done setting the universal firewall rule.

A BroadcastReciever listening on ACTION_USER_PRESENT_BROADCAST undoes any universal firewall rules ScreenLockService might have set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.