Skip to content

Commit

Permalink
πŸ”– From test β†’ Bump version: v1.1.9-test into prod (#43)
Browse files Browse the repository at this point in the history
Automatically created pull request for release v1.1.9-test into prod
branch.
  • Loading branch information
JuanVilla424 authored Oct 30, 2024
2 parents 32ee0d0 + ddeeeed commit dc5714c
Show file tree
Hide file tree
Showing 11 changed files with 973 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.1.8
current_version = 1.1.9
commit = True
tag = False

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# πŸ—„οΈ Scripts Repository

![CI/CD](https://img.shields.io/badge/CI/CD-Pipeline-blue)
![Status](https://img.shields.io/badge/Status-Stable-green.svg)
![Python](https://img.shields.io/badge/Python-3.11%2B-blue.svg)
![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)

This repository contains a collection of base Python scripts that are invoked by the CI/CD processes of other repositories, especially the template repository. These scripts are used for formatting, checking files, version control, and updating the year in file headers or documentation.

## πŸ“š Table of Contents
Expand Down
3 changes: 2 additions & 1 deletion control_commit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def emit(self, record):
)
self.stream.write(msg + self.terminator)
self.flush()
except Exception:
except Exception as e_handle_emit:
logger.debug(f"SafeStreamHandler error: {e_handle_emit}")
self.handleError(record)

safe_console_handler = SafeStreamHandler()
Expand Down
18 changes: 18 additions & 0 deletions crypto_controller/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Password KP Settings
## Password Key Pair (API-Token Mode)
# API_URI="https://tu.dominio.com/private-key" <- Uncomment and comment KP_PASSWORD
# API_TOKEN_SECURITY="api_token" <- Uncomment and comment KP_PASSWORD
# API_TIMEOUT=12 <- Uncomment and comment KP_PASSWORD
### OR
## Pasword Key Pair (Local Mode)
KP_PASSWORD="<28 (Chars)>"

# Certificate Vault Settings
CERT_EXPIRATION_YEARS=6

# Expiration Notifications Settings
SMTP_SERVER=smtp.example.com
SMTP_PORT=587
SMTP_USER=[email protected]
SMTP_PASSWORD=your_email_password
ALERT_RECIPIENT=[email protected]
219 changes: 219 additions & 0 deletions crypto_controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# πŸ” CryptoController

![Status](https://img.shields.io/badge/Status-Stable-green.svg)
![Python](https://img.shields.io/badge/Python-3.11%2B-blue.svg)
![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)

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.

## πŸ“š Table of Contents

- [Features](#-features)
- [Installation](#-installation)
- [Configuration](#-configuration)
- [Usage](#-usage)
- [Initialization](#-initialization)
- [Renewing Keys](#-renewing-keys)
- [Encrypting Data](#-encrypting-data)
- [Decrypting Data](#-decrypting-data)
- [Checking Status](#-checking-status)
- [Environment Variables](#-environment-variables)
- [Logging](#-logging)
- [License](#-license)
- [Contact](#-contact)

## ✨ Features

- **Hybrid Encryption:** Combines AES (symmetric) and RSA (asymmetric) encryption for enhanced security.
- **Key Management:** Generates, verifies, and renews RSA key pairs securely.
- **Expiration Handling:** Tracks key expiration dates and sends email alerts before keys expire.
- **Status Reporting:** Provides detailed status reports of the cryptographic setup.
- **Secure Storage:** Stores keys in a protected certificate vault with appropriate permissions.
- **Logging:** Comprehensive logging with rotating file handlers for easy monitoring and debugging.

## πŸ› οΈ Installation

1. **Clone the Repository:**

```bash
cd crypto_controller
```

2. **Create a Virtual Environment**

```bash
python -m venv venv
```

3. **Activate the Virtual Environment**

On Unix or MacOS:

```bash
source venv/bin/activate
```

On Windows:

```bash
.\venv\Scripts\activate
```

- or

```bash
powershell.exe -ExecutionPolicy Bypass -File .\venv\Scripts\Activate.ps1
```

4. **Upgrade pip**

```bash
pip install --upgrade pip
```

5. **Install Dependencies**

```bash
pip install -r requirements.txt
```

- Deactivate the Virtual Environment

When you're done, deactivate the environment:

```bash
deactivate
```

## βš™οΈ Configuration

**Environment Variables**:

Create a .env file in the project root directory and populate it with the following variables:

```bash
# Password KP Settings
## Password Key Pair (API-Token Mode)
# API_URI="https://tu.dominio.com/private-key" <- Uncomment and comment KP_PASSWORD
# API_TOKEN_SECURITY="api_token" <- Uncomment and comment KP_PASSWORD
# API_TIMEOUT=12 <- Uncomment and comment KP_PASSWORD
### OR
## Password Key Pair (Local Mode)
KP_PASSWORD="<28 (Chars)>"

# Certificate Vault Settings
CERT_EXPIRATION_YEARS=6

# Expiration Notifications Settings
SMTP_SERVER=smtp.example.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your_email_password
[email protected]
```

- Descriptions:
- API_URI: Password API mode base URI.
- API_TOKEN_SECURITY: Password API mode token security.
- API_TIMEOUT: Password API mode timeout.
- KP_PASSWORD: Password plain mode, used it or API vars.
- CERT_EXPIRATION_YEARS: Number of years before key expiration.
- SMTP_SERVER: SMTP server address for sending emails.
- SMTP_PORT: SMTP server port.
- SMTP_USER: SMTP server username.
- SMTP_PASSWORD: SMTP server password.
- ALERT_RECIPIENT: Email address to receive expiration alerts.

## πŸš€ Usage

CryptoController supports several operations: init, renew, encrypt, decrypt, and status.

### πŸ“¦ Initialization

Generates a new RSA key pair and sets up the certificate vault.

```bash
python main.py init --log-level DEBUG
```

Options:
--cert-location: Directory to store certificates (default: certs in the current directory).
--key-pair-name: Name of the key pair (default: Crypto-Key-Pair-<YEAR>).
--log-level: Logging level (INFO or DEBUG).

### πŸ”„ Renewing Keys

Renews existing keys by cleaning the vault and generating new keys.

```bash
python main.py renew --log-level DEBUG
```

### πŸ”’ Encrypting Data

Encrypts plain text using hybrid encryption.

```bash
python main.py encrypt "Your sensitive data here" --log-level DEBUG
```

Output: Encrypted Base64 string.

### πŸ”“ Decrypting Data

Decrypts previously encrypted data.

```bash
python main.py decrypt "EncryptedBase64StringHere" --log-level DEBUG
```

Output: Decrypted plain text.

### πŸ“ Checking Status

Retrieves and displays the current status of the CryptoController.

```bash
python main.py status --log-level DEBUG
```

### πŸ“œ Environment Variables

Ensure all required environment variables are set in the .env file:

Password KP Settings:
Password Key Pair (API-Token Mode):
API_URI: Password API mode base URI.
API_TOKEN_SECURITY: Password API mode token security.
API_TIMEOUT: Password API mode timeout.

Pasword Key Pair (Local Mode):
KP_PASSWORD: Password plain mode, used it or API vars.

Certificate Vault Settings:
CERT_EXPIRATION_YEARS: Number of years before key expiration.

Expiration Notifications Settings:
SMTP_SERVER: SMTP server address for sending emails.
SMTP_PORT: SMTP server port.
SMTP_USER: SMTP server username.
SMTP_PASSWORD: SMTP server password.
ALERT_RECIPIENT: Email address to receive expiration alerts.

## πŸ“Š Logging

Logs are maintained in crypto_controller.log with rotating file handlers to prevent excessive file sizes.

Log Levels:
INFO: General operational messages.
DEBUG: Detailed diagnostic information.

## πŸ“« Contact

For any inquiries or support, please open an issue or contact [[email protected]](mailto:[email protected]).

---

## πŸ“œ License

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.
Loading

0 comments on commit dc5714c

Please sign in to comment.