vaulttool 2.0.4__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {vaulttool-2.0.4 → vaulttool-2.1.0}/PKG-INFO +10 -10
  2. {vaulttool-2.0.4 → vaulttool-2.1.0}/README.md +9 -9
  3. {vaulttool-2.0.4 → vaulttool-2.1.0}/pyproject.toml +2 -2
  4. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/__init__.py +6 -8
  5. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/cli.py +49 -53
  6. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/config.py +2 -2
  7. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/core.py +534 -296
  8. vaulttool-2.1.0/vaulttool/tests/test_security_hardening.py +179 -0
  9. vaulttool-2.1.0/vaulttool/tests/test_source_selection.py +144 -0
  10. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_utils.py +20 -0
  11. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/utils.py +70 -84
  12. {vaulttool-2.0.4 → vaulttool-2.1.0}/LICENSE +0 -0
  13. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/__main__.py +0 -0
  14. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/conftest.py +0 -0
  15. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_checksum_trigger.py +0 -0
  16. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_config.py +0 -0
  17. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_core.py +0 -0
  18. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_decrypt_missing_sources.py +0 -0
  19. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_env_config.py +0 -0
  20. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_error_aggregation.py +0 -0
  21. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_gitignore.py +0 -0
  22. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_key_file_validation.py +0 -0
  23. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_main_integration.py +0 -0
  24. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_priority3_fixes.py +0 -0
  25. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_security_and_edge_cases.py +0 -0
  26. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_suffix_fallback.py +0 -0
  27. {vaulttool-2.0.4 → vaulttool-2.1.0}/vaulttool/tests/test_suffix_switch_bug.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vaulttool
3
- Version: 2.0.4
3
+ Version: 2.1.0
4
4
  Summary: Secure file encryption for secrets/configs
5
5
  License: Apache-2
6
6
  License-File: LICENSE
@@ -60,7 +60,7 @@ vaulttool refresh
60
60
 
61
61
  **Key Concepts:**
62
62
 
63
- - Encrypts files with AES-256-CBC + HMAC-SHA256
63
+ - Encrypts files with AES-256-GCM (authenticated) + HMAC-SHA256 change detection
64
64
  - Creates `.vault` files that are safe to commit to git
