mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix owntracks topic in encrypted ios (#19220)
* Fix owntracks topic * Warn if per-topic secret and using HTTP
This commit is contained in:
parent
031ee71adf
commit
7d9e257713
@ -316,13 +316,18 @@ async def async_handle_waypoints_message(hass, context, message):
|
||||
@HANDLERS.register('encrypted')
|
||||
async def async_handle_encrypted_message(hass, context, message):
|
||||
"""Handle an encrypted message."""
|
||||
plaintext_payload = _decrypt_payload(context.secret, message['topic'],
|
||||
if 'topic' not in message and isinstance(context.secret, dict):
|
||||
_LOGGER.error("You cannot set per topic secrets when using HTTP")
|
||||
return
|
||||
|
||||
plaintext_payload = _decrypt_payload(context.secret, message.get('topic'),
|
||||
message['data'])
|
||||
|
||||
if plaintext_payload is None:
|
||||
return
|
||||
|
||||
decrypted = json.loads(plaintext_payload)
|
||||
if 'topic' in message and 'topic' not in decrypted:
|
||||
decrypted['topic'] = message['topic']
|
||||
|
||||
await async_handle_message(hass, context, decrypted)
|
||||
|
@ -137,15 +137,16 @@ async def handle_webhook(hass, webhook_id, request):
|
||||
user = headers.get('X-Limit-U')
|
||||
device = headers.get('X-Limit-D', user)
|
||||
|
||||
if user is None:
|
||||
if user:
|
||||
topic_base = re.sub('/#$', '', context.mqtt_topic)
|
||||
message['topic'] = '{}/{}/{}'.format(topic_base, user, device)
|
||||
|
||||
elif message['_type'] != 'encrypted':
|
||||
_LOGGER.warning('No topic or user found in message. If on Android,'
|
||||
' set a username in Connection -> Identification')
|
||||
# Keep it as a 200 response so the incorrect packet is discarded
|
||||
return json_response([])
|
||||
|
||||
topic_base = re.sub('/#$', '', context.mqtt_topic)
|
||||
message['topic'] = '{}/{}/{}'.format(topic_base, user, device)
|
||||
|
||||
hass.helpers.dispatcher.async_dispatcher_send(
|
||||
DOMAIN, hass, context, message)
|
||||
return json_response([])
|
||||
|
Loading…
x
Reference in New Issue
Block a user