mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
ssh: Add the error of ssh-keyscan to the verification view
This commit takes the stderr of `ssh-keyscan` (in case of a returncode thats not zero) and stores it as as string in the form object. The view then displays the information as preformatted text in a warning class. Signed-off-by: Birger Schacht <birger@rantanplan.org> [sunil: Cosmetic: variable name change for consistent naming] [sunil: <pre> can't be inside <p>, keep it out] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
25bcee6488
commit
7eb6d23e83
@ -233,8 +233,8 @@ class VerifySshHostkeyForm(forms.Form):
|
|||||||
"""Initialize the form with selectable apps."""
|
"""Initialize the form with selectable apps."""
|
||||||
hostname = kwargs.pop('hostname')
|
hostname = kwargs.pop('hostname')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['ssh_public_key'].choices = self._get_all_public_keys(
|
(self.fields['ssh_public_key'].choices,
|
||||||
hostname)
|
self.keyscan_error) = self._get_all_public_keys(hostname)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_all_public_keys(hostname):
|
def _get_all_public_keys(hostname):
|
||||||
@ -242,11 +242,12 @@ class VerifySshHostkeyForm(forms.Form):
|
|||||||
# Fetch public keys of ssh remote
|
# Fetch public keys of ssh remote
|
||||||
keyscan = subprocess.run(['ssh-keyscan', hostname],
|
keyscan = subprocess.run(['ssh-keyscan', hostname],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL)
|
stderr=subprocess.PIPE)
|
||||||
keys = keyscan.stdout.decode().splitlines()
|
keys = keyscan.stdout.decode().splitlines()
|
||||||
|
error_message = keyscan.stderr.decode() if keyscan.returncode else None
|
||||||
# Generate user-friendly fingerprints of public keys
|
# Generate user-friendly fingerprints of public keys
|
||||||
keygen = subprocess.run(['ssh-keygen', '-l', '-f', '-'],
|
keygen = subprocess.run(['ssh-keygen', '-l', '-f', '-'],
|
||||||
input=keyscan.stdout, stdout=subprocess.PIPE)
|
input=keyscan.stdout, stdout=subprocess.PIPE)
|
||||||
fingerprints = keygen.stdout.decode().splitlines()
|
fingerprints = keygen.stdout.decode().splitlines()
|
||||||
|
|
||||||
return zip(keys, fingerprints)
|
return zip(keys, fingerprints), error_message
|
||||||
|
|||||||
@ -35,6 +35,9 @@
|
|||||||
is up and accepting connections.
|
is up and accepting connections.
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</p>
|
</p>
|
||||||
|
{% if form.keyscan_error %}
|
||||||
|
<pre class="alert alert-danger">{{ form.keyscan_error }}</pre>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
The authenticity of SSH host {{ hostname }} could not be established. The host advertises the following SSH public keys. Please verify any one of them.
|
The authenticity of SSH host {{ hostname }} could not be established. The host advertises the following SSH public keys. Please verify any one of them.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user