Broker/Protocol Analyse
This commit is contained in:
1 parent
c477a05f03
commit
268e150f2b
7 files changed
+868
-2
No files matched your search
@@ -65,6 +65,10 @@ def ws(ws, tenant):
|
||||
|
||||
msg = WSMessage.from_json(data)
|
||||
if not msg:
|
||||
current_app.logger.warning(
|
||||
'WebSocket-Nachricht ist kein gültiges JSON: tenant=%s account=%s length=%s',
|
||||
tenant_id, account_id, len(data)
|
||||
)
|
||||
continue
|
||||
|
||||
# Die Absender-ID stammt immer aus der Session und kann vom Client
|
||||
@@ -76,15 +80,25 @@ def ws(ws, tenant):
|
||||
token, session_id = _parse_auth_payload(msg.msg)
|
||||
if not session_id:
|
||||
session_id = getattr(msg, 'session_id', None)
|
||||
if session_id:
|
||||
msg.session_id = session_id
|
||||
if not token or not broker.authenticate(
|
||||
tenant_id, account_id, token, session_id
|
||||
):
|
||||
broker.log_incoming(
|
||||
tenant_id, msg, recipients=[],
|
||||
note='Code-0-Handshake fehlgeschlagen'
|
||||
)
|
||||
current_app.logger.warning(
|
||||
'WebSocket-Authentifizierung fehlgeschlagen: tenant=%s account=%s',
|
||||
tenant_id, account_id
|
||||
)
|
||||
ws.close()
|
||||
break
|
||||
broker.log_incoming(
|
||||
tenant_id, msg, recipients=[account_id],
|
||||
note='Code-0-Handshake erfolgreich'
|
||||
)
|
||||
# Bestätigt dem Client den erfolgreichen Handshake. Erst jetzt
|
||||
# darf er gepufferte fachliche Nachrichten senden.
|
||||
broker.send_to_connection(
|
||||
@@ -97,6 +111,10 @@ def ws(ws, tenant):
|
||||
# Fachliche Nachrichten sind erst nach erfolgreicher
|
||||
# Authentifizierung erlaubt.
|
||||
if not broker.is_authenticated(tenant_id, account_id):
|
||||
broker.log_incoming(
|
||||
tenant_id, msg, recipients=[],
|
||||
note='Nachricht vor Code-0-Authentifizierung'
|
||||
)
|
||||
ws.close()
|
||||
break
|
||||
|
||||
|
||||
Reference in new issue
Block a user