Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed client certificate treatment. #983

Merged
merged 1 commit into from
Jul 7, 2023
Merged

Fixed client certificate treatment. #983

merged 1 commit into from
Jul 7, 2023

Conversation

redboltz
Copy link
Owner

@redboltz redboltz commented Jul 7, 2023

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

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
@redboltz
Copy link
Owner Author

redboltz commented Jul 7, 2023

This PR also contains #982 revert.

@codecov
Copy link

codecov bot commented Jul 7, 2023

Codecov Report

Merging #983 (e38fc28) into master (35a14f7) will decrease coverage by 20.89%.
The diff coverage is 68.75%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #983       +/-   ##
===========================================
- Coverage   83.92%   63.04%   -20.89%     
===========================================
  Files          65       63        -2     
  Lines       10750     9416     -1334     
===========================================
- Hits         9022     5936     -3086     
- Misses       1728     3480     +1752     

@redboltz redboltz merged commit 8e9c8f9 into master Jul 7, 2023
23 of 25 checks passed
@redboltz redboltz deleted the fix_client_cert_3 branch July 7, 2023 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant