arp-spoofing/RSA/server/main.py
2025-01-25 01:08:15 +01:00

34 lines
No EOL
1.1 KiB
Python

import base64
import ssl
from flask import Flask, jsonify, render_template, request
import rsa
app = Flask(__name__)
app.config['SECRET_KEY'] = 'c&S2QL9DDhZjwlqPoRYRGSN6gOidjaC9f25CW#SF1AinsMg7$3*JxC3e^9FnuliC5DWfhAPwiPcAMJcutBn#5k&VsIP0KBOMf9VvzKTN@Wuuq5i*UjoonTZEMHiyabpI' # Required for Flask-WTF
# SSL Configuration
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile='ssl/CA.crt', keyfile='ssl/CA.pem')
@app.route("/")
def index():
return render_template("index.html")
@app.route('/data', methods=['POST'])
def receive():
try:
encrypted_message = request.data
with open("ssl/server_private.pem","r") as f_public:
pubi_k = rsa.PrivateKey.load_pkcs1(f_public.read())
decrypt_message = rsa.decrypt(encrypted_message,pubi_k).decode()
print("Message received :",decrypt_message)
return jsonify({'status': 'success', 'decrypted_message': decrypt_message}), 200
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 400
if __name__ == "__main__":
app.run(ssl_context=context, host='localhost', port=5000)