|
20 | 20 | app = Flask(__name__) |
21 | 21 |
|
22 | 22 | # Configuration |
23 | | -CONFIG_FILE = os.environ.get('ORACLE_CONFIG', '/etc/chelon/chelon.conf') |
| 23 | +CONFIG_FILE = os.environ.get('CHELON_CONFIG', '/etc/chelon/chelon.conf') |
24 | 24 | DATA_DIR = '/var/lib/chelon' |
25 | 25 |
|
26 | 26 | def load_config(path): |
@@ -184,8 +184,38 @@ def sign_repodata(): |
184 | 184 |
|
185 | 185 | if __name__ == '__main__': |
186 | 186 | # Run the Flask app |
187 | | - host = os.environ.get('ORACLE_HOST', '127.0.0.1') |
188 | | - port = int(os.environ.get('ORACLE_PORT', 5050)) |
| 187 | + host = os.environ.get('CHELON_HOST', '127.0.0.1') |
| 188 | + port = int(os.environ.get('CHELON_PORT', 5050)) |
189 | 189 |
|
190 | 190 | logger.info(f"Starting Chelon service on {host}:{port}") |
191 | | - app.run(host=host, port=port, debug=False) |
| 191 | + |
| 192 | + # SSL Configuration |
| 193 | + ssl_cert = os.environ.get('CHELON_SSL_CERT', config.get('CHELON_SSL_CERT')) |
| 194 | + ssl_key = os.environ.get('CHELON_SSL_KEY', config.get('CHELON_SSL_KEY')) |
| 195 | + ssl_ca = os.environ.get('CHELON_SSL_CA', config.get('CHELON_SSL_CA')) |
| 196 | + verify_client = os.environ.get('CHELON_SSL_VERIFY_CLIENT', config.get('CHELON_SSL_VERIFY_CLIENT', 'false')).lower() == 'true' |
| 197 | + |
| 198 | + ssl_context = None |
| 199 | + if ssl_cert and ssl_key: |
| 200 | + if not os.path.exists(ssl_cert) or not os.path.exists(ssl_key): |
| 201 | + logger.error(f"SSL cert or key not found: {ssl_cert}, {ssl_key}") |
| 202 | + sys.exit(1) |
| 203 | + |
| 204 | + import ssl |
| 205 | + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) |
| 206 | + ssl_context.load_cert_chain(ssl_cert, ssl_key) |
| 207 | + |
| 208 | + if ssl_ca: |
| 209 | + if not os.path.exists(ssl_ca): |
| 210 | + logger.error(f"SSL CA not found: {ssl_ca}") |
| 211 | + sys.exit(1) |
| 212 | + ssl_context.load_verify_locations(ssl_ca) |
| 213 | + |
| 214 | + if verify_client: |
| 215 | + ssl_context.verify_mode = ssl.CERT_REQUIRED |
| 216 | + else: |
| 217 | + ssl_context.verify_mode = ssl.CERT_OPTIONAL |
| 218 | + |
| 219 | + logger.info(f"SSL Enabled. Client Verify: {verify_client}") |
| 220 | + |
| 221 | + app.run(host=host, port=port, debug=False, ssl_context=ssl_context) |
0 commit comments