Handle no U2F device available (#3648)

This commit is contained in:
Daniel Girtler 2025-07-15 17:35:54 +10:00 committed by GitHub
parent 47f4e63006
commit 231530d5f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 12 deletions

View File

@ -35,20 +35,13 @@ class AuthenticationMenu(AbstractSubMenu[AuthenticationConfiguration]):
return [ return [
MenuItem( MenuItem(
text=tr('U2F login setup'), text=tr('U2F login setup'),
action=setup_u2f_login, action=select_u2f_login,
value=self._auth_config.u2f_config, value=self._auth_config.u2f_config,
preview_action=self._prev_u2f_login, preview_action=self._prev_u2f_login,
dependencies=[self._depends_on_u2f],
key='u2f_config', key='u2f_config',
), ),
] ]
def _depends_on_u2f(self) -> bool:
devices = Fido2.get_fido2_devices()
if not devices:
return False
return True
def _prev_u2f_login(self, item: MenuItem) -> str | None: def _prev_u2f_login(self, item: MenuItem) -> str | None:
if item.value is not None: if item.value is not None:
u2f_config: U2FLoginConfiguration = item.value u2f_config: U2FLoginConfiguration = item.value
@ -60,10 +53,19 @@ class AuthenticationMenu(AbstractSubMenu[AuthenticationConfiguration]):
output += tr('Passwordless sudo: ') + (tr('Enabled') if u2f_config.passwordless_sudo else tr('Disabled')) output += tr('Passwordless sudo: ') + (tr('Enabled') if u2f_config.passwordless_sudo else tr('Disabled'))
return output return output
devices = Fido2.get_fido2_devices()
if not devices:
return tr('No U2F devices found')
return None return None
def setup_u2f_login(preset: U2FLoginConfiguration) -> U2FLoginConfiguration | None: def select_u2f_login(preset: U2FLoginConfiguration) -> U2FLoginConfiguration | None:
devices = Fido2.get_fido2_devices()
if not devices:
return None
items = [] items = []
for method in U2FLoginMethod: for method in U2FLoginMethod:
items.append(MenuItem(method.display_value(), value=method)) items.append(MenuItem(method.display_value(), value=method))

View File

@ -36,7 +36,10 @@ class Fido2:
fido_devices = clear_vt100_escape_codes_from_str(ret) fido_devices = clear_vt100_escape_codes_from_str(ret)
for line in fido_devices.split('\r\n'): if not fido_devices:
return []
for line in fido_devices.splitlines():
path, details = line.replace(',', '').split(':', maxsplit=1) path, details = line.replace(',', '').split(':', maxsplit=1)
_, product, manufacturer = details.strip().split(' ', maxsplit=2) _, product, manufacturer = details.strip().split(' ', maxsplit=2)

View File

@ -1507,7 +1507,7 @@ class Installer:
parent_dev_path = device_handler.get_parent_device_path(boot_partition.safe_dev_path) parent_dev_path = device_handler.get_parent_device_path(boot_partition.safe_dev_path)
cmd_template = [ cmd_template = (
'efibootmgr', 'efibootmgr',
'--create', '--create',
'--disk', '--disk',
@ -1521,7 +1521,7 @@ class Installer:
'--unicode', '--unicode',
*cmdline, *cmdline,
'--verbose', '--verbose',
] )
for kernel in self.kernels: for kernel in self.kernels:
# Setup the firmware entry # Setup the firmware entry