mardi 21 mars 2023

Openssl 3.0 problem with existing BIO communication

Earlier below code was working in openssl 1.0.2 on Windows:-

BIO_METHOD bio;    
memcpy(&bio, BIO_s_socket(), sizeof(BIO_METHOD));
bio.bwrite = SslBioWrite;
bio.bread = SslBioRead;
BIO *wbio = BIO_new(bio);
BIO_set_app_data(wbio, this);
BIO_set_fd(wbio, (int)_socket, BIO_NOCLOSE); //_socket is an already connected TCP socket
SSL_set_bio(_ssl, wbio, wbio); //_ssl is already setup ssl with ssl context
SSL_connect(_ssl); //==>> this works and gets connected

But in openssl 3.0, as BIO_METHOD structure has become opaque and BIO_s_socket() returns const BIO_METHOD pointer, above approach can't work. I tried below approach...

I tried below with openssl 3.0.8:-

const BIO_METHOD *bio = BIO_s_socket();
BIO_METHOD *tbio = BIO_meth_new(BIO_TYPE_SOCKET, "sslsocket");
assert(tbio);
assert(BIO_meth_set_write(tbio, SslBioWrite) == 1);
assert(BIO_meth_set_read(tbio, SslBioRead) == 1);
assert(BIO_meth_set_create(tbio, BIO_meth_get_create(biom)) == 1);
assert(BIO_meth_set_destroy(tbio, BIO_meth_get_destroy(biom)) == 1);
assert(BIO_meth_set_callback_ctrl(tbio, BIO_meth_get_callback_ctrl(biom)) == 1);
BIO *wbio = BIO_new(tbio);
BIO_set_app_data(wbio, this);
BIO_set_fd(wbio, (int)_socket, BIO_NOCLOSE); //_socket is an already connected TCP socket
SSL_set_bio(_ssl, wbio, wbio); //_ssl is already setup ssl with ssl context
SSL_connect(_ssl); ==>> this fails with error SSL_ERROR_SSL

Aucun commentaire:

Enregistrer un commentaire