SSHReverseTunnel Class

Properties   Methods   Events   Configuration Settings   Errors  

The SSHReverseTunnel class provides a simple way to establish a reverse tunnel with a SSH host.




The SSHReverseTunnel class may be used to establish a reverse tunnel with a SSH host. The SSH host will listen for incoming connections on the specified port and forward traffic to the class through the SSH tunnel.

The SSHHost and SSHPort properties specify the SSH server to use. The SSHUser and SSHPassword properties allow the client to authenticate itself with the server. The SSHServerAuthentication event and/or SSHAcceptServerHostKey property allow you to check the server identity. Finally, the SSHStatus event provides information about the SSH handshake.

To begin call SSHLogon to connect to the SSH host. After this method returns the connection to the SSH server has been successfully established. To establish a reverse tunnel call RequestForwarding. This method takes parameters to tell the SSH host on which port to listen.

The class has two modes that allow data to be dealt with directly from the events, or automatically forwarded on to a different endpoint.

Event Based Operation

In this mode any data received by the class over the tunnel causes the events of the class to fire. For instance:


In the above code forwarding is request from port 777 on the SSHHost. Any data received on port 777 by the SSHHost will be sent to the class. In the above code the last two parameters are empty or 0 indicating to the class that no local forwarding is requested.

Once RequestForwarding returns the SSH reverse tunnel is established and any connection made to the SSH host on the specified port will trigger events of the class to fire allowing you to handle the connection request and data.

When a client connects to the SSH host on the specified port the SSHChannelOpenRequest event will fire. Within this event choose to accept or reject the connection by setting the e.Accept parameter. This event contains details about the connection that may be used when determining whether to accept the connection.

After the channel is established data is received through the SSHChannelData event. To send data over the channel call the SendChannelData method. To close the channel call the CloseChannel method.

Local Forwarding

In this mode the any data received by the class is automatically forwarded to a separate endpoint. This allows the class to act as a sort of proxy. There is no need to handle data directly in this case. For instance:


In the above code forwarding is request from port 777 on SSHHost. The class is instructed to establish a connection to "" on port 80 when a client connect to SSHHost on port 777. Any data received from the client connected to SSHHost on port 777 will automatically be forwarded to "" on port 80. Any data received back from "" on port 80 will be sent back to the connected client.

In this mode data may flow freely from the client connected to the SSHHost to the endpoint specified in the RequestForwarding method without any additional code required.

Additional Notes

The following events are applicable when a connection is made to the SSH host:

To stop a previously established reverse tunnel call the CancelForwarding method.

Property List

The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

ChannelsA collection of currently open channels.
ConnectedTriggers a connection or disconnection.
FirewallA set of properties related to firewall access.
LocalHostThe name of the local host or user-assigned IP interface through which connections are initiated or accepted.
LocalPortThe TCP port in the local host where the class binds.
SSHAcceptServerHostKeyInstructs the class to accept the server host key that matches the supplied key.
SSHAuthModeThe authentication method to be used the class when calling SSHLogon .
SSHCertA certificate to be used for authenticating the SSHUser .
SSHCompressionAlgorithmsA comma-separated list containing all allowable compression algorithms.
SSHEncryptionAlgorithmsA comma-separated list containing all allowable encryption algorithms.
SSHHostThe address of the SSH host.
SSHPasswordThe password for SSH password-based authentication.
SSHPortThe port on the SSH server where the SSH service is running; by default, 22.
SSHUserThe username for SSH authentication.
TimeoutA timeout for the class.

Method List

The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

CancelForwardingRequests the server to stop forwarding a remote TCP/IP port.
CloseChannelCloses a existing SSHChannel .
ConfigSets or retrieves a configuration setting.
DecodePacketDecodes a hex-encoded SSH packet.
DoEventsProcesses events from the internal message queue.
EncodePacketHex encodes an SSH packet.
ExchangeKeysCauses the class to exchange a new set of session keys with the SSHHost .
GetSSHParamUsed to read a field from an SSH packet's payload.
GetSSHParamBytesUsed to read a field from an SSH packet's payload.
RequestForwardingRequests the server to forward a remote TCP/IP port.
ResetReset the class.
SendChannelDataUsed to send regular data over an SSH channel.
SetSSHParamUsed to write a field to the end of a payload.
SSHLogoffLogoff from the SSH server.
SSHLogonLogon to the SSHHost using the current SSHUser and SSHPassword .

Event List

The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

