Skip to content

Commit d42295f

Browse files
committed
Testing
1 parent 034de67 commit d42295f

7 files changed

Lines changed: 69 additions & 9 deletions

File tree

app/proguard-rules.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
-keep,allowobfuscation,allowshrinking class com.google.gson.** { *; }
106106
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.** { *; }
107107

108+
# Keep ConfigurationProvider's List<String> cert fields (tslCerts / certBundle),
109+
-keepclassmembers,allowobfuscation class ee.ria.DigiDoc.** {
110+
@com.google.gson.annotations.SerializedName <fields>;
111+
@com.google.gson.annotations.JsonAdapter <fields>;
112+
}
113+
108114
# BouncyCastle
109115
-keep class org.bouncycastle.** { *; }
110116

app/src/main/kotlin/ee/ria/DigiDoc/fragment/screen/AdvancedSettingsScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.compose.material3.Scaffold
4242
import androidx.compose.material3.Text
4343
import androidx.compose.material3.TextButton
4444
import androidx.compose.runtime.Composable
45+
import androidx.compose.runtime.collectAsState
4546
import androidx.compose.runtime.getValue
4647
import androidx.compose.runtime.mutableStateOf
4748
import androidx.compose.runtime.remember

config-lib/src/main/kotlin/ee/ria/DigiDoc/configuration/utils/TSLUtil.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ object TSLUtil {
6161
}
6262

