diff options
author | Jesús <heckyel@hyperbola.info> | 2022-02-05 10:48:13 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2022-02-05 10:48:13 -0500 |
commit | c4b763b19f54ed5dfc2fd408adb9ed74126f6740 (patch) | |
tree | 1bbf4450644370608f97bf6d4d7db818c5039f55 /yt_dlp/cookies.py | |
parent | 5aac4e0267e32d98eb68692afedafda3b41ea629 (diff) | |
parent | a3125791c7a5cdf2c8c025b99788bf686edd1a8a (diff) | |
download | hypervideo-pre-c4b763b19f54ed5dfc2fd408adb9ed74126f6740.tar.lz hypervideo-pre-c4b763b19f54ed5dfc2fd408adb9ed74126f6740.tar.xz hypervideo-pre-c4b763b19f54ed5dfc2fd408adb9ed74126f6740.zip |
updated from upstream | 05/02/2022 at 10:48
Diffstat (limited to 'yt_dlp/cookies.py')
-rw-r--r-- | yt_dlp/cookies.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py index 74e133bc9..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, @@ -669,8 +673,7 @@ def _get_linux_desktop_environment(env): return _LinuxDesktopEnvironment.GNOME elif 'KDE_FULL_SESSION' in env: return _LinuxDesktopEnvironment.KDE - else: - return _LinuxDesktopEnvironment.OTHER + return _LinuxDesktopEnvironment.OTHER def _choose_linux_keyring(logger): @@ -790,7 +793,7 @@ def _get_linux_keyring_password(browser_keyring_name, keyring, logger): # Chromium supports a flag: --password-store=<basic|gnome|kwallet> so the automatic detection # will not be sufficient in all cases. - keyring = _LinuxKeyring[keyring] or _choose_linux_keyring(logger) + keyring = _LinuxKeyring[keyring] if keyring else _choose_linux_keyring(logger) logger.debug(f'Chosen keyring: {keyring.name}') if keyring == _LinuxKeyring.KWALLET: @@ -847,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 |