Logo
~Sockets~
~Examples~
~Contact~


SSLInitializer Class Reference

#include <SSLInitializer.h>

Collaboration diagram for SSLInitializer:

List of all members.


Public Member Functions

 SSLInitializer ()
 init openssl bio_err create random file
 ~SSLInitializer ()
 remove random file
void DeleteRandFile ()

Static Public Member Functions

static void SSL_locking_function (int mode, int n, const char *file, int line)
 SSL; mutex locking function callback.
static unsigned long SSL_id_function ()
 Return thread id.

Public Attributes

BIO * bio_err

Private Attributes

std::string m_rand_file
long m_rand_size

Static Private Attributes

static std::map< int, Mutex * > m_mmap
static Mutex m_mmap_mutex

Detailed Description

Definition at line 47 of file SSLInitializer.h.


Constructor & Destructor Documentation

SSLInitializer::SSLInitializer (  ) 

init openssl bio_err create random file

Definition at line 60 of file SSLInitializer.cpp.

References bio_err, DEB, m_rand_file, m_rand_size, Utility::SetEnv(), SSL_id_function(), and SSL_locking_function().

00061 {
00062 DEB(    fprintf(stderr, "SSLInitializer()\n");)
00063 
00064         bio_err = NULL;
00065         m_rand_size = 1024;
00066 
00067         /* An error write context */
00068         bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
00069 
00070         /* Global system initialization*/
00071         SSL_library_init();
00072         SSL_load_error_strings();
00073         OpenSSL_add_all_algorithms();
00074         CRYPTO_set_locking_callback( SSL_locking_function );
00075         CRYPTO_set_id_callback( SSL_id_function );
00076 
00077         char *randfile = getenv("RANDFILE");
00078         char *home = getenv("HOME");
00079         if (!randfile && !home)
00080         {
00081                 char *homepath = getenv("HOMEPATH");
00082                 if (homepath)
00083                 {
00084                         Utility::SetEnv("HOME", homepath);
00085                 }
00086         }
00087         char path[512];
00088         *path = 0;
00089         RAND_file_name(path, 512);
00090         if (*path)
00091         {
00092                 m_rand_file = path;
00093                 m_rand_size = 1024;
00094                 RAND_write_file(path);
00095         }
00096         else
00097         {
00098 DEB(            fprintf(stderr, "SSLInitializer: no random file generated\n");)
00099         }
00100 
00101         /* Load randomness */
00102         if (!m_rand_file.size() || !RAND_load_file(m_rand_file.c_str(), m_rand_size))
00103         {
00104 DEB(            fprintf(stderr, "SSLInitializer: PRNG not initialized\n");)
00105         }
00106 
00107 }

SSLInitializer::~SSLInitializer (  ) 

remove random file

Definition at line 110 of file SSLInitializer.cpp.

References DEB, and DeleteRandFile().

00111 {
00112 DEB(    fprintf(stderr, "~SSLInitializer()\n");)
00113         DeleteRandFile();
00114         // %! delete mutexes
00115 }


Member Function Documentation

void SSLInitializer::DeleteRandFile (  ) 

Definition at line 118 of file SSLInitializer.cpp.

References m_rand_file.

Referenced by ~SSLInitializer().

00119 {
00120         if (m_rand_file.size())
00121         {
00122                 unlink(m_rand_file.c_str());
00123         }
00124 }

void SSLInitializer::SSL_locking_function ( int  mode,
int  n,
const char *  file,
int  line 
) [static]

SSL; mutex locking function callback.

Definition at line 127 of file SSLInitializer.cpp.

References m_mmap, and m_mmap_mutex.

Referenced by SSLInitializer().

00128 {
00129         Mutex *mutex = NULL;
00130         {
00131                 Lock lock(m_mmap_mutex);
00132                 if (m_mmap.find(n) == m_mmap.end())
00133                 {
00134                         m_mmap[n] = new Mutex;
00135                 }
00136                 mutex = m_mmap[n];
00137         }
00138         if (mode & CRYPTO_LOCK)
00139         {
00140                 mutex -> Lock();
00141         }
00142         else
00143         {
00144                 mutex -> Unlock();
00145         }
00146 }

unsigned long SSLInitializer::SSL_id_function (  )  [static]

Return thread id.

Definition at line 149 of file SSLInitializer.cpp.

References Utility::ThreadID().

Referenced by SSLInitializer().

00150 {
00151         return Utility::ThreadID();
00152 }


Member Data Documentation

Definition at line 70 of file SSLInitializer.h.

Referenced by SSLInitializer().

std::string SSLInitializer::m_rand_file [private]

Definition at line 73 of file SSLInitializer.h.

Referenced by DeleteRandFile(), and SSLInitializer().

Definition at line 74 of file SSLInitializer.h.

Referenced by SSLInitializer().

std::map< int, Mutex * > SSLInitializer::m_mmap [static, private]

Definition at line 75 of file SSLInitializer.h.

Referenced by SSL_locking_function().

Definition at line 76 of file SSLInitializer.h.

Referenced by SSL_locking_function().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4