diff --git a/README.rst b/README.rst index e76110d..50ca662 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,6 @@ Prerequisite * Whitelist your IP. * Generate a new key-pair. + Copy-paste the private key into a file. - + Either reformat the key to PKCS#1 format using ``$ openssl rsa -in input.key -out decrypted_key`` or install cryptography using ``$ pip install cryptography``. + Put the private key in a file called ``decrypted_key`` beside this ``README.rst`` file. Setup diff --git a/setup.py b/setup.py index fbdb780..bf92d96 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def find_version(*file_paths): }, install_requires=[ 'requests', - 'rsa', + 'cryptography', 'suds-jurko', ], classifiers=[ diff --git a/transip/client.py b/transip/client.py index 2ce7469..44d5fc3 100644 --- a/transip/client.py +++ b/transip/client.py @@ -10,7 +10,10 @@ import uuid from collections import OrderedDict -import rsa +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric import padding from suds.client import Client as SudsClient from suds.sudsobject import Object as SudsObject from suds.xsd.doctor import Import, ImportDoctor @@ -27,14 +30,6 @@ except ImportError: suds_requests = None -try: - from cryptography.hazmat.backends import default_backend - from cryptography.hazmat.primitives import serialization - from cryptography.hazmat.primitives import hashes - from cryptography.hazmat.primitives.asymmetric import padding - HAS_CRYPTOGRAPHY = True -except ImportError: - HAS_CRYPTOGRAPHY = False URI_TEMPLATE = 'https://{}/wsdl/?service={}' @@ -104,22 +99,16 @@ def _sign(self, message): else: raise RuntimeError('The private key does not exist.') - if HAS_CRYPTOGRAPHY: - private_key = serialization.load_pem_private_key( - str.encode(keydata), - password=None, - backend=default_backend() - ) - signature = private_key.sign( - str.encode(message), - padding.PKCS1v15(), - hashes.SHA512(), - ) - else: - privkey = rsa.PrivateKey.load_pkcs1(keydata) - signature = rsa.sign( - message.encode('utf-8'), privkey, 'SHA-512' - ) + private_key = serialization.load_pem_private_key( + str.encode(keydata), + password=None, + backend=default_backend() + ) + signature = private_key.sign( + str.encode(message), + padding.PKCS1v15(), + hashes.SHA512(), + ) signature = base64.b64encode(signature) signature = quote_plus(signature)