I am trying to use OpenSSL in my application, and achieve a secure connection.
At first I tried:
- create ssl struct
- create socketbio for the tcp socket
- create a sslbio
- set socketbio to SSL strcut
SSL_accept(ssl)BIO_push(ssl, socketbio)
This cause handshake to happen successfully, but application data wasn’t properly decrypted.
Then I tweaked a little, and relaced 6 with
(new) BIO_ctrl(sslbio, SET_SSL, ssl)
and things worked fine.
I Wanted to know, what’s wrong with previous approach, and what’s causing the new apprach work?
It’s hard to answer the question without knowing why you think
BIO_pushis all you need to do. At any rate, you shouldn’t callBIO_ctrldirectly. You should use the high-level wrapperBIO_set_ssldefined inbio.h:This macro sets the ssl member of the BIO object as you can see in
bio_ssl.c:The important step in this function is not the
BIO_push, but rather is where it sets the ssl pointer in theBIO_SSLobject to your active SSL context, i.e.,((BIO_SSL *)b->ptr)->ssl=ssl;.