Skip to content

Commit

Permalink
UPDATE prefs to add settings for log level and audit switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradSun committed Jan 15, 2023
1 parent a755fe6 commit 828f419
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 159 deletions.
Binary file modified Docs/Preferences.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
388 changes: 243 additions & 145 deletions NuwaClient/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion NuwaClient/KextManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class KextManager {
var connection: io_connect_t = 0
var isConnected: Bool = false
var nuwaLog = NuwaLog()
var auditSwitch = (UserDefaults.standard.integer(forKey: UserAuditSwitch) != 0)
var delegate: NuwaEventProcessProtocol?

private func processConnectionRequest(iterator: io_iterator_t) {
Expand Down Expand Up @@ -149,7 +150,13 @@ extension KextManager {
return
}
}
delegate?.processAuthEvent(nuwaEvent)

if auditSwitch {
delegate?.processAuthEvent(nuwaEvent)
}
else {
_ = replyAuthEvent(eventID: nuwaEvent.eventID, isAllowed: true)
}
}

func processNotifyEvent(_ event: inout NuwaKextEvent) {
Expand Down Expand Up @@ -270,6 +277,11 @@ extension KextManager: NuwaEventProviderProtocol {
return true
}

func setAuditSwitch(status: Bool) -> Bool {
auditSwitch = status
return true
}

func replyAuthEvent(eventID: UInt64, isAllowed: Bool) -> Bool {
guard eventID != 0 else {
Logger(.Warning, "Invalid ID for auth event.")
Expand Down
13 changes: 12 additions & 1 deletion NuwaClient/SextManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SextManager {
private var sextProxy: SextXPCProtocol?
static let shared = SextManager()
var nuwaLog = NuwaLog()
var auditSwitch = (UserDefaults.standard.integer(forKey: UserAuditSwitch) != 0)
var delegate: NuwaEventProcessProtocol?
}

Expand Down Expand Up @@ -50,7 +51,12 @@ extension SextManager: ManagerXPCProtocol {
return
}

delegate?.processAuthEvent(event)
if auditSwitch {
delegate?.processAuthEvent(event)
}
else {
_ = replyAuthEvent(eventID: event.eventID, isAllowed: true)
}
}
}

Expand Down Expand Up @@ -100,6 +106,11 @@ extension SextManager: NuwaEventProviderProtocol {
return true
}

func setAuditSwitch(status: Bool) -> Bool {
auditSwitch = status
return true
}

func replyAuthEvent(eventID: UInt64, isAllowed: Bool) -> Bool {
if eventID == 0 {
return false
Expand Down
19 changes: 17 additions & 2 deletions NuwaClient/ViewManager/PrefsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ class PrefsViewController: NSViewController {
case MuteProcess
}

@IBOutlet weak var logLevelButton: NSPopUpButton!
@IBOutlet weak var auditSwitchButton: NSPopUpButton!
@IBOutlet weak var upRadioButton: NSButton!
@IBOutlet weak var downRadioButton: NSButton!
@IBOutlet weak var pathView: NSTextView!
@IBOutlet weak var fileCheckButton: NSButton!
@IBOutlet weak var networkCheckButton: NSButton!
@IBOutlet weak var processCheckButton: NSButton!

private var nuwaLog = NuwaLog()
private var auditSwitch = true
private var isUpButtonChoosed = true
private var muteChoice = MuteChoice.FilterFile
private var muteType = NuwaMuteType.FilterFileByFilePath
Expand All @@ -40,6 +44,10 @@ class PrefsViewController: NSViewController {
else {
eventProvider = KextManager.shared
}
auditSwitch = (UserDefaults.standard.integer(forKey: UserAuditSwitch) != 0)

logLevelButton.selectItem(withTag: Int(nuwaLog.logLevel))
auditSwitchButton.selectItem(withTag: (auditSwitch ? 1 : 0))
}

private func updateCheckButton(choice: MuteChoice) {
Expand Down Expand Up @@ -89,7 +97,6 @@ class PrefsViewController: NSViewController {
muteChoice = .FilterFile
updateCheckButton(choice: muteChoice)
upButtonClicked(upRadioButton)
Logger(.Info, "fileButtonClicked")
}

@IBAction func networkButtonClicked(_ sender: NSButton) {
Expand All @@ -99,7 +106,6 @@ class PrefsViewController: NSViewController {
networkCheckButton.isHidden = false
updateCheckButton(choice: muteChoice)
upButtonClicked(upRadioButton)
Logger(.Info, "networkButtonClicked")
}

@IBAction func processButtonClicked(_ sender: NSButton) {
Expand Down Expand Up @@ -131,6 +137,8 @@ class PrefsViewController: NSViewController {

@IBAction func updateButtonClicked(_ sender: NSButton) {
let inputs = pathView.string.components(separatedBy: "\n")
let level = logLevelButton.selectedItem!.tag
let status = auditSwitchButton.selectedItem!.tag > 0

switch muteType {
case .FilterFileByFilePath, .FilterFileByProcPath:
Expand All @@ -146,6 +154,13 @@ class PrefsViewController: NSViewController {
_ = eventProvider!.udpateMuteList(list: inputs, type: muteType)
}

if level != nuwaLog.logLevel {
_ = eventProvider!.setLogLevel(level: UInt8(level))
}
if status != auditSwitch {
_ = eventProvider!.setAuditSwitch(status: status)
}

view.window?.close()
}
}
20 changes: 12 additions & 8 deletions NuwaStone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.nuwastone.service.eps;
PRODUCT_NAME = "$(inherited)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -773,7 +773,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.nuwastone.service.eps;
PRODUCT_NAME = "$(inherited)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -799,6 +799,7 @@
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = NuwaService/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = NuwaService;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
Expand All @@ -807,7 +808,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.nuwastone.service;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -832,6 +833,7 @@
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = NuwaService/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = NuwaService;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
Expand All @@ -840,7 +842,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.nuwastone.service;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -981,6 +983,7 @@
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = NuwaClient/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = NuwaClient;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
Expand All @@ -989,7 +992,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.nuwastone.client;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1015,6 +1018,7 @@
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = NuwaClient/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = NuwaClient;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
Expand All @@ -1023,7 +1027,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.nuwastone.client;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1047,7 +1051,7 @@
INFOPLIST_FILE = NuwaKext/Info.plist;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
MODULE_NAME = com.nuwastone.service;
MODULE_START = 0;
MODULE_STOP = 0;
Expand Down Expand Up @@ -1076,7 +1080,7 @@
INFOPLIST_FILE = NuwaKext/Info.plist;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
MODULE_NAME = com.nuwastone.service;
MODULE_START = 0;
MODULE_STOP = 0;
Expand Down
1 change: 1 addition & 0 deletions NuwaUtils/NuwaCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let KextService = "DriverService"
let MachServiceKey = "MachServiceName"

let UserLogLevel = "Log Level"
let UserAuditSwitch = "Audit Switch"
let UserAllowExecList = "Allow Exec List"
let UserDenyExecList = "Deny Exec List"
let UserMuteFileByFile = "File Paths for Filtering File"
Expand Down
1 change: 1 addition & 0 deletions NuwaUtils/NuwaEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protocol NuwaEventProviderProtocol {
func startProvider() -> Bool
func stopProvider() -> Bool
func setLogLevel(level: UInt8) -> Bool
func setAuditSwitch(status: Bool) -> Bool
func replyAuthEvent(eventID: UInt64, isAllowed: Bool) -> Bool
func udpateMuteList(list: [String], type: NuwaMuteType) -> Bool
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ NuwaStone wont't let unsigned app run without your authorization, but the app wi

<p align="center"><img src="https://raw.githubusercontent.com/ConradSun/NuwaStone/main/Docs/Preferences.png" width=512></p>

Select 'Preferences' from the status bar menu of **NuwaClient** application to check or update user preferences.
It supports filtering as below
Select 'Preferences' or 'Settings' from the status bar menu of **NuwaClient** application to check or update user preferences.
It supports setting the log level, opening/closing audit switch, and filtering events as below

- Mute file events by file paths or process paths
- Mute network events by process paths or remote ip addresses
Expand Down

0 comments on commit 828f419

Please sign in to comment.