From 4ebdf585ef61495b559615c45dbc5805a573ad39 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Mon, 21 Dec 2020 00:59:20 +0100 Subject: [PATCH] Adding meaningful feedback when host keys don't match / aren't found --- README.md | 2 +- src/rmview/rmview.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d57d4d3..89140c0 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Connection parameters are provided as a dictionary with the following keys (all An update to the reMarkable tablet would change its "fingerprint" i.e. the identifier that signals we are connecting to the expected device (and not somebody impersonating it). When this happens you may get an error message upon connection. There are two main ways to fix this: - 1. Change your `.known_hosts` file to match the new fingerprint (you can get instructions by connecting manually via ssh). + 1. Change your `~/.ssh/known_hosts` file to match the new fingerprint (you can get instructions by connecting manually via ssh). 2. Set the `insecure_auto_add_host` setting to `true`, which will make rmview ignore the check. This is not recommended unless you are in a trusted network. diff --git a/src/rmview/rmview.py b/src/rmview/rmview.py index 7f53373..34ee04b 100644 --- a/src/rmview/rmview.py +++ b/src/rmview/rmview.py @@ -7,6 +7,8 @@ from .workers import FrameBufferWorker, PointerWorker from .connection import rMConnect from .viewer import QtImageViewer +from paramiko import BadHostKeyException, SSHException + from .rmparams import * import sys @@ -335,7 +337,39 @@ class rMViewApp(QApplication): icon = QPixmap(":/assets/dead.svg") icon.setDevicePixelRatio(self.devicePixelRatio()) mbox.setIconPixmap(icon) - mbox.setInformativeText("I could not connect to the reMarkable at %s:\n%s." % (self.config.get('ssh').get('address'), e)) + if isinstance(e, BadHostKeyException): + mbox.setDetailedText(str(e)) + mbox.setInformativeText( + "The host at %s has the wrong key.
" + "This usually happens just after a software update on the tablet.


" + "You have three options to fix this problem:" + "
  1. " + "Change your ~/.ssh/known_hosts file to match the new fingerprint.
    " + "The easiest way to do this is connecting manually via ssh and follow the instructions." + "
  2. " + "Set \"insecure_auto_add_host\": true to rmView\'s settings.
    " + "This is not recommended unless you are in a trusted network." + "
  3. " + "Connect using username/password." + "
    1. " % (self.config.get('ssh').get('address')) + ) + elif isinstance(e, SSHException) and str(e).endswith('known_hosts'): + mbox.setInformativeText( + "The host at %s is unknown.
      " + "This usually happens if this is the first time you use ssh with your tablet.


      " + "You have three options to fix this problem:" + "
      1. " + "Change your ~/.ssh/known_hosts file to match the new fingerprint.
        " + "The easiest way to do this is connecting manually via ssh and follow the instructions." + "
      2. " + "Set \"insecure_auto_add_host\": true to rmView\'s settings.
        " + "This is not recommended unless you are in a trusted network." + "
      3. " + "Connect using username/password." + "
        1. " % (self.config.get('ssh').get('address')) + ) + else: + mbox.setInformativeText("I could not connect to the reMarkable at %s:\n%s." % (self.config.get('ssh').get('address'), e)) mbox.addButton(QMessageBox.Cancel) if self.config_file: mbox.addButton("Settings...", QMessageBox.ResetRole)