Skip to content

Commit 74a536c

Browse files
making temporary files for ssl certificates
1 parent 687f56e commit 74a536c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

a2rchi/bin/service_chat.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from flask import Flask
99
from flask_login import LoginManager
10+
import tempfile
1011

1112
global_config = Config_Loader().config["global"]
1213
app_config = Config_Loader().config["interfaces"]["chat_app"]
@@ -79,10 +80,24 @@ def load_user(user_id):
7980
print(f"Starting Chat Service with (host, port): ({app_config['HOST']}, {app_config['PORT']})")
8081
app = FlaskAppWrapper(app)
8182
if app_config["HOSTNAME"] == "a2rchi.mit.edu":
83+
8284
print("Adding SSL certificates for a2rchi.mit.edu")
83-
certificate_path = os.getenv("A2RCHI_SSL_CERTIFICATE_FILE")
84-
key_path = os.getenv("A2RCHI_SSL_CERTIFICATE_KEY_FILE")
85-
app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context=(certificate_path, key_path))
85+
86+
#get the ssl cert and key and save them to temporary files
87+
ssl_cert = read_secret("A2RCHI_SSL_CERTIFICATE")
88+
ssl_key = read_secret("A2RCHI_SSL_CERTIFICATE_KEY")
89+
cert_file = tempfile.NamedTemporaryFile(delete=False)
90+
key_file = tempfile.NamedTemporaryFile(delete=False)
91+
cert_file.write(ssl_cert.encode())
92+
key_file.write(ssl_key.encode())
93+
94+
app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context=(cert_file.name, key_file.name))
95+
96+
#remove the temp ssl cert and key temp files
97+
os.unlink(cert_file.name)
98+
os.unlink(key_file.name)
99+
86100
else:
101+
87102
print("No SSL certificate for this server found. Starting up with adhoc SSL certification")
88103
app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context="adhoc")

0 commit comments

Comments
 (0)