VeraCrypt: Speichere Passwort abhängig von USB-Stick- und Containernamen

This commit is contained in:
Christopher Spinrath 2019-08-02 14:15:19 +02:00
parent 61fee22239
commit abfcaa3aa1
1 changed files with 17 additions and 14 deletions

View File

@ -47,19 +47,16 @@ def __sync_io():
])
res.check_returncode()
def __store_password(pw):
username = getpass.getuser()
def __store_password(username, pw):
keyring.set_password(KEYRING_SERVICE, username, pw)
def __delete_password():
username = getpass.getuser()
def __delete_password(username):
keyring.delete_password(KEYRING_SERVICE, username)
def __get_password(reset_pw = False):
def __get_password(username, reset_pw = False):
if reset_pw:
__delete_password()
__delete_password(username)
username = getpass.getuser()
pw = keyring.get_password(KEYRING_SERVICE, username)
if not pw:
pw = getpass.getpass()
@ -92,8 +89,8 @@ def unmount_usbdrive(usbdrive_mnt_path):
res.check_returncode()
def vera_mount(volume_path, container):
pw = __get_password()
def vera_mount(volume_path, container, identifier):
pw = __get_password(identifier)
res = __vera_exec([
VERA_PARAM_NON_INTERACTIVE,
@ -102,7 +99,7 @@ def vera_mount(volume_path, container):
assert res == 0, \
"Failed to mount VeraCrypt volume! VeraCrypt exited with status {}.".format(res)
__store_password(pw)
__store_password(identifier, pw)
def __parse_cmdline():
parser = argparse.ArgumentParser(description = DESCRIPTION)
@ -128,9 +125,6 @@ def __parse_cmdline():
def __main():
args = __parse_cmdline()
if args[ARG_RESET_PASSWORD]:
__delete_password()
volume_name = args[ARG_VERA_VOL_NAME]
mnt_path = args[ARG_MOUNT_PATH]
volume = os.path.join(mnt_path, volume_name)
@ -141,6 +135,15 @@ def __main():
container_name = args[ARG_CONTAINER_NAME]
container = os.path.join(usbdrive, container_name)
identifier = ':'.join([
getpass.getuser(),
usbdrive_name,
container_name,
])
if args[ARG_RESET_PASSWORD]:
__delete_password(identifier)
if not os.path.exists(usbdrive):
print(":: USB partition mount point \"{}\" doesn't exist. Ignoring request.".format(usbdrive))
return
@ -159,7 +162,7 @@ def __main():
print(":: VeraCrypt mount point \"{}\" already exists! Assuming container is already mounted.".format(volume))
return
vera_mount(volume, container)
vera_mount(volume, container, identifier)
if __name__ == '__main__':
__main()