Skip to content
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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ dependencies {
implementation(project(":utils-lib"))
implementation(project(":commons-lib"))
implementation(project(":id-card-lib"))
implementation(project(":web-eid-lib"))

androidTestImplementation(project(":commons-lib:test-files"))
}

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions app/src/main/kotlin/ee/ria/DigiDoc/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ class MainActivity :
val locale = dataStore.getLocale() ?: getLocale("en")
val webEidUri = intent?.data?.takeIf { it.scheme == "web-eid-mobile" }

val externalFileUris = if (webEidUri != null) {
listOf()
} else {
getExternalFileUris(intent)
}
val externalFileUris =
if (webEidUri != null) {
listOf()
} else {
getExternalFileUris(intent)
}

localeUtil.updateLocale(applicationContext, locale)

Expand Down Expand Up @@ -172,7 +173,7 @@ class MainActivity :
RIADigiDocTheme(darkTheme = useDarkMode) {
RIADigiDocAppScreen(
externalFileUris = externalFileUris,
webEidUri = webEidUri
webEidUri = webEidUri,
)
}
}
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/kotlin/ee/ria/DigiDoc/RIADigiDocAppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ import ee.ria.DigiDoc.viewmodel.shared.SharedSettingsViewModel
import ee.ria.DigiDoc.viewmodel.shared.SharedSignatureViewModel

@Composable
fun RIADigiDocAppScreen(externalFileUris: List<Uri>, webEidUri: Uri? = null) {
fun RIADigiDocAppScreen(
externalFileUris: List<Uri>,
webEidUri: Uri? = null,
) {
val navController = rememberNavController()
val sharedMenuViewModel: SharedMenuViewModel = hiltViewModel()
val sharedContainerViewModel: SharedContainerViewModel = hiltViewModel()
Expand All @@ -88,11 +91,12 @@ fun RIADigiDocAppScreen(externalFileUris: List<Uri>, webEidUri: Uri? = null) {

sharedContainerViewModel.setExternalFileUris(externalFileUris)

val startDestination = when {
webEidUri != null -> Route.WebEidScreen.route
sharedSettingsViewModel.dataStore.getLocale() != null -> Route.Home.route
else -> Route.Init.route
}
val startDestination =
when {
webEidUri != null -> Route.WebEidScreen.route
sharedSettingsViewModel.dataStore.getLocale() != null -> Route.Home.route
else -> Route.Init.route
}

NavHost(
navController = navController,
Expand Down Expand Up @@ -392,7 +396,9 @@ fun RIADigiDocAppScreen(externalFileUris: List<Uri>, webEidUri: Uri? = null) {
@Composable
fun RIADigiDocAppScreenPreview() {
RIADigiDocTheme {
RIADigiDocAppScreen(listOf(),
webEidUri = null)
RIADigiDocAppScreen(
listOf(),
webEidUri = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ enum class IdentityAction(
SIGN("SIGN"),
AUTH("AUTH"),
DECRYPT("DECRYPT"),
CERTIFICATE("CERTIFICATE"),
}
29 changes: 29 additions & 0 deletions app/src/main/kotlin/ee/ria/DigiDoc/domain/preferences/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package ee.ria.DigiDoc.domain.preferences

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Resources
Expand Down Expand Up @@ -119,6 +120,34 @@ class DataStore
errorLog(logTag, "Unable to save CAN")
}

fun getSigningCertificate(): String {
val encryptedPrefs = getEncryptedPreferences(context)
if (encryptedPrefs == null) {
errorLog(logTag, "Unable to read signing certificate")
return ""
}

val currentCan = getCanNumber()
val key = "${resources.getString(R.string.main_settings_signing_cert_key)}_$currentCan"
return encryptedPrefs.getString(key, "") ?: ""
}

@SuppressLint("ApplySharedPref")
fun setSigningCertificate(cert: String) {
val encryptedPrefs = getEncryptedPreferences(context)
if (encryptedPrefs == null) {
errorLog(logTag, "Unable to save signing certificate")
return
}

val currentCanNumber = getCanNumber()
val key = "${resources.getString(R.string.main_settings_signing_cert_key)}_$currentCanNumber"
val editor = encryptedPrefs.edit()

editor.remove(key).commit()
if (cert.isNotEmpty()) editor.putString(key, cert).commit()
}

fun getPhoneNo(): String =
preferences.getString(
resources.getString(R.string.main_settings_phone_no_key),
Expand Down
62 changes: 57 additions & 5 deletions app/src/main/kotlin/ee/ria/DigiDoc/fragment/WebEidFragment.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
/*
* Copyright 2017 - 2026 Riigi Infosüsteemi Amet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

@file:Suppress("PackageName", "FunctionName")

package ee.ria.DigiDoc.fragment

import android.app.Activity
import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
import androidx.activity.compose.LocalActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
Expand All @@ -16,12 +38,15 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import ee.ria.DigiDoc.fragment.screen.WebEidScreen
import ee.ria.DigiDoc.ui.theme.RIADigiDocTheme
import ee.ria.DigiDoc.viewmodel.WebEidViewModel
import ee.ria.DigiDoc.viewmodel.shared.SharedContainerViewModel
import ee.ria.DigiDoc.viewmodel.shared.SharedMenuViewModel
import ee.ria.DigiDoc.viewmodel.shared.SharedSettingsViewModel

@OptIn(ExperimentalComposeUiApi::class)
@Composable
Expand All @@ -30,10 +55,34 @@ fun WebEidFragment(
navController: NavHostController,
webEidUri: Uri?,
viewModel: WebEidViewModel = hiltViewModel(),
sharedSettingsViewModel: SharedSettingsViewModel = hiltViewModel(),
sharedContainerViewModel: SharedContainerViewModel = hiltViewModel(),
sharedMenuViewModel: SharedMenuViewModel = hiltViewModel(),
) {
val activity = LocalActivity.current as Activity

LaunchedEffect(viewModel) {
viewModel.relyingPartyResponseEvents.collect { responseUri ->
val browserIntent =
Intent(Intent.ACTION_VIEW, responseUri).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
activity.startActivity(browserIntent)
activity.finishAndRemoveTask()
}
}

LaunchedEffect(webEidUri) {
println("DEBUG: WebEidFragment got URI = $webEidUri")
webEidUri?.let { viewModel.handleAuth(it) }
webEidUri?.let {
when (it.host) {
"auth" -> viewModel.handleAuth(it)
"cert" -> viewModel.handleCertificate(it)
"sign" -> viewModel.handleSign(it)
else -> {
viewModel.handleUnknown(it)
}
}
}
}

Surface(
Expand All @@ -49,6 +98,9 @@ fun WebEidFragment(
modifier = modifier,
navController = navController,
viewModel = viewModel,
sharedSettingsViewModel = sharedSettingsViewModel,
sharedContainerViewModel = sharedContainerViewModel,
sharedMenuViewModel = sharedMenuViewModel,
)
}
}
Expand All @@ -60,7 +112,7 @@ fun WebEidFragmentPreview() {
RIADigiDocTheme {
WebEidFragment(
navController = rememberNavController(),
webEidUri = null
webEidUri = null,
)
}
}
}
Loading
Loading