Store SSH private keys in Keychain instead of files
This commit is contained in:
parent
6b95e60ea1
commit
f1337622dc
9 changed files with 45 additions and 30 deletions
|
|
@ -22,6 +22,10 @@ public class AppKeychain {
|
|||
keychain[key] = string
|
||||
}
|
||||
|
||||
public static func contains(key: String) -> Bool {
|
||||
return (try? keychain.contains(key)) ?? false
|
||||
}
|
||||
|
||||
public static func get(for key: String) -> Data? {
|
||||
return try? keychain.getData(key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,3 +34,20 @@ public enum PgpKey: CryptographicKey {
|
|||
}
|
||||
}
|
||||
|
||||
public enum SshKey: CryptographicKey {
|
||||
case PRIVATE
|
||||
|
||||
public func getKeychainKey() -> String {
|
||||
switch self {
|
||||
case .PRIVATE:
|
||||
return "sshPrivateKey"
|
||||
}
|
||||
}
|
||||
|
||||
public func getFileSharingPath() -> String {
|
||||
switch self {
|
||||
case .PRIVATE:
|
||||
return Globals.iTunesFileSharingSSHPrivate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public extension DefaultsKeys {
|
|||
// Keep them for legacy reasons.
|
||||
static let pgpPublicKeyArmor = DefaultsKey<String?>("pgpPublicKeyArmor")
|
||||
static let pgpPrivateKeyArmor = DefaultsKey<String?>("pgpPrivateKeyArmor")
|
||||
static let gitSSHPrivateKeyArmor = DefaultsKey<String?>("gitSSHPrivateKeyArmor")
|
||||
|
||||
static let gitURL = DefaultsKey<URL?>("gitURL")
|
||||
static let gitAuthenticationMethod = DefaultsKey<String?>("gitAuthenticationMethod")
|
||||
|
|
@ -26,7 +27,6 @@ public extension DefaultsKeys {
|
|||
static let gitBranchName = DefaultsKey<String>("gitBranchName", defaultValue: "master")
|
||||
static let gitSSHPrivateKeyURL = DefaultsKey<URL?>("gitSSHPrivateKeyURL")
|
||||
static let gitSSHKeySource = DefaultsKey<String?>("gitSSHKeySource")
|
||||
static let gitSSHPrivateKeyArmor = DefaultsKey<String?>("gitSSHPrivateKeyArmor")
|
||||
static let gitSignatureName = DefaultsKey<String?>("gitSignatureName")
|
||||
static let gitSignatureEmail = DefaultsKey<String?>("gitSignatureEmail")
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public class KeyFileManager {
|
|||
|
||||
public static let PublicPgp = KeyFileManager(keyType: PgpKey.PUBLIC)
|
||||
public static let PrivatePgp = KeyFileManager(keyType: PgpKey.PRIVATE)
|
||||
public static let PrivateSsh = KeyFileManager(keyType: SshKey.PRIVATE)
|
||||
|
||||
private let keyType: CryptographicKey
|
||||
private let keyPath: String
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue