Developed by:
- Mikha Gracia Sugiono
- Azarel Grahandito A
- Alvin Vincent Oswald Reba
This Flask-based application provides secure file management and controlled file sharing for users. It includes features like encryption of files using AES, DES, or RC4 algorithms via PyCryptodome for secure data protection. Users can securely upload, encrypt, share, and manage permissions on files within a collaborative environment. The application integrates Flask-Migrate for database migrations and SQLAlchemy to interact with a PostgreSQL database for managing stored files, users, and activity logs.
Key Libraries:
- Flask-Migrate: For database schema migrations.
- SQLAlchemy: ORM for handling PostgreSQL interactions.
- PyCryptodome: For AES, DES, and RC4 encryption and decryption algorithms.
- Flask-Session: For secure session management.
- Python 3.7 or higher
- Pip (Python package manager)
- PostgreSQL as the primary database
- Virtual Environment (recommended for isolated dependencies)
Follow these steps to set up and run the application:
git clone https://github.com/username/project-name.git
cd project-namepython3 -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activateInstall required libraries using requirements.txt:
pip install -r requirements.txtIf requirements.txt is unavailable, you can manually install key dependencies:
pip install Flask Flask-Migrate Flask-SQLAlchemy psycopg2-binary pycryptodome python-dotenv-
Access PostgreSQL:
psql -U postgres
-
Create a Database and User for the Application:
CREATE DATABASE database_name; CREATE USER user_name WITH PASSWORD 'user_password'; ALTER ROLE user_name SET client_encoding TO 'utf8'; ALTER ROLE user_name SET default_transaction_isolation TO 'read committed'; ALTER ROLE user_name SET timezone TO 'UTC'; GRANT ALL PRIVILEGES ON DATABASE database_name TO user_name;
The config.py file contains settings for application configuration, including encryption parameters, database credentials, and the location of the uploaded files.
import os
class Config:
SECRET_KEY = os.getenv('SECRET_KEY') or os.urandom(32)
DB_USER = os.getenv('DB_USER', 'your_db_user')
DB_HOST = os.getenv('DB_HOST', 'localhost')
DB_PASSWORD = os.getenv('DB_PASSWORD', 'your_db_password')
DB_NAME = os.getenv('DB_NAME', 'your_db_name')
SQLALCHEMY_DATABASE_URI = f'postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/{DB_NAME}'
SQLALCHEMY_TRACK_MODIFICATIONS = False
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads')
PERMANENT_SESSION_LIFETIME = 1800The application requires a MASTER_KEY for secure encryption and decryption. This key is auto-generated and stored securely in .bashrc to protect user-specific keys against unauthorized access.
-
Run the
master.pyscript to create and store theMASTER_KEY:python master.py
-
Reload the terminal session to load the key into the environment:
source ~/.bashrc
Purpose of MASTER_KEY Storage in .bashrc:
- By storing the
MASTER_KEYin.bashrc, the application can retrieve the key only when necessary, preventing exposure of the key within the codebase or database. - Each user's key is encrypted with this
MASTER_KEY, adding a layer of security. Even if database access is compromised, encrypted user keys cannot be decrypted without theMASTER_KEYstored securely in the user’s environment.
Use Flask-Migrate to initialize and apply migrations:
-
Initialize Migration Directory:
flask --app server db init
-
Create a Migration:
flask --app server db migrate -m "Initial migration with tables and relationships" -
Apply Migrations:
flask --app server db upgrade
If Migration Errors Occur:
flask db stamp headStart the Flask application:
python server.pyBy default, the application runs at http://127.0.0.1:5001/.
-
User Registration & Authentication:
- Secure login and session management using encrypted passwords.
-
File Encryption & Storage:
- Users can encrypt files using AES, DES, or RC4 before uploading them. The files are encrypted client-side to ensure they remain protected in storage.
-
Secure File Sharing:
- Users can request access to files shared by other users. File owners can review, approve, or reject requests with specific access durations.
-
Activity Logging:
- Tracks key actions, such as file uploads, access requests, approvals, and downloads. Logs use usernames rather than IDs for easy identification.
-
Access Management:
- Owners have control over shared files, including options to block, unblock, and revoke access to previously shared files.
-
Session Management:
- Session timeout automatically logs out inactive users after 30 minutes, enhancing security.
server.py: Main application file defining routes and logic.config.py: Stores configuration settings (database credentials, session configurations).models.py: Contains database models (User, Files, ShareRequest, ActivityLog).templates/: HTML templates for user interaction.master.py: Generates theMASTER_KEYto encrypt/decrypt user data.
-
Encrypting and Uploading Files:
- Users select an encryption algorithm and upload a file. The encrypted file is stored securely in the database.
-
Requesting Access to Shared Files:
- Users can enter the username of another user to request access to their shared files. The owner of the file can approve or reject the request and set an access duration.
-
Managing Access:
- File owners can view and manage incoming access requests, with options to approve, block, unblock, or delete access. Approved access can be time-limited based on the specified duration.
-
Activity Logs:
- The system logs actions like encryption, file sharing, and access approvals, providing a comprehensive overview of recent activities using usernames for easy tracking.
-
MASTER_KEYin.bashrc:- The
MASTER_KEY, used for encrypting user-specific keys, is stored in.bashrcfor enhanced security, making it accessible only in a secure environment. This prevents key exposure in code or database, adding a layer of security to user data.
- The
-
User-Specific Encryption Keys:
- Each user’s encryption key is securely encrypted with the
MASTER_KEY, ensuring that even if unauthorized access occurs, these keys remain protected.
- Each user’s encryption key is securely encrypted with the
-
Session Timeout:
- User sessions expire after 30 minutes of inactivity, reducing the risk of unauthorized access through unattended sessions.
-
Encrypted File Storage:
- Files are stored in their encrypted form, making it difficult for unauthorized users to retrieve meaningful data from the database directly.
- File Decryption Preview: Allow users to preview files without downloading.
- Admin Dashboard: Add a management interface for admins to oversee user activity and manage permissions.
- Role-Based Access Control (RBAC): Implement different user roles to improve access control.
[Specify License Here]