Logo
~Sockets~
~Examples~
~Contact~


SSLInitializer Class Reference

#include <SSLInitializer.h>

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

Detailed Description

Definition at line 37 of file SSLInitializer.h.


Constructor & Destructor Documentation

SSLInitializer::SSLInitializer (  ) 

init openssl bio_err create random file

Definition at line 47 of file SSLInitializer.cpp.

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

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

SSLInitializer::~SSLInitializer (  ) 

remove random file

Definition at line 97 of file SSLInitializer.cpp.

References DEB, and DeleteRandFile().

00098 {
00099 DEB(    fprintf(stderr, "~SSLInitializer()\n");)
00100         DeleteRandFile();
00101         // %! delete mutexes
00102 }


Member Function Documentation

void SSLInitializer::DeleteRandFile (  ) 

Definition at line 105 of file SSLInitializer.cpp.

References m_rand_file.

Referenced by ~SSLInitializer().

00106 {
00107         if (m_rand_file.size())
00108         {
00109                 unlink(m_rand_file.c_str());
00110         }
00111 }

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

SSL; mutex locking function callback.

Definition at line 114 of file SSLInitializer.cpp.

Referenced by SSLInitializer().

00115 {
00116 static  std::map<int, Mutex *> mmap;
00117         if (mmap.find(n) == mmap.end())
00118         {
00119                 mmap[n] = new Mutex;
00120         }
00121         if (mode & CRYPTO_LOCK)
00122         {
00123                 mmap[n] -> Lock();
00124         }
00125         else
00126         {
00127                 mmap[n] -> Unlock();
00128         }
00129 }

unsigned long SSLInitializer::SSL_id_function (  )  [static]

Return thread id.

Definition at line 132 of file SSLInitializer.cpp.

References Utility::ThreadID().

Referenced by SSLInitializer().

00133 {
00134         return Utility::ThreadID();
00135 }


Member Data Documentation

Definition at line 60 of file SSLInitializer.h.

Referenced by SSLInitializer().

std::string SSLInitializer::m_rand_file [private]

Definition at line 63 of file SSLInitializer.h.

Referenced by DeleteRandFile(), and SSLInitializer().

Definition at line 64 of file SSLInitializer.h.

Referenced by SSLInitializer().


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