mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-10 11:37:23 +01:00
XPC scaffolding
This commit is contained in:
@@ -24,6 +24,9 @@ let package = Package(
|
||||
.library(
|
||||
name: "SecretAgentKitHeaders",
|
||||
targets: ["SecretAgentKitHeaders"]),
|
||||
.library(
|
||||
name: "SecretAgentKitProtocol",
|
||||
targets: ["SecretAgentKitProtocol"]),
|
||||
.library(
|
||||
name: "Brief",
|
||||
targets: ["Brief"]),
|
||||
@@ -32,8 +35,7 @@ let package = Package(
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "SecretKit",
|
||||
dependencies: []
|
||||
name: "SecretKit"
|
||||
),
|
||||
.testTarget(
|
||||
name: "SecretKitTests",
|
||||
@@ -49,18 +51,20 @@ let package = Package(
|
||||
),
|
||||
.target(
|
||||
name: "SecretAgentKit",
|
||||
dependencies: ["SecretKit", "SecretAgentKitHeaders"]
|
||||
dependencies: ["SecretKit", "SecretAgentKitHeaders", "SecretAgentKitProtocol"]
|
||||
),
|
||||
.systemLibrary(
|
||||
name: "SecretAgentKitHeaders"
|
||||
),
|
||||
.target(
|
||||
name: "SecretAgentKitProtocol"
|
||||
),
|
||||
.testTarget(
|
||||
name: "SecretAgentKitTests",
|
||||
dependencies: ["SecretAgentKit"])
|
||||
,
|
||||
.target(
|
||||
name: "Brief",
|
||||
dependencies: []
|
||||
name: "Brief"
|
||||
),
|
||||
.testTarget(
|
||||
name: "BriefTests",
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
@objc public protocol AgentProtocol {
|
||||
func updatedStore(withID: UUID) async throws
|
||||
}
|
||||
|
||||
public struct AgentProtocolStoreNotFoundError: Error {
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,11 +58,13 @@ public class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable {
|
||||
private let _create: (String, Bool) throws -> Void
|
||||
private let _delete: (AnySecret) throws -> Void
|
||||
private let _update: (AnySecret, String) throws -> Void
|
||||
private let _reload: () throws -> Void
|
||||
|
||||
public init<SecretStoreType>(modifiable secretStore: SecretStoreType) where SecretStoreType: SecretStoreModifiable {
|
||||
_create = { try secretStore.create(name: $0, requiresAuthentication: $1) }
|
||||
_delete = { try secretStore.delete(secret: $0.base as! SecretStoreType.SecretType) }
|
||||
_update = { try secretStore.update(secret: $0.base as! SecretStoreType.SecretType, name: $1) }
|
||||
_reload = { try secretStore.reload() }
|
||||
super.init(secretStore)
|
||||
}
|
||||
|
||||
@@ -78,4 +80,8 @@ public class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable {
|
||||
try _update(secret, name)
|
||||
}
|
||||
|
||||
public func reload() throws {
|
||||
try _reload()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ public protocol SecretStoreModifiable: SecretStore {
|
||||
/// - name: The new name for the Secret.
|
||||
func update(secret: SecretType, name: String) throws
|
||||
|
||||
/// Reloads the secrets from the backing store.
|
||||
func reload() throws
|
||||
|
||||
}
|
||||
|
||||
extension NSNotification.Name {
|
||||
|
||||
@@ -23,9 +23,6 @@ extension SecureEnclave {
|
||||
|
||||
/// Initializes a Store.
|
||||
public init() {
|
||||
DistributedNotificationCenter.default().addObserver(forName: .secretStoreUpdated, object: nil, queue: .main) { _ in
|
||||
self.reloadSecrets(notify: false)
|
||||
}
|
||||
loadSecrets()
|
||||
}
|
||||
|
||||
@@ -68,7 +65,7 @@ extension SecureEnclave {
|
||||
throw KeychainError(statusCode: nil)
|
||||
}
|
||||
try savePublicKey(publicKey, name: name)
|
||||
reloadSecrets()
|
||||
reload()
|
||||
}
|
||||
|
||||
public func delete(secret: Secret) throws {
|
||||
@@ -80,7 +77,7 @@ extension SecureEnclave {
|
||||
if status != errSecSuccess {
|
||||
throw KeychainError(statusCode: status)
|
||||
}
|
||||
reloadSecrets()
|
||||
reload()
|
||||
}
|
||||
|
||||
public func update(secret: Secret, name: String) throws {
|
||||
@@ -97,9 +94,14 @@ extension SecureEnclave {
|
||||
if status != errSecSuccess {
|
||||
throw KeychainError(statusCode: status)
|
||||
}
|
||||
reloadSecrets()
|
||||
reload()
|
||||
}
|
||||
|
||||
|
||||
public func reload() {
|
||||
secrets.removeAll()
|
||||
loadSecrets()
|
||||
}
|
||||
|
||||
public func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> SignedData {
|
||||
let context: LAContext
|
||||
if let existing = persistedAuthenticationContexts[secret], existing.valid {
|
||||
@@ -170,16 +172,6 @@ extension SecureEnclave {
|
||||
|
||||
extension SecureEnclave.Store {
|
||||
|
||||
/// Reloads all secrets from the store.
|
||||
/// - Parameter notify: A boolean indicating whether a distributed notification should be posted, notifying other processes (ie, the SecretAgent) to reload their stores as well.
|
||||
private func reloadSecrets(notify: Bool = true) {
|
||||
secrets.removeAll()
|
||||
loadSecrets()
|
||||
if notify {
|
||||
DistributedNotificationCenter.default().post(name: .secretStoreUpdated, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads all secrets from the store.
|
||||
private func loadSecrets() {
|
||||
let attributes = [
|
||||
|
||||
Reference in New Issue
Block a user