From 32c658879903741f82b9512f43074546cfc034f7 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 18 Sep 2019 14:02:58 -0400 Subject: [PATCH 1/2] Fixes incorrect socket timeout value --- SwiftSH/Session.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftSH/Session.swift b/SwiftSH/Session.swift index dcf9b4b..e33d89b 100644 --- a/SwiftSH/Session.swift +++ b/SwiftSH/Session.swift @@ -166,7 +166,7 @@ open class SSHSession { } // Try to connect to resolved address - if CFSocketConnectToAddress(socket, dataAddress as CFData, Double(self.timeout)/1000) == .success { + if CFSocketConnectToAddress(socket, dataAddress as CFData, Double(self.timeout)) == .success { self.log.info("Connection to \(ipAddress) on port \(self.port) successful") self.socket = socket break From 4a7d339f17c930dc270eaa8f4ad204cea1afb126 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 2 Dec 2019 17:24:34 -0500 Subject: [PATCH 2/2] Disables logging by default --- SwiftSH/Session.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/SwiftSH/Session.swift b/SwiftSH/Session.swift index e33d89b..6397d50 100644 --- a/SwiftSH/Session.swift +++ b/SwiftSH/Session.swift @@ -37,10 +37,10 @@ open class SSHSession { /// The server host to connect to. public let host: String - + /// The server port to connect to. public let port: UInt16 - + /// The logger. public var log: Logger @@ -48,12 +48,12 @@ open class SSHSession { public var version: String { return self.sshLibrary.version } - + public init(sshLibrary: SSHLibrary.Type = Libssh2.self, host: String, port: UInt16 = 22) throws { self.sshLibrary = sshLibrary self.host = host self.port = port - self.log = ConsoleLogger(level: .debug, enabled: true) + self.log = ConsoleLogger(level: .debug, enabled: false) self.queue = Queue(label: "SSH Queue", concurrent: false) self.session = try sshLibrary.makeSession() self.timeout = 10 @@ -79,7 +79,7 @@ open class SSHSession { /// The banner received from the remote host. public fileprivate(set) var remoteBanner: String? - + /// The fingerprint received from the remote host. public fileprivate(set) var fingerprint: [FingerprintHashType: String] = [:] @@ -202,13 +202,13 @@ open class SSHSession { // Connection completed successfully self.connected = true - + // Get the remote banner self.remoteBanner = self.session.banner if let remoteBanner = self.remoteBanner { self.log.debug("Remote banner is \(remoteBanner)") } - + // Get the host's fingerprint self.fingerprint = [:] for hashType: FingerprintHashType in [.md5, .sha1] { @@ -247,13 +247,13 @@ open class SSHSession { if let socket = self.socket, CFSocketIsValid(socket) { CFSocketInvalidate(socket) } - + // Clean up state self.socket = nil self.connected = false self.remoteBanner = nil self.fingerprint = [:] - + self.log.debug("Disconnected") } } @@ -314,20 +314,20 @@ open class SSHSession { let privateKey = (privateKey as NSString).expandingTildeInPath try self.session.authenticateByPublicKeyFromFile(username, password: password, publicKey: publicKey, privateKey: privateKey) - + case .byPublicKeyFromMemory(let username, let password, let publicKey, let privateKey): // Public Key authentication try self.session.authenticateByPublicKeyFromMemory(username, password: password, publicKey: publicKey, privateKey: privateKey) } } } - + public func checkFingerprint(_ callback: @escaping ([FingerprintHashType: String]) -> Bool) -> Self { self.queue.async { guard self.connected else { return } - + let fingerprint = self.fingerprint var disconnect = false