mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-08-20 08:09:01 +02:00
Adding host reader xpc service and connection info
This commit is contained in:
@@ -13,7 +13,7 @@ import SwiftUI
|
||||
|
||||
extension EnvironmentValues {
|
||||
|
||||
@MainActor fileprivate static let _certificateStore: CertificateStore = CertificateStore()
|
||||
@MainActor fileprivate static let _certificateStore = CertificateStore()
|
||||
|
||||
@MainActor var certificateStore: CertificateStore {
|
||||
EnvironmentValues._certificateStore
|
||||
@@ -49,14 +49,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
logger.debug("SecretAgent finished launching")
|
||||
Task {
|
||||
_ = Task {
|
||||
for await session in socketController.sessions {
|
||||
Task {
|
||||
_ = Task {
|
||||
let inputParser = try await XPCAgentInputParser()
|
||||
let hostsReader = try await XPCHostsfileReader()
|
||||
let hosts = try? await hostsReader.read()
|
||||
do {
|
||||
for await message in session.messages {
|
||||
let request = try await inputParser.parse(data: message)
|
||||
let agentResponse = await agent.handle(request: request, provenance: session.provenance)
|
||||
let agentResponse = await agent.handle(request: request, provenance: session.provenance, hosts: hosts)
|
||||
try session.write(agentResponse)
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -60,12 +60,19 @@ final class Notifier: Sendable {
|
||||
notificationCenter.requestAuthorization(options: .alert) { _, _ in }
|
||||
}
|
||||
|
||||
func notify(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) async {
|
||||
func notify(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance, target: SigningRequestTarget?) async {
|
||||
await notificationDelegate.state.setPending(secret: secret, store: store)
|
||||
let notificationCenter = UNUserNotificationCenter.current()
|
||||
let notificationContent = UNMutableNotificationContent()
|
||||
notificationContent.title = String(localized: .signedNotificationTitle(appName: provenance.origin.displayName))
|
||||
notificationContent.subtitle = String(localized: .signedNotificationDescription(secretName: secret.name))
|
||||
switch target {
|
||||
case .connection(let payload) where payload.host != nil:
|
||||
notificationContent.subtitle = String(localized: .signedConnectionNotificationDescription(secretName: secret.name, username: payload.username, host: payload.host!))
|
||||
case .signature(let payload):
|
||||
notificationContent.subtitle = String(localized: .signedSignatureNotificationDescription(secretName: secret.name, namespace: payload.namespace))
|
||||
default:
|
||||
notificationContent.subtitle = String(localized: .signedNotificationDescription(secretName: secret.name))
|
||||
}
|
||||
notificationContent.userInfo[Constants.persistSecretIDKey] = secret.id.description
|
||||
notificationContent.userInfo[Constants.persistStoreIDKey] = store.id.description
|
||||
notificationContent.interruptionLevel = .timeSensitive
|
||||
@@ -100,11 +107,21 @@ final class Notifier: Sendable {
|
||||
|
||||
extension Notifier: SigningWitness {
|
||||
|
||||
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) async throws {
|
||||
func speakNowOrForeverHoldYourPeace(
|
||||
forAccessTo secret: AnySecret,
|
||||
from store: AnySecretStore,
|
||||
by provenance: SigningRequestProvenance,
|
||||
target: SigningRequestTarget?
|
||||
) async throws {
|
||||
}
|
||||
|
||||
func witness(accessTo secret: AnySecret, from store: AnySecretStore, by provenance: SigningRequestProvenance) async throws {
|
||||
await notify(accessTo: secret, from: store, by: provenance)
|
||||
func witness(
|
||||
accessTo secret: AnySecret,
|
||||
from store: AnySecretStore,
|
||||
by provenance: SigningRequestProvenance,
|
||||
target: SigningRequestTarget?
|
||||
) async throws {
|
||||
await notify(accessTo: secret, from: store, by: provenance, target: target)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
<string>1</string>
|
||||
<key>com.apple.security.hardened-process.hardened-heap</key>
|
||||
<true/>
|
||||
<key>com.apple.security.hardened-process.platform-restrictions-string</key>
|
||||
<string>2</string>
|
||||
<key>com.apple.security.smartcard</key>
|
||||
<true/>
|
||||
<key>com.apple.security.hardened-process.platform-restrictions-string</key>
|
||||
<string>2</string>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$(AppIdentifierPrefix)com.maxgoedjen.Secretive</string>
|
||||
|
||||
36
Sources/SecretAgent/XPCHostsfileReader.swift
Normal file
36
Sources/SecretAgent/XPCHostsfileReader.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
import Foundation
|
||||
import OSLog
|
||||
import XPCWrappers
|
||||
import OSLog
|
||||
|
||||
public final class XPCHostsfileReader {
|
||||
|
||||
private let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "XPCHostsfileReader")
|
||||
private let session: XPCTypedSession<[Data: String], HostsfileReaderError>
|
||||
|
||||
public init() async throws {
|
||||
logger.debug("Creating XPCHostsfileReader")
|
||||
session = try await XPCTypedSession(serviceName: "com.maxgoedjen.Secretive.SecretAgentHostsfileReader", warmup: true)
|
||||
logger.debug("XPCHostsfileReader is warmed up.")
|
||||
}
|
||||
|
||||
public func read() async throws -> [Data: String] {
|
||||
logger.debug("Reading hosts file")
|
||||
defer { logger.debug("Read hosts file") }
|
||||
return try await session.send(Data())
|
||||
}
|
||||
|
||||
deinit {
|
||||
session.complete()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension XPCHostsfileReader {
|
||||
|
||||
public enum HostsfileReaderError: Error, Codable {
|
||||
case fileDoesNotExist
|
||||
case parseError
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user