summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgy Frolov <gosha@fro.lv>2021-01-17 11:01:07 +0300
committerGeorgy Frolov <gosha@fro.lv>2021-02-23 21:49:58 +0300
commite2ff2cc09ccde085eb11fb4e0c4c1c2742195468 (patch)
treec698f153844ed3d9b407b8a1bacc42d0450f314f
parent4ac38ecf359a1d0738dc2b5919af701387aef62b (diff)
switch to pyaes for password decoding
-rw-r--r--changelog.md6
-rw-r--r--mycli/config.py17
-rwxr-xr-xsetup.py4
3 files changed, 10 insertions, 17 deletions
diff --git a/changelog.md b/changelog.md
index 0173322..07af737 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,5 @@
-TODO
-====
+TBD
+===
Bug Fixes:
----------
@@ -15,7 +15,7 @@ Internal:
---------
* Remove unused function is_open_quote()
* Test various host-port combinations in command line arguments
-
+* switched from Cryptography to pyaes for decrypting mylogin.cnf
1.23.2
===
diff --git a/mycli/config.py b/mycli/config.py
index 0ff1a6e..53a026b 100644
--- a/mycli/config.py
+++ b/mycli/config.py
@@ -9,8 +9,7 @@ import sys
from typing import Union
from configobj import ConfigObj, ConfigObjError
-from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
-from cryptography.hazmat.backends import default_backend
+import pyaes
try:
basestring
@@ -200,11 +199,9 @@ def read_and_decrypt_mylogin_cnf(f):
return None
rkey = struct.pack('16B', *rkey)
- # Create a decryptor object using the key.
- decryptor = _get_decryptor(rkey)
-
# Create a bytes buffer to hold the plaintext.
plaintext = BytesIO()
+ aes = pyaes.AESModeOfOperationECB(rkey)
while True:
# Read the length of the ciphertext.
@@ -215,7 +212,9 @@ def read_and_decrypt_mylogin_cnf(f):
# Read cipher_len bytes from the file and decrypt.
cipher = f.read(cipher_len)
- plain = _remove_pad(decryptor.update(cipher))
+ plain = _remove_pad(
+ b''.join([aes.decrypt(cipher[i: i + 16]) for i in range(0, cipher_len, 16)])
+ )
if plain is False:
continue
plaintext.write(plain)
@@ -259,12 +258,6 @@ def strip_matching_quotes(s):
return s
-def _get_decryptor(key):
- """Get the AES decryptor."""
- c = Cipher(algorithms.AES(key), modes.ECB(), backend=default_backend())
- return c.decryptor()
-
-
def _remove_pad(line):
"""Remove the pad from the *line*."""
try:
diff --git a/setup.py b/setup.py
index 4aa7f91..540600c 100755
--- a/setup.py
+++ b/setup.py
@@ -23,9 +23,9 @@ install_requirements = [
'PyMySQL >= 0.9.2',
'sqlparse>=0.3.0,<0.4.0',
'configobj >= 5.0.5',
- 'cryptography >= 1.0.0',
'cli_helpers[styles] >= 2.0.1',
- 'pyperclip >= 1.8.1'
+ 'pyperclip >= 1.8.1',
+ 'pyaes >= 1.6.1'
]