TrustCore SDK NanoSSH API reference  version 7.0
Core (Async and Sync) Client Functions

Functions

MOC_EXTERN void SSHC_close (sbyte4 connectionInstance)
 Close an SSH session and releases all its resources. More...
 
MOC_EXTERN sbyte4 SSHC_connect (TCP_SOCKET tempSocket, sbyte4 *pConnectionInstance, sbyte *pCommonName, struct certStore *pCertStore)
 Create a secure SSH connection with a remote server. More...
 
MOC_EXTERN sbyte4 SSHC_getCookie (sbyte4 connectionInstance, void **pRetCookie)
 Get a connection's cookie containing custom (application-specific) information. More...
 
MOC_EXTERN sbyte4 SSHC_init (sbyte4 numClientConnections)
 Initialize NanoSSH client internal structures. More...
 
MOC_EXTERN sbyte4 SSHC_initiateReKey (sbyte4 connectionInstance, ubyte4 msAllowToComply)
 Initiate an SSH re-key operation. More...
 
MOC_EXTERN sbyte4 SSHC_negotiateCloseChannel (sbyte4 connectionInstance, sbyte4 channelNumber)
 Negotiate closing of a channel. More...
 
MOC_EXTERN sbyte4 SSHC_negotiateConnection (sbyte4 connectionInstance)
 Authenticate a server (which establishes a secure connection). More...
 
MOC_EXTERN sbyte4 SSHC_negotiateSession (sbyte4 connectionInstance)
 Negotiate a connection (the client is authenticated by the server). More...
 
MOC_EXTERN sbyte4 SSHC_negotiateSFTPHello (sbyte4 connectionInstance)
 Start a NanoSSH client SFTP session. More...
 
MOC_EXTERN sbyte4 SSHC_negotiateSubsystemSFTPChannelRequest (sbyte4 connectionInstance)
 Send an SSH exec sftp command on the specified connection. More...
 
MOC_EXTERN sbyte4 SSHC_numBytesTransmitted (sbyte4 connectionInstance, ubyte8 *pRetNumBytes)
 Get the number of bytes sent and received through a given connectionInstance. More...
 
MOC_EXTERN sbyte4 SSHC_setCookie (sbyte4 connectionInstance, void *cookie)
 Save a cookie containing custom information. More...
 
MOC_EXTERN sbyte4 SSHC_shutdown (void)
 Release memory initialized by SSHC_init(). More...
 
MOC_EXTERN sshClientSettingsSSHC_sshClientSettings (void)
 Get a pointer to the session's NanoSSH Client settings. More...
 
MOC_EXTERN sbyte4 SSHC_useThisCipher (sbyte4 connectionInstance, ubyte *pCipher)
 Set an SSH connection's cipher. More...
 
MOC_EXTERN sbyte4 SSHC_useThisHmac (sbyte4 connectionInstance, ubyte *pHmac)
 Set an SSH connection's HMAC. More...
 

Detailed Description

Function Documentation

◆ SSHC_close()

MOC_EXTERN void SSHC_close ( sbyte4  connectionInstance)

This function closes an SSH session and releases all resources that are managed by the NanoSSH client.

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_connect()

MOC_EXTERN sbyte4 SSHC_connect ( TCP_SOCKET  tempSocket,
sbyte4 *  pConnectionInstance,
sbyte *  pCommonName,
struct certStore *  pCertStore 
)

This function creates a connection context for a secure SSH connection with a remote server.

Since
1.41
Version
3.2 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
tempSocketSocket returned by OS-specific TCP connection call.
pConnectionInstanceOn return, pointer to new connection context.
pCommonNameExpected common name of target server's certificate.
pCertStorePointer to SoT Platform certificate store that contains the SSH connection's certificate (as a trust point or identify).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_getCookie()

MOC_EXTERN sbyte4 SSHC_getCookie ( sbyte4  connectionInstance,
void **  pRetCookie 
)

This function retrieves custom (application-specific) information stored in the connection instance's context. Your application should not call this function until after it calls SSHC_setCookie().

Since
1.41
Version
1.41 and later

(pRetCookie changed type)

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
pRetCookieOn return, pointer to cookie containing custom information.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_init()

MOC_EXTERN sbyte4 SSHC_init ( sbyte4  numClientConnections)

This function initializes NanoSSH client internal structures.

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
numClientConnectionsMaximum number of NanoSSH client connections to allow.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_initiateReKey()

