Emit new info messages and better debug messages in the exporter modules
Marco Ricci

Marco Ricci commited on 2024-12-07 09:30:38
Zeige 2 geänderte Dateien mit 8 Einfügungen und 3 Löschungen.

... ...
@@ -665,6 +665,7 @@ def export_storeroom_data(  # noqa: C901,PLR0912,PLR0914,PLR0915
665 665
     if encrypted_keys_version != 1:
666 666
         msg = f'cannot handle version {encrypted_keys_version} encrypted keys'
667 667
         raise RuntimeError(msg)
668
+    logger.info('Parsing master keys data from .keys')
668 669
     encrypted_keys_iterations = 2 ** (10 + (encrypted_keys_params & 0x0F))
669 670
     master_keys_keys = derive_master_keys_keys(
670 671
         master_keys_key, encrypted_keys_iterations
... ...
@@ -682,6 +683,7 @@ def export_storeroom_data(  # noqa: C901,PLR0912,PLR0914,PLR0915
682 683
         if fnmatch.fnmatch(hashdir_name, '[01][0-9a-f]')
683 684
     ]
684 685
     for file in valid_hashdirs:
686
+        logger.info('Decrypting bucket %s', file)
685 687
         bucket_contents = list(
686 688
             decrypt_bucket_file(file, master_keys, root_dir=storeroom_path)
687 689
         )
... ...
@@ -693,6 +695,7 @@ def export_storeroom_data(  # noqa: C901,PLR0912,PLR0914,PLR0915
693 695
             )
694 696
     dirs_to_check: dict[str, list[str]] = {}
695 697
     json_payload: Any
698
+    logger.info('Assembling config structure')
696 699
     for path, json_content in sorted(json_contents.items()):
697 700
         if path.endswith('/'):
698 701
             logger.debug(
... ...
@@ -721,7 +724,8 @@ def export_storeroom_data(  # noqa: C901,PLR0912,PLR0914,PLR0915
721 724
                 json_content.decode('utf-8'),
722 725
             )
723 726
             _store(config_structure, path, json_content)
724
-    # Sorted order is important; see `mabye_obj` below.
727
+    logger.info('Checking structure consistency')
728
+    # Sorted order is important; see `maybe_obj` below.
725 729
     for _dir, namelist in sorted(dirs_to_check.items()):
726 730
         namelist = [x.rstrip('/') for x in namelist]  # noqa: PLW2901
727 731
         obj: dict[Any, Any] = config_structure
... ...
@@ -168,6 +168,7 @@ class VaultNativeConfigParser(abc.ABC):
168 168
             salt=vault.Vault._UUID,  # noqa: SLF001
169 169
             iterations=iterations,
170 170
         ).derive(bytes(password))
171
+        result_key = raw_key.hex().lower().encode('ASCII')
171 172
         logger.debug(
172 173
             'binary = pbkdf2(%s, %s, %s, %s, %s) = %s -> %s',
173 174
             repr(password),
... ...
@@ -176,9 +177,9 @@ class VaultNativeConfigParser(abc.ABC):
176 177
             key_size // 2,
177 178
             repr('sha1'),
178 179
             _h(raw_key),
179
-            _h(raw_key.hex().lower().encode('ASCII')),
180
+            _h(result_key),
180 181
         )
181
-        return raw_key.hex().lower().encode('ASCII')
182
+        return result_key
182 183
 
183 184
     def _parse_contents(self) -> None:
184 185
         logger.info('Parsing IV, payload and signature from the file contents')
185 186