Changed functions for encryption and decryption of accounts to use str of master_pass instead of bytes
This commit is contained in:
parent
f7f954ecd3
commit
c2280e8bc2
@ -225,7 +225,7 @@ def _add_account5(
|
||||
name, login, passwd = data["name"], data["login"], data["passwd"]
|
||||
|
||||
enc_login, enc_pass, salt = cryptography.other_accounts.encrypt_account_info(
|
||||
login, passwd, text.encode("utf-8")
|
||||
login, passwd, text
|
||||
)
|
||||
|
||||
result = database.add.add_account(
|
||||
@ -288,7 +288,7 @@ def _get_account3(
|
||||
engine, mes.from_user.id, name
|
||||
)
|
||||
login, passwd = cryptography.other_accounts.decrypt_account_info(
|
||||
enc_login, enc_pass, text.encode("utf-8"), salt
|
||||
enc_login, enc_pass, text, salt
|
||||
)
|
||||
send_tmp_message(
|
||||
bot,
|
||||
@ -456,7 +456,7 @@ def _import3(
|
||||
failed.append(name)
|
||||
continue
|
||||
enc_login, enc_passwd, salt = cryptography.other_accounts.encrypt_account_info(
|
||||
login, passwd, text.encode("utf-8")
|
||||
login, passwd, text
|
||||
)
|
||||
result = database.add.add_account(
|
||||
engine, mes.from_user.id, name, salt, enc_login, enc_passwd
|
||||
|
@ -59,7 +59,6 @@ def get_all_accounts(
|
||||
engine: Engine, user_id: int, master_pass: str
|
||||
) -> list[tuple[str, str, str]]:
|
||||
accounts: list[tuple[str, str, str]] = []
|
||||
master_pass = master_pass.encode("utf-8")
|
||||
for account_name in database.get.get_accounts(engine, user_id):
|
||||
salt, enc_login, enc_passwd = database.get.get_account_info(
|
||||
engine, user_id, account_name
|
||||
|
@ -20,12 +20,12 @@ def _generate_key(salt: bytes, master_pass: bytes) -> bytes:
|
||||
|
||||
|
||||
def encrypt_account_info(
|
||||
login: str, passwd: str, master_pass: bytes
|
||||
login: str, passwd: str, master_pass: str
|
||||
) -> tuple[bytes, bytes, bytes]:
|
||||
"""Encrypts login and password of a user using their master password as a key.
|
||||
Returns a tuple of encrypted login, password and salt"""
|
||||
salt = os.urandom(64)
|
||||
key = _generate_key(salt, master_pass)
|
||||
key = _generate_key(salt, master_pass.encode("utf-8"))
|
||||
f = Fernet(key)
|
||||
enc_login = f.encrypt(login.encode("utf-8"))
|
||||
enc_passwd = f.encrypt(passwd.encode("utf-8"))
|
||||
@ -33,11 +33,11 @@ def encrypt_account_info(
|
||||
|
||||
|
||||
def decrypt_account_info(
|
||||
enc_login: bytes, enc_pass: bytes, master_pass: bytes, salt: bytes
|
||||
enc_login: bytes, enc_pass: bytes, master_pass: str, salt: bytes
|
||||
) -> tuple[str, str]:
|
||||
"""Decrypts login and password using their master password as a key.
|
||||
Returns a tuple of decrypted login and password"""
|
||||
key = _generate_key(salt, master_pass)
|
||||
key = _generate_key(salt, master_pass.encode("utf-8"))
|
||||
f = Fernet(key)
|
||||
login_bytes = f.decrypt(enc_login)
|
||||
pass_bytes = f.decrypt(enc_pass)
|
||||
|
Reference in New Issue
Block a user