Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32518862
D7873.1767127495.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D7873.1767127495.diff
View Options
diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java b/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
--- a/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
+++ b/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
@@ -9,6 +9,7 @@
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;
+import android.util.JsonReader;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import androidx.lifecycle.Lifecycle;
@@ -21,10 +22,16 @@
import app.comm.android.fbjni.GlobalDBSingleton;
import app.comm.android.fbjni.MessageOperationsUtilities;
import app.comm.android.fbjni.NetworkModule;
+import app.comm.android.fbjni.NotificationsCryptoModule;
import app.comm.android.fbjni.ThreadOperations;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
import me.leolin.shortcutbadger.ShortcutBadger;
public class CommNotificationsHandler extends FirebaseMessagingService {
@@ -33,6 +40,8 @@
private static final String BACKGROUND_NOTIF_TYPE_KEY = "backgroundNotifType";
private static final String SET_UNREAD_STATUS_KEY = "setUnreadStatus";
private static final String NOTIF_ID_KEY = "id";
+ private static final String ENCRYPTED_PAYLOAD_KEY = "encryptedPayload";
+ private static final String ENCRYPTION_FAILED_KEY = "encryptionFailed";
private static final String CHANNEL_ID = "default";
private static final long[] VIBRATION_SPEC = {500, 500};
@@ -78,6 +87,29 @@
handleNotificationRescind(message);
}
+ if (message.getData().get(ENCRYPTED_PAYLOAD_KEY) != null) {
+ try {
+ message = this.decryptRemoteMessage(message);
+ } catch (IOException e) {
+ Log.w(
+ "COMM", "IO exception while parsing notification JSON payload.", e);
+ return;
+ } catch (IllegalStateException e) {
+ Log.w(
+ "COMM",
+ "Notification payload JSON is not {[string]: string} type.",
+ e);
+ return;
+ } catch (Exception e) {
+ Log.w("COMM", "Failed to decrypt encrypted notification", e);
+ return;
+ }
+ } else if ("1".equals(message.getData().get(ENCRYPTION_FAILED_KEY))) {
+ Log.w(
+ "COMM",
+ "Received unencrypted notification for client with existing olm session for notifications");
+ }
+
String badge = message.getData().get(BADGE_KEY);
if (badge != null) {
try {
@@ -205,4 +237,27 @@
intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
}
+
+ private RemoteMessage decryptRemoteMessage(RemoteMessage message)
+ throws IOException, IllegalStateException {
+ String encryptedSerializedPayload =
+ message.getData().get(ENCRYPTED_PAYLOAD_KEY);
+ String decryptedSerializedPayload = NotificationsCryptoModule.decrypt(
+ encryptedSerializedPayload,
+ NotificationsCryptoModule.olmEncryptedTypeMessage(),
+ "CommNotificationsHandler");
+
+ JsonReader decryptedPayloadReader =
+ new JsonReader(new StringReader(decryptedSerializedPayload));
+
+ decryptedPayloadReader.beginObject();
+ while (decryptedPayloadReader.hasNext()) {
+ String payloadFieldName = decryptedPayloadReader.nextName();
+ String payloadFieldValue = decryptedPayloadReader.nextString();
+ message.getData().put(payloadFieldName, payloadFieldValue);
+ }
+ decryptedPayloadReader.endObject();
+
+ return message;
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 30, 8:44 PM (16 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5869896
Default Alt Text
D7873.1767127495.diff (3 KB)
Attached To
Mode
D7873: Implement notification decryption in CommNotificationsHandler
Attached
Detach File
Event Timeline
Log In to Comment