Add crypto test to ensure calculating RSA fingerprints works

This commit is contained in:
Lonami Exo 2017-08-23 22:26:31 +02:00
parent d5fd147881
commit ba32d6f270

View File

@ -3,6 +3,8 @@ from hashlib import sha1
import telethon.helpers as utils import telethon.helpers as utils
from telethon.crypto import AES, Factorization from telethon.crypto import AES, Factorization
from telethon.crypto import rsa
from Crypto.PublicKey import RSA as PyCryptoRSA
class CryptoTests(unittest.TestCase): class CryptoTests(unittest.TestCase):
@ -117,10 +119,25 @@ class CryptoTests(unittest.TestCase):
assert iv == expected_iv, 'Key ("{}") does not equal expected ("{}")'.format( assert iv == expected_iv, 'Key ("{}") does not equal expected ("{}")'.format(
key, expected_iv) 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 @staticmethod
def test_factorize(): def test_factorize():
pq = 3118979781119966969 pq = 3118979781119966969
p, q = Factorization.factorize(pq) p, q = Factorization.factorize(pq)
if p > q:
p, q = q, p
assert p == 1719614201, 'Factorized pair did not yield the correct result' assert p == 1719614201, 'Factorized pair did not yield the correct result'
assert q == 1813767169, 'Factorized pair did not yield the correct result' assert q == 1813767169, 'Factorized pair did not yield the correct result'