diff --git a/GPG API for Kigen Flow.postman_collection.json b/GPG API for Kigen Flow.postman_collection.json new file mode 100644 index 0000000..d44b936 --- /dev/null +++ b/GPG API for Kigen Flow.postman_collection.json @@ -0,0 +1,135 @@ +{ + "info": { + "_postman_id": "e77bfc0a-79fb-4594-be9d-06c53989ad2a", + "name": "GPG API for Kigen Flow", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "43522475", + "_collection_link": "https://chintan-533591.postman.co/workspace/Chintan's-Workspace~f62d7ab1-6c32-44dd-894e-371a5145aefa/collection/43522475-e77bfc0a-79fb-4594-be9d-06c53989ad2a?action=share&source=collection_link&creator=43522475" + }, + "item": [ + { + "name": "1. Check & Install GPG", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://3.29.0.254:8080/api/setup/gnupg", + "protocol": "http", + "host": [ + "3", + "29", + "0", + "254" + ], + "port": "8080", + "path": [ + "api", + "setup", + "gnupg" + ] + } + }, + "response": [] + }, + { + "name": "2. Generate GPG Key", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"RollxManager Platform\",\n \"email\": \"user@example.com\",\n \"comment\": \"PGP Key for Kigen\",\n \"passphrase\": \"your-secure-passphrase\"\n}" + }, + "url": { + "raw": "http://3.29.0.254:8080/api/generate-key", + "protocol": "http", + "host": [ + "3", + "29", + "0", + "254" + ], + "port": "8080", + "path": [ + "api", + "generate-key" + ] + } + }, + "response": [] + }, + { + "name": "3. Download Public Key", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://3.29.0.254:8080/api/download/public-key?email=user@example.com", + "protocol": "http", + "host": [ + "3", + "29", + "0", + "254" + ], + "port": "8080", + "path": [ + "api", + "download", + "public-key" + ], + "query": [ + { + "key": "email", + "value": "user@example.com" + } + ] + } + }, + "response": [] + }, + { + "name": "4. Upload GPG Encrypted File & Decrypt", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "file", + "type": "file", + "src": "/path/to/your/zip.gpg" + }, + { + "key": "passphrase", + "value": "your-secure-passphrase", + "type": "text" + } + ] + }, + "url": { + "raw": "http://3.29.0.254:8080/api/upload-decrypt", + "protocol": "http", + "host": [ + "3", + "29", + "0", + "254" + ], + "port": "8080", + "path": [ + "api", + "upload-decrypt" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/Screenshot 2025-07-07 at 12.54.33.png b/Screenshot 2025-07-07 at 12.54.33.png new file mode 100644 index 0000000..48cecce Binary files /dev/null and b/Screenshot 2025-07-07 at 12.54.33.png differ diff --git a/gpg_key_ui_backend.py b/gpg_key_ui_backend.py new file mode 100644 index 0000000..2f5d777 --- /dev/null +++ b/gpg_key_ui_backend.py @@ -0,0 +1,90 @@ +# gpg_api.py + +from flask import Flask, request, jsonify, send_file +import subprocess +import tempfile +import os +from werkzeug.utils import secure_filename + +app = Flask(__name__) +UPLOAD_DIR = "/tmp/gpg_files" +os.makedirs(UPLOAD_DIR, exist_ok=True) + +@app.route("/api/setup/gnupg", methods=["GET"]) +def setup_gnupg(): + try: + subprocess.run(["gpg", "--version"], check=True) + return jsonify({"status": "GnuPG is already installed"}) + except Exception: + subprocess.run(["apt", "update"], check=True) + subprocess.run(["apt", "install", "-y", "gnupg"], check=True) + return jsonify({"status": "GnuPG installed"}) + +@app.route("/api/generate-key", methods=["POST"]) +def generate_key(): + data = request.json + name = data['name'] + email = data['email'] + comment = data.get('comment', '') + passphrase = data['passphrase'] + + key_input = f""" + %echo Generating GPG Key + Key-Type: RSA + Key-Length: 4096 + Name-Real: {name} + Name-Email: {email} + Name-Comment: {comment} + Expire-Date: 0 + Passphrase: {passphrase} + %commit + %echo Done + """ + + with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f: + f.write(key_input) + keyfile_path = f.name + + try: + subprocess.run(["gpg", "--batch", "--generate-key", keyfile_path], check=True) + return jsonify({"status": "Key generated successfully"}) + except subprocess.CalledProcessError as e: + return jsonify({"error": "Key generation failed", "details": str(e)}), 500 + finally: + os.remove(keyfile_path) + +@app.route("/api/download/public-key", methods=["GET"]) +def export_key(): + email = request.args.get('email') + filename = os.path.join(UPLOAD_DIR, f"{secure_filename(email)}_public.asc") + try: + subprocess.run(["gpg", "--armor", "--output", filename, "--export", email], check=True) + return send_file(filename, as_attachment=True) + except Exception as e: + return jsonify({"error": "Export failed", "details": str(e)}), 500 + +@app.route("/api/upload-decrypt", methods=["POST"]) +def upload_and_decrypt(): + if 'file' not in request.files: + return jsonify({"error": "Missing file"}), 400 + file = request.files['file'] + passphrase = request.form.get('passphrase') + + filename = secure_filename(file.filename) + gpg_path = os.path.join(UPLOAD_DIR, filename) + output_path = os.path.join(UPLOAD_DIR, f"decrypted_{filename[:-4]}.zip") + file.save(gpg_path) + + try: + subprocess.run([ + "gpg", "--batch", "--yes", + "--passphrase", passphrase, + "--output", output_path, + "--decrypt", gpg_path + ], check=True) + return send_file(output_path, as_attachment=True) + except subprocess.CalledProcessError as e: + return jsonify({"error": "Decryption failed", "details": str(e)}), 500 + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=8080, debug=True)