SshTunnel C Reference Documentation

SshTunnel

Current Version: 11.5.0

Chilkat.SshTunnel

Create SSH tunnels for secure local, fixed-destination, dynamic, and multi-hop forwarding.

Chilkat.SshTunnel creates SSH tunnels for forwarding local client connections through an SSH server to a destination service, such as a database server or other TCP service. It supports fixed destination forwarding, dynamic SOCKS-style port forwarding, password and public-key authentication, keyboard-interactive authentication, proxy connections to the SSH server, multi-hop SSH connections, background accept threads, tunnel/client logging, secure secret lookup, and connection diagnostics.

Local port forwarding

Listen on a local port and forward accepted client connections through an SSH server to a configured destination host and port.

Dynamic forwarding

Enable SOCKS-style dynamic port forwarding when each client connection should choose its own destination through the tunnel.

SSH authentication

Authenticate to the SSH server using passwords, public keys, password-plus-key, secure password lookup, or keyboard-interactive authentication.

Proxy and multi-hop access

Reach the SSH server through HTTP or SOCKS proxies, or build tunnels through an existing SSH connection for multi-hop scenarios.

Accept and manage clients

Start accepting client connections in the background, inspect current state, stop accepting new clients, and disconnect active tunnel clients.

Logging and diagnostics

Use accept logs, tunnel logs, current-state XML, and LastErrorText to troubleshoot SSH connection, forwarding, authentication, or client-connection problems.

Common pattern: Configure the SSH server, authentication method, local listen settings, and destination forwarding options, then call BeginAccepting to start the tunnel. Local client applications connect to the tunnel's listen port, and SshTunnel forwards the traffic through SSH. Use Chilkat.SshTunnel for port forwarding; use Chilkat.Ssh for direct SSH sessions, commands, channels, and shell access.

Create/Dispose

HCkSshTunnel instance = CkSshTunnel_Create();
// ...
CkSshTunnel_Dispose(instance);
HCkSshTunnel CkSshTunnel_Create(void);

Creates an instance of the HCkSshTunnel object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkSshTunnel_Dispose(HCkSshTunnel handle);

Objects created by calling CkSshTunnel_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkSshTunnel_Dispose.

Callback Functions

void CkSshTunnel_setAbortCheck(HCkSshTunnel cHandle, BOOL (*fnAbortCheck)(void));

Provides the opportunity for a method call to be aborted. If TRUE is returned, the operation in progress is aborted. Return FALSE to allow the current method call to continue. This callback function is called periodically based on the value of the HeartbeatMs property. (If HeartbeatMs is 0, then no callbacks are made.) As an example, to make 5 AbortCheck callbacks per second, set the HeartbeatMs property equal to 200.

void CkSshTunnel_setPercentDone(HCkSshTunnel cHandle, BOOL (*fnPercentDone)(int pctDone));

Provides the percentage completed for any method that involves network communications or time-consuming processing (assuming it is a method where a percentage completion can be measured). This callback is only called when it is possible to know a percentage completion, and when it makes sense to express the operation as a percentage completed. The pctDone argument will have a value from 1 to 100. For methods that complete very quickly, the number of PercentDone callbacks will vary, but the final callback should have a value of 100. For long running operations, no more than one callback per percentage point will occur (for example: 1, 2, 3, ... 98, 99, 100).

This callback counts as an AbortCheck callback, and takes the place of the AbortCheck event when it fires.

The return value indicates whether the method call should be aborted, or whether it should proceed. Return TRUE to abort, and FALSE to proceed.

void CkSshTunnel_setProgressInfo(HCkSshTunnel cHandle, void (*fnProgressInfo)(const char *name, const char *value));

This is a general callback that provides name/value information about what is happening at certain points during a method call. To see the information provided in ProgressInfo callbacks, if any, write code to handle this event and log the name/value pairs. Most are self-explanatory.

void CkSshTunnel_setTaskCompleted(HCkSshTunnel cHandle, void (*fnTaskCompleted)(HCkTask hTask));

Called in the background thread when an asynchronous task completes. (Note: When an async method is running, all callbacks are in the background thread.)

Properties

AbortCurrent
BOOL CkSshTunnel_getAbortCurrent(HCkSshTunnel cHandle);
void CkSshTunnel_putAbortCurrent(HCkSshTunnel cHandle, BOOL newVal);
Introduced in version 9.5.0.58

Set this property to TRUE from another thread to request that the currently running foreground operation be aborted. For example, it can interrupt a synchronous Connect that is waiting for an SSH server response.

This property does not stop the background listener or terminate established background tunnel clients.

Do not assume the property is automatically reset after an operation is aborted. It may remain TRUE; set it back to FALSE before starting another operation.

