Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand All @@ -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()
Expand Down
Loading