Change LUKS password based on crypttab UUID

This commit is contained in:
Disassembler 2019-06-12 16:23:07 +02:00
parent 54d3c1d23b
commit d9334fd12b
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -86,7 +86,9 @@ class VMMgr:
def update_password(self, oldpassword, newpassword):
# Update LUKS password and adminpwd for WSGI application
pwinput = '{}\n{}'.format(oldpassword, newpassword).encode()
subprocess.run(['cryptsetup', 'luksChangeKey', '/dev/sda2'], input=pwinput, check=True)
partition_uuid = open('/etc/crypttab').read().split()[1][5:]
partition_name = subprocess.run(['/sbin/blkid', '-U', partition_uuid], check=True, stdout=subprocess.PIPE).stdout.decode().strip()
subprocess.run(['cryptsetup', 'luksChangeKey', partition_name], input=pwinput, check=True)
# Update bcrypt-hashed password in config
self.conf['host']['adminpwd'] = crypto.adminpwd_hash(newpassword)
# Save config to file