From 8527d8a3e1f8fe513daf20961b90ca9e051ea6cb Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Thu, 28 Jan 2021 00:02:37 +0100 Subject: [PATCH] change module pycryptodome to pycryptodomex --- otp/Otp.py | 17 ++++++++--------- otp/load.py | 2 +- otp/oaep.py | 14 +++++++------- requirements.txt | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/otp/Otp.py b/otp/Otp.py index 82fe44e..8a81db4 100644 --- a/otp/Otp.py +++ b/otp/Otp.py @@ -3,13 +3,12 @@ import traceback from secrets import token_hex, token_bytes import requests -from Crypto.Cipher import AES - +from Cryptodome.Cipher import AES +from Cryptodome.PublicKey import RSA +from Cryptodome import Hash from math import ceil -import Crypto -from Crypto.PublicKey import RSA from collections import defaultdict from xml.etree import cElementTree as ET @@ -96,7 +95,7 @@ class Otp: self.pinmode = pinmode self.Kiw = self.decode_oeap(Kiw, self.Kfact) key = RSA.construct((int(self.Kiw, 16), Otp.exponent)) - self.cipher = oaep.new(key, hashAlgo=Crypto.Hash.SHA256) + self.cipher = oaep.new(key, hashAlgo=Hash.SHA256) def getSerial(self): return self.device_id + "/_/" + self.iwalea @@ -128,7 +127,7 @@ class Otp: def decode_oeap(self, enc, key): modulus = int(key, 16) key = RSA.construct((modulus, Otp.exponent)) - cipher = oaep.new(key, hashAlgo=Crypto.Hash.SHA256) + cipher = oaep.new(key, hashAlgo=Hash.SHA256) block_size = 128 dec_string = "" enc_b = bytes.fromhex(enc) @@ -228,7 +227,7 @@ class Otp: self.action = "synchro" res = self.decode_oeap(xml["ms_key"], self.Kfact) temp_key = RSA.construct((int(res, 16), self.exponent)) - temp_cipher = oaep.new(temp_key, hashAlgo=Crypto.Hash.SHA256) + temp_cipher = oaep.new(temp_key, hashAlgo=Hash.SHA256) if random_bytes is None: random_bytes = token_bytes(16) KpubEncode = temp_cipher.encrypt(random_bytes) @@ -276,11 +275,11 @@ class Otp: self.__dict__.update(dict) if self.Kiw is not None: key = RSA.construct((int(self.Kiw, 16), Otp.exponent)) - self.cipher = oaep.new(key, hashAlgo=Crypto.Hash.SHA256) + self.cipher = oaep.new(key, hashAlgo=Hash.SHA256) def encode_oeap(text, key): - cipher = oaep.new(bytes.fromhex(key), hashAlgo=Crypto.Hash.SHA256) + cipher = oaep.new(bytes.fromhex(key), hashAlgo=Hash.SHA256) return cipher.encrypt(text) def save_otp(obj): diff --git a/otp/load.py b/otp/load.py index ff50258..8aebeee 100644 --- a/otp/load.py +++ b/otp/load.py @@ -2,7 +2,7 @@ import hashlib from locale import atoi from time import time -from Crypto.Cipher import AES +from Cryptodome.Cipher import AES from otp.Tokenizer import Tokenizer diff --git a/otp/oaep.py b/otp/oaep.py index 05605f6..7229711 100644 --- a/otp/oaep.py +++ b/otp/oaep.py @@ -1,9 +1,9 @@ -import Crypto -from Crypto import Random -from Crypto.Cipher.PKCS1_OAEP import PKCS1OAEP_Cipher -from Crypto.Util.number import ceil_div, bytes_to_long, long_to_bytes -from Crypto.Util.py3compat import bord -from Crypto.Util.strxor import strxor +import Cryptodome +from Cryptodome import Random +from Cryptodome.Cipher.PKCS1_OAEP import PKCS1OAEP_Cipher +from Cryptodome.Util.number import ceil_div, bytes_to_long, long_to_bytes +from Cryptodome.Util.py3compat import bord +from Cryptodome.Util.strxor import strxor class MyOAEP(PKCS1OAEP_Cipher): @@ -26,7 +26,7 @@ class MyOAEP(PKCS1OAEP_Cipher): """ # See 7.1.2 in RFC3447 - modBits = Crypto.Util.number.size(self._key.n) + modBits = Cryptodome.Util.number.size(self._key.n) k = ceil_div(modBits, 8) # Convert from bits to bytes hLen = self._hashObj.digest_size diff --git a/requirements.txt b/requirements.txt index 832383f..39d8f46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ dash_bootstrap_components geojson reverse_geocode androguard -pycryptodome +pycryptodomex #swagger req certifi >= 14.05.14