Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CATLSClientSocket Class Reference
Inheritance diagram for CATLSClientSocket:
CASocket CAClientSocket

Public Member Functions

 CATLSClientSocket ()
 
 ~CATLSClientSocket ()
 
SINT32 sendFully (const UINT8 *buff, UINT32 len)
 Sends all data over the network. More...
 
SINT32 send (const UINT8 *buff, UINT32 len)
 Sends all data over the network. More...
 
SINT32 receive (UINT8 *buff, UINT32 len)
 Will receive some bytes from the socket. More...
 
SINT32 close ()
 Shuts down the socket. More...
 
SINT32 connect (const CASocketAddr &psa, UINT32 msTimeout)
 Establishes the actual TCP/IP connection and performs the TLS handshake. More...
 
SINT32 setServerCertificate (CACertificate *pCert)
 Sets the Certifcate we accept as server identification. More...
 
- Public Member Functions inherited from CASocket
 CASocket (bool bIsReserved=false)
 
 ~CASocket ()
 
virtual SINT32 create ()
 
virtual SINT32 create (bool a_bShowTypicalError)
 
virtual SINT32 create (SINT32 type)
 
virtual SINT32 listen (const CASocketAddr &psa)
 Starts listening on address psa. More...
 
virtual SINT32 listen (UINT16 port)
 
virtual SINT32 accept (CASocket &s)
 Accepts a new connection. More...
 
virtual SINT32 connect (const CASocketAddr &psa)
 
virtual SINT32 connect (const CASocketAddr &psa, UINT32 retry, UINT32 sWaitTime)
 Tries to connect to the peer described by psa. More...
 
virtual SINT32 sendFullyTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend)
 Sends all data over the network. More...
 
virtual SINT32 sendTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Sends some data over the network. More...
 
virtual SINT32 receiveFullyT (UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Trys to receive all bytes. More...
 
virtual SINT32 receiveLine (UINT8 *line, UINT32 maxLen, UINT32 msTimeOut)
 
virtual SINT32 peek (UINT8 *buff, UINT32 len)
 Will peek some bytes from the socket read queue. More...
 
SOCKET getSocket ()
 Returns the number of the Socket used. More...
 
virtual SINT32 getLocalIP (UINT8 r_Ip[4])
 LERNGRUPPE Returns the source address of the socket. More...
 
virtual SINT32 getLocalPort ()
 
virtual SINT32 getPeerIP (UINT8 ip[4])
 
virtual SINT32 getPeerPort ()
 
virtual SINT32 setReuseAddr (bool b)
 
virtual SINT32 setSendTimeOut (UINT32 msTimeOut)
 
virtual SINT32 getSendTimeOut ()
 
virtual SINT32 setRecvBuff (UINT32 r)
 
virtual SINT32 getRecvBuff ()
 
virtual SINT32 setSendBuff (SINT32 r)
 Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r) More...
 
virtual SINT32 getSendBuff ()
 
virtual SINT32 setKeepAlive (bool b)
 Enables/disables the socket keep-alive option. More...
 
virtual SINT32 setKeepAlive (UINT32 sec)
 Enables the socket keep-alive option with a given ping time (in seconds). More...
 
virtual SINT32 setNonBlocking (bool b)
 
virtual SINT32 getNonBlocking (bool *b)
 
virtual bool isClosed ()
 
- Public Member Functions inherited from CAClientSocket
virtual ~CAClientSocket ()
 
SINT32 receiveFully (UINT8 *buff, UINT32 len)
 Receives all len bytes. More...
 

Private Member Functions

SINT32 doTLSConnect (const CASocketAddr &psa)
 Does the TLS handshake. More...
 

Private Attributes

SSL * m_pSSL
 
SSL_CTX * m_pCtx
 
CACertificatem_pRootCert
 
bool m_bConnectedTLS
 is the TLS layer established ? More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CASocket
static SINT32 init ()
 
static SINT32 cleanup ()
 
static SINT32 setMaxNormalSockets (UINT32 u)
 Sets the max number of allowed "normal" sockets. More...
 
static SINT32 getMaxOpenSockets ()
 Tries to find out how many socket we can open by open as many socket as possible witthout errors. More...
 
static UINT32 countOpenSockets ()
 
- Protected Attributes inherited from CASocket
volatile bool m_bSocketIsClosed
 check More...
 
SOCKET m_Socket
 
CASingleSocketGroupm_pSingleSocketGroupRead
 

