Series x Secure Sockets
Series 60 2.x adds some new classes to handle secure sockets. The main one is CSecureSocket, which is instantiated from an RSocket handle to represent a secure socket. Its API is derived from the new mixin interface MSecureSocket.
The main shortcoming from Series 60 1 .x that is addressed by the new API is the lack of notification when the secure handshake completes. In Series 60 2.x, the handshake is initiated explicitly by means of an asynchronous function, and the corresponding Active Object is notified when the handshake completes.
Another key difference from Series 60 1 .x is that the RSocket handle must be connected before it is secured. So now the sequence of events is always as follows:
• Open a TCP/IP socket exactly as before, using RSocket::Open().
• Connect the socket, again just as in Series 60 1.x, using RSocket::Connect().
• Once RSocket::Connect() has completed, create a CSecureSocket object, passing the connected RSocket handle into its NewL() function.
• Call StartClientHandshake() on your secure socket, and wait for this to complete.
• Transfer data securely using the Send()and Recv() methods of CSecureSocket.
The following code segment shows construction of a CSecureSocket object and the initiation of the SSL handshake. Assume this is within a class derived from CActive, with member data ¡Socket (RSocket) and ¡SecureSocket (CSecureSocket*). ¡Socket has been opened and connected as described above.
// Construct the secure socket object _LIT(KSSL3, "SSL3.0"); // or "TLS1.0" for TLS ¡SecureSocket = CSecureSocket::NewL(iSocket, KSSL3);
// Start the SSL handshake process
¡SecureSocket->StartClientHandshake(iStatus);
SetActive();
When the handshake completes, the Active Object's RunL() method will be called, with the value of ¡Status indicating whether the handshake was successful. If the handshake succeeded, you can then go on to transfer data as follows:
// Class has the following members:
// - ¡RequestBuffer, a TBuf8 big enough to contain what we
// initialize ¡RequestBuffer here
¡SecureSocket->Send(iRequestBuffer, ¡Status, ¡BytesSent);
SetActiveQ;
When the Active Object's RunL() is called, iBytesSent will contain the number of bytes successfully sent from iRequestBuffer. If not all bytes have been sent, you will need to issue further Send() requests until the entire buffer has been transmitted.

Post a comment