Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"LAF Crypto failed to import!" error is unhelpful #39

Open
Jookia opened this issue Dec 29, 2017 · 3 comments
Open

"LAF Crypto failed to import!" error is unhelpful #39

Jookia opened this issue Dec 29, 2017 · 3 comments

Comments

@Jookia
Copy link

Jookia commented Dec 29, 2017

try:
    import laf_crypto
except ImportError:
    _logger.warning("LAF Crypto failed to import!")
   pass

Printing a warning but not explaining why it happened isn't helpful, there's no way to know why it didn't load (missing a library, etc)

@gjdunga
Copy link

gjdunga commented Feb 4, 2018

So, the following advice may not work for you, but this is what I found.

I am using Windows x64 Python 3.6.4. because the laf_crypto was not importing, there must be an issue with the module. (lglaf requires _AES.py) in case your wondering.

Sure enough, there is a further dependency in laf_crypto for crypto.cipher.

However getting it installed with 'pip pycrypto'. fails. Digging in further, the project seems dead ( SEE: pycrypto/pycrypto#173 ) and is not working with Python for windows. There is a FORK of the project named pycryptodome that at least provides the library.

Your best bet is to remove any version of pycrypto and install pycryptodome with:
pip uninstall pycrypto & pip install pycryptodome

See: https://pycryptodome.readthedocs.io/en/latest/src/examples.html

@Lekensteyn
Copy link
Owner

Only an AES ECB encrypt implementation is required, the https://cryptography.io/en/latest/ library seems better maintained, would it be OK to switch to that @tuxuser ?

@tuxuser
Copy link
Contributor

tuxuser commented Feb 5, 2018

@Lekensteyn sure!

Maybe somebody can test this?

diff --git a/laf_crypto.py b/laf_crypto.py
index fa6cad5..fb1c434 100644
--- a/laf_crypto.py
+++ b/laf_crypto.py
@@ -1,4 +1,5 @@
-from Crypto.Cipher import AES
+from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
+from cryptography.hazmat.backends import default_backend
 from utils import int_as_byte

 class LafCrypto(object):
@@ -30,5 +31,6 @@ class LafCrypto(object):
             plaintext += int_as_byte(k)
         encryption_key = LafCrypto.key_transform(encryption_key)
         xored_key = LafCrypto.xor_key(encryption_key, kilo_challenge)
-        obj = AES.new(xored_key, AES.MODE_ECB)
-        return obj.encrypt(plaintext)
+        obj = Cipher(algorithms.AES(xored_key), modes.ECB(), backend=default_backend()).encryptor()
+        # Is finalize (aka. add padding) desired?
+        return obj.update(plaintext) + obj.finalize()

BTW, oscrypto is worth a look too, completely relies on system-own crypto libs, I will post a snippet in a few -> oscrypto does not support ECB

UPDATE: PR sent, #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants