|
2 | 2 |
|
3 | 3 | ## Supported Versions |
4 | 4 |
|
5 | | -Currently, only the latest major version of the Crypto module receives security updates. |
| 5 | +Only the latest major version of **maatify/crypto** receives security updates. |
6 | 6 |
|
7 | | -| Version | Supported | |
8 | | -| ------- | ------------------ | |
9 | | -| 1.x | :white_check_mark: | |
| 7 | +| Version | Supported | |
| 8 | +| ------- | ---------- | |
| 9 | +| 1.x | ✅ | |
| 10 | + |
| 11 | +--- |
10 | 12 |
|
11 | 13 | ## Cryptographic Guarantees |
12 | 14 |
|
13 | | -This module provides the following strict cryptographic guarantees: |
| 15 | +The library provides the following strict cryptographic guarantees: |
| 16 | + |
| 17 | +1. **Authenticated Encryption (AEAD)** |
| 18 | + All reversible encryption uses modern AEAD algorithms. |
| 19 | + The default implementation uses **AES-256-GCM**, ensuring confidentiality and integrity. |
| 20 | + Any modification of ciphertext or metadata is detected during decryption. |
| 21 | + |
| 22 | +2. **Domain Separation (HKDF)** |
| 23 | + Context-based encryption derives unique keys using **HKDF (RFC 5869)**. |
| 24 | + Each context (e.g. `auth:session:v1`) produces an independent encryption key, preventing cross-domain compromise. |
| 25 | + |
| 26 | +3. **Secure Password Hashing** |
| 27 | + Passwords are hashed using **Argon2id**. |
| 28 | + The system supports an optional but highly recommended **global pepper** applied via HMAC-SHA256 before hashing. |
| 29 | + |
| 30 | +4. **Fail-Closed Design** |
| 31 | + Any cryptographic failure results in an **immediate exception**. |
| 32 | + The library never: |
| 33 | + - falls back to weaker algorithms |
| 34 | + - silently ignores failures |
| 35 | + - returns partially decrypted data |
| 36 | + |
| 37 | +5. **Key Rotation Safety** |
| 38 | + The system supports multiple keys with lifecycle states: |
| 39 | + - **ACTIVE** – used for encryption |
| 40 | + - **INACTIVE** – preserved for decryption |
| 41 | + - **RETIRED** – legacy decryption only |
| 42 | + |
| 43 | + Exactly one key must always be **ACTIVE**. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Safe Usage Guidelines |
| 48 | + |
| 49 | +### Protect Your Root Keys and Peppers |
| 50 | + |
| 51 | +The security of this library depends entirely on the secrecy of: |
| 52 | + |
| 53 | +- encryption root keys |
| 54 | +- password peppers |
| 55 | + |
| 56 | +Never hardcode them in source code. |
| 57 | + |
| 58 | +Use secure storage mechanisms such as: |
| 59 | + |
| 60 | +- environment variables |
| 61 | +- secret managers |
| 62 | +- vault systems |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +### Prefer Context-Based Encryption |
| 67 | + |
| 68 | +Always prefer: |
| 69 | + |
| 70 | +```php |
| 71 | +$crypto->context("domain:entity:v1"); |
| 72 | +```` |
14 | 73 |
|
15 | | -1. **Authenticated Encryption (AEAD):** All reversible encryption uses AEAD algorithms (e.g., XChaCha20-Poly1305 or AES-256-GCM). Data cannot be tampered with without detection. |
16 | | -2. **Domain Separation (HKDF):** Context-based encryption derives unique, independent keys for different domains (contexts). A compromised key in one domain does not compromise data in another. |
17 | | -3. **Secure Password Hashing:** Passwords are hashed using state-of-the-art algorithms (Argon2id) and support an optional, highly recommended global pepper (HMAC-SHA256) to mitigate offline attacks. |
18 | | -4. **Fail-Closed Design:** Any cryptographic failure (e.g., missing keys, invalid tags, malformed data, unsupported algorithms) results in an immediate exception. The module will never fall back to an insecure state or return partial/corrupted data. |
19 | | -5. **Seamless Key Rotation:** The system supports multiple keys with distinct states (Active, Inactive, Retired) to allow seamless decryption of legacy data while ensuring new data is always encrypted with the current Active key. |
| 74 | +This ensures proper **HKDF domain separation**. |
20 | 75 |
|
21 | | -## Safe Usage Warnings |
| 76 | +Direct encryption: |
22 | 77 |
|
23 | | -- **Protect Your Root Keys and Peppers:** The security of this module depends entirely on the secrecy of your injected root keys and password peppers. Do not hardcode them. Store them securely (e.g., in a secrets manager or environment variables) and inject them at runtime. |
24 | | -- **Use Contexts (`cryptoProvider->context(...)`) over Direct Encryption:** Always prefer context-based encryption to ensure proper domain separation. Only use direct encryption (`cryptoProvider->direct(...)`) if you have a specific, justifiable reason to bypass HKDF. |
25 | | -- **Do Not Ignore Exceptions:** Ensure your application handles exceptions thrown by the Crypto module gracefully. A thrown exception indicates a serious security condition (e.g., attempted tampering, missing key). |
26 | | -- **Do Not Modify Core Algorithms:** The core algorithms and primitives are intentionally locked down. Do not attempt to bypass them or introduce custom, unverified cryptographic logic. |
| 78 | +```php |
| 79 | +$crypto->direct(); |
| 80 | +``` |
| 81 | + |
| 82 | +bypasses HKDF and should only be used for: |
| 83 | + |
| 84 | +* infrastructure secrets |
| 85 | +* internal system encryption |
| 86 | +* controlled environments where domain separation is unnecessary |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +### Always Handle Exceptions |
| 91 | + |
| 92 | +Cryptographic operations may throw exceptions when: |
| 93 | + |
| 94 | +* ciphertext is corrupted |
| 95 | +* authentication tags fail |
| 96 | +* keys are missing |
| 97 | +* metadata is invalid |
| 98 | + |
| 99 | +These exceptions indicate **security-relevant conditions** and must never be ignored. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +### Do Not Modify Cryptographic Primitives |
| 104 | + |
| 105 | +The algorithms and primitives in this library are intentionally restricted. |
| 106 | + |
| 107 | +Do **not**: |
| 108 | + |
| 109 | +* replace algorithms |
| 110 | +* add fallback ciphers |
| 111 | +* inject custom crypto logic |
| 112 | + |
| 113 | +Doing so may introduce severe vulnerabilities. |
| 114 | + |
| 115 | +--- |
27 | 116 |
|
28 | 117 | ## Reporting a Vulnerability |
29 | 118 |
|
30 | | -If you discover a security vulnerability within this module, please report it immediately. |
| 119 | +If you discover a security vulnerability in **maatify/crypto**, please report it responsibly. |
| 120 | + |
| 121 | +**Do not open a public GitHub issue.** |
| 122 | + |
| 123 | +Instead, send a report to: |
| 124 | + |
| 125 | +``` |
| 126 | +security@maatify.com |
| 127 | +``` |
| 128 | + |
| 129 | +Please include: |
31 | 130 |
|
32 | | -**Do not open a public issue.** |
| 131 | +* description of the vulnerability |
| 132 | +* steps to reproduce |
| 133 | +* affected versions |
33 | 134 |
|
34 | | -Please send an email to the security contact for this repository. We will acknowledge receipt of your vulnerability report and strive to send you regular updates about our progress. If you do not receive a response within 48 hours, please follow up. |
| 135 | +We will acknowledge receipt within **48 hours** and work with you to resolve the issue responsibly. |
0 commit comments