SSL_accept () throws error "Invalid argument"

I am trying to create a client-server program, but I am having a hard time continuing, unfortunately, the meager amount of OpenSSL documentation.

My problem: SSL_acceptthrows an "Invalid argument" when executing the following code (simplified):

SSL* ssl = SSL_new(ctx); // ctx is created earlier
SSL_set_fd(ssl, socket); // socket is created earlier as well
BIO * bio = BIO_new(BIO_s_accept());
BIO_set_fd(bio, socket, BIO_NOCLOSE);
SSL_set_bio(ssl, bio, bio);
SSL_accept(ssl); 

I check for errors after every method call, and neither the socket nor the biography are getting worse. There is no indication that something strange is happening until I try to call SSL_accept. I assume the ssl object was corrupted somewhere along the way, but I have no clue as to how ~

Change . The SSL object and the BIO object are not null at the SSL_accept () call point.

It would be helpful to evaluate any pointers in the right direction: D

+3
source share
2 answers

Like you, it was difficult for me with a lack of documentation. Therefore, I can’t say whether the calls are incorrect or correct set_fd, but I received it without them. The sequence of calls that I have successfully used is:

BIO *sbio = BIO_new_socket( socket, BIO_NOCLOSE );
SSL* ssl = SSL_new(ctx); 
SSL_set_bio( ssl, sbio, sbio );
SSL_accept( ssl );
+1
source

SSL_set_fd()means a convenient alternative to manual BIO tuning. It automatically creates a BIO and installs it - so all you have to do is:

SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, socket);
SSL_accept(ssl); 
+2
source

Source: https://habr.com/ru/post/1763171/


All Articles