mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 21:36:17 +00:00
just tried to revert to it being pastable textfields but nope it doesnt work
its bc its not base64 encoded maybe try that after?
This commit is contained in:
@@ -47,7 +47,7 @@ struct blankHost: HostPr {
|
|||||||
|
|
||||||
struct debugHost: HostPr {
|
struct debugHost: HostPr {
|
||||||
var address: String = "localhost"
|
var address: String = "localhost"
|
||||||
var port: Int = 32222
|
var port: Int = 22
|
||||||
var username: String = "default"
|
var username: String = "default"
|
||||||
var password: String = ""
|
var password: String = ""
|
||||||
var key: Data? = nil
|
var key: Data? = nil
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class SSHHandler: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func authWithPubkey(pub: Data, priv: Data, pass: String) {
|
func authWithPubkey(pub: String, priv: String, pass: String) {
|
||||||
guard session != nil else {
|
guard session != nil else {
|
||||||
withAnimation { authorized = false }
|
withAnimation { authorized = false }
|
||||||
return
|
return
|
||||||
@@ -184,8 +184,8 @@ class SSHHandler: ObservableObject {
|
|||||||
fileManager.createFile(atPath: tempPubkey.path(), contents: nil)
|
fileManager.createFile(atPath: tempPubkey.path(), contents: nil)
|
||||||
fileManager.createFile(atPath: tempKey.path(), contents: nil)
|
fileManager.createFile(atPath: tempKey.path(), contents: nil)
|
||||||
|
|
||||||
try? pub.write(to: tempPubkey)
|
try? Data(base64Encoded: pub)?.write(to: tempPubkey)
|
||||||
try? priv.write(to: tempKey)
|
try? Data(base64Encoded: priv)?.write(to: tempKey)
|
||||||
|
|
||||||
var pubkey: ssh_key?
|
var pubkey: ssh_key?
|
||||||
ssh_pki_import_pubkey_file(tempPubkey.path(), &pubkey)
|
ssh_pki_import_pubkey_file(tempPubkey.path(), &pubkey)
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ struct ContentView: View {
|
|||||||
|
|
||||||
@State var passphrase: String = ""
|
@State var passphrase: String = ""
|
||||||
|
|
||||||
@State var pubkeyData: Data?
|
@State var pubkey: String = ""
|
||||||
@State var privkeyData: Data?
|
@State var privkey: String = ""
|
||||||
|
|
||||||
@State var privPickerPresented: Bool = false
|
@State var privPickerPresented: Bool = false
|
||||||
@State var pubPickerPresented: Bool = false
|
@State var pubPickerPresented: Bool = false
|
||||||
@@ -21,31 +21,45 @@ struct ContentView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
List {
|
List {
|
||||||
Button("Choose Publickey") {
|
HStack {
|
||||||
|
TextField("", text: $pubkey, prompt: Text("Public Key"))
|
||||||
|
Button() {
|
||||||
pubPickerPresented.toggle()
|
pubPickerPresented.toggle()
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "folder")
|
||||||
}
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
.fileImporter(isPresented: $pubPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
.fileImporter(isPresented: $pubPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||||
do {
|
do {
|
||||||
let fileURL = try Result.get()
|
let fileURL = try Result.get()
|
||||||
pubkeyData = try? Data(contentsOf: fileURL)
|
let data = try! Data(contentsOf: fileURL)
|
||||||
|
pubkey = data.base64EncodedString()
|
||||||
print(fileURL)
|
print(fileURL)
|
||||||
} catch {
|
} catch {
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Button("Choose Privatekey") {
|
HStack {
|
||||||
|
TextField("", text: $pubkey, prompt: Text("Public Key"))
|
||||||
|
Button() {
|
||||||
privPickerPresented.toggle()
|
privPickerPresented.toggle()
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "folder")
|
||||||
}
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
.fileImporter(isPresented: $privPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
.fileImporter(isPresented: $privPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||||
do {
|
do {
|
||||||
let fileURL = try Result.get()
|
let fileURL = try Result.get()
|
||||||
privkeyData = try? Data(contentsOf: fileURL)
|
let data = try! Data(contentsOf: fileURL)
|
||||||
|
privkey = data.base64EncodedString()
|
||||||
print(fileURL)
|
print(fileURL)
|
||||||
} catch {
|
} catch {
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TextField("", text: $passphrase)
|
TextField("", text: $passphrase)
|
||||||
HStack {
|
HStack {
|
||||||
@@ -92,8 +106,8 @@ struct ContentView: View {
|
|||||||
} else {
|
} else {
|
||||||
Button() {
|
Button() {
|
||||||
handler.connect()
|
handler.connect()
|
||||||
if pubkeyData != nil && privkeyData != nil {
|
if !pubkey.isEmpty && !privkey.isEmpty {
|
||||||
handler.authWithPubkey(pub: pubkeyData!, priv: privkeyData!, pass: passphrase)
|
handler.authWithPubkey(pub: pubkey, priv: privkey, pass: passphrase)
|
||||||
} else {
|
} else {
|
||||||
let _ = handler.authWithPw()
|
let _ = handler.authWithPw()
|
||||||
}
|
}
|
||||||
@@ -102,7 +116,7 @@ struct ContentView: View {
|
|||||||
Label("Connect", systemImage: "powerplug.portrait")
|
Label("Connect", systemImage: "powerplug.portrait")
|
||||||
}
|
}
|
||||||
.disabled(
|
.disabled(
|
||||||
pubkeyData == nil && privkeyData == nil ||
|
pubkey.isEmpty && privkey.isEmpty ||
|
||||||
handler.host.username.isEmpty && handler.host.password.isEmpty
|
handler.host.username.isEmpty && handler.host.password.isEmpty
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user