ConnectedFired immediately after a connection completes (or fails).
ConnectionStatusFired to indicate changes in connection state.
DisconnectedFired when a connection is closed.
ErrorInformation about errors during data delivery.
LogFires once for each log message.
ReconnectAttemptFires when attempting to reconnect.
SSHChannelClosedFired when a channel is closed.
SSHChannelDataFired when the SSHHost sends channel data to the client.
SSHChannelEOFFired when the remote peer signals the end of the data stream for the channel.
SSHChannelOpenedFired when a channel is successfully opened.
SSHChannelOpenRequestFired when the peer attempts to open a new channel.
SSHChannelReadyToSendFired when the class is ready to send data.
SSHChannelRequestFired when the SSHHost sends a channel request to the client.
SSHChannelRequestedFired if the SSHChannelRequest was successful, any further processing for the channel request should be done here.
SSHCustomAuthFired when the class is doing custom authentication.
SSHKeyboardInteractiveFired when the class receives a request for user input from the server.
SSHServerAuthenticationFired after the server presents its public key to the client.
SSHStatusShows the progress of the secure connection.

Configuration Settings

The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.

AutoReconnectWhether to automatically reestablish the SSH connection.
DefaultChannelIdleTimeoutThe inactivity timeout for channels.
ForwardedPortThe remote port which is forwarded.
ForwardingLocalHostThe interface on which to bind when forwarding data.
MaxRetryCountThe maximum number of retries when reconnecting.
RetryIntervalThe interval in seconds between reconnect attempts.
ClientSSHVersionStringThe SSH version string used by the class.
EnablePageantAuthWhether to use a key stored in Pageant to perform client authentication.
KerberosDelegationIf true, asks for credentials with delegation enabled during authentication.
KerberosRealmThe fully qualified domain name of the Kerberos Realm to use for GSSAPI authentication.
KerberosSPNThe Kerberos Service Principal Name of the SSH host.
KeyRenegotiationThresholdSets the threshold for the SSH Key Renegotiation.
LogLevelSpecifies the level of detail that is logged.
MaxPacketSizeThe maximum packet size of the channel, in bytes.
MaxWindowSizeThe maximum window size allowed for the channel, in bytes.
PasswordPromptThe text of the password prompt used in keyboard-interactive authentication.
PreferredDHGroupBitsThe size (in bits) of the preferred modulus (p) to request from the server.
RecordLengthThe length of received data records.
ServerSSHVersionStringThe remote host's SSH version string.
SignedSSHCertThe CA signed client public key used when authenticating.
SSHAcceptAnyServerHostKeyIf set the class will accept any key presented by the server.
SSHAcceptServerCAKeyThe CA public key that signed the server's host key.
SSHAcceptServerHostKeyFingerPrintThe fingerprint of the server key to accept.
SSHFingerprintHashAlgorithmThe algorithm used to calculate the fingerprint.
SSHFingerprintMD5The server hostkey's MD5 fingerprint.
SSHFingerprintSHA1The server hostkey's SHA1 fingerprint.
SSHFingerprintSHA256The server hostkey's SHA256 fingerprint.
SSHKeepAliveCountMaxThe maximum number of keep alive packets to send without a response.
SSHKeepAliveIntervalThe interval between keep alive packets.
SSHKeyExchangeAlgorithmsSpecifies the supported key exchange algorithms.
SSHKeyRenegotiateCauses the class to renegotiate the SSH keys.
SSHMacAlgorithmsSpecifies the supported Mac algorithms.
SSHPubKeyAuthSigAlgorithmsSpecifies the signature algorithm when attempting public key authentication.
SSHPublicKeyAlgorithmsSpecifies the supported public key algorithms.
SSHVersionPatternThe pattern used to match the remote host's version string.
TryAllAvailableAuthMethodsIf set to true, the class will try all available authentication methods.
WaitForChannelCloseWhether to wait for channels to be closed before disconnected.
WaitForServerDisconnectWhether to wait for the server to close the connection.
ConnectionTimeoutSets a separate timeout value for establishing a connection.
FirewallAutoDetectTells the class whether or not to automatically detect and use firewall system settings, if available.
FirewallHostName or IP address of firewall (optional).
FirewallPasswordPassword to be used if authentication is to be used when connecting through the firewall.
FirewallPortThe TCP port for the FirewallHost;.
FirewallTypeDetermines the type of firewall to connect through.
FirewallUserA user name if authentication is to be used connecting through a firewall.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
LingerWhen set to True, connections are terminated gracefully.
LingerTimeTime in seconds to have the connection linger.
LocalHostThe name of the local host through which connections are initiated or accepted.
LocalPortThe port in the local host where the class binds.
MaxLineLengthThe maximum amount of data to accumulate when no EOL is found.
MaxTransferRateThe transfer rate limit in bytes per second.
ProxyExceptionsListA semicolon separated list of hosts and IPs to bypass when using a proxy.
TCPKeepAliveDetermines whether or not the keep alive socket option is enabled.
TcpNoDelayWhether or not to delay when sending packets.
UseIPv6Whether to use IPv6.
AbsoluteTimeoutDetermines whether timeouts are inactivity timeouts or absolute timeouts.
FirewallDataUsed to send extra data to the firewall.
InBufferSizeThe size in bytes of the incoming queue of the socket.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
UseInternalSecurityAPITells the class whether or not to use the system security libraries or an internal implementation.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks SSH 2020 JS Edition - Version 20.0 [Build 8162]