From ad42b6cd4cf183b4596f29b85291388eb1f93188 Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Mon, 4 May 2026 14:46:40 +0200 Subject: [PATCH 1/2] feat(push): Optionally use OAEP padding Signed-off-by: alperozturk96 --- .../nextcloud/client/jobs/NotificationWork.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt b/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt index b852fea8176e..4fbdaf74a056 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt @@ -55,6 +55,7 @@ import java.io.IOException import java.security.GeneralSecurityException import java.security.PrivateKey import java.security.SecureRandom +import javax.crypto.BadPaddingException import javax.crypto.Cipher import javax.inject.Inject @@ -96,9 +97,7 @@ class NotificationWork constructor( base64DecodedSubject ) if (signatureVerification != null && signatureVerification.signatureValid) { - val cipher = Cipher.getInstance("RSA/None/PKCS1Padding") - cipher.init(Cipher.DECRYPT_MODE, privateKey) - val decryptedSubject = cipher.doFinal(base64DecodedSubject) + val decryptedSubject = decryptSubject(privateKey, base64DecodedSubject) val gson = Gson() val decryptedPushMessage = gson.fromJson( String(decryptedSubject), @@ -124,6 +123,17 @@ class NotificationWork constructor( return Result.success() } + private fun decryptSubject(privateKey: PrivateKey, base64DecodedSubject: ByteArray): ByteArray = try { + val cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding") + cipher.init(Cipher.DECRYPT_MODE, privateKey) + cipher.doFinal(base64DecodedSubject) + } catch (e: BadPaddingException) { + Log_OC.e(TAG, "OAEP padding failed, trying PKCS1 for compatibility", e) + val cipher = Cipher.getInstance("RSA/None/PKCS1Padding") + cipher.init(Cipher.DECRYPT_MODE, privateKey) + cipher.doFinal(base64DecodedSubject) + } + @Suppress("LongMethod") // legacy code private fun sendNotification(notification: Notification, user: User) { val randomId = SecureRandom() From e9bb9d5d426d15e694b11eab6433b7f92321ad28 Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Mon, 4 May 2026 15:17:32 +0200 Subject: [PATCH 2/2] add note Signed-off-by: alperozturk96 --- .../android/services/firebase/NCFirebaseMessagingService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java b/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java index ce6beea9b7e9..c1854f1c59e8 100644 --- a/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java +++ b/app/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java @@ -28,6 +28,9 @@ import androidx.annotation.NonNull; import dagger.android.AndroidInjection; +/** + * Works only with gplay variant and Google Play Services installed devices. + */ public class NCFirebaseMessagingService extends FirebaseMessagingService { @Inject AppPreferences preferences; @Inject UserAccountManager accountManager;