mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-06 09:47:22 +01:00
.
This commit is contained in:
@@ -35,13 +35,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
logger.debug("SecretAgent finished launching")
|
||||
Task {
|
||||
let inputParser = try XPCAgentInputParser()
|
||||
Task {
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
var len = (5 as UInt32).littleEndian
|
||||
var raw = SSHAgent.Request.requestIdentities.protocolID
|
||||
let data = Data(bytes: &len, count: MemoryLayout<UInt32>.size) + Data(bytes: &raw, count: MemoryLayout<UInt8>.size)
|
||||
print(try? await inputParser.parse(data: data))
|
||||
}
|
||||
for await session in socketController.sessions {
|
||||
Task {
|
||||
do {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import SecretAgentKit
|
||||
|
||||
/// Delegates all agent input parsing to an XPC service which wraps OpenSSH
|
||||
public final class XPCAgentInputParser: SSHAgentInputParserProtocol {
|
||||
|
||||
private let session: XPCSession
|
||||
@@ -8,11 +9,15 @@ public final class XPCAgentInputParser: SSHAgentInputParserProtocol {
|
||||
|
||||
public init() throws {
|
||||
if #available(macOS 26.0, *) {
|
||||
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser", targetQueue: queue, options: .inactive, requirement: .isFromSameTeam())
|
||||
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser", targetQueue: queue, requirement: .isFromSameTeam())
|
||||
} else {
|
||||
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser", targetQueue: queue, options: .inactive)
|
||||
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser", targetQueue: queue)
|
||||
}
|
||||
Task {
|
||||
// Warm up the XPC endpoint.
|
||||
_ = try? await parse(data: Data())
|
||||
|
||||
}
|
||||
try session.activate()
|
||||
}
|
||||
|
||||
public func parse(data: Data) async throws -> SSHAgent.Request {
|
||||
@@ -21,10 +26,12 @@ public final class XPCAgentInputParser: SSHAgentInputParserProtocol {
|
||||
try session.send(data) { result in
|
||||
switch result {
|
||||
case .success(let result):
|
||||
do {
|
||||
continuation.resume(returning: try result.decode(as: SSHAgent.Request.self))
|
||||
} catch {
|
||||
if let result = try? result.decode(as: SSHAgent.Request.self) {
|
||||
continuation.resume(returning: result)
|
||||
} else if let error = try? result.decode(as: SSHAgentInputParser.AgentParsingError.self) {
|
||||
continuation.resume(throwing: error)
|
||||
} else {
|
||||
continuation.resume(throwing: UnknownMessageError())
|
||||
}
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
@@ -40,4 +47,6 @@ public final class XPCAgentInputParser: SSHAgentInputParserProtocol {
|
||||
session.cancel(reason: "Done")
|
||||
}
|
||||
|
||||
struct UnknownMessageError: Error {}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user