diff --git a/telethon_tests/crypto_test.py b/telethon_tests/crypto_test.py index 96bdb5e9..cec18084 100644 --- a/telethon_tests/crypto_test.py +++ b/telethon_tests/crypto_test.py @@ -3,6 +3,8 @@ from hashlib import sha1 import telethon.helpers as utils from telethon.crypto import AES, Factorization +from telethon.crypto import rsa +from Crypto.PublicKey import RSA as PyCryptoRSA class CryptoTests(unittest.TestCase): @@ -117,10 +119,25 @@ class CryptoTests(unittest.TestCase): assert iv == expected_iv, 'Key ("{}") does not equal expected ("{}")'.format( key, expected_iv) + @staticmethod + def test_fingerprint_from_key(): + assert rsa._compute_fingerprint(PyCryptoRSA.importKey( + '-----BEGIN RSA PUBLIC KEY-----\n' + 'MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6\n' + 'lyDONS789sVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcixlEKzwKENj1Yz/s7daS\n' + 'an9tqw3bfUV/nqgbhGX81v/+7RFAEd+RwFnK7a+XYl9sluzHRyVVaTTveB2GazTw\n' + 'Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+\n' + '8hdlLmAjbCVfaigxX0CDqWeR1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n\n' + 'Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB\n' + '-----END RSA PUBLIC KEY-----' + )) == b'!k\xe8l\x02+\xb4\xc3', 'Wrong fingerprint calculated' + @staticmethod def test_factorize(): pq = 3118979781119966969 p, q = Factorization.factorize(pq) + if p > q: + p, q = q, p assert p == 1719614201, 'Factorized pair did not yield the correct result' assert q == 1813767169, 'Factorized pair did not yield the correct result'