mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
ssh: Don't fail on page load when SSH host key can't be read
Closes: #2575. Tests: - 'touch /etc/ssh/ssh_host_dsa_key.pub'. Try to load the SSH app page. It fails. With the patch, it succeeds. A warning message is printed about failing to read the key with proper returncode, stdout, and stderr. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
0ab9be2ae0
commit
485391620b
@ -1,6 +1,7 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""FreedomBox app for OpenSSH server."""
|
"""FreedomBox app for OpenSSH server."""
|
||||||
|
|
||||||
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -18,6 +19,8 @@ from plinth.package import Packages
|
|||||||
|
|
||||||
from . import manifest, privileged
|
from . import manifest, privileged
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_description = [
|
_description = [
|
||||||
_('A Secure Shell server uses the secure shell protocol to accept '
|
_('A Secure Shell server uses the secure shell protocol to accept '
|
||||||
'connections from remote computers. An authorized remote computer '
|
'connections from remote computers. An authorized remote computer '
|
||||||
@ -101,13 +104,21 @@ def get_host_keys():
|
|||||||
r'.+ \((?P<algorithm>\w+)\)$')
|
r'.+ \((?P<algorithm>\w+)\)$')
|
||||||
|
|
||||||
for public_key in etc_ssh.glob('*.pub'):
|
for public_key in etc_ssh.glob('*.pub'):
|
||||||
process = subprocess.run(['ssh-keygen', '-l', '-f',
|
try:
|
||||||
str(public_key)], stdout=subprocess.PIPE,
|
process = subprocess.run(
|
||||||
check=True)
|
['ssh-keygen', '-l', '-f',
|
||||||
output = process.stdout.decode().strip()
|
str(public_key)], stdout=subprocess.PIPE,
|
||||||
if output:
|
stderr=subprocess.PIPE, check=True)
|
||||||
match = re.match(pattern, output)
|
output = process.stdout.decode().strip()
|
||||||
if match:
|
if output:
|
||||||
host_keys.append(match.groupdict())
|
match = re.match(pattern, output)
|
||||||
|
if match:
|
||||||
|
host_keys.append(match.groupdict())
|
||||||
|
except subprocess.CalledProcessError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Unable to read SSH host public key file: %s, '
|
||||||
|
'returncode=%s, stdout=%s, stderr=%s', public_key,
|
||||||
|
exception.returncode, exception.stdout.decode(),
|
||||||
|
exception.stderr.decode())
|
||||||
|
|
||||||
return host_keys
|
return host_keys
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user