More Information and Examples
top
AcceptLog
void CkSshTunnel_getAcceptLog(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putAcceptLog(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_acceptLog(HCkSshTunnel cHandle);

Contains the in-memory activity log for the background listener thread started by BeginAccepting.

The log is populated only when KeepAcceptLog is TRUE.

More Information and Examples
top
AcceptLogPath
void CkSshTunnel_getAcceptLogPath(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putAcceptLogPath(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_acceptLogPath(HCkSshTunnel cHandle);
Introduced in version 9.5.0.50

Specifies the local file path where activity from the background listener thread is written.

This file-based log is separate from the in-memory AcceptLog.

More Information and Examples
top
ClientIdentifier
void CkSshTunnel_getClientIdentifier(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putClientIdentifier(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_clientIdentifier(HCkSshTunnel cHandle);
Introduced in version 9.5.0.95

Specifies the SSH client-identification string sent when connecting to the SSH server.

Starting in Chilkat v9.5.0.99, the default is SSH-2.0-Chilkat_ followed by the Chilkat version number, such as SSH-2.0-Chilkat_9.5.0.99.

The identifier should begin with SSH-2.0-. Some SSH servers disconnect clients that send an invalid identification string.

top
ClientLogDir
void CkSshTunnel_getClientLogDir(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putClientLogDir(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_clientLogDir(HCkSshTunnel cHandle);
Introduced in version 11.1.0

Specifies the local directory where a separate log file is created for each tunnel client.

When this property is not empty, files are named using the pattern tunnel_client_log_{random_id}.txt.

top
ConnectTimeoutMs
int CkSshTunnel_getConnectTimeoutMs(HCkSshTunnel cHandle);
void CkSshTunnel_putConnectTimeoutMs(HCkSshTunnel cHandle, int newVal);

Specifies the maximum number of milliseconds allowed for establishing the SSH connection.

  • The default value is 30000 milliseconds (30 seconds).
  • A value of 0 disables the connection timeout and allows an unlimited wait.

The timeout applies to more than the initial TCP connection. It also covers connection setup performed through an HTTP or SOCKS proxy and waiting for the SSH server identification string after the TCP connection has been established.

More Information and Examples
top
DebugLogFilePath
void CkSshTunnel_getDebugLogFilePath(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putDebugLogFilePath(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_debugLogFilePath(HCkSshTunnel cHandle);

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
DestHostname
void CkSshTunnel_getDestHostname(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putDestHostname(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_destHostname(HCkSshTunnel cHandle);

Specifies the destination hostname or IP address for fixed-destination port forwarding. This is typically the host running the database server or other TCP service that local clients need to reach.

The destination is interpreted from the SSH server's network environment. For example, localhost and 127.0.0.1 refer to the SSH server itself, not the computer running the application. Hostname resolution is therefore performed as part of the forwarding request on the SSH-server side.

Traffic accepted by the local listener is carried through SSH, forwarded by the SSH server to this destination, and returned through the same tunnel.

This property is ignored when DynamicPortForwarding is TRUE. Changing the destination while the listener is running affects new clients only; existing clients remain connected to the destination selected when they were accepted.

top
DestPort
int CkSshTunnel_getDestPort(HCkSshTunnel cHandle);
void CkSshTunnel_putDestPort(HCkSshTunnel cHandle, int newVal);

Specifies the TCP port of the destination service used for fixed-destination forwarding, such as the port of a database server.

It is used together with DestHostname and is ignored when DynamicPortForwarding is TRUE.

top
DynamicPortForwarding
BOOL CkSshTunnel_getDynamicPortForwarding(HCkSshTunnel cHandle);
void CkSshTunnel_putDynamicPortForwarding(HCkSshTunnel cHandle, BOOL newVal);
Introduced in version 9.5.0.50

Controls whether the listener performs fixed-destination or dynamic port forwarding.

  • When FALSE (the default), every accepted connection is forwarded to DestHostname and DestPort.
  • When TRUE, the listener acts as a SOCKS proxy and each inbound client supplies its own destination.

The SOCKS version is detected independently from each inbound client handshake; there is no separate inbound SOCKS-version property. SOCKS4 and SOCKS5 CONNECT requests are supported. SOCKS5 BIND and UDP association are not supported.

Leave InboundSocksUsername empty to allow SOCKS5 clients to use the no-authentication method. Set the inbound username and password to require SOCKS5 username/password authentication. For SOCKS4, only the user ID can be checked because SOCKS4 has no password field.

SOCKS4a hostname-form requests are not supported. Use a numeric IPv4 address with SOCKS4, or use SOCKS5 when the client needs to supply a domain name.

top
EnableSecrets
BOOL CkSshTunnel_getEnableSecrets(HCkSshTunnel cHandle);
void CkSshTunnel_putEnableSecrets(HCkSshTunnel cHandle, BOOL newVal);
Introduced in version 11.5.0

Enables automatic resolution of credentials from secure storage provided by the operating system.

When set to TRUE, supported password properties and methods may receive a secret specification string beginning with !! instead of a literal password. Chilkat resolves the secret from:

  • Windows Credential Manager on Windows.
  • Apple Keychain on macOS.

The specification format is: !![appName|]service[|domain]|username

This applies to HttpProxyPassword, SocksPassword, AuthenticatePw, and AuthenticatePwPk.

The default value is FALSE.

top
HostKeyFingerprint
void CkSshTunnel_getHostKeyFingerprint(HCkSshTunnel cHandle, HCkString retval);
const char *CkSshTunnel_hostKeyFingerprint(HCkSshTunnel cHandle);
Introduced in version 9.5.0.56

Contains the SSH server host-key fingerprint after Connect or ConnectThroughSsh establishes the SSH connection. The value is available before user authentication.

Example: ssh-ed25519 256 e0:33:b1:81:a5:c6:9a:d2:2e:c9:d3:15:60:ea:cf:4c

Compare this value with a trusted expected fingerprint to verify the identity of the SSH server. For ConnectThroughSsh, the fingerprint is for the final SSH server, not the first-hop server.

The value may remain populated after CloseTunnel or after the connection is lost. Use IsSshConnected to determine current connection state.

More Information and Examples
top
HttpProxyAuthMethod
void CkSshTunnel_getHttpProxyAuthMethod(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putHttpProxyAuthMethod(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_httpProxyAuthMethod(HCkSshTunnel cHandle);

Specifies the authentication method to use when the outbound connection to the SSH server passes through an HTTP proxy that requires authentication.

Valid values are Basic and NTLM.

If SocksVersion is set to 4 or 5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.

More Information and Examples
top
HttpProxyDomain
void CkSshTunnel_getHttpProxyDomain(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putHttpProxyDomain(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_httpProxyDomain(HCkSshTunnel cHandle);

Specifies the optional Windows domain used for NTLM authentication with the HTTP proxy.

This applies only to the outbound proxy connection used to reach the SSH server, and only when HttpProxyAuthMethod is NTLM.

If SocksVersion is set to 4 or 5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.

More Information and Examples
top
HttpProxyHostname
void CkSshTunnel_getHttpProxyHostname(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putHttpProxyHostname(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_httpProxyHostname(HCkSshTunnel cHandle);

Specifies the hostname or IPv4 address of the HTTP proxy through which the outbound connection to the SSH server is made.

Leave this property empty when no HTTP proxy is required.

If SocksVersion is set to 4 or 5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.

More Information and Examples
top
HttpProxyPassword
void CkSshTunnel_getHttpProxyPassword(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putHttpProxyPassword(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_httpProxyPassword(HCkSshTunnel cHandle);

Specifies the password used to authenticate with the HTTP proxy for the outbound connection to the SSH server.

If SocksVersion is set to 4 or 5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.

More Information and Examples
top
HttpProxyPort
int CkSshTunnel_getHttpProxyPort(HCkSshTunnel cHandle);
void CkSshTunnel_putHttpProxyPort(HCkSshTunnel cHandle, int newVal);

Specifies the TCP port of the HTTP proxy used for the outbound connection to the SSH server.

Common HTTP proxy ports include 8080 and 3128.

If SocksVersion is set to 4 or 5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.

More Information and Examples
top
HttpProxyUsername
void CkSshTunnel_getHttpProxyUsername(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putHttpProxyUsername(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_httpProxyUsername(HCkSshTunnel cHandle);

Specifies the username used to authenticate with the HTTP proxy for the outbound connection to the SSH server.

If SocksVersion is set to 4 or 5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.

More Information and Examples
top
IdleTimeoutMs
int CkSshTunnel_getIdleTimeoutMs(HCkSshTunnel cHandle);
void CkSshTunnel_putIdleTimeoutMs(HCkSshTunnel cHandle, int newVal);

Specifies a stall timeout, in milliseconds, for tunnel data-transfer operations. The default value is 30000 milliseconds (30 seconds). A value of 0 disables the timeout.

This property is not a general inactivity timer for established background tunnel clients. An otherwise idle client, or a client with data queued while an SSH channel is flow-controlled, may remain connected beyond this interval. Applications should not rely on this property to disconnect clients merely because no application data is flowing.

More Information and Examples
top
InboundSocksPassword
void CkSshTunnel_getInboundSocksPassword(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putInboundSocksPassword(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_inboundSocksPassword(HCkSshTunnel cHandle);
Introduced in version 9.5.0.50

Specifies the password required from inbound SOCKS5 clients when DynamicPortForwarding is TRUE.

This property is used together with InboundSocksUsername. It does not apply to SOCKS4 because the SOCKS4 protocol has no password field.

top
InboundSocksUsername
void CkSshTunnel_getInboundSocksUsername(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putInboundSocksUsername(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_inboundSocksUsername(HCkSshTunnel cHandle);
Introduced in version 9.5.0.50

Specifies the username required from inbound SOCKS clients when DynamicPortForwarding is TRUE.

  • For SOCKS5, setting this property enables username/password authentication.
  • For SOCKS4, the value is compared with the client-supplied user ID.
  • Leave it empty to require no inbound SOCKS username.

top
IsAccepting
BOOL CkSshTunnel_getIsAccepting(HCkSshTunnel cHandle);

TRUE when the local listener thread is running and accepting inbound TCP connections; otherwise FALSE.

This property describes only the local listener. It can remain TRUE after the SSH connection is lost or after CloseTunnel is called. In those states a client may connect to the local port even though its traffic cannot be forwarded.

Use IsSshConnected separately when the application also needs to know whether the SSH transport is available.

More Information and Examples
top
KeepAcceptLog
BOOL CkSshTunnel_getKeepAcceptLog(HCkSshTunnel cHandle);
void CkSshTunnel_putKeepAcceptLog(HCkSshTunnel cHandle, BOOL newVal);

Controls whether activity from the background listener thread is retained in memory.

The default value is FALSE. When enabled, retrieve the log from AcceptLog.

More Information and Examples
top
KeepTunnelLog
BOOL CkSshTunnel_getKeepTunnelLog(HCkSshTunnel cHandle);
void CkSshTunnel_putKeepTunnelLog(HCkSshTunnel cHandle, BOOL newVal);
Introduced in version 9.5.0.50

Controls whether SSH tunnel-thread activity is retained in memory.

The default value is FALSE. When enabled, retrieve the log from TunnelLog.

More Information and Examples
top
LastErrorHtml
void CkSshTunnel_getLastErrorHtml(HCkSshTunnel cHandle, HCkString retval);
const char *CkSshTunnel_lastErrorHtml(HCkSshTunnel cHandle);

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
void CkSshTunnel_getLastErrorText(HCkSshTunnel cHandle, HCkString retval);
const char *CkSshTunnel_lastErrorText(HCkSshTunnel cHandle);

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
void CkSshTunnel_getLastErrorXml(HCkSshTunnel cHandle, HCkString retval);
const char *CkSshTunnel_lastErrorXml(HCkSshTunnel cHandle);

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
BOOL CkSshTunnel_getLastMethodSuccess(HCkSshTunnel cHandle);
void CkSshTunnel_putLastMethodSuccess(HCkSshTunnel cHandle, BOOL newVal);

Indicates the success or failure of the most recent method call: TRUE means success, FALSE means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
ListenBindIpAddress
void CkSshTunnel_getListenBindIpAddress(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putListenBindIpAddress(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_listenBindIpAddress(HCkSshTunnel cHandle);

Specifies the local IPv4 address to which the tunnel's listening socket is bound.

Value Listener exposure
Empty string Binds to 0.0.0.0 and accepts connections on all local IPv4 interfaces, subject to firewall rules.
127.0.0.1 Accepts connections only from the local computer through loopback.
A specific local LAN address Accepts connections through that interface only; loopback is not included automatically.
For a tunnel intended only for local applications, explicitly set this property to 127.0.0.1. Leaving it empty may expose the listening port to other computers on the network.

If the value is malformed or is not assigned to a local interface, BeginAccepting returns FALSE and the bind failure is available in LastErrorText and the accept log.

top
ListenPort
int CkSshTunnel_getListenPort(HCkSshTunnel cHandle);

Contains the local TCP port used by the listener started by BeginAccepting.

  • If BeginAccepting succeeds with a nonzero requested port, this property contains that port.
  • If BeginAccepting succeeds with 0, the operating system chooses an available port and this property contains the allocated port when the method returns.
  • After a bind failure for an explicitly requested port, this property may still contain the requested port even though IsAccepting is FALSE.
  • The value is initially 0.

top
OutboundBindIpAddress
void CkSshTunnel_getOutboundBindIpAddress(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putOutboundBindIpAddress(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_outboundBindIpAddress(HCkSshTunnel cHandle);

Specifies the local IP address to which the outbound socket is bound before connecting to the SSH server.

Most applications should leave this property empty. Set it only on a multihomed computer when the SSH connection must originate from a specific local network interface or IP address.

More Information and Examples
top
OutboundBindPort
int CkSshTunnel_getOutboundBindPort(HCkSshTunnel cHandle);
void CkSshTunnel_putOutboundBindPort(HCkSshTunnel cHandle, int newVal);

Specifies the local TCP port to bind before making the outbound connection to the SSH server.

The default value is 0, which allows the operating system to choose an available ephemeral port. Nearly all applications should leave this property unchanged.

More Information and Examples
top
PreferIpv6
BOOL CkSshTunnel_getPreferIpv6(HCkSshTunnel cHandle);
void CkSshTunnel_putPreferIpv6(HCkSshTunnel cHandle, BOOL newVal);
Introduced in version 9.5.0.70

Controls which IP version is preferred when a hostname resolves to both IPv4 and IPv6 addresses.

  • FALSE (the default) prefers IPv4.
  • TRUE prefers IPv6.

More Information and Examples
top
SocksHostname
void CkSshTunnel_getSocksHostname(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putSocksHostname(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_socksHostname(HCkSshTunnel cHandle);

Specifies the hostname or IPv4 address of the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.

This property is used only when SocksVersion is 4 or 5.

More Information and Examples
top
SocksPassword
void CkSshTunnel_getSocksPassword(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putSocksPassword(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_socksPassword(HCkSshTunnel cHandle);

Specifies the password for authenticating with an outbound SOCKS5 proxy used to reach the SSH server.

SOCKS4 does not support password authentication, so this property does not apply when SocksVersion is 4.

More Information and Examples
top
SocksPort
int CkSshTunnel_getSocksPort(HCkSshTunnel cHandle);
void CkSshTunnel_putSocksPort(HCkSshTunnel cHandle, int newVal);

Specifies the TCP port of the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.

The default value is 1080. This property is used only when SocksVersion is 4 or 5.

More Information and Examples
top
SocksUsername
void CkSshTunnel_getSocksUsername(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putSocksUsername(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_socksUsername(HCkSshTunnel cHandle);

Specifies the username for the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.

This property is used only when SocksVersion is 4 or 5.

More Information and Examples
top
SocksVersion
int CkSshTunnel_getSocksVersion(HCkSshTunnel cHandle);
void CkSshTunnel_putSocksVersion(HCkSshTunnel cHandle, int newVal);

Selects whether the outbound connection to the SSH server is made through a SOCKS proxy.

Value Behavior
0 Do not use a SOCKS proxy. This is the default.
4 Connect through a SOCKS4 proxy.
5 Connect through a SOCKS5 proxy.

When this property is 4 or 5, the SOCKS proxy settings take precedence over the HTTP proxy settings. The SOCKS and HTTP proxies are not chained.

More Information and Examples
top
SoRcvBuf
int CkSshTunnel_getSoRcvBuf(HCkSshTunnel cHandle);
void CkSshTunnel_putSoRcvBuf(HCkSshTunnel cHandle, int newVal);

Sets the receive-buffer size for the underlying TCP socket.

The default value is 4194304 bytes. Normally this property should remain unchanged. If receive performance is unusually slow, testing a larger value that is a multiple of 4096 may help.

top
SoSndBuf
int CkSshTunnel_getSoSndBuf(HCkSshTunnel cHandle);
void CkSshTunnel_putSoSndBuf(HCkSshTunnel cHandle, int newVal);

Sets the send-buffer size for the underlying TCP socket.

The default value is 262144 bytes. Normally this property should remain unchanged. If send performance is unusually slow, testing values such as 524288 or 1048576 may help. A multiple of 4096 is recommended.

top
TcpNoDelay
BOOL CkSshTunnel_getTcpNoDelay(HCkSshTunnel cHandle);
void CkSshTunnel_putTcpNoDelay(HCkSshTunnel cHandle, BOOL newVal);

Controls the TCP_NODELAY socket option for the underlying TCP connection.

The default value is FALSE. Setting it to TRUE disables the Nagle algorithm, which can reduce latency when many small amounts of data are sent.

More Information and Examples
top
TunnelLog
void CkSshTunnel_getTunnelLog(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putTunnelLog(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_tunnelLog(HCkSshTunnel cHandle);
Introduced in version 9.5.0.50

Contains the in-memory activity log for the SSH tunnel and client-manager threads. The log is populated only when KeepTunnelLog is TRUE.

Treat this log as sensitive diagnostic data. It can contain hostnames, ports, usernames, proxy details, SOCKS handshake information, and authentication failure values. Do not publish or persist it without reviewing and protecting its contents.

More Information and Examples
top
TunnelLogPath
void CkSshTunnel_getTunnelLogPath(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putTunnelLogPath(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_tunnelLogPath(HCkSshTunnel cHandle);
Introduced in version 9.5.0.50

Specifies the local file path where SSH tunnel-thread activity is written.

This file-based log is separate from the in-memory TunnelLog.

More Information and Examples
top
UncommonOptions
void CkSshTunnel_getUncommonOptions(HCkSshTunnel cHandle, HCkString retval);
void CkSshTunnel_putUncommonOptions(HCkSshTunnel cHandle, const char *newVal);
const char *CkSshTunnel_uncommonOptions(HCkSshTunnel cHandle);
Introduced in version 9.5.0.73

Provides optional behavior for uncommon requirements. The default value is an empty string, which is appropriate for most applications.

To enable more than one option, provide a comma-separated list of keywords.

Keyword Effect
ForceUserAuthRsaSha1 Forces rsa-sha1 for public-key user authentication. Set this before connecting. Added in v9.5.0.98.
NoKeepAliveIgnoreMsg Disables the default SSH ignore message sent every 20 seconds to keep an idle connection alive. Added in v9.5.0.76.
no-weak-mac-algs Removes hmac-sha1-96, hmac-sha1, hmac-md5, and hmac-ripemd160 from the offered MAC algorithms. Added in v9.5.0.98.
ProtectFromVpn On Android, bypasses an installed or active VPN. Added in v9.5.0.80.
+ssh-hmac-etm Re-enables SSH encrypt-then-MAC algorithms that were disabled by default in v9.5.0.97 as part of the Terrapin mitigation.
+chacha20-poly1305@openssh.com Re-enables chacha20-poly1305@openssh.com, which was removed from the default offer in v9.5.0.97 as part of the Terrapin mitigation.

More Information and Examples
top
Utf8
BOOL CkSshTunnel_getUtf8(HCkSshTunnel cHandle);
void CkSshTunnel_putUtf8(HCkSshTunnel cHandle, BOOL newVal);

When set to TRUE, all const char * arguments and return values are interpreted as UTF-8 strings. When set to FALSE, they are interpreted as ANSI strings.

In Chilkat v11.0.0 and later, the default value is TRUE. Before v11.0.0, it was FALSE.

top
VerboseLogging
BOOL CkSshTunnel_getVerboseLogging(HCkSshTunnel cHandle);
void CkSshTunnel_putVerboseLogging(HCkSshTunnel cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
void CkSshTunnel_getVersion(HCkSshTunnel cHandle, HCkString retval);
const char *CkSshTunnel_version(HCkSshTunnel cHandle);

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

AuthenticatePk
BOOL CkSshTunnel_AuthenticatePk(HCkSshTunnel cHandle, const char *username, HCkSshKey privateKey);
Introduced in version 9.5.0.50

Authenticates with the SSH server using public-key authentication.

The public key corresponding to privateKey must already be installed for username on the SSH server.

Call Connect or ConnectThroughSsh before calling this method.

When requesting support for an authentication failure, include the complete LastErrorText.

Returns TRUE for success, FALSE for failure.

top
AuthenticatePkAsync (1)
HCkTask CkSshTunnel_AuthenticatePkAsync(HCkSshTunnel cHandle, const char *username, HCkSshKey privateKey);
Introduced in version 9.5.0.50

Creates an asynchronous task to call the AuthenticatePk method with the arguments provided.

Returns NULL on failure

top
AuthenticatePw
BOOL CkSshTunnel_AuthenticatePw(HCkSshTunnel cHandle, const char *login, const char *password);
Introduced in version 9.5.0.50

Authenticates with the SSH server using login and password.

Establish the SSH connection first by calling Connect or ConnectThroughSsh. After authentication succeeds, call BeginAccepting to begin accepting tunnel clients.

  • A rejected username or password does not close the SSH connection; the application may correct the credentials and call this method again.
  • Calling this method again after authentication has already succeeded returns FALSE with an “Already authenticated” error.
When requesting support for an authentication failure, include the complete LastErrorText captured immediately after the failed call.

Returns TRUE for success, FALSE for failure.

top
AuthenticatePwAsync (1)
HCkTask CkSshTunnel_AuthenticatePwAsync(HCkSshTunnel cHandle, const char *login, const char *password);
Introduced in version 9.5.0.50

Creates an asynchronous task to call the AuthenticatePw method with the arguments provided.

Returns NULL on failure

top
AuthenticatePwPk
BOOL CkSshTunnel_AuthenticatePwPk(HCkSshTunnel cHandle, const char *username, const char *password, HCkSshKey privateKey);
Introduced in version 9.5.0.50

Authenticates with an SSH server that requires both a password and a private key.

The public key corresponding to privateKey must already be installed for username on the SSH server. Most SSH servers require either password authentication or public-key authentication rather than both.

When requesting support for an authentication failure, include the complete LastErrorText.

Returns TRUE for success, FALSE for failure.

top
AuthenticatePwPkAsync (1)
HCkTask CkSshTunnel_AuthenticatePwPkAsync(HCkSshTunnel cHandle, const char *username, const char *password, HCkSshKey privateKey);
Introduced in version 9.5.0.50

Creates an asynchronous task to call the AuthenticatePwPk method with the arguments provided.

Returns NULL on failure

top
AuthenticateSecPw
BOOL CkSshTunnel_AuthenticateSecPw(HCkSshTunnel cHandle, HCkSecureString login, HCkSecureString password);
Introduced in version 9.5.0.71

Performs the same password authentication as AuthenticatePw, but receives the login and password in SecureString objects.

Returns TRUE for success, FALSE for failure.

top
AuthenticateSecPwAsync (1)
HCkTask CkSshTunnel_AuthenticateSecPwAsync(HCkSshTunnel cHandle, HCkSecureString login, HCkSecureString password);
Introduced in version 9.5.0.71

Creates an asynchronous task to call the AuthenticateSecPw method with the arguments provided.

Returns NULL on failure

top
AuthenticateSecPwPk
BOOL CkSshTunnel_AuthenticateSecPwPk(HCkSshTunnel cHandle, HCkSecureString username, HCkSecureString password, HCkSshKey privateKey);
Introduced in version 9.5.0.71

Performs the same combined password-and-private-key authentication as AuthenticatePwPk, but receives the username and password in SecureString objects.

Returns TRUE for success, FALSE for failure.

top
AuthenticateSecPwPkAsync (1)
HCkTask CkSshTunnel_AuthenticateSecPwPkAsync(HCkSshTunnel cHandle, HCkSecureString username, HCkSecureString password, HCkSshKey privateKey);
Introduced in version 9.5.0.71

Creates an asynchronous task to call the AuthenticateSecPwPk method with the arguments provided.

Returns NULL on failure

top
BeginAccepting
BOOL CkSshTunnel_BeginAccepting(HCkSshTunnel cHandle, int listenPort);

Creates and starts the local listener on listenPort.

The SSH connection must already have been established. Although the listener can be started before user authentication, clients accepted in that state cannot be forwarded. The recommended sequence is to connect, authenticate, and then call this method.

  • The requested port must not already be in use on the selected local interface.
  • Pass 0 to let the operating system choose an available port, then read ListenPort.
  • Calling this method while the listener is already running returns FALSE.

The method waits for the initial bind-and-listen result. It returns FALSE for errors such as an occupied port, a malformed bind address, or an address that is not assigned to the local computer. Details are available immediately in LastErrorText and, when enabled, the accept log.

A successful return means the listener was bound and started. No additional fixed delay is required merely to discover an initial bind failure.

Returns TRUE for success, FALSE for failure.

top
BeginAcceptingAsync (1)
HCkTask CkSshTunnel_BeginAcceptingAsync(HCkSshTunnel cHandle, int listenPort);

Creates an asynchronous task to call the BeginAccepting method with the arguments provided.

Returns NULL on failure

top
CloseTunnel
BOOL CkSshTunnel_CloseTunnel(HCkSshTunnel cHandle, BOOL waitForThreads);
Introduced in version 9.5.0.50

Disconnects active tunnel clients and stops the tunnel-manager thread.

When waitForThreads is TRUE, the method waits for the client and tunnel-manager threads to exit. It returns FALSE if a worker thread does not stop; capture LastErrorText immediately for details.

This method does not stop the local listener and does not disconnect or reset the underlying SSH transport. Call StopAccepting separately to stop accepting local TCP connections. After this method returns, the listener may still accept a local connection even though the connection cannot be forwarded.

Calling this method more than once is allowed. However, it does not reset the object for a new call to Connect. Use a new SshTunnel object when connecting to a different SSH server.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
Connect
BOOL CkSshTunnel_Connect(HCkSshTunnel cHandle, const char *hostname, int port);
Introduced in version 9.5.0.50

Establishes the SSH connection that will carry tunneled traffic. This method performs the TCP or proxy connection, the SSH protocol handshake, and host-key negotiation, but it does not authenticate the SSH user.

After connecting, verify HostKeyFingerprint, then authenticate by calling one of the Authenticate* methods. Finally, call BeginAccepting to start the local listener.

The host-key fingerprint is available immediately after this method succeeds, before user authentication. Calling Connect again while an SSH tunnel already exists returns FALSE.

Chilkat sends an SSH ignore message every 20 seconds to help keep an unused SSH connection alive. To disable this behavior, add NoKeepAliveIgnoreMsg to UncommonOptions before connecting.

Returns TRUE for success, FALSE for failure.

top
ConnectAsync (1)
HCkTask CkSshTunnel_ConnectAsync(HCkSshTunnel cHandle, const char *hostname, int port);
Introduced in version 9.5.0.50

Creates an asynchronous task to call the Connect method with the arguments provided.

Returns NULL on failure

top
ConnectThroughSsh
BOOL CkSshTunnel_ConnectThroughSsh(HCkSshTunnel cHandle, HCkSsh ssh, const char *hostname, int port);
Introduced in version 9.5.0.55

Connects to a second SSH server through the existing connected and authenticated Ssh object supplied in ssh.

application -> first SSH server -> second SSH server

hostname and port identify the second SSH server. After this method succeeds, call an authentication method on this SshTunnel object to authenticate with the second server.

The supplied Ssh object is borrowed, not copied. It must remain alive, connected, and authenticated for as long as this tunnel is used. If the first-hop object is disconnected, existing forwarded clients stop working and new local connections cannot be forwarded. The local listener may nevertheless remain active until explicitly stopped.

HostKeyFingerprint reports the fingerprint of the second SSH server. After the connection is established, fixed forwarding destinations such as 127.0.0.1 are interpreted from the second server's network environment.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
ConnectThroughSshAsync (1)
HCkTask CkSshTunnel_ConnectThroughSshAsync(HCkSshTunnel cHandle, HCkSsh ssh, const char *hostname, int port);
Introduced in version 9.5.0.55

Creates an asynchronous task to call the ConnectThroughSsh method with the arguments provided.

Returns NULL on failure

top
ContinueKeyboardAuth
BOOL CkSshTunnel_ContinueKeyboardAuth(HCkSshTunnel cHandle, const char *response, HCkString outStr);
const char *CkSshTunnel_continueKeyboardAuth(HCkSshTunnel cHandle, const char *response);
Introduced in version 9.5.0.78

Continues a keyboard-interactive authentication exchange started by StartKeyboardAuth.

If the server requested one response, pass that value directly in response. If it requested multiple responses, pass XML in the following form:

<response>
  <response1>response to first prompt</response1>
  <response2>response to second prompt</response2>
  ...
  <responseN>response to Nth prompt</responseN>
</response>

When authentication completes, the returned XML indicates success or failure:

<success>success message</success>

<error>error message</error>

If another challenge is required, the method returns another infoRequest XML document containing the next set of prompts.

Returns TRUE for success, FALSE for failure.

top
ContinueKeyboardAuthAsync (1)
HCkTask CkSshTunnel_ContinueKeyboardAuthAsync(HCkSshTunnel cHandle, const char *response);
Introduced in version 9.5.0.78

Creates an asynchronous task to call the ContinueKeyboardAuth method with the arguments provided.

Returns NULL on failure

top
DisconnectAllClients
BOOL CkSshTunnel_DisconnectAllClients(HCkSshTunnel cHandle, BOOL waitForThreads);
Introduced in version 9.5.0.50

Disconnects all active tunnel clients while leaving the local listener and SSH connection available.

When waitForThreads is TRUE, the method waits for the current client threads to exit before returning. The listener continues accepting new clients, and newly accepted clients can be forwarded normally.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
GetCurrentState
BOOL CkSshTunnel_GetCurrentState(HCkSshTunnel cHandle, HCkString outStr);
const char *CkSshTunnel_getCurrentState(HCkSshTunnel cHandle);
Introduced in version 9.5.0.65

Returns an XML snapshot describing the tunnel manager, SSH channels, and current tunnel clients. The returned data is intended for diagnostics and monitoring.

A typical result has the following structure:

<CurrentState>
  <tunnelManager rcvByteCount="433" sndByteCount="34"
      threadRunning="1" dynamicPortForwarding="0"
      staticDestHost="localhost" staticDestPort="18080">
    <openChannels count="1">
      <channel num="101" channelType="direct-tcpip"
          clientWinSize="2096927" serverWinSize="2097127" />
    </openChannels>
    <closedChannels count="0" />
  </tunnelManager>
  <clients count="1">
    <client destIp="localhost" destPort="18080"
        sshChannelNum="101" threadRunning="1"
        rcvByteCount="25" sndByteCount="225" />
  </clients>
</CurrentState>

The exact child elements can vary with state. For example, channel collections may be empty, and some transport details may be omitted before the tunnel is started or after it stops.

Section Information
tunnelManager Aggregate byte counts, worker-thread state, forwarding mode, and configured fixed destination.
openChannels and closedChannels SSH channel numbers, close/EOF flags, packet sizes, and flow-control window sizes.
clients Per-client destination, SSH channel number, worker state, age/activity counters, pending-data flags, and byte counts.

Returns TRUE for success, FALSE for failure.

top
IsSshConnected
BOOL CkSshTunnel_IsSshConnected(HCkSshTunnel cHandle);
Introduced in version 9.5.0.61

Returns TRUE when the SSH transport used by this tunnel is connected; otherwise returns FALSE.

This is independent of the local listener state. The listener may still be accepting local TCP connections when this method returns FALSE, but those connections cannot be forwarded until a usable SSH transport exists.

For a tunnel created with ConnectThroughSsh, this method becomes FALSE when the borrowed first-hop Ssh connection is disconnected.

top
LoadTaskCaller
BOOL CkSshTunnel_LoadTaskCaller(HCkSshTunnel cHandle, HCkTask task);
Introduced in version 9.5.0.80

Loads this object with the SshTunnel instance that initiated the asynchronous operation represented by task.

Returns TRUE for success, FALSE for failure.

top
SetAllowedAlgorithms
BOOL CkSshTunnel_SetAllowedAlgorithms(HCkSshTunnel cHandle, HCkJsonObject json);
Introduced in version 9.5.0.99

Restricts the SSH connection to the algorithms specified in json.

This allows an application to define the exact algorithm set that may be used during SSH negotiation.

Returns TRUE for success, FALSE for failure.

top
StartKeyboardAuth
BOOL CkSshTunnel_StartKeyboardAuth(HCkSshTunnel cHandle, const char *login, HCkString outStr);
const char *CkSshTunnel_startKeyboardAuth(HCkSshTunnel cHandle, const char *login);
Introduced in version 9.5.0.78

Begins keyboard-interactive authentication for login.

When the server requests one or more responses, the returned XML contains the request name, instructions, and prompts:

<infoRequest numPrompts="N">
  <name>name text</name>
  <instruction>instruction text</instruction>
  <prompt1 echo="1_or_0">prompt text</prompt1>
  ...
  <promptN echo="1_or_0">prompt text</promptN>
</infoRequest>

The echo attribute indicates whether the response should be displayed while entered.

If authentication immediately succeeds or fails without requiring a response, the returned XML has one of these forms:

<success>success message</success>

<error>error message</error>

Pass the requested response or responses to ContinueKeyboardAuth.

Returns TRUE for success, FALSE for failure.

top
StartKeyboardAuthAsync (1)
HCkTask CkSshTunnel_StartKeyboardAuthAsync(HCkSshTunnel cHandle, const char *login);
Introduced in version 9.5.0.78

Creates an asynchronous task to call the StartKeyboardAuth method with the arguments provided.

Returns NULL on failure

top
StopAccepting
BOOL CkSshTunnel_StopAccepting(HCkSshTunnel cHandle, BOOL waitForThread);

Stops the local listener so that no new client connections are accepted. Existing forwarded clients remain connected and continue exchanging data.

  • When waitForThread is TRUE, the method waits for the listener thread to exit before returning.
  • When it is FALSE, shutdown is asynchronous and IsAccepting may remain TRUE briefly after the method returns.

Call BeginAccepting again to resume accepting connections. The listener can be restarted on the same port after the previous listener has stopped.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top