mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
added keypair protocol
added bell support added getkeys added ui to show hostkeys all in one place
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
26
ShhShell/Views/Keys/Keypair.swift
Normal file
26
ShhShell/Views/Keys/Keypair.swift
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user