Hi,
Thanks . I would do what you have suggested if I cannot find a way out.
But your suggestion doesnt actually solve my problem.
I want to use the SSL_CTX_set_tmp_rsa/dh_cb(.....,cb) so that i can decide on
what length key to use depending
on the cipher used.

So firstly i pre-generate 2 pairs of keys for RSA and DH, one of 512 bits and
the other 1024 bits.

I then store these  in the SSL_CTX using SSL_CTX_set_app_data(....).

In my callback I retrieve them from the SSL_CTX in the following way

RSA * CSetupCallbacks::SSLCallbackTmpRSA(SSL *pSSL, int isExport, int
nKeyLen)
{
    RSA *pRsa;
    pRsa = NULL;
    CCallbackData * pCbData = reinterpret_cast<CCallbackData
*>(SSL_CTX_get_app_data(pSSL->ctx));
     if (!isExport) {
          if (nKeyLen == 512)
               pRsa = pCbData->m_p512BitRSAKey;
          else
                pRsa = pCbData->m_p1024BitRSAKey;
     }
     else {
          pRsa = pCbData->m_p512BitRSAKey;
     }
    return pRsa;
}

/*
 * Handle out the already generated DH parameters...
 */


DH * CSetupCallbacks::SSLCallbackTmpDH(SSL *pSSL, int isExport, int nKeyLen)
{
    DH *pDh;
    pDh = NULL;
     CCallbackData * pCbData = reinterpret_cast<CCallbackData
*>(SSL_CTX_get_app_data(pSSL->ctx));
        if (!isExport) {

            if(nKeyLen == 512)
               pDh = pCbData->m_p512BitDHKey;
          else
               pDh = pCbData->m_p1024BitDHKey;

        }
        else {

            pDh = pCbData->m_p512BitDHKey;
        }
     return pDh;
}

Now these keys are returned so send_server_key_exchange to be used in the key
exchange.
Assuming all is well when i cleanup SSL_CTX structure I do the following

 if (m_pSSLCTX)
 {
  delete reinterpret_cast<CCallbackData *>(SSL_CTX_get_app_data(m_pSSLCTX)) ;


  SSL_CTX_free(m_pSSLCTX);
  m_pSSLCTX = NULL;
 }

........................
......................
CCallbackData : : ~CCallbackData()
{
    if(m_pCRLStore != NULL)
      X509_STORE_free(m_pCRLStore);

     if(m_p512BitRSAKey != NULL)
      RSA_free(m_p512BitRSAKey);

     if(m_p1024BitRSAKey != NULL)
      RSA_free(m_p1024BitRSAKey);

     if(m_p512BitDHKey != NULL)
      DH_free(m_p512BitDHKey);

     if(m_p1024BitDHKey != NULL)
      DH_free(m_p1024BitDHKey);
}

then my application terminates with some DH key leaks though i seem to have
cleaned it up all
(The cipher causes a DH key exchange in my test case).
This is my problem and even after looking into the SSL code i'm more confused
than ever
Is there a clean way out?

One more thing!! How does SSL_OP_SINGLE_DH_USE work with all this??

Thanks,
Amit.


Bodo Moeller wrote:

> On Tue, Apr 11, 2000 at 05:10:12PM +0530, Amit Chopra wrote:
>
> >    I found that when my application terminates the temporary keys
> > generated leak.
>
> Directly after SSL_[CTX_]_set_tmp_{rsa,dh}, you may call {RSA,DH}_free
> for the key given in the parameter.  This is because the reference
> account is increased for RSA keys, and DH parameters are copied.
>
> >    So to clean it up I am storing some information like the temp DH key
> > generated during the handshake in the SSL ex_data structure [...]
>
> Doing this is unnecessarily complicated, see above.
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> Development Mailing List                       [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to