|
| 1 | +# π CryptoController |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +CryptoController is a robust Python application designed for secure key management, encryption, and decryption operations. It leverages hybrid encryption (AES + RSA) to ensure data confidentiality and integrity, making it ideal for applications requiring strong cryptographic safeguards. |
| 8 | + |
| 9 | +## π Table of Contents |
| 10 | + |
| 11 | +- [Features](#-features) |
| 12 | +- [Installation](#-installation) |
| 13 | +- [Configuration](#-configuration) |
| 14 | +- [Usage](#-usage) |
| 15 | + - [Initialization](#-initialization) |
| 16 | + - [Renewing Keys](#-renewing-keys) |
| 17 | + - [Encrypting Data](#-encrypting-data) |
| 18 | + - [Decrypting Data](#-decrypting-data) |
| 19 | + - [Checking Status](#-checking-status) |
| 20 | +- [Environment Variables](#-environment-variables) |
| 21 | +- [Logging](#-logging) |
| 22 | +- [License](#-license) |
| 23 | +- [Contact](#-contact) |
| 24 | + |
| 25 | +## β¨ Features |
| 26 | + |
| 27 | +- **Hybrid Encryption:** Combines AES (symmetric) and RSA (asymmetric) encryption for enhanced security. |
| 28 | +- **Key Management:** Generates, verifies, and renews RSA key pairs securely. |
| 29 | +- **Expiration Handling:** Tracks key expiration dates and sends email alerts before keys expire. |
| 30 | +- **Status Reporting:** Provides detailed status reports of the cryptographic setup. |
| 31 | +- **Secure Storage:** Stores keys in a protected certificate vault with appropriate permissions. |
| 32 | +- **Logging:** Comprehensive logging with rotating file handlers for easy monitoring and debugging. |
| 33 | + |
| 34 | +## π οΈ Installation |
| 35 | + |
| 36 | +1. **Clone the Repository:** |
| 37 | + |
| 38 | + ```bash |
| 39 | + cd crypto_controller |
| 40 | + ``` |
| 41 | + |
| 42 | +2. **Create a Virtual Environment** |
| 43 | + |
| 44 | + ```bash |
| 45 | + python -m venv venv |
| 46 | + ``` |
| 47 | + |
| 48 | +3. **Activate the Virtual Environment** |
| 49 | + |
| 50 | + On Unix or MacOS: |
| 51 | + |
| 52 | + ```bash |
| 53 | + source venv/bin/activate |
| 54 | + ``` |
| 55 | + |
| 56 | + On Windows: |
| 57 | + |
| 58 | + ```bash |
| 59 | + .\venv\Scripts\activate |
| 60 | + ``` |
| 61 | + |
| 62 | + - or |
| 63 | + |
| 64 | + ```bash |
| 65 | + powershell.exe -ExecutionPolicy Bypass -File .\venv\Scripts\Activate.ps1 |
| 66 | + ``` |
| 67 | + |
| 68 | +4. **Upgrade pip** |
| 69 | + |
| 70 | + ```bash |
| 71 | + pip install --upgrade pip |
| 72 | + ``` |
| 73 | + |
| 74 | +5. **Install Dependencies** |
| 75 | + |
| 76 | + ```bash |
| 77 | + pip install -r requirements.txt |
| 78 | + ``` |
| 79 | + |
| 80 | + - Deactivate the Virtual Environment |
| 81 | + |
| 82 | + When you're done, deactivate the environment: |
| 83 | + |
| 84 | + ```bash |
| 85 | + deactivate |
| 86 | + ``` |
| 87 | + |
| 88 | +## βοΈ Configuration |
| 89 | + |
| 90 | +**Environment Variables**: |
| 91 | + |
| 92 | +Create a .env file in the project root directory and populate it with the following variables: |
| 93 | + |
| 94 | +```bash |
| 95 | +# Password KP Settings |
| 96 | +## Password Key Pair (API-Token Mode) |
| 97 | +# API_URI="https://tu.dominio.com/private-key" <- Uncomment and comment KP_PASSWORD |
| 98 | +# API_TOKEN_SECURITY="api_token" <- Uncomment and comment KP_PASSWORD |
| 99 | +# API_TIMEOUT=12 <- Uncomment and comment KP_PASSWORD |
| 100 | +### OR |
| 101 | +## Password Key Pair (Local Mode) |
| 102 | +KP_PASSWORD="<28 (Chars)>" |
| 103 | + |
| 104 | +# Certificate Vault Settings |
| 105 | +CERT_EXPIRATION_YEARS=6 |
| 106 | + |
| 107 | +# Expiration Notifications Settings |
| 108 | +SMTP_SERVER=smtp.example.com |
| 109 | +SMTP_PORT=587 |
| 110 | + |
| 111 | +SMTP_PASSWORD=your_email_password |
| 112 | + |
| 113 | +``` |
| 114 | + |
| 115 | +- Descriptions: |
| 116 | + - API_URI: Password API mode base URI. |
| 117 | + - API_TOKEN_SECURITY: Password API mode token security. |
| 118 | + - API_TIMEOUT: Password API mode timeout. |
| 119 | + - KP_PASSWORD: Password plain mode, used it or API vars. |
| 120 | + - CERT_EXPIRATION_YEARS: Number of years before key expiration. |
| 121 | + - SMTP_SERVER: SMTP server address for sending emails. |
| 122 | + - SMTP_PORT: SMTP server port. |
| 123 | + - SMTP_USER: SMTP server username. |
| 124 | + - SMTP_PASSWORD: SMTP server password. |
| 125 | + - ALERT_RECIPIENT: Email address to receive expiration alerts. |
| 126 | + |
| 127 | +## π Usage |
| 128 | + |
| 129 | +CryptoController supports several operations: init, renew, encrypt, decrypt, and status. |
| 130 | + |
| 131 | +### π¦ Initialization |
| 132 | + |
| 133 | +Generates a new RSA key pair and sets up the certificate vault. |
| 134 | + |
| 135 | +```bash |
| 136 | +python main.py init --log-level DEBUG |
| 137 | +``` |
| 138 | + |
| 139 | + Options: |
| 140 | + --cert-location: Directory to store certificates (default: certs in the current directory). |
| 141 | + --key-pair-name: Name of the key pair (default: Crypto-Key-Pair-<YEAR>). |
| 142 | + --log-level: Logging level (INFO or DEBUG). |
| 143 | + |
| 144 | +### π Renewing Keys |
| 145 | + |
| 146 | +Renews existing keys by cleaning the vault and generating new keys. |
| 147 | + |
| 148 | +```bash |
| 149 | +python main.py renew --log-level DEBUG |
| 150 | +``` |
| 151 | + |
| 152 | +### π Encrypting Data |
| 153 | + |
| 154 | +Encrypts plain text using hybrid encryption. |
| 155 | + |
| 156 | +```bash |
| 157 | +python main.py encrypt "Your sensitive data here" --log-level DEBUG |
| 158 | +``` |
| 159 | + |
| 160 | + Output: Encrypted Base64 string. |
| 161 | + |
| 162 | +### π Decrypting Data |
| 163 | + |
| 164 | +Decrypts previously encrypted data. |
| 165 | + |
| 166 | +```bash |
| 167 | +python main.py decrypt "EncryptedBase64StringHere" --log-level DEBUG |
| 168 | +``` |
| 169 | + |
| 170 | + Output: Decrypted plain text. |
| 171 | + |
| 172 | +### π Checking Status |
| 173 | + |
| 174 | +Retrieves and displays the current status of the CryptoController. |
| 175 | + |
| 176 | +```bash |
| 177 | +python main.py status --log-level DEBUG |
| 178 | +``` |
| 179 | + |
| 180 | +### π Environment Variables |
| 181 | + |
| 182 | +Ensure all required environment variables are set in the .env file: |
| 183 | + |
| 184 | + Password KP Settings: |
| 185 | + Password Key Pair (API-Token Mode): |
| 186 | + API_URI: Password API mode base URI. |
| 187 | + API_TOKEN_SECURITY: Password API mode token security. |
| 188 | + API_TIMEOUT: Password API mode timeout. |
| 189 | + |
| 190 | + Pasword Key Pair (Local Mode): |
| 191 | + KP_PASSWORD: Password plain mode, used it or API vars. |
| 192 | + |
| 193 | + Certificate Vault Settings: |
| 194 | + CERT_EXPIRATION_YEARS: Number of years before key expiration. |
| 195 | + |
| 196 | + Expiration Notifications Settings: |
| 197 | + SMTP_SERVER: SMTP server address for sending emails. |
| 198 | + SMTP_PORT: SMTP server port. |
| 199 | + SMTP_USER: SMTP server username. |
| 200 | + SMTP_PASSWORD: SMTP server password. |
| 201 | + ALERT_RECIPIENT: Email address to receive expiration alerts. |
| 202 | + |
| 203 | +## π Logging |
| 204 | + |
| 205 | +Logs are maintained in crypto_controller.log with rotating file handlers to prevent excessive file sizes. |
| 206 | + |
| 207 | + Log Levels: |
| 208 | + INFO: General operational messages. |
| 209 | + DEBUG: Detailed diagnostic information. |
| 210 | + |
| 211 | +## π« Contact |
| 212 | + |
| 213 | +For any inquiries or support, please open an issue or contact [[email protected]](mailto:[email protected]). |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +## π License |
| 218 | + |
| 219 | +2024 - This project is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html). You are free to use, modify, and distribute this software under the terms of the GPL-3.0 license. For more details, please refer to the [LICENSE](../LICENSE) file included in this repository. |
0 commit comments