Hi All,
I am new to openssl and I am trying to achieve server client communication
using Openssl with BIO interfaces.
As per my understanding on the man page of BIO_do_accept(BIO *abio), first
call to it will set's up accept BIO and Second call to the same is a
blocking call and wait for incoming connections. In my server, i am being
blocked at first call to BIO_do_accept. What all scenarios will make my
call a blocking call?. Thanks for your help.
a part of my Openssl server:
if(BIO_do_accept(server) <= 0) /* place the underlying socket into
listening mode */
{
cout<<" Error setting up accept\n"<<std::endl;
}
while(1)
{
if(BIO_do_accept(server) <= 0) /* wait for a new connec;tion */
{
cout<<" Error in accepting(BIO) the client connections\n"<<std::endl;
}
sclient = BIO_pop(server);/* new_bio now behaves like a BIO_s_socket( )
BIO */
}
Please let me know if i miss something to give. Complete SSL Server code is
attached with the mail.
int sockfd, portno;
struct sockaddr_in serv_addr;
const SSL_METHOD *sslMethod;
SSL_CTX *sCtx;
BIO *server;
BIO *sclient;
SSL *ssl;
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
sslMethod = SSLv23_server_method();
sCtx = SSL_CTX_new(sslMethod);
const char *cert_file = "/home/fedora/cert.pem";
SSL_CTX_use_certificate_file(sCtx,cert_file,SSL_FILETYPE_PEM);
const char *key_file = "/home/fedora/key.pem";
SSL_CTX_use_PrivateKey_file(sCtx,key_file,SSL_FILETYPE_PEM);
SSL_CTX_check_private_key(sCtx);
sockfd = socket(AF_INET,SOCK_STREAM,0);
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(portno);
bind(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr);
listen(sockfd,NO_CLIENTS);
ssl = SSL_new(sCtx);
char* portnum=new char[sizeof(portno)];
snprintf(portnum,sizeof(portno)+1,"%d",portno);
BIO_set_bind_mode(server,BIO_BIND_REUSEADDR);
server = BIO_new_accept(portnum);
BIO_set_fd(server, sockfd, BIO_NOCLOSE);
if(BIO_do_accept(server) <= 0) /* place the underlying socket into listening mode */
{
cout<<" Error setting up accept\n"<<std::endl;
}
while(1)
{
if(BIO_do_accept(server) <= 0) /* wait for a new connec;tion */
{
cout<<" Error in accepting(BIO) the client connections\n"<<std::endl;
}
sclient = BIO_pop(server);/* new_bio now behaves like a BIO_s_socket( ) BIO */
BIO_free(sclient);
}
BIO_free(server);
--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users