65
65
  - Uses a single encryption key (store securely, don't commit!)
66
66
  - Configure via `.vaulttool.yml` or environment variables
@@ -140,7 +140,7 @@ vaulttool refresh
140
140
  - **Detects changes automatically**: Updates encrypted files whenever the original files change.
141
141
  - **Restores missing files**: Automatically decrypts files if the original is missing and a `.vault` file exists.
142
142
  - **Refreshes plaintext from vaults**: On demand, overwrite existing plaintext from `.vault` files (with `--force`).
143
- - **Uses AES-256-CBC encryption**: Secures your data with strong, industry-standard encryption via Python's cryptography library.
143
+ - **Uses AES-256-GCM authenticated encryption**: Detects tampering before any plaintext is written, via Python's cryptography library.
144
144
  - **Updates .gitignore for you**: Adds plain text files to `.gitignore` to prevent accidental commits of secrets.
145
145
  - **Verifies file integrity**: Uses HMACs to make sure encrypted files are always up to date.
146
146
  - **Editor-friendly format**: Encrypted files are base64 encoded, making them easy to copy and paste.
@@ -174,7 +174,7 @@ VaultTool v2.0.0 represents a **major quality improvement** with comprehensive e
174
174
  a fixed-size output (the HMAC tag). This tag is unique to both the input data and the key, making it an effective
175
175
  way to verify data integrity and authenticity.
176
176
 
177
- 3. **AES-256-CBC Encryption**
177
+ 3. **AES-256-GCM Encryption (AEAD)**
178
178
  - 256-bit encryption key
179
179
  - Random IV per encryption
180
180
  - PKCS7 padding
@@ -193,7 +193,7 @@ derive_keys() with HKDF
193
193
  │
194
194
  └─→ HKDF(info="encryption-key") → Encryption Key (32 bytes)
195
195
  ↓
196
- Used for AES-256-CBC encryption
196
+ Used for AES-256-GCM encryption
197
197
  ```
198
198
 
199
199
  ## Vault File Format
@@ -219,7 +219,7 @@ ae5bee7bdc95c4aa85c5e773876fc78c2b8e9f4d3c7a6b5e8d1f0a9c2e4b7d6f
219
219
  - **Removed OpenSSL requirement**: Now uses Python's `cryptography` library directly
220
220
  - **Simpler installation**: Just install VaultTool with pip or Poetry - no system dependencies
221
221
  - **Better portability**: Works consistently across all platforms (Linux, macOS, Windows)
222
- - **Same strong encryption**: Still uses AES-256-CBC with HMAC-SHA256 for authentication
222
+ - **Same strong encryption**: Still uses AES-256-GCM authenticated encryption
223
223
 
224
224
  **Result:** Installation is now as simple as `pip install vaulttool` or `poetry install` - no need to install OpenSSL or other system packages!
225
225
 
@@ -378,7 +378,7 @@ vaulttool
378
378
 
379
379
  - Python 3.10 or newer
380
380
  - Python packages (automatically installed):
381
- - `cryptography` - For AES-256-CBC encryption and HMAC
381
+ - `cryptography` - For AES-256-GCM encryption and HMAC
382
382
  - `typer` - Command-line interface
383
383
  - `pyyaml` - Configuration file parsing
384
384
 
@@ -513,7 +513,7 @@ vaulttool:
513
513
  - "*.vault"
514
514
  options:
515
515
  suffix: ".vault" # Suffix for encrypted files
516
- algorithm: "aes-256-cbc" # Encryption algorithm (AES-256-CBC)
516
+ algorithm: "aes-256-cbc" # Deprecated: ignored, encryption is always AES-256-GCM
517
517
  key_type: "file" # Key storage type
518
518
  key_file: "vault.key" # Path to encryption key file
519
519
  ```
@@ -526,7 +526,7 @@ vaulttool:
526
526
  - **`exclude_patterns`**: Patterns for files to exclude. Defaults to `[*.vault]` (options.suffix).
527
527
  - **`options`**: Encryption settings including:
528
528
  - `suffix`: File extension for encrypted files (default: `.vault`)
529
- - `algorithm`: Encryption algorithm (default: `aes-256-cbc`). Uses AES-256-CBC with HMAC-SHA256 for authentication.
529
+ - `algorithm`: Deprecated and ignored. Encryption always uses AES-256-GCM; legacy AES-256-CBC vault files remain readable.
530
530
  - `key_file`: Path to encryption key file (must be at least 32 bytes)
531
531
 
532
532
  **Note:** The `openssl_path` option has been removed in v2.0.0 as VaultTool now uses Python's `cryptography` library directly.
@@ -820,7 +820,7 @@ repos:
820
820
 
821
821
  ## Related Tools
822
822
 
823
- - **[Python Cryptography](https://cryptography.io/)**: The cryptography library used by VaultTool for AES-256-CBC encryption and HMAC
823
+ - **[Python Cryptography](https://cryptography.io/)**: The cryptography library used by VaultTool for AES-256-GCM encryption and HMAC
824
824
  - **[pipx](https://pypa.github.io/pipx/)**: Install and run Python applications in isolated environments
825
825
  - **[pre-commit](https://pre-commit.com/)**: Framework for managing Git pre-commit hooks
826
826
  - **[Git](https://git-scm.com/)**: Version control system
@@ -36,7 +36,7 @@ vaulttool refresh
36
36
 
37
37
  **Key Concepts:**
38
38
 
39
- - Encrypts files with AES-256-CBC + HMAC-SHA256
39
+ - Encrypts files with AES-256-GCM (authenticated) + HMAC-SHA256 change detection
40
40
  - Creates `.vault` files that are safe to commit to git
41
41
  - Uses a single encryption key (store securely, don't commit!)
42
42
  - Configure via `.vaulttool.yml` or environment variables
@@ -116,7 +116,7 @@ vaulttool refresh
116
116
  - **Detects changes automatically**: Updates encrypted files whenever the original files change.
117
117
  - **Restores missing files**: Automatically decrypts files if the original is missing and a `.vault` file exists.
118
118
  - **Refreshes plaintext from vaults**: On demand, overwrite existing plaintext from `.vault` files (with `--force`).
119
- - **Uses AES-256-CBC encryption**: Secures your data with strong, industry-standard encryption via Python's cryptography library.
119
+ - **Uses AES-256-GCM authenticated encryption**: Detects tampering before any plaintext is written, via Python's cryptography library.
120
120
  - **Updates .gitignore for you**: Adds plain text files to `.gitignore` to prevent accidental commits of secrets.
121
121
  - **Verifies file integrity**: Uses HMACs to make sure encrypted files are always up to date.
122
122
  - **Editor-friendly format**: Encrypted files are base64 encoded, making them easy to copy and paste.
@@ -150,7 +150,7 @@ VaultTool v2.0.0 represents a **major quality improvement** with comprehensive e
150
150
  a fixed-size output (the HMAC tag). This tag is unique to both the input data and the key, making it an effective
151
151
  way to verify data integrity and authenticity.
152
152
 
153
- 3. **AES-256-CBC Encryption**
153
+ 3. **AES-256-GCM Encryption (AEAD)**
154
154
  - 256-bit encryption key
155
155
  - Random IV per encryption
156
156
  - PKCS7 padding
@@ -169,7 +169,7 @@ derive_keys() with HKDF
169
169
  │
170
170
  └─→ HKDF(info="encryption-key") → Encryption Key (32 bytes)
171
171
  ↓
172
- Used for AES-256-CBC encryption
172
+ Used for AES-256-GCM encryption
173
173
  ```
174
174
 
175
175
  ## Vault File Format
@@ -195,7 +195,7 @@ ae5bee7bdc95c4aa85c5e773876fc78c2b8e9f4d3c7a6b5e8d1f0a9c2e4b7d6f
195
195
  - **Removed OpenSSL requirement**: Now uses Python's `cryptography` library directly
196
196
  - **Simpler installation**: Just install VaultTool with pip or Poetry - no system dependencies
197
197
  - **Better portability**: Works consistently across all platforms (Linux, macOS, Windows)
198
- - **Same strong encryption**: Still uses AES-256-CBC with HMAC-SHA256 for authentication
198
+ - **Same strong encryption**: Still uses AES-256-GCM authenticated encryption
199
199
 
200
200
  **Result:** Installation is now as simple as `pip install vaulttool` or `poetry install` - no need to install OpenSSL or other system packages!
201
201
 
@@ -354,7 +354,7 @@ vaulttool
354
354
 
355
355
  - Python 3.10 or newer
356
356
  - Python packages (automatically installed):
357
- - `cryptography` - For AES-256-CBC encryption and HMAC
357
+ - `cryptography` - For AES-256-GCM encryption and HMAC
358
358
  - `typer` - Command-line interface
359
359
  - `pyyaml` - Configuration file parsing
360
360
 
@@ -489,7 +489,7 @@ vaulttool:
489
489
  - "*.vault"
490
490
  options:
491
491
  suffix: ".vault" # Suffix for encrypted files
492
- algorithm: "aes-256-cbc" # Encryption algorithm (AES-256-CBC)
492
+ algorithm: "aes-256-cbc" # Deprecated: ignored, encryption is always AES-256-GCM
493
493
  key_type: "file" # Key storage type
494
494
  key_file: "vault.key" # Path to encryption key file
495
495
  ```
@@ -502,7 +502,7 @@ vaulttool:
502
502
  - **`exclude_patterns`**: Patterns for files to exclude. Defaults to `[*.vault]` (options.suffix).
503
503
  - **`options`**: Encryption settings including:
504
504
  - `suffix`: File extension for encrypted files (default: `.vault`)
505
- - `algorithm`: Encryption algorithm (default: `aes-256-cbc`). Uses AES-256-CBC with HMAC-SHA256 for authentication.
505
+ - `algorithm`: Deprecated and ignored. Encryption always uses AES-256-GCM; legacy AES-256-CBC vault files remain readable.
506
506
  - `key_file`: Path to encryption key file (must be at least 32 bytes)
507
507
 
508
508
  **Note:** The `openssl_path` option has been removed in v2.0.0 as VaultTool now uses Python's `cryptography` library directly.
@@ -796,7 +796,7 @@ repos:
796
796
 
797
797
  ## Related Tools
798
798
 
799
- - **[Python Cryptography](https://cryptography.io/)**: The cryptography library used by VaultTool for AES-256-CBC encryption and HMAC
799
+ - **[Python Cryptography](https://cryptography.io/)**: The cryptography library used by VaultTool for AES-256-GCM encryption and HMAC
800
800
  - **[pipx](https://pypa.github.io/pipx/)**: Install and run Python applications in isolated environments
801
801
  - **[pre-commit](https://pre-commit.com/)**: Framework for managing Git pre-commit hooks
802
802
  - **[Git](https://git-scm.com/)**: Version control system
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vaulttool"
3
- version = "2.0.4"
3
+ version = "2.1.0"
4
4
  description = "Secure file encryption for secrets/configs"
5
5
  authors = [{name = "Josef Fuchs"}]
6
6
  license = {text = "Apache-2"}
@@ -24,7 +24,7 @@ vaulttool = "vaulttool.cli:app"
24
24
 
25
25
  [tool.poetry]
26
26
  name = "vaulttool"
27
- version = "2.0.4"
27
+ version = "2.1.0"
28
28
  description = "Secure file encryption for secrets/configs"
29
29
  authors = ["Josef Fuchs"]
30
30
  license = "Apache-2"
@@ -1,17 +1,18 @@
1
1
  """VaultTool - Secure file encryption for secrets and configuration files.
2
2
 
3
3
  This package provides secure encryption and management of sensitive files using
4
- AES-256-CBC encryption with HMAC authentication.
4
+ AES-256-GCM authenticated encryption (legacy AES-256-CBC vaults remain readable).
5
5
  """
6
6
 
7
7
  import logging
8
8
  import sys
9
+ from importlib.metadata import PackageNotFoundError, version
9
10
  from typing import Optional
10
11
 
11
- __version__ = "2.0.0"
12
-
13
- # Default logger for the package
14
- _logger: Optional[logging.Logger] = None
12
+ try: # pragma: no cover - depends on how the package is installed
13
+ __version__ = version("vaulttool")
14
+ except PackageNotFoundError: # pragma: no cover
15
+ __version__ = "0.0.0+unknown"
15
16
 
16
17
 
17
18
  def get_logger(name: str = "vaulttool") -> logging.Logger:
@@ -77,9 +78,6 @@ def setup_logging(
77
78
  # Prevent propagation to root logger to avoid duplicate messages
78
79
  logger.propagate = False
79
80
 
80
- global _logger
81
- _logger = logger
82
-
83
81
  return logger
84
82
 
85
83
 
@@ -15,12 +15,13 @@ Available commands:
15
15
  """
16
16
 
17
17
  import logging
18
+ import os
18
19
  import sys
19
20
  import secrets
20
21
  from pathlib import Path
21
22
  from datetime import datetime
22
23
  import typer
23
- from . import setup_logging, get_logger
24
+ from . import setup_logging, __version__
24
25
  from .core import VaultTool
25
26
 
26
27
  # Create app with proper help text
@@ -28,7 +29,7 @@ from .core import VaultTool
28
29
  app = typer.Typer(
29
30
  help="""Secure file encryption for secrets and configuration files.
30
31
 
31
- Encrypts sensitive files using AES-256-CBC and manages their encrypted counterparts.
32
+ Encrypts sensitive files using AES-256-GCM and manages their encrypted counterparts.
32
33
 
33
34
  \b
34
35
  Key Options:
@@ -83,52 +84,37 @@ def _setup_cli_logging(verbose: bool = False, quiet: bool = False) -> logging.Lo
83
84
  return setup_logging(level=level, include_timestamp=False)
84
85
 
85
86
 
86
- def _get_version() -> str:
87
- """Get the version of vaulttool package."""
88
- logger = get_logger(__name__)
87
+ def _write_private_file(path: Path, content: str, exclusive: bool = False) -> None:
88
+ """Write a file that is only readable by its owner (mode 0600).
89
89
 
90
- try:
91
- from importlib.metadata import version
92
- pkg_version = version("vaulttool")
93
- logger.debug(f"Retrieved version from importlib.metadata: {pkg_version}")
94
- return pkg_version
95
- except ImportError:
96
- # importlib.metadata not available in older Python versions
97
- logger.debug("importlib.metadata not available, trying fallback")
98
- except Exception as e:
99
- # Package not found or other metadata error
100
- logger.warning(f"Failed to get version from metadata: {e}")
90
+ The permissions are applied with ``os.open`` at creation time, so the file
91
+ is never world-readable, not even briefly (``write_text`` + ``chmod`` leaves
92
+ such a window open).
101
93
 
102
- # Fallback - try to read from pyproject.toml if available
94
+ Args:
95
+ path: Destination path.
96
+ content: Text to write.
97
+ exclusive: If True, fail instead of overwriting an existing file.
98
+ """
99
+ flags = os.O_WRONLY | os.O_CREAT | (os.O_EXCL if exclusive else os.O_TRUNC)
100
+ fd = os.open(path, flags, 0o600)
103
101
  try:
104
- from pathlib import Path
105
-
106
- # Look for pyproject.toml in parent directories
107
- current_dir = Path(__file__).parent
108
- logger.debug(f"Looking for pyproject.toml starting from {current_dir}")
109
-
110
- for level in range(3): # Check up to 3 levels up
111
- pyproject_path = current_dir / "pyproject.toml"
112
- if pyproject_path.exists():
113
- logger.debug(f"Found pyproject.toml at {pyproject_path}")
114
- with open(pyproject_path, "r") as f:
115
- content = f.read()
116
- # Simple parsing for version
117
- for line in content.split('\n'):
118
- if line.strip().startswith('version = "'):
119
- fallback_version = line.split('"')[1]
120
- logger.debug(f"Extracted version from pyproject.toml: {fallback_version}")
121
- return fallback_version
122
- current_dir = current_dir.parent
123
- logger.debug(f"Level {level + 1}: No pyproject.toml found, checking parent")
124
-
125
- except (IOError, OSError) as e:
126
- logger.warning(f"Failed to read pyproject.toml: {e}")
127
- except Exception as e:
128
- logger.warning(f"Unexpected error reading pyproject.toml: {e}")
102
+ if hasattr(os, "fchmod"):
103
+ os.fchmod(fd, 0o600)
104
+ os.write(fd, content.encode("utf-8"))
105
+ os.fsync(fd)
106
+ finally:
107
+ os.close(fd)
129
108
 
130
- logger.debug("Using development version fallback")
131
- return "unknown (development version)"
109
+
110
+ def _get_version() -> str:
111
+ """Return the installed VaultTool version.
112
+
113
+ The version is resolved once, at import time, from the installed package
114
+ metadata (see :mod:`vaulttool`), so ``pyproject.toml`` never has to be
115
+ parsed at runtime.
116
+ """
117
+ return __version__
132
118
 
133
119
 
134
120
  @app.command("generate-key")
@@ -219,9 +205,8 @@ Examples:
219
205
  # Ensure parent directory exists
220
206
  key_path.parent.mkdir(parents=True, exist_ok=True)
221
207
 
222
- # Write new key
223
- key_path.write_text(new_key + "\n")
224
- key_path.chmod(0o600)
208
+ # Create the key with 0600 permissions from the start
209
+ _write_private_file(key_path, new_key + "\n", exclusive=True)
225
210
 
226
211
  if not quiet:
227
212
  typer.echo(f"✅ Successfully created new key file: {key_path}")
@@ -319,9 +304,8 @@ Examples:
319
304
  # Read old key
320
305
  old_key = key_path.read_text()
321
306
 
322
- # Write backup
323
- backup_path.write_text(old_key)
324
- backup_path.chmod(0o600)
307
+ # Write backup (0600, never overwrite an existing backup)
308
+ _write_private_file(backup_path, old_key, exclusive=True)
325
309
 
326
310
  if not quiet:
327
311
  typer.echo(f" ✅ Old key backed up to: {backup_path}")
@@ -334,8 +318,7 @@ Examples:
334
318
 
335
319
  # Write new key
336
320
  try:
337
- key_path.write_text(new_key + "\n")
338
- key_path.chmod(0o600)
321
+ _write_private_file(key_path, new_key + "\n")
339
322
 
340
323
  if not quiet:
341
324
  typer.echo(f" ✅ New key written to: {key_path}")
@@ -645,7 +628,20 @@ Example:
645
628
 
646
629
  try:
647
630
  vt = VaultTool()
648
- vt.check_ignore_task()
631
+ result = vt.check_ignore_task()
632
+
633
+ if not quiet:
634
+ typer.echo("\n" + "=" * 60)
635
+ typer.echo("Check Ignore Summary:")
636
+ typer.echo(f" Total: {result['total']}")
637
+ typer.echo(f" Ignored: {result['ignored']}")
638
+ typer.echo(f" Not ignored: {len(result['not_ignored'])}")
639
+ typer.echo("=" * 60)
640
+ for not_ignored in result["not_ignored"]:
641
+ typer.echo(f" \u26a0 {not_ignored}", err=True)
642
+
643
+ if result["not_ignored"]:
644
+ sys.exit(1)
649
645
  except Exception as e:
650
646
  typer.echo(f"ERROR: {e}", err=True)
651
647
  sys.exit(1)
@@ -157,8 +157,8 @@ def load_config(path: str = ".vaulttool.yml") -> Dict[str, Any]:
157
157
 
158
158
  Example:
159
159
  >>> config = load_config()
160
- >>> print(config['options']['algorithm'])
161
- 'aes-256-cbc'
160
+ >>> print(config['options']['suffix'])
161
+ '.vault'
162
162
 
163
163
  >>> # With environment override:
164
164
  >>> os.environ['VAULTTOOL_OPTIONS_KEY_FILE'] = '/custom/key'