mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 05:19:13 +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 {
|
||||
var address: String = "localhost"
|
||||
var port: Int = 32222
|
||||
var port: Int = 22
|
||||
var username: String = "default"
|
||||
var password: String = ""
|
||||
var key: Data? = nil
|
||||
|
||||
@@ -169,7 +169,7 @@ class SSHHandler: ObservableObject {
|
||||
return
|
||||
}
|
||||
|
||||
func authWithPubkey(pub: Data, priv: Data, pass: String) {
|
||||
func authWithPubkey(pub: String, priv: String, pass: String) {
|
||||
guard session != nil else {
|
||||
withAnimation { authorized = false }
|
||||
return
|
||||
@@ -184,8 +184,8 @@ class SSHHandler: ObservableObject {
|
||||
fileManager.createFile(atPath: tempPubkey.path(), contents: nil)
|
||||
fileManager.createFile(atPath: tempKey.path(), contents: nil)
|
||||
|
||||
try? pub.write(to: tempPubkey)
|
||||
try? priv.write(to: tempKey)
|
||||
try? Data(base64Encoded: pub)?.write(to: tempPubkey)
|
||||
try? Data(base64Encoded: priv)?.write(to: tempKey)
|
||||
|
||||
var pubkey: ssh_key?
|
||||
ssh_pki_import_pubkey_file(tempPubkey.path(), &pubkey)
|
||||
|
||||
@@ -12,8 +12,8 @@ struct ContentView: View {
|
||||
|
||||
@State var passphrase: String = ""
|
||||
|
||||
@State var pubkeyData: Data?
|
||||
@State var privkeyData: Data?
|
||||
@State var pubkey: String = ""
|
||||
@State var privkey: String = ""
|
||||
|
||||
@State var privPickerPresented: Bool = false
|
||||
@State var pubPickerPresented: Bool = false
|
||||
@@ -21,29 +21,43 @@ struct ContentView: View {
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Button("Choose Publickey") {
|
||||
pubPickerPresented.toggle()
|
||||
}
|
||||
HStack {
|
||||
TextField("", text: $pubkey, prompt: Text("Public Key"))
|
||||
Button() {
|
||||
pubPickerPresented.toggle()
|
||||
} label: {
|
||||
Image(systemName: "folder")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.fileImporter(isPresented: $pubPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||
do {
|
||||
let fileURL = try Result.get()
|
||||
pubkeyData = try? Data(contentsOf: fileURL)
|
||||
let data = try! Data(contentsOf: fileURL)
|
||||
pubkey = data.base64EncodedString()
|
||||
print(fileURL)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
Button("Choose Privatekey") {
|
||||
privPickerPresented.toggle()
|
||||
}
|
||||
.fileImporter(isPresented: $privPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||
do {
|
||||
let fileURL = try Result.get()
|
||||
privkeyData = try? Data(contentsOf: fileURL)
|
||||
print(fileURL)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
|
||||
HStack {
|
||||
TextField("", text: $pubkey, prompt: Text("Public Key"))
|
||||
Button() {
|
||||
privPickerPresented.toggle()
|
||||
} label: {
|
||||
Image(systemName: "folder")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.fileImporter(isPresented: $privPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||
do {
|
||||
let fileURL = try Result.get()
|
||||
let data = try! Data(contentsOf: fileURL)
|
||||
privkey = data.base64EncodedString()
|
||||
print(fileURL)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +106,8 @@ struct ContentView: View {
|
||||
} else {
|
||||
Button() {
|
||||
handler.connect()
|
||||
if pubkeyData != nil && privkeyData != nil {
|
||||
handler.authWithPubkey(pub: pubkeyData!, priv: privkeyData!, pass: passphrase)
|
||||
if !pubkey.isEmpty && !privkey.isEmpty {
|
||||
handler.authWithPubkey(pub: pubkey, priv: privkey, pass: passphrase)
|
||||
} else {
|
||||
let _ = handler.authWithPw()
|
||||
}
|
||||
@@ -102,8 +116,8 @@ struct ContentView: View {
|
||||
Label("Connect", systemImage: "powerplug.portrait")
|
||||
}
|
||||
.disabled(
|
||||
pubkeyData == nil && privkeyData == nil ||
|
||||
handler.host.username.isEmpty && handler.host.password.isEmpty
|
||||
pubkey.isEmpty && privkey.isEmpty ||
|
||||
handler.host.username.isEmpty && handler.host.password.isEmpty
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user