Skip to content

Commit 761f845

Browse files
committed
separate argon2 check
Signed-off-by: Zen <[email protected]>
1 parent 05b3a09 commit 761f845

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/ugrd/crypto/cryptsetup.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
__author__ = 'desultory'
2-
__version__ = '2.8.1'
2+
__version__ = '2.9.0'
33

44
from zenlib.util import contains
55

66
from pathlib import Path
77

88
_module_name = 'ugrd.crypto.cryptsetup'
99

10-
CRYPTSETUP_PARAMETERS = ['key_type', 'partuuid', 'uuid', 'path', 'key_file', 'header_file', 'retries', 'key_command', 'reset_command', 'try_nokey', 'include_key', 'validate_key', 'validate']
10+
CRYPTSETUP_PARAMETERS = ['key_type', 'partuuid', 'uuid', 'path',
11+
'key_file', 'header_file', 'retries',
12+
'key_command', 'reset_command', 'try_nokey',
13+
'include_key', 'validate_key', 'validate']
1114

1215

1316
def _merge_cryptsetup(self, mapped_name: str, config: dict) -> None:
@@ -176,7 +179,7 @@ def _validate_cryptsetup_device(self, mapped_name) -> None:
176179
return self.logger.error("[%s] Unable to read LUKS header: %s" % (mapped_name, e))
177180
self.logger.warning("[%s] Cannot read detached LUKS header for validation: %s" % (mapped_name, e))
178181

179-
if token_type == 'uuid': # Validate the LUKS UUID
182+
if token_type == 'uuid': # Validate the LUKS UUID using the header
180183
for line in luks_info:
181184
if 'UUID' in line:
182185
if line.split()[1] != cryptsetup_token:
@@ -189,22 +192,27 @@ def _validate_cryptsetup_device(self, mapped_name) -> None:
189192
if 'Cipher: aes-xts-plain64' in luks_info:
190193
self['kernel_modules'] = 'crypto_xts'
191194

192-
has_argon = False
195+
if not self['argon2']:
196+
if cryptsetup_info.get('header_file'): # A header may be specified but unavailable
197+
self.logger.error("[%s] Unable to check: libargon2.so" % mapped_name)
198+
if 'PBKDF: argon2id' in luks_info: # If luks info is found, and argon is used, raise an error
199+
raise FileNotFoundError("[%s] Missing cryptsetup dependency: libargon2.so" % mapped_name)
200+
self.logger.error("[%s] Unable to validate argon support for LUKS: %s" % (mapped_name, luks_info))
201+
202+
203+
def detect_argon2(self) -> None:
204+
""" Validates that argon2 is available when argon2id is used. """
205+
argon = False
193206
for dep in self['dependencies']: # Ensure argon is installed if argon2id is used
194207
if dep.name.startswith('libargon2.so'):
195-
has_argon = True
208+
argon = True
196209
elif dep.name.startswith('libcrypto.so'):
197210
openssl_kdfs = self._run(['openssl', 'list', '-kdf-algorithms']).stdout.decode().lower().split('\n')
198211
self.logger.debug("OpenSSL KDFs: %s" % openssl_kdfs)
199212
for kdf in openssl_kdfs:
200213
if kdf.lstrip().startswith('argon2id') and 'default' in kdf:
201-
has_argon = True
202-
if not has_argon:
203-
if cryptsetup_info.get('header_file'): # A header may be specified but unavailable
204-
self.logger.error("[%s] Unable to check: libargon2.so" % mapped_name)
205-
if 'PBKDF: argon2id' in luks_info: # If luks info is found, and argon is used, raise an error
206-
raise FileNotFoundError("[%s] Missing cryptsetup dependency: libargon2.so" % mapped_name)
207-
self.logger.error("[%s] Unable to validate argon support for LUKS: %s" % (mapped_name, luks_info))
214+
argon = True
215+
self['argon2'] = argon
208216

209217

210218
@contains('validate', "Skipping cryptsetup configuration validation.", log_level=30)

src/ugrd/crypto/cryptsetup.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ cryptsetup_keyfile_validation = true
1010
[imports.config_processing]
1111
"ugrd.crypto.cryptsetup" = [ "_process_cryptsetup_multi", "_process_cryptsetup_key_types_multi" ]
1212

13+
[imports.build_pre]
14+
"ugrd.crypto.cryptsetup" = [ "detect_argon2" ]
15+
1316
[imports.build_tasks]
1417
"ugrd.crypto.cryptsetup" = [ "export_crypt_sources" ]
1518

@@ -31,3 +34,4 @@ cryptsetup_prompt = "bool" # Whether to prompt the user to press enter before u
3134
cryptsetup_autoretry = "bool" # Whether to automatically retry unlocking devices
3235
cryptsetup_trim = "bool" # Adds the --allow-discards option to cryptsetup commands
3336
cryptsetup = "dict" # Dict of cryptsetup volume to be unlocked, keyed by mapped device name
37+
argon2 = "bool" # Whether or not argon2 is available

0 commit comments

Comments
 (0)