This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: wip analytics * fix: rename attestate to attest * fix: actually use serverDate * feat: add analytics configuration settings * feat: add `byAdding` utility method to Date * feat: advance analytics logic * chore: remove token validation request * feat: add ExposureAnalyticsWorker and logic to schedule it * feat: advance analytics implementation * feat: wip analytics * fix: implement missing pieces * feat: implement retry mechanism with exponential backoff for sending operational info * feat: add SafetyNetApiKey * feat: add attestation tests * fix: add dummy operational info call * fix: exponential backoff within worker timeout * feat: wip tests for analytics * fix: date parsing * feat: add tests and fixes for analytics * fix: operationalInfoWithoutExposureSamplingRate value * feat: wip tests for analytics * fix: analytics tests * feat: add test for invalid attestation * feat: complete analytics tests * fix: do not require hardware attestation * feat: add success status on attestation result * fix: use current date rather than 0 date * chore: ktlint * chore: use 1000L rather than converting toLong * fix: use Dispatchers.Main with GlobalScope * refactor: move date methods to a CalendarUtils object * refactor: avoid duplicated Base64 encoder * fix: import * chore: add new debug menu entries for analytics * fix: send analytics only from hardware-backed devices * fix: avoid context switching in coroutine * fix: avoid crash on migration Co-authored-by: Stefano Rodriguez <[email protected]> Co-authored-by: Marco Uberti <[email protected]>
- Loading branch information
1 parent
00716c5
commit c984e40
Showing
28 changed files
with
1,656 additions
and
39 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
50 changes: 50 additions & 0 deletions
50
app/src/androidTest/java/it/ministerodellasalute/immuni/attestation/GoogleAttestationTest.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 @@ | ||
/* | ||
* Copyright (C) 2020 Presidenza del Consiglio dei Ministri. | ||
* Please refer to the AUTHORS file for more information. | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package it.ministerodellasalute.immuni.attestation | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import it.ministerodellasalute.immuni.BuildConfig | ||
import it.ministerodellasalute.immuni.extensions.attestation.AttestationClient | ||
import it.ministerodellasalute.immuni.extensions.attestation.SafetyNetAttestationClient | ||
import it.ministerodellasalute.immuni.extensions.utils.base64EncodedSha256 | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class GoogleAttestationTest { | ||
private val context get() = InstrumentationRegistry.getInstrumentation().targetContext | ||
|
||
@Test | ||
fun testAttestationSucceeds() = runBlocking { | ||
val client = SafetyNetAttestationClient( | ||
context = context, | ||
parameters = SafetyNetAttestationClient.AttestationParameters( | ||
apiKey = BuildConfig.SAFETY_NET_TEST_API_KEY, | ||
apkPackageName = context.packageName, | ||
requiresBasicIntegrity = true, | ||
requiresCtsProfile = true, | ||
requiresHardwareAttestation = true | ||
) | ||
) | ||
|
||
val response = client.attest("nonce".base64EncodedSha256()) | ||
|
||
assertTrue(response is AttestationClient.Result.Success) | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
app/src/main/java/it/ministerodellasalute/immuni/api/services/ExposureAnalyticsService.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,42 @@ | ||
/* | ||
* Copyright (C) 2020 Presidenza del Consiglio dei Ministri. | ||
* Please refer to the AUTHORS file for more information. | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package it.ministerodellasalute.immuni.api.services | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import okhttp3.ResponseBody | ||
import retrofit2.Response | ||
import retrofit2.http.* | ||
|
||
interface ExposureAnalyticsService { | ||
@JsonClass(generateAdapter = true) | ||
data class OperationalInfoRequest( | ||
@field:Json(name = "province") val province: String, | ||
@field:Json(name = "exposure_permission") val exposurePermission: Int, | ||
@field:Json(name = "bluetooth_active") val bluetoothActive: Int, | ||
@field:Json(name = "notification_permission") val notificationPermission: Int, | ||
@field:Json(name = "exposure_notification") val exposureNotification: Int, | ||
@field:Json(name = "last_risky_exposure_on") val lastRiskyExposureOn: String, | ||
@field:Json(name = "salt") val salt: String, | ||
@field:Json(name = "signed_attestation") val signedAttestation: String | ||
) | ||
|
||
@POST("/v1/analytics/google/operational-info") | ||
suspend fun operationalInfo( | ||
@Header("Immuni-Dummy-Data") isDummyData: Int, | ||
@Body body: OperationalInfoRequest | ||
): Response<ResponseBody> | ||
} |
29 changes: 29 additions & 0 deletions
29
.../main/java/it/ministerodellasalute/immuni/config/ExposureAnalyticsNetworkConfiguration.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,29 @@ | ||
/* | ||
* Copyright (C) 2020 Presidenza del Consiglio dei Ministri. | ||
* Please refer to the AUTHORS file for more information. | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package it.ministerodellasalute.immuni.config | ||
|
||
import android.content.Context | ||
import com.squareup.moshi.Moshi | ||
import it.ministerodellasalute.immuni.R | ||
|
||
class ExposureAnalyticsNetworkConfiguration( | ||
context: Context, | ||
override val moshi: Moshi | ||
) : BaseNetworkConfiguration(context, moshi) { | ||
override fun baseUrl(): String { | ||
return context.getString(R.string.analytics_base_url) | ||
} | ||
} |
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
Oops, something went wrong.