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 @@ -21,7 +21,7 @@ extension Dictionary where Key == String, Value == ConfigurationProvider.CDOC2Co
}
}

public struct ConfigurationProvider: Codable, Sendable, Equatable {
public struct ConfigurationProvider: Codable, Sendable, Equatable, Loggable {
public struct MetaInf: Codable, Sendable, Equatable {
public let url: String
public let date: String
Expand Down Expand Up @@ -95,6 +95,7 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
public let cdoc2DefaultKeyserver: String
public let cdoc2UseKeyserver: Bool
public let cdoc2Conf: [String: CDOC2Conf]
public let unsupportedAppVersion: String?

private enum CodingKeys: String, CodingKey {
case metaInf = "META-INF"
Expand All @@ -117,6 +118,7 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
case cdoc2DefaultKeyserver = "CDOC2-DEFAULT-KEYSERVER"
case cdoc2UseKeyserver = "CDOC2-USE-KEYSERVER"
case cdoc2Conf = "CDOC2-CONF"
case unsupportedAppVersion = "RIADD-UNSUPPORTED"
}

public func encode(to encoder: Encoder) throws {
Expand Down Expand Up @@ -147,6 +149,7 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
try container.encode(cdoc2DefaultKeyserver, forKey: .cdoc2DefaultKeyserver)
try container.encode(cdoc2UseKeyserver, forKey: .cdoc2UseKeyserver)
try container.encode(cdoc2Conf, forKey: .cdoc2Conf)
try container.encodeIfPresent(unsupportedAppVersion, forKey: .unsupportedAppVersion)
}

public init(from decoder: Decoder) throws {
Expand All @@ -170,6 +173,14 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
cdoc2DefaultKeyserver = try container.decode(String.self, forKey: .cdoc2DefaultKeyserver)
cdoc2UseKeyserver = try container.decode(Bool.self, forKey: .cdoc2UseKeyserver)
cdoc2Conf = try container.decode([String: CDOC2Conf].self, forKey: .cdoc2Conf)
do {
unsupportedAppVersion = try container.decodeIfPresent(String.self, forKey: .unsupportedAppVersion)
} catch {
ConfigurationProvider.logger().error(
"Unable to decode unsupported app version: \(String(reflecting: error), privacy: .public)"
)
unsupportedAppVersion = nil
}

let lastUpdateCheckString = try container.decodeIfPresent(
String.self,
Expand Down Expand Up @@ -202,6 +213,7 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
cdoc2DefaultKeyserver: String,
cdoc2UseKeyserver: Bool,
cdoc2Conf: [String: CDOC2Conf],
unsupportedAppVersion: String? = nil
) {
self.metaInf = metaInf
self.sivaUrl = sivaUrl
Expand All @@ -223,5 +235,11 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
self.cdoc2DefaultKeyserver = cdoc2DefaultKeyserver
self.cdoc2UseKeyserver = cdoc2UseKeyserver
self.cdoc2Conf = cdoc2Conf
self.unsupportedAppVersion = unsupportedAppVersion
}

public func isAppVersionUnsupported(_ appVersion: String) -> Bool {
guard let unsupportedAppVersion else { return false }
return ConfigurationUtil.isVersion(appVersion, lowerThan: unsupportedAppVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,27 @@ struct ConfigurationUtil {

return encoded == decodedData.base64EncodedString()
}

static func isVersion(_ version: String, lowerThan otherVersion: String) -> Bool {
guard let components = versionComponents(version),
let otherComponents = versionComponents(otherVersion) else {
return false
}

let count = max(components.count, otherComponents.count)
let padded = components + Array(repeating: 0, count: count - components.count)
let otherPadded = otherComponents + Array(repeating: 0, count: count - otherComponents.count)

return padded.lexicographicallyPrecedes(otherPadded)
}

private static func versionComponents(_ version: String) -> [Int]? {
let parts = version
.trimmingCharacters(in: .whitespaces)
.split(separator: ".", omittingEmptySubsequences: false)
let components = parts.compactMap { part in
part.allSatisfy({ $0.isASCII && $0.isNumber }) ? Int(part) : nil
}
return components.count == parts.count ? components : nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-FileCopyrightText: Estonian Information System Authority
// SPDX-License-Identifier: LGPL-2.1-or-later

import ConfigLibMocks
import Foundation
import Testing

@testable import ConfigLib

struct ConfigurationProviderTests {

@Test
func isAppVersionUnsupported_returnFalseWhenUnsupportedVersionIsMissing() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider()

#expect(!provider.isAppVersionUnsupported("0.0.1"))
}

@Test
func isAppVersionUnsupported_returnTrueWhenAppVersionIsLower() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider(unsupportedAppVersion: "3.2.1")

#expect(provider.isAppVersionUnsupported("3.2.0.100"))
}

@Test
func isAppVersionUnsupported_returnFalseWhenAppVersionIsEqualOrHigher() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider(unsupportedAppVersion: "3.2.1")

#expect(!provider.isAppVersionUnsupported("3.2.1.0"))
#expect(!provider.isAppVersionUnsupported("3.3.0.1"))
}

@Test
func decode_readsUnsupportedAppVersion() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider(unsupportedAppVersion: "3.2.1")

let decoded = try JSONDecoder().decode(ConfigurationProvider.self, from: JSONEncoder().encode(provider))

#expect(decoded.unsupportedAppVersion == "3.2.1")
}

@Test
func decode_returnNilUnsupportedAppVersionWhenKeyIsMissing() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider()

let data = try JSONEncoder().encode(provider)
let json = try #require(String(data: data, encoding: .utf8))
let decoded = try JSONDecoder().decode(ConfigurationProvider.self, from: data)

#expect(!json.contains("RIADD-UNSUPPORTED"))
#expect(decoded.unsupportedAppVersion == nil)
}

@Test(arguments: ["", "3.2.1-beta", "abc"])
func isAppVersionUnsupported_returnFalseWhenUnsupportedVersionIsInvalid(unsupportedAppVersion: String) throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider(
unsupportedAppVersion: unsupportedAppVersion
)

#expect(!provider.isAppVersionUnsupported("3.2.0.1"))
}

@Test
func isAppVersionUnsupported_returnFalseWhenAppVersionIsUnknown() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider(unsupportedAppVersion: "99.0.0")

#expect(!provider.isAppVersionUnsupported("-.-"))
}

@Test
func decode_ignoresNonStringUnsupportedAppVersion() throws {
let provider = try TestConfigurationProvider.mockConfigurationProvider()
var json = try #require(
JSONSerialization.jsonObject(with: JSONEncoder().encode(provider)) as? [String: Any]
)
json["RIADD-UNSUPPORTED"] = 3.3

let decoded = try JSONDecoder().decode(
ConfigurationProvider.self,
from: JSONSerialization.data(withJSONObject: json)
)

#expect(decoded.unsupportedAppVersion == nil)
#expect(decoded.sivaUrl == provider.sivaUrl)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,42 @@ final class ConfigurationUtilTests {
let base64WithWhitespace = " SGVsbG8gd29ybGQ= "
#expect(!ConfigurationUtil.isBase64(encoded: base64WithWhitespace))
}

