mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
track authorization status fixing freeze when trying to auth when already authorized
fix authWithNone fix debug settings
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
A92538CD2DEE0744007E0A18 /* ShhShellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538CB2DEE0744007E0A18 /* ShhShellTests.swift */; };
|
||||
A92538D12DEE0745007E0A18 /* ShhShellUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538CE2DEE0745007E0A18 /* ShhShellUITests.swift */; };
|
||||
A92538D22DEE0745007E0A18 /* ShhShellUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538CF2DEE0745007E0A18 /* ShhShellUITestsLaunchTests.swift */; };
|
||||
A95FAA452DF3870B00DE2F5A /* libssh2.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA442DF3870A00DE2F5A /* libssh2.xcframework */; };
|
||||
A9C897EF2DF1A9A400EF9A5F /* SSHHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */; };
|
||||
A9C897F12DF1AB5700EF9A5F /* ShellHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C897F02DF1AB5700EF9A5F /* ShellHandler.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
@@ -68,6 +69,7 @@
|
||||
A92538CB2DEE0744007E0A18 /* ShhShellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShhShellTests.swift; sourceTree = "<group>"; };
|
||||
A92538CE2DEE0745007E0A18 /* ShhShellUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShhShellUITests.swift; sourceTree = "<group>"; };
|
||||
A92538CF2DEE0745007E0A18 /* ShhShellUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShhShellUITestsLaunchTests.swift; sourceTree = "<group>"; };
|
||||
A95FAA442DF3870A00DE2F5A /* libssh2.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libssh2.xcframework; path = ../blink/xcfs/.build/artifacts/xcfs/libssh2/libssh2.xcframework; sourceTree = SOURCE_ROOT; };
|
||||
A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHHandler.swift; sourceTree = "<group>"; };
|
||||
A9C897F02DF1AB5700EF9A5F /* ShellHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellHandler.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
@@ -79,6 +81,7 @@
|
||||
files = (
|
||||
A9083E372DF221AE0042906E /* LibSSH.xcframework in Frameworks */,
|
||||
A9083E402DF2226F0042906E /* libz.tbd in Frameworks */,
|
||||
A95FAA452DF3870B00DE2F5A /* libssh2.xcframework in Frameworks */,
|
||||
A9083E412DF222920042906E /* openssl.xcframework in Frameworks */,
|
||||
A9083E322DF2214A0042906E /* LibSSH.xcframework in Frameworks */,
|
||||
);
|
||||
@@ -173,6 +176,7 @@
|
||||
A9083E3F2DF2225A0042906E /* libz.tbd */,
|
||||
A9083E342DF2218D0042906E /* openssl.xcframework */,
|
||||
A9083E312DF2214A0042906E /* LibSSH.xcframework */,
|
||||
A95FAA442DF3870A00DE2F5A /* libssh2.xcframework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
|
||||
@@ -12,6 +12,7 @@ import OSLog
|
||||
class SSHHandler: ObservableObject {
|
||||
var session: ssh_session?
|
||||
|
||||
@Published var authorized: Bool = false
|
||||
@Published var username: String
|
||||
@Published var password: String
|
||||
@Published var address: String
|
||||
@@ -25,16 +26,16 @@ class SSHHandler: ObservableObject {
|
||||
address: String = "",
|
||||
port: Int = 22
|
||||
) {
|
||||
#if DEBUG
|
||||
self.username = "root"
|
||||
self.password = "root"
|
||||
self.address = "localhost"
|
||||
self.port = 2222
|
||||
#endif
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.address = address
|
||||
self.port = port
|
||||
#if DEBUG
|
||||
self.username = "root"
|
||||
self.password = "root"
|
||||
self.address = "localhost"
|
||||
self.port = 2222
|
||||
#endif
|
||||
}
|
||||
|
||||
func getHostkey() {
|
||||
@@ -82,6 +83,8 @@ class SSHHandler: ObservableObject {
|
||||
}
|
||||
ssh_disconnect(session)
|
||||
ssh_free(session)
|
||||
session = nil
|
||||
authorized = false
|
||||
}
|
||||
|
||||
func testExec() -> Bool {
|
||||
@@ -91,7 +94,7 @@ class SSHHandler: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
guard authWithPw() else { return false }
|
||||
guard authorized else { return false }
|
||||
|
||||
var status: CInt
|
||||
var buffer: [Int] = Array(repeating: 0, count: 256)
|
||||
@@ -158,18 +161,20 @@ class SSHHandler: ObservableObject {
|
||||
logSshGetError()
|
||||
return false
|
||||
}
|
||||
authorized = true
|
||||
return true
|
||||
}
|
||||
|
||||
func authWithPw() -> Bool {
|
||||
var status: CInt
|
||||
status = ssh_userauth_password(session, username, password)
|
||||
guard status != SSH_AUTH_SUCCESS.rawValue else {
|
||||
guard status == SSH_AUTH_SUCCESS.rawValue else {
|
||||
print("ssh pw auth error")
|
||||
logSshGetError()
|
||||
return false
|
||||
}
|
||||
print("auth success")
|
||||
authorized = true
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -222,17 +227,17 @@ class SSHHandler: ObservableObject {
|
||||
}
|
||||
status = ssh_userauth_kbdint(session, nil, nil)
|
||||
}
|
||||
authorized = true
|
||||
return true
|
||||
}
|
||||
|
||||
func authWithNone() -> Bool {
|
||||
let status = ssh_userauth_none(session, nil)
|
||||
if status == SSH_AUTH_SUCCESS.rawValue {
|
||||
print("no security moment lol")
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
guard status == SSH_AUTH_SUCCESS.rawValue else { return false }
|
||||
|
||||
print("no security moment lol")
|
||||
authorized = true
|
||||
return true
|
||||
}
|
||||
|
||||
func getAuthMethods() {
|
||||
|
||||
@@ -31,7 +31,7 @@ struct ContentView: View {
|
||||
handler.connect()
|
||||
handler.authWithPw()
|
||||
}
|
||||
Button("disconnect & free") {
|
||||
Button("disconnect") {
|
||||
handler.disconnect()
|
||||
}
|
||||
Button("testExec") {
|
||||
|
||||
Reference in New Issue
Block a user