From b0d397142b8066d92510c2fa234996f957b26380 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 16 Jan 2025 11:17:16 +1100 Subject: [PATCH 1/7] fix a case for PNs with no content --- .../Sending & Receiving/Notifications/PushNotificationAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 5d27f601f..71ce28c64 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -438,7 +438,7 @@ public enum PushNotificationAPI { guard let notificationData: Data = notification.data, notification.info.dataLength == notificationData.count - else { return (nil, notification.info, .failure) } + else { return (nil, notification.info, .failureNoContent) } // Success, we have the notification content return (notificationData, notification.info, .success) From 4303179b3f973a933b47fb967e823ba5611a0b3d Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 16 Jan 2025 15:12:42 +1100 Subject: [PATCH 2/7] add some logs for testing --- .../Notifications/PushNotificationAPI.swift | 10 ++++++++-- SessionUtilitiesKit/Utilities/BencodeResponse.swift | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 71ce28c64..642b767c4 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -428,7 +428,10 @@ public enum PushNotificationAPI { ), let notification: BencodeResponse = try? BencodeDecoder(using: dependencies) .decode(BencodeResponse.self, from: decryptedData) - else { return (nil, .invalid, .failure) } + else { + SNLog("Failed to decrypt or decode notification") + return (nil, .invalid, .failure) + } // If the metadata says that the message was too large then we should show the generic // notification (this is a valid case) @@ -438,7 +441,10 @@ public enum PushNotificationAPI { guard let notificationData: Data = notification.data, notification.info.dataLength == notificationData.count - else { return (nil, notification.info, .failureNoContent) } + else { + SNLog("Get notification data failed") + return (nil, notification.info, .failureNoContent) + } // Success, we have the notification content return (notificationData, notification.info, .success) diff --git a/SessionUtilitiesKit/Utilities/BencodeResponse.swift b/SessionUtilitiesKit/Utilities/BencodeResponse.swift index d3ec8e4b9..b2b2b784e 100644 --- a/SessionUtilitiesKit/Utilities/BencodeResponse.swift +++ b/SessionUtilitiesKit/Utilities/BencodeResponse.swift @@ -15,13 +15,16 @@ extension BencodeResponse: Decodable { info = try { /// First try to decode it directly if let info: T = try? container.decode(T.self) { + SNLog("Successfully decoded info directly") return info } /// If that failed then we need to reset the container and try decode it as a JSON string container = try decoder.unkeyedContainer() let infoString: String = try container.decode(String.self) + SNLog("Successfully decoded info to JSON string") let infoData: Data = try infoString.data(using: .ascii) ?? { throw NetworkError.parsingFailed }() + SNLog("Successfully decoded info to JSON data") return try JSONDecoder(using: decoder.dependencies).decode(T.self, from: infoData) }() From 6aa77a966a112528c292542a1c8915057921b8a5 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 16 Jan 2025 15:13:04 +1100 Subject: [PATCH 3/7] update version & build number --- Session.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index ca7b114b1..ac7236f95 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -7825,6 +7825,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 527; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -7862,6 +7863,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; + MARKETING_VERSION = 2.8.7; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -7894,6 +7896,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 527; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -7931,6 +7934,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; + MARKETING_VERSION = 2.8.7; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; From 07e75d0cca36b703a0d0dfea4242a2be835d3aff Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Fri, 17 Jan 2025 10:13:47 +1100 Subject: [PATCH 4/7] add check for PNs from other namespaces --- .../Notifications/PushNotificationAPI.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 642b767c4..7774ac454 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -435,7 +435,16 @@ public enum PushNotificationAPI { // If the metadata says that the message was too large then we should show the generic // notification (this is a valid case) - guard !notification.info.dataTooLong else { return (nil, notification.info, .successTooLong) } + guard !notification.info.dataTooLong else { + SNLog("Ignoring notification due to data being too long") + return (nil, notification.info, .successTooLong) + } + + // Only show notifcations for messages from default namespace + guard notification.info.namespace == .default else { + SNLog("Ignoring notification due to namespace being \(notification.info.namespace) instead of default") + return (nil, notification.info, .failureNoContent) + } // Check that the body we were given is valid guard From 8c02b7ac08abf9afa5b803336510a88df6289245 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Mon, 20 Jan 2025 09:57:22 +1100 Subject: [PATCH 5/7] fix a case where the received notification payload is not valid either for legacy or current PN protocol --- .../Notifications/PushNotificationAPI.swift | 1 + .../NotificationServiceExtension.swift | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 7774ac454..e476b9a5e 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -441,6 +441,7 @@ public enum PushNotificationAPI { } // Only show notifcations for messages from default namespace + // TODO: Add group messages namespace guard notification.info.namespace == .default else { SNLog("Ignoring notification due to namespace being \(notification.info.namespace) instead of default") return (nil, notification.info, .failureNoContent) diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 1780aee91..bf0d0e7eb 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -76,7 +76,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension switch result { // If we got an explicit failure, or we got a success but no content then show // the fallback notification - case .success, .legacySuccess, .failure, .legacyFailure: + case .success, .legacySuccess, .failure: return self.handleFailure(for: notificationContent, error: .processing(result)) // Just log if the notification was too long (a ~2k message should be able to fit so @@ -92,6 +92,10 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension case .failureNoContent: Log.warn("Failed due to missing notification content.") return self.completeSilenty(handledNotification: false) + + case .legacyFailure: + Log.warn("Received a notification without a valid payload.") + return self.completeSilenty(handledNotification: false) } } From d528a70bfc4939d11e3e9c4478138152d115b11b Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 30 Jan 2025 16:14:20 +1100 Subject: [PATCH 6/7] clean up --- SessionUtilitiesKit/Utilities/BencodeResponse.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/SessionUtilitiesKit/Utilities/BencodeResponse.swift b/SessionUtilitiesKit/Utilities/BencodeResponse.swift index b2b2b784e..d3ec8e4b9 100644 --- a/SessionUtilitiesKit/Utilities/BencodeResponse.swift +++ b/SessionUtilitiesKit/Utilities/BencodeResponse.swift @@ -15,16 +15,13 @@ extension BencodeResponse: Decodable { info = try { /// First try to decode it directly if let info: T = try? container.decode(T.self) { - SNLog("Successfully decoded info directly") return info } /// If that failed then we need to reset the container and try decode it as a JSON string container = try decoder.unkeyedContainer() let infoString: String = try container.decode(String.self) - SNLog("Successfully decoded info to JSON string") let infoData: Data = try infoString.data(using: .ascii) ?? { throw NetworkError.parsingFailed }() - SNLog("Successfully decoded info to JSON data") return try JSONDecoder(using: decoder.dependencies).decode(T.self, from: infoData) }() From e88a7ed453a83b0e3050b401ab416af6d0fe5945 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 30 Jan 2025 16:49:26 +1100 Subject: [PATCH 7/7] Allow notifications from non-default namespaces, handle empty data --- .../Notifications/PushNotificationAPI.swift | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index e476b9a5e..86ad23fe6 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -440,17 +440,11 @@ public enum PushNotificationAPI { return (nil, notification.info, .successTooLong) } - // Only show notifcations for messages from default namespace - // TODO: Add group messages namespace - guard notification.info.namespace == .default else { - SNLog("Ignoring notification due to namespace being \(notification.info.namespace) instead of default") - return (nil, notification.info, .failureNoContent) - } - - // Check that the body we were given is valid + // Check that the body we were given is valid and not empty guard let notificationData: Data = notification.data, - notification.info.dataLength == notificationData.count + notification.info.dataLength == notificationData.count, + !notificationData.isEmpty else { SNLog("Get notification data failed") return (nil, notification.info, .failureNoContent)