Attempt 2 at fixing crypto

This commit is contained in:
Lorenz Diener 2019-10-12 00:27:52 +02:00
pare ff160ec401
commit 87630e66e4

Veure arxiu

@ -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)