From def4960be6630d1319f6a3bbd2dc95940c210879 Mon Sep 17 00:00:00 2001 From: mishnz Date: Mon, 2 Jan 2023 23:56:52 +1300 Subject: [PATCH 1/2] Second fix for MIME64 inconsistency in serverKey. The previous fix https://github.com/mastodon/mastodon-android/pull/486 would break any connections to any instances using WEB_SAFE MIME64 encoding on the serverKey, which actually appears to be the usual case. This update reverts to the previous logic, but also converts standard MIME64 characters ('/' and '+') to their WEB_SAFE equivalents. This ensures the standard case of WEB_SAFE BASE64 serverKeys and the anomolous case of DEFAULT BASE64 keys both work. --- .../org/joinmastodon/android/api/PushSubscriptionManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java index 01822fb8..710fda0c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java @@ -162,7 +162,9 @@ public class PushSubscriptionManager{ @Override public void onSuccess(PushSubscription result){ MastodonAPIController.runInBackground(()->{ - serverKey=deserializeRawPublicKey(Base64.decode(result.serverKey, Base64.DEFAULT)); + result.serverKey=result.serverKey.replace('/','_'); + result.serverKey=result.serverKey.replace('+','-'); + deserializeRawPublicKey(Base64.decode(result.serverKey, Base64.URL_SAFE)); AccountSession session=AccountSessionManager.getInstance().tryGetAccount(accountID); if(session==null) From 726498276127f9bb37892c33e6834402b36c8b3f Mon Sep 17 00:00:00 2001 From: mishnz Date: Tue, 3 Jan 2023 00:15:45 +1300 Subject: [PATCH 2/2] serverKey assignment was missing, corrected. --- .../org/joinmastodon/android/api/PushSubscriptionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java index 710fda0c..3294a02f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java @@ -164,7 +164,7 @@ public class PushSubscriptionManager{ MastodonAPIController.runInBackground(()->{ result.serverKey=result.serverKey.replace('/','_'); result.serverKey=result.serverKey.replace('+','-'); - deserializeRawPublicKey(Base64.decode(result.serverKey, Base64.URL_SAFE)); + serverKey=deserializeRawPublicKey(Base64.decode(result.serverKey, Base64.URL_SAFE)); AccountSession session=AccountSessionManager.getInstance().tryGetAccount(accountID); if(session==null)