Encapsulates an SSL connection data structure. More...
#include <tcpssl.h>
Public Member Functions | |
SSL (DataSocket &owner, SSLContext &context) | |
Constructor. More... | |
virtual | ~SSL () |
Destructor. | |
void | setOptions (bool verifypeer=false) |
Sets default options for all SSL objects created from this context. More... | |
bool | setCertificateAndKey (const char *certfile, const char *keyfile) |
Sets the certificate filename and key filename. More... | |
void | setPrivateKeyPassword (string value) |
Sets the value of the private key password. | |
virtual int | passwordCallback (char *buf, int size, int rwflag) |
Called when a password to decrypt a private key is required. More... | |
bool | setfd (int socket) |
Sets the socket file descripter for this SSL object. More... | |
string & | getSubjectName () |
Returns the peer certificate subject name or an empty string if none was sent. | |
bool | verifyResult () |
Return true if the peer certificate was verified or if no certificate was presented. | |
bool | connect () |
Starts the SSL client handshake sequence. | |
bool | accept () |
Starts the SSL server handshake sequence. | |
size_t | read (void *buffer, size_t size) |
Reads and decrypts SSL socket data. More... | |
size_t | write (const void *buffer, size_t size) |
Encrypts and writes SSL socket data. More... | |
void | clear () |
Resets the SSL object for another connection. More... | |
void | shutdown () |
Closes the SSL connection gracefully. | |
void | setHostname (const string value) |
A client/server may store the internal hostname property for certificate post validation. | |
Public Attributes | |
bool | requiresCertPostValidation { false } |
If True, the certificate will be checked for validity on the first read/write operation. | |
Protected Member Functions | |
bool | performCertPostValidation () |
Performs a post handshake validation of the peer certificate. More... | |
virtual bool | validateSubjectName (const string &subjectName, const string &hostName) |
Validate the peer certificate subject name. More... | |
Protected Attributes | |
DataSocket & | owner_ |
A reference to the socket | |
SSLMode | mode_ |
Either SERVER or CLIENT | |
::SSL * | ssl_ |
The openSSL handle for API calls. | |
Friends | |
class | SSLContext |
tcp::SSL::SSL | ( | DataSocket & | owner, |
SSLContext & | context | ||
) |
Constructor.
owner | [in] The tcp::Session or tcp::Client this SSL object is for |
context | [in] The context object used as defaults for this SSL connection |
Definition at line 396 of file tcpssl.cpp.
void tcp::SSL::clear | ( | ) |
Resets the SSL object for another connection.
This method could be used by a client reconnecting to the same server
Definition at line 632 of file tcpssl.cpp.
|
virtual |
Called when a password to decrypt a private key is required.
Descendant classes may want to override this to provide a more secure means of storing the private key password. The default behavior is to return the value of keypass_.
SSL_CTX_set_default_passwd_cb
for more details Definition at line 460 of file tcpssl.cpp.
|
protected |
Performs a post handshake validation of the peer certificate.
The post validation is performed on the first read or write operation If the post validation fails the session is disconnected. This check is only performed if requiresCertPostValidation is true
Definition at line 533 of file tcpssl.cpp.
size_t tcp::SSL::read | ( | void * | buffer, |
size_t | size | ||
) |
Reads and decrypts SSL socket data.
buffer | [in] Where to place the read data |
size | [in] The size of buffer |
Definition at line 594 of file tcpssl.cpp.
bool tcp::SSL::setCertificateAndKey | ( | const char * | certfile, |
const char * | keyfile | ||
) |
Sets the certificate filename and key filename.
Sets the certificate and key file for the SSL connection To set this property for all client or server connections, see the corresponding method in the SSLContext class
certfile | [in] The filename of a certificate chain in PEM (or CRT) format |
keyfile | [in] The filename of a private key in PEM (or CRT) format |
Definition at line 418 of file tcpssl.cpp.
bool tcp::SSL::setfd | ( | int | socket | ) |
Sets the socket file descripter for this SSL object.
An application must set the file descriptor for the socket prior to calling accept() or connect()
socket | [in] The linux socket handle |
Definition at line 472 of file tcpssl.cpp.
void tcp::SSL::setOptions | ( | bool | verifypeer = false | ) |
Sets default options for all SSL objects created from this context.
Additional options can be set in the SSLContext object associated with this SSL object
verifypeer | [in] If true, the server/client will validate the peer certificate |
Definition at line 407 of file tcpssl.cpp.
|
protectedvirtual |
Validate the peer certificate subject name.
This function should return true if the subject name is considered valid. It is intended to verify that the hostname matches the certificate subjectname. The default implementation uses whte wildcmp function to perform a wildcard compare. Only called if checkPeerSubjectName is true.
Definition at line 528 of file tcpssl.cpp.
size_t tcp::SSL::write | ( | const void * | buffer, |
size_t | size | ||
) |
Encrypts and writes SSL socket data.
buffer | [in] Where to place the read data |
size | [in] The size of buffer |
Definition at line 613 of file tcpssl.cpp.