TrustCore SDK NanoSSL API reference  version 7.0
Synchronous Client and Server Functions

Synchronous NanoSSL client and server functions. More...

Functions

MOC_EXTERN sbyte4 SSL_checkRehandshakeTimer (sbyte4 connectionInstance)
 Timer check for rehandshaking. More...
 
MOC_EXTERN sbyte4 SSL_closeConnection (sbyte4 connectionInstance)
 Close an SSL session and release resources. More...
 
MOC_EXTERN sbyte4 SSL_init (sbyte4 numServerConnections, sbyte4 numClientConnections)
 Initialize NanoSSL client or server internal structures. More...
 
MOC_EXTERN sbyte4 SSL_negotiateConnection (sbyte4 connectionInstance)
 Establish a secure SSL client-server connection. More...
 
MOC_EXTERN sbyte4 SSL_recv (sbyte4 connectionInstance, sbyte *pRetBuffer, sbyte4 bufferSize, sbyte4 *pNumBytesReceived, ubyte4 timeout)
 Get data from a connected server/client. More...
 
MOC_EXTERN sbyte4 SSL_recvPending (sbyte4 connectionInstance, sbyte4 *pRetBooleanIsPending)
 Test if a connection instance's SSL receive buffer contains data. More...
 
MOC_EXTERN sbyte4 SSL_send (sbyte4 connectionInstance, sbyte *pBuffer, sbyte4 bufferSize)
 Send data to a connected server/client. More...
 
MOC_EXTERN sbyte4 SSL_sendPending (sbyte4 connectionInstance, sbyte4 *pNumBytesPending)
 Determines whether there is data in a connection instance's SSL send buffer. More...
 

Detailed Description

See also
Synchronous Client Functions
Synchronous Server Functions
Core (Async and Sync) Client Functions
Core (Async and Sync) Client and Server Functions
Core (Async and Sync) Server Functions

Function Documentation

◆ SSL_checkRehandshakeTimer()

MOC_EXTERN sbyte4 SSL_checkRehandshakeTimer ( sbyte4  connectionInstance)

This function checks whether a rehandshaking request for the server SSL session has timed out, and if so, calls the callback function. If timeout occurs, it will call the callback function to initiate the rehandshake.

Since
5.8
Version
5.8 and later

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

  • __ENABLE_MOCANA_SSL_REHANDSHAKE__

Additionally, at least one of the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSL_SERVER__
  • __ENABLE_MOCANA_SSL_ASYNC_SERVER_API__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_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 clients and servers.

ssl.c

◆ SSL_closeConnection()

MOC_EXTERN sbyte4 SSL_closeConnection ( sbyte4  connectionInstance)

This function closes a synchronous SSL session and releases all the resources that are managed by the NanoSSL client/server.

Since
1.41
Version
3.06 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_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 clients and servers.

ssl.c

◆ SSL_init()

MOC_EXTERN sbyte4 SSL_init ( sbyte4  numServerConnections,
sbyte4  numClientConnections 
)

This function initializes NanoSSL client/server internal structures. Your application should call this function before starting the HTTPS and application servers.

Since
1.41
Version
1.41 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
numServerConnectionsMaximum number of SSL/TLS server connections to allow. (Each connection requires only a few bytes of memory.)
numClientConnectionsMaximum number of SSL/TLS 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 clients and servers.

ssl.c

◆ SSL_negotiateConnection()

MOC_EXTERN sbyte4 SSL_negotiateConnection ( sbyte4  connectionInstance)

This function performs SSL handshaking, establishing a secure connection between a client and server. Before calling this function, you must first create a connection context (instance) by calling SSL_connect().

Since
1.41
Version
1.41 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_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 clients and servers.
sbyte4 connectionInstance;
int mySocket;
// connect to server
connect(mySocket, (struct sockaddr *)&server, sizeof(server))
// register connect, get connectionInstance
connectionInstance = SSL_connect(mySocket, 0, NULL, NULL, "mocana.com");
// set a cookie
SSL_setCookie(connectionInstance, (int)&someFutureContext);
// negotiate SSL secure connection
if (0 > SSL_negotiateConnection(connectionInstance))
goto error;

ssl.c

◆ SSL_recv()

MOC_EXTERN sbyte4 SSL_recv ( sbyte4  connectionInstance,
sbyte *  pRetBuffer,
sbyte4  bufferSize,
sbyte4 *  pNumBytesReceived,
ubyte4  timeout 
)

This function retrieves data from a connected server/client. It should not be called until an SSL connection is established between the client and server.

Since
1.41
Version
1.41 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_connect().
pRetBufferPointer to the buffer in which to write the received data.
bufferSizeNumber of bytes in receive data buffer.
pNumBytesReceivedOn return, pointer to the number of bytes received.
timeoutNumber of milliseconds the client/server will wait to receive the message. To specify no timeout (an infinite wait), set this parameter to 0.
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 clients and servers.
static int GetSecurePageAux(int connectionInstance, const char* pageName)
{
char buffer[1025];
unsigned int bytesSent;
int result = 0;
sprintf(buffer, "GET /%s HTTP/1.0\r\n\r\n", pageName);
bytesSent = SSL_send(connectionInstance,
buffer, strlen(buffer));
if (bytesSent == strlen(buffer)) {
int bytesReceived;
// how to receive
while (0 <= result) {
memset(buffer, 0x00, 1025);
result = SSL_recv(connectionInstance,
buffer, 1024, &bytesReceived, 0);
printf("%s", buffer);
}
return 0;
}
return -1;
}

ssl.c

◆ SSL_recvPending()

MOC_EXTERN sbyte4 SSL_recvPending ( sbyte4  connectionInstance,
sbyte4 *  pRetBooleanIsPending 
)

This function determines whether there is data in a connection instance's SSL receive buffer, and returns either TRUE or FALSE accordingly.

Since
1.41
Version
1.41 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_connect().
pRetBooleanIsPendingOn return, contains TRUE if there is data to be received, or FALSE if no data is pending receipt.
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 clients and servers.

ssl.c

◆ SSL_send()

MOC_EXTERN sbyte4 SSL_send ( sbyte4  connectionInstance,
sbyte *  pBuffer,
sbyte4  bufferSize 
)

This function sends data to a connected server/client. It should not be called until a secure SSL connection is established between the client and server. A negative return value indicates that an error has occurred. A return value >= 0 indicates the number of bytes transmitted.

Since
1.41
Version
1.41 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_connect().
pBufferPointer to buffer containing the data to send.
bufferSizeNumber of bytes in pBuffer.
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 clients and servers.
char reply[1024];
sbyte4 status;
status = SSL_send(connectionInstance, reply, strlen(reply));

ssl.c

◆ SSL_sendPending()

MOC_EXTERN sbyte4 SSL_sendPending ( sbyte4  connectionInstance,
sbyte4 *  pNumBytesPending 
)

This function determines whether there is data in a connection instance's SSL send buffer. If the send buffer is empty, zero (0) is returned through the pNumBytesPending parameter. If send data is pending, an attempt is made to send the data, and the subsequent number of bytes remaining to be sent is returned through the pNumBytesPending parameter. (A function return value of zero (0) indicates that the send was successful and that no data remains in the send buffer.)

Since
1.41
Version
1.41 and later

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

  • __ENABLE_MOCANA_SSL_CLIENT__
  • __ENABLE_MOCANA_SSL_SERVER__

ssl.h

Parameters
connectionInstanceConnection instance returned from SSL_acceptconnection() or SSL_connect().
pNumBytesPendingOn return, the number of bytes remaining in the SSL send buffer.
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 clients and servers.

ssl.c