From 228e7c3b5d82079916b5ea63f95d9693f7c92610 Mon Sep 17 00:00:00 2001 From: Daniel Bimschas Date: Thu, 17 Aug 2023 09:43:28 +0200 Subject: [PATCH 1/6] Allow to configure if pushkey should be converted to hex before sending to APNs --- sygnal.yaml.sample | 5 +++++ sygnal/apnspushkin.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sygnal.yaml.sample b/sygnal.yaml.sample index 0a2c9b3c..22891bd7 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 use a hexadecimally encoded push token. If True + # # (default) the pushkey received is trancoded from base64 to hex. If False + # # the pushkey received is passed to APNs as is. + # #apns_device_token_use_hex: false # This is an example GCM/FCM push configuration. # diff --git a/sygnal/apnspushkin.py b/sygnal/apnspushkin.py index e47374d7..e8b59649 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -242,7 +242,10 @@ async def _dispatch_request( log.info(f"Sending as APNs-ID {notif_id}") span.set_tag("apns_id", notif_id) - device_token = base64.b64decode(device.pushkey).hex() + if self.get_config("apns_device_token_use_hex", bool, True): + device_token = base64.b64decode(device.pushkey).hex() + else: + device_token = device.pushkey request = NotificationRequest( device_token=device_token, From 6f3bfb82d6882635bc29c42b3fac6343b08b8b11 Mon Sep 17 00:00:00 2001 From: Daniel Bimschas Date: Thu, 30 Nov 2023 10:33:52 +0100 Subject: [PATCH 2/6] Add comment to base64->hex conversion Co-authored-by: Patrick Cloke --- sygnal/apnspushkin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sygnal/apnspushkin.py b/sygnal/apnspushkin.py index e8b59649..c77a0a13 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -242,6 +242,8 @@ async def _dispatch_request( log.info(f"Sending as APNs-ID {notif_id}") span.set_tag("apns_id", notif_id) + # 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("apns_device_token_use_hex", bool, True): device_token = base64.b64decode(device.pushkey).hex() else: From d0b6f359753285905ee3ab1915759fc5c079ace5 Mon Sep 17 00:00:00 2001 From: Daniel Bimschas Date: Thu, 30 Nov 2023 10:39:01 +0100 Subject: [PATCH 3/6] Simplify configuration sample comment --- sygnal.yaml.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sygnal.yaml.sample b/sygnal.yaml.sample index 22891bd7..5cc22105 100644 --- a/sygnal.yaml.sample +++ b/sygnal.yaml.sample @@ -198,9 +198,9 @@ apps: # # The default is 'production'. Uncomment to use the sandbox instance. # #platform: sandbox # # - # # Specifies whether to use a hexadecimally encoded push token. If True - # # (default) the pushkey received is trancoded from base64 to hex. If False - # # the pushkey received is passed to APNs as is. + # # 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. # #apns_device_token_use_hex: false # This is an example GCM/FCM push configuration. From 2fb22ec403688f0a7192c7cafcbc9015dd179009 Mon Sep 17 00:00:00 2001 From: Daniel Bimschas Date: Thu, 30 Nov 2023 13:42:01 +0100 Subject: [PATCH 4/6] Rename config setting to convert_device_token_to_hex --- sygnal.yaml.sample | 2 +- sygnal/apnspushkin.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sygnal.yaml.sample b/sygnal.yaml.sample index 5cc22105..b62d564f 100644 --- a/sygnal.yaml.sample +++ b/sygnal.yaml.sample @@ -201,7 +201,7 @@ apps: # # 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. - # #apns_device_token_use_hex: false + # #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 c77a0a13..0dd588b1 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -244,7 +244,7 @@ async def _dispatch_request( # 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("apns_device_token_use_hex", bool, True): + if self.get_config("convert_device_token_to_hex", bool, True): device_token = base64.b64decode(device.pushkey).hex() else: device_token = device.pushkey From 745e8d3e22193710770cdd5fb1afc54ed8c5c778 Mon Sep 17 00:00:00 2001 From: Daniel Bimschas Date: Thu, 30 Nov 2023 15:19:32 +0100 Subject: [PATCH 5/6] Add changelog / newsfragment entry --- changelog.d/344.feature | 1 + 1 file changed, 1 insertion(+) 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..c3e1ce14 --- /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. (#344) \ No newline at end of file From 243fe02b50a1f069bd9a548e8fda6266a49a1c0a Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 30 Nov 2023 09:22:34 -0500 Subject: [PATCH 6/6] Update changelog. --- changelog.d/344.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/344.feature b/changelog.d/344.feature index c3e1ce14..bbc908d1 100644 --- a/changelog.d/344.feature +++ b/changelog.d/344.feature @@ -1 +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. (#344) \ No newline at end of file +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