mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
in go(), auth is now handled by looping over the auth methods the server requests
rewrote getauthmethods, returns a [AuthType] added authtype to list all auth types
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
A9FD375B2E143D77005319A8 /* GenericPasswordStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD375A2E143D77005319A8 /* GenericPasswordStore.swift */; };
|
A9FD375B2E143D77005319A8 /* GenericPasswordStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD375A2E143D77005319A8 /* GenericPasswordStore.swift */; };
|
||||||
A9FD375D2E143D7E005319A8 /* KeyStoreError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD375C2E143D7E005319A8 /* KeyStoreError.swift */; };
|
A9FD375D2E143D7E005319A8 /* KeyStoreError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD375C2E143D7E005319A8 /* KeyStoreError.swift */; };
|
||||||
A9FD375F2E14648E005319A8 /* KeyImporterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD375E2E14648E005319A8 /* KeyImporterView.swift */; };
|
A9FD375F2E14648E005319A8 /* KeyImporterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD375E2E14648E005319A8 /* KeyImporterView.swift */; };
|
||||||
|
A9FD37652E169937005319A8 /* AuthType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FD37642E169937005319A8 /* AuthType.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@@ -172,6 +173,7 @@
|
|||||||
A9FD375A2E143D77005319A8 /* GenericPasswordStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericPasswordStore.swift; sourceTree = "<group>"; };
|
A9FD375A2E143D77005319A8 /* GenericPasswordStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericPasswordStore.swift; sourceTree = "<group>"; };
|
||||||
A9FD375C2E143D7E005319A8 /* KeyStoreError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyStoreError.swift; sourceTree = "<group>"; };
|
A9FD375C2E143D7E005319A8 /* KeyStoreError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyStoreError.swift; sourceTree = "<group>"; };
|
||||||
A9FD375E2E14648E005319A8 /* KeyImporterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyImporterView.swift; sourceTree = "<group>"; };
|
A9FD375E2E14648E005319A8 /* KeyImporterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyImporterView.swift; sourceTree = "<group>"; };
|
||||||
|
A9FD37642E169937005319A8 /* AuthType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthType.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -316,6 +318,7 @@
|
|||||||
A93143C12DF61E8500FCD5DB /* SSH */ = {
|
A93143C12DF61E8500FCD5DB /* SSH */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
A9FD37642E169937005319A8 /* AuthType.swift */,
|
||||||
A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */,
|
A9C897EE2DF1A9A400EF9A5F /* SSHHandler.swift */,
|
||||||
A9C4140B2E096DB7005E3047 /* SSHError.swift */,
|
A9C4140B2E096DB7005E3047 /* SSHError.swift */,
|
||||||
A96C6A892E0C0B1100F377FE /* SSHState.swift */,
|
A96C6A892E0C0B1100F377FE /* SSHState.swift */,
|
||||||
@@ -613,6 +616,7 @@
|
|||||||
A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */,
|
A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */,
|
||||||
A9DA97712E0D30ED00142DDC /* HostSymbol.swift in Sources */,
|
A9DA97712E0D30ED00142DDC /* HostSymbol.swift in Sources */,
|
||||||
A96C90A12E12B87A00724253 /* TextBox.swift in Sources */,
|
A96C90A12E12B87A00724253 /* TextBox.swift in Sources */,
|
||||||
|
A9FD37652E169937005319A8 /* AuthType.swift in Sources */,
|
||||||
A96BE6A82E116E2B00C0FEE9 /* SessionsListView.swift in Sources */,
|
A96BE6A82E116E2B00C0FEE9 /* SessionsListView.swift in Sources */,
|
||||||
A96C90A32E12D53B00724253 /* KeyType.swift in Sources */,
|
A96C90A32E12D53B00724253 /* KeyType.swift in Sources */,
|
||||||
A98554612E058433009051BD /* HostsManager.swift in Sources */,
|
A98554612E058433009051BD /* HostsManager.swift in Sources */,
|
||||||
|
|||||||
27
ShhShell/SSH/AuthType.swift
Normal file
27
ShhShell/SSH/AuthType.swift
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// AuthType.swift
|
||||||
|
// ShhShell
|
||||||
|
//
|
||||||
|
// Created by neon443 on 03/07/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum AuthType: UInt32, CustomStringConvertible, CaseIterable {
|
||||||
|
case password = 2
|
||||||
|
case publickey = 4
|
||||||
|
case hostbased = 8
|
||||||
|
case interactive = 16
|
||||||
|
var description: String {
|
||||||
|
switch self {
|
||||||
|
case .password:
|
||||||
|
return "Password"
|
||||||
|
case .publickey:
|
||||||
|
return "Publickey"
|
||||||
|
case .hostbased:
|
||||||
|
return "Hostbased"
|
||||||
|
case .interactive:
|
||||||
|
return "Keyboard Interactive"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,57 +57,48 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func go() {
|
func go() {
|
||||||
guard !connected else {
|
guard !connected else { disconnect(); return }
|
||||||
disconnect()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do { try connect() } catch {
|
||||||
try connect()
|
print("error when connecting \(error.localizedDescription)")
|
||||||
} catch {
|
|
||||||
// print("error in connect \(error.localizedDescription)")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try authWithNone()
|
try authWithNone()
|
||||||
} catch {
|
} catch { print("auth with none is not authed") }
|
||||||
|
|
||||||
}
|
|
||||||
getAuthMethods()
|
|
||||||
|
|
||||||
if self.host.key != getHostkey() {
|
|
||||||
self.host.key = getHostkey()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard state != .authorized else { return }
|
guard state != .authorized else { return }
|
||||||
|
|
||||||
if !host.password.isEmpty {
|
//TODO: check hostkey
|
||||||
|
|
||||||
|
for method in getAuthMethods() {
|
||||||
|
switch method {
|
||||||
|
case .password:
|
||||||
do { try authWithPw() } catch {
|
do { try authWithPw() } catch {
|
||||||
state = .authFailed
|
state = .authFailed
|
||||||
print("pw auth error")
|
print("pw auth error")
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
} else {
|
case .publickey:
|
||||||
do {
|
do { try authWithPubkey() } catch {
|
||||||
if host.privateKeyID != nil {
|
|
||||||
try authWithPubkey()
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
state = .authFailed
|
state = .authFailed
|
||||||
print("error with pubkey auth")
|
print("error with pubkey auth")
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
case .hostbased:
|
||||||
|
disconnect()
|
||||||
|
case .interactive:
|
||||||
|
disconnect()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard state == .authorized else { return }
|
||||||
|
|
||||||
ssh_channel_request_env(channel, "TERM", "xterm-256color")
|
ssh_channel_request_env(channel, "TERM", "xterm-256color")
|
||||||
ssh_channel_request_env(channel, "LANG", "en_US.UTF-8")
|
ssh_channel_request_env(channel, "LANG", "en_US.UTF-8")
|
||||||
ssh_channel_request_env(channel, "LC_ALL", "en_US.UTF-8")
|
ssh_channel_request_env(channel, "LC_ALL", "en_US.UTF-8")
|
||||||
|
|
||||||
do {
|
do { try openShell() } catch {
|
||||||
try openShell()
|
|
||||||
} catch {
|
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,29 +306,16 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAuthMethods() {
|
func getAuthMethods() -> [AuthType] {
|
||||||
var recievedMethod: CInt
|
var result: [AuthType] = []
|
||||||
recievedMethod = ssh_userauth_list(session, nil)
|
let recievedMethod = UInt32(ssh_userauth_list(session, nil))
|
||||||
|
|
||||||
let allAuthDescriptions: [String] = [
|
for method in AuthType.allCases {
|
||||||
"password",
|
if (recievedMethod & method.rawValue) != 0 {
|
||||||
"publickey",
|
result.append(method)
|
||||||
"hostbased",
|
|
||||||
"interactive"
|
|
||||||
]
|
|
||||||
let allAuthRaws: [UInt32] = [
|
|
||||||
SSH_AUTH_METHOD_PASSWORD,
|
|
||||||
SSH_AUTH_METHOD_PUBLICKEY,
|
|
||||||
SSH_AUTH_METHOD_HOSTBASED,
|
|
||||||
SSH_AUTH_METHOD_INTERACTIVE
|
|
||||||
]
|
|
||||||
let allAuths = zip(allAuthDescriptions, allAuthRaws)
|
|
||||||
|
|
||||||
for authMethod in allAuths {
|
|
||||||
if (recievedMethod & Int32(authMethod.1)) != 0 {
|
|
||||||
print(authMethod.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: shell
|
//MARK: shell
|
||||||
|
|||||||
Reference in New Issue
Block a user