Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions electrum/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ def strip_PKCS7_padding(data: bytes) -> bytes:
return data[0:-padlen]


def aes_encrypt_with_iv(key: bytes, iv: bytes, data: bytes) -> bytes:
def aes_encrypt_with_iv(key: bytes, iv: bytes, data: bytes, append_pkcs7=True) -> bytes:
assert_bytes(key, iv, data)
data = append_PKCS7_padding(data)
if append_pkcs7:
data = append_PKCS7_padding(data)
if HAS_CRYPTODOME:
e = CD_AES.new(key, CD_AES.MODE_CBC, iv).encrypt(data)
elif HAS_CRYPTOGRAPHY:
Expand All @@ -152,7 +153,7 @@ def aes_encrypt_with_iv(key: bytes, iv: bytes, data: bytes) -> bytes:
return e


def aes_decrypt_with_iv(key: bytes, iv: bytes, data: bytes) -> bytes:
def aes_decrypt_with_iv(key: bytes, iv: bytes, data: bytes, strip_pkcs7=True) -> bytes:
assert_bytes(key, iv, data)
if HAS_CRYPTODOME:
cipher = CD_AES.new(key, CD_AES.MODE_CBC, iv)
Expand All @@ -168,9 +169,11 @@ def aes_decrypt_with_iv(key: bytes, iv: bytes, data: bytes) -> bytes:
else:
raise Exception("no AES backend found")
try:
return strip_PKCS7_padding(data)
if strip_pkcs7:
data = strip_PKCS7_padding(data)
except InvalidPadding:
raise InvalidPassword()
return data


def EncodeAES_bytes(secret: bytes, msg: bytes) -> bytes:
Expand Down
5 changes: 2 additions & 3 deletions electrum/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,14 +1955,13 @@ def update_buttons_on_seed(self):
self.password_button.setVisible(self.wallet.may_have_password())

def change_password_dialog(self):
from electrum.storage import StorageEncryptionVersion
if StorageEncryptionVersion.XPUB_PASSWORD in self.wallet.get_available_storage_encryption_versions():
if self.wallet.is_hw_encryption_available():
from .password_dialog import ChangePasswordDialogForHW
d = ChangePasswordDialogForHW(self, self.wallet)
ok, old_password, new_password, encrypt_with_xpub = d.run()
if not ok:
return
has_xpub_encryption = self.wallet.storage.get_encryption_version() == StorageEncryptionVersion.XPUB_PASSWORD
has_xpub_encryption = self.wallet.storage.is_encrypted_with_hw_device()
def on_password(hw_dev_pw):
self._update_wallet_password(
old_password = hw_dev_pw if has_xpub_encryption else old_password,
Expand Down
Loading