Closed Bug 2078515 Opened 1 month ago Closed 1 month ago

Captive portal service should not run on Android

Categories

(Core :: Networking, defect, P1)

defect

Tracking

()

RESOLVED FIXED
160 Branch
Tracking Status
firefox160 --- fixed

People

(Reporter: valentin, Assigned: valentin)

References

Details

(Whiteboard: [necko-triaged][necko-priority-next])

Attachments

(3 external files)

The intention was for the captive portal service not to run on Android at all.
However, due to some missing pref checks in mozilla::net::CaptivePortalService::RecheckCaptivePortal these still trigger a check, even if the result is not used for anything.

No longer blocks: 2036862
Blocks: 2036862
  • Moved prefs to StaticPrefList
  • Checked pref in all CPS methods
  • Added test that recheckCaptivePortal does not trigger a check when pref is off

How to simulate a captive portal with the Android emulator:

  1. Run a fake portal on the host

  The emulator reaches the host at 10.0.2.2.

  #!/usr/bin/env python3
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

  unlocked = False

  class Portal(BaseHTTPRequestHandler):
      def reply(self, code, body=b"", headers=()):
          self.send_response(code)
          for k, v in headers:
              self.send_header(k, v)
          self.send_header("Content-Length", str(len(body)))
          self.end_headers()
          self.wfile.write(body)
      
      def do_GET(self):
          global unlocked
          if self.path.startswith("/generate_204"):
              if unlocked:
                  self.reply(204)
              else:
                  self.reply(302, headers=[("Location", "http://10.0.2.2:8000/login")])
          elif self.path.startswith("/login"):
              self.reply(200, b"<form method=post action=/login><button>Log in</button></form>",
                         [("Content-Type", "text/html")])
          elif self.path.startswith("/lock"):
              unlocked = False
              self.reply(200, b"locked\n")
          else:
              self.reply(404)

      def do_POST(self):
          global unlocked
          unlocked = True
          self.reply(200, b"Logged in", [("Content-Type", "text/html")])

  ThreadingHTTPServer(("0.0.0.0", 8000), Portal).serve_forever()

  2. Point Android's probe at it

  adb shell settings put global captive_portal_http_url http://10.0.2.2:8000/generate_204
  adb shell settings put global captive_portal_use_https 0   # only use the HTTP probe
  adb shell settings put global captive_portal_mode 1        # show the sign-in prompt

  Turning off the HTTPS probe matters. Otherwise Android also probes Google over HTTPS, which succeeds and can mark the network as validated, or as having partial connectivity, instead of captive.

  3. Pick which case to test

  - Wi-Fi is the only network (your "should say captive" case): run adb shell svc data disable.
  - Mobile data stays the default: leave data on. Gecko should then report NOT_CAPTIVE.

  4. Run through it

  1. Start Fenix or the GeckoView example app.
  2. Reconnect Wi-Fi so Android probes again: adb shell svc wifi disable && adb shell svc wifi enable. You should get a "Sign in to Wi-Fi network" notification, and Gecko should go to LOCKED_PORTAL.
  3. Tap the notification and press Log in. The OS login screen probes again, gets the 204, and closes. Android marks the network VALIDATED and Gecko should go to UNLOCKED_PORTAL. The app is in the background at this point, which is the case the always-registered callback is for.
  4. To lock it again: curl http://localhost:8000/lock, then reconnect Wi-Fi.

  Only Android's probe is faked. Real traffic, including Gecko's, isn't blocked at any point.

You can also read the state directly from the main-process console in about:debugging:

  Cc["@mozilla.org/network/captive-portal-service;1"].getService(Ci.nsICaptivePortalService).state

On Android we do not want to perform the captive portal checks ourselves, since
the OS does that for us. However, knowing when we are in a captive portal is a useful
piece of information.
This patch adds a network callback and checks when the default network is in a captive portal,
or when it leaves a captive portal.
Android might still use Mobile Data while logging into the captive portal, but we don't care
about that use case, since Firefox will always use the default network. The only time we will
notice there is a captive portal is when the only/default network has an active captive portal.

Tested manually using instructions in bug 2078515 comment 3

Status: NEW → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 160 Branch
QA Whiteboard: [qa-triage-done-c161/b160]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: