Skip to content

Commit

Permalink
Merge branch 'develop' into develop-networkmanager
Browse files Browse the repository at this point in the history
# Conflicts:
#	sdk/src/main/java/it/ministerodellasalute/verificaC19sdk/di/NetworkModule.kt
  • Loading branch information
nicola-95 committed Apr 5, 2023
2 parents e189a0a + d596379 commit d35d59e
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 246 deletions.
17 changes: 17 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
10 changes: 10 additions & 0 deletions .github/workflows/publiccode-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
on: [push, pull_request]

jobs:
publiccode_validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: italia/publiccode-parser-action@v0.0.2-alpha
with:
publiccode: 'publiccode.yml'
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
buildscript {

ext {
kotlin_version = '1.3.72'
kotlin_version = '1.6.10'
}
repositories {
google()
Expand All @@ -16,7 +16,6 @@ buildscript {
classpath Deps.androidx_navigation
classpath Deps.hilt_plugin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.5.0"
classpath "io.realm:realm-gradle-plugin:10.8.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
8 changes: 5 additions & 3 deletions publiccode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
publiccodeYmlVersion: '0.2'
name: Digital Covid Certificate Android SDK
url: 'https://github.com/ministero-salute/it-dgc-verificac19-sdk-android'
softwareVersion: 1.1.6
releaseDate: '2022-03-07'
softwareVersion: 1.1.10
releaseDate: '2022-06-13'
developmentStatus: stable
softwareType: library
platforms:
Expand Down Expand Up @@ -80,6 +80,8 @@ description:
verifica della Certificazione verde COVID-19 o le informazioni rilevate
dalla lettura dei QR code e le informazioni fornite in esito ai controlli,
come indicato nel DPCM 12 ottobre 2021.
features:
- Verifica Digital Covid Certificate
en:
genericName: 'Android DCC SDK'
apiDocumentation: |-
Expand Down Expand Up @@ -111,4 +113,4 @@ description:
verification of the COVID-19 Green Certification,
as indicated in the Prime Ministerial Decree released on 12 October 2021.
features:
- Verifica Digital Covid Certificate
- Verifies Digital Covid Certificate
12 changes: 7 additions & 5 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'jacoco'
id 'org.jetbrains.dokka'
id 'org.jetbrains.dokka' version '1.6.21'
id 'realm-android'
}

Expand Down Expand Up @@ -102,16 +102,18 @@ android {
buildConfigField "String", "SHOW_DEBUG_BUTTONS", "\"true\""
buildConfigField "String", "BASE_URL", "\"https://testaka4.sogei.it/v1/dgc/\""
buildConfigField "String", "SERVER_HOST", "\"testaka4.sogei.it\""
buildConfigField "String", "CERTIFICATE_SHA", "\"sha256/R0d+cI8vTcJ3sCbpfQCH0OmdBbulPH3deYhngzOqJVA=\""
buildConfigField "String", "SDK_VERSION", "\"1.1.6\""
buildConfigField "String", "LEAF_CERTIFICATE", "\"sha256/sWTArAhfhED6GnBexDo3sf0srn/rvHl1gPmRoLSM5xY=\""
buildConfigField "String", "BACKUP_CERTIFICATE", "\"sha256/KpZtVwF9rcXdbBMB/Poep8h3VSYXA/ZSFMkkWlQ0ZNk=\""
buildConfigField "String", "SDK_VERSION", "\"1.1.12\""
}

release {
buildConfigField "String", "SHOW_DEBUG_BUTTONS", "\"true\""
buildConfigField "String", "BASE_URL", "\"https://get.dgc.gov.it/v1/dgc/\""
buildConfigField "String", "SERVER_HOST", "\"get.dgc.gov.it\""
buildConfigField "String", "CERTIFICATE_SHA", "\"sha256/7cZJIDPacG8FS3pq6Mvxg+7yBDM/VYc2alOcbVe/e74=\""
buildConfigField "String", "SDK_VERSION", "\"1.1.6\""
buildConfigField "String", "LEAF_CERTIFICATE", "\"sha256/ep8PpqFVLsdiHg+J4qSZwV0HdoSB6AiO+sLAFZ53HUs=\""
buildConfigField "String", "BACKUP_CERTIFICATE", "\"sha256/095kxU9rqrJ3f+YM1pG+Y2YCgAUvR1f5blSuZYXvEy8=\""
buildConfigField "String", "SDK_VERSION", "\"1.1.12\""

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ interface Preferences {

var maxRetryNumber: Int

var isDoubleScanFlow: Boolean

var userName: String?

/**
Expand Down Expand Up @@ -195,11 +193,6 @@ class PreferencesImpl(context: Context) : Preferences {
false
)

override var isDoubleScanFlow by BooleanPreference(
preferences,
PrefKeys.KEY_IS_DOUBLE_SCAN_FLOW,
false
)
override var userName by StringPreference(preferences, PrefKeys.KEY_USER_NAME, "")

override fun clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ object NetworkModule {
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(
chain: Array<out java.security.cert.X509Certificate>?,
authType: String?
chain: Array<out java.security.cert.X509Certificate>?, authType: String?
) {
}

@Throws(CertificateException::class)
override fun checkServerTrusted(
chain: Array<out java.security.cert.X509Certificate>?,
authType: String?
chain: Array<out java.security.cert.X509Certificate>?, authType: String?
) {
}

Expand All @@ -138,14 +136,12 @@ object NetworkModule {
val trustManagerFactory: TrustManagerFactory =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(null as KeyStore?)
val trustManagers: Array<TrustManager> =
trustManagerFactory.trustManagers
val trustManagers: Array<TrustManager> = trustManagerFactory.trustManagers
check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) {
"Unexpected default trust managers:" + trustManagers.contentToString()
}

val trustManager =
trustManagers[0] as X509TrustManager
val trustManager = trustManagers[0] as X509TrustManager


val builder = OkHttpClient.Builder()
Expand All @@ -166,11 +162,8 @@ object NetworkModule {
*
*/
private fun createRetrofit(okHttpClient: Lazy<OkHttpClient>): Retrofit {
return Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(Gson()))
.baseUrl(BuildConfig.BASE_URL)
.callFactory { okHttpClient.get().newCall(it) }
.build()
return Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(Gson()))
.baseUrl(BuildConfig.BASE_URL).callFactory { okHttpClient.get().newCall(it) }.build()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ data class TestModel(
val countryOfVaccination: String,
val certificateIssuer: String,
val certificateIdentifier: String,
val resultType: TestResult,
var isPreviousScanModeBooster: Boolean = false
val resultType: TestResult
) : CertificateData

enum class TestResult(val value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class FirstViewModel @Inject constructor(

init {
preferences.shouldInitDownload = false
preferences.isDoubleScanFlow = false
preferences.userName = ""

fetchStatus.addSource(verifierRepository.getCertificateFetchStatus()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ class VerificationViewModel @Inject constructor(

fun getScanMode() = ScanMode.from(preferences.scanMode!!)

fun getDoubleScanFlag() = preferences.isDoubleScanFlow

fun setDoubleScanFlag(flag: Boolean) = run { preferences.isDoubleScanFlow = flag }

fun getUserName() = preferences.userName

fun setUserName(firstName: String) = run{ preferences.userName = firstName}

fun getRuleSet() = RuleSet(preferences.validationRulesJson)

fun nukeData() {
Expand Down Expand Up @@ -244,10 +236,7 @@ class VerificationViewModel @Inject constructor(
val certificateModel = greenCertificate.toCertificateModel(verificationResult).apply {
isBlackListed = blackListCheckResult
isRevoked = isCertificateRevoked(certificateIdentifier.sha256())
tests?.let {
it.last().isPreviousScanModeBooster = scanMode == ScanMode.BOOSTER
}
this.scanMode = if (getDoubleScanFlag()) ScanMode.DOUBLE_SCAN else scanMode
this.scanMode = scanMode
this.certificateIdentifier = certificateIdentifier
this.certificate = certificate
this.exemptions = exemptions?.toList()
Expand All @@ -265,14 +254,14 @@ class VerificationViewModel @Inject constructor(
private fun extractExemption(
decodeData: GreenCertificateData?
): Array<Exemption>? {
val jsonObject = JSONObject(decodeData!!.hcertJson)
val exemptionJson = if (jsonObject.has("e")) jsonObject.getString("e") else null

exemptionJson?.let {
Log.i("exemption found", it)
return Gson().fromJson(exemptionJson, Array<Exemption>::class.java)
}
return null
decodeData?.hcertJson?.let { json ->
val jsonObject = JSONObject(json)
val exemptionJson = if (jsonObject.has("e")) jsonObject.getString("e") else null
exemptionJson?.let {
Log.i("exemption found", it)
return Gson().fromJson(exemptionJson, Array<Exemption>::class.java)
}
} ?: return null
}

/**
Expand Down Expand Up @@ -306,7 +295,7 @@ class VerificationViewModel @Inject constructor(
*/
fun getCertificateStatus(certificateModel: CertificateModel, ruleSet: RuleSet): CertificateStatus {
return Validator.validate(certificateModel, ruleSet)
}
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package it.ministerodellasalute.verificaC19sdk.model.validation

import android.util.Log
import it.ministerodellasalute.verificaC19sdk.model.ScanMode
import it.ministerodellasalute.verificaC19sdk.model.CertificateModel
import it.ministerodellasalute.verificaC19sdk.model.CertificateStatus
import it.ministerodellasalute.verificaC19sdk.model.Exemption
Expand All @@ -36,9 +35,11 @@ class ExemptionValidationStrategy : ValidationStrategy {
* This method checks the [Exemption] and returns a proper [CertificateStatus]
* after checking the validity start and end dates.
*/
override fun checkCertificate(certificateModel: CertificateModel, ruleSet: RuleSet): CertificateStatus {
override fun checkCertificate(
certificateModel: CertificateModel,
ruleSet: RuleSet
): CertificateStatus {
val exemption: Exemption = certificateModel.exemptions!!.last()
val scanMode = certificateModel.scanMode

try {
val startDate: LocalDate = exemption.certificateValidFrom.toLocalDate()
Expand All @@ -53,11 +54,8 @@ class ExemptionValidationStrategy : ValidationStrategy {
return CertificateStatus.EXPIRED
}
}
return when (scanMode) {
ScanMode.ENTRY_ITALY -> return CertificateStatus.NOT_VALID
ScanMode.BOOSTER -> return CertificateStatus.TEST_NEEDED
else -> CertificateStatus.VALID
}
return CertificateStatus.VALID

} catch (e: Exception) {
return CertificateStatus.NOT_EU_DCC
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,25 @@ package it.ministerodellasalute.verificaC19sdk.model.validation

import android.util.Log
import it.ministerodellasalute.verificaC19sdk.model.*
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.getAge
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.toLocalDate
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.toValidDateOfBirth
import java.time.LocalDate

class RecoveryValidationStrategy : ValidationStrategy {

override fun checkCertificate(certificateModel: CertificateModel, ruleSet: RuleSet): CertificateStatus {
override fun checkCertificate(
certificateModel: CertificateModel,
ruleSet: RuleSet
): CertificateStatus {
val recovery: RecoveryModel = certificateModel.recoveryStatements!!.first()
val scanMode = certificateModel.scanMode
val certificate = certificateModel.certificate

val countryCode = if (scanMode == ScanMode.ENTRY_ITALY) recovery.country else Country.IT.value
val countryCode = Country.IT.value

val recoveryBis = recovery.isRecoveryBis(certificate)
val startDaysToAdd = if (recoveryBis) ruleSet.getRecoveryCertPVStartDay() else ruleSet.getRecoveryCertStartDayUnified(countryCode)
val startDaysToAdd =
if (recoveryBis) ruleSet.getRecoveryCertPVStartDay() else ruleSet.getRecoveryCertStartDayUnified(
countryCode
)

val endDaysToAdd = when {
recoveryBis -> ruleSet.getRecoveryCertPvEndDay()
Expand All @@ -53,9 +56,10 @@ class RecoveryValidationStrategy : ValidationStrategy {

Log.d("RecoveryDates", "Start: $startDate End: $endDate")
return when {
LocalDate.now().isBefore(startDate.plusDays(startDaysToAdd)) -> CertificateStatus.NOT_VALID_YET
LocalDate.now()
.isBefore(startDate.plusDays(startDaysToAdd)) -> CertificateStatus.NOT_VALID_YET
LocalDate.now().isAfter(endDate) -> CertificateStatus.EXPIRED
else -> return if (scanMode == ScanMode.BOOSTER && !recoveryBis) CertificateStatus.TEST_NEEDED else CertificateStatus.VALID
else -> return CertificateStatus.VALID
}
} catch (e: Exception) {
return CertificateStatus.NOT_VALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
package it.ministerodellasalute.verificaC19sdk.model.validation

import android.util.Log
import it.ministerodellasalute.verificaC19sdk.model.ScanMode
import it.ministerodellasalute.verificaC19sdk.model.*
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.getAge
import it.ministerodellasalute.verificaC19sdk.util.TimeUtility.toValidDateOfBirth
import java.time.LocalDateTime
import java.time.OffsetDateTime

Expand All @@ -39,11 +36,11 @@ class TestValidationStrategy : ValidationStrategy {
* status as [CertificateStatus].
*
*/
override fun checkCertificate(certificateModel: CertificateModel, ruleSet: RuleSet): CertificateStatus {
override fun checkCertificate(
certificateModel: CertificateModel,
ruleSet: RuleSet
): CertificateStatus {
val test: TestModel = certificateModel.tests!!.first()
val scanMode = certificateModel.scanMode
val isADoubleScanBoosterTest = test.isPreviousScanModeBooster
val isTestNotAllowed = scanMode == ScanMode.BOOSTER || scanMode == ScanMode.STRENGTHENED

if (test.resultType == TestResult.DETECTED) {
return CertificateStatus.NOT_VALID
Expand All @@ -59,12 +56,10 @@ class TestValidationStrategy : ValidationStrategy {

when (testType) {
TestType.MOLECULAR.value -> {
startDate = ldtDateTimeOfCollection.plusHours(ruleSet.getMolecularTestStartHour())
startDate =
ldtDateTimeOfCollection.plusHours(ruleSet.getMolecularTestStartHour())
endDate =
if (scanMode == ScanMode.DOUBLE_SCAN && isADoubleScanBoosterTest)
ldtDateTimeOfCollection.plusHours(ruleSet.getRapidTestEndHour())
else
ldtDateTimeOfCollection.plusHours(ruleSet.getMolecularTestEndHour())
ldtDateTimeOfCollection.plusHours(ruleSet.getMolecularTestEndHour())
}
TestType.RAPID.value -> {
startDate = ldtDateTimeOfCollection.plusHours(ruleSet.getRapidTestStartHour())
Expand All @@ -78,7 +73,6 @@ class TestValidationStrategy : ValidationStrategy {
return when {
LocalDateTime.now().isBefore(startDate) -> CertificateStatus.NOT_VALID_YET
LocalDateTime.now().isAfter(endDate) -> CertificateStatus.EXPIRED
isTestNotAllowed -> CertificateStatus.NOT_VALID
else -> CertificateStatus.VALID
}
} catch (e: Exception) {
Expand Down

0 comments on commit d35d59e

Please sign in to comment.