I have a TCP networking library which implements a bunch of protocol (redis, http etc), and they are implemented using BSD sockets.
A lot of the code uses select() and other functions that are meant for BSD sockets. Am I right in assuming that this won't work on the SSL sockets? Or will they work as is?
I'm just wondering if SSL and BSD sockets are so different that they require a completely different approach to implementation.
Secure Sockets Layer (SSL) is the most widely used protocol for implementing cryptography on the Web. SSL uses a combination of cryptographic processes to provide secure communication over a network.
BSD Socket. The BSD sockets application programming interface (API) is a set of standard function calls that can be used in an application. They allow programmers to add Internet communication to their products. A client/server architecture is mandatory for BSD sockets.
Assuming you are referring to OpenSSL, it sits on top of the socket, it does not replace it. So all direct-socket operations, like select()
, still work. The difference, however, is that OpenSSL handles reading and writing for you so you would replace recv()
with ssl_read()
and send()
with ssl_write()
, but you can (and in some cases need to) still use select()
directly. However, you can't just call it whenever you want, you have to wait until OpenSSL tells you to call it. So, for example, if you have a reading loop that calls select()
first and then calls recv()
only when select()
reports readability, you would have to swap that logic around. Call ssl_read()
first, and then call select
() only if ssl_read()
returns either SSL_ERROR_WANT_READ
or SSL_ERROR_WANT_WRITE
(note that ssl_read()
can perform writing operations internally, and ssl_write()
can perform reading operations internally).
One thing that comes to mind is that you should not do a select on the fd via which the ssl connection runs. That is because it might for example say you can read from it while the ssl_read will block. That is then caused for example by SSL doing a key renegotiating and not application data to become available. That's one of the pitfals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With