Thanks for the response.
I have defined the three functions in the following manner. Pls let me
know if i am missing ne thing
HANDLE * SSLMultiThread::m_lock_cs = NULL;
/*************Thread_Setup***********************/
void SSLMultiThread::thread_setup ()
{
LOG_FOR_DEBUG (_T("In SSL thread_setup for creating mutex."));
SSLMultiThread::m_lock_cs = (HANDLE *) OPENSSL_malloc
(CRYPTO_num_locks() * sizeof(HANDLE));
for (int index = 0; index < CRYPTO_num_locks(); index++)
{
SSLMultiThread::m_lock_cs[index] = ::CreateMutex (NULL, FALSE,
NULL);
LOG_CRITICAL_FAILURE_HR_IF_FALSE ((NULL !=
SSLMultiThread::m_lock_cs[index]), HRESULT_FROM_WIN32
(::GetLastError()));
}
// CRYPTO_set_locking_callback ((void (*)(int, int, const char *,
int)) bv_locking_callback);
CRYPTO_set_locking_callback (bv_locking_callback);
}
/*************Thread_Cleanup***********************/
void SSLMultiThread::thread_cleanup ()
{
LOG_FOR_DEBUG (_T("In SSL thread_cleanup for freeing mutex."));
CRYPTO_set_locking_callback (NULL);
for (int index = 0; index < CRYPTO_num_locks(); index++)
{
if (NULL != SSLMultiThread::m_lock_cs[index])
{
BOOL bRet = ::CloseHandle
(SSLMultiThread::m_lock_cs[index]);
LOG_CRITICAL_FAILURE_HR_IF_FALSE (bRet,
HRESULT_FROM_WIN32
(::GetLastError()));
}
}
OPENSSL_free(SSLMultiThread::m_lock_cs);
}
/*************Locking_Callback***********************/
extern "C" void bv_locking_callback (int mode, int type, const char
*file, int line)
{
if (mode & CRYPTO_LOCK)
{
// LOG_FOR_DEBUG (_T("In SSL callback function waiting for
mutex."));
unsigned long ulWaitTime = 3*60*1000; // 3 minutes
unsigned long ulWaitResult = ::WaitForSingleObject
(SSLMultiThread::m_lock_cs[type], ulWaitTime);
if (WAIT_OBJECT_0 != ulWaitResult)
LOG_CRITICAL_FAILURE_HR_IF_FAILED (HRESULT_FROM_WIN32
(::GetLastError()));
}
else
{
// LOG_FOR_DEBUG (_T("In SSL callback function for releasing
mutex."));
BOOL bRet = ::ReleaseMutex (SSLMultiThread::m_lock_cs[type]);
LOG_CRITICAL_FAILURE_HR_IF_FALSE (bRet, HRESULT_FROM_WIN32
(::GetLastError()));
}
}
/*******************************************************************************/
On 4/20/05, Daniel Witt <[EMAIL PROTECTED]> wrote:
> Are you defining the OpenSSL threading call backs? This seems to be the most
> common problem with using OpenSSL in multithreaded applications.
> see: http://www.openssl.org/docs/crypto/threads.html
>
> Also, I believe that this really is an issue for the users list but am not
> 100% sure on that.
>
> -----Original Message-----
> From: [EMAIL PROTECTED] on behalf of Sumit Jain
> Sent: Tue 4/19/2005 2:25 AM
> To: [email protected]
> Subject: Issuse with SSL_connect in Multi-threaded mode
>
> Hi All,
>
> I am facing some problem while using SSL_connect. I have posted this
> on user group also but no one has a clue. I think developers can help
> me on this.
>
> Problem:
>
> I'm using openssl in a mutithreaded application. OpenSSL is used to
> connect Unix box from Windows box to fetch some information. While
> calling SSL_Connect() from windows, i get a return value as -1. For
> this SSL_get_error() returns error code as 1, while ERR_get_error()
> returns Error code 336142597.
>
> On the Unix Box side I'm getting error as "sslv3 alert illegal
> parameter" and due to this handshake failed while calling
> tls::handshake
>
> $<channel identifier>
> And I'm not able to connect to the Unix Box.
>
> Detail Description:
>
> I can configure to run my application either in single threaded or
> multithreaded mode.
>
> 1. When I run the application in single thread, I never face this
> problem, everything works fine.
>
> 2. When I run the application in a multithreaded mode, and on a given
> thread a single connection is opened to the Unix box, then also
> everything works fine.
>
> 3. But when i run the application in a multithreaded mode and on a
> given thread a connection is opened/closed more than once
> (twice/thrice) to the Unix box, SSL connect fails intermittently. This
> behavior is very inconsistent. However, once such failure occurs,
> every subsequent connect fails with the same error, unless I shutdown
> the windows process and restart the windows application.
>
> Here when i say its multithreaded means on each thread I'm trying to
> connect to different Unix Box, and I'm using named mutex, i.e. it will
> never be the case of having simultaneous access to same Unix Box. And
> here each time i'm opening and closing connection to the Unix Box.I'm
> caching nothing apart from SSL_CTX * sm_pSSLContext.
>
> Even if it's not cached, the failure still occurs
>
> tls::handshake method mention above is in the tls library(wrapper on
> openssl), used in the Unix code base.We use tls1.3 and tls1.4.
>
> tls1.3 is used on most of the flavors whereas 1.4 is use on AIX .
>
> Is there anything I'm missing while making SSL connection multiple
> times on a worker thread in a multi-threaded environment?
>
> Thanks,
> Sumit
> ______________________________________________________________________
> OpenSSL Project http://www.openssl.org
> Development Mailing List [email protected]
> Automated List Manager [EMAIL PROTECTED]
>
>
>
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]