-
-
Notifications
You must be signed in to change notification settings - Fork 118
feat: add reusable SSH tunnel profiles #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8743051
feat: add reusable SSH tunnel profiles (#381)
datlechin 3425d99
fix: prevent SSHProfileStorage from overwriting data on decode failure
datlechin c462a74
fix: remove unrelated DynamoDB target from pbxproj
datlechin b7d424b
fix: remove unrelated DynamoDB type from PR
datlechin 61b1ab3
fix: remove DynamoDB from changelog, localize labels, cache profile l…
datlechin 021cc7e
feat: add SSH profile editor with create, edit, save-as, and delete
datlechin 07ff075
fix: address review issues in SSH profile integration
datlechin 098dfec
feat: add iCloud sync for SSH profiles and documentation
datlechin 88deb90
docs: rewrite SSH profiles docs for accuracy and clarity
datlechin d372156
fix: address PR review - profile validation, secret cleanup, edit vs …
datlechin cf56490
fix: cache selected profile lookup, fix sshInlineFields indentation
datlechin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // | ||
| // SSHProfileStorage.swift | ||
| // TablePro | ||
| // | ||
|
|
||
| import Foundation | ||
| import os | ||
|
|
||
| final class SSHProfileStorage { | ||
| static let shared = SSHProfileStorage() | ||
| private static let logger = Logger(subsystem: "com.TablePro", category: "SSHProfileStorage") | ||
|
|
||
| private let profilesKey = "com.TablePro.sshProfiles" | ||
| private let defaults = UserDefaults.standard | ||
| private let encoder = JSONEncoder() | ||
| private let decoder = JSONDecoder() | ||
| private var lastLoadFailed = false | ||
|
|
||
| private init() {} | ||
|
|
||
| // MARK: - Profile CRUD | ||
|
|
||
| func loadProfiles() -> [SSHProfile] { | ||
| guard let data = defaults.data(forKey: profilesKey) else { | ||
| lastLoadFailed = false | ||
| return [] | ||
| } | ||
|
|
||
| do { | ||
| let profiles = try decoder.decode([SSHProfile].self, from: data) | ||
| lastLoadFailed = false | ||
| return profiles | ||
| } catch { | ||
| Self.logger.error("Failed to load SSH profiles: \(error)") | ||
| lastLoadFailed = true | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| func saveProfiles(_ profiles: [SSHProfile]) { | ||
| guard !lastLoadFailed else { | ||
| Self.logger.warning("Refusing to save SSH profiles: previous load failed (would overwrite existing data)") | ||
| return | ||
| } | ||
| do { | ||
| let data = try encoder.encode(profiles) | ||
| defaults.set(data, forKey: profilesKey) | ||
| SyncChangeTracker.shared.markDirty(.sshProfile, ids: profiles.map { $0.id.uuidString }) | ||
| } catch { | ||
| Self.logger.error("Failed to save SSH profiles: \(error)") | ||
| } | ||
| } | ||
|
|
||
| func saveProfilesWithoutSync(_ profiles: [SSHProfile]) { | ||
| guard !lastLoadFailed else { return } | ||
| do { | ||
| let data = try encoder.encode(profiles) | ||
| defaults.set(data, forKey: profilesKey) | ||
| } catch { | ||
| Self.logger.error("Failed to save SSH profiles: \(error)") | ||
| } | ||
| } | ||
|
|
||
| func addProfile(_ profile: SSHProfile) { | ||
| var profiles = loadProfiles() | ||
| guard !lastLoadFailed else { return } | ||
| profiles.append(profile) | ||
| saveProfiles(profiles) | ||
| } | ||
|
|
||
| func updateProfile(_ profile: SSHProfile) { | ||
| var profiles = loadProfiles() | ||
| guard !lastLoadFailed else { return } | ||
| if let index = profiles.firstIndex(where: { $0.id == profile.id }) { | ||
| profiles[index] = profile | ||
| saveProfiles(profiles) | ||
| } | ||
| } | ||
|
|
||
| func deleteProfile(_ profile: SSHProfile) { | ||
| SyncChangeTracker.shared.markDeleted(.sshProfile, id: profile.id.uuidString) | ||
| var profiles = loadProfiles() | ||
| guard !lastLoadFailed else { return } | ||
| profiles.removeAll { $0.id == profile.id } | ||
| saveProfiles(profiles) | ||
|
|
||
| deleteSSHPassword(for: profile.id) | ||
| deleteKeyPassphrase(for: profile.id) | ||
| deleteTOTPSecret(for: profile.id) | ||
| } | ||
|
|
||
| func profile(for id: UUID) -> SSHProfile? { | ||
| loadProfiles().first { $0.id == id } | ||
| } | ||
|
|
||
| // MARK: - SSH Password Storage | ||
|
|
||
| func saveSSHPassword(_ password: String, for profileId: UUID) { | ||
| let key = "com.TablePro.sshprofile.password.\(profileId.uuidString)" | ||
| KeychainHelper.shared.saveString(password, forKey: key) | ||
| } | ||
|
|
||
| func loadSSHPassword(for profileId: UUID) -> String? { | ||
| let key = "com.TablePro.sshprofile.password.\(profileId.uuidString)" | ||
| return KeychainHelper.shared.loadString(forKey: key) | ||
| } | ||
|
|
||
| func deleteSSHPassword(for profileId: UUID) { | ||
| let key = "com.TablePro.sshprofile.password.\(profileId.uuidString)" | ||
| KeychainHelper.shared.delete(key: key) | ||
| } | ||
|
|
||
| // MARK: - Key Passphrase Storage | ||
|
|
||
| func saveKeyPassphrase(_ passphrase: String, for profileId: UUID) { | ||
| let key = "com.TablePro.sshprofile.keypassphrase.\(profileId.uuidString)" | ||
| KeychainHelper.shared.saveString(passphrase, forKey: key) | ||
| } | ||
|
|
||
| func loadKeyPassphrase(for profileId: UUID) -> String? { | ||
| let key = "com.TablePro.sshprofile.keypassphrase.\(profileId.uuidString)" | ||
| return KeychainHelper.shared.loadString(forKey: key) | ||
| } | ||
|
|
||
| func deleteKeyPassphrase(for profileId: UUID) { | ||
| let key = "com.TablePro.sshprofile.keypassphrase.\(profileId.uuidString)" | ||
| KeychainHelper.shared.delete(key: key) | ||
| } | ||
|
|
||
| // MARK: - TOTP Secret Storage | ||
|
|
||
| func saveTOTPSecret(_ secret: String, for profileId: UUID) { | ||
| let key = "com.TablePro.sshprofile.totpsecret.\(profileId.uuidString)" | ||
| KeychainHelper.shared.saveString(secret, forKey: key) | ||
| } | ||
|
|
||
| func loadTOTPSecret(for profileId: UUID) -> String? { | ||
| let key = "com.TablePro.sshprofile.totpsecret.\(profileId.uuidString)" | ||
| return KeychainHelper.shared.loadString(forKey: key) | ||
| } | ||
|
|
||
| func deleteTOTPSecret(for profileId: UUID) { | ||
| let key = "com.TablePro.sshprofile.totpsecret.\(profileId.uuidString)" | ||
| KeychainHelper.shared.delete(key: key) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.