3fe3634dc06a5339cfd939ba01062d4778f4f064
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py          1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py   2) #
src/derivepassphrase/exporter/vault_v03_and_below.py   3) # SPDX-License-Identifier: MIT
src/derivepassphrase/exporter/vault_v03_and_below.py   4) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py          5) """Exporter for the vault native configuration format (v0.2 or v0.3).
src/derivepassphrase/exporter/vault_native.py          6) 
src/derivepassphrase/exporter/vault_native.py          7) The vault native formats are the configuration formats used by vault
src/derivepassphrase/exporter/vault_native.py          8) v0.2 and v0.3.  The configuration is stored as a single encrypted file,
src/derivepassphrase/exporter/vault_native.py          9) which is encrypted and authenticated.  v0.2 and v0.3 differ in some
src/derivepassphrase/exporter/vault_native.py         10) details concerning key derivation and expected format of internal
src/derivepassphrase/exporter/vault_native.py         11) structures, so they are *not* compatible.  v0.2 additionally contains
src/derivepassphrase/exporter/vault_native.py         12) cryptographic weaknesses (API misuse of a key derivation function, and
src/derivepassphrase/exporter/vault_native.py         13) a low-entropy method of generating initialization vectors for CBC block
src/derivepassphrase/exporter/vault_native.py         14) encryption mode) and should thus be avoided if possible.
src/derivepassphrase/exporter/vault_native.py         15) 
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/exporter/vault_native.py         16) The public interface is the [`export_vault_native_data`][] function.
src/derivepassphrase/exporter/vault_native.py         17) Multiple *non-public* classes are additionally documented here for
src/derivepassphrase/exporter/vault_native.py         18) didactical and educational reasons, but they are not part of the module
src/derivepassphrase/exporter/vault_native.py         19) API, are subject to change without notice (including removal), and
src/derivepassphrase/exporter/vault_native.py         20) should *not* be used or relied on.
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py         21) 
src/derivepassphrase/exporter/vault_native.py         22) """
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  23) 
src/derivepassphrase/exporter/vault_v03_and_below.py  24) from __future__ import annotations
src/derivepassphrase/exporter/vault_v03_and_below.py  25) 
src/derivepassphrase/exporter/vault_v03_and_below.py  26) import abc
src/derivepassphrase/exporter/vault_v03_and_below.py  27) import base64
src/derivepassphrase/exporter/vault_v03_and_below.py  28) import json
src/derivepassphrase/exporter/vault_v03_and_below.py  29) import logging
src/derivepassphrase/exporter/vault_v03_and_below.py  30) import warnings
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  31) from typing import TYPE_CHECKING
src/derivepassphrase/exporter/vault_v03_and_below.py  32) 
src/derivepassphrase/exporter/vault_v03_and_below.py  33) from derivepassphrase import exporter, vault
src/derivepassphrase/exporter/vault_v03_and_below.py  34) 
src/derivepassphrase/exporter/vault_v03_and_below.py  35) if TYPE_CHECKING:
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py         36)     from collections.abc import Sequence
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  37)     from typing import Any
src/derivepassphrase/exporter/vault_v03_and_below.py  38) 
src/derivepassphrase/exporter/vault_v03_and_below.py  39)     from typing_extensions import Buffer
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  40) 
src/derivepassphrase/exporter/vault_v03_and_below.py  41) if TYPE_CHECKING:
src/derivepassphrase/exporter/vault_v03_and_below.py  42)     from cryptography import exceptions as crypt_exceptions
src/derivepassphrase/exporter/vault_v03_and_below.py  43)     from cryptography import utils as crypt_utils
src/derivepassphrase/exporter/vault_v03_and_below.py  44)     from cryptography.hazmat.primitives import ciphers, hashes, hmac, padding
src/derivepassphrase/exporter/vault_v03_and_below.py  45)     from cryptography.hazmat.primitives.ciphers import algorithms, modes
src/derivepassphrase/exporter/vault_v03_and_below.py  46)     from cryptography.hazmat.primitives.kdf import pbkdf2
src/derivepassphrase/exporter/vault_v03_and_below.py  47) else:
src/derivepassphrase/exporter/vault_v03_and_below.py  48)     try:
src/derivepassphrase/exporter/vault_v03_and_below.py  49)         from cryptography import exceptions as crypt_exceptions
src/derivepassphrase/exporter/vault_v03_and_below.py  50)         from cryptography import utils as crypt_utils
src/derivepassphrase/exporter/vault_v03_and_below.py  51)         from cryptography.hazmat.primitives import (
src/derivepassphrase/exporter/vault_v03_and_below.py  52)             ciphers,
src/derivepassphrase/exporter/vault_v03_and_below.py  53)             hashes,
src/derivepassphrase/exporter/vault_v03_and_below.py  54)             hmac,
src/derivepassphrase/exporter/vault_v03_and_below.py  55)             padding,
src/derivepassphrase/exporter/vault_v03_and_below.py  56)         )
src/derivepassphrase/exporter/vault_v03_and_below.py  57)         from cryptography.hazmat.primitives.ciphers import algorithms, modes
src/derivepassphrase/exporter/vault_v03_and_below.py  58)         from cryptography.hazmat.primitives.kdf import pbkdf2
src/derivepassphrase/exporter/vault_v03_and_below.py  59)     except ModuleNotFoundError as exc:
src/derivepassphrase/exporter/vault_v03_and_below.py  60) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  61)         class _DummyModule:  # pragma: no cover
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  62)             def __init__(self, exc: type[Exception]) -> None:
src/derivepassphrase/exporter/vault_v03_and_below.py  63)                 self.exc = exc
src/derivepassphrase/exporter/vault_v03_and_below.py  64) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  65)             def __getattr__(self, name: str) -> Any:  # noqa: ANN401
src/derivepassphrase/exporter/vault_v03_and_below.py  66)                 def func(*args: Any, **kwargs: Any) -> Any:  # noqa: ANN401,ARG001
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  67)                     raise self.exc
src/derivepassphrase/exporter/vault_v03_and_below.py  68) 
src/derivepassphrase/exporter/vault_v03_and_below.py  69)                 return func
src/derivepassphrase/exporter/vault_v03_and_below.py  70) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  71)         crypt_exceptions = crypt_utils = _DummyModule(exc)
src/derivepassphrase/exporter/vault_v03_and_below.py  72)         ciphers = hashes = hmac = padding = _DummyModule(exc)
src/derivepassphrase/exporter/vault_v03_and_below.py  73)         algorithms = modes = pbkdf2 = _DummyModule(exc)
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  74)         STUBBED = True
src/derivepassphrase/exporter/vault_v03_and_below.py  75)     else:
src/derivepassphrase/exporter/vault_v03_and_below.py  76)         STUBBED = False
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  77) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py         78) __all__ = ('export_vault_native_data',)
src/derivepassphrase/exporter/vault_native.py         79) 
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  80) logger = logging.getLogger(__name__)
src/derivepassphrase/exporter/vault_v03_and_below.py  81) 
src/derivepassphrase/exporter/vault_v03_and_below.py  82) 
src/derivepassphrase/exporter/vault_v03_and_below.py  83) def _h(bs: bytes | bytearray) -> str:
src/derivepassphrase/exporter/vault_v03_and_below.py  84)     return 'bytes.fromhex({!r})'.format(bs.hex(' '))
src/derivepassphrase/exporter/vault_v03_and_below.py  85) 
src/derivepassphrase/exporter/vault_v03_and_below.py  86) 
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  87) class VaultNativeConfigParser(abc.ABC):
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  88)     """A base parser for vault's native configuration format.
src/derivepassphrase/exporter/vault_v03_and_below.py  89) 
src/derivepassphrase/exporter/vault_v03_and_below.py  90)     Certain details are specific to the respective vault versions, and
src/derivepassphrase/exporter/vault_v03_and_below.py  91)     are abstracted out.  This class by itself is not instantiable
src/derivepassphrase/exporter/vault_v03_and_below.py  92)     because of this.
src/derivepassphrase/exporter/vault_v03_and_below.py  93) 
src/derivepassphrase/exporter/vault_v03_and_below.py  94)     """
src/derivepassphrase/exporter/vault_v03_and_below.py  95) 
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  96)     def __init__(self, contents: Buffer, password: str | Buffer) -> None:
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py  97)         """Initialize the parser.
src/derivepassphrase/exporter/vault_v03_and_below.py  98) 
src/derivepassphrase/exporter/vault_v03_and_below.py  99)         Args:
src/derivepassphrase/exporter/vault_v03_and_below.py 100)             contents:
src/derivepassphrase/exporter/vault_v03_and_below.py 101)                 The binary contents of the encrypted configuration file.
src/derivepassphrase/exporter/vault_v03_and_below.py 102) 
src/derivepassphrase/exporter/vault_v03_and_below.py 103)                 Note: On disk, these are usually stored in
src/derivepassphrase/exporter/vault_v03_and_below.py 104)                 base64-encoded form, not in the "raw" form as needed
src/derivepassphrase/exporter/vault_v03_and_below.py 105)                 here.
src/derivepassphrase/exporter/vault_v03_and_below.py 106) 
src/derivepassphrase/exporter/vault_v03_and_below.py 107)             password:
src/derivepassphrase/exporter/vault_v03_and_below.py 108)                 The vault master key/master passphrase the file is
src/derivepassphrase/exporter/vault_v03_and_below.py 109)                 encrypted with.  Must be non-empty.  See
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/exporter/vault_native.py        110)                 [`exporter.get_vault_key`][] for details.
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 111) 
src/derivepassphrase/exporter/vault_v03_and_below.py 112)                 If this is a text string, then the UTF-8 encoding of the
src/derivepassphrase/exporter/vault_v03_and_below.py 113)                 string is used as the binary password.
src/derivepassphrase/exporter/vault_v03_and_below.py 114) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        115)         Warning:
src/derivepassphrase/exporter/vault_native.py        116)             Non-public class, provided for didactical and educational
src/derivepassphrase/exporter/vault_native.py        117)             purposes only. Subject to change without notice, including
src/derivepassphrase/exporter/vault_native.py        118)             removal.
src/derivepassphrase/exporter/vault_native.py        119) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 120)         """
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 121)         if not password:
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 122)             msg = 'Password must not be empty'
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 123)             raise ValueError(msg)  # noqa: DOC501
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 124)         self._contents = bytes(contents)
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 125)         self._iv_size = 0
src/derivepassphrase/exporter/vault_v03_and_below.py 126)         self._mac_size = 0
src/derivepassphrase/exporter/vault_v03_and_below.py 127)         self._encryption_key = b''
src/derivepassphrase/exporter/vault_v03_and_below.py 128)         self._encryption_key_size = 0
src/derivepassphrase/exporter/vault_v03_and_below.py 129)         self._signing_key = b''
src/derivepassphrase/exporter/vault_v03_and_below.py 130)         self._signing_key_size = 0
src/derivepassphrase/exporter/vault_v03_and_below.py 131)         self._message = b''
src/derivepassphrase/exporter/vault_v03_and_below.py 132)         self._message_tag = b''
src/derivepassphrase/exporter/vault_v03_and_below.py 133)         self._iv = b''
src/derivepassphrase/exporter/vault_v03_and_below.py 134)         self._payload = b''
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 135)         self._password = password
src/derivepassphrase/exporter/vault_v03_and_below.py 136)         self._sentinel: object = object()
src/derivepassphrase/exporter/vault_v03_and_below.py 137)         self._data: Any = self._sentinel
src/derivepassphrase/exporter/vault_v03_and_below.py 138) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 139)     def __call__(self) -> Any:  # noqa: ANN401
src/derivepassphrase/exporter/vault_v03_and_below.py 140)         """Return the decrypted and parsed vault configuration.
src/derivepassphrase/exporter/vault_v03_and_below.py 141) 
src/derivepassphrase/exporter/vault_v03_and_below.py 142)         Raises:
src/derivepassphrase/exporter/vault_v03_and_below.py 143)             cryptography.exceptions.InvalidSignature:
src/derivepassphrase/exporter/vault_v03_and_below.py 144)                 The encrypted configuration does not contain a valid
src/derivepassphrase/exporter/vault_v03_and_below.py 145)                 signature.
src/derivepassphrase/exporter/vault_v03_and_below.py 146)             ValueError:
src/derivepassphrase/exporter/vault_v03_and_below.py 147)                 The format is invalid, in a non-cryptographic way.  (For
src/derivepassphrase/exporter/vault_v03_and_below.py 148)                 example, it contains an unsupported version marker, or
src/derivepassphrase/exporter/vault_v03_and_below.py 149)                 unexpected extra contents, or invalid padding.)
src/derivepassphrase/exporter/vault_v03_and_below.py 150) 
src/derivepassphrase/exporter/vault_v03_and_below.py 151)         """
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 152)         if self._data is self._sentinel:
src/derivepassphrase/exporter/vault_v03_and_below.py 153)             self._parse_contents()
src/derivepassphrase/exporter/vault_v03_and_below.py 154)             self._derive_keys()
src/derivepassphrase/exporter/vault_v03_and_below.py 155)             self._check_signature()
src/derivepassphrase/exporter/vault_v03_and_below.py 156)             self._data = self._decrypt_payload()
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 157)         return self._data
src/derivepassphrase/exporter/vault_v03_and_below.py 158) 
src/derivepassphrase/exporter/vault_v03_and_below.py 159)     @staticmethod
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 160)     def _pbkdf2(
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 161)         password: str | Buffer, key_size: int, iterations: int
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 162)     ) -> bytes:
src/derivepassphrase/exporter/vault_v03_and_below.py 163)         if isinstance(password, str):
src/derivepassphrase/exporter/vault_v03_and_below.py 164)             password = password.encode('utf-8')
src/derivepassphrase/exporter/vault_v03_and_below.py 165)         raw_key = pbkdf2.PBKDF2HMAC(
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 166)             algorithm=hashes.SHA1(),
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 167)             length=key_size // 2,
src/derivepassphrase/exporter/vault_v03_and_below.py 168)             salt=vault.Vault._UUID,  # noqa: SLF001
src/derivepassphrase/exporter/vault_v03_and_below.py 169)             iterations=iterations,
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 170)         ).derive(bytes(password))
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 171)         logger.debug(
src/derivepassphrase/exporter/vault_v03_and_below.py 172)             'binary = pbkdf2(%s, %s, %s, %s, %s) = %s -> %s',
src/derivepassphrase/exporter/vault_v03_and_below.py 173)             repr(password),
src/derivepassphrase/exporter/vault_v03_and_below.py 174)             repr(vault.Vault._UUID),  # noqa: SLF001
src/derivepassphrase/exporter/vault_v03_and_below.py 175)             iterations,
src/derivepassphrase/exporter/vault_v03_and_below.py 176)             key_size // 2,
src/derivepassphrase/exporter/vault_v03_and_below.py 177)             repr('sha1'),
src/derivepassphrase/exporter/vault_v03_and_below.py 178)             _h(raw_key),
src/derivepassphrase/exporter/vault_v03_and_below.py 179)             _h(raw_key.hex().lower().encode('ASCII')),
src/derivepassphrase/exporter/vault_v03_and_below.py 180)         )
src/derivepassphrase/exporter/vault_v03_and_below.py 181)         return raw_key.hex().lower().encode('ASCII')
src/derivepassphrase/exporter/vault_v03_and_below.py 182) 
src/derivepassphrase/exporter/vault_v03_and_below.py 183)     def _parse_contents(self) -> None:
src/derivepassphrase/exporter/vault_v03_and_below.py 184)         logger.info('Parsing IV, payload and signature from the file contents')
src/derivepassphrase/exporter/vault_v03_and_below.py 185) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 186)         if len(self._contents) < self._iv_size + 16 + self._mac_size:
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 187)             msg = 'Invalid vault configuration file: file is truncated'
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 188)             raise ValueError(msg)
src/derivepassphrase/exporter/vault_v03_and_below.py 189) 
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 190)         def cut(buffer: bytes, cutpoint: int) -> tuple[bytes, bytes]:
src/derivepassphrase/exporter/vault_v03_and_below.py 191)             return buffer[:cutpoint], buffer[cutpoint:]
src/derivepassphrase/exporter/vault_v03_and_below.py 192) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 193)         cutpos1 = len(self._contents) - self._mac_size
src/derivepassphrase/exporter/vault_v03_and_below.py 194)         cutpos2 = self._iv_size
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 195) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 196)         self._message, self._message_tag = cut(self._contents, cutpos1)
src/derivepassphrase/exporter/vault_v03_and_below.py 197)         self._iv, self._payload = cut(self._message, cutpos2)
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 198) 
src/derivepassphrase/exporter/vault_v03_and_below.py 199)         logger.debug(
src/derivepassphrase/exporter/vault_v03_and_below.py 200)             'buffer %s = [[%s, %s], %s]',
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 201)             _h(self._contents),
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 202)             _h(self._iv),
src/derivepassphrase/exporter/vault_v03_and_below.py 203)             _h(self._payload),
src/derivepassphrase/exporter/vault_v03_and_below.py 204)             _h(self._message_tag),
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 205)         )
src/derivepassphrase/exporter/vault_v03_and_below.py 206) 
src/derivepassphrase/exporter/vault_v03_and_below.py 207)     def _derive_keys(self) -> None:
src/derivepassphrase/exporter/vault_v03_and_below.py 208)         logger.info('Deriving an encryption and signing key')
src/derivepassphrase/exporter/vault_v03_and_below.py 209)         self._generate_keys()
src/derivepassphrase/exporter/vault_v03_and_below.py 210)         assert (
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 211)             len(self._encryption_key) == self._encryption_key_size
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 212)         ), 'Derived encryption key is invalid'
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 213)         assert (
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 214)             len(self._signing_key) == self._signing_key_size
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 215)         ), 'Derived signing key is invalid'
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 216) 
src/derivepassphrase/exporter/vault_v03_and_below.py 217)     @abc.abstractmethod
src/derivepassphrase/exporter/vault_v03_and_below.py 218)     def _generate_keys(self) -> None:
src/derivepassphrase/exporter/vault_v03_and_below.py 219)         raise AssertionError
src/derivepassphrase/exporter/vault_v03_and_below.py 220) 
src/derivepassphrase/exporter/vault_v03_and_below.py 221)     def _check_signature(self) -> None:
src/derivepassphrase/exporter/vault_v03_and_below.py 222)         logger.info('Checking HMAC signature')
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 223)         mac = hmac.HMAC(self._signing_key, hashes.SHA256())
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 224)         mac_input = self._hmac_input()
src/derivepassphrase/exporter/vault_v03_and_below.py 225)         logger.debug(
src/derivepassphrase/exporter/vault_v03_and_below.py 226)             'mac_input = %s, expected_tag = %s',
src/derivepassphrase/exporter/vault_v03_and_below.py 227)             _h(mac_input),
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 228)             _h(self._message_tag),
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 229)         )
src/derivepassphrase/exporter/vault_v03_and_below.py 230)         mac.update(mac_input)
src/derivepassphrase/exporter/vault_v03_and_below.py 231)         try:
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 232)             mac.verify(self._message_tag)
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 233)         except crypt_exceptions.InvalidSignature:
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 234)             msg = 'File does not contain a valid signature'
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 235)             raise ValueError(msg) from None
src/derivepassphrase/exporter/vault_v03_and_below.py 236) 
src/derivepassphrase/exporter/vault_v03_and_below.py 237)     @abc.abstractmethod
src/derivepassphrase/exporter/vault_v03_and_below.py 238)     def _hmac_input(self) -> bytes:
src/derivepassphrase/exporter/vault_v03_and_below.py 239)         raise AssertionError
src/derivepassphrase/exporter/vault_v03_and_below.py 240) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 241)     def _decrypt_payload(self) -> Any:  # noqa: ANN401
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 242)         decryptor = self._make_decryptor()
src/derivepassphrase/exporter/vault_v03_and_below.py 243)         padded_plaintext = bytearray()
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 244)         padded_plaintext.extend(decryptor.update(self._payload))
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 245)         padded_plaintext.extend(decryptor.finalize())
src/derivepassphrase/exporter/vault_v03_and_below.py 246)         logger.debug('padded plaintext = %s', _h(padded_plaintext))
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 247)         unpadder = padding.PKCS7(self._iv_size * 8).unpadder()
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 248)         plaintext = bytearray()
src/derivepassphrase/exporter/vault_v03_and_below.py 249)         plaintext.extend(unpadder.update(padded_plaintext))
src/derivepassphrase/exporter/vault_v03_and_below.py 250)         plaintext.extend(unpadder.finalize())
src/derivepassphrase/exporter/vault_v03_and_below.py 251)         logger.debug('plaintext = %s', _h(plaintext))
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 252)         return json.loads(plaintext)
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 253) 
src/derivepassphrase/exporter/vault_v03_and_below.py 254)     @abc.abstractmethod
src/derivepassphrase/exporter/vault_v03_and_below.py 255)     def _make_decryptor(self) -> ciphers.CipherContext:
src/derivepassphrase/exporter/vault_v03_and_below.py 256)         raise AssertionError
src/derivepassphrase/exporter/vault_v03_and_below.py 257) 
src/derivepassphrase/exporter/vault_v03_and_below.py 258) 
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 259) class VaultNativeV03ConfigParser(VaultNativeConfigParser):
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 260)     """A parser for vault's native configuration format (v0.3).
src/derivepassphrase/exporter/vault_v03_and_below.py 261) 
src/derivepassphrase/exporter/vault_v03_and_below.py 262)     This is the modern, pre-storeroom configuration format.
src/derivepassphrase/exporter/vault_v03_and_below.py 263) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        264)     Warning:
src/derivepassphrase/exporter/vault_native.py        265)         Non-public class, provided for didactical and educational
src/derivepassphrase/exporter/vault_native.py        266)         purposes only. Subject to change without notice, including
src/derivepassphrase/exporter/vault_native.py        267)         removal.
src/derivepassphrase/exporter/vault_native.py        268) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 269)     """
src/derivepassphrase/exporter/vault_v03_and_below.py 270) 
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 271)     KEY_SIZE = 32
src/derivepassphrase/exporter/vault_v03_and_below.py 272) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        273)     def __init__(self, *args: Any, **kwargs: Any) -> None:  # noqa: ANN401
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 274)         super().__init__(*args, **kwargs)
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 275)         self._iv_size = 16
src/derivepassphrase/exporter/vault_v03_and_below.py 276)         self._mac_size = 32
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 277) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        278)     def __call__(self) -> Any:  # noqa: ANN401
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 279)         if self._data is self._sentinel:
src/derivepassphrase/exporter/vault_v03_and_below.py 280)             logger.info('Attempting to parse as v0.3 configuration')
src/derivepassphrase/exporter/vault_v03_and_below.py 281)             return super().__call__()
src/derivepassphrase/exporter/vault_v03_and_below.py 282)         return self._data
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 283) 
src/derivepassphrase/exporter/vault_v03_and_below.py 284)     def _generate_keys(self) -> None:
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 285)         self._encryption_key = self._pbkdf2(self._password, self.KEY_SIZE, 100)
src/derivepassphrase/exporter/vault_v03_and_below.py 286)         self._signing_key = self._pbkdf2(self._password, self.KEY_SIZE, 200)
src/derivepassphrase/exporter/vault_v03_and_below.py 287)         self._encryption_key_size = self._signing_key_size = self.KEY_SIZE
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 288) 
src/derivepassphrase/exporter/vault_v03_and_below.py 289)     def _hmac_input(self) -> bytes:
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 290)         return self._message.hex().lower().encode('ASCII')
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 291) 
src/derivepassphrase/exporter/vault_v03_and_below.py 292)     def _make_decryptor(self) -> ciphers.CipherContext:
src/derivepassphrase/exporter/vault_v03_and_below.py 293)         return ciphers.Cipher(
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 294)             algorithms.AES256(self._encryption_key), modes.CBC(self._iv)
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 295)         ).decryptor()
src/derivepassphrase/exporter/vault_v03_and_below.py 296) 
src/derivepassphrase/exporter/vault_v03_and_below.py 297) 
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 298) class VaultNativeV02ConfigParser(VaultNativeConfigParser):
Marco Ricci Fix the docstring of the va...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 299)     """A parser for vault's native configuration format (v0.2).
src/derivepassphrase/exporter/vault_v03_and_below.py 300) 
src/derivepassphrase/exporter/vault_v03_and_below.py 301)     This is the classic configuration format.  Compared to v0.3, it
src/derivepassphrase/exporter/vault_v03_and_below.py 302)     contains an (accidental) API misuse for the generation of the master
src/derivepassphrase/exporter/vault_v03_and_below.py 303)     keys, a low-entropy method of generating initialization vectors for
src/derivepassphrase/exporter/vault_v03_and_below.py 304)     the AES-CBC encryption step, and extra layers of base64 encoding.
src/derivepassphrase/exporter/vault_v03_and_below.py 305)     Because of these significantly weakened confidentiality guarantees,
src/derivepassphrase/exporter/vault_v03_and_below.py 306)     v0.2 configurations should be upgraded to at least v0.3 as soon as
src/derivepassphrase/exporter/vault_v03_and_below.py 307)     possible.
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 308) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        309)     Warning:
src/derivepassphrase/exporter/vault_native.py        310)         Non-public class, provided for didactical and educational
src/derivepassphrase/exporter/vault_native.py        311)         purposes only. Subject to change without notice, including
src/derivepassphrase/exporter/vault_native.py        312)         removal.
src/derivepassphrase/exporter/vault_native.py        313) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 314)     """
src/derivepassphrase/exporter/vault_v03_and_below.py 315) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        316)     def __init__(self, *args: Any, **kwargs: Any) -> None:  # noqa: ANN401
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 317)         super().__init__(*args, **kwargs)
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 318)         self._iv_size = 16
src/derivepassphrase/exporter/vault_v03_and_below.py 319)         self._mac_size = 64
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 320) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        321)     def __call__(self) -> Any:  # noqa: ANN401
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 322)         if self._data is self._sentinel:
src/derivepassphrase/exporter/vault_v03_and_below.py 323)             logger.info('Attempting to parse as v0.2 configuration')
src/derivepassphrase/exporter/vault_v03_and_below.py 324)             return super().__call__()
src/derivepassphrase/exporter/vault_v03_and_below.py 325)         return self._data
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 326) 
src/derivepassphrase/exporter/vault_v03_and_below.py 327)     def _parse_contents(self) -> None:
src/derivepassphrase/exporter/vault_v03_and_below.py 328)         super()._parse_contents()
src/derivepassphrase/exporter/vault_v03_and_below.py 329)         logger.debug('Decoding payload (base64) and message tag (hex)')
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 330)         self._payload = base64.standard_b64decode(self._payload)
src/derivepassphrase/exporter/vault_v03_and_below.py 331)         self._message_tag = bytes.fromhex(self._message_tag.decode('ASCII'))
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 332) 
src/derivepassphrase/exporter/vault_v03_and_below.py 333)     def _generate_keys(self) -> None:
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 334)         self._encryption_key = self._pbkdf2(self._password, 8, 16)
src/derivepassphrase/exporter/vault_v03_and_below.py 335)         self._signing_key = self._pbkdf2(self._password, 16, 16)
src/derivepassphrase/exporter/vault_v03_and_below.py 336)         self._encryption_key_size = 8
src/derivepassphrase/exporter/vault_v03_and_below.py 337)         self._signing_key_size = 16
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 338) 
src/derivepassphrase/exporter/vault_v03_and_below.py 339)     def _hmac_input(self) -> bytes:
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 340)         return base64.standard_b64encode(self._message)
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 341) 
src/derivepassphrase/exporter/vault_v03_and_below.py 342)     def _make_decryptor(self) -> ciphers.CipherContext:
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 343)         def evp_bytestokey_md5_one_iteration_no_salt(
src/derivepassphrase/exporter/vault_v03_and_below.py 344)             data: bytes, key_size: int, iv_size: int
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 345)         ) -> tuple[bytes, bytes]:
src/derivepassphrase/exporter/vault_v03_and_below.py 346)             total_size = key_size + iv_size
src/derivepassphrase/exporter/vault_v03_and_below.py 347)             buffer = bytearray()
src/derivepassphrase/exporter/vault_v03_and_below.py 348)             last_block = b''
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 349)             salt = b''
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 350)             logging.debug(
src/derivepassphrase/exporter/vault_v03_and_below.py 351)                 (
src/derivepassphrase/exporter/vault_v03_and_below.py 352)                     'data = %s, salt = %s, key_size = %s, iv_size = %s, '
src/derivepassphrase/exporter/vault_v03_and_below.py 353)                     'buffer length = %s, buffer = %s'
src/derivepassphrase/exporter/vault_v03_and_below.py 354)                 ),
src/derivepassphrase/exporter/vault_v03_and_below.py 355)                 _h(data),
src/derivepassphrase/exporter/vault_v03_and_below.py 356)                 _h(salt),
src/derivepassphrase/exporter/vault_v03_and_below.py 357)                 key_size,
src/derivepassphrase/exporter/vault_v03_and_below.py 358)                 iv_size,
src/derivepassphrase/exporter/vault_v03_and_below.py 359)                 len(buffer),
src/derivepassphrase/exporter/vault_v03_and_below.py 360)                 _h(buffer),
src/derivepassphrase/exporter/vault_v03_and_below.py 361)             )
src/derivepassphrase/exporter/vault_v03_and_below.py 362)             while len(buffer) < total_size:
src/derivepassphrase/exporter/vault_v03_and_below.py 363)                 with warnings.catch_warnings():
src/derivepassphrase/exporter/vault_v03_and_below.py 364)                     warnings.simplefilter(
src/derivepassphrase/exporter/vault_v03_and_below.py 365)                         'ignore', crypt_utils.CryptographyDeprecationWarning
src/derivepassphrase/exporter/vault_v03_and_below.py 366)                     )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 367)                     block = hashes.Hash(hashes.MD5())
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 368)                 block.update(last_block)
src/derivepassphrase/exporter/vault_v03_and_below.py 369)                 block.update(data)
src/derivepassphrase/exporter/vault_v03_and_below.py 370)                 block.update(salt)
src/derivepassphrase/exporter/vault_v03_and_below.py 371)                 last_block = block.finalize()
src/derivepassphrase/exporter/vault_v03_and_below.py 372)                 buffer.extend(last_block)
src/derivepassphrase/exporter/vault_v03_and_below.py 373)                 logging.debug(
src/derivepassphrase/exporter/vault_v03_and_below.py 374)                     'buffer length = %s, buffer = %s', len(buffer), _h(buffer)
src/derivepassphrase/exporter/vault_v03_and_below.py 375)                 )
src/derivepassphrase/exporter/vault_v03_and_below.py 376)             logging.debug(
src/derivepassphrase/exporter/vault_v03_and_below.py 377)                 'encryption_key = %s, iv = %s',
src/derivepassphrase/exporter/vault_v03_and_below.py 378)                 _h(buffer[:key_size]),
src/derivepassphrase/exporter/vault_v03_and_below.py 379)                 _h(buffer[key_size:total_size]),
src/derivepassphrase/exporter/vault_v03_and_below.py 380)             )
src/derivepassphrase/exporter/vault_v03_and_below.py 381)             return bytes(buffer[:key_size]), bytes(buffer[key_size:total_size])
src/derivepassphrase/exporter/vault_v03_and_below.py 382) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 383)         data = base64.standard_b64encode(self._iv + self._encryption_key)
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 384)         encryption_key, iv = evp_bytestokey_md5_one_iteration_no_salt(
src/derivepassphrase/exporter/vault_v03_and_below.py 385)             data, key_size=32, iv_size=16
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 386)         )
src/derivepassphrase/exporter/vault_v03_and_below.py 387)         return ciphers.Cipher(
src/derivepassphrase/exporter/vault_v03_and_below.py 388)             algorithms.AES256(encryption_key), modes.CBC(iv)
src/derivepassphrase/exporter/vault_v03_and_below.py 389)         ).decryptor()
src/derivepassphrase/exporter/vault_v03_and_below.py 390) 
src/derivepassphrase/exporter/vault_v03_and_below.py 391) 
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        392) def export_vault_native_data(
src/derivepassphrase/exporter/vault_native.py        393)     contents: Buffer | None = None,
src/derivepassphrase/exporter/vault_native.py        394)     key: str | Buffer | None = None,
src/derivepassphrase/exporter/vault_native.py        395)     *,
src/derivepassphrase/exporter/vault_native.py        396)     try_formats: Sequence[str] = ('v0.3', 'v0.2'),
src/derivepassphrase/exporter/vault_native.py        397) ) -> Any:  # noqa: ANN401
src/derivepassphrase/exporter/vault_native.py        398)     """Export the full configuration stored in vault native format.
src/derivepassphrase/exporter/vault_native.py        399) 
src/derivepassphrase/exporter/vault_native.py        400)     Args:
src/derivepassphrase/exporter/vault_native.py        401)         contents:
src/derivepassphrase/exporter/vault_native.py        402)             The binary encrypted contents of the vault configuration
src/derivepassphrase/exporter/vault_native.py        403)             file.  If not given, then query
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/exporter/vault_native.py        404)             [`exporter.get_vault_path`][] for the correct filename and
src/derivepassphrase/exporter/vault_native.py        405)             read the contents from there.
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        406) 
src/derivepassphrase/exporter/vault_native.py        407)             Note: On disk, these are usually stored in base64-encoded
src/derivepassphrase/exporter/vault_native.py        408)             form, not in the "raw" form as needed here.
src/derivepassphrase/exporter/vault_native.py        409)         key:
src/derivepassphrase/exporter/vault_native.py        410)             Encryption key/password for the configuration file, usually
src/derivepassphrase/exporter/vault_native.py        411)             the username, or passed via the `VAULT_KEY` environment
src/derivepassphrase/exporter/vault_native.py        412)             variable.  If not given, then query
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/exporter/vault_native.py        413)             [`exporter.get_vault_key`][] for the value.
Marco Ricci Add vault_native exporter f...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_native.py        414)         try_formats:
src/derivepassphrase/exporter/vault_native.py        415)             A sequence of formats to try out, in order.  Each key must
src/derivepassphrase/exporter/vault_native.py        416)             be one of `v0.2` or `v0.3`.
src/derivepassphrase/exporter/vault_native.py        417) 
src/derivepassphrase/exporter/vault_native.py        418)     Returns:
src/derivepassphrase/exporter/vault_native.py        419)         The vault configuration, as recorded in the configuration file.
src/derivepassphrase/exporter/vault_native.py        420) 
src/derivepassphrase/exporter/vault_native.py        421)         This may or may not be a valid configuration according to vault
src/derivepassphrase/exporter/vault_native.py        422)         or derivepassphrase.
src/derivepassphrase/exporter/vault_native.py        423) 
src/derivepassphrase/exporter/vault_native.py        424)     Raises:
src/derivepassphrase/exporter/vault_native.py        425)         RuntimeError:
src/derivepassphrase/exporter/vault_native.py        426)             Something went wrong during data collection, e.g. we
src/derivepassphrase/exporter/vault_native.py        427)             encountered unsupported or corrupted data in the storeroom.
src/derivepassphrase/exporter/vault_native.py        428)         json.JSONDecodeError:
src/derivepassphrase/exporter/vault_native.py        429)             An internal JSON data structure failed to parse from disk.
src/derivepassphrase/exporter/vault_native.py        430)             The storeroom is probably corrupted.
src/derivepassphrase/exporter/vault_native.py        431)         ValueError:
src/derivepassphrase/exporter/vault_native.py        432)             The requested formats to try out are invalid, or the
src/derivepassphrase/exporter/vault_native.py        433)             encrypted contents aren't in any of the attempted
src/derivepassphrase/exporter/vault_native.py        434)             configuration formats.
src/derivepassphrase/exporter/vault_native.py        435) 
src/derivepassphrase/exporter/vault_native.py        436)     """
src/derivepassphrase/exporter/vault_native.py        437)     if contents is None:
src/derivepassphrase/exporter/vault_native.py        438)         with open(exporter.get_vault_path(), 'rb') as infile:
src/derivepassphrase/exporter/vault_native.py        439)             contents = base64.standard_b64decode(infile.read())
src/derivepassphrase/exporter/vault_native.py        440)     if key is None:
src/derivepassphrase/exporter/vault_native.py        441)         key = exporter.get_vault_key()
src/derivepassphrase/exporter/vault_native.py        442)     stored_exception: Exception | None = None
src/derivepassphrase/exporter/vault_native.py        443)     for config_format in try_formats:
src/derivepassphrase/exporter/vault_native.py        444)         match config_format:
src/derivepassphrase/exporter/vault_native.py        445)             case 'v0.2':
src/derivepassphrase/exporter/vault_native.py        446)                 try:
src/derivepassphrase/exporter/vault_native.py        447)                     return VaultNativeV02ConfigParser(contents, key)()
src/derivepassphrase/exporter/vault_native.py        448)                 except ValueError as exc:
src/derivepassphrase/exporter/vault_native.py        449)                     exc.__context__ = stored_exception
src/derivepassphrase/exporter/vault_native.py        450)                     stored_exception = exc
src/derivepassphrase/exporter/vault_native.py        451)             case 'v0.3':
src/derivepassphrase/exporter/vault_native.py        452)                 try:
src/derivepassphrase/exporter/vault_native.py        453)                     return VaultNativeV03ConfigParser(contents, key)()
src/derivepassphrase/exporter/vault_native.py        454)                 except ValueError as exc:
src/derivepassphrase/exporter/vault_native.py        455)                     exc.__context__ = stored_exception
src/derivepassphrase/exporter/vault_native.py        456)                     stored_exception = exc
src/derivepassphrase/exporter/vault_native.py        457)             case _:  # pragma: no cover
src/derivepassphrase/exporter/vault_native.py        458)                 msg = (
src/derivepassphrase/exporter/vault_native.py        459)                     f'Invalid vault native configuration format: '
src/derivepassphrase/exporter/vault_native.py        460)                     f'{config_format!r}'
src/derivepassphrase/exporter/vault_native.py        461)                 )
src/derivepassphrase/exporter/vault_native.py        462)                 raise ValueError(msg)
src/derivepassphrase/exporter/vault_native.py        463)     msg = (
src/derivepassphrase/exporter/vault_native.py        464)         f'Not a valid vault native configuration. '
src/derivepassphrase/exporter/vault_native.py        465)         f'(We tried: {try_formats!r}.)'
src/derivepassphrase/exporter/vault_native.py        466)     )
src/derivepassphrase/exporter/vault_native.py        467)     raise stored_exception or ValueError(msg)
src/derivepassphrase/exporter/vault_native.py        468) 
src/derivepassphrase/exporter/vault_native.py        469) 
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 470) if __name__ == '__main__':
src/derivepassphrase/exporter/vault_v03_and_below.py 471)     import os
src/derivepassphrase/exporter/vault_v03_and_below.py 472) 
src/derivepassphrase/exporter/vault_v03_and_below.py 473)     logging.basicConfig(level=('DEBUG' if os.getenv('DEBUG') else 'WARNING'))
Marco Ricci Move vault key and path det...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 474)     with open(exporter.get_vault_path(), 'rb') as infile:
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 475)         contents = base64.standard_b64decode(infile.read())
Marco Ricci Move vault key and path det...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 476)     password = exporter.get_vault_key()
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 477)     try:
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 478)         config = VaultNativeV03ConfigParser(contents, password)()
Marco Ricci Add prototype for "vault v0...

Marco Ricci authored 4 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 479)     except ValueError:
Marco Ricci Rename vault v0.2/v0.3 clas...

Marco Ricci authored 3 months ago

src/derivepassphrase/exporter/vault_v03_and_below.py 480)         config = VaultNativeV02ConfigParser(contents, password)()