Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.5 pt2 #618

Merged
merged 4 commits into from
Jul 25, 2024
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
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ Requires macOS 12.0 and higher.
- macOS device is 14.2: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-08 00:00:00 +0000
- macOS device is 14.3: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-08 00:00:00 +0000
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-08 00:00:00 +0000
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-15 00:00:00 +0000
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.5 requiredInstallationDate of 2024-06-03 00:00:00 +0000
- This device's requiredInstallationDate is different than the others as there is no active exploit on 14.4.1
- macOS device is 14.5: Required OS: 14.5 - Fully updated
- Ex: `minorVersionRecalculationThreshold` is set to 2 and SOFA feed has macOS 14.5 available
- macOS device is 14.0: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
- macOS device is 14.1: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
- macOS device is 14.2: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
- macOS device is 14.3: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-15 00:00:00 +0000
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-04-08 00:00:00 +0000
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-06-03 00:00:00 +0000
- macOS device is 14.5: Required OS: 14.5 - Fully updated
- Ex: `minorVersionRecalculationThreshold` is set to 3 and SOFA feed has macOS 14.5 available
- macOS device is 14.0: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
- macOS device is 14.1: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
- macOS device is 14.2: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
- macOS device is 14.3: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-04-08 00:00:00 +0000
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-06-03 00:00:00 +0000
- macOS device is 14.5: Required OS: 14.5 - Fully updated
- Addresses [612](https://github.com/macadmins/nudge/issues/612)
- To ease testing, you can now pass `-simulate-date` as an argument to override the built-in date check.
- Ex: `-simulate-date "2024-07-25T00:00:00Z"`

### Changed
- The `Actively Exploited` logic internally within Nudge and the UI on the left sidebar will show `True` if any previous updates missing on the device had active exploits.
Expand All @@ -36,6 +46,7 @@ Requires macOS 12.0 and higher.
- Addresses [610](https://github.com/macadmins/nudge/issues/610) and [613](https://github.com/macadmins/nudge/issues/613)
- When `showRequiredDate` is set to `True` and the admin is using the default values for `requiredInstallationDisplayFormat`, Nudge will attempt to understand the current locale and display the menu item appropriately.
- Addresses [615](https://github.com/macadmins/nudge/issues/615)
- Banned shortcut keys - including the ability to quit the application - are now allowed when passing `-simulate-os-version` or `-simulate-hardware-id` or `-simulate-date`

### Fixed
- Several components in the Github Actions were triggering deprecation warnings. These have been addressed by updating to the latest version of these components
Expand Down
14 changes: 11 additions & 3 deletions Nudge/UI/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if nudgePrimaryState.shouldExit {
return .terminateNow
} else {
if (CommandLineUtilities().simulateOSVersion() != nil) || (CommandLineUtilities().simulateHardwareID() != nil) || (CommandLineUtilities().simulateDate() != nil) {
LogManager.warning("Attempt to exit Nudge was allowed due to simulation arguments.", logger: uiLog)
return .terminateNow
}
// Log the attempt to exit the application if it should not exit yet
LogManager.warning("Attempt to exit Nudge was prevented.", logger: uiLog)
return .terminateCancel
Expand Down Expand Up @@ -231,9 +235,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
})

// Filter versions with the same major version as the current installed version
let minorVersions = VersionManager().removeDuplicates(from: filteredVersions.filter { version in
var minorVersions = VersionManager().removeDuplicates(from: filteredVersions.filter { version in
VersionManager.getMajorVersion(from: version) == currentMajorVersion
})
// Remove the current installed version from minorVersions
minorVersions.removeAll { $0 == currentInstalledVersion }

// Count actively exploited CVEs in the filtered versions
LogManager.notice("Assessing macOS version range for active exploits: \(filteredVersions) ", logger: sofaLog)
Expand Down Expand Up @@ -283,13 +289,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if minorVersions.isEmpty {
requiredInstallationDate = selectedOS!.releaseDate?.addingTimeInterval(slaExtension) ?? DateManager().getCurrentDate().addingTimeInterval(TimeInterval(90 * 86400))
} else {
LogManager.notice("Assessing macOS version range for recalculation: \(minorVersions)", logger: sofaLog)
let safeIndex = max(0, minorVersions.count - (OSVersionRequirementVariables.minorVersionRecalculationThreshold + 1)) // Ensure the index is within bounds
let targetVersion = minorVersions[safeIndex]
var foundVersion = false
LogManager.notice("minorVersionRecalculationThreshold is set to \(OSVersionRequirementVariables.minorVersionRecalculationThreshold) - Current Version: \(currentInstalledVersion) - Targeting version \(targetVersion) requiredInstallationDate via SOFA", logger: sofaLog)
for osVersion in macOSSOFAAssets {
for securityRelease in osVersion.securityReleases.reversed() {
if VersionManager.versionGreaterThanOrEqual(currentVersion: securityRelease.productVersion, newVersion: targetVersion) && VersionManager.versionLessThanOrEqual(currentVersion: currentInstalledVersion, newVersion: targetVersion) {
for securityRelease in osVersion.securityReleases {
if securityRelease.productVersion == targetVersion {
requiredInstallationDate = securityRelease.releaseDate?.addingTimeInterval(slaExtension) ?? DateManager().getCurrentDate().addingTimeInterval(TimeInterval(90 * 86400))
LogManager.notice("Found target macOS version \(targetVersion) - releaseDate is \(securityRelease.releaseDate!), slaExtension is \(LoggerUtilities().printTimeInterval(slaExtension))", logger: sofaLog)
foundVersion = true
Expand Down Expand Up @@ -531,6 +538,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

private func detectBannedShortcutKeys(with event: NSEvent) -> Bool {
if (CommandLineUtilities().simulateOSVersion() != nil) || (CommandLineUtilities().simulateHardwareID() != nil) || (CommandLineUtilities().simulateDate() != nil) { return false }
guard NSApplication.shared.isActive else { return false }
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
// Disable CMD + H - Hides Nudge
Expand Down
1 change: 1 addition & 0 deletions Nudge/Utilities/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LogState {
var hasLoggedRequireMajorUgprade = false
var hasLoggedScreenshotIconMode = false
var hasLoggedSimpleMode = false
var hasLoggedSimulatedDate = false
var hasLoggedUnitTestingMode = false
}

Expand Down
26 changes: 25 additions & 1 deletion Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ struct CommandLineUtilities {
return argumentPassed
}

func simulateDate() -> String? {
return valueForArgument("-simulate-date")
}

func simulateHardwareID() -> String? {
return valueForArgument("-simulate-hardware-id")
}
Expand Down Expand Up @@ -592,11 +596,31 @@ struct DateManager {
}

func getCurrentDate() -> Date {
switch Calendar.current.identifier {
let dateFormatterISO8601 = ISO8601DateFormatter()

if (CommandLineUtilities().simulateDate() != nil) {
// Try to parse the provided ISO8601 string
if let date = dateFormatterISO8601.date(from: CommandLineUtilities().simulateDate()!) {
if !nudgeLogState.hasLoggedSimulatedDate {
LogManager.notice("Simulated Date set via -simulated-date, returning \(CommandLineUtilities().simulateDate()!)", logger: uiLog)
nudgeLogState.hasLoggedSimulatedDate = true
}
return date
} else {
if !nudgeLogState.hasLoggedSimulatedDate {
LogManager.error("Failed to parse -simulated-date, returning current date.", logger: uiLog)
nudgeLogState.hasLoggedSimulatedDate = true
}
return Date()
}
} else {
// If no string is provided, return the current date based on calendar
switch Calendar.current.identifier {
case .buddhist, .japanese, .gregorian, .coptic, .ethiopicAmeteMihret, .hebrew, .iso8601, .indian, .islamic, .islamicCivil, .islamicTabular, .islamicUmmAlQura, .persian:
return dateFormatterISO8601.date(from: dateFormatterISO8601.string(from: Date())) ?? Date()
default:
return Date()
}
}
}

Expand Down