Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/revocation configs #317

Merged
merged 3 commits into from
May 25, 2022
Merged
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
2 changes: 0 additions & 2 deletions branches/dcc/revocation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ android {
productFlavors {
tst {
dimension "version"
buildConfigField "String", "REVOCATION_SERVICE_HOST", "\"https://dgca-revocation-service-eu-test.cfapps.eu10.hana.ondemand.com\""
}
acc {
dimension "version"
buildConfigField "String", "REVOCATION_SERVICE_HOST", "\"https://dgca-revocation-service-eu-acc.cfapps.eu10.hana.ondemand.com\""
}
bloom {
dimension "revocationDataSliceType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,50 @@ import retrofit2.http.*

interface RevocationService {

@GET("/lists")
@GET
suspend fun getRevocationLists(
@Header("If-None-Match") eTag: String
@Header("If-None-Match") eTag: String,
@Url url: String
): Response<List<RevocationKIDResponse>>

@GET("/lists/{kid}/partitions")
@GET
suspend fun getRevocationListPartitions(
@Header("if-Match") eTag: String,
@Header("if-modified-since") modifiedSince: String?,
@Header("X-SLICE-FILTER-TYPE") type: SliceType,
@Path("kid") kid: String
@Url url: String
): Response<List<RevocationPartitionResponse>>

@POST("/lists/{kid}/partitions/{id}/slices")
@POST
suspend fun getRevocationPartitionChunks(
@Header("if-Match") eTag: String,
@Header("X-SLICE-FILTER-TYPE") type: SliceType,
@Path("kid") kid: String,
@Path("id") partitionId: String,
@Url url: String,
@Body cidList: List<String>
): Response<ResponseBody>

@GET("/lists/{kid}/partitions/{id}/chunks/{cid}/slices")
@GET
suspend fun getRevocationChunk(
@Header("If-Match") eTag: String,
@Header("if-modified-since") modifiedSince: String,
@Header("X-SLICE-FILTER-TYPE") type: SliceType,
@Path("kid") kid: String,
@Path("id") id: String,
@Path("cid") chunkId: String
@Url url: String
): Response<ResponseBody>

@POST("/lists/{kid}/partitions/{id}/chunks/{cid}/slices")
@POST
suspend fun getRevocationChunkSlices(
@Header("if-Match") eTag: String,
@Header("if-modified-since") modifiedSince: String,
@Header("X-SLICE-FILTER-TYPE") type: SliceType,
@Path("kid") kid: String,
@Path("id") partitionId: String,
@Path("cid") cid: String,
@Url url: String,
@Body sidList: List<String>
): Response<ResponseBody>

@GET("/lists/{kid}/partitions/{id}/chunks/{cid}/slices/{sid}")
@GET
suspend fun getRevocationChunkSlice(
@Header("If-Match") eTag: String,
@Header("if-modified-since") modifiedSince: String,
@Header("X-SLICE-FILTER-TYPE") type: SliceType,
@Path("kid") kid: String,
@Path("id") id: String,
@Path("cid") chunkId: String,
@Path("sid") sid: String
@Url url: String
): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ import okhttp3.ResponseBody
interface RevocationRepository {

@Throws(Exception::class)
suspend fun getRevocationLists(): List<RevocationKidData>?
suspend fun getRevocationLists(baseUrl: String): List<RevocationKidData>?

@Throws(Exception::class)
suspend fun getRevocationPartitions(
baseUrl: String,
lastUpdated: String?,
sliceType: SliceType,
kid: String,
): List<RevocationPartitionResponse>?

@Throws(Exception::class)
suspend fun getPartitionChunks(
baseUrl: String,
sliceType: SliceType,
kid: String,
partitionId: String?,
Expand All @@ -52,6 +54,7 @@ interface RevocationRepository {

@Throws(Exception::class)
suspend fun getRevocationChunk(
baseUrl: String,
lastUpdated: String,
sliceType: SliceType,
kid: String,
Expand All @@ -61,6 +64,7 @@ interface RevocationRepository {

@Throws(Exception::class)
suspend fun getRevocationChunkSlices(
baseUrl: String,
lastUpdated: String,
sliceType: SliceType,
kid: String,
Expand All @@ -71,6 +75,7 @@ interface RevocationRepository {

@Throws(Exception::class)
suspend fun getSlice(
baseUrl: String,
lastUpdated: String,
sliceType: SliceType,
kid: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* ---license-start
* eu-digital-covid-certificates / dcc-verifier-app-android
* ---
* Copyright (C) 2022 T-Systems International GmbH and all other contributors
* ---
* Licensed 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.
* ---license-end
*
* Created by osarapulov on 5/25/22, 8:12 AM
*/

package dcc.app.revocation.domain.usacase

interface GetRevocationBaseUr {

suspend fun invoke(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package dcc.app.revocation.domain.usacase

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import dcc.app.revocation.BuildConfig
import dcc.app.revocation.data.RevocationPreferences
import dcc.app.revocation.data.network.model.RevocationPartitionResponse
import dcc.app.revocation.data.network.model.Slice
Expand All @@ -50,6 +51,7 @@ import java.util.zip.GZIPInputStream
import javax.inject.Inject

class GetRevocationDataUseCase @Inject constructor(
private val getRevocationBaseUr: GetRevocationBaseUr,
private val repository: RevocationRepository,
private val revocationPreferences: RevocationPreferences,
dispatcher: CoroutineDispatcher,
Expand All @@ -61,8 +63,10 @@ class GetRevocationDataUseCase @Inject constructor(
override suspend fun invoke(params: Any) {
revocationPreferences.lastRevocationSyncTimeMillis = System.currentTimeMillis()

val baseUrl = getRevocationBaseUr.invoke()

// Load list of KIDs
val newKidItems = repository.getRevocationLists() ?: return
val newKidItems = repository.getRevocationLists(baseUrl) ?: return

// Remove all entities not matching KIDs from list
repository.deleteOutdatedKidItems(newKidItems.map { it.kid })
Expand Down Expand Up @@ -116,7 +120,9 @@ class GetRevocationDataUseCase @Inject constructor(

private suspend fun getPartitions(kid: String, lastUpdated: String? = null) {
val kidUrlSafe = kid.toBase64Url()
val baseUrl = getRevocationBaseUr.invoke()
repository.getRevocationPartitions(
baseUrl = baseUrl,
sliceType = sliceType,
kid = kidUrlSafe,
lastUpdated = lastUpdated
Expand All @@ -132,9 +138,12 @@ class GetRevocationDataUseCase @Inject constructor(
val lastUpdated = localPartition.lastUpdated.toUtcString()
compareChunksWithLocal(kid, localPartition, remotePartition, lastUpdated)
} else {
val baseUrl = getRevocationBaseUr.invoke()

// Initial sync. load all chunks for partition
val result =
repository.getPartitionChunks(
baseUrl = baseUrl,
sliceType = sliceType,
kid = kid.toBase64Url(),
partitionId = remotePartition.id,
Expand All @@ -161,12 +170,14 @@ class GetRevocationDataUseCase @Inject constructor(
val type: Type = object : TypeToken<Map<String, Map<String, Slice>>>() {}.type
val localChunks =
Gson().fromJson<Map<String, Map<String, Slice>>>(localPartition.chunks, type)
val baseUrl = getRevocationBaseUr.invoke()

remotePartition.chunks.forEach { (remoteChunkKey, remoteChunkValue) ->
val localSlices = localChunks[remoteChunkKey]
if (localSlices == null) {
// When chunk not found load from api
val response = repository.getRevocationChunk(
baseUrl = baseUrl,
lastUpdated = lastUpdated,
sliceType = sliceType,
kid = kid.toBase64Url(),
Expand All @@ -190,6 +201,7 @@ class GetRevocationDataUseCase @Inject constructor(
if (slices.size < remoteChunkValue.size / 2) {
// Load updated or missing slices by sid list.
val response = repository.getRevocationChunkSlices(
baseUrl = baseUrl,
lastUpdated = lastUpdated,
sliceType = sliceType,
kid = kid.toBase64Url(),
Expand All @@ -200,6 +212,7 @@ class GetRevocationDataUseCase @Inject constructor(
handlePartitionSlices(kid, remotePartition, response)
} else {
val response = repository.getRevocationChunk(
baseUrl = baseUrl,
lastUpdated = lastUpdated,
sliceType = sliceType,
kid = kid.toBase64Url(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package dcc.app.revocation.repository

import dcc.app.revocation.BuildConfig
import dcc.app.revocation.data.RevocationPreferences
import dcc.app.revocation.data.containsServerError
import dcc.app.revocation.data.local.DccRevocationLocalDataSource
Expand All @@ -47,9 +48,10 @@ class RevocationRepositoryImpl @Inject constructor(
) : RevocationRepository {

@Throws(Exception::class)
override suspend fun getRevocationLists(): List<RevocationKidData>? {
override suspend fun getRevocationLists(baseUrl: String): List<RevocationKidData>? {
val eTag = revocationPreferences.eTag ?: ""
val response = revocationService.getRevocationLists(eTag)
val url = "$baseUrl/lists"
val response = revocationService.getRevocationLists(eTag, url)

if (response.containsServerError()) {
throw HttpException(response)
Expand All @@ -65,16 +67,18 @@ class RevocationRepositoryImpl @Inject constructor(

@Throws(Exception::class)
override suspend fun getRevocationPartitions(
baseUrl: String,
lastUpdated: String?,
sliceType: SliceType,
kid: String
): List<RevocationPartitionResponse>? {
val eTag = revocationPreferences.eTag ?: ""
val url = "$baseUrl/lists/$kid/partitions"
val response = revocationService.getRevocationListPartitions(
eTag = eTag,
modifiedSince = lastUpdated,
url = url,
type = sliceType,
kid = kid
)

if (response.containsServerError()) {
Expand All @@ -86,17 +90,18 @@ class RevocationRepositoryImpl @Inject constructor(

@Throws(Exception::class)
override suspend fun getPartitionChunks(
baseUrl: String,
sliceType: SliceType,
kid: String,
partitionId: String?,
cidList: List<String>
): ResponseBody? {
val eTag = revocationPreferences.eTag ?: ""
val url = "$baseUrl/lists/$kid/partitions/$partitionId/slices"
val response = revocationService.getRevocationPartitionChunks(
eTag = eTag,
type = sliceType,
kid = kid,
partitionId = partitionId ?: "null",
url = url,
cidList = cidList
)

Expand All @@ -109,20 +114,20 @@ class RevocationRepositoryImpl @Inject constructor(

@Throws(Exception::class)
override suspend fun getRevocationChunk(
baseUrl: String,
lastUpdated: String,
sliceType: SliceType,
kid: String,
id: String?,
chunkId: String
): ResponseBody? {
val eTag = revocationPreferences.eTag ?: ""
val url = "$baseUrl/lists/$kid/partitions/$id/chunks/$chunkId/slices"
val response = revocationService.getRevocationChunk(
eTag = eTag,
modifiedSince = lastUpdated,
type = sliceType,
kid = kid,
id = id ?: "null",
chunkId = chunkId
url = url
)

if (response.containsServerError()) {
Expand All @@ -134,6 +139,7 @@ class RevocationRepositoryImpl @Inject constructor(

@Throws(Exception::class)
override suspend fun getRevocationChunkSlices(
baseUrl: String,
lastUpdated: String,
sliceType: SliceType,
kid: String,
Expand All @@ -142,13 +148,12 @@ class RevocationRepositoryImpl @Inject constructor(
sidList: List<String>
): ResponseBody? {
val eTag = revocationPreferences.eTag ?: ""
val url = "$baseUrl/lists/$kid/partitions/$partitionId/chunks/$cid/slices"
val response = revocationService.getRevocationChunkSlices(
eTag = eTag,
modifiedSince = lastUpdated,
type = sliceType,
kid = kid,
partitionId = partitionId ?: "null",
cid = cid,
url = url,
sidList = sidList
)

Expand All @@ -161,6 +166,7 @@ class RevocationRepositoryImpl @Inject constructor(

@Throws(Exception::class)
override suspend fun getSlice(
baseUrl: String,
lastUpdated: String,
sliceType: SliceType,
kid: String,
Expand All @@ -169,14 +175,12 @@ class RevocationRepositoryImpl @Inject constructor(
sid: String
): ResponseBody? {
val eTag = revocationPreferences.eTag ?: ""
val url = "$baseUrl/lists/$kid/partitions/$partitionId/chunks/$cid/slices/$sid"
val response = revocationService.getRevocationChunkSlice(
eTag = eTag,
modifiedSince = lastUpdated,
type = sliceType,
kid = kid,
id = partitionId ?: "null",
chunkId = cid,
sid = sid
url = url
)

if (response.containsServerError()) {
Expand Down
7 changes: 7 additions & 0 deletions branches/dcc/src/acc/assets/verifier-context.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
},
"revocation": {
"url": "https://dgca-revocation-service-eu-acc.cfapps.eu10.hana.ondemand.com",
"pubKeys": [
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
}
}
},
Expand Down
Loading