Skip to content

Commit 782c0e4

Browse files
Added check for dnspython package
1 parent a74be8c commit 782c0e4

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

arch/PKGBUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Maintainer: Proton Technologies AG <[email protected]>
22
pkgname=python-proton-client
33
pkgver=0.6.1
4-
pkgrel=3
4+
pkgrel=4
55
pkgdesc="Safely login with ProtonVPN credentials to connect to Proton."
66
arch=("any")
77
url="https://github.com/ProtonMail/proton-python-client"

debian/changelog

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
proton-python-client (0.6.1-3) unstable; urgency=medium
1+
proton-python-client (0.6.1-4) unstable; urgency=medium
22

33
* Feature: Alternative Routing
44

proton/api.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818
from concurrent.futures import ThreadPoolExecutor
1919

2020

21-
from dns import message
22-
from dns.rdatatype import TXT
23-
24-
2521
from .cert_pinning import TLSPinningAdapter
2622
from .constants import (ALT_HASH_DICT, DEFAULT_TIMEOUT, DNS_HOSTS,
2723
ENCODED_URLS, SRP_MODULUS_KEY,
2824
SRP_MODULUS_KEY_FINGERPRINT)
2925
from .exceptions import (ConnectionTimeOutError, NetworkError,
3026
NewConnectionError, ProtonAPIError, TLSPinningError,
31-
UnknownConnectionError)
27+
UnknownConnectionError, MissingDepedencyError)
3228
from .logger import CustomLogger
3329
from .metadata import MetadataBackend
3430
from .srp import User as PmsrpUser
@@ -151,6 +147,7 @@ def __init__(
151147
self.__metadata = MetadataBackend.get_backend()
152148
self.__metadata.cache_dir_path = cache_dir_path
153149
self.__metadata.logger = self._logger
150+
self.__allow_alternative_routes = None
154151

155152
# Verify modulus
156153
self.__gnupg = gnupg.GPG()
@@ -473,6 +470,18 @@ def get_alternative_routes_from_dns(self, callback=None):
473470
If callback is passed then the method does not return any value, otherwise it
474471
returns a set().
475472
"""
473+
474+
try:
475+
from dns import message
476+
from dns.rdatatype import TXT
477+
except ImportError as e:
478+
self._logger.exception(e)
479+
raise MissingDepedencyError(
480+
"Could not find dnspython package. "
481+
"Please either install the missing package or disable "
482+
"alternative routing."
483+
)
484+
476485
routes = set()
477486

478487
for encoded_url in ENCODED_URLS:
@@ -511,6 +520,9 @@ def __generate_dns_message(self, encoded_url):
511520
dns_query (dns.message.Message): output of dns.message.make_query
512521
base64_dns_message (base64): encode bytes
513522
"""
523+
from dns import message
524+
from dns.rdatatype import TXT
525+
514526
dns_query = message.make_query(encoded_url, TXT)
515527
dns_wire = dns_query.to_wire()
516528
base64_dns_message = base64.urlsafe_b64encode(dns_wire).rstrip(b"=")
@@ -552,6 +564,7 @@ def __extract_dns_answer(self, query_content, dns_query):
552564
Returns:
553565
set(): alternative routes for API
554566
"""
567+
from dns import message
555568
r = message.from_wire(
556569
query_content,
557570
keyring=dns_query.keyring,

proton/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ class ConnectionTimeOutError(ProtonError):
4040

4141
class UnknownConnectionError(ProtonError):
4242
"""UnknownConnectionError"""
43+
44+
45+
class MissingDepedencyError(ProtonError):
46+
"""Missing dependency error"""

rpmbuild/SPECS/python3-proton-client.spec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%define unmangled_name proton-client
22
%define version 0.6.1
3-
%define release 3
3+
%define release 4
44

55
Prefix: %{_prefix}
66

@@ -49,7 +49,7 @@ rm -rf $RPM_BUILD_ROOT
4949
%defattr(-,root,root)
5050

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

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

0 commit comments

Comments
 (0)