diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 7b6c801..37ca999 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -20,9 +20,20 @@ import threading | |||
20 | import sys | 20 | import sys |
21 | import six | 21 | import six |
22 | from decorator import decorate | 22 | from decorator import decorate |
23 | from cryptography.hazmat.backends import default_backend | 23 | |
24 | from cryptography.hazmat.primitives.asymmetric import ec | 24 | IMPL_HAS_CRYPTO = True |
25 | import http_ece | 25 | try: |
26 | from cryptography.hazmat.backends import default_backend | ||
27 | from cryptography.hazmat.primitives.asymmetric import ec | ||
28 | except: | ||
29 | IMPL_HAS_CRYPTO = False | ||
30 | |||
31 | IMPL_HAS_ECE = True | ||
32 | try: | ||
33 | import http_ece | ||
34 | except: | ||
35 | IMPL_HAS_ECE = False | ||
36 | |||
26 | import base64 | 37 | import base64 |
27 | import json | 38 | import json |
28 | import blurhash | 39 | import blurhash |
@@ -2306,6 +2317,9 @@ class Mastodon: | |||
2306 | Returns two dicts: One with the private key and shared secret and another with the | 2317 | Returns two dicts: One with the private key and shared secret and another with the |
2307 | public key and shared secret. | 2318 | public key and shared secret. |
2308 | """ | 2319 | """ |
2320 | if not IMPL_HAS_CRYPTO: | ||
2321 | raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.') | ||
2322 | |||
2309 | push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) | 2323 | push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) |
2310 | push_key_priv = push_key_pair.private_numbers().private_value | 2324 | push_key_priv = push_key_pair.private_numbers().private_value |
2311 | push_key_pub = push_key_pair.public_key().public_numbers().encode_point() | 2325 | push_key_pub = push_key_pair.public_key().public_numbers().encode_point() |
@@ -2331,6 +2345,9 @@ class Mastodon: | |||
2331 | 2345 | ||
2332 | Returns the decoded webpush as a `push notification dict`_. | 2346 | Returns the decoded webpush as a `push notification dict`_. |
2333 | """ | 2347 | """ |
2348 | if (not IMPL_HAS_ECE) or (not IMPL_HAS_CRYPTO): | ||
2349 | raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.') | ||
2350 | |||
2334 | salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip()) | 2351 | salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip()) |
2335 | dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip()) | 2352 | dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip()) |
2336 | p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip()) | 2353 | p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip()) |