From 87630e66e4990c1087edabb6bf31291be49942da Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sat, 12 Oct 2019 00:27:52 +0200 Subject: Attempt 2 at fixing crypto --- mastodon/Mastodon.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index a3903df..1d41551 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -27,6 +27,7 @@ try: import cryptography from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import ec + from cryptography.hazmat.primitives import serialization except: IMPL_HAS_CRYPTO = False @@ -2588,8 +2589,12 @@ class Mastodon: push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) push_key_priv = push_key_pair.private_numbers().private_value - if bigger_version(cryptography.__version__, "2.5.0") == cryptography.__version__: - push_key_pub = push_key_pair.public_key().public_numbers().public_bytes() + + crypto_ver = cryptography.__version__ + if len(crypto_ver) > 5: + crypto_ver += ".0" + if bigger_version(crypto_ver, "2.5.0") == crypto_ver: + push_key_pub = push_key_pair.public_key().public_bytes(serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint) else: push_key_pub = push_key_pair.public_key().public_numbers().encode_point() push_shared_secret = os.urandom(16) -- cgit v1.2.3