Constructor & Destructor Documentation

◆ CATLSClientSocket()

CATLSClientSocket::CATLSClientSocket ( )

◆ ~CATLSClientSocket()

CATLSClientSocket::~CATLSClientSocket ( )

References close(), m_pCtx, and m_pRootCert.

Member Function Documentation

◆ close()

SINT32 CATLSClientSocket::close ( )
virtual

Shuts down the socket.

This is an overridden virtual function which shuts down the TLS layer first

Reimplemented from CASocket.

References CASocket::close(), m_bConnectedTLS, and m_pSSL.

Referenced by doTLSConnect(), CAAccountingBIInterface::initBIConnection(), CAAccountingBIInterface::terminateBIConnection(), and ~CATLSClientSocket().

◆ connect()

SINT32 CATLSClientSocket::connect ( const CASocketAddr psa,
UINT32  msTimeout 
)
virtual

Establishes the actual TCP/IP connection and performs the TLS handshake.

Establishes the TCP/IP connection, performs the TLS handshake and checks the server certificate validity.

Reimplemented from CASocket.

References CASocket::close(), CASocket::connect(), doTLSConnect(), and E_SUCCESS.

Referenced by CAAccountingBIInterface::initBIConnection().

◆ doTLSConnect()

SINT32 CATLSClientSocket::doTLSConnect ( const CASocketAddr psa)
private

Does the TLS handshake.

The TCP Connection must be established first and openSSL library must be initialized

References close(), E_SUCCESS, E_UNKNOWN, CACertificate::getX509(), m_bConnectedTLS, m_pCtx, m_pRootCert, m_pSSL, CASocket::m_Socket, and CAMsg::printMsg().

Referenced by connect().

◆ receive()

SINT32 CATLSClientSocket::receive ( UINT8 buff,
UINT32  len 
)
virtual

Will receive some bytes from the socket.

May block or not depending on whatever this socket was set to blocking or non-blocking mode. Warning: If socket is in blocking mode and receive is called, receive will block until some data is available, EVEN IF AN OTHER THREAD WILL CLOSE THIS SOCKET!

Parameters
buffthe buffer which get the received data
lensize of buff
Returns
SOCKET_ERROR if an error occured
Return values
E_AGAIN,ifsocket was in non-blocking mode and receive would block or a timeout was reached
0if socket was gracefully closed
Returns
the number of bytes received (always >0)

Reimplemented from CASocket.

References E_AGAIN, len, m_pSSL, CAMsg::printMsg(), SOCKET_ERROR, and strerror().

◆ send()

SINT32 CATLSClientSocket::send ( const UINT8 buff,
UINT32  len 
)
virtual

Sends all data over the network.

This may block, until all data was sent.

Parameters
buffthe buffer of data to send
lencontent length
Return values
E_UNKNOWNif an error occured
E_SUCCESSif successfull

Reimplemented from CASocket.

References E_AGAIN, E_SUCCESS, len, m_pSSL, CAMsg::printMsg(), SOCKET_ERROR, and strerror().

◆ sendFully()

SINT32 CATLSClientSocket::sendFully ( const UINT8 buff,
UINT32  len 
)
virtual

Sends all data over the network.

This may block, until all data was sent.

Parameters
buffthe buffer of data to send
lencontent length
Return values
E_UNKNOWNif an error occured
E_SUCCESSif successfull

Reimplemented from CASocket.

References E_SUCCESS, E_UNKNOWN, len, and m_pSSL.

◆ setServerCertificate()

SINT32 CATLSClientSocket::setServerCertificate ( CACertificate pCert)

Sets the Certifcate we accept as server identification.

Init the SSL object.

Set to NULL if you do not want any certificate checking. @Note At the moment only a depth of verification path of zero or one is supported!

SSL_init_library() must be called before this!

References CACertificate::clone(), E_SUCCESS, and m_pRootCert.

Referenced by CAAccountingBIInterface::initBIConnection().

Member Data Documentation

◆ m_bConnectedTLS

bool CATLSClientSocket::m_bConnectedTLS
private

is the TLS layer established ?

Referenced by CATLSClientSocket(), close(), and doTLSConnect().

◆ m_pCtx

SSL_CTX* CATLSClientSocket::m_pCtx
private

◆ m_pRootCert

CACertificate* CATLSClientSocket::m_pRootCert
private

◆ m_pSSL

SSL* CATLSClientSocket::m_pSSL
private