IBR-DTNSuite  0.8
ibrcommon::TLSStream Class Reference

A Stream Class that adds Signatures and Encryption through TLS. More...

#include <TLSStream.h>

List of all members.

Public Types

typedef std::char_traits< char > traits

Public Member Functions

 TLSStream (std::iostream *stream)
 The TLSStream Constructor.
virtual ~TLSStream ()
 The default Destructor.
void setServer (bool val)
void close ()
 Closes the TLS Connection.
X509 * activate ()

Static Public Member Functions

static void init (X509 *certificate, EVP_PKEY *privateKey, ibrcommon::File trustedCAPath, bool enableEncryption=false)
 Initializes the TLSStream class.
static void flushInitialization ()
 Removes the SSL_CTX to allow a new init()
static bool isInitialized ()
 checks if the Class is already initialized.

Static Public Attributes

static const size_t BUFF_SIZE = 5120
 The size of the input and output buffers.

Protected Member Functions

virtual int sync ()
virtual traits::int_type overflow (traits::int_type=traits::eof())
virtual traits::int_type underflow ()

Detailed Description

A Stream Class that adds Signatures and Encryption through TLS.

The Stream passes data from and to the underlying Stream unchanged(unencrypted) until activate() is called. init() has to be called before the first usage.

Definition at line 27 of file TLSStream.h.


Member Typedef Documentation

typedef std::char_traits<char> ibrcommon::TLSStream::traits

Definition at line 30 of file TLSStream.h.


Constructor & Destructor Documentation

ibrcommon::TLSStream::TLSStream ( std::iostream *  stream)

The TLSStream Constructor.

Parameters:
streamthe underlying Stream to read from / write to
serverstates, if TLS is used in client or server mode (true for server, false for client)

Definition at line 32 of file TLSStream.cpp.

References BUFF_SIZE.

The default Destructor.

Definition at line 42 of file TLSStream.cpp.


Member Function Documentation

Returns:
the X509 certificate of the peer
Warning:
the caller has to check the identity in the certificate

Definition at line 55 of file TLSStream.cpp.

References ibrcommon::iostreamBIO::getBIO(), IBRCOMMON_LOGGER, IBRCOMMON_LOGGER_ENDL, and ibrcommon::Exception::what().

Here is the call graph for this function:

Closes the TLS Connection.

Warning:
The underlying Stream is not closed by this function.

Definition at line 347 of file TLSStream.cpp.

References IBRCOMMON_LOGGER_DEBUG, and IBRCOMMON_LOGGER_ENDL.

Referenced by underflow().

Removes the SSL_CTX to allow a new init()

Definition at line 328 of file TLSStream.cpp.

void ibrcommon::TLSStream::init ( X509 *  certificate,
EVP_PKEY *  privateKey,
ibrcommon::File  trustedCAPath,
bool  enableEncryption = false 
) [static]

Initializes the TLSStream class.

Parameters:
certificateThe certificate for the private Key
privateKeyThe private Key to use with openSSL
trustedCAPathA directory containing certificates that are trusted. These are also used to build the own certificate chain.
enableEncryptionTrue if encryption shall be enabled. Otherwise only authentication is enabled.

In particular, this function initializes the used openSSL Context. The certificate directory has to hold certificates files with hashed names created by c_rehash (from the openssl library).

Warning:
Beware that the certificate path does not have certificates valid and invalid certificates mixed with the same subject, openssl will only use the first that is found.
on default, encryption is disabled and the stream does only provide authentication

Definition at line 237 of file TLSStream.cpp.

References ibrcommon::File::getFiles(), ibrcommon::File::getPath(), IBRCOMMON_LOGGER, IBRCOMMON_LOGGER_ENDL, and ibrcommon::File::isDirectory().

Here is the call graph for this function:

checks if the Class is already initialized.

Returns:
true if its initialized, false otherwise

Definition at line 343 of file TLSStream.cpp.

Referenced by dtn::net::TCPConvergenceLayer::componentRun(), dtn::net::TCPConvergenceLayer::open(), and dtn::net::TCPConvergenceLayer::queue().

TLSStream::traits::int_type ibrcommon::TLSStream::overflow ( traits::int_type  c = traits::eof()) [protected, virtual]

Definition at line 189 of file TLSStream.cpp.

References BUFF_SIZE, IBRCOMMON_LOGGER_DEBUG, and IBRCOMMON_LOGGER_ENDL.

Referenced by sync().

void ibrcommon::TLSStream::setServer ( bool  val)

If true, set the connection mode to server.

Parameters:
val

Definition at line 50 of file TLSStream.cpp.

int ibrcommon::TLSStream::sync ( ) [protected, virtual]

Definition at line 363 of file TLSStream.cpp.

References overflow().

Here is the call graph for this function:

TLSStream::traits::int_type ibrcommon::TLSStream::underflow ( ) [protected, virtual]

Definition at line 139 of file TLSStream.cpp.

References BUFF_SIZE, close(), IBRCOMMON_LOGGER_DEBUG, and IBRCOMMON_LOGGER_ENDL.

Here is the call graph for this function:


Member Data Documentation

const size_t ibrcommon::TLSStream::BUFF_SIZE = 5120 [static]

The size of the input and output buffers.

Definition at line 81 of file TLSStream.h.

Referenced by overflow(), TLSStream(), and underflow().


The documentation for this class was generated from the following files: