Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add server min version supported check to native iOS sync implementation (#520)
Leendert de Borst33ed79e95132
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppConfig.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppConfig.ktnew file mode 100644index 000000000..2372ff5c8--- /dev/null+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppConfig.kt@@ -0,0 +1,27 @@+package net.aliasvault.app.vaultstore++/**+ * Application configuration constants+ * This file contains version requirements and other app-wide configuration values+ */+object AppConfig {+ /**+ * The minimum supported AliasVault server (API) version.+ *+ * If the server version is below this minimum, the client will reject the connection+ * and throw a vault sync error, indicating that the server should be updated to a newer version.+ *+ * This ensures that the mobile app only communicates with servers that support+ * all required API features and prevents compatibility issues with older server versions.+ *+ * **Version Format**: Follows Semantic Versioning (SemVer) with optional pre-release tags+ * - Examples: "0.12.0", "0.12.0-dev", "1.0.0-beta"+ *+ * **When to Update**: This value should be updated when:+ * - The mobile app requires new API endpoints that don't exist in older servers+ * - Breaking changes in API request/response formats require newer server versions+ *+ * **Note**: This is used by vault sync operations.+ */+ const val MIN_SERVER_VERSION = "0.12.0-dev"+}diff --git a/apps/mobile-app/hooks/useVaultSync.ts b/apps/mobile-app/hooks/useVaultSync.tsindex 26b2753c0..8a0c1d0af 100644--- a/apps/mobile-app/hooks/useVaultSync.ts+++ b/apps/mobile-app/hooks/useVaultSync.ts@@ -118,7 +118,11 @@ export const useVaultSync = () : {return false;case VaultSyncErrorCode.CLIENT_VERSION_NOT_SUPPORTED:- await app.logout(t('vault.errors.versionNotSupported'));+ onError?.(t('vault.errors.versionNotSupported'));+ return false;++ case VaultSyncErrorCode.SERVER_VERSION_NOT_SUPPORTED:+ await app.logout(t('vault.errors.serverVersionNotSupported'));return false;case VaultSyncErrorCode.SERVER_UNAVAILABLE:@@ -201,12 +205,20 @@ export const useVaultSync = () : {await app.logout(t('vault.errors.passwordChanged'));return false;- case VaultSyncErrorCode.NETWORK_ERROR:- case VaultSyncErrorCode.TIMEOUT:+ case VaultSyncErrorCode.CLIENT_VERSION_NOT_SUPPORTED:+ onError?.(t('vault.errors.versionNotSupported'));+ return false;++ case VaultSyncErrorCode.SERVER_VERSION_NOT_SUPPORTED:+ await app.logout(t('vault.errors.serverVersionNotSupported'));+ return false;++ case VaultSyncErrorCode.SERVER_UNAVAILABLE:await NativeVaultManager.setOfflineMode(true);return true;- case VaultSyncErrorCode.SERVER_UNAVAILABLE:+ case VaultSyncErrorCode.NETWORK_ERROR:+ case VaultSyncErrorCode.TIMEOUT:await NativeVaultManager.setOfflineMode(true);return true;diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.jsonindex dac6b9de1..606904bc1 100644--- a/apps/mobile-app/i18n/locales/en.json+++ b/apps/mobile-app/i18n/locales/en.json@@ -81,7 +81,7 @@"failedToSyncVault": "Failed to sync vault","operationFailed": "Operation failed","versionNotSupported": "This version of the AliasVault mobile app is not supported by the server anymore. Please update your app to the latest version.",- "serverNeedsUpdate": "The AliasVault server needs to be updated to a newer version in order to use this mobile app. Please contact support if you need help.",+ "serverVersionNotSupported": "The AliasVault server needs to be updated to a newer version in order to use this mobile app. Please contact support if you need help.","appOutdated": "This app is outdated and cannot be used to access this (newer) vault version. Please update the AliasVault app to continue.","vaultDecryptFailed": "Vault could not be decrypted, if the problem persists please logout and login again.","passwordChanged": "Your password has changed since the last time you logged in. Please login again for security reasons."diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swiftindex 1e46d3584..0cefaf36f 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift@@ -569,7 +569,6 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {// Extract PRF inputs from the passkey request if availablevar prfInputs: PrfInputs?- // TODO: Enable prf inputs via this manual credential selection flowif #available(iOS 18.0, *), let extensionInput = self.currentPasskeyRequest?.extensionInput {prfInputs = extractPrfInputs(from: extensionInput)}diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swiftindex dbad39cce..d51e06f02 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift@@ -304,6 +304,10 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlletitle = NSLocalizedString("version_not_supported_title", comment: "Update Required")message = NSLocalizedString("version_not_supported_message", comment: "Your app version is no longer supported. Please update to the latest version.")+ case .serverVersionNotSupported:+ title = NSLocalizedString("server_version_not_supported_title", comment: "Server Update Required")+ message = NSLocalizedString("server_version_not_supported_message", comment: "The server version is outdated. Please contact your administrator to update the server.")+case .serverUnavailable:title = NSLocalizedString("server_unavailable_title", comment: "Server Unavailable")message = NSLocalizedString("server_unavailable_message", comment: "The server is currently unavailable. Please try again later.")diff --git a/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings b/apps/mobile-app/ios/Autofill/en.lproj/Localizable.stringsindex 11bb35d03..ec1113bbf 100644Binary files a/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings and b/apps/mobile-app/ios/Autofill/en.lproj/Localizable.strings differdiff --git a/apps/mobile-app/ios/VaultStoreKit/AppConfig.swift b/apps/mobile-app/ios/VaultStoreKit/AppConfig.swiftnew file mode 100644index 000000000..26cfd139c--- /dev/null+++ b/apps/mobile-app/ios/VaultStoreKit/AppConfig.swift@@ -0,0 +1,22 @@+import Foundation++/// Application configuration constants+/// This file contains version requirements and other app-wide configuration values+public enum AppConfig {+ /// The minimum supported AliasVault server (API) version.+ ///+ /// If the server version is below this minimum, the client will reject the connection+ /// and throw a `VaultSyncError.serverVersionNotSupported` error, indicating that the+ /// server should be updated to a newer version.+ ///+ /// This ensures that the mobile app only communicates with servers that support+ /// all required API features and prevents compatibility issues with older server versions.+ ///+ /// **Version Format**: Follows Semantic Versioning (SemVer) with optional pre-release tags+ /// - Examples: "0.12.0", "0.12.0-dev", "1.0.0-beta"+ ///+ /// **When to Update**: This value should be updated when:+ /// - The mobile app requires new API endpoints that don't exist in older servers+ /// - Breaking changes in API request/response formats require newer server versions+ public static let minServerVersion = "0.12.0-dev"+}diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swiftindex 7daa4c17d..abd47fe85 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swift@@ -102,6 +102,12 @@ extension VaultStore {throw VaultSyncError.clientVersionNotSupported}+ // Validate server version meets minimum requirement+ guard VersionComparison.isServerVersionSupported(status.serverVersion) else {+ print("VaultStore: Server version \(status.serverVersion) does not meet minimum requirement \(AppConfig.minServerVersion)")+ throw VaultSyncError.serverVersionNotSupported+ }+try validateSrpSalt(status.srpSalt)return status}diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultSyncError.swift b/apps/mobile-app/ios/VaultStoreKit/VaultSyncError.swiftindex ee5cd4924..3e5aec56f 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultSyncError.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultSyncError.swift@@ -15,6 +15,7 @@ public enum VaultSyncError: Error {// Version/compatibility errorscase clientVersionNotSupported+ case serverVersionNotSupportedcase vaultVersionIncompatible// Vault status errors@@ -45,6 +46,8 @@ public enum VaultSyncError: Error {return "VAULT_SYNC_TIMEOUT"case .clientVersionNotSupported:return "VAULT_SYNC_CLIENT_VERSION_NOT_SUPPORTED"+ case .serverVersionNotSupported:+ return "VAULT_SYNC_SERVER_VERSION_NOT_SUPPORTED"case .vaultVersionIncompatible:return "VAULT_SYNC_VAULT_VERSION_INCOMPATIBLE"case .vaultMergeRequired:@@ -77,6 +80,8 @@ public enum VaultSyncError: Error {return "Request timeout"case .clientVersionNotSupported:return "Client version not supported"+ case .serverVersionNotSupported:+ return "Server version not supported"case .vaultVersionIncompatible:return "Vault version incompatible"case .vaultMergeRequired:diff --git a/apps/mobile-app/ios/VaultStoreKit/VersionComparison.swift b/apps/mobile-app/ios/VaultStoreKit/VersionComparison.swiftnew file mode 100644index 000000000..e2a7cb8f6--- /dev/null+++ b/apps/mobile-app/ios/VaultStoreKit/VersionComparison.swift@@ -0,0 +1,74 @@+import Foundation++/// Utility for comparing semantic version strings+public enum VersionComparison {+ /// Checks if version1 is greater than or equal to version2, following SemVer rules.+ ///+ /// Pre-release versions (e.g., -alpha, -beta, -dev) are considered lower than release versions.+ ///+ /// - Parameters:+ /// - version1: First version string (e.g., "1.2.3" or "1.2.3-beta")+ /// - version2: Second version string (e.g., "1.2.0" or "1.2.0-alpha")+ /// - Returns: true if version1 >= version2, false otherwise+ ///+ /// - Example:+ /// ```swift+ /// VersionComparison.isGreaterThanOrEqualTo("1.2.3", "1.2.0") // true+ /// VersionComparison.isGreaterThanOrEqualTo("1.2.0-alpha", "1.2.0") // false+ /// VersionComparison.isGreaterThanOrEqualTo("1.2.0", "1.2.0-alpha") // true+ /// ```+ public static func isGreaterThanOrEqualTo(_ version1: String, _ version2: String) -> Bool {+ // Split versions into core and pre-release parts+ let components1 = version1.split(separator: "-", maxSplits: 1)+ let components2 = version2.split(separator: "-", maxSplits: 1)++ let core1 = String(components1[0])+ let core2 = String(components2[0])++ let preRelease1 = components1.count > 1 ? String(components1[1]) : nil+ let preRelease2 = components2.count > 1 ? String(components2[1]) : nil++ // Parse core version numbers+ let parts1 = core1.split(separator: ".").compactMap { Int($0) }+ let parts2 = core2.split(separator: ".").compactMap { Int($0) }++ // Compare core versions first+ let maxLength = max(parts1.count, parts2.count)+ for iVal in 0..<maxLength {+ let part1 = iVal < parts1.count ? parts1[iVal] : 0+ let part2 = iVal < parts2.count ? parts2[iVal] : 0++ if part1 > part2 {+ return true+ }+ if part1 < part2 {+ return false+ }+ }++ // If core versions are equal, check pre-release versions+ // No pre-release (release version) is greater than pre-release version+ if preRelease1 == nil && preRelease2 != nil {+ return true+ }+ if preRelease1 != nil && preRelease2 == nil {+ return false+ }+ if preRelease1 == nil && preRelease2 == nil {+ return true+ }++ // Both have pre-release versions, compare them lexically+ return preRelease1! >= preRelease2!+ }++ /// Checks if a given server version meets the minimum requirement+ ///+ /// - Parameters:+ /// - serverVersion: The server version to validate+ /// - minimumVersion: The minimum required version (defaults to AppConfig.minServerVersion)+ /// - Returns: true if the server version is supported, false otherwise+ public static func isServerVersionSupported(_ serverVersion: String, minimumVersion: String = AppConfig.minServerVersion) -> Bool {+ return isGreaterThanOrEqualTo(serverVersion, minimumVersion)+ }+}diff --git a/apps/mobile-app/utils/AppInfo.ts b/apps/mobile-app/utils/AppInfo.tsindex fbb38d445..4acdb69d9 100644--- a/apps/mobile-app/utils/AppInfo.ts+++ b/apps/mobile-app/utils/AppInfo.ts@@ -18,12 +18,6 @@ export class AppInfo {return AppInfo.VERSION.split('-')[0];})();- /**- * The minimum supported AliasVault server (API) version. If the server version is below this, the- * client will throw an error stating that the server should be updated.- */- public static readonly MIN_SERVER_VERSION = '0.12.0-dev';-/*** The client name to use in the X-AliasVault-Client header.* Detects the specific browser being used.@@ -56,56 +50,4 @@ export class AppInfo {* Prevent instantiation of this utility class*/private constructor() {}-- /**- * Checks if a given server version is supported- * @param serverVersion The version to check- * @returns boolean indicating if the version is supported- */- public static isServerVersionSupported(serverVersion: string): boolean {- return this.versionGreaterThanOrEqualTo(serverVersion, this.MIN_SERVER_VERSION);- }-- /**- * Checks if version1 is greater than or equal to version2, following SemVer rules.- * Pre-release versions (e.g., -alpha, -beta) are considered lower than release versions.- * @param version1 First version string (e.g., "1.2.3" or "1.2.3-beta")- * @param version2 Second version string (e.g., "1.2.0" or "1.2.0-alpha")- * @returns true if version1 >= version2, false otherwise- */- public static versionGreaterThanOrEqualTo(version1: string, version2: string): boolean {- // Split versions into core and pre-release parts- const [core1, preRelease1] = version1.split('-');- const [core2, preRelease2] = version2.split('-');-- const parts1 = core1.split('.').map(Number);- const parts2 = core2.split('.').map(Number);-- // Compare core versions first- for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {- const part1 = parts1[i] ?? 0;- const part2 = parts2[i] ?? 0;-- if (part1 > part2) {- return true;- }- if (part1 < part2) {- return false;- }- }-- // If core versions are equal, check pre-release versions.- if (!preRelease1 && preRelease2) {- return true;- }- if (preRelease1 && !preRelease2) {- return false;- }- if (!preRelease1 && !preRelease2) {- return true;- }-- // Both have pre-release versions, compare them lexically- return preRelease1 >= preRelease2;- }}diff --git a/apps/mobile-app/utils/types/errors/VaultSyncErrorCodes.ts b/apps/mobile-app/utils/types/errors/VaultSyncErrorCodes.tsindex 8837cfa6f..a3eddb8e8 100644--- a/apps/mobile-app/utils/types/errors/VaultSyncErrorCodes.ts+++ b/apps/mobile-app/utils/types/errors/VaultSyncErrorCodes.ts@@ -16,6 +16,7 @@ export enum VaultSyncErrorCode {// Version/compatibility errorsCLIENT_VERSION_NOT_SUPPORTED = 'VAULT_SYNC_CLIENT_VERSION_NOT_SUPPORTED',+ SERVER_VERSION_NOT_SUPPORTED = 'VAULT_SYNC_SERVER_VERSION_NOT_SUPPORTED',VAULT_VERSION_INCOMPATIBLE = 'VAULT_SYNC_VAULT_VERSION_INCOMPATIBLE',// Vault status errors