mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 01:46:35 +03:00
Decrypt files downloaded from CDNs (closes #208)
This commit is contained in:
parent
940a2896e8
commit
e5e7715a31
|
@ -488,6 +488,7 @@ class TelegramBareClient:
|
||||||
try:
|
try:
|
||||||
offset_index = 0
|
offset_index = 0
|
||||||
cdn_redirect = None
|
cdn_redirect = None
|
||||||
|
cdn_aes = None
|
||||||
while True:
|
while True:
|
||||||
offset = offset_index * part_size
|
offset = offset_index * part_size
|
||||||
|
|
||||||
|
@ -504,6 +505,15 @@ class TelegramBareClient:
|
||||||
if isinstance(result, FileCdnRedirect):
|
if isinstance(result, FileCdnRedirect):
|
||||||
# https://core.telegram.org/cdn
|
# https://core.telegram.org/cdn
|
||||||
cdn_redirect = result
|
cdn_redirect = result
|
||||||
|
cdn_aes = pyaes.AESModeOfOperationCTR(
|
||||||
|
result.encryption_key
|
||||||
|
)
|
||||||
|
# The returned IV is the counter used on CTR
|
||||||
|
cdn_aes._counter._counter = list(
|
||||||
|
result.encryption_iv[:12] +
|
||||||
|
(offset >> 4).to_bytes(4, 'big')
|
||||||
|
)
|
||||||
|
|
||||||
client, cdn_file = self._get_cdn_client(
|
client, cdn_file = self._get_cdn_client(
|
||||||
result.dc_id,
|
result.dc_id,
|
||||||
GetCdnFileRequest(
|
GetCdnFileRequest(
|
||||||
|
@ -535,8 +545,8 @@ class TelegramBareClient:
|
||||||
|
|
||||||
if cdn_redirect:
|
if cdn_redirect:
|
||||||
# We first need to decrypt the result
|
# We first need to decrypt the result
|
||||||
# TODO Decrypt the file, and use libssl if available
|
# TODO Use libssl if available
|
||||||
pass
|
result.bytes = cdn_aes.encrypt(result.bytes)
|
||||||
|
|
||||||
f.write(result.bytes)
|
f.write(result.bytes)
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user