P2 finito tout marche

This commit is contained in:
vSpaike 2025-01-25 01:08:15 +01:00
parent f5be203305
commit 9e2fd37838
15 changed files with 238 additions and 143 deletions

View file

@ -1,12 +1,15 @@
import base64
import ssl
from flask import Flask, render_template, request
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.key')
context.load_cert_chain(certfile='ssl/CA.crt', keyfile='ssl/CA.pem')
@app.route("/")
def index():
@ -14,10 +17,18 @@ def index():
@app.route('/data', methods=['POST'])
def receive():
encrypted_data = request.form.get('data', None) # Safely get form data
if encrypted_data:
return f"Received encrypted data: {encrypted_data}", 200
return "No data received", 400
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='0.0.0.0', port=5000) # Allow external access
app.run(ssl_context=context, host='localhost', port=5000)