This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from corona-warn-app/dev
0.8.5
- Loading branch information
Showing
87 changed files
with
12,374 additions
and
948 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
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
132 changes: 132 additions & 0 deletions
132
Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/util/security/DBPasswordTest.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,132 @@ | ||
/****************************************************************************** | ||
* Corona-Warn-App * | ||
* * | ||
* SAP SE and all other contributors / * | ||
* copyright owners license this file to you under the Apache * | ||
* License, Version 2.0 (the "License"); you may not use this * | ||
* file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, * | ||
* software distributed under the License is distributed on an * | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * | ||
* KIND, either express or implied. See the License for the * | ||
* specific language governing permissions and limitations * | ||
* under the License. * | ||
******************************************************************************/ | ||
|
||
package de.rki.coronawarnapp.util.security | ||
|
||
import android.content.Context | ||
import android.database.sqlite.SQLiteDatabase | ||
import androidx.test.core.app.ApplicationProvider | ||
import de.rki.coronawarnapp.storage.AppDatabase | ||
import de.rki.coronawarnapp.storage.DATABASE_NAME | ||
import de.rki.coronawarnapp.storage.keycache.KeyCacheEntity | ||
import kotlinx.coroutines.runBlocking | ||
import net.sqlcipher.database.SQLiteException | ||
import org.hamcrest.Matchers.equalTo | ||
import org.hamcrest.Matchers.not | ||
import org.junit.Assert.assertThat | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
import java.io.File | ||
import java.util.UUID | ||
import kotlin.random.Random | ||
|
||
@RunWith(JUnit4::class) | ||
class DBPasswordTest { | ||
|
||
private val appContext: Context | ||
get() = ApplicationProvider.getApplicationContext() | ||
|
||
private val db: AppDatabase | ||
get() = AppDatabase.getInstance(appContext) | ||
|
||
@Before | ||
fun setUp() { | ||
clearSharedPreferences() | ||
AppDatabase.reset(appContext) | ||
} | ||
|
||
@Test | ||
fun generatesPassphraseInCorrectLength() { | ||
val passphrase = SecurityHelper.getDBPassword() | ||
assertTrue(passphrase.size in 32..48) | ||
} | ||
|
||
@Test | ||
fun secondPassphraseShouldBeDifferFromFirst() { | ||
val passphrase1 = SecurityHelper.getDBPassword() | ||
|
||
clearSharedPreferences() | ||
val passphrase2 = SecurityHelper.getDBPassword() | ||
|
||
assertThat(passphrase1, not(equalTo(passphrase2))) | ||
} | ||
|
||
@Test | ||
fun canLoadDataFromEncryptedDatabase() { | ||
runBlocking { | ||
val id = UUID.randomUUID().toString() | ||
val path = UUID.randomUUID().toString() | ||
val type = Random.nextInt(1000) | ||
|
||
insertFakeEntity(id, path, type) | ||
val keyCacheEntity = loadFakeEntity() | ||
|
||
assertThat(keyCacheEntity.id, equalTo(id)) | ||
assertThat(keyCacheEntity.path, equalTo(path)) | ||
assertThat(keyCacheEntity.type, equalTo(type)) | ||
} | ||
} | ||
|
||
@Test | ||
fun testDbInstanceIsActuallyResetWhenCalled() { | ||
val before = this.db | ||
AppDatabase.reset(appContext) | ||
val after = this.db | ||
|
||
assertTrue(before != after) | ||
} | ||
|
||
@Test(expected = SQLiteException::class) | ||
fun loadingDataFromDatabaseWillFailWhenPassphraseIsIncorrect() { | ||
runBlocking { | ||
val id = UUID.randomUUID().toString() | ||
val path = UUID.randomUUID().toString() | ||
val type = Random.nextInt(1000) | ||
insertFakeEntity(id, path, type) | ||
|
||
clearSharedPreferences() | ||
AppDatabase.resetInstance() | ||
|
||
val keyCacheEntity = loadFakeEntity() | ||
assertThat(keyCacheEntity.id, equalTo(id)) | ||
assertThat(keyCacheEntity.path, equalTo(path)) | ||
assertThat(keyCacheEntity.type, equalTo(type)) | ||
} | ||
} | ||
|
||
private suspend fun insertFakeEntity( | ||
id: String, | ||
path: String, | ||
type: Int | ||
) { | ||
db.dateDao().insertEntry(KeyCacheEntity().apply { | ||
this.id = id | ||
this.path = path | ||
this.type = type | ||
}) | ||
} | ||
|
||
private suspend fun loadFakeEntity(): KeyCacheEntity = db.dateDao().getAllEntries().first() | ||
|
||
private fun clearSharedPreferences() = | ||
SecurityHelper.globalEncryptedSharedPreferencesInstance.edit().clear().commit() | ||
} |
2 changes: 2 additions & 0 deletions
2
Corona-Warn-App/src/main/assets/export-server-public-keys-for-verification.properties
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,2 @@ | ||
de.rki.coronawarnapp-dev=MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE3BYTxr2HuJYQG+d7Ezu6KS8GEbFkiEvyJFg0j+C839gTjT6j7Ho0EXXZ/a07ZfvKcC2cmc1SunsrqU9Jov1J5Q== | ||
de.rki.coronawarnapp=MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEc7DEstcUIRcyk35OYDJ95/hTg3UVhsaDXKT0zK7NhHPXoyzipEnOp3GyNXDVpaPi3cAfQmxeuFMZAIX2+6A5Xg== |
Binary file not shown.
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
28 changes: 0 additions & 28 deletions
28
...na-Warn-App/src/main/java/de/rki/coronawarnapp/exception/SubmissionTanInvalidException.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/TestAlreadyPairedException.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/TestPairingInvalidException.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/WebRequestException.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.