diff --git a/CommunicationBridge/ServiceDelegate.swift b/CommunicationBridge/ServiceDelegate.swift index e34dee9..838de51 100644 --- a/CommunicationBridge/ServiceDelegate.swift +++ b/CommunicationBridge/ServiceDelegate.swift @@ -8,6 +8,11 @@ class ServiceDelegate: NSObject, NSXPCListenerDelegate { _: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection ) -> Bool { + if checkForManagedProperties() { + Logger.communicationBridge.error("Managed properties detected. Rejecting connection.") + return false + } + newConnection.exportedInterface = NSXPCInterface( with: CommunicationBridgeXPCServiceProtocol.self ) @@ -20,6 +25,12 @@ class ServiceDelegate: NSObject, NSXPCListenerDelegate { return true } + + func checkForManagedProperties() -> Bool { + // Implement the logic to check for managed properties + // Return true if managed properties are found, otherwise false + return false + } } class XPCService: CommunicationBridgeXPCServiceProtocol { @@ -162,4 +173,3 @@ actor ExtensionServiceLauncher { } } } - diff --git a/CommunicationBridge/main.swift b/CommunicationBridge/main.swift index b420b80..b063837 100644 --- a/CommunicationBridge/main.swift +++ b/CommunicationBridge/main.swift @@ -19,3 +19,13 @@ app.delegate = appDelegate Logger.communicationBridge.info("Communication bridge started") app.run() +func checkForManagedProperties() -> Bool { + // Implement the logic to check for managed properties + // Return true if managed properties are found, otherwise false + return false +} + +if checkForManagedProperties() { + Logger.communicationBridge.error("Managed properties detected. Exiting.") + exit(1) +} diff --git a/Copilot-for-Xcode-Info.plist b/Copilot-for-Xcode-Info.plist index b45f6d1..7f9a3fb 100644 --- a/Copilot-for-Xcode-Info.plist +++ b/Copilot-for-Xcode-Info.plist @@ -28,5 +28,12 @@ $(SPARKLE_PUBLIC_KEY) TEAM_ID_PREFIX $(TeamIdentifierPrefix) + SecuritySettings + + CheckManagedProperties + + NetworkInterception + + diff --git a/Core/Sources/Service/Service.swift b/Core/Sources/Service/Service.swift index 3fb9afa..57e62c3 100644 --- a/Core/Sources/Service/Service.swift +++ b/Core/Sources/Service/Service.swift @@ -100,6 +100,11 @@ public final class Service { } }.store(in: &cancellable) } + + if checkForNetworkInterception() { + Logger.service.error("Network interception detected. Exiting.") + exit(1) + } } @MainActor @@ -108,6 +113,12 @@ public final class Service { keyBindingManager.stopForExit() await scheduledCleaner.closeAllChildProcesses() } + + private func checkForNetworkInterception() -> Bool { + // Implement the logic to check for network interception + // Return true if network interception is detected, otherwise false + return false + } } public extension Service { @@ -119,4 +130,3 @@ public extension Service { reply(nil, XPCRequestNotHandledError()) } } - diff --git a/Core/Sources/Service/XPCService.swift b/Core/Sources/Service/XPCService.swift index a2ef2ca..88d2905 100644 --- a/Core/Sources/Service/XPCService.swift +++ b/Core/Sources/Service/XPCService.swift @@ -11,6 +11,10 @@ public class XPCService: NSObject, XPCServiceProtocol { // MARK: - Service public func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void) { + if checkForNetworkInterception() { + Logger.service.error("Network interception detected. Exiting.") + exit(1) + } reply( Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "N/A", Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "N/A" @@ -219,6 +223,12 @@ public class XPCService: NSObject, XPCServiceProtocol { reply: reply ) } + + private func checkForNetworkInterception() -> Bool { + // Implement the logic to check for network interception + // Return true if network interception is detected, otherwise false + return false + } } struct NoAccessToAccessibilityAPIError: Error, LocalizedError { @@ -228,4 +238,3 @@ struct NoAccessToAccessibilityAPIError: Error, LocalizedError { init() {} } - diff --git a/Core/Tests/ServiceTests/ManagedPropertiesTests.swift b/Core/Tests/ServiceTests/ManagedPropertiesTests.swift new file mode 100644 index 0000000..5df964a --- /dev/null +++ b/Core/Tests/ServiceTests/ManagedPropertiesTests.swift @@ -0,0 +1,19 @@ +import XCTest +@testable import CommunicationBridge + +class ManagedPropertiesTests: XCTestCase { + + func testCheckForManagedProperties() { + let result = checkForManagedProperties() + XCTAssertFalse(result, "Managed properties should not be detected in this test environment.") + } + + func testListenerShouldAcceptNewConnection() { + let serviceDelegate = ServiceDelegate() + let listener = NSXPCListener(machServiceName: "com.example.service") + let connection = NSXPCConnection(machServiceName: "com.example.service", options: []) + + let shouldAccept = serviceDelegate.listener(listener, shouldAcceptNewConnection: connection) + XCTAssertTrue(shouldAccept, "Connection should be accepted in this test environment.") + } +} diff --git a/Core/Tests/ServiceTests/NetworkInterceptionTests.swift b/Core/Tests/ServiceTests/NetworkInterceptionTests.swift new file mode 100644 index 0000000..deb7cdf --- /dev/null +++ b/Core/Tests/ServiceTests/NetworkInterceptionTests.swift @@ -0,0 +1,17 @@ +import XCTest +@testable import Service + +class NetworkInterceptionTests: XCTestCase { + + func testNetworkInterceptionDetected() { + let service = Service.shared + let result = service.checkForNetworkInterception() + XCTAssertTrue(result, "Network interception should be detected.") + } + + func testNetworkInterceptionNotDetected() { + let service = Service.shared + let result = service.checkForNetworkInterception() + XCTAssertFalse(result, "Network interception should not be detected.") + } +}