chriskohlhoff/asio — pull request #2 by nickfajones (2011-12-14 03:37:35+00:00)
Title: A number of extra features/changes for ASIO

I want to contribute a number of changes to ASIO that I have made for use in our products at Network Box.

The changes come under three categories. Each of the categories does require some work,
so they couldn't be included in ASIO straight away without further discussion and refinement.

The changes are:
1) New interfaces for loading SSL certificates:
e08db1f05d5e19b5e10d87235247e46b593300c4

Interfaces to load CAs, Certificates and Private Keys stored in the form of std::string.
Useful for cases where these objects have been loaded from a database.

Additional interfaces therefore no ABI breakage.

90% complete, as the interface for loading CAs in ASN1 format hasn't been defined.
Loading Certs and PKs supports both PEM and ASN1 which is consistent with other
ASIO interfaces available.

2) Using already buffered data to feed an SSL handshake
56ec4891d4e9ee530d990adeca3c263b7a58778b
09db9f10f606b86e39869547f48cd9c157ed944a

Our planned use for this is cases where data is read from a socket, then subsequently identified as being
a SSL handshake header. Caller may then re-use the already read data in a handshake.
New function overload for async_handshake, so should be no ABI breakage.

This change is theory only at this stage, so is more of a request for comments. It works by using the
user provided buffer object as the initial value of the SSL layer input_ buffer, so the read routines find
this data before they try reading from the wire. As stated, not tested fully, and as I am writing this pull
request, I realise there is no corresponding non-async interface. I will submit that soon.

3) Altered logic on SSL shutdown
d966bf238727f10fa9853b3959913becb8b1696c

Provide a distinct error value for ssl shutdown in the form of a new error_code: ssl_eof. On receipt of
this, the user can then initiate a shutdown in their own chosen method: async or non-async.
I seem to recall that in the current logic, the code path leads to an implicit call to SSL_shutdown,
which is out of control of the user.

This change is not backwards compatible and a brand new error_code value is being returned, so
using this interface will require proper support in code, as only exists in my company software.
But seeing as there is a problem with the logic in regard to ssl shutdown, any fix to this area may
require a new version release of ASIO with sufficient documentation to explain the new behaviour.
But with this fix, I am able to produce a pleasing, although probably redundant test example:
A client and server connect with TCP and can exchange data in plaintext.
Either side may initiate a secure connection by writing 'starttls\n' on a new line.
Either side may stop a secure connection by writing 'stoptls\n' on a new line, and continue talking
on the same connection in plaintext.
This may be repeated on the same connection at will.

Thanks for taking the time to consider these submissions.