From 241e0a43d49611d0f8306ced905c8d372cd3b52d Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:59:05 -0600 Subject: [PATCH] Fix Galaxy local pairing with a new password --- openpilot/starpilot/galaxy/access.py | 9 +++-- openpilot/starpilot/galaxy/server.py | 8 ++--- .../galaxy/tests/test_galaxy_access.mjs | 2 ++ .../galaxy/tests/test_remote_pairing.py | 36 +++++++++++++++++++ .../starpilot/galaxy/web/js/remote-access.js | 5 ++- prebuilt.json | 2 +- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/openpilot/starpilot/galaxy/access.py b/openpilot/starpilot/galaxy/access.py index c277393c0b..dc3648afb4 100644 --- a/openpilot/starpilot/galaxy/access.py +++ b/openpilot/starpilot/galaxy/access.py @@ -177,10 +177,13 @@ class GalaxyAccessOwner: def replace_for_pairing(self, password: str, parked: Callable[[], bool]) -> bool: """Set a new remote login password from an authorized, parked local pairing flow.""" - if not 8 <= len(password) <= 255 or not parked() or self.status().status != AccessStatus.CONFIGURED_LOCAL: + if not 8 <= len(password) <= 255 or not parked(): return False - generation = self.current_generation() - if generation is None: + status = self.status().status + if status not in (AccessStatus.CONFIGURED_LOCAL, AccessStatus.LEGACY_IMPORT_AVAILABLE): + return False + generation = self.current_generation() if status == AccessStatus.CONFIGURED_LOCAL else None + if status == AccessStatus.CONFIGURED_LOCAL and generation is None: return False try: return self._write(password, parked, replace_generation=generation) diff --git a/openpilot/starpilot/galaxy/server.py b/openpilot/starpilot/galaxy/server.py index 7034c58783..eee9fa374d 100644 --- a/openpilot/starpilot/galaxy/server.py +++ b/openpilot/starpilot/galaxy/server.py @@ -2194,7 +2194,7 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe except (OSError, ValueError, UnicodeError): self.json(503, {'error': 'Remote password storage is unavailable'}) return - legacy_root = access.legacy_root if status == AccessStatus.LEGACY_IMPORT_AVAILABLE else None + legacy_root = None if status == AccessStatus.UNCONFIGURED: if len(password) < 8: self.json(400, {'error': 'New Galaxy passwords must be at least 8 characters'}) @@ -2202,11 +2202,7 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe if not access.configure(password, parked): self.json(503, {'error': 'Could not configure remote password'}) return - elif status == AccessStatus.LEGACY_IMPORT_AVAILABLE: - if not access.import_legacy(password, parked): - self.json(403, {'error': 'Galaxy password does not match existing pairing'}) - return - elif status == AccessStatus.CONFIGURED_LOCAL: + elif status in (AccessStatus.LEGACY_IMPORT_AVAILABLE, AccessStatus.CONFIGURED_LOCAL): if access.legacy_available() is None: self.json(503, {'error': 'Existing Galaxy pairing storage is unavailable'}) return diff --git a/openpilot/starpilot/galaxy/tests/test_galaxy_access.mjs b/openpilot/starpilot/galaxy/tests/test_galaxy_access.mjs index eda3c72bf1..3d6bf04d57 100644 --- a/openpilot/starpilot/galaxy/tests/test_galaxy_access.mjs +++ b/openpilot/starpilot/galaxy/tests/test_galaxy_access.mjs @@ -63,10 +63,12 @@ try { await nextTick() assert.match(text(host), /test key/) await remote.unpair() + remote.legacyPassword = true await nextTick() assert.equal(vm.url, '') assert.equal(remote.appKey, '') assert.equal(remote.keyVisible, false) + assert.match(text(host), /choose a new one with at least 8 characters/) remote.password = 'new-password' await remote.pair() await nextTick() diff --git a/openpilot/starpilot/galaxy/tests/test_remote_pairing.py b/openpilot/starpilot/galaxy/tests/test_remote_pairing.py index fa7d6056ce..97f367114d 100644 --- a/openpilot/starpilot/galaxy/tests/test_remote_pairing.py +++ b/openpilot/starpilot/galaxy/tests/test_remote_pairing.py @@ -436,6 +436,42 @@ class RemotePairingTest(unittest.TestCase): worker.join(timeout=2) server.server_close() + def test_direct_local_unpair_and_repair_with_new_password_without_a_local_verifier(self): + legacy = self.pairing.root.parent / 'legacy' + legacy.mkdir() + old_password = 'oldpw6' + slug = 'ExistingGalaxy01' + old_token = 'b' * 64 + (legacy / 'glxyauth').write_text(hashlib.sha256(old_password.encode()).hexdigest()) + (legacy / 'glxyslug').write_text(slug) + (legacy / 'glxysession').write_text(old_token) + self.owner.legacy_root = legacy + self.assertTrue(self.pairing.migrate_legacy(legacy)) + self.assertIsNone(self.owner.current_generation()) + origin = f'http://127.0.0.1:{self.local.server_port}' + cookie = self.request(self.local, '/api/auth/session')[2]['Set-Cookie'].split(';', 1)[0] + local = dict(method='POST', origin=origin, cookie=cookie) + pair = '/api/galaxy/pair' + new_password = {'password': 'different-password'} + self.assertEqual(self.request(self.local, pair, payload=new_password, **local)[0], 409) + self.assertEqual(self.request(self.local, '/api/galaxy/unpair', payload={}, **local)[0], 200) + self.assertEqual(self.request(self.local, pair, method='POST', origin=origin, payload=new_password)[0], 401) + self.assertEqual(self.request(self.local, pair, method='POST', origin='https://wrong.example', + cookie=cookie, payload=new_password)[0], 403) + with mock.patch('openpilot.starpilot.galaxy.server.direct_local_connection', return_value=False): + self.assertEqual(self.request(self.local, pair, payload=new_password, **local)[0], 403) + self.assertEqual(self.request(self.local, pair, payload={'password': 'other6'}, **local)[0], 400) + self.assertIsNone(self.owner.current_generation()) + code, body, _ = self.request(self.local, pair, payload=new_password, **local) + self.assertEqual(code, 200) + record = self.pairing.read() + assert record is not None + self.assertNotEqual(record['slug'], slug) + self.assertNotEqual(record['session'], old_token) + self.assertTrue(json.loads(body)['url'].endswith(record['slug'])) + self.assertTrue(self.owner.verify(new_password['password'])) + self.assertFalse(self.owner.verify(old_password)) + def test_existing_local_verifier_does_not_hide_matching_legacy_link(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory) diff --git a/openpilot/starpilot/galaxy/web/js/remote-access.js b/openpilot/starpilot/galaxy/web/js/remote-access.js index 47279d08aa..6899e21085 100644 --- a/openpilot/starpilot/galaxy/web/js/remote-access.js +++ b/openpilot/starpilot/galaxy/web/js/remote-access.js @@ -108,10 +108,9 @@ export const RemoteAccess = {
-Enter your existing password to keep your Galaxy link.
-Enter your old password to keep the link, or choose a new one with at least 8 characters.
+Use your old password or choose a new one with at least 8 characters.
Choose a password to pair your comma.
-