diff options
author | Lorenz Diener <[email protected]> | 2019-10-12 00:12:22 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-10-12 00:12:22 +0200 |
commit | ff160ec40180608e223153ca60bb41cc42fbb85c (patch) | |
tree | 0e4032cfbbe23bf5b59ebb916f6b11ac72098628 /mastodon | |
parent | 8a2452c6be948dc7e582750309c0ef67279f7e42 (diff) | |
download | mastodon.py-ff160ec40180608e223153ca60bb41cc42fbb85c.tar.gz |
Try to future-proof cryptography module while remaining extremely backwards compatible since most distributions don't even have the old one (sighs)
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2a9833b..a3903df 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -24,6 +24,7 @@ import hashlib | |||
24 | 24 | ||
25 | IMPL_HAS_CRYPTO = True | 25 | IMPL_HAS_CRYPTO = True |
26 | try: | 26 | try: |
27 | import cryptography | ||
27 | from cryptography.hazmat.backends import default_backend | 28 | from cryptography.hazmat.backends import default_backend |
28 | from cryptography.hazmat.primitives.asymmetric import ec | 29 | from cryptography.hazmat.primitives.asymmetric import ec |
29 | except: | 30 | except: |
@@ -2587,7 +2588,10 @@ class Mastodon: | |||
2587 | 2588 | ||
2588 | push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) | 2589 | push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) |
2589 | push_key_priv = push_key_pair.private_numbers().private_value | 2590 | push_key_priv = push_key_pair.private_numbers().private_value |
2590 | push_key_pub = push_key_pair.public_key().public_numbers().encode_point() | 2591 | if bigger_version(cryptography.__version__, "2.5.0") == cryptography.__version__: |
2592 | push_key_pub = push_key_pair.public_key().public_numbers().public_bytes() | ||
2593 | else: | ||
2594 | push_key_pub = push_key_pair.public_key().public_numbers().encode_point() | ||
2591 | push_shared_secret = os.urandom(16) | 2595 | push_shared_secret = os.urandom(16) |
2592 | 2596 | ||
2593 | priv_dict = { | 2597 | priv_dict = { |