Skip to content

Commit

Permalink
Fixed bug in downgrade detection (it used to check build number inste…
Browse files Browse the repository at this point in the history
…ad of major version number).
  • Loading branch information
tijme committed Jun 28, 2023
1 parent e02a346 commit 457fecc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Raivo enables you to add your own icons to OTPs. You can add your own icon via t
The following migration guides walk you through the process of migrating from your existing OTP app to Raivo OTP.

* [Migrating from **Authy** to Raivo OTP](https://tij.me/blog/migrating-your-one-time-passwords-from-authy-to-raivo-otp/)
* [Migrating from **Aegis** to Raivo OTP](https://github.com/tygerbytes/OtpTranslator/commits?author=tygerbytes)
* [Migrating from **Aegis** to Raivo OTP](https://github.com/tygerbytes/OtpTranslator)

## Issues

Expand Down
8 changes: 4 additions & 4 deletions Raivo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Raivo/Raivo.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 85;
CURRENT_PROJECT_VERSION = 86;
DEVELOPMENT_TEAM = 564B4ETY69;
INFOPLIST_FILE = "$(SRCROOT)/Raivo/Supporting/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
Expand All @@ -1658,7 +1658,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.20;
MARKETING_VERSION = 1.4.21;
PRODUCT_BUNDLE_IDENTIFIER = com.finnwea.Raivo.Debug;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand All @@ -1676,7 +1676,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Raivo/Raivo.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 85;
CURRENT_PROJECT_VERSION = 86;
DEVELOPMENT_TEAM = 564B4ETY69;
INFOPLIST_FILE = "$(SRCROOT)/Raivo/Supporting/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
Expand All @@ -1685,7 +1685,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.20;
MARKETING_VERSION = 1.4.21;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
Expand Down
2 changes: 1 addition & 1 deletion Raivo/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class ApplicationDelegate: UIResponder, UIApplicationDelegate {
applicationInForeground = false

if currentStoryboardName == StateHelper.Storyboard.MAIN {
updateStoryboard()
updateStoryboard(instant: true)
}
}

Expand Down
5 changes: 5 additions & 0 deletions Raivo/Helpers/AppHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class AppHelper {
///
/// - Note Our version cannot be nil since it's hardcoded in the 'info.plist' file
public static let version = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String

/// The main bundle major version representation (e.g. 3).
///
/// - Note Our version cannot be nil since it's hardcoded in the 'info.plist' file
public static let versionMajor = Int(version.components(separatedBy: ".")[0])!

/// The main bundle compilation method (e.g. 'Debug' or 'Release').
///
Expand Down
1 change: 1 addition & 0 deletions Raivo/Helpers/MigrationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MigrationHelper {
}

try StorageHelper.shared.setPreviousBuild(AppHelper.build)
try StorageHelper.shared.setPreviousMajorVersion(AppHelper.versionMajor)
}

/// Start migrations that have to run during initialization of the app (before getting the current syncer account)
Expand Down
7 changes: 4 additions & 3 deletions Raivo/Helpers/StateHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ class StateHelper {
}
}

/// Ensure the user did not downgrade to a lower version of the application.
/// Ensure the user did not downgrade to a lower build of the application.
///
/// - Returns: Positive if the user did not downgrade.
@available(*, deprecated, message: "Downgrade detection checks the major version only, since build 86.")
private func userDidNotDowngrade() -> Bool {
if let previous = StorageHelper.shared.getPreviousBuild() {
let downgraded = AppHelper.build < previous
Expand All @@ -265,8 +266,8 @@ class StateHelper {
///
/// - Returns: Positive if the user did not downgrade a "major" version.
private func userDidNotDowngradeMajor() -> Bool {
if let previous = StorageHelper.shared.getPreviousBuild() {
let downgraded = AppHelper.build < previous
if let previous = StorageHelper.shared.getPreviousMajorVersion() {
let downgraded = AppHelper.versionMajor < previous
return !downgraded
}

Expand Down
21 changes: 21 additions & 0 deletions Raivo/Helpers/StorageHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class StorageHelper {
static let PASSCODE_TRIED_AMOUNT = "PasscodeTriedAmount"
static let PASSCODE_TRIED_TIMESTAMP = "PasscodeTriedTimestamp"
static let PREVIOUS_BUILD = "PreviousBuild"
static let PREVIOUS_MAJOR_VERSION = "PreviousMajorVersion"
static let ENCRYPTION_KEY = "EncryptionKey"
static let TOUCHID_ENABLED = "TouchIDEnabled"
static let BIOMETRIC_AUTHENTICATION_ENABLED = "BiometricAuthenticationEnabled"
Expand Down Expand Up @@ -256,6 +257,26 @@ class StorageHelper {
return Int(build)
}

/// Set the previous application major version.
///
/// - Parameter major: The new 'previous major version'.
/// - Throws: Valet/Keychain exceptions on fail
public func setPreviousMajorVersion(_ major: Int) throws {
log.verbose("Setting previous major version")
try settings().setString(String(major), forKey: Key.PREVIOUS_MAJOR_VERSION)
}

/// Get the previous application major version.
///
/// - Returns: The previous major version
public func getPreviousMajorVersion() -> Int? {
guard let major = try? settings().string(forKey: Key.PREVIOUS_MAJOR_VERSION) else {
return nil
}

return Int(major)
}

/// Set the complete encryption key (password+passcode) in Secure Enclave.
///
/// - Parameter key: The encryption key
Expand Down

0 comments on commit 457fecc

Please sign in to comment.