mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-18 05:22:11 +00:00
Cleanup of agent
This commit is contained in:
parent
2095dd1203
commit
6d2f767c97
@ -1,5 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import SecretKit
|
import SecretKit
|
||||||
|
import SecretAgentKit
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
class Notifier {
|
class Notifier {
|
||||||
@ -10,7 +11,7 @@ class Notifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func notify<SecretType: Secret>(accessTo secret: SecretType) {
|
func notify(accessTo secret: AnySecret) {
|
||||||
let notificationCenter = UNUserNotificationCenter.current()
|
let notificationCenter = UNUserNotificationCenter.current()
|
||||||
let notificationContent = UNMutableNotificationContent()
|
let notificationContent = UNMutableNotificationContent()
|
||||||
notificationContent.title = "Signed Request"
|
notificationContent.title = "Signed Request"
|
||||||
@ -20,3 +21,11 @@ class Notifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Notifier: SigningWitness {
|
||||||
|
|
||||||
|
func witness(accessTo secret: AnySecret) throws {
|
||||||
|
notify(accessTo: secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -6,20 +6,20 @@ import SecretKit
|
|||||||
public class Agent {
|
public class Agent {
|
||||||
|
|
||||||
fileprivate let storeList: SecretStoreList
|
fileprivate let storeList: SecretStoreList
|
||||||
// fileprivate let notifier: Notifier
|
fileprivate let witness: SigningWitness?
|
||||||
fileprivate let writer = OpenSSHKeyWriter()
|
fileprivate let writer = OpenSSHKeyWriter()
|
||||||
|
|
||||||
public init(storeList: SecretStoreList/*, notifier: Notifier*/) {
|
public init(storeList: SecretStoreList, witness: SigningWitness? = nil) {
|
||||||
os_log(.debug, "Agent is running")
|
os_log(.debug, "Agent is running")
|
||||||
self.storeList = storeList
|
self.storeList = storeList
|
||||||
// self.notifier = notifier
|
self.witness = witness
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Agent {
|
extension Agent {
|
||||||
|
|
||||||
public tfunc handle(fileHandle: FileHandle) {
|
public func handle(fileHandle: FileHandle) {
|
||||||
os_log(.debug, "Agent handling new data")
|
os_log(.debug, "Agent handling new data")
|
||||||
let data = fileHandle.availableData
|
let data = fileHandle.availableData
|
||||||
guard !data.isEmpty else { return }
|
guard !data.isEmpty else { return }
|
||||||
@ -78,12 +78,17 @@ extension Agent {
|
|||||||
let reader = OpenSSHReader(data: data)
|
let reader = OpenSSHReader(data: data)
|
||||||
let hash = try reader.readNextChunk()
|
let hash = try reader.readNextChunk()
|
||||||
guard let (store, secret) = secret(matching: hash) else {
|
guard let (store, secret) = secret(matching: hash) else {
|
||||||
|
os_log(.debug, "Agent did not have a key matching %@", hash as NSData)
|
||||||
throw AgentError.noMatchingKey
|
throw AgentError.noMatchingKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let witness = witness {
|
||||||
|
try witness.witness(accessTo: secret)
|
||||||
|
}
|
||||||
|
|
||||||
let dataToSign = try reader.readNextChunk()
|
let dataToSign = try reader.readNextChunk()
|
||||||
let derSignature = try store.sign(data: dataToSign, with: secret)
|
let derSignature = try store.sign(data: dataToSign, with: secret)
|
||||||
// TODO: Move this
|
|
||||||
// notifier.notify(accessTo: secret)
|
|
||||||
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
||||||
|
|
||||||
// Convert from DER formatted rep to raw (r||s)
|
// Convert from DER formatted rep to raw (r||s)
|
||||||
|
8
SecretAgentKit/SigningWitness.swift
Normal file
8
SecretAgentKit/SigningWitness.swift
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import Foundation
|
||||||
|
import SecretKit
|
||||||
|
|
||||||
|
public protocol SigningWitness {
|
||||||
|
|
||||||
|
func witness(accessTo secret: AnySecret) throws
|
||||||
|
|
||||||
|
}
|
@ -34,6 +34,7 @@
|
|||||||
50731669241E00C20023809E /* NoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50731668241E00C20023809E /* NoticeView.swift */; };
|
50731669241E00C20023809E /* NoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50731668241E00C20023809E /* NoticeView.swift */; };
|
||||||
507CE4ED2420A3C70029F750 /* Agent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A3B79F24026B9900D209EA /* Agent.swift */; };
|
507CE4ED2420A3C70029F750 /* Agent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A3B79F24026B9900D209EA /* Agent.swift */; };
|
||||||
507CE4EE2420A3CA0029F750 /* SocketController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A3B79D24026B9900D209EA /* SocketController.swift */; };
|
507CE4EE2420A3CA0029F750 /* SocketController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A3B79D24026B9900D209EA /* SocketController.swift */; };
|
||||||
|
507CE4F02420A4C50029F750 /* SigningWitness.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507CE4EF2420A4C50029F750 /* SigningWitness.swift */; };
|
||||||
508A58AA241E06B40069DC07 /* PreviewUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58A9241E06B40069DC07 /* PreviewUpdater.swift */; };
|
508A58AA241E06B40069DC07 /* PreviewUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58A9241E06B40069DC07 /* PreviewUpdater.swift */; };
|
||||||
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */; };
|
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */; };
|
||||||
508A58B5241ED48F0069DC07 /* PreviewAgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B4241ED48F0069DC07 /* PreviewAgentStatusChecker.swift */; };
|
508A58B5241ED48F0069DC07 /* PreviewAgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B4241ED48F0069DC07 /* PreviewAgentStatusChecker.swift */; };
|
||||||
@ -98,6 +99,13 @@
|
|||||||
remoteGlobalIDString = 50617DA723FCE4AB0099B055;
|
remoteGlobalIDString = 50617DA723FCE4AB0099B055;
|
||||||
remoteInfo = SecretKit;
|
remoteInfo = SecretKit;
|
||||||
};
|
};
|
||||||
|
507CE4F12420A6B50029F750 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = 50617D7723FCE48D0099B055 /* Project object */;
|
||||||
|
proxyType = 1;
|
||||||
|
remoteGlobalIDString = 50617DA723FCE4AB0099B055;
|
||||||
|
remoteInfo = SecretKit;
|
||||||
|
};
|
||||||
5099A076240242BA0062B6F2 /* PBXContainerItemProxy */ = {
|
5099A076240242BA0062B6F2 /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = 50617D7723FCE48D0099B055 /* Project object */;
|
containerPortal = 50617D7723FCE48D0099B055 /* Project object */;
|
||||||
@ -194,6 +202,7 @@
|
|||||||
506838A22415EA5D00F55094 /* AnySecretStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySecretStore.swift; sourceTree = "<group>"; };
|
506838A22415EA5D00F55094 /* AnySecretStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySecretStore.swift; sourceTree = "<group>"; };
|
||||||
50731665241DF8660023809E /* Updater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Updater.swift; sourceTree = "<group>"; };
|
50731665241DF8660023809E /* Updater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Updater.swift; sourceTree = "<group>"; };
|
||||||
50731668241E00C20023809E /* NoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeView.swift; sourceTree = "<group>"; };
|
50731668241E00C20023809E /* NoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeView.swift; sourceTree = "<group>"; };
|
||||||
|
507CE4EF2420A4C50029F750 /* SigningWitness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SigningWitness.swift; sourceTree = "<group>"; };
|
||||||
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUpdater.swift; sourceTree = "<group>"; };
|
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUpdater.swift; sourceTree = "<group>"; };
|
||||||
508A58AB241E121B0069DC07 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
508A58AB241E121B0069DC07 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
||||||
508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgentStatusChecker.swift; sourceTree = "<group>"; };
|
508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgentStatusChecker.swift; sourceTree = "<group>"; };
|
||||||
@ -458,6 +467,7 @@
|
|||||||
5099A06E240242BA0062B6F2 /* SecretAgentKit.h */,
|
5099A06E240242BA0062B6F2 /* SecretAgentKit.h */,
|
||||||
5099A089240242C20062B6F2 /* SSHAgentProtocol.swift */,
|
5099A089240242C20062B6F2 /* SSHAgentProtocol.swift */,
|
||||||
50A3B79D24026B9900D209EA /* SocketController.swift */,
|
50A3B79D24026B9900D209EA /* SocketController.swift */,
|
||||||
|
507CE4EF2420A4C50029F750 /* SigningWitness.swift */,
|
||||||
50A3B79F24026B9900D209EA /* Agent.swift */,
|
50A3B79F24026B9900D209EA /* Agent.swift */,
|
||||||
5099A06F240242BA0062B6F2 /* Info.plist */,
|
5099A06F240242BA0062B6F2 /* Info.plist */,
|
||||||
);
|
);
|
||||||
@ -611,6 +621,7 @@
|
|||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
dependencies = (
|
dependencies = (
|
||||||
|
507CE4F22420A6B50029F750 /* PBXTargetDependency */,
|
||||||
);
|
);
|
||||||
name = SecretAgentKit;
|
name = SecretAgentKit;
|
||||||
productName = SecretAgentKit;
|
productName = SecretAgentKit;
|
||||||
@ -838,6 +849,7 @@
|
|||||||
507CE4EE2420A3CA0029F750 /* SocketController.swift in Sources */,
|
507CE4EE2420A3CA0029F750 /* SocketController.swift in Sources */,
|
||||||
5099A08A240242C20062B6F2 /* SSHAgentProtocol.swift in Sources */,
|
5099A08A240242C20062B6F2 /* SSHAgentProtocol.swift in Sources */,
|
||||||
507CE4ED2420A3C70029F750 /* Agent.swift in Sources */,
|
507CE4ED2420A3C70029F750 /* Agent.swift in Sources */,
|
||||||
|
507CE4F02420A4C50029F750 /* SigningWitness.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -886,6 +898,11 @@
|
|||||||
target = 50617DA723FCE4AB0099B055 /* SecretKit */;
|
target = 50617DA723FCE4AB0099B055 /* SecretKit */;
|
||||||
targetProxy = 50617DBB23FCE4AB0099B055 /* PBXContainerItemProxy */;
|
targetProxy = 50617DBB23FCE4AB0099B055 /* PBXContainerItemProxy */;
|
||||||
};
|
};
|
||||||
|
507CE4F22420A6B50029F750 /* PBXTargetDependency */ = {
|
||||||
|
isa = PBXTargetDependency;
|
||||||
|
target = 50617DA723FCE4AB0099B055 /* SecretKit */;
|
||||||
|
targetProxy = 507CE4F12420A6B50029F750 /* PBXContainerItemProxy */;
|
||||||
|
};
|
||||||
5099A077240242BA0062B6F2 /* PBXTargetDependency */ = {
|
5099A077240242BA0062B6F2 /* PBXTargetDependency */ = {
|
||||||
isa = PBXTargetDependency;
|
isa = PBXTargetDependency;
|
||||||
target = 5099A06B240242BA0062B6F2 /* SecretAgentKit */;
|
target = 5099A06B240242BA0062B6F2 /* SecretAgentKit */;
|
||||||
|
Loading…
Reference in New Issue
Block a user