Skip to content

Commit d650d90

Browse files
committed
TLS support
Signed-off-by: Scott R. Shinn <scott@atomicorp.com>
1 parent 2db2acb commit d650d90

5 files changed

Lines changed: 41 additions & 11 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ deps:
4747
test-local:
4848
@echo "Starting Chelon service locally on port 5050..."
4949
@echo "Make sure GPG keys are imported first!"
50-
cd server && python3 oracle-service.py
50+
cd server && python3 chelon-service.py

chelon.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ install -d %{buildroot}%{_unitdir}
4646
install -d %{buildroot}%{_localstatedir}/lib/%{name}
4747

4848
# Install server files
49-
install -m 755 server/oracle-service.py %{buildroot}%{_datadir}/%{name}/server/
49+
install -m 755 server/chelon-service.py %{buildroot}%{_datadir}/%{name}/server/
5050
install -m 644 server/signing_engine.py %{buildroot}%{_datadir}/%{name}/server/
5151
install -m 644 server/auth.py %{buildroot}%{_datadir}/%{name}/server/
5252
install -m 644 server/audit.py %{buildroot}%{_datadir}/%{name}/server/

server/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def validate_token(self, token: str) -> Dict:
121121

122122
# Verify secret
123123
secret_hash = hashlib.sha256(secret.encode()).hexdigest()
124-
if secret_hash != token_info['secret_hash']:
124+
if not secrets.compare_digest(secret_hash, token_info['secret_hash']):
125125
raise ValueError("Invalid token secret")
126126

127127
# Check rate limit (Fixed Window)

server/chelon-service.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
app = Flask(__name__)
2121

2222
# 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')
2424
DATA_DIR = '/var/lib/chelon'
2525

2626
def load_config(path):
@@ -184,8 +184,38 @@ def sign_repodata():
184184

185185
if __name__ == '__main__':
186186
# 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))
189189

190190
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)

systemd/chelon.service

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Type=simple
77
User=chelon
88
Group=chelon
99
WorkingDirectory=/usr/share/chelon/server
10-
Environment="ORACLE_HOST=0.0.0.0"
11-
Environment="ORACLE_PORT=5050"
12-
Environment="ORACLE_CONFIG=/etc/chelon/chelon.conf"
13-
ExecStart=/usr/bin/python3 /usr/share/chelon/server/oracle-service.py
10+
Environment="CHELON_HOST=0.0.0.0"
11+
Environment="CHELON_PORT=5050"
12+
Environment="CHELON_CONFIG=/etc/chelon/chelon.conf"
13+
ExecStart=/usr/bin/python3 /usr/share/chelon/server/chelon-service.py
1414
Restart=always
1515
RestartSec=10
1616

0 commit comments

Comments
 (0)