From db8833fa25c3d01a0ab8b1b30f7bea99879168a5 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Wed, 16 Feb 2022 22:15:47 -0800 Subject: [PATCH] Switch key reps to an md5 based name (#349) --- .../Sources/SecretKit/PublicKeyStandinFileController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift b/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift index 3f6db48..3d84317 100644 --- a/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift +++ b/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift @@ -6,6 +6,7 @@ public class PublicKeyFileStoreController { private let logger = Logger() private let directory: String + private let keyWriter = OpenSSHKeyWriter() /// Initializes a PublicKeyFileStoreController. public init(homeDirectory: String) { @@ -21,7 +22,6 @@ public class PublicKeyFileStoreController { try? FileManager.default.removeItem(at: URL(fileURLWithPath: directory)) } try? FileManager.default.createDirectory(at: URL(fileURLWithPath: directory), withIntermediateDirectories: false, attributes: nil) - let keyWriter = OpenSSHKeyWriter() for secret in secrets { let path = path(for: secret) guard let data = keyWriter.openSSHString(secret: secret).data(using: .utf8) else { continue } @@ -35,7 +35,8 @@ public class PublicKeyFileStoreController { /// - 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 path(for secret: SecretType) -> String { - directory.appending("/").appending("\(secret.name.replacingOccurrences(of: " ", with: "-")).pub") + let minimalHex = keyWriter.openSSHMD5Fingerprint(secret: secret).replacingOccurrences(of: ":", with: "") + return directory.appending("/").appending("\(minimalHex).pub") } }