From 68f09f7b1391471e1389af811eb4ee2de5e0a89c Mon Sep 17 00:00:00 2001 From: Steffen Gufler Date: Mon, 16 Oct 2023 22:29:22 +0200 Subject: [PATCH] luks_device: improve detection of luks version --- plugins/modules/luks_device.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/modules/luks_device.py b/plugins/modules/luks_device.py index 5aceb22f3..b03e68c21 100644 --- a/plugins/modules/luks_device.py +++ b/plugins/modules/luks_device.py @@ -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):