aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/cookies.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-01-31 20:19:33 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-02-01 00:29:36 +0530
commit1d3586d0d513783e313428a6c57e18691a51f1fe (patch)
tree0097ad07eade89720e9c162640b4eef3e5bbfeac /yt_dlp/cookies.py
parentc533c89ce1d6965d8575413738d76a5bf9e2de59 (diff)
downloadhypervideo-pre-1d3586d0d513783e313428a6c57e18691a51f1fe.tar.lz
hypervideo-pre-1d3586d0d513783e313428a6c57e18691a51f1fe.tar.xz
hypervideo-pre-1d3586d0d513783e313428a6c57e18691a51f1fe.zip
[aes] Add unpad_pkcs7
Diffstat (limited to 'yt_dlp/cookies.py')
-rw-r--r--yt_dlp/cookies.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py
index 700415b35..fc033a8ae 100644
--- a/yt_dlp/cookies.py
+++ b/yt_dlp/cookies.py
@@ -11,7 +11,11 @@ from datetime import datetime, timedelta, timezone
from enum import Enum, auto
from hashlib import pbkdf2_hmac
-from .aes import aes_cbc_decrypt_bytes, aes_gcm_decrypt_and_verify_bytes
+from .aes import (
+ aes_cbc_decrypt_bytes,
+ aes_gcm_decrypt_and_verify_bytes,
+ unpad_pkcs7,
+)
from .compat import (
compat_b64decode,
compat_cookiejar_Cookie,
@@ -846,10 +850,9 @@ def pbkdf2_sha1(password, salt, iterations, key_length):
def _decrypt_aes_cbc(ciphertext, key, logger, initialization_vector=b' ' * 16):
- plaintext = aes_cbc_decrypt_bytes(ciphertext, key, initialization_vector)
- padding_length = plaintext[-1]
+ plaintext = unpad_pkcs7(aes_cbc_decrypt_bytes(ciphertext, key, initialization_vector))
try:
- return plaintext[:-padding_length].decode('utf-8')
+ return plaintext.decode('utf-8')
except UnicodeDecodeError:
logger.warning('failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?', only_once=True)
return None