mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
rewrote authwithpubkey - currently doesnt auth but it can save the pub/privkeys temporarily and import? testing rn
This commit is contained in:
@@ -164,16 +164,25 @@ class SSHHandler: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func authWithPubkey() -> Bool {
|
func authWithPubkey(pub: String, priv: String, pass: String) {
|
||||||
var status: CInt
|
let fileManager = FileManager.default
|
||||||
status = ssh_userauth_publickey_auto(session, nil, nil)
|
let tempDir = fileManager.temporaryDirectory
|
||||||
if status == SSH_AUTH_ERROR.rawValue {
|
let tempPubkey = tempDir.appendingPathComponent("key.pub")
|
||||||
print("pubkey auth failed")
|
let tempKey = tempDir.appendingPathComponent("key")
|
||||||
logSshGetError()
|
|
||||||
return false
|
fileManager.createFile(atPath: tempPubkey.path(), contents: nil)
|
||||||
}
|
fileManager.createFile(atPath: tempKey.path(), contents: nil)
|
||||||
withAnimation { authorized = true }
|
|
||||||
return true
|
try? pub.data(using: .utf8)?.write(to: tempPubkey)
|
||||||
|
try? priv.data(using: .utf8)?.write(to: tempKey)
|
||||||
|
|
||||||
|
var pubkey: ssh_key?
|
||||||
|
ssh_pki_import_pubkey_file(tempPubkey.path(), &pubkey)
|
||||||
|
let status = ssh_userauth_try_publickey(session, nil, pubkey)
|
||||||
|
print(status)
|
||||||
|
|
||||||
|
var privkey: ssh_key?
|
||||||
|
ssh_pki_import_privkey_file(tempKey.path(), pass, nil, nil, &privkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func authWithPw() -> Bool {
|
func authWithPw() -> Bool {
|
||||||
|
|||||||
@@ -9,11 +9,17 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@ObservedObject var handler: SSHHandler
|
@ObservedObject var handler: SSHHandler
|
||||||
// @State var connected: Bool = false
|
|
||||||
|
@State var pubkey: String = ""
|
||||||
|
@State var privkey: String = ""
|
||||||
|
@State var passphrase: String = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
List {
|
List {
|
||||||
|
TextField("", text: $pubkey)
|
||||||
|
TextField("", text: $privkey)
|
||||||
|
TextField("", text: $passphrase)
|
||||||
HStack {
|
HStack {
|
||||||
Text(handler.connected ? "connected" : "not connected")
|
Text(handler.connected ? "connected" : "not connected")
|
||||||
.modifier(foregroundColorStyle(handler.connected ? .green : .red))
|
.modifier(foregroundColorStyle(handler.connected ? .green : .red))
|
||||||
@@ -46,12 +52,16 @@ struct ContentView: View {
|
|||||||
TextField("username", text: $handler.host.username)
|
TextField("username", text: $handler.host.username)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
|
|
||||||
TextField("password", text: $handler.host.password)
|
SecureField("password", text: $handler.host.password)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
handler.connect()
|
handler.connect()
|
||||||
let _ = handler.authWithPw()
|
if !pubkey.isEmpty && !privkey.isEmpty {
|
||||||
|
handler.authWithPubkey(pub: pubkey, priv: privkey, pass: passphrase)
|
||||||
|
} else {
|
||||||
|
let _ = handler.authWithPw()
|
||||||
|
}
|
||||||
handler.openShell()
|
handler.openShell()
|
||||||
} label: {
|
} label: {
|
||||||
Label("Connect", systemImage: "powerplug.portrait")
|
Label("Connect", systemImage: "powerplug.portrait")
|
||||||
|
|||||||
Reference in New Issue
Block a user