Skip to content

Commit

Permalink
Added check for dnspython package
Browse files Browse the repository at this point in the history
  • Loading branch information
calexandru2018 committed Sep 16, 2021
1 parent a74be8c commit 782c0e4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion arch/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Proton Technologies AG <[email protected]>
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"
Expand Down
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 18 additions & 5 deletions proton/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"=")
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions proton/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ class ConnectionTimeOutError(ProtonError):

class UnknownConnectionError(ProtonError):
"""UnknownConnectionError"""


class MissingDepedencyError(ProtonError):
"""Missing dependency error"""
4 changes: 2 additions & 2 deletions rpmbuild/SPECS/python3-proton-client.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%define unmangled_name proton-client
%define version 0.6.1
%define release 3
%define release 4

Prefix: %{_prefix}

Expand Down Expand Up @@ -49,7 +49,7 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root)

%changelog
* Thu Jul 08 2021 Proton Technologies AG <[email protected]> 0.6.1-3
* Thu Jul 08 2021 Proton Technologies AG <[email protected]> 0.6.1-4
- Feature: Alternative Routing

* Mon May 24 2021 Proton Technologies AG <[email protected]> 0.5.1-3
Expand Down

0 comments on commit 782c0e4

Please sign in to comment.