MOC_EXTERN sbyte4 SSHC_initiateReKey ( sbyte4  connectionInstance,
ubyte4  msAllowToComply 
)

This function initiates an SSH re-key operation. NanoSSH automatically processes re-key requests from an SSH client.

Since
4.2
Version
4.2 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__
Parameters
connectionInstanceConnection instance returned from SSHC_connect().
msAllowToComplyNumber of milliseconds to wait for an SSH client to respond before closing the session. Zero (0) indicates that the request is not being strictly enforced.

sshc.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous and asynchronous clients.
Many SSH implementations do not support re-keying.

sshc.h

◆ SSHC_negotiateCloseChannel()

MOC_EXTERN sbyte4 SSHC_negotiateCloseChannel ( sbyte4  connectionInstance,
sbyte4  channelNumber 
)

This function negotiates the closing of the channel associated with channelNumber.

Since
3.2
Version
3.2 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
channelNumberChannel number of the channel we want to close.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_negotiateConnection()

MOC_EXTERN sbyte4 SSHC_negotiateConnection ( sbyte4  connectionInstance)

This function authenticates a server, establishing a secure connection.

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_negotiateSession()

MOC_EXTERN sbyte4 SSHC_negotiateSession ( sbyte4  connectionInstance)

This function negotiates a connection (the client is authenticated by the server), after which the SSH server can provide services requested by NanoSSH client.

Since
3.2
Version
3.2 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_negotiateSFTPHello()

MOC_EXTERN sbyte4 SSHC_negotiateSFTPHello ( sbyte4  connectionInstance)

This function starts a NanoSsH client SFTP session by negotiating an SFTP protocol version.

Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__
  • __ENABLE_MOCANA_SSH_FTP_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous SFTP clients.

sshc.h

◆ SSHC_negotiateSubsystemSFTPChannelRequest()

MOC_EXTERN sbyte4 SSHC_negotiateSubsystemSFTPChannelRequest ( sbyte4  connectionInstance)

This function sends an SSH exec sftp command on the specified connection.

Since
3.2
Version
3.2 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_numBytesTransmitted()

MOC_EXTERN sbyte4 SSHC_numBytesTransmitted ( sbyte4  connectionInstance,
ubyte8 *  pRetNumBytes 
)

This function returns (through the pRetNumBytes parameter) the number of bytes sent and received through a given connectionInstance. Typical usage for this function is to determine when it's appropriate to initiate a re-key exchange operation.

Since
4.2
Version
4.2 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__
Parameters
connectionInstanceConnection instance returned from SSHC_connect().
pRetNumBytesOn return, the number of bytes received and transmitted.

sshc.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous and asynchronous clients.

sshc.h

◆ SSHC_setCookie()

MOC_EXTERN sbyte4 SSHC_setCookie ( sbyte4  connectionInstance,
void *  cookie 
)

This function saves a cookie containing custom (application-specific) information about the context connection. Your application should not call this function until after it calls SSHC_connect().

Since
1.41
Version
1.41 and later

(pRetCookie changed type)

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
cookieCustom information (the cookie).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_shutdown()

MOC_EXTERN sbyte4 SSHC_shutdown ( void  )

This function releases memory that was initialized by SSHC_init().

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_sshClientSettings()

MOC_EXTERN sshClientSettings* SSHC_sshClientSettings ( void  )

This function returns a pointer to the session's NanoSSH client settings.

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Returns
Pointer to NanoSSH client settings.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_useThisCipher()

MOC_EXTERN sbyte4 SSHC_useThisCipher ( sbyte4  connectionInstance,
ubyte *  pCipher 
)

This function explicitly sets the cipher used by the specified SSH connection (instead of enabling automatic cipher selection). Because this function requires a valid connection instance, the function cannot be called until after a call to SSHC_connect().

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
pCipherPointer to string containing the desired cipher name (see sshc.hipher_suites).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h

◆ SSHC_useThisHmac()

MOC_EXTERN sbyte4 SSHC_useThisHmac ( sbyte4  connectionInstance,
ubyte *  pHmac 
)

This function explicitly sets the HMAC used by the specified SSH connection (instead of enabling automatic HMAC selection). Because this function requires a valid connection instance, the function cannot be called until after a call to SSHC_connect().

Since
5.1
Version
5.1 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_CLIENT__

sshc.h

Parameters
connectionInstanceConnection instance returned from SSHC_connect().
pHmacPointer to string containing the desired HMAC name (an entry in the mHmacSuites array, declared in sshc_trans.c).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous NanoSSH clients.

sshc.h