-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: push notification version support (#12)
* Discard invalid notifications. * Run junit tests on github workflows.
- Loading branch information
Showing
14 changed files
with
354 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: JUnit Tests (no end-to-end) | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
jUnit: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Gradle Wrapper Verification | ||
uses: gradle/wrapper-validation-action@v1 | ||
|
||
- name: JDK setup | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'zulu' | ||
java-version: 17 | ||
|
||
- name: run tests | ||
run: ./gradlew test -Dskip.unit-tests=false -Dskip.e2e=true -Dskip.debugVariants=true -Dskip.flavor.unrestricted=true -Dskip.flavor.beta=true | ||
|
||
- name: Test Report | ||
uses: dorny/test-reporter@v1 | ||
if: success() || failure() # run this step even if previous step failed | ||
with: | ||
name: Android Unit Tests | ||
path: test-outputs/**/*.xml | ||
reporter: java-junit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...t/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/core/common/test/UnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package de.tum.informatics.www1.artemis.native_app.core.common.test | ||
|
||
interface UnitTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...de/tum/informatics/www1/artemis/native_app/feature/push/service/PushNotificationCipher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.push.service | ||
|
||
interface PushNotificationCipher { | ||
|
||
fun decipherPushNotification(ciphertext: String, iv: String): String? | ||
} |
10 changes: 10 additions & 0 deletions
10
...e/tum/informatics/www1/artemis/native_app/feature/push/service/PushNotificationHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.push.service | ||
|
||
interface PushNotificationHandler { | ||
|
||
/** | ||
* Handles the receiving of a push notification. The push notification has to be decrypted. | ||
* Based on the type stores it and shows it to the user. | ||
*/ | ||
fun handleServerPushNotification(payload: String) | ||
} |
50 changes: 50 additions & 0 deletions
50
...formatics/www1/artemis/native_app/feature/push/service/impl/PushNotificationCipherImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package de.tum.informatics.www1.artemis.native_app.feature.push.service.impl | ||
|
||
import android.util.Base64 | ||
import de.tum.informatics.www1.artemis.native_app.feature.push.service.PushNotificationCipher | ||
import de.tum.informatics.www1.artemis.native_app.feature.push.service.PushNotificationConfigurationService | ||
import kotlinx.coroutines.runBlocking | ||
import java.security.NoSuchAlgorithmException | ||
import javax.crypto.Cipher | ||
import javax.crypto.NoSuchPaddingException | ||
import javax.crypto.SecretKey | ||
import javax.crypto.spec.IvParameterSpec | ||
|
||
class PushNotificationCipherImpl( | ||
private val pushNotificationConfigurationService: PushNotificationConfigurationService | ||
) : PushNotificationCipher { | ||
|
||
private companion object { | ||
private const val ALGORITHM = "AES/CBC/PKCS7Padding" | ||
|
||
private val cipher: Cipher? = try { | ||
Cipher.getInstance(ALGORITHM) | ||
} catch (e: NoSuchAlgorithmException) { | ||
null | ||
} catch (e: NoSuchPaddingException) { | ||
null | ||
} | ||
} | ||
|
||
override fun decipherPushNotification(ciphertext: String, iv: String): String? = runBlocking { | ||
val key = pushNotificationConfigurationService.getCurrentAESKey() ?: return@runBlocking null | ||
val cipher = cipher ?: return@runBlocking null | ||
|
||
val ivAsBytes = Base64.decode(iv.toByteArray(Charsets.ISO_8859_1), Base64.DEFAULT) | ||
|
||
cipher.decrypt(ciphertext, key, ivAsBytes) ?: return@runBlocking null | ||
} | ||
|
||
private fun Cipher.decrypt(ciphertext: String, key: SecretKey, iv: ByteArray): String? { | ||
return try { | ||
init(Cipher.DECRYPT_MODE, key, IvParameterSpec(iv)) | ||
|
||
val cipherTextBytes = ciphertext.toByteArray(Charsets.ISO_8859_1) | ||
val textBytes = doFinal(Base64.decode(cipherTextBytes, Base64.DEFAULT)) | ||
|
||
String(textBytes, Charsets.UTF_8) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} | ||
} |
Oops, something went wrong.