Hello everyone,

I am new to openssl and I am currently trying to write a small wrapper for
this library that will allow it to be used with wxWidgets. wxWidgets is a
cross-platform GUI library that offers network facilities. My goal is to
enrich the wxSocketClient implementation with ssl capabilities.

So, in order to use the existing wxSocketClient for I/O operations, I
decided to write my own BIO. I then implemented a function
wxSSLSocketClient::InitiateSSLSession that is supposed to negociate a SSL
connection, as well as a wxSSLSocketClient::TerminateSSLSession function
that is supposed to terminate this SSL connection.

My problem arises when trying to establish the SSL connection. I execute
the following code : 

   /* Configure ssl context */
   ctx = ssl_lib.SSL_CTX_new(ssl_lib.SSLv23_client_method());
   //ssl_lib.SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,SSL_OP_ALL,NULL);

   /* Create SSL connection */
   ssl = ssl_lib.SSL_new(ctx);
   if (ssl != NULL)
   {
      /* Configure cypher algorithms supported */
      ssl_lib.SSL_set_cipher_list(ssl, "ALL");

      bio = ssl_lib.BIO_new(SslBio::GetBio());
      bio->ptr = this;
      ssl_lib.SSL_set_bio(ssl,bio,bio);

      ssl_lib.SSL_set_connect_state(ssl);

      int ret = ssl_lib.SSL_connect(ssl);
      if (ret <= 0)
      {
         ... error ....
      }
      ...

The problem arises when invoking the SSL_connect. When invoking this
command, the write command of my BIO is invoked and, after, the SSL_connect
function returns with code -1. A call to SSL_get_error returns the error 1,
and by invoking the 'ERR_get_error' and 'ERR_error_string', I can retrieve
the following text error message : 

Error 336351298 : error:140C5042:SSL
routines:SSL_UNDEFINED_FUNCTION:called a function you should not call

I am not sure my BIO implementation is related to this problem, but in
case of, here is the code of the relevant functions called before the crash
: 

BIO_METHOD* wxSSLSocketClient::SslBio::GetBio()
{
   static BIO_METHOD methods =
   {
      BIO_TYPE_SOCKET,
      "wxEmail Socket",
      Write,
      Read,
      Puts,
      Gets,
      Ctrl,
      Create,
      Destroy,
      NULL,
   };
   return &methods;
}
...
int wxSSLSocketClient::SslBio::Write(BIO* bio, const char* buffer, int
nbytes)
{
   wxLogDebug("Will write...");
   wxSSLSocketClient* ptr = (wxSSLSocketClient*)bio->ptr;
   ptr->Write(buffer, nbytes);
   if (ptr->Error())
   {
      return -1;
   }
   else
   {
      return ptr->LastCount();
   }
}
...
int wxSSLSocketClient::SslBio::Create(BIO* bio)
{
   bio->init=1;
   bio->num=-1;
   bio->ptr=NULL;
   bio->flags=0;
   return 1;
}


One last information that can maybe be useful : I am using the bio->ptr
field to store internal stuff necessary for my implementation. So, this
field is overriden after BIO initialisation.

Any help would be highly appreciated.

Thanks in advance,

Brice André


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to