views:

33

answers:

2

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

A: 

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 );
Mark Wilkins
Excellent. The issue was with creating a new bio socket with BIO_s_accept(). I'll do some more digging as to why, but once I just made a standard BIO socket, accept seemed to work like a charm.
kelly.dunn
+1  A: 

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); 
caf
Awesome~ From reading the documentation, I would've never got that. Thanks!
kelly.dunn