@Test(arguments: [
("3.2.0", "3.2.1"),
("3.2.0.100", "3.2.1"),
("3.2.0.100", "3.2.0.101"),
("3.2", "3.2.0.1"),
("3.9.0", "3.10.0"),
("2.99.99", "3")
])
func isVersionLowerThan_returnTrueWhenVersionIsLower(version: String, otherVersion: String) {
#expect(ConfigurationUtil.isVersion(version, lowerThan: otherVersion))
}

@Test(arguments: [
("3.2.1", "3.2.1"),
("3.2.1.0", "3.2.1"),
("3.2.1", "3.2.1.0"),
("3.2.1.5", "3.2.1"),
("3.10.0", "3.9.0"),
("4", "3.99.99")
])
func isVersionLowerThan_returnFalseWhenVersionIsEqualOrHigher(version: String, otherVersion: String) {
#expect(!ConfigurationUtil.isVersion(version, lowerThan: otherVersion))
}

@Test(arguments: [
("3.2.0", ""),
("3.2.0", "abc"),
("3.2.0", "3.2.x"),
("3.2.0", "3..2"),
("3.2.0", "+4.0"),
("3.2.0", "-4.0"),
("-.-", "4.0.0"),
("", "4.0.0")
])
func isVersionLowerThan_returnFalseWhenEitherVersionIsInvalid(version: String, otherVersion: String) {
#expect(!ConfigurationUtil.isVersion(version, lowerThan: otherVersion))
}
}
6 changes: 4 additions & 2 deletions Modules/ConfigLib/Tests/Mocks/TestConfigurationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class TestConfigurationProvider {
cdoc2ConfUUID: String = "00000000-0000-0000-0000-000000000000",
cdoc2ConfName: String = "RIA",
cdoc2ConfPostUrl: String = "https://cdoc2.example.ee:8443",
cdoc2ConfFetchUrl: String = "https://cdoc2.example.ee:8444"
cdoc2ConfFetchUrl: String = "https://cdoc2.example.ee:8444",
unsupportedAppVersion: String? = nil
) throws -> ConfigurationProvider {
let metaInf = ConfigurationProvider.MetaInf(
url: metaInfUrl,
Expand Down Expand Up @@ -98,7 +99,8 @@ public class TestConfigurationProvider {
cdoc2Default: cdoc2Default,
cdoc2DefaultKeyserver: cdoc2DefaultKeyserver,
cdoc2UseKeyserver: cdoc2UseKeyserver,
cdoc2Conf: cdoc2Conf
cdoc2Conf: cdoc2Conf,
unsupportedAppVersion: unsupportedAppVersion
)
}

Expand Down
28 changes: 28 additions & 0 deletions RIADigiDoc/RIADigiDocApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct RIADigiDocApp: App, Loggable {

@State private var isSetupComplete = false
@State private var isJailbroken: Bool = false
@State private var isAppVersionUnsupported: Bool = false
@State private var isInitialLanguageSelected: Bool = false

@State private var pathManager = NavigationPathManager()
Expand All @@ -41,16 +42,36 @@ struct RIADigiDocApp: App, Loggable {
self.documentsMigrator = Container.shared.documentsMigrator()
}

private func loadBlockingScreenLanguage() async {
if await dataStore.getIsInitialLanguageSelected() {
await languageSettings.loadSelectedLanguage()
} else {
languageSettings.loadDeviceLanguage()
}
}

private func onLaunchScreenViewAppear() {
Task {
if await JailbreakDetection.isDeviceJailbroken(fileManager: fileManager) {
await loadBlockingScreenLanguage()
await MainActor.run {
self.isJailbroken = true
}
return
}

await librarySetup.setupLibraries()

if await configurationLoader.getConfiguration()?
.isAppVersionUnsupported(BundleUtil.getAppVersion()) == true {
RIADigiDocApp.logger().error("App version \(BundleUtil.getAppVersion()) is unsupported")
await loadBlockingScreenLanguage()
await MainActor.run {
self.isAppVersionUnsupported = true
}
return
}

await crashReportManager.evaluateCrashReporting()
fileUtil.removeSavedFilesDirectory(savedFilesDirectory: nil)

Expand Down Expand Up @@ -82,6 +103,13 @@ struct RIADigiDocApp: App, Loggable {
if isJailbroken {
JailbreakView()
.environment(\.typography, Typography.current())
.environment(languageSettings)
.environment(themeSettings)
.preferredColorScheme(currentTheme.colorScheme)
} else if isAppVersionUnsupported {
UnsupportedVersionView()
.environment(\.typography, Typography.current())
.environment(languageSettings)
.environment(themeSettings)
.preferredColorScheme(currentTheme.colorScheme)
} else if isSetupComplete {
Expand Down
18 changes: 18 additions & 0 deletions RIADigiDoc/Supporting files/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@
}
}
},
"App version unsupported message" : {
"comment" : "Full-screen message when central configuration marks this app version unsupported",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "This version of ID-software on your device is unsupported. RIA DigiDoc cannot be used until you update ID-software. Install new ID-software from [www.id.ee](https://www.id.ee/en/article/install-id-software/)"
}
},
"et" : {
"stringUnit" : {
"state" : "translated",
"value" : "Sinu nutiseadmes olev ID-tarkvara ei ole toetatud. RIA DigiDoc kasutamiseks pead mobiilirakendust uuendama. Paigalda uus ID-tarkvara veebilehelt [www.id.ee](https://www.id.ee/artikkel/paigalda-id-tarkvara/)"
}
}
}
},
"Archive timestamp" : {
"comment" : "Archive timestamp label in signature details",
"extractionState" : "manual",
Expand Down
63 changes: 63 additions & 0 deletions RIADigiDoc/UI/Component/UnsupportedVersionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: Estonian Information System Authority
// SPDX-License-Identifier: LGPL-2.1-or-later

import SwiftUI
import FactoryKit
import UtilsLib

struct UnsupportedVersionView: View, Loggable {
@AppTheme private var theme
@AppTypography private var typography
@Environment(LanguageSettings.self) private var languageSettings

private var message: AttributedString {
let text = languageSettings.localized("App version unsupported message")
do {
return try AttributedString(markdown: text)
} catch {
UnsupportedVersionView.logger().error(
"Unable to parse unsupported version message: \(String(reflecting: error), privacy: .public)"
)
return AttributedString(text)
}
}

var body: some View {
ZStack {
theme.surface.ignoresSafeArea()

ScrollView {
if let url = message.runs.compactMap(\.link).first {
Link(destination: url) {
messageText
}
} else {
messageText
}
}
.defaultScrollAnchor(.center, for: .alignment)
}
}

private var messageText: some View {
var styledMessage = message
for run in styledMessage.runs where run.link != nil {
styledMessage[run.range].foregroundColor = theme.primary
styledMessage[run.range].underlineStyle = .single
styledMessage[run.range].link = nil
}

return Text(styledMessage)
.foregroundStyle(theme.onSurface)
.font(typography.bodyLarge)
.multilineTextAlignment(.center)
.padding()
.frame(maxWidth: .infinity)
}
}

#Preview {
UnsupportedVersionView()
.environment(Container.shared.languageSettings())
.environment(Container.shared.themeSettings())
}
Loading
Loading