-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcer_server.py~
28 lines (19 loc) · 876 Bytes
/
cer_server.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import subprocess
from flask import Flask, request, send_from_directory
app = Flask(__name__)
cert_dir = "./Hhome/" # Path to the directory storing certificates
fpath = os.path.join(cert_dir, 'server.key')
def get_serverCert():
subprocess.run(['openssl', 'req', '-x509', '-newkey', 'rsa:2048', '-keyout',
f'{fpath}', '-out', 'server.crt', '-days', '365', '-nodes', '-subj "/CN=CertServer"'])
get_serverCert()
@app.route('/<filename>', methods=['GET'])
def download_file(filename):
if os.path.exists(os.path.join(cert_dir, filename)):
return send_from_directory(cert_dir, filename, as_attachment=True)
else:
return "File not found", 404
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, ssl_context=(
os.path.join(cert_dir, 'server.crt'), os.path.join(cert_dir, 'server.key')) # HTTPS