Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

ACE::INet::SSL_CallbackManager Class Reference

#include <SSL_CallbackManager.h>

Collaboration diagram for ACE::INet::SSL_CallbackManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SSL_CallbackManager ()
 ~SSL_CallbackManager ()
void initialize_callbacks (ACE_SSL_Context *ssl_ctx=ACE_SSL_Context::instance())
const ACE_SSL_Contextcontext () const
void set_certificate_callback (ACE::INet::SSL_CertificateCallback *cb)
void set_password_callback (ACE::INet::SSL_PasswordCallback *cb)

Static Public Member Functions

static SSL_CallbackManagerinstance ()

Private Types

typedef
ACE_Refcounted_Auto_Ptr
< ACE::INet::SSL_CertificateCallback,
ACE_SYNCH::MUTEX > 
TCertificateCallback
typedef
ACE_Refcounted_Auto_Ptr
< ACE::INet::SSL_PasswordCallback,
ACE_SYNCH::MUTEX > 
TPasswordCallback

Private Member Functions

int verify_certificate_callback (SSL_CertificateCallbackArg &arg)
void passwd_callback (ACE_CString &pwd)

Static Private Member Functions

static int verify_certificate_callback (int ok, X509_STORE_CTX *cert_ctx)
static int passwd_callback (char *buf, int size, int rwflag, void *user_data)

Private Attributes

ACE_SSL_Contextssl_ctx_
TCertificateCallback cert_callback_
TPasswordCallback passwd_callback_

Static Private Attributes

static int ssl_ctx_mngr_index_ = (-2)

Detailed Description

Definition at line 24 of file SSL_CallbackManager.h.


Member Typedef Documentation

Definition at line 46 of file SSL_CallbackManager.h.

Definition at line 48 of file SSL_CallbackManager.h.


Constructor & Destructor Documentation

ACE::INet::SSL_CallbackManager::SSL_CallbackManager (  ) 

Definition at line 24 of file SSL_CallbackManager.cpp.

      {
      }

ACE::INet::SSL_CallbackManager::~SSL_CallbackManager (  ) 

Definition at line 28 of file SSL_CallbackManager.cpp.

      {
      }


Member Function Documentation

const ACE_SSL_Context * ACE::INet::SSL_CallbackManager::context ( void   )  const [inline]

Definition at line 13 of file SSL_CallbackManager.inl.

      {
        return this->ssl_ctx_;
      }

void ACE::INet::SSL_CallbackManager::initialize_callbacks ( ACE_SSL_Context ssl_ctx = ACE_SSL_Context::instance ()  ) 

Definition at line 32 of file SSL_CallbackManager.cpp.

      {
        if (ssl_ctx_mngr_index_ < -1)
          {
            ssl_ctx_mngr_index_ = ::SSL_CTX_get_ex_new_index (0, 0, 0,0,0);
            if (ssl_ctx_mngr_index_ < 0)
              {
                INET_ERROR (1, (LM_ERROR, DLINFO
                                ACE_TEXT ("SSL_CallbackManager::initialize_callbacks - ")
                                ACE_TEXT ("failed to allocate SSL_CTX ex_data index.\n")));
                return;
              }
          }

        this->ssl_ctx_ = ssl_ctx == 0 ? ACE_SSL_Context::instance () : ssl_ctx;
        ::SSL_CTX_set_ex_data (this->ssl_ctx_->context (), ssl_ctx_mngr_index_, this);
        this->ssl_ctx_->default_verify_callback (verify_certificate_callback);
        ::SSL_CTX_set_default_passwd_cb (ssl_ctx->context(), passwd_callback);
        ::SSL_CTX_set_default_passwd_cb_userdata (ssl_ctx->context(), this);
      }

SSL_CallbackManager * ACE::INet::SSL_CallbackManager::instance ( void   )  [static]
int ACE::INet::SSL_CallbackManager::passwd_callback ( char *  buf,
int  size,
int  rwflag,
void *  user_data 
) [static, private]

Definition at line 97 of file SSL_CallbackManager.cpp.

      {
        if (user_data == 0)
          return 0;

        SSL_CallbackManager* cbmngr = reinterpret_cast<SSL_CallbackManager*> (user_data);

        ACE_CString pwd;
        cbmngr->passwd_callback (pwd);
        if (!pwd.empty ())
          {
            ACE_OS::strncpy (buf, pwd.c_str (), size);
            buf[size - 1] = '\0';
            if (size > ACE_Utils::truncate_cast<int> (pwd.length ()))
              size = ACE_Utils::truncate_cast<int> (pwd.length ());

            return size;
          }
        else
          return 0;
      }

void ACE::INet::SSL_CallbackManager::passwd_callback ( ACE_CString pwd  )  [private]

Definition at line 68 of file SSL_CallbackManager.cpp.

      {
        TPasswordCallback pw_cb = passwd_callback_;
        if (pw_cb)
          {
            pw_cb->get_privatekey_password (pwd);
          }
      }

void ACE::INet::SSL_CallbackManager::set_certificate_callback ( ACE::INet::SSL_CertificateCallback cb  )  [inline]

Definition at line 19 of file SSL_CallbackManager.inl.

      {
        this->cert_callback_.reset (cb);
      }

void ACE::INet::SSL_CallbackManager::set_password_callback ( ACE::INet::SSL_PasswordCallback cb  )  [inline]

Definition at line 25 of file SSL_CallbackManager.inl.

      {
        this->passwd_callback_.reset (cb);
      }

int ACE::INet::SSL_CallbackManager::verify_certificate_callback ( SSL_CertificateCallbackArg arg  )  [private]

Definition at line 58 of file SSL_CallbackManager.cpp.

      {
        TCertificateCallback cert_cb = this->cert_callback_;
        if (cert_cb)
          {
            cert_cb->handle_certificate_failure (arg);
          }
        return (arg.ignore_error () ? 1 : 0);
      }

int ACE::INet::SSL_CallbackManager::verify_certificate_callback ( int  ok,
X509_STORE_CTX *  cert_ctx 
) [static, private]

Definition at line 77 of file SSL_CallbackManager.cpp.

      {
        if (!ok && ssl_ctx_mngr_index_>=0)
        {
          // Retrieve the pointer to the SSL of the connection currently treated
          void* ex_data = ::X509_STORE_CTX_get_ex_data (cert_ctx, ::SSL_get_ex_data_X509_STORE_CTX_idx());
          ::SSL* ssl = reinterpret_cast< ::SSL* > (ex_data);
          // Retrieve SSL_CTX pointer of the connection currently treated
          ::SSL_CTX* ssl_ctx = ::SSL_get_SSL_CTX (ssl);
          // Retrieve our SSL_CallbackManager
          ex_data = ::SSL_CTX_get_ex_data (ssl_ctx, ssl_ctx_mngr_index_);
          SSL_CallbackManager* cbmngr = reinterpret_cast<SSL_CallbackManager*> (ex_data);

          SSL_CertificateCallbackArg arg (cbmngr->context(), cert_ctx);
          ok = cbmngr->verify_certificate_callback (arg);
        }

        return ok;
      }


Member Data Documentation

Definition at line 50 of file SSL_CallbackManager.h.

Definition at line 51 of file SSL_CallbackManager.h.

Definition at line 43 of file SSL_CallbackManager.h.

Definition at line 56 of file SSL_CallbackManager.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines