Skip to content

Commit

Permalink
Feature/rules filtering (eu-digital-green-certificates#125)
Browse files Browse the repository at this point in the history
* Integrated rules use case

* Updated verification flow

* Update

* Version update 1.1.2(10) -> 1.1.3(11)
  • Loading branch information
oleksandrsarapulovgl authored Jul 1, 2021
1 parent fc59288 commit d7dc926
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import dgca.verifier.app.decoder.prefixvalidation.DefaultPrefixValidationService
import dgca.verifier.app.decoder.prefixvalidation.PrefixValidationService
import dgca.verifier.app.decoder.schema.DefaultSchemaValidator
import dgca.verifier.app.decoder.schema.SchemaValidator
import dgca.verifier.app.decoder.services.X509
import javax.inject.Singleton

/**
Expand Down Expand Up @@ -76,5 +77,9 @@ object DecoderModule {

@Singleton
@Provides
fun provideCryptoService(): CryptoService = VerificationCryptoService()
fun provideX509(): X509 = X509()

@Singleton
@Provides
fun provideCryptoService(x509: X509): CryptoService = VerificationCryptoService(x509)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import dgca.verifier.app.engine.data.source.valuesets.DefaultValueSetsRemoteData
import dgca.verifier.app.engine.data.source.valuesets.DefaultValueSetsRepository
import dgca.verifier.app.engine.data.source.valuesets.ValueSetsApiService
import dgca.verifier.app.engine.data.source.valuesets.ValueSetsRepository
import dgca.verifier.app.engine.domain.rules.DefaultGetRulesUseCase
import dgca.verifier.app.engine.domain.rules.GetRulesUseCase
import retrofit2.Retrofit
import javax.inject.Singleton

Expand Down Expand Up @@ -173,4 +175,10 @@ object EngineModule {
remoteDataSource: ValueSetsRemoteDataSource,
localDataSource: ValueSetsLocalDataSource
): ValueSetsRepository = DefaultValueSetsRepository(remoteDataSource, localDataSource)

@Singleton
@Provides
fun provideGetRulesUseCase(
rulesRepository: RulesRepository
): GetRulesUseCase = DefaultGetRulesUseCase(rulesRepository)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ import dgca.verifier.app.decoder.toBase64
import dgca.verifier.app.engine.*
import dgca.verifier.app.engine.data.CertificateType
import dgca.verifier.app.engine.data.ExternalParameter
import dgca.verifier.app.engine.data.Rule
import dgca.verifier.app.engine.data.Type
import dgca.verifier.app.engine.data.source.rules.RulesRepository
import dgca.verifier.app.engine.data.source.valuesets.ValueSetsRepository
import dgca.verifier.app.engine.domain.rules.GetRulesUseCase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand All @@ -76,7 +74,7 @@ class VerificationViewModel @Inject constructor(
private val cborService: CborService,
private val verifierRepository: VerifierRepository,
private val engine: CertLogicEngine,
private val rulesRepository: RulesRepository,
private val getRulesUseCase: GetRulesUseCase,
private val valueSetsRepository: ValueSetsRepository
) : ViewModel() {

Expand Down Expand Up @@ -136,33 +134,27 @@ class VerificationViewModel @Inject constructor(
}
noPublicKeysFound = false
certificates.forEach { innerCertificate ->
cryptoService.validate(cose, innerCertificate, verificationResult)
cryptoService.validate(
cose,
innerCertificate,
verificationResult,
greenCertificateData?.greenCertificate?.getType()
?: dgca.verifier.app.decoder.model.CertificateType.UNKNOWN
)
if (verificationResult.coseVerified) {
return@forEach
}
}

greenCertificateData?.apply {
if (countryIsoCode.isNotBlank()) {
val rules = mutableListOf<Rule>()
rules.addAll(
rulesRepository.getRulesBy(
countryIsoCode, ZonedDateTime.now().withZoneSameInstant(
UTC_ZONE_ID
), Type.ACCEPTANCE, this.greenCertificate.getType()
)
val issuingCountry: String =
if (this.issuingCountry?.isNotBlank() == true && this.issuingCountry != null) this.issuingCountry!! else this.greenCertificate.getIssuingCountry()
val rules = getRulesUseCase.invoke(
countryIsoCode,
issuingCountry,
this.greenCertificate.getEngineCertificateType()
)
val issuingCountry: String? =
if (this.issuingCountry?.isNotBlank() == true) this.issuingCountry else this.greenCertificate.getIssuingCountry()
if (issuingCountry?.isNotBlank() == true) {
rules.addAll(
rulesRepository.getRulesBy(
issuingCountry, ZonedDateTime.now().withZoneSameInstant(
UTC_ZONE_ID
), Type.INVALIDATION, this.greenCertificate.getType()
)
)
}
val valueSetsMap = mutableMapOf<String, List<String>>()
valueSetsRepository.getValueSets().forEach { valueSet ->
val ids = mutableListOf<String>()
Expand Down Expand Up @@ -213,7 +205,7 @@ class VerificationViewModel @Inject constructor(
}
}

private fun GreenCertificate.getType(): CertificateType {
private fun GreenCertificate.getEngineCertificateType(): CertificateType {
return when {
this.recoveryStatements?.isNotEmpty() == true -> CertificateType.RECOVERY
this.vaccinations?.isNotEmpty() == true -> CertificateType.VACCINATION
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ object Config {
const val targetSdk = 29
val javaVersion = JavaVersion.VERSION_1_8

const val versionCode = 10
const val versionName = "1.1.2"
const val versionCode = 11
const val versionName = "1.1.3"

const val androidTestInstrumentation = "androidx.test.runner.AndroidJUnitRunner"
const val proguardConsumerRules = "consumer-rules.pro"
Expand Down

0 comments on commit d7dc926

Please sign in to comment.