Fixed client certificate treatment. #983
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first problem is the callback function that is set by set_verify_callback() is not called the first accept. But the second accept and later one is called.
I analyzed the problem.
server.hpp calls ctx_.set_verify_callback() int do_accept(). ctx_ is moved from user at the constructor.
Then it is passed to socket_t parameter (actual type is ssl::stream). The type of parameter is
ssl::context&
but it behaves as copy in the constructor. So ctx_ configuration must be finished before socket_t is created.I updated the order.
Then the first problem is solved.
However, the second problem is appared.
The username that is set by the callback is wrong. This is caused by ctx_.set_verify_callback() overwriting.
The second do_accept() is called when the first TCP async_accept (lowest_layer) is finished. It is too early. Because in the do_accept(), ctx_.set_verify_callback() is called with the new username memory. Then the callback is called. The expected behavior is the callback is the first one, but the second one is called. To solve this problem, I moved the next do_accept() call to after the all handshake sequences are finished. It would cause degrade connecting performance but so far, there is no way.
Ideally, create the new ctx for each accept, but it requires a big breaking change. So I don't do that.
NOTE: async_mqtt solves the problem using this way https://github.com/redboltz/async_mqtt/blob/04748f1311f3dff6c2d418f1ac9d39b64f4da0a0/tool/broker.cpp#L322