From a3b5ccbc3deb48c4e3f830d3e433467ed0d452d7 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 16 Nov 2021 23:04:46 -0800 Subject: [PATCH] WIP --- SecretAgent/AppDelegate.swift | 6 +++ .../PublicKeyStandinFileController.swift | 47 +++++++++++++++++++ Secretive.xcodeproj/project.pbxproj | 4 ++ 3 files changed, 57 insertions(+) create mode 100644 SecretAgentKit/PublicKeyStandinFileController.swift diff --git a/SecretAgent/AppDelegate.swift b/SecretAgent/AppDelegate.swift index d54210c..4234172 100644 --- a/SecretAgent/AppDelegate.swift +++ b/SecretAgent/AppDelegate.swift @@ -23,6 +23,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { let path = (NSHomeDirectory() as NSString).appendingPathComponent("socket.ssh") as String return SocketController(path: path) }() + private lazy var fakeFile: PublicKeyStandinFileStoreController = { + PublicKeyStandinFileStoreController(secrets: storeList.stores.flatMap({ $0.secrets })) + }() private var updateSink: AnyCancellable? func applicationDidFinishLaunching(_ aNotification: Notification) { @@ -35,6 +38,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { guard let update = update else { return } self.notifier.notify(update: update, ignore: self.updater.ignore(release:)) } + DispatchQueue.main.async { + print(self.fakeFile) + } } diff --git a/SecretAgentKit/PublicKeyStandinFileController.swift b/SecretAgentKit/PublicKeyStandinFileController.swift new file mode 100644 index 0000000..51b5421 --- /dev/null +++ b/SecretAgentKit/PublicKeyStandinFileController.swift @@ -0,0 +1,47 @@ +import Foundation +import SecretKit + +public class PublicKeyStandinFileStoreController { + + var files: [PublicKeyStandinFileController] = [] + + public init(secrets: [AnySecret]) { + let directory = NSHomeDirectory().appending("/PublicKeys") + try? FileManager.default.removeItem(at: URL(fileURLWithPath: directory)) + try? FileManager.default.createDirectory(at: URL(fileURLWithPath: directory), withIntermediateDirectories: false, attributes: nil) + // TODO: TEST + files = secrets.filter({ $0.name == "Git Signature"}) + /*files = secrets*/.map { PublicKeyStandinFileController(secret: $0, path: directory.appending("/").appending("test") )} + print("Done") + } + + enum Constants { + static var standinExtension = "secretive-public-key" + } + +} + +public class PublicKeyStandinFileController { + + private var fileHandle: FileHandle? + private let secret: AnySecret + private let keyWriter = OpenSSHKeyWriter() + + public init(secret: AnySecret, path: String) { + self.secret = secret + resetHandle(path: path) + } + + func resetHandle(path: String) { + try? FileManager.default.removeItem(atPath: path) + let fifo = mkfifo(UnsafePointer(Array(path.utf8CString)), S_IRWXU) + assert(fifo == 0) + fileHandle = nil + fileHandle = FileHandle(forWritingAtPath: path) + fileHandle?.writeabilityHandler = { [self] handle in + try! handle.write(contentsOf: keyWriter.openSSHString(secret: secret).data(using: .utf8)!) + try! fileHandle?.close() +// self.resetHandle(path: path) + } + } +} diff --git a/Secretive.xcodeproj/project.pbxproj b/Secretive.xcodeproj/project.pbxproj index 630f5c5..c025620 100644 --- a/Secretive.xcodeproj/project.pbxproj +++ b/Secretive.xcodeproj/project.pbxproj @@ -49,6 +49,7 @@ 506838A32415EA5D00F55094 /* AnySecretStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506838A22415EA5D00F55094 /* AnySecretStore.swift */; }; 506AB87E2412334700335D91 /* SecretAgent.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 50A3B78A24026B7500D209EA /* SecretAgent.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 5079BA0F250F29BF00EA86F4 /* StoreListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5079BA0E250F29BF00EA86F4 /* StoreListView.swift */; }; + 507CBBC92744AE4E00A0D79A /* PublicKeyStandinFileController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507CBBC82744AE4E00A0D79A /* PublicKeyStandinFileController.swift */; }; 507CE4ED2420A3C70029F750 /* Agent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A3B79F24026B9900D209EA /* Agent.swift */; }; 507CE4EE2420A3CA0029F750 /* SocketController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A3B79D24026B9900D209EA /* SocketController.swift */; }; 507CE4F02420A4C50029F750 /* SigningWitness.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507CE4EF2420A4C50029F750 /* SigningWitness.swift */; }; @@ -269,6 +270,7 @@ 506838A02415EA5600F55094 /* AnySecret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySecret.swift; sourceTree = ""; }; 506838A22415EA5D00F55094 /* AnySecretStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySecretStore.swift; sourceTree = ""; }; 5079BA0E250F29BF00EA86F4 /* StoreListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreListView.swift; sourceTree = ""; }; + 507CBBC82744AE4E00A0D79A /* PublicKeyStandinFileController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicKeyStandinFileController.swift; sourceTree = ""; }; 507CE4EF2420A4C50029F750 /* SigningWitness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SigningWitness.swift; sourceTree = ""; }; 507CE4F32420A8C10029F750 /* SigningRequestProvenance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SigningRequestProvenance.swift; sourceTree = ""; }; 507CE4F52420A96F0029F750 /* SigningRequestTracer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SigningRequestTracer.swift; sourceTree = ""; }; @@ -610,6 +612,7 @@ 5099A06E240242BA0062B6F2 /* SecretAgentKit.h */, 5099A089240242C20062B6F2 /* SSHAgentProtocol.swift */, 50A3B79D24026B9900D209EA /* SocketController.swift */, + 507CBBC82744AE4E00A0D79A /* PublicKeyStandinFileController.swift */, 507CE4EF2420A4C50029F750 /* SigningWitness.swift */, 507CE4F52420A96F0029F750 /* SigningRequestTracer.swift */, 50A3B79F24026B9900D209EA /* Agent.swift */, @@ -1102,6 +1105,7 @@ 5099A08A240242C20062B6F2 /* SSHAgentProtocol.swift in Sources */, 507CE4ED2420A3C70029F750 /* Agent.swift in Sources */, 507CE4F02420A4C50029F750 /* SigningWitness.swift in Sources */, + 507CBBC92744AE4E00A0D79A /* PublicKeyStandinFileController.swift in Sources */, 507CE4F62420A96F0029F750 /* SigningRequestTracer.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;