Home | C-Bits Package Documentation | Project Page |
#include <SSLSocket.h>
Inheritance diagram for cbits::SSLSocket:
Public Types | |
typedef SSL * | SSL_PTR |
\typedef A type definition used with the cbits::SSLSocket-to- OpenSSL SSL conversion operator. More... | |
Public Methods | |
SSLSocket (const std::string &host, const int port, SSLContext *const ctxt=0, const bool now=true) throw ( SocketException ) | |
Construct a SSL-enabled socket. More... | |
SSLSocket (const char *host, const int port, SSLContext *const ctxt=0, const bool now=true) throw ( SocketException ) | |
Construct a SSL-enabled socket. More... | |
virtual | ~SSLSocket () |
Destructor. More... | |
virtual void | connect () throw (SocketException) |
Complete (establish) the network connection. More... | |
virtual const ssize_t | read (char *const buffer, const int buflen, int *const error=0, const long int msec=0) throw ( SocketException ) |
Read data from the network connection into a user-supplied buffer. More... | |
virtual const ssize_t | receive (char *const buffer, const int buflen, const long int msec=0, int *const error=0) throw ( SocketException ) |
Synonym for cbits::Socket::read with the error and msec argument positions reversed. More... | |
virtual const ssize_t | readLine (std::string &buffer, const std::string &delim, int *const error=0, const long int msec=0) throw ( SocketException ) |
Read from the network connection until a specified delimiter string is encountered. More... | |
virtual const ssize_t | write (const char *buffer, const long buflen, int *const error=0, const long int msec=0) throw ( SocketException ) |
Write a buffer of data to the network connection. More... | |
virtual const ssize_t | send (const char *buffer, const long buflen, int *const error=0, const long int msec=0) throw ( SocketException ) |
const SSLPeer & | getPeer () const throw ( SocketException ) |
Access information about the SSL peer. More... | |
operator SSL_PTR () | |
Type conversion operator to allow a cbits::SSLSocket instance to be used where an OpenSSL SSL object is required. More... | |
virtual const ssize_t | send (const char *buffer, const long buflen, const long int msec=0, int *const error=0) throw ( SocketException ) |
Synonym for cbits::Socket::write with the error and msec argument positions reversed. More... | |
const socket_t | getHandle () const |
Get a handle to the underlying BSD socket connection. More... | |
std::iostream & | get_iostream () throw (SocketException) |
Get a std::iostream instance that can be used to write to or read from the socket. More... | |
const struct sockaddr_in & | get_addr () const |
Access the socket address that this cbits::Socket is bound to. More... | |
virtual const bool | isError () const |
Check the error status of thenetwork connection. More... | |
const std::string & | getError () const |
Access a human readable description of the socket error condition, if any. More... | |
virtual const bool | isReadable (long int *msec=0, int *const error=0) const |
Determine if the socket has data. More... | |
virtual const bool | isWritable (long int *msec=0, int *const error=0) const |
Determine if the socket can accept data. More... | |
operator std::ostream & () | |
Type conversion operator for when cbits::Socket needs to be used as a std::ostream instance. More... | |
operator std::istream & () | |
Type conversion operator for when cbits::Socket needs to be used as a std::istream instance. More... | |
virtual const bool | set_blocking_on () |
Configure the network connection such that calls to read data will block if none is available and calls to write data will block if the network connection can not immediately accept the data. More... | |
virtual const bool | set_blocking_off () |
set_blocking_off. More... | |
virtual const int | getSockOpt (const int level, const int op_name, char *buffer, int *buflen) const |
Access the value of a socket option. More... | |
std::ostream * | getLogger () const |
Access this Socket's debug logging stream. More... | |
std::ostream * | getLocalLogger () const |
Access this Sockets individual logging stream, set via cbits::setLocalLogger, if any. More... | |
void | setLocalLogger (std::ostream *os) const |
Set a instance debug logging stream for this Socket. More... | |
void | closeLocalLogger () const |
Close this Socket's individually set debug log stream, set via cbits::Socket::setLocalLogger, if any. More... | |
Static Public Methods | |
SSLSocket * | create (const socket_t fd, SSLContext *const ctxt=0) throw ( SocketException ) |
Create a SSL-enabled socket instance from an existing socket file descriptor. More... | |
void | setGlobalContext (SSLContext *gctx) throw ( SSLContextException ) |
Set a SSL context to be used by ALL new SSLSocket instances. More... | |
Socket * | create (const socket_t s) |
Wrap a pre-existing low-level BSD socket in a cbits::Socket. More... | |
std::ostream * | getGlobalLogger () |
Access the global debug logging stream for all Socket instances that don't have an individual logging stream. More... | |
void | setGlobalLogger (std::ostream *os) |
Set a global debug logging stream to be used by all Socket instances. More... | |
void | closeGlobalLogger () |
Close the globally set debug log stream, set via cbits::Socket::setGlobalLogger, if any. More... | |
Protected Methods | |
SSLSocket (const socket_t fd, SSLContext *const ctxt=0) throw ( SocketException ) | |
Protected constructor for wrapping a socket descriptor in an cbits::SSLSocket object. More... | |
const bool | isAvailable (fd_set *rd, fd_set *wr, long int *msec=0, int *error=0) const |
Use the 'select' system call to determine if any of a set of file descriptors are available for reading or writing. More... | |
Protected Attributes | |
bool | _ssl_is_connected |
A state flag that is set to true after the SSL handshake has successfully completed. More... | |
socket_t | _sockfd |
The BSD socket descriptor. More... | |
sockaddr_in | _host |
Address of remote host. More... | |
int | _port |
Port of remote host application. More... | |
std::iostream * | _iostream |
<iostream> rep of this Socket. More... | |
bool | _error |
Last error that occurred. More... | |
std::string | _errstr |
Human readable descripton of _error. More... | |
bool | _is_connected |
true if socket is connected. More... | |
bool | _is_bound |
std::ostream * | _llogr |
instance-scoped logging stream. More... | |
Static Protected Attributes | |
std::ostream * | _glogr = 0 |
class-scoped logging stream. More... | |
Private Methods | |
void | set_bio (const socket_t fd) throw ( SocketException ) |
Wrap the underlying network socket in an OpenSSL socket BIO object. More... | |
Private Attributes | |
BIO * | _bio |
The OpenSSL BIO object that wraps the low-level network socket connection. More... | |
SSLContext * | _ctxt |
The SSL context for this SSL connection. More... | |
SSL * | _ssl |
The OpenSSL SSL object representing this SSL connection. More... | |
SSLPeer * | _peer |
The SSL peer if the SSL connection is complete. More... | |
CriticalSection | _csect |
Critical section used to synchronize access to non-read/write specific code. More... | |
CriticalSection | _read_csect |
Critical section object used to prevent multiple threads from simultaneously reading from this SSL socket. More... | |
CriticalSection | _write_csect |
Critical section object used to prevent multiple threads from simultaneously writing to this SSL socket. More... | |
Static Private Attributes | |
SSLContext * | _global_ctxt |
The global, default SSL context, if set. More... |
The OpenSSL library (http://www.openssl.org) is used to provide SSL-related functionality and X.509 certificate handling.
The current version of this class is a minimal implementation. Overtime, more of the power available via OpenSSL will become visible in its interface.
From the user's perspective, a cbits::SSLSocket is (in principle) identical to a cbits::Socket in terms of functionality after the network connection has been established and the SSL handshake has succeeded.
However, all SSL sockets have to be created within a particular SSL context that defines parameters and data used during the SSL handshake, such as what ciphers are allowed (or not) and the location of relevant X.509 certificates.
The cbits::SSLContext class is used to represent an SSL security context for establishing SSL network connections. An instance of cbits::SSLContext should be provided to the cbits::SSLSocket constructor or set globally, in advance, for all (future) SSLSocket instances via the cbits::SSLSocket::setGlobalContext method.
Other methods in cbits::SSLSocket not inherited from cbits::Socket include those related to accessing the security credentials of the SSL peer (e.g. see cbits::SSLPeer).
|
\typedef A type definition used with the cbits::SSLSocket-to- OpenSSL SSL conversion operator.
|
|
Construct a SSL-enabled socket.
|
|
Construct a SSL-enabled socket.
|
|
Destructor. Close the network connection and destroy this socket instance. |
|
Protected constructor for wrapping a socket descriptor in an cbits::SSLSocket object.
|
|
Close the globally set debug log stream, set via cbits::Socket::setGlobalLogger, if any. Since the output stream supplied to cbits::Socket::setGlobalLogger is externally created, the output stream itself is not closed by this action. |
|
Close this Socket's individually set debug log stream, set via cbits::Socket::setLocalLogger, if any. Since the output stream supplied to cbits::Socket::setLocalLogger is externally created, the output stream itself is not closed by this action. |
|
Complete (establish) the network connection.
Reimplemented from cbits::Socket. |
|
Wrap a pre-existing low-level BSD socket in a cbits::Socket.
|
|
Create a SSL-enabled socket instance from an existing socket file descriptor. An SSL context must be specified for the new socket.
|
|
Access the socket address that this cbits::Socket is bound to.
|
|
Get a std::iostream instance that can be used to write to or read from the socket. All of the rules related to use of a std::iostream instance apply, including the need to check the stream flags for errors.
|
|
Access a human readable description of the socket error condition, if any. @Returns A non-empty string if an error exists on the socket; otherwise an empty string is returned. |
|
Access the global debug logging stream for all Socket instances that don't have an individual logging stream. This only accesses the logging stream that is used by Socket instances that haven't been individually configured with their own logging stream via cbits::Socket::setLocalLogger.
|
|
Get a handle to the underlying BSD socket connection.
|
|
Access this Sockets individual logging stream, set via cbits::setLocalLogger, if any.
|
|
Access this Socket's debug logging stream. A pointer to a stream is always returned. Logging statements that use this method should perform runtime checks to determine if application debug logging is enabled.
|
|
Access information about the SSL peer.
|
|
Access the value of a socket option.
|
|
Use the 'select' system call to determine if any of a set of file descriptors are available for reading or writing.
|
|
Check the error status of thenetwork connection. Generally, any error on a cbits::Socket should invalidate it.
|
|
Determine if the socket has data. Arguments: ----------- error - optional pointer to an error flag that is updated to a non-zero value if an error occurs during the call. Returns: ------------ true if the socket is readble (as determined by 'select'); otherwise, false. Exceptions: ----------- none.
|
|
Determine if the socket can accept data.
|
|
Type conversion operator to allow a cbits::SSLSocket instance to be used where an OpenSSL SSL object is required.
|
|
Type conversion operator for when cbits::Socket needs to be used as a std::istream instance.
|
|
Type conversion operator for when cbits::Socket needs to be used as a std::ostream instance.
|
|
Read data from the network connection into a user-supplied buffer.
Reimplemented from cbits::Socket. |
|
Read from the network connection until a specified delimiter string is encountered.
For instance, readLine("\r set to the specific 'errno' value returned by the OS.
Reimplemented from cbits::Socket. |
|
Synonym for cbits::Socket::read with the error and msec argument positions reversed.
Reimplemented from cbits::Socket. |
|
Synonym for cbits::Socket::write with the error and msec argument positions reversed.
|
|
|
|
Wrap the underlying network socket in an OpenSSL socket BIO object.
|
|
set_blocking_off. Configure the network connection such that calls to read data will not block if none is available and calls to write data will not block if the network connection can not immediately accept the data.
|
|
Configure the network connection such that calls to read data will block if none is available and calls to write data will block if the network connection can not immediately accept the data.
|
|
Set a SSL context to be used by ALL new SSLSocket instances. This may be overridden for individual SSLSocket instances by supplying a different context to the SSLSocket constructor when the SSLSocket is created.
|
|
Set a global debug logging stream to be used by all Socket instances. This does not override a Socket instance's specific logging stream if any. This method is a useful way to provide a default logging stream to all Socket instances, without having to configure each instance separately, but still be able to set the logging stream for specific Socket instances. |
|
Set a instance debug logging stream for this Socket.
|
|
Write a buffer of data to the network connection.
Reimplemented from cbits::Socket. |
|
The OpenSSL BIO object that wraps the low-level network socket connection. This BIO object is in turn wrapped by an OpenSSL SSL object. |
|
Critical section used to synchronize access to non-read/write specific code.
Reimplemented from cbits::Socket. |
|
The SSL context for this SSL connection.
|
|
Last error that occurred.
|
|
Human readable descripton of _error.
|
|
The global, default SSL context, if set.
|
|
class-scoped logging stream.
|
|
Address of remote host.
|
|
<iostream> rep of this Socket.
|
|
|
|
true if socket is connected.
|
|
instance-scoped logging stream.
|
|
The SSL peer if the SSL connection is complete.
|
|
Port of remote host application.
|
|
Critical section object used to prevent multiple threads from simultaneously reading from this SSL socket.
Reimplemented from cbits::Socket. |
|
The BSD socket descriptor.
|
|
The OpenSSL SSL object representing this SSL connection.
|
|
A state flag that is set to true after the SSL handshake has successfully completed.
|
|
Critical section object used to prevent multiple threads from simultaneously writing to this SSL socket.
Reimplemented from cbits::Socket. |
|
|