I’m writing a simple application to connect to a server, using OpenSSL. The initial idea was to write a custom BIO method to get information on the hardware socket timestamp via linux’s SO_TIMESTAMPING, but in the meantime I realized that I’m missing something in how to build a proper BIO, so I restarted my understanding process from the scratch.
Most basic idea: let’s use a BIO to connect to the socket and a BIO to do the crypto stuff, in order to recreate the basic behaviour of SSL_write and SSL_read.
The code that is instantiating the BIO method and binding it to the SSL is the following:
BIO *sock_bio = BIO_new(BIO_s_socket());
BIO *ssl_bio = BIO_new(BIO_f_ssl());
BIO_push(default_sck_bio, default_ssl_bio);
SSL_set_bio(ssl, default_sck_bio, default_sck_bio);
In this way I expect that under the hood SSL_read is doing a BIO-based recv() and then the SSL encription, while for SSL_write a SSL encription and then the BIO-based send(). However, my SSL_connect keep producing a SSL_ERROR_SSL with the err message: error:10000078:BIO routines::uninitialized
. Am I missing something?
Once I solved this problem, my original intention was to write a custom BIO method, but then the next question pops up into my mind: How to call SSL encryption functions from inside the read/write BIO callbacks (that I set via BIO_meth_set_read
)?