Disallow checkAuthenticationBotToken in Ready state.

GitOrigin-RevId: 74290424fabe07988d646ee17e831911ffcd1594
This commit is contained in:
levlam 2020-09-25 01:11:17 +03:00
parent 6cb823bbce
commit 95feb7baa5

View File

@ -144,30 +144,18 @@ void AuthManager::get_state(uint64 query_id) {
void AuthManager::check_bot_token(uint64 query_id, string bot_token) { void AuthManager::check_bot_token(uint64 query_id, string bot_token) {
if (state_ == State::WaitPhoneNumber && net_query_id_ == 0) { if (state_ == State::WaitPhoneNumber && net_query_id_ == 0) {
// can ignore previous checks // can ignore previous checks
was_check_bot_token_ = false; // TODO can we remove was_check_bot_token_ after State::Ok is disallowed? was_check_bot_token_ = false; // TODO can we remove was_check_bot_token_?
} }
if (state_ != State::WaitPhoneNumber && state_ != State::Ok) { if (state_ != State::WaitPhoneNumber) {
// TODO do not allow State::Ok
return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationBotToken unexpected")); return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationBotToken unexpected"));
} }
if (!send_code_helper_.phone_number().empty() || was_qr_code_request_) { if (!send_code_helper_.phone_number().empty() || was_qr_code_request_) {
return on_query_error( return on_query_error(
query_id, Status::Error(400, "Cannot set bot token after authentication beginning. You need to log out first")); query_id, Status::Error(400, "Cannot set bot token after authentication began. You need to log out first"));
} }
if (was_check_bot_token_ && bot_token_ != bot_token) { if (was_check_bot_token_ && bot_token_ != bot_token) {
return on_query_error(query_id, Status::Error(8, "Cannot change bot token. You need to log out first")); return on_query_error(query_id, Status::Error(8, "Cannot change bot token. You need to log out first"));
} }
if (state_ == State::Ok) {
if (!is_bot_) {
// fix old bots
const int64 AUTH_IS_BOT_FIXED_DATE = 1500940800;
if (G()->shared_config().get_option_integer("authorization_date") < AUTH_IS_BOT_FIXED_DATE) {
G()->td_db()->get_binlog_pmc()->set("auth_is_bot", "true");
is_bot_ = true;
}
}
return send_ok(query_id);
}
on_new_query(query_id); on_new_query(query_id);
bot_token_ = bot_token; bot_token_ = bot_token;