Fix Galaxy local pairing with a new password

This commit is contained in:
firestar5683
2026-11-23 22:59:05 -06:00
parent 19b7edf344
commit 241e0a43d4
6 changed files with 49 additions and 13 deletions
+6 -3
View File
@@ -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)
+2 -6
View File
@@ -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
@@ -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()
@@ -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)
@@ -108,10 +108,9 @@ export const RemoteAccess = {
<div class="gx-actions"><button type="button" class="gx-btn gx-btn--danger" @click="unpair">{{ busy ? 'Disconnecting…' : 'Turn off remote access' }}</button></div>
</template>
<template v-else>
<p v-if="legacyPassword">Enter your existing password to keep your Galaxy link.</p>
<p v-else-if="legacyPairingAvailable">Enter your old password to keep the link, or choose a new one with at least 8 characters.</p>
<p v-if="legacyPassword || legacyPairingAvailable">Use your old password or choose a new one with at least 8 characters.</p>
<p v-else>Choose a password to pair your comma.</p>
<div class="gx-actions"><input class="gx-field gx-filter-field" type="password" v-model="password" :minlength="legacyPassword || legacyPairingAvailable ? 6 : 8" maxlength="255" :autocomplete="legacyPassword ? 'current-password' : 'new-password'" :placeholder="legacyPassword ? 'Existing Galaxy password' : legacyPairingAvailable ? 'Existing or new Galaxy password' : 'New password (at least 8 characters)'" @keydown.enter="pair" />
<div class="gx-actions"><input class="gx-field gx-filter-field" type="password" v-model="password" :minlength="legacyPassword || legacyPairingAvailable ? 6 : 8" maxlength="255" autocomplete="new-password" :placeholder="legacyPassword || legacyPairingAvailable ? 'Existing or new Galaxy password' : 'New password (at least 8 characters)'" @keydown.enter="pair" />
<button type="button" class="gx-btn" :disabled="password.trim().length < (legacyPassword || legacyPairingAvailable ? 6 : 8)" @click="pair">{{ busy ? 'Setting up…' : 'Set up remote access' }}</button></div>
</template>
<GxNotice tone="danger" v-if="error">{{ error }}</GxNotice>
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "393da7238e62ed6d8275b342a46f696919c449d905614b1d9a29c79a15467e70", "schema_version": 1}
{"protected_inventory_sha256": "45a9758818ebc2cf0646d74f88315abccfeb85302054216b3eef874bb2a34807", "schema_version": 1}