From 7efde31f413868ad295092840a4c99b62543f015 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 14 Dec 2025 11:46:23 -0800 Subject: [PATCH] Pulling out a bunch of openssh stuff to dedicated package. --- Package.swift | 16 ++++++++ Sources/Packages/Package.swift | 22 +++++++++-- Sources/Packages/Sources/Common/URLs.swift | 17 +++++++++ .../Sources/SSHProtocolKit/Data+Hex.swift | 37 +++++++++++++++++++ .../LengthAndData.swift | 0 .../OpenSSHPublicKeyWriter.swift | 5 +-- .../OpenSSHReader.swift | 27 +++++++++----- .../OpenSSHSignatureWriter.swift | 1 + .../SSHAgentProtocol.swift | 0 .../Sources/SecretAgentKit/Agent.swift | 1 + .../OpenSSHCertificateHandler.swift | 3 +- .../PublicKeyStandinFileController.swift | 19 ++++------ .../SecretAgentKit/SSHAgentInputParser.swift | 5 ++- .../OpenSSHPublicKeyWriterTests.swift | 7 ++-- .../SSHProtocolKitTests/TestSecret.swift | 11 ++++++ Sources/SecretAgent/AppDelegate.swift | 2 +- Sources/SecretAgent/XPCInputParser.swift | 1 + .../SecretAgentInputParser.swift | 1 + Sources/Secretive.xcodeproj/project.pbxproj | 7 ++++ .../Configuration/ToolConfigurationView.swift | 5 ++- .../Views/Secrets/SecretDetailView.swift | 5 ++- 21 files changed, 151 insertions(+), 41 deletions(-) create mode 100644 Sources/Packages/Sources/SSHProtocolKit/Data+Hex.swift rename Sources/Packages/Sources/{SecretKit/OpenSSH => SSHProtocolKit}/LengthAndData.swift (100%) rename Sources/Packages/Sources/{SecretKit/OpenSSH => SSHProtocolKit}/OpenSSHPublicKeyWriter.swift (96%) rename Sources/Packages/Sources/{SecretAgentKit => SSHProtocolKit}/OpenSSHReader.swift (52%) rename Sources/Packages/Sources/{SecretKit/OpenSSH => SSHProtocolKit}/OpenSSHSignatureWriter.swift (99%) rename Sources/Packages/Sources/{SecretAgentKit => SSHProtocolKit}/SSHAgentProtocol.swift (100%) rename Sources/Packages/Sources/{SecretKit => SecretAgentKit}/PublicKeyStandinFileController.swift (77%) rename Sources/Packages/Tests/{SecretKitTests => SSHProtocolKitTests}/OpenSSHPublicKeyWriterTests.swift (72%) create mode 100644 Sources/Packages/Tests/SSHProtocolKitTests/TestSecret.swift diff --git a/Package.swift b/Package.swift index 2ba06ef..3ca29ce 100644 --- a/Package.swift +++ b/Package.swift @@ -22,6 +22,9 @@ let package = Package( .library( name: "SmartCardSecretKit", targets: ["SmartCardSecretKit"]), + .library( + name: "SSHProtocolKit", + targets: ["SSHProtocolKit"]), ], dependencies: [ ], @@ -53,6 +56,19 @@ let package = Package( resources: [localization], swiftSettings: swiftSettings ), + .target( + name: "SSHProtocolKit", + dependencies: ["SecretKit"], + path: "Sources/Packages/Sources/SSHProtocolKit", + resources: [localization], + swiftSettings: swiftSettings, + ), + .testTarget( + name: "SSHProtocolKitTests", + dependencies: ["SSHProtocolKit"], + path: "Sources/Packages/Tests/SSHProtocolKitTests", + swiftSettings: swiftSettings, + ), ] ) diff --git a/Sources/Packages/Package.swift b/Sources/Packages/Package.swift index 92dc60d..5d48a5e 100644 --- a/Sources/Packages/Package.swift +++ b/Sources/Packages/Package.swift @@ -21,7 +21,7 @@ let package = Package( targets: ["SmartCardSecretKit"]), .library( name: "SecretAgentKit", - targets: ["SecretAgentKit", "XPCWrappers"]), + targets: ["SecretAgentKit"]), .library( name: "Common", targets: ["Common"]), @@ -31,6 +31,9 @@ let package = Package( .library( name: "XPCWrappers", targets: ["XPCWrappers"]), + .library( + name: "SSHProtocolKit", + targets: ["SSHProtocolKit"]), ], dependencies: [ ], @@ -60,7 +63,7 @@ let package = Package( ), .target( name: "SecretAgentKit", - dependencies: ["SecretKit"], + dependencies: ["SecretKit", "SSHProtocolKit", "Common"], resources: [localization], swiftSettings: swiftSettings, ), @@ -68,15 +71,26 @@ let package = Package( name: "SecretAgentKitTests", dependencies: ["SecretAgentKit"], ), + .target( + name: "SSHProtocolKit", + dependencies: ["SecretKit"], + resources: [localization], + swiftSettings: swiftSettings, + ), + .testTarget( + name: "SSHProtocolKitTests", + dependencies: ["SSHProtocolKit"], + swiftSettings: swiftSettings, + ), .target( name: "Common", - dependencies: [], + dependencies: ["SSHProtocolKit", "SecretKit"], resources: [localization], swiftSettings: swiftSettings, ), .target( name: "Brief", - dependencies: ["XPCWrappers"], + dependencies: ["XPCWrappers", "SSHProtocolKit"], resources: [localization], swiftSettings: swiftSettings, ), diff --git a/Sources/Packages/Sources/Common/URLs.swift b/Sources/Packages/Sources/Common/URLs.swift index a2f37f3..9dfee59 100644 --- a/Sources/Packages/Sources/Common/URLs.swift +++ b/Sources/Packages/Sources/Common/URLs.swift @@ -1,4 +1,6 @@ import Foundation +import SSHProtocolKit +import SecretKit extension URL { @@ -14,6 +16,20 @@ extension URL { #endif } + public static var publicKeyDirectory: URL { + agentHomeURL.appending(component: "PublicKeys") + } + + /// The path for a Secret's public key. + /// - Parameter secret: The Secret to return the path for. + /// - Returns: The path to the Secret's public key. + /// - Warning: This method returning a path does not imply that a key has been written to disk already. This method only describes where it will be written to. + public static func publicKeyPath(for secret: SecretType, in directory: URL) -> String { + let keyWriter = OpenSSHPublicKeyWriter() + let minimalHex = keyWriter.openSSHMD5Fingerprint(secret: secret).replacingOccurrences(of: ":", with: "") + return directory.appending(component: "\(minimalHex).pub").path() + } + } extension String { @@ -27,3 +43,4 @@ extension String { } } + diff --git a/Sources/Packages/Sources/SSHProtocolKit/Data+Hex.swift b/Sources/Packages/Sources/SSHProtocolKit/Data+Hex.swift new file mode 100644 index 0000000..bf1bb1d --- /dev/null +++ b/Sources/Packages/Sources/SSHProtocolKit/Data+Hex.swift @@ -0,0 +1,37 @@ +import Foundation +import CryptoKit + +public struct HexDataStyle: Hashable, Codable { + + let separator: String + + public init(separator: String) { + self.separator = separator + } + +} + +extension HexDataStyle: FormatStyle where SequenceType.Element == UInt8 { + + public func format(_ value: SequenceType) -> String { + value + .compactMap { ("0" + String($0, radix: 16, uppercase: false)).suffix(2) } + .joined(separator: separator) + } + +} + +extension FormatStyle where Self == HexDataStyle { + + public static func hex(separator: String = "") -> HexDataStyle { + HexDataStyle(separator: separator) + } + +} +extension FormatStyle where Self == HexDataStyle { + + public static func hex(separator: String = ":") -> HexDataStyle { + HexDataStyle(separator: separator) + } + +} diff --git a/Sources/Packages/Sources/SecretKit/OpenSSH/LengthAndData.swift b/Sources/Packages/Sources/SSHProtocolKit/LengthAndData.swift similarity index 100% rename from Sources/Packages/Sources/SecretKit/OpenSSH/LengthAndData.swift rename to Sources/Packages/Sources/SSHProtocolKit/LengthAndData.swift diff --git a/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHPublicKeyWriter.swift b/Sources/Packages/Sources/SSHProtocolKit/OpenSSHPublicKeyWriter.swift similarity index 96% rename from Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHPublicKeyWriter.swift rename to Sources/Packages/Sources/SSHProtocolKit/OpenSSHPublicKeyWriter.swift index 30249e0..2c669db 100644 --- a/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHPublicKeyWriter.swift +++ b/Sources/Packages/Sources/SSHProtocolKit/OpenSSHPublicKeyWriter.swift @@ -1,5 +1,6 @@ import Foundation import CryptoKit +import SecretKit /// Generates OpenSSH representations of the public key sof secrets. public struct OpenSSHPublicKeyWriter: Sendable { @@ -49,9 +50,7 @@ public struct OpenSSHPublicKeyWriter: Sendable { /// Generates an OpenSSH MD5 fingerprint string. /// - Returns: OpenSSH MD5 fingerprint string. public func openSSHMD5Fingerprint(secret: SecretType) -> String { - Insecure.MD5.hash(data: data(secret: secret)) - .compactMap { ("0" + String($0, radix: 16, uppercase: false)).suffix(2) } - .joined(separator: ":") + Insecure.MD5.hash(data: data(secret: secret)).formatted(.hex(separator: ":")) } public func comment(secret: SecretType) -> String { diff --git a/Sources/Packages/Sources/SecretAgentKit/OpenSSHReader.swift b/Sources/Packages/Sources/SSHProtocolKit/OpenSSHReader.swift similarity index 52% rename from Sources/Packages/Sources/SecretAgentKit/OpenSSHReader.swift rename to Sources/Packages/Sources/SSHProtocolKit/OpenSSHReader.swift index a3508e3..6378df2 100644 --- a/Sources/Packages/Sources/SecretAgentKit/OpenSSHReader.swift +++ b/Sources/Packages/Sources/SSHProtocolKit/OpenSSHReader.swift @@ -1,42 +1,49 @@ import Foundation /// Reads OpenSSH protocol data. -final class OpenSSHReader { +public final class OpenSSHReader { var remaining: Data + var done = false /// Initialize the reader with an OpenSSH data payload. /// - Parameter data: The data to read. - init(data: Data) { + public init(data: Data) { remaining = Data(data) } /// Reads the next chunk of data from the playload. /// - Returns: The next chunk of data. - func readNextChunk(convertEndianness: Bool = true) throws(OpenSSHReaderError) -> Data { - let littleEndianLength = try readNextBytes(as: UInt32.self) - let length = convertEndianness ? Int(littleEndianLength.bigEndian) : Int(littleEndianLength) + public func readNextChunk(convertEndianness: Bool = true) throws(OpenSSHReaderError) -> Data { + let length = try readNextBytes(as: UInt32.self, convertEndianness: convertEndianness) guard remaining.count >= length else { throw .beyondBounds } - let dataRange = 0..(as: T.Type) throws(OpenSSHReaderError) -> T { + public func readNextBytes(as: T.Type, convertEndianness: Bool = true) throws(OpenSSHReaderError) -> T { let size = MemoryLayout.size guard remaining.count >= size else { throw .beyondBounds } let lengthRange = 0.. String { + public func readNextChunkAsString(convertEndianness: Bool = true) throws(OpenSSHReaderError) -> String { try String(decoding: readNextChunk(convertEndianness: convertEndianness), as: UTF8.self) } - func readNextChunkAsSubReader(convertEndianness: Bool = true) throws(OpenSSHReaderError) -> OpenSSHReader { + public func readNextChunkAsSubReader(convertEndianness: Bool = true) throws(OpenSSHReaderError) -> OpenSSHReader { OpenSSHReader(data: try readNextChunk(convertEndianness: convertEndianness)) } diff --git a/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHSignatureWriter.swift b/Sources/Packages/Sources/SSHProtocolKit/OpenSSHSignatureWriter.swift similarity index 99% rename from Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHSignatureWriter.swift rename to Sources/Packages/Sources/SSHProtocolKit/OpenSSHSignatureWriter.swift index b713d53..e5c618d 100644 --- a/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHSignatureWriter.swift +++ b/Sources/Packages/Sources/SSHProtocolKit/OpenSSHSignatureWriter.swift @@ -1,5 +1,6 @@ import Foundation import CryptoKit +import SecretKit /// Generates OpenSSH representations of Secrets. public struct OpenSSHSignatureWriter: Sendable { diff --git a/Sources/Packages/Sources/SecretAgentKit/SSHAgentProtocol.swift b/Sources/Packages/Sources/SSHProtocolKit/SSHAgentProtocol.swift similarity index 100% rename from Sources/Packages/Sources/SecretAgentKit/SSHAgentProtocol.swift rename to Sources/Packages/Sources/SSHProtocolKit/SSHAgentProtocol.swift diff --git a/Sources/Packages/Sources/SecretAgentKit/Agent.swift b/Sources/Packages/Sources/SecretAgentKit/Agent.swift index 83ce175..ba66603 100644 --- a/Sources/Packages/Sources/SecretAgentKit/Agent.swift +++ b/Sources/Packages/Sources/SecretAgentKit/Agent.swift @@ -3,6 +3,7 @@ import CryptoKit import OSLog import SecretKit import AppKit +import SSHProtocolKit /// The `Agent` is an implementation of an SSH agent. It manages coordination and access between a socket, traces requests, notifies witnesses and passes requests to stores. public final class Agent: Sendable { diff --git a/Sources/Packages/Sources/SecretAgentKit/OpenSSHCertificateHandler.swift b/Sources/Packages/Sources/SecretAgentKit/OpenSSHCertificateHandler.swift index 5451e49..7fbb0b3 100644 --- a/Sources/Packages/Sources/SecretAgentKit/OpenSSHCertificateHandler.swift +++ b/Sources/Packages/Sources/SecretAgentKit/OpenSSHCertificateHandler.swift @@ -1,11 +1,12 @@ import Foundation import OSLog import SecretKit +import SSHProtocolKit /// Manages storage and lookup for OpenSSH certificates. public actor OpenSSHCertificateHandler: Sendable { - private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: URL.homeDirectory) + private let publicKeyFileStoreController = PublicKeyFileStoreController(directory: URL.publicKeyDirectory) private let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "OpenSSHCertificateHandler") private let writer = OpenSSHPublicKeyWriter() private var keyBlobsAndNames: [AnySecret: (Data, Data)] = [:] diff --git a/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift b/Sources/Packages/Sources/SecretAgentKit/PublicKeyStandinFileController.swift similarity index 77% rename from Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift rename to Sources/Packages/Sources/SecretAgentKit/PublicKeyStandinFileController.swift index 49e417e..a8aaffd 100644 --- a/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift +++ b/Sources/Packages/Sources/SecretAgentKit/PublicKeyStandinFileController.swift @@ -1,5 +1,8 @@ import Foundation import OSLog +import SecretKit +import SSHProtocolKit +import Common /// Controller responsible for writing public keys to disk, so that they're easily accessible by scripts. public final class PublicKeyFileStoreController: Sendable { @@ -9,8 +12,8 @@ public final class PublicKeyFileStoreController: Sendable { private let keyWriter = OpenSSHPublicKeyWriter() /// Initializes a PublicKeyFileStoreController. - public init(homeDirectory: URL) { - directory = homeDirectory.appending(component: "PublicKeys") + public init(directory: URL) { + self.directory = directory } /// Writes out the keys specified to disk. @@ -19,7 +22,7 @@ public final class PublicKeyFileStoreController: Sendable { public func generatePublicKeys(for secrets: [AnySecret], clear: Bool = false) throws { logger.log("Writing public keys to disk") if clear { - let validPaths = Set(secrets.map { publicKeyPath(for: $0) }) + let validPaths = Set(secrets.map { URL.publicKeyPath(for: $0, in: directory) }) .union(Set(secrets.map { sshCertificatePath(for: $0) })) let contentsOfDirectory = (try? FileManager.default.contentsOfDirectory(atPath: directory.path())) ?? [] let fullPathContents = contentsOfDirectory.map { directory.appending(path: $0).path() } @@ -33,21 +36,13 @@ public final class PublicKeyFileStoreController: Sendable { } try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false, attributes: nil) for secret in secrets { - let path = publicKeyPath(for: secret) + let path = URL.publicKeyPath(for: secret, in: directory) let data = Data(keyWriter.openSSHString(secret: secret).utf8) FileManager.default.createFile(atPath: path, contents: data, attributes: nil) } logger.log("Finished writing public keys") } - /// The path for a Secret's public key. - /// - Parameter secret: The Secret to return the path for. - /// - Returns: The path to the Secret's public key. - /// - Warning: This method returning a path does not imply that a key has been written to disk already. This method only describes where it will be written to. - public func publicKeyPath(for secret: SecretType) -> String { - let minimalHex = keyWriter.openSSHMD5Fingerprint(secret: secret).replacingOccurrences(of: ":", with: "") - return directory.appending(component: "\(minimalHex).pub").path() - } /// Short-circuit check to ship enumerating a bunch of paths if there's nothing in the cert directory. public var hasAnyCertificates: Bool { diff --git a/Sources/Packages/Sources/SecretAgentKit/SSHAgentInputParser.swift b/Sources/Packages/Sources/SecretAgentKit/SSHAgentInputParser.swift index 6e9a2ee..e8c4d61 100644 --- a/Sources/Packages/Sources/SecretAgentKit/SSHAgentInputParser.swift +++ b/Sources/Packages/Sources/SecretAgentKit/SSHAgentInputParser.swift @@ -1,11 +1,12 @@ import Foundation import OSLog import SecretKit +import SSHProtocolKit public protocol SSHAgentInputParserProtocol { func parse(data: Data) async throws -> SSHAgent.Request - + } public struct SSHAgentInputParser: SSHAgentInputParserProtocol { @@ -13,7 +14,7 @@ public struct SSHAgentInputParser: SSHAgentInputParserProtocol { private let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "InputParser") public init() { - + } public func parse(data: Data) throws(AgentParsingError) -> SSHAgent.Request { diff --git a/Sources/Packages/Tests/SecretKitTests/OpenSSHPublicKeyWriterTests.swift b/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift similarity index 72% rename from Sources/Packages/Tests/SecretKitTests/OpenSSHPublicKeyWriterTests.swift rename to Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift index 92c3132..806d399 100644 --- a/Sources/Packages/Tests/SecretKitTests/OpenSSHPublicKeyWriterTests.swift +++ b/Sources/Packages/Tests/SSHProtocolKitTests/OpenSSHPublicKeyWriterTests.swift @@ -1,8 +1,7 @@ import Foundation import Testing @testable import SecretKit -@testable import SecureEnclaveSecretKit -@testable import SmartCardSecretKit +import SSHProtocolKit @Suite struct OpenSSHPublicKeyWriterTests { @@ -47,8 +46,8 @@ import Testing extension OpenSSHPublicKeyWriterTests { enum Constants { - static let ecdsa256Secret = SmartCard.Secret(id: Data(), name: "Test Key (ECDSA 256)", publicKey: Data(base64Encoded: "BOVEjgAA5PHqRgwykjN5qM21uWCHFSY/Sqo5gkHAkn+e1MMQKHOLga7ucB9b3mif33MBid59GRK9GEPVlMiSQwo=")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 256), authentication: .notRequired, publicKeyAttribution: "test@example.com")) - static let ecdsa384Secret = SmartCard.Secret(id: Data(), name: "Test Key (ECDSA 384)", publicKey: Data(base64Encoded: "BG2MNc/C5OTHFE2tBvbZCVcpOGa8vBMquiTLkH4lwkeqOPxhi+PyYUfQZMTRJNPiTyWPoMBqNiCIFRVv60yPN/AHufHaOgbdTP42EgMlMMImkAjYUEv9DESHTVIs2PW1yQ==")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 384), authentication: .notRequired, publicKeyAttribution: "test@example.com")) + static let ecdsa256Secret = TestSecret(id: Data(), name: "Test Key (ECDSA 256)", publicKey: Data(base64Encoded: "BOVEjgAA5PHqRgwykjN5qM21uWCHFSY/Sqo5gkHAkn+e1MMQKHOLga7ucB9b3mif33MBid59GRK9GEPVlMiSQwo=")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 256), authentication: .notRequired, publicKeyAttribution: "test@example.com")) + static let ecdsa384Secret = TestSecret(id: Data(), name: "Test Key (ECDSA 384)", publicKey: Data(base64Encoded: "BG2MNc/C5OTHFE2tBvbZCVcpOGa8vBMquiTLkH4lwkeqOPxhi+PyYUfQZMTRJNPiTyWPoMBqNiCIFRVv60yPN/AHufHaOgbdTP42EgMlMMImkAjYUEv9DESHTVIs2PW1yQ==")!, attributes: Attributes(keyType: KeyType(algorithm: .ecdsa, size: 384), authentication: .notRequired, publicKeyAttribution: "test@example.com")) } diff --git a/Sources/Packages/Tests/SSHProtocolKitTests/TestSecret.swift b/Sources/Packages/Tests/SSHProtocolKitTests/TestSecret.swift new file mode 100644 index 0000000..7dca504 --- /dev/null +++ b/Sources/Packages/Tests/SSHProtocolKitTests/TestSecret.swift @@ -0,0 +1,11 @@ +import Foundation +import SecretKit + +public struct TestSecret: SecretKit.Secret { + + public let id: Data + public let name: String + public let publicKey: Data + public var attributes: Attributes + +} diff --git a/Sources/SecretAgent/AppDelegate.swift b/Sources/SecretAgent/AppDelegate.swift index b49cb81..49c109a 100644 --- a/Sources/SecretAgent/AppDelegate.swift +++ b/Sources/SecretAgent/AppDelegate.swift @@ -22,7 +22,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { }() private let updater = Updater(checkOnLaunch: true) private let notifier = Notifier() - private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: URL.homeDirectory) + private let publicKeyFileStoreController = PublicKeyFileStoreController(directory: URL.publicKeyDirectory) private lazy var agent: Agent = { Agent(storeList: storeList, witness: notifier) }() diff --git a/Sources/SecretAgent/XPCInputParser.swift b/Sources/SecretAgent/XPCInputParser.swift index b78f316..a3d7f28 100644 --- a/Sources/SecretAgent/XPCInputParser.swift +++ b/Sources/SecretAgent/XPCInputParser.swift @@ -3,6 +3,7 @@ import SecretAgentKit import Brief import XPCWrappers import OSLog +import SSHProtocolKit /// Delegates all agent input parsing to an XPC service which wraps OpenSSH public final class XPCAgentInputParser: SSHAgentInputParserProtocol { diff --git a/Sources/SecretAgentInputParser/SecretAgentInputParser.swift b/Sources/SecretAgentInputParser/SecretAgentInputParser.swift index cc0c8fd..6f69047 100644 --- a/Sources/SecretAgentInputParser/SecretAgentInputParser.swift +++ b/Sources/SecretAgentInputParser/SecretAgentInputParser.swift @@ -2,6 +2,7 @@ import Foundation import OSLog import XPCWrappers import SecretAgentKit +import SSHProtocolKit final class SecretAgentInputParser: NSObject, XPCProtocol { diff --git a/Sources/Secretive.xcodeproj/project.pbxproj b/Sources/Secretive.xcodeproj/project.pbxproj index bcd4b37..7d70771 100644 --- a/Sources/Secretive.xcodeproj/project.pbxproj +++ b/Sources/Secretive.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 2C4A9D2F2636FFD3008CC8E2 /* EditSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C4A9D2E2636FFD3008CC8E2 /* EditSecretView.swift */; }; 50020BB024064869003D4025 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50020BAF24064869003D4025 /* AppDelegate.swift */; }; + 5002C3AB2EEF483300FFAD22 /* XPCWrappers in Frameworks */ = {isa = PBXBuildFile; productRef = 5002C3AA2EEF483300FFAD22 /* XPCWrappers */; }; 5003EF3B278005E800DF2006 /* SecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF3A278005E800DF2006 /* SecretKit */; }; 5003EF3D278005F300DF2006 /* Brief in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF3C278005F300DF2006 /* Brief */; }; 5003EF3F278005F300DF2006 /* SecretAgentKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF3E278005F300DF2006 /* SecretAgentKit */; }; @@ -265,6 +266,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5002C3AB2EEF483300FFAD22 /* XPCWrappers in Frameworks */, 50692E6C2E6FFA510043C7BB /* SecretAgentKit in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -539,6 +541,7 @@ name = SecretAgentInputParser; packageProductDependencies = ( 50692E6B2E6FFA510043C7BB /* SecretAgentKit */, + 5002C3AA2EEF483300FFAD22 /* XPCWrappers */, ); productName = SecretAgentInputParser; productReference = 50692E502E6FF9D20043C7BB /* SecretAgentInputParser.xpc */; @@ -1499,6 +1502,10 @@ /* End XCConfigurationList section */ /* Begin XCSwiftPackageProductDependency section */ + 5002C3AA2EEF483300FFAD22 /* XPCWrappers */ = { + isa = XCSwiftPackageProductDependency; + productName = XPCWrappers; + }; 5003EF3A278005E800DF2006 /* SecretKit */ = { isa = XCSwiftPackageProductDependency; productName = SecretKit; diff --git a/Sources/Secretive/Views/Configuration/ToolConfigurationView.swift b/Sources/Secretive/Views/Configuration/ToolConfigurationView.swift index 8696e06..495254b 100644 --- a/Sources/Secretive/Views/Configuration/ToolConfigurationView.swift +++ b/Sources/Secretive/Views/Configuration/ToolConfigurationView.swift @@ -1,5 +1,7 @@ import SwiftUI import SecretKit +import SSHProtocolKit +import Common struct ToolConfigurationView: View { @@ -111,10 +113,9 @@ struct ToolConfigurationView: View { let writer = OpenSSHPublicKeyWriter() let gitAllowedSignersString = [email.isEmpty ? String(localized: .integrationsConfigureUsingEmailPlaceholder) : email, writer.openSSHString(secret: selectedSecret)] .joined(separator: " ") - let fileController = PublicKeyFileStoreController(homeDirectory: URL.agentHomeURL) return text .replacingOccurrences(of: Instructions.Constants.publicKeyPlaceholder, with: gitAllowedSignersString) - .replacingOccurrences(of: Instructions.Constants.publicKeyPathPlaceholder, with: fileController.publicKeyPath(for: selectedSecret)) + .replacingOccurrences(of: Instructions.Constants.publicKeyPathPlaceholder, with: URL.publicKeyPath(for: selectedSecret, in: URL.publicKeyDirectory)) } } diff --git a/Sources/Secretive/Views/Secrets/SecretDetailView.swift b/Sources/Secretive/Views/Secrets/SecretDetailView.swift index b3940ff..da9cf75 100644 --- a/Sources/Secretive/Views/Secrets/SecretDetailView.swift +++ b/Sources/Secretive/Views/Secrets/SecretDetailView.swift @@ -1,12 +1,13 @@ import SwiftUI import SecretKit +import Common +import SSHProtocolKit struct SecretDetailView: View { let secret: SecretType private let keyWriter = OpenSSHPublicKeyWriter() - private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: URL.agentHomeURL) var body: some View { ScrollView { @@ -21,7 +22,7 @@ struct SecretDetailView: View { CopyableView(title: .secretDetailPublicKeyLabel, image: Image(systemName: "key"), text: keyString) Spacer() .frame(height: 20) - CopyableView(title: .secretDetailPublicKeyPathLabel, image: Image(systemName: "lock.doc"), text: publicKeyFileStoreController.publicKeyPath(for: secret), showRevealInFinder: true) + CopyableView(title: .secretDetailPublicKeyPathLabel, image: Image(systemName: "lock.doc"), text: URL.publicKeyPath(for: secret, in: URL.publicKeyDirectory), showRevealInFinder: true) Spacer() } }