Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import ee.ria.DigiDoc.network.siva.SivaSetting
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import android.net.Uri
import android.util.Base64.URL_SAFE
import android.util.Base64.decode
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.platform.app.InstrumentationRegistry
import ee.ria.DigiDoc.R
import ee.ria.DigiDoc.domain.preferences.DataStore
import ee.ria.DigiDoc.webEid.WebEidAuthService
import ee.ria.DigiDoc.webEid.WebEidSignService
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -60,8 +58,6 @@ class WebEidViewModelTest {
@Mock
private lateinit var signService: WebEidSignService

private lateinit var dataStore: DataStore

private lateinit var viewModel: WebEidViewModel

private val signingCertBase64Raw =
Expand All @@ -86,9 +82,7 @@ class WebEidViewModelTest {
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
val context = InstrumentationRegistry.getInstrumentation().targetContext
dataStore = DataStore(context)
viewModel = WebEidViewModel(authService, signService, dataStore)
viewModel = WebEidViewModel(authService, signService)
}

@Test
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/kotlin/ee/ria/DigiDoc/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.app.ActivityCompat
import androidx.core.net.toUri
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -58,7 +59,6 @@ import ee.ria.DigiDoc.utilsLib.logging.LoggingUtil
import kotlinx.coroutines.launch
import java.util.logging.Logger
import javax.inject.Inject
import androidx.core.net.toUri

@AndroidEntryPoint
class MainActivity :
Expand Down Expand Up @@ -204,14 +204,17 @@ class MainActivity :
private fun isDarkModeEnabled(dataStore: DataStore): Boolean = dataStore.getThemeSetting() == ThemeSetting.DARK

private fun resolveBrowserPackage(intent: Intent): String? =
(intent
.getStringExtra("com.android.browser.application_id")
?.takeIf { it.isNotEmpty() }
?: ActivityCompat.getReferrer(this)?.host) // TODO: This needs testing with App Link
(
intent
.getStringExtra("com.android.browser.application_id")
?.takeIf { it.isNotEmpty() }
?: ActivityCompat.getReferrer(this)?.host
) // TODO: This needs testing with App Link
?.takeIf { pkg ->
val browseIntent = Intent(Intent.ACTION_VIEW, "https://".toUri()).apply {
setPackage(pkg)
}
val browseIntent =
Intent(Intent.ACTION_VIEW, "https://".toUri()).apply {
setPackage(pkg)
}
@Suppress("QueryPermissionsNeeded")
packageManager.resolveActivity(browseIntent, PackageManager.MATCH_DEFAULT_ONLY) != null
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/kotlin/ee/ria/DigiDoc/utils/WebEidUriUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ package ee.ria.DigiDoc.utils

import android.net.Uri

enum class WebEidOperation(val operation: String) {
enum class WebEidOperation(
val operation: String,
) {
AUTH("auth"),
CERT("cert"),
SIGN("sign");
SIGN("sign"),
;

companion object {
fun fromOperation(operation: String): WebEidOperation? =
entries.find { it.operation == operation }
fun fromOperation(operation: String): WebEidOperation? = entries.find { it.operation == operation }
}
}

Expand Down
18 changes: 17 additions & 1 deletion app/src/main/kotlin/ee/ria/DigiDoc/viewmodel/NFCViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,9 @@ class NFCViewModel

if (!expectedCert.contentEquals(signerCert)) {
_certMismatch.postValue(true)
throw IllegalStateException("Web eID signing certificate mismatch")
throw IllegalStateException(
"Web eID card does not match the card used for authentication",
)
}
}

Expand Down Expand Up @@ -773,6 +775,15 @@ class NFCViewModel
)
}

private fun showWebEidAuthenticationCardMismatchError(e: Exception) {
_errorState.postValue(Triple(R.string.web_eid_signing_card_mismatch, null, null))
errorLog(
logTag,
"Web eID signing failed - selected ID card does not match the card used for authentication",
e,
)
}

private fun showTechnicalError(e: Exception) {
_errorState.postValue(Triple(R.string.signature_update_nfc_technical_error, null, null))
errorLog(logTag, "Unable to perform with NFC: ${e.message}", e)
Expand Down Expand Up @@ -863,6 +874,11 @@ class NFCViewModel
true
}

message.contains("Web eID card does not match the card used for authentication") -> {
showWebEidAuthenticationCardMismatchError(ex)
true
}

else -> false
}.also {
errorLog(logTag, "Exception: ${ex.message}", ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import android.net.Uri
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import ee.ria.DigiDoc.R
import ee.ria.DigiDoc.domain.preferences.DataStore
import ee.ria.DigiDoc.utilsLib.logging.LoggingUtil.Companion.errorLog
import ee.ria.DigiDoc.webEid.WebEidAuthService
import ee.ria.DigiDoc.webEid.WebEidSignService
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,5 @@
<string name="web_eid_request_error">Päringu viga</string>
<string name="web_eid_invalid_auth_request_error">Vigane autentimispäring</string>
<string name="signature_update_nfc_detection_timeout">Kaarti ei tuvastatud. Palun alusta uuesti.</string>
<string name="web_eid_signing_card_mismatch">Valitud ID-kaart ei ühti autentimisel kasutatud kaardiga. Palun kasuta sama ID-kaarti.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,5 @@
<string name="web_eid_request_error">Request error</string>
<string name="web_eid_invalid_auth_request_error">Invalid authentication request</string>
<string name="signature_update_nfc_detection_timeout">Card not detected. Please start again.</string>
<string name="web_eid_signing_card_mismatch">The selected ID card does not match the card used for authentication. Please use the same ID card.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,12 @@ object FileUtil {
intent.data?.takeIf { it.scheme in ALLOWED_FILE_SCHEMES }?.let { externalFileUris.add(it) }
intent.clipData?.let { clipData ->
for (i in 0 until clipData.itemCount) {
clipData.getItemAt(i)?.uri?.takeIf { it.scheme in ALLOWED_FILE_SCHEMES }?.let { externalFileUris.add(it) }
clipData
.getItemAt(
i,
)?.uri
?.takeIf { it.scheme in ALLOWED_FILE_SCHEMES }
?.let { externalFileUris.add(it) }
}
}
return externalFileUris
Expand Down
Loading