From c6a04a2e83c9024de934e86fbf9519b5573b8689 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 21 Sep 2023 21:35:17 -0300 Subject: [PATCH] Disable including timestamp for Session Android It breaks on the extra "t" and "z" fields; we will re-enable once supported and enough time has passed for users to upgrade to a new, supporting release. --- spns/notifiers/firebase.py | 5 ++++- spns/notifiers/huawei.py | 5 ++++- spns/notifiers/util.py | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spns/notifiers/firebase.py b/spns/notifiers/firebase.py index f843a1e..287178b 100644 --- a/spns/notifiers/firebase.py +++ b/spns/notifiers/firebase.py @@ -69,7 +69,10 @@ def validate(msg: Message): def push_notification(msg: Message): data = oxenc.bt_deserialize(msg.data()[0]) - enc_payload = encrypt_notify_payload(data, max_msg_size=MAX_MSG_SIZE) + # TODO: remote `include_ts=False` parameter here start including timestamps; current Android + # release breaks when receiving extra fields, so it is disabled for now until we have a release + # (and enough time for upgrades). + enc_payload = encrypt_notify_payload(data, max_msg_size=MAX_MSG_SIZE, include_ts=False) device_token = data[b"&"].decode() # unique service id, as we returned from validate diff --git a/spns/notifiers/huawei.py b/spns/notifiers/huawei.py index 1562c5d..ce1b03c 100644 --- a/spns/notifiers/huawei.py +++ b/spns/notifiers/huawei.py @@ -68,7 +68,10 @@ def validate(msg: Message): def push_notification(msg: Message): data = oxenc.bt_deserialize(msg.data()[0]) - enc_payload = encrypt_notify_payload(data, max_msg_size=MAX_MSG_SIZE) + # TODO: remote `include_ts=False` parameter here start including timestamps; current Android + # release breaks when receiving extra fields, so it is disabled for now until we have a release + # (and enough time for upgrades). + enc_payload = encrypt_notify_payload(data, max_msg_size=MAX_MSG_SIZE, include_ts=False) device_token = data[b"&"].decode() # unique service id, as we returned from validate diff --git a/spns/notifiers/util.py b/spns/notifiers/util.py index e9f13b2..f51e081 100644 --- a/spns/notifiers/util.py +++ b/spns/notifiers/util.py @@ -36,10 +36,14 @@ def encrypt_payload(msg: bytes, enc_key: bytes): return nonce + ciphertext -def encrypt_notify_payload(data: dict, max_msg_size: int = 2500): +def encrypt_notify_payload(data: dict, max_msg_size: int = 2500, include_ts: bool = True): enc_key = data[b"^"] metadata = {"@": data[b"@"].hex(), "#": data[b"#"].decode(), "n": data[b"n"], "t": data[b"t"], "z": data[b"z"]} + if not include_ts: + for t in ("t", "z"): + del metadata[t] + body = data.get(b"~") if body: