From e2c81c950f711243fc41446319194da4762d77c0 Mon Sep 17 00:00:00 2001 From: tomaae <23486452+tomaae@users.noreply.github.com> Date: Sun, 8 Dec 2019 09:57:28 +0100 Subject: [PATCH] added ssl_handshake_failure error for UI --- custom_components/mikrotik_router/.translations/en.json | 1 + custom_components/mikrotik_router/mikrotikapi.py | 6 +++++- custom_components/mikrotik_router/strings.json | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom_components/mikrotik_router/.translations/en.json b/custom_components/mikrotik_router/.translations/en.json index 3396511..d0d68fc 100644 --- a/custom_components/mikrotik_router/.translations/en.json +++ b/custom_components/mikrotik_router/.translations/en.json @@ -18,6 +18,7 @@ "error": { "name_exists": "Name already exists.", "cannot_connect": "Cannot connect to Mikrotik.", + "ssl_handshake_failure": "SSL handshake failure", "connection_timeout": "Mikrotik connection timeout.", "wrong_login": "Invalid user name or password." } diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index 2b3d76b..0be5a0e 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -75,7 +75,8 @@ class MikrotikAPI: librouteros.exceptions.MultiTrapError, librouteros.exceptions.ConnectionClosed, librouteros.exceptions.ProtocolError, - librouteros.exceptions.FatalError + librouteros.exceptions.FatalError, + ssl.SSLError ) as api_error: _LOGGER.error("Mikrotik %s: %s", self._host, api_error) self.error_to_strings("%s" % api_error) @@ -95,6 +96,9 @@ class MikrotikAPI: self.error = "cannot_connect" if error == "invalid user name or password (6)": self.error = "wrong_login" + + if "ALERT_HANDSHAKE_FAILURE" in error: + self.error = "ssl_handshake_failure" return diff --git a/custom_components/mikrotik_router/strings.json b/custom_components/mikrotik_router/strings.json index 3396511..d0d68fc 100644 --- a/custom_components/mikrotik_router/strings.json +++ b/custom_components/mikrotik_router/strings.json @@ -18,6 +18,7 @@ "error": { "name_exists": "Name already exists.", "cannot_connect": "Cannot connect to Mikrotik.", + "ssl_handshake_failure": "SSL handshake failure", "connection_timeout": "Mikrotik connection timeout.", "wrong_login": "Invalid user name or password." }