From e2eaa5c988d017d0bf0f5516306c023ef3f13f2d Mon Sep 17 00:00:00 2001 From: Daniel Bimschas Date: Thu, 30 Nov 2023 15:57:10 +0100 Subject: [PATCH] Allow to configure if pushkey should be converted to hex before sending to APNs (#344) Some APNs libraries give the pushkey in hex directly, but sygnal assumes that the pushkey is given in base64 (and attempts to convert it to hex). This adds a configuration option to avoid this processing / assumption. --- changelog.d/344.feature | 1 + sygnal.yaml.sample | 5 +++++ sygnal/apnspushkin.py | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelog.d/344.feature diff --git a/changelog.d/344.feature b/changelog.d/344.feature new file mode 100644 index 00000000..bbc908d1 --- /dev/null +++ b/changelog.d/344.feature @@ -0,0 +1 @@ +Add a new `convert_device_token_to_hex` configuration option for APNs apps, to allow disabling the conversion of device tokens from base64 to hex. \ No newline at end of file diff --git a/sygnal.yaml.sample b/sygnal.yaml.sample index 9a700e8d..810821fc 100644 --- a/sygnal.yaml.sample +++ b/sygnal.yaml.sample @@ -197,6 +197,11 @@ apps: # # # # The default is 'production'. Uncomment to use the sandbox instance. # #platform: sandbox + # # + # # Specifies whether to convert the device push token from base 64 to hex. + # # Defaults to True, set this to False if your client library provides a + # # push token in hex format. + # #convert_device_token_to_hex: false # This is an example GCM/FCM push configuration. # diff --git a/sygnal/apnspushkin.py b/sygnal/apnspushkin.py index 92b77e13..f227dc5a 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -238,7 +238,12 @@ async def _dispatch_request( """ span.set_tag("apns_id", notif_id) - device_token = base64.b64decode(device.pushkey).hex() + # Some client libraries will provide the push token in hex format already. Avoid + # attempting to convert from base 64 to hex. + if self.get_config("convert_device_token_to_hex", bool, True): + device_token = base64.b64decode(device.pushkey).hex() + else: + device_token = device.pushkey request = NotificationRequest( device_token=device_token,