diff options
author | href <href@random.sh> | 2018-12-08 17:32:58 +0100 |
---|---|---|
committer | href <href@random.sh> | 2018-12-14 13:05:47 +0100 |
commit | 7facbb2b8d68abc608d6d36f21207d5c0f131029 (patch) | |
tree | 2cf3f10e7d2f4ef3db0610af28a288b23a3b5fdd /lib | |
parent | 324933a0ac8db810669375315d43fc9250a93a7b (diff) | |
download | pleroma-7facbb2b8d68abc608d6d36f21207d5c0f131029.tar.gz |
Push.Subscription: convert base64 to base64 urlsafe
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/push/subscription.ex | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index cfab7a98e..1ad405daf 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -37,8 +37,8 @@ defmodule Pleroma.Web.Push.Subscription do user_id: user.id, token_id: token.id, endpoint: endpoint, - key_auth: key_auth, - key_p256dh: key_p256dh, + key_auth: ensure_base64_urlsafe(key_auth), + key_p256dh: ensure_base64_urlsafe(key_p256dh), data: alerts(params) }) end @@ -63,4 +63,14 @@ defmodule Pleroma.Web.Push.Subscription do sub -> Repo.delete(sub) end end + + # Some webpush clients (e.g. iOS Toot!) use an non urlsafe base64 as an encoding for the key. + # However, the web push rfs specify to use base64 urlsafe, and the `web_push_encryption` library we use + # requires the key to be properly encoded. So we just convert base64 to urlsafe base64. + defp ensure_base64_urlsafe(string) do + string + |> String.replace("+", "-") + |> String.replace("/", "_") + |> String.replace("=", "") + end end |