SharkSSL™ Embedded SSL/TLS Stack
Client Session Cache Manager

Detailed Description

Simplifies SSL client session management when connectiong to an arbitrary number of servers.

The SharkSSL Session Cache Manager (SharkSslSCMgr) is an optional plugin that simplifies SSL resumption for clients that are designed to connect to an arbitrary number of servers. An instance of the SharkSslSCMgr class maintains a time limited database of servers that have previously been connected and automatically resumes the SSL session for new connections when the server address is found in the database.

The following example illustrates how to use the SharkSslSCMgr. The example below is a code snippet from the sessioncache.c example, where error checking has been removed:

const char* servers[]= {"realtimelogic.com", "sharkssl.com", "www.google.com"};
for(i=0 ; i < sizeof(servers)/sizeof(servers[0]); i++)
{
SOCKET sock;
se_connect(&sock, servers[i], 443)
SharkSslCon* scon = SharkSsl_createCon(&sharkSsl);
SharkSslSCMgrNode* scn = SharkSslSCMgr_get(&scMgr, scon, servers[i], 443);
seSec_handshake(scon,&sock,3000);
SharkSslSCMgr_save(&scMgr, scon, servers[i], 443, scn);
// Secure connection code here, such as HTTPS
SharkSsl_terminateCon(&sharkSsl, scon);
se_close(&sock);
}

SharkSslSCMgr requires that the following SharkSSL features are enabled: SHARKSSL_SSL_CLIENT_CODE and SHARKSSL_ENABLE_SESSION_CACHE

Data Structures

struct  SharkSslSCMgrNode
 The handle returned by SharkSslSCMgr_get and passed into SharkSslSCMgr_save. More...
 
struct  SharkSslSCMgr
 See SharkSslSCMgr_constructor for details. More...
 

Functions

SHARKSSL_API void SharkSslSCMgr_constructor (SharkSslSCMgr *o, SharkSsl *ssl, U32 maxTime)
 SharkSslSCMgr simplifies using the session API for TLS clients; the constructor initializes a SharkSslSCMgr instance. More...
 
SHARKSSL_API SharkSslSCMgrNodeSharkSslSCMgr_get (SharkSslSCMgr *o, SharkSslCon *scon, const char *host, U16 port)
 Resume a session. More...
 
SHARKSSL_API int SharkSslSCMgr_save (SharkSslSCMgr *o, SharkSslCon *scon, const char *host, U16 port)
 Save the session when SharkSslSCMgr_get returns NULL. More...
 

Function Documentation

◆ SharkSslSCMgr_constructor()

SHARKSSL_API void SharkSslSCMgr_constructor ( SharkSslSCMgr o,
SharkSsl ssl,
U32  maxTime 
)

SharkSslSCMgr simplifies using the session API for TLS clients; the constructor initializes a SharkSslSCMgr instance.

Parameters
oan uninitialized static object or dynamically allocated object.
sslan initialized SharkSsl instance.
maxTimethe maximum time for stored sessions in seconds. A good value would be 60*60.

◆ SharkSslSCMgr_get()

SHARKSSL_API SharkSslSCMgrNode * SharkSslSCMgr_get ( SharkSslSCMgr o,
SharkSslCon scon,
const char *  host,
U16  port 
)

Resume a session.

The returned value is a handle and should not be modified by the client. The method returns NULL if no session could be resumed. The method must be called just after SharkSslCon_isHandshakeComplete() returns true.

◆ SharkSslSCMgr_save()

SHARKSSL_API int SharkSslSCMgr_save ( SharkSslSCMgr o,
SharkSslCon scon,
const char *  host,
U16  port 
)

Save the session when SharkSslSCMgr_get returns NULL.

It is an error calling this method if SharkSslSCMgr_get returns a handle. The method should be called when closing the connection and just before terminating the SharkSslCon object.

Parameters
oan initialized SharkSslSCMgrNode object
scona valid SharkSslCon object.
hostthe server's domain name
portthe server's port number e.g. 443
Returns
0 if session was saved, otherwise -1 is returned.