From 782c0e4d6c7cc9188f5a746982c5fa9f81b38363 Mon Sep 17 00:00:00 2001 From: Alexandru Cheltuitor Date: Thu, 16 Sep 2021 10:48:47 +0100 Subject: [PATCH] Added check for dnspython package --- arch/PKGBUILD | 2 +- debian/changelog | 2 +- proton/api.py | 23 ++++++++++++++++++----- proton/exceptions.py | 4 ++++ rpmbuild/SPECS/python3-proton-client.spec | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/arch/PKGBUILD b/arch/PKGBUILD index cc8b29a..6287ada 100644 --- a/arch/PKGBUILD +++ b/arch/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Proton Technologies AG pkgname=python-proton-client pkgver=0.6.1 -pkgrel=3 +pkgrel=4 pkgdesc="Safely login with ProtonVPN credentials to connect to Proton." arch=("any") url="https://github.com/ProtonMail/proton-python-client" diff --git a/debian/changelog b/debian/changelog index d6feb79..3827be6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -proton-python-client (0.6.1-3) unstable; urgency=medium +proton-python-client (0.6.1-4) unstable; urgency=medium * Feature: Alternative Routing diff --git a/proton/api.py b/proton/api.py index 456a602..10fe605 100644 --- a/proton/api.py +++ b/proton/api.py @@ -18,17 +18,13 @@ from concurrent.futures import ThreadPoolExecutor -from dns import message -from dns.rdatatype import TXT - - from .cert_pinning import TLSPinningAdapter from .constants import (ALT_HASH_DICT, DEFAULT_TIMEOUT, DNS_HOSTS, ENCODED_URLS, SRP_MODULUS_KEY, SRP_MODULUS_KEY_FINGERPRINT) from .exceptions import (ConnectionTimeOutError, NetworkError, NewConnectionError, ProtonAPIError, TLSPinningError, - UnknownConnectionError) + UnknownConnectionError, MissingDepedencyError) from .logger import CustomLogger from .metadata import MetadataBackend from .srp import User as PmsrpUser @@ -151,6 +147,7 @@ def __init__( self.__metadata = MetadataBackend.get_backend() self.__metadata.cache_dir_path = cache_dir_path self.__metadata.logger = self._logger + self.__allow_alternative_routes = None # Verify modulus self.__gnupg = gnupg.GPG() @@ -473,6 +470,18 @@ def get_alternative_routes_from_dns(self, callback=None): If callback is passed then the method does not return any value, otherwise it returns a set(). """ + + try: + from dns import message + from dns.rdatatype import TXT + except ImportError as e: + self._logger.exception(e) + raise MissingDepedencyError( + "Could not find dnspython package. " + "Please either install the missing package or disable " + "alternative routing." + ) + routes = set() for encoded_url in ENCODED_URLS: @@ -511,6 +520,9 @@ def __generate_dns_message(self, encoded_url): dns_query (dns.message.Message): output of dns.message.make_query base64_dns_message (base64): encode bytes """ + from dns import message + from dns.rdatatype import TXT + dns_query = message.make_query(encoded_url, TXT) dns_wire = dns_query.to_wire() base64_dns_message = base64.urlsafe_b64encode(dns_wire).rstrip(b"=") @@ -552,6 +564,7 @@ def __extract_dns_answer(self, query_content, dns_query): Returns: set(): alternative routes for API """ + from dns import message r = message.from_wire( query_content, keyring=dns_query.keyring, diff --git a/proton/exceptions.py b/proton/exceptions.py index abe00af..b73bdc7 100644 --- a/proton/exceptions.py +++ b/proton/exceptions.py @@ -40,3 +40,7 @@ class ConnectionTimeOutError(ProtonError): class UnknownConnectionError(ProtonError): """UnknownConnectionError""" + + +class MissingDepedencyError(ProtonError): + """Missing dependency error""" diff --git a/rpmbuild/SPECS/python3-proton-client.spec b/rpmbuild/SPECS/python3-proton-client.spec index f9a90f3..8ec1442 100644 --- a/rpmbuild/SPECS/python3-proton-client.spec +++ b/rpmbuild/SPECS/python3-proton-client.spec @@ -1,6 +1,6 @@ %define unmangled_name proton-client %define version 0.6.1 -%define release 3 +%define release 4 Prefix: %{_prefix} @@ -49,7 +49,7 @@ rm -rf $RPM_BUILD_ROOT %defattr(-,root,root) %changelog -* Thu Jul 08 2021 Proton Technologies AG 0.6.1-3 +* Thu Jul 08 2021 Proton Technologies AG 0.6.1-4 - Feature: Alternative Routing * Mon May 24 2021 Proton Technologies AG 0.5.1-3