Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(security): client_negotiation handle mechanism selected response #612

Merged
merged 22 commits into from
Sep 4, 2020

Conversation

levy5307
Copy link
Contributor

@levy5307 levy5307 commented Sep 2, 2020

client_negotiation handle mechanism selected response

@levy5307 levy5307 marked this pull request as draft September 2, 2020 10:09
@levy5307 levy5307 marked this pull request as ready for review September 3, 2020 08:17
include/dsn/utility/error_code.h Outdated Show resolved Hide resolved
src/runtime/security/sasl_client_wrapper.cpp Outdated Show resolved Hide resolved
include/dsn/utility/error_code.h Outdated Show resolved Hide resolved
src/runtime/security/client_negotiation.cpp Outdated Show resolved Hide resolved
Comment on lines +77 to +100
if (!check_status(rpc.request().status, negotiation_status::type::SASL_SELECT_MECHANISMS)) {
fail_negotiation();
return;
}

error_s err_s = _sasl->init();
if (!err_s.is_ok()) {
dwarn_f("{}: server initialize sasl failed, error = {}, msg = {}",
_name,
err_s.code().to_string(),
err_s.description());
fail_negotiation();
return;
}
_selected_mechanism = request.msg;
if (supported_mechanisms.find(_selected_mechanism) == supported_mechanisms.end()) {
dwarn_f("the mechanism of {} is not supported", _selected_mechanism);
fail_negotiation();
return;
}

negotiation_response &response = rpc.response();
_status = response.status = negotiation_status::type::SASL_SELECT_MECHANISMS_RESP;
} else {
dwarn_f("{}: got message({}) while expect({})",
error_s err_s = _sasl->init();
if (!err_s.is_ok()) {
dwarn_f("{}: server initialize sasl failed, error = {}, msg = {}",
_name,
enum_to_string(request.status),
negotiation_status::type::SASL_SELECT_MECHANISMS);
err_s.code().to_string(),
err_s.description());
fail_negotiation();
return;
}

negotiation_response &response = rpc.response();
_status = response.status = negotiation_status::type::SASL_SELECT_MECHANISMS_RESP;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactor!

@@ -48,5 +50,18 @@ void negotiation::fail_negotiation()
_session->on_failure(true);
}

bool negotiation::check_status(negotiation_status::type status,
negotiation_status::type expect_status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected_status may be better.

@levy5307 levy5307 merged commit fafbd59 into XiaoMi:master Sep 4, 2020
@levy5307 levy5307 deleted the on_mechanism_selected branch September 4, 2020 06:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants