|
5 | 5 | ``docs/design/encryption_architecture_redesign.md``; here is a brief summary |
6 | 6 | of how the pieces fit together: |
7 | 7 |
|
8 | | -**Master key** (``TOMTOOLKIT_FIELD_ENCRYPTION_KEY`` in settings / environment): |
| 8 | +**Master key** (``TOMTOOLKIT_DEK_ENCRYPTION_KEY`` in settings / environment): |
9 | 9 | A Fernet key that never touches the database. It encrypts each user's |
10 | 10 | Data Encryption Key so that database access alone cannot reveal user data. |
11 | 11 |
|
|
54 | 54 | def _get_master_cipher() -> Fernet: |
55 | 55 | """Return a Fernet cipher built from the server-side master key. |
56 | 56 |
|
57 | | - The master key (``TOMTOOLKIT_FIELD_ENCRYPTION_KEY``) lives in the server |
| 57 | + The master key (``TOMTOOLKIT_DEK_ENCRYPTION_KEY``) lives in the server |
58 | 58 | environment, not in the database. It is used only to encrypt and decrypt |
59 | 59 | per-user DEKs — never to encrypt user data directly. |
60 | 60 |
|
61 | 61 | Raises: |
62 | 62 | django.core.exceptions.ImproperlyConfigured: If the setting is missing |
63 | 63 | or empty. |
64 | 64 | """ |
65 | | - key = getattr(settings, 'TOMTOOLKIT_FIELD_ENCRYPTION_KEY', '') |
| 65 | + key = getattr(settings, 'TOMTOOLKIT_DEK_ENCRYPTION_KEY', '') |
66 | 66 | if not key: |
67 | 67 | from django.core.exceptions import ImproperlyConfigured |
68 | 68 | raise ImproperlyConfigured( |
69 | | - "TOMTOOLKIT_FIELD_ENCRYPTION_KEY is not set. This setting is required for " |
| 69 | + "TOMTOOLKIT_DEK_ENCRYPTION_KEY is not set. This setting is required for " |
70 | 70 | "encrypting sensitive user data at rest. Generate one with:\n" |
71 | 71 | " python -c \"from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())\"\n" |
72 | 72 | "Then add it to your environment or settings.py." |
@@ -261,13 +261,13 @@ def rotate_master_key(new_key: str) -> RotationResult: |
261 | 261 | """Re-encrypt all per-user DEKs with a new master key. |
262 | 262 |
|
263 | 263 | Each Profile's ``encrypted_dek`` is decrypted with the current master key |
264 | | - (from ``TOMTOOLKIT_FIELD_ENCRYPTION_KEY``) and re-encrypted with |
| 264 | + (from ``TOMTOOLKIT_DEK_ENCRYPTION_KEY``) and re-encrypted with |
265 | 265 | ``new_key``. The user Profile's plaintext DEK is unchanged — only its |
266 | 266 | encryption layer (i.e. `encrypted_dek`) is replaced. The actual encrypted |
267 | 267 | data is not touched. |
268 | 268 |
|
269 | 269 | After this function completes successfully, the server's |
270 | | - ``TOMTOOLKIT_FIELD_ENCRYPTION_KEY`` must be updated to ``new_key`` and the |
| 270 | + ``TOMTOOLKIT_DEK_ENCRYPTION_KEY`` must be updated to ``new_key`` and the |
271 | 271 | server restarted. Until that happens, the re-encrypted DEKs cannot be |
272 | 272 | decrypted. |
273 | 273 |
|
|
0 commit comments