crypto
¶
Cryptography module for secure token and configuration management.
This module provides Fernet-based symmetric encryption for tokens and configuration data.
CryptographyManager
¶
Manages Fernet-based encryption for tokens and configuration data.
Initialize CryptographyManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance for error reporting |
required |
key_file_path
|
str
|
Path to encryption key file |
'encryption.key'
|
Source code in src/app/features/crypto/encryption.py
is_token_encrypted
staticmethod
¶
Check if a token is encrypted (Fernet format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Token to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if token appears to be Fernet-encrypted |
Source code in src/app/features/crypto/encryption.py
encrypt_token
¶
Encrypt a token using Fernet symmetric encryption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Token to encrypt |
required |
key
|
str | None
|
Optional base64-encoded encryption key |
None
|
passphrase
|
str | None
|
Optional passphrase for key derivation |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Base64-encoded encrypted token |
Raises:
| Type | Description |
|---|---|
EncryptionError
|
If encryption fails |
Source code in src/app/features/crypto/encryption.py
decrypt_token
¶
Decrypt a token using Fernet symmetric encryption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encrypted_token
|
str
|
Base64-encoded encrypted token |
required |
key
|
str | None
|
Optional base64-encoded encryption key |
None
|
passphrase
|
str | None
|
Optional passphrase for key derivation |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Decrypted token |
Raises:
| Type | Description |
|---|---|
DecryptionError
|
If decryption fails |
InvalidTokenError
|
If token format is invalid |
Source code in src/app/features/crypto/encryption.py
rotate_key
¶
Rotate the encryption key to a new one.
WARNING: This method only rotates the encryption key file itself. Any data encrypted with the old key will become inaccessible after rotation unless you: 1. Decrypt all existing data with the old key BEFORE calling this method 2. Re-encrypt the data with the new key AFTER rotation completes
For automatic token migration, use the orchestrator's rotate_keys command
which handles the complete re-encryption workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_passphrase
|
str | None
|
Passphrase for new key derivation |
None
|
backup_old_key
|
bool
|
Whether to backup the old key |
True
|
Raises:
| Type | Description |
|---|---|
KeyGenerationError
|
If key rotation fails |
Source code in src/app/features/crypto/encryption.py
get_secure_config_status
¶
Get security configuration status.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Status dictionary with current configuration |
Source code in src/app/features/crypto/encryption.py
CryptographyError
¶
Bases: Exception
Base exception for cryptography operations.
Initialize CryptographyError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error description |
required |
details
|
dict[str, Any] | None
|
Additional error context |
None
|
Source code in src/app/features/crypto/exceptions.py
DecryptionError
¶
Bases: CryptographyError
Exception raised when decryption fails.
Source code in src/app/features/crypto/exceptions.py
EncryptionError
¶
Bases: CryptographyError
Exception raised when encryption fails.
Source code in src/app/features/crypto/exceptions.py
InvalidKeyError
¶
Bases: CryptographyError
Exception raised when encryption key is invalid.
Source code in src/app/features/crypto/exceptions.py
InvalidTokenError
¶
Bases: CryptographyError
Exception raised when token format is invalid.
Source code in src/app/features/crypto/exceptions.py
KeyGenerationError
¶
Bases: CryptographyError
Exception raised when key generation fails.