tfUseSsl

Jump to: navigation, search

Table of Contents >> SSL Programmer's Reference


#include <trsocket.h>


int tfUseSsl (int maximumSession);


Function Description

tfUseSsl() must be called after tfStartTreck(), and before any other SSL function calls. This function allocates memory for SSL global variable.


Parameters

  • maximumSession
    Maximum sessions user wants to support, must greater or equal to zero, and less than 65536. If user passes invalid value, default value TM_SSL_NUMBEROF_SESSION_DEFAULT (32) is used. In Treck SSL, each session maintains its own connect information for the convenience of resumption. You can resume a previous connection only if the current connect attempt and the previous one are in the same SSL session, and your previous connection cache hasn’t been overwritten yet. For Treck SSL server, all connections spawned from a single listening socket belongs to one session, you should assign the session Id to the listening socket. All accepted sockets will inherit that session Id. For Treck SSL client, user determines which session one connection belongs to. For example, user may decide that any connection to the same SSL-enabled web server uses a single session Id, so that when user is trying to connect to the same server again, (s)he may resume the previous connection.


Returns

  • TM_ENOERROR
    Success
  • TM_EINVAL
    Invalid value is passed in
  • TM_EALREADY
    tfUseSsl has been called before
  • TM_ENOBUFS
    No more buffers


Example

 
{
...
/* start treck */
errorCode = tfStartTreck();
if (errorCode != TM_ENOERROR)
{
}
/* start PKI, see Treck Crypto Library User Document for details . To
use SSL, you must use PKI in order to support RSA/DSS algorithms */
errorCode = tfUsePki();
/* Add CA’s certificate */
errorCode = tfPkiCertificateAdd (…);
/* SSL server’s private key and public key pairs . In OpenSSL files,
it is called private key */
errorCode = tfPkiOwnKeyPairAdd (…);
/* Add SSL server’s certificate, which is signed by the CA you added
before */
errorCode = tfPkiCertificateAdd (…);
/* start SSL */
errorCode = tfUseSsl(1); /*Suppose we have only one SSL server
to run, so one session is enough. */
...
 

Table of Contents >> SSL Programmer's Reference