Skip to content

Commit

Permalink
luks_device: improve detection of luks version
Browse files Browse the repository at this point in the history
  • Loading branch information
zemdreg committed Oct 16, 2023
1 parent 7c20340 commit 68f09f7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions plugins/modules/luks_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,13 @@ def get_luks_type(self, device):
''' get the luks type of a device
'''
if self.is_luks(device):
result = self._run_command([self._cryptsetup_bin, 'luksDump', device])
for line in result[STDOUT].splitlines():
if 'Version' in line:
version = line.split()[1]
return 'luks2' if version == '2' else 'luks1'
with open(device, 'rb') as f:
f.seek(LUKS2_HEADER_OFFSETS[0])
data = f.read(LUKS_HEADER_L)
if data == LUKS2_HEADER2:
return 'luks2'
else:
return 'luks1'
return None

def is_luks_slot_set(self, device, keyslot):
Expand Down

0 comments on commit 68f09f7

Please sign in to comment.