diff --git a/ShhShell.xcodeproj/project.pbxproj b/ShhShell.xcodeproj/project.pbxproj index aecfec4..c6da5bb 100644 --- a/ShhShell.xcodeproj/project.pbxproj +++ b/ShhShell.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ A95FAA562DF4B62A00DE2F5A /* openssl.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA512DF4B62100DE2F5A /* openssl.xcframework */; }; A95FAA572DF4B62A00DE2F5A /* openssl.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA512DF4B62100DE2F5A /* openssl.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A96C6A8A2E0C0B1100F377FE /* SSHState.swift in Sources */ = {isa = PBXBuildFile; fileRef = A96C6A892E0C0B1100F377FE /* SSHState.swift */; }; + A96C6AFE2E0C43B600F377FE /* Keypair.swift in Sources */ = {isa = PBXBuildFile; fileRef = A96C6AFD2E0C43B600F377FE /* Keypair.swift */; }; A98554552E05535F009051BD /* KeyManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98554542E05535F009051BD /* KeyManagerView.swift */; }; A98554592E0553AA009051BD /* KeyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98554582E0553AA009051BD /* KeyManager.swift */; }; A985545D2E055D4D009051BD /* ConnectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A985545C2E055D4D009051BD /* ConnectionView.swift */; }; @@ -95,6 +96,7 @@ A95FAA5B2DF4B7A000DE2F5A /* ci_pre_xcodebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_pre_xcodebuild.sh; sourceTree = ""; }; A95FAA5C2DF4B7A300DE2F5A /* ci_prost_xcodebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_prost_xcodebuild.sh; sourceTree = ""; }; A96C6A892E0C0B1100F377FE /* SSHState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHState.swift; sourceTree = ""; }; + A96C6AFD2E0C43B600F377FE /* Keypair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keypair.swift; sourceTree = ""; }; A98554542E05535F009051BD /* KeyManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManagerView.swift; sourceTree = ""; }; A98554582E0553AA009051BD /* KeyManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManager.swift; sourceTree = ""; }; A985545C2E055D4D009051BD /* ConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionView.swift; sourceTree = ""; }; @@ -246,6 +248,7 @@ isa = PBXGroup; children = ( A98554542E05535F009051BD /* KeyManagerView.swift */, + A96C6AFD2E0C43B600F377FE /* Keypair.swift */, ); path = Keys; sourceTree = ""; @@ -436,6 +439,7 @@ A9C897EF2DF1A9A400EF9A5F /* SSHHandler.swift in Sources */, A98554552E05535F009051BD /* KeyManagerView.swift in Sources */, A923172D2E07138000ECE1E6 /* SSHTerminalView.swift in Sources */, + A96C6AFE2E0C43B600F377FE /* Keypair.swift in Sources */, A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */, A923172A2E07113100ECE1E6 /* TerminalController.swift in Sources */, ); diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 1017968..675dca5 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -57,4 +57,16 @@ class HostsManager: ObservableObject { userDefaults.synchronize() } } + + func getKeys() -> [Keypair] { + var result: [Keypair] = [] + for host in savedHosts { + if !result.contains(where: { $0 == Keypair(publicKey: host.publicKey, privateKey: host.privateKey)}) { + + } else { + result.append(Keypair(publicKey: host.publicKey, privateKey: host.privateKey)) + } + } + return result + } } diff --git a/ShhShell/Views/ContentView.swift b/ShhShell/Views/ContentView.swift index 25ac8a6..64de759 100644 --- a/ShhShell/Views/ContentView.swift +++ b/ShhShell/Views/ContentView.swift @@ -22,7 +22,7 @@ struct ContentView: View { .tabItem { Label("Hosts", systemImage: "server.rack") } - KeyManagerView(keyManager: keyManager) + KeyManagerView(hostsManager: hostsManger, keyManager: keyManager) .tabItem { Label("Keys", systemImage: "key.2.on.ring") } diff --git a/ShhShell/Views/Keys/KeyManagerView.swift b/ShhShell/Views/Keys/KeyManagerView.swift index ed41e2f..f3f95ac 100644 --- a/ShhShell/Views/Keys/KeyManagerView.swift +++ b/ShhShell/Views/Keys/KeyManagerView.swift @@ -8,18 +8,47 @@ import SwiftUI struct KeyManagerView: View { + @ObservedObject var hostsManager: HostsManager @ObservedObject var keyManager: KeyManager var body: some View { - List { - Button("ed25519") { - keyManager.generateEd25519() - } - Button("rsa") { - do { - try keyManager.generateRSA() - } catch { - print(error.localizedDescription) + NavigationStack { + List { + Section { + ForEach(hostsManager.savedHosts) { host in + NavigationLink { + + } label: { + + } + } + } + Section { + NavigationLink { + List { + ForEach(hostsManager.savedHosts) { host in + Text(host.address) + .bold() + Text(host.key ?? "nil") + } + } + } label: { + HStack { + Image(systemName: "server.rack") + Image(systemName: "key.fill") + Text("Hostkey fingerprints") + } + } + } + Button("ed25519") { + keyManager.generateEd25519() + } + Button("rsa") { + do { + try keyManager.generateRSA() + } catch { + print(error.localizedDescription) + } } } } @@ -27,5 +56,8 @@ struct KeyManagerView: View { } #Preview { - KeyManagerView(keyManager: KeyManager()) + KeyManagerView( + hostsManager: HostsManager(), + keyManager: KeyManager() + ) } diff --git a/ShhShell/Views/Keys/Keypair.swift b/ShhShell/Views/Keys/Keypair.swift new file mode 100644 index 0000000..17f8e72 --- /dev/null +++ b/ShhShell/Views/Keys/Keypair.swift @@ -0,0 +1,26 @@ +// +// Keypair.swift +// ShhShell +// +// Created by neon443 on 25/06/2025. +// + +import Foundation + +protocol KeypairProtocol: Equatable, Codable, Hashable { + var publicKey: Data? { get set } + var privateKey: Data? { get set } +} + +struct Keypair: KeypairProtocol { + var publicKey: Data? + var privateKey: Data? + + init( + publicKey: Data?, + privateKey: Data? + ) { + self.publicKey = publicKey + self.privateKey = privateKey + } +} diff --git a/ShhShell/Views/Terminal/SSHTerminalView.swift b/ShhShell/Views/Terminal/SSHTerminalView.swift index 83033b0..1f96d4d 100644 --- a/ShhShell/Views/Terminal/SSHTerminalView.swift +++ b/ShhShell/Views/Terminal/SSHTerminalView.swift @@ -65,7 +65,7 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie } nonisolated public func scrolled(source: TerminalView, position: Double) { - print("scrolled to \(position)") + } nonisolated public func setTerminalTitle(source: TerminalView, title: String) { @@ -100,4 +100,9 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie nonisolated public func rangeChanged(source: TerminalView, startY: Int, endY: Int) { print(startY, endY) } + + public func bell(source: TerminalView) { + print("bell rung") + handler?.ring() + } }