Click here to Skip to main content
15,507,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, actually i have done the attachment of socket fd with normal openssl code. but due to need of encryption has to introduce bio in my code but i do not know how to introduce it. and then why am using TCP socket fd in ssl means have to use select function but with BIO how to attach the FD?... that was My question....?

SSL_CTX *ctx;
long server = -1;
SSL *ssl;

SSL_METHOD *method;
OpenSSL_add_all_algorithms(); /* Load cryptos, */
SSL_load_error_strings(); /* Bring in and register error messages */
method = SSLv3_client_method(); /* Create new client-method instance */
ctx = SSL_CTX_new(method); /* Create new context */

if(ctx == NULL)
g_Logger.log(LOG_LEVEL_WARNING, "%s <ln:%d> Failed to Create a Context using SSL_METHOD", __FUNCTION__, __LINE__);
return false;

if(false == LoadCertificates(ctx, (char *)p_Certfile, (char *)p_KeyFile))
g_Logger.log(LOG_LEVEL_WARNING, "%s <ln:%d> Failed at Loading Certificate in SSL Function", __FUNCTION__, __LINE__);
return false;

if(-1 == (server = OpenConnection(p_IpAdd, p_Port)))//normal tcp socket initialization function return the socket file descriptor
g_Logger.log(LOG_LEVEL_WARNING, "%s <ln:%d> Socket Connection establishment is failed", __FUNCTION__, __LINE__);
return false;

ssl = SSL_new(ctx); /* create new SSL connection state */
SSL_set_fd(ssl, server); /* attach the socket descriptor */

if ( SSL_connect(ssl) != 1 ) /* perform the connection */
g_Logger.log(LOG_LEVEL_WARNING, "%s <ln:%d> SSL Connection establishment is failed", __FUNCTION__, __LINE__);
close(server); /* close socket */
SSL_CTX_free(ctx); /* release context */
return false;
//write and read operation perform it.


What I have tried:

Hi have tried the openssl code without the BIO
Updated 19-Apr-22 6:19am

1 solution

You can use SSL_get_rbio() and SSL_get_wbio() to get the read and write BIOS associated with an SSL connection. Alternatively instead of using SSL_connect(), you can use SSL_accept() which returns a BIO suitable for reading and writing.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900