6363
createDirectoryIfNotExist(destination)
64+
debugLog(logTag, "Setting up TSL files in cache; bundled in assets: ${tslFiles?.joinToString() ?: "none"}")
6465
if (!tslFiles.isNullOrEmpty()) {
6566
for (fileName in tslFiles) {
6667
if (isXMLFile(fileName) && shouldCopyTSL(context, assetsPath, fileName, destination)) {
6768
copyTSLFromAssets(context, assetsPath, fileName, destination)
6869
val tslFile = File(destination, fileName)
6970
setFileDateAttributes(tslFile)
7071
removeExistingETag(tslFile.path)
72+
debugLog(logTag, "Copied TSL '$fileName' from assets into cache (${tslFile.length()} bytes)")
7173
}
7274
}
7375
}
@@ -82,20 +84,28 @@ object TSLUtil {
8284
fileName: String,
8385
destinationDir: String,
8486
): Boolean {
85-
if (!FileUtil.fileExists(File(destinationDir, fileName).path)) {
87+
val cachedFile = File(destinationDir, fileName)
88+
if (!FileUtil.fileExists(cachedFile.path)) {
89+
debugLog(logTag, "TSL '$fileName' is not in the cache yet; copying it from assets")
8690
return true
8791
} else {
8892
try {
8993
context.assets
9094
.open(File(sourcePath, fileName).path)
9195
.use { assetsTSLInputStream ->
92-
FileInputStream(File(destinationDir, fileName))
96+
FileInputStream(cachedFile)
9397
.use { cachedTSLInputStream ->
9498
val assetsTslVersion: Int =
9599
readSequenceNumber(assetsTSLInputStream)
96100
val cachedTslVersion: Int =
97101
readSequenceNumber(cachedTSLInputStream)
98-
return assetsTslVersion > cachedTslVersion
102+
val isAssetNewer = assetsTslVersion > cachedTslVersion
103+
debugLog(
104+
logTag,
105+
"TSL '$fileName': assets version $assetsTslVersion, cached version " +
106+
"$cachedTslVersion${if (isAssetNewer) "updating cache" else "cache is up to date"}",
107+
)
108+
return isAssetNewer
99109
}
100110
}
101111
} catch (e: Exception) {

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ android.enableBuildConfigAsBytecode=true
2929
# Allows library modules to share package names. Set to false to avoid strict
3030
# unique package name enforcement across modules
3131
android.uniquePackageNames=false
32-
# Disables R8's strict validation of keep rules to avoid build failures caused
33-
# by rules that reference missing classes
34-
android.r8.strictFullModeForKeepRules=false
32+
# Enforce strict R8 validation of keep rules (full mode): rules that reference
33+
# missing classes fail the build instead of being silently ignored.
34+
android.r8.strictFullModeForKeepRules=true

libdigidoc-lib/src/main/kotlin/ee/ria/DigiDoc/libdigidoclib/domain/model/ContainerWrapper.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
package ee.ria.DigiDoc.libdigidoclib.domain.model
2323

2424
import ee.ria.DigiDoc.libdigidoclib.SignedContainer
25+
import ee.ria.DigiDoc.utilsLib.logging.LoggingUtil.Companion.debugLog
26+
import ee.ria.DigiDoc.utilsLib.logging.LoggingUtil.Companion.errorLog
2527
import ee.ria.DigiDoc.utilsLib.text.TextUtil.removeEmptyStrings
2628
import ee.ria.libdigidocpp.ExternalSigner
2729
import ee.ria.libdigidocpp.Signature
@@ -46,6 +48,7 @@ interface ContainerWrapper {
4648

4749
class ContainerWrapperImpl : ContainerWrapper {
4850
private lateinit var signature: Signature
51+
private val logTag = "Libdigidoc-ContainerWrapper"
4952

5053
@Throws(CertificateException::class)
5154
override fun prepareSignature(
@@ -54,6 +57,7 @@ class ContainerWrapperImpl : ContainerWrapper {
5457
cert: ByteArray?,
5558
roleData: RoleData?,
5659
): ByteArray {
60+
debugLog(logTag, "Preparing signature (with role data: ${roleData != null})")
5761
signature =
5862
when {
5963
roleData != null && signedContainer != null -> {
@@ -75,7 +79,9 @@ class ContainerWrapperImpl : ContainerWrapper {
7579
}
7680
else -> throw IllegalStateException("Unable to get container")
7781
}
78-
return signature.dataToSign()
82+
val dataToSign = signature.dataToSign()
83+
debugLog(logTag, "Signature prepared (${dataToSign.size} bytes to sign)")
84+
return dataToSign
7985
}
8086

8187
override fun finalizeSignature(
@@ -84,7 +90,14 @@ class ContainerWrapperImpl : ContainerWrapper {
8490
signatureArray: ByteArray,
8591
) {
8692
signature.setSignatureValue(signatureArray)
87-
signature.extendSignatureProfile(signer)
93+
debugLog(logTag, "Extending signature profile (fetches OCSP confirmation and timestamp)")
94+
try {
95+
signature.extendSignatureProfile(signer)
96+
} catch (e: Exception) {
97+
errorLog(logTag, "Unable to extend signature profile: ${e.message}", e)
98+
throw e
99+
}
88100
signedContainer?.rawContainer()?.save()
101+
debugLog(logTag, "Signature finalized and container saved")
89102
}
90103
}

libdigidoc-lib/src/main/kotlin/ee/ria/DigiDoc/libdigidoclib/init/Initialization.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class Initialization
9393
isLoggingEnabled: Boolean = false,
9494
) {
9595
if (isInitialized) {
96+
debugLog(libdigidocInitLogTag, "libdigidocpp is already initialized; only refreshing the log level")
9697
setLibdigidocppLogLevel(isLoggingEnabled)
9798
throw AlreadyInitializedException("Libdigidocpp is already initialized")
9899
}
@@ -111,6 +112,10 @@ class Initialization
111112
throw erre
112113
}
113114

115+
debugLog(
116+
libdigidocInitLogTag,
117+
"TSL cache directory contains: ${getSchemaDir(context).list()?.joinToString() ?: "(empty)"}",
118+
)
114119
initLibDigiDocpp(
115120
context,
116121
getSchemaPath(context),
@@ -130,6 +135,7 @@ class Initialization
130135
)
131136
digidoc.initializeLib(UserAgentUtil.getAppInfo(context), path)
132137
UserAgentUtil.setLibdigidocppVersion(digidoc.version())
138+
debugLog(libdigidocInitLogTag, "Initialized libdigidocpp ${digidoc.version()} (TSL cache: $path)")
133139
isInitialized = true
134140
}
135141

@@ -189,6 +195,16 @@ class Initialization
189195
context: Context,
190196
configurationProvider: ConfigurationProvider,
191197
) {
198+
debugLog(
199+
libdigidocInitLogTag,
200+
"Applying configuration to libdigidocpp — " +
201+
"TSL URL: ${configurationProvider.tslUrl}, TSA URL: ${configurationProvider.tsaUrl}, " +
202+
"SiVa URL: ${configurationProvider.sivaUrl}, " +
203+
"TSL signer certs: ${configurationProvider.tslCerts.size}, " +
204+
"trust bundle certs: ${configurationProvider.certBundle.size}, " +
205+
"config serial: ${configurationProvider.metaInf.serial}",
206+
)
207+
192208
overrideTSLUrl(configurationProvider.tslUrl)
193209
overrideTSLCert(configurationProvider.tslCerts)
194210
overrideSivaUrl(configurationProvider.sivaUrl)
@@ -418,9 +434,19 @@ class Initialization
418434
}
419435

420436
private fun loadConfiguration(context: Context) {
421-
configurationRepository.getConfiguration()?.let { overrideConfiguration(context, it) }
437+
val current = configurationRepository.getConfiguration()
438+
debugLog(
439+
libdigidocInitLogTag,
440+
if (current == null) {
441+
"No cached configuration yet; will apply it once it is loaded"
442+
} else {
443+
"Applying cached configuration"
444+
},
445+
)
446+
current?.let { overrideConfiguration(context, it) }
422447
CoroutineScope(Main).launch {
423448
configurationRepository.observeConfigurationUpdates { newConfig ->
449+
debugLog(libdigidocInitLogTag, "Configuration updated; reapplying it to libdigidocpp")
424450
overrideConfiguration(context, newConfig)
425451
}
426452
}

libdigidoc-lib/src/main/kotlin/ee/ria/DigiDoc/libdigidoclib/utils/FileUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ object FileUtils {
6868
errorLog(LIBDIGIDOC_FILEUTILS_LOG_TAG, "Unable to get 'schema' resource", nfe)
6969
throw nfe
7070
}
71+
debugLog(LIBDIGIDOC_FILEUTILS_LOG_TAG, "Extracting XML schema into ${schemaDir.absolutePath}")
72+
val extractedFiles = mutableListOf<String>()
7173
schemaResourceInputStream.use { inputStream ->
7274
ZipInputStream(inputStream).use { zipInputStream ->
7375
var entry: ZipEntry?
@@ -78,9 +80,11 @@ object FileUtils {
7880
throw ZipException("Bad zip entry: $entryName")
7981
}
8082
Files.copy(zipInputStream, Paths.get(entryFile.toURI()), StandardCopyOption.REPLACE_EXISTING)
83+
extractedFiles.add(entryName)
8184
}
8285
}
8386
}
87+
debugLog(LIBDIGIDOC_FILEUTILS_LOG_TAG, "Extracted schema files: ${extractedFiles.joinToString()}")
8488
}
8589

8690
private fun isChild(

0 commit comments

Comments
 (0)