Cleanup of agent

This commit is contained in:
Max Goedjen
2020-03-16 23:34:38 -07:00
parent 2095dd1203
commit 6d2f767c97
4 changed files with 46 additions and 7 deletions

View File

@@ -6,20 +6,20 @@ import SecretKit
public class Agent {
fileprivate let storeList: SecretStoreList
// fileprivate let notifier: Notifier
fileprivate let witness: SigningWitness?
fileprivate let writer = OpenSSHKeyWriter()
public init(storeList: SecretStoreList/*, notifier: Notifier*/) {
public init(storeList: SecretStoreList, witness: SigningWitness? = nil) {
os_log(.debug, "Agent is running")
self.storeList = storeList
// self.notifier = notifier
self.witness = witness
}
}
extension Agent {
public tfunc handle(fileHandle: FileHandle) {
public func handle(fileHandle: FileHandle) {
os_log(.debug, "Agent handling new data")
let data = fileHandle.availableData
guard !data.isEmpty else { return }
@@ -78,12 +78,17 @@ extension Agent {
let reader = OpenSSHReader(data: data)
let hash = try reader.readNextChunk()
guard let (store, secret) = secret(matching: hash) else {
os_log(.debug, "Agent did not have a key matching %@", hash as NSData)
throw AgentError.noMatchingKey
}
if let witness = witness {
try witness.witness(accessTo: secret)
}
let dataToSign = try reader.readNextChunk()
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)!
// Convert from DER formatted rep to raw (r||s)

View File

@@ -0,0 +1,8 @@
import Foundation
import SecretKit
public protocol SigningWitness {
func witness(accessTo secret: AnySecret) throws
}