37 lines
No EOL
1.2 KiB
Python
37 lines
No EOL
1.2 KiB
Python
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:
|
|
# Receive message from the client
|
|
encrypted_message = request.data
|
|
|
|
# Open our private key
|
|
with open("ssl/server_private.pem","r") as f_public:
|
|
pubi_k = rsa.PrivateKey.load_pkcs1(f_public.read())
|
|
|
|
# Decrypt the message and post-it
|
|
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)
|
|
|