2 * @file SSL_CallbackManager.h
4 * @author Martin Corino <mcorino@remedy.nl>
7 #ifndef ACE_SSL_CALLBACKMANAGER_H
8 #define ACE_SSL_CALLBACKMANAGER_H
10 #include /**/ "ace/pre.h"
12 #include "ace/SString.h"
13 #include "ace/Refcounted_Auto_Ptr.h"
14 #include "ace/SSL/SSL_Context.h"
15 #include "ace/INet/SSL_CertificateCallback.h"
16 #include "ace/INet/SSL_PasswordCallback.h"
17 #include "ace/INet/INet_SSL_Export.h"
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
25 // NOTE: Some compilers will issue warnings if the
26 // the correct type of function pointer (i.e. extern "C" ) is not stored/used
28 // Warning (Anachronism): Formal argument 1 of type
29 // extern "C" int(*)(int,x509_store_ctx_st*) in call to
30 // ACE_SSL_Context::default_verify_callback(extern "C" int(*)(int,x509_store_ctx_st*))
31 // is being passed int(*)(int,x509_store_ctx_st*).
33 // Warning (Anachronism): Formal argument cb of type
34 // extern "C" int(*)(char*,int,int,void*) in call to
35 // SSL_CTX_set_default_passwd_cb(ssl_ctx_st*, extern "C" int(*)(char*,int,int,void*))
36 // is being passed int(*)(char*,int,int,void*).
37 // when C library routines are passed CallBack functions pointers that are
38 // actually C++ functions. (Static class member functions are NOT extern "C" by default.)
40 // Unfortunatly you cannot specify extern "C" linkage anywhere inside a class
41 // declaration or inside a function prototype for individual parameters. We are therefore
42 // forced to declare friend functions external to the class to do this job (and of course
43 // the function names cannot be overloaded as they are C functions). They also cannot be
44 // static functions (or annominous namespace) to make them private to the cpp file as
45 // they need to be seen by the class declaration and therefore included in the header file
46 // and so must be global) thus:
48 int extern_C_verify_certificate_callback (int ok
, X509_STORE_CTX
* cert_ctx
);
49 int extern_C_passwd_callback (char* buf
, int size
, int rwflag
, void* user_data
);
53 * @class ACE_INet_SSL_CallbackManager
55 * @brief Implements manager class for configuring and handling
59 class ACE_INET_SSL_Export SSL_CallbackManager
62 SSL_CallbackManager ();
63 ~SSL_CallbackManager ();
65 void initialize_callbacks (ACE_SSL_Context
* ssl_ctx
= ACE_SSL_Context::instance ());
67 const ACE_SSL_Context
* context () const;
69 void set_certificate_callback (ACE::INet::SSL_CertificateCallback
* cb
);
70 void set_password_callback (ACE::INet::SSL_PasswordCallback
* cb
);
72 static SSL_CallbackManager
* instance ();
75 int verify_certificate_callback (SSL_CertificateCallbackArg
& arg
);
76 void passwd_callback (ACE_CString
& pwd
);
78 ACE_SSL_Context
* ssl_ctx_
;
80 typedef ACE_Refcounted_Auto_Ptr
<ACE::INet::SSL_CertificateCallback
,
81 ACE_SYNCH::MUTEX
> TCertificateCallback
;
82 typedef ACE_Refcounted_Auto_Ptr
<ACE::INet::SSL_PasswordCallback
,
83 ACE_SYNCH::MUTEX
> TPasswordCallback
;
85 TCertificateCallback cert_callback_
;
86 TPasswordCallback passwd_callback_
;
88 friend int extern_C_verify_certificate_callback (int ok
, X509_STORE_CTX
* cert_ctx
);
89 friend int extern_C_passwd_callback (char* buf
, int size
, int rwflag
, void* user_data
);
91 static int ssl_ctx_mngr_index_
;
96 ACE_END_VERSIONED_NAMESPACE_DECL
98 #if defined (__ACE_INLINE__)
99 #include "ace/INet/SSL_CallbackManager.inl"
102 #include /**/ "ace/post.h"
103 #endif /* ACE_SSL_CALLBACKMANAGER_H */