kelly.dunn
kelly.dunn

Reputation: 1546

SSL_accept() throws "Invalid argument" error

I'm attempting to create a client/server program, but I'm finding some difficulty continuing with the unfortunately sparse amount of OpenSSL documentation.

My issue: SSL_accept throws an "Invalid Argument" upon 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 errors after each method call, and the neither the socket nor the bio goes bad. There's no indication that anything odd is happening until I attempt calling SSL_accept. I assume that the ssl object was corrupted somewhere along the way, but I don't have a clue as to how~

Edit The SSL object and the BIO object are not null at the point of calling SSL_accept().

Any pointers in the right direction would be greatly appreciated :D

Upvotes: 3

Views: 1536

Answers (2)

caf
caf

Reputation: 239341

SSL_set_fd() is meant as a convenient alternative to manually setting up the BIOs. It automatically creates a BIO and sets it up - so all you need to do is:

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

Upvotes: 2

Mark Wilkins
Mark Wilkins

Reputation: 41262

Like you, I have had a difficult time with the dearth of documentation. So I can't say whether or not the set_fd calls are wrong or right, but I got it working without those. The sequence of calls that I have used successfully is:

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

Upvotes: 1

Related Questions