2018-03-14 19:04:41 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-03-14 19:04:41 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
2018-07-03 21:29:04 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-03-14 19:04:41 +01:00
|
|
|
#include "td/telegram/AuthManager.h"
|
2021-10-27 16:32:09 +02:00
|
|
|
|
2019-12-17 17:17:57 +01:00
|
|
|
#include "td/telegram/logevent/LogEventHelper.h"
|
2019-02-16 17:01:47 +01:00
|
|
|
#include "td/telegram/SendCodeHelper.hpp"
|
2018-06-08 16:20:42 +02:00
|
|
|
#include "td/telegram/Version.h"
|
|
|
|
|
2018-03-27 15:11:15 +02:00
|
|
|
#include "td/utils/format.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2018-03-14 19:04:41 +01:00
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
2018-06-07 20:42:17 +02:00
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void AuthManager::WaitPasswordState::store(StorerT &storer) const {
|
2018-03-15 11:06:26 +01:00
|
|
|
using td::store;
|
2018-08-04 08:55:49 +02:00
|
|
|
store(current_client_salt_, storer);
|
|
|
|
store(current_server_salt_, storer);
|
2018-08-10 15:22:48 +02:00
|
|
|
store(srp_g_, storer);
|
|
|
|
store(srp_p_, storer);
|
|
|
|
store(srp_B_, storer);
|
|
|
|
store(srp_id_, storer);
|
2018-03-15 11:06:26 +01:00
|
|
|
store(hint_, storer);
|
|
|
|
store(has_recovery_, storer);
|
|
|
|
store(email_address_pattern_, storer);
|
2023-02-22 13:59:36 +01:00
|
|
|
store(has_secure_values_, storer);
|
2018-03-15 11:06:26 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void AuthManager::WaitPasswordState::parse(ParserT &parser) {
|
2018-03-15 11:06:26 +01:00
|
|
|
using td::parse;
|
2018-08-04 08:55:49 +02:00
|
|
|
parse(current_client_salt_, parser);
|
|
|
|
parse(current_server_salt_, parser);
|
2018-08-10 15:22:48 +02:00
|
|
|
parse(srp_g_, parser);
|
|
|
|
parse(srp_p_, parser);
|
|
|
|
parse(srp_B_, parser);
|
|
|
|
parse(srp_id_, parser);
|
2018-03-15 11:06:26 +01:00
|
|
|
parse(hint_, parser);
|
|
|
|
parse(has_recovery_, parser);
|
|
|
|
parse(email_address_pattern_, parser);
|
2023-02-22 13:59:36 +01:00
|
|
|
parse(has_secure_values_, parser);
|
2018-03-15 11:06:26 +01:00
|
|
|
}
|
2018-03-14 19:04:41 +01:00
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void AuthManager::DbState::store(StorerT &storer) const {
|
2018-03-14 19:04:41 +01:00
|
|
|
using td::store;
|
2018-06-07 20:42:17 +02:00
|
|
|
bool has_terms_of_service = !terms_of_service_.get_id().empty();
|
2018-08-04 08:55:49 +02:00
|
|
|
bool is_pbkdf2_supported = true;
|
2018-08-10 15:22:48 +02:00
|
|
|
bool is_srp_supported = true;
|
2019-07-16 21:08:34 +02:00
|
|
|
bool is_wait_registration_supported = true;
|
2019-11-08 17:23:05 +01:00
|
|
|
bool is_wait_registration_stores_phone_number = true;
|
2019-12-17 17:17:57 +01:00
|
|
|
bool is_wait_qr_code_confirmation_supported = true;
|
2022-09-21 13:25:31 +02:00
|
|
|
bool is_time_store_supported = true;
|
2018-06-07 20:42:17 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_terms_of_service);
|
2018-08-04 08:55:49 +02:00
|
|
|
STORE_FLAG(is_pbkdf2_supported);
|
2018-08-10 15:22:48 +02:00
|
|
|
STORE_FLAG(is_srp_supported);
|
2019-07-16 21:08:34 +02:00
|
|
|
STORE_FLAG(is_wait_registration_supported);
|
2019-11-08 17:23:05 +01:00
|
|
|
STORE_FLAG(is_wait_registration_stores_phone_number);
|
2019-12-17 17:17:57 +01:00
|
|
|
STORE_FLAG(is_wait_qr_code_confirmation_supported);
|
2022-09-06 11:31:54 +02:00
|
|
|
STORE_FLAG(allow_apple_id_);
|
|
|
|
STORE_FLAG(allow_google_id_);
|
2022-09-21 13:25:31 +02:00
|
|
|
STORE_FLAG(is_time_store_supported);
|
2018-06-07 20:42:17 +02:00
|
|
|
END_STORE_FLAGS();
|
2018-03-14 20:47:08 +01:00
|
|
|
store(state_, storer);
|
2018-03-14 19:04:41 +01:00
|
|
|
store(api_id_, storer);
|
|
|
|
store(api_hash_, storer);
|
2022-11-15 09:36:39 +01:00
|
|
|
store_time(expires_at_, storer);
|
2018-03-15 11:06:26 +01:00
|
|
|
|
2018-06-07 20:42:17 +02:00
|
|
|
if (has_terms_of_service) {
|
|
|
|
store(terms_of_service_, storer);
|
|
|
|
}
|
|
|
|
|
2022-09-06 11:31:54 +02:00
|
|
|
if (state_ == State::WaitEmailAddress) {
|
|
|
|
store(send_code_helper_, storer);
|
2022-09-06 15:08:10 +02:00
|
|
|
} else if (state_ == State::WaitEmailCode) {
|
|
|
|
store(send_code_helper_, storer);
|
|
|
|
store(email_address_, storer);
|
2022-09-06 16:42:19 +02:00
|
|
|
store(email_code_info_, storer);
|
2022-09-06 17:15:43 +02:00
|
|
|
store(next_phone_number_login_date_, storer);
|
2022-09-06 11:31:54 +02:00
|
|
|
} else if (state_ == State::WaitCode) {
|
2018-03-15 11:06:26 +01:00
|
|
|
store(send_code_helper_, storer);
|
2019-12-17 17:17:57 +01:00
|
|
|
} else if (state_ == State::WaitQrCodeConfirmation) {
|
|
|
|
store(other_user_ids_, storer);
|
|
|
|
store(login_token_, storer);
|
|
|
|
store_time(login_token_expires_at_, storer);
|
2018-03-15 11:06:26 +01:00
|
|
|
} else if (state_ == State::WaitPassword) {
|
|
|
|
store(wait_password_state_, storer);
|
2019-07-16 21:08:34 +02:00
|
|
|
} else if (state_ == State::WaitRegistration) {
|
2019-11-08 17:23:05 +01:00
|
|
|
store(send_code_helper_, storer);
|
2018-03-15 11:06:26 +01:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2018-03-14 19:04:41 +01:00
|
|
|
}
|
2018-06-07 20:42:17 +02:00
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void AuthManager::DbState::parse(ParserT &parser) {
|
2018-03-14 19:04:41 +01:00
|
|
|
using td::parse;
|
2018-06-07 20:42:17 +02:00
|
|
|
bool has_terms_of_service = false;
|
2018-08-04 08:55:49 +02:00
|
|
|
bool is_pbkdf2_supported = false;
|
2018-08-10 15:22:48 +02:00
|
|
|
bool is_srp_supported = false;
|
2019-07-16 21:08:34 +02:00
|
|
|
bool is_wait_registration_supported = false;
|
2019-11-08 17:23:05 +01:00
|
|
|
bool is_wait_registration_stores_phone_number = false;
|
2019-12-17 17:17:57 +01:00
|
|
|
bool is_wait_qr_code_confirmation_supported = false;
|
2022-09-21 13:25:31 +02:00
|
|
|
bool is_time_store_supported = false;
|
2018-06-07 20:42:17 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddTermsOfService)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_terms_of_service);
|
2018-08-04 08:55:49 +02:00
|
|
|
PARSE_FLAG(is_pbkdf2_supported);
|
2018-08-10 15:22:48 +02:00
|
|
|
PARSE_FLAG(is_srp_supported);
|
2019-07-16 21:08:34 +02:00
|
|
|
PARSE_FLAG(is_wait_registration_supported);
|
2019-11-08 17:23:05 +01:00
|
|
|
PARSE_FLAG(is_wait_registration_stores_phone_number);
|
2019-12-17 17:17:57 +01:00
|
|
|
PARSE_FLAG(is_wait_qr_code_confirmation_supported);
|
2022-09-06 11:31:54 +02:00
|
|
|
PARSE_FLAG(allow_apple_id_);
|
|
|
|
PARSE_FLAG(allow_google_id_);
|
2022-09-21 13:25:31 +02:00
|
|
|
PARSE_FLAG(is_time_store_supported);
|
2018-06-07 20:42:17 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2022-09-21 13:25:31 +02:00
|
|
|
if (!is_time_store_supported) {
|
|
|
|
return parser.set_error("Have no time store support");
|
2019-07-16 21:08:34 +02:00
|
|
|
}
|
|
|
|
CHECK(is_pbkdf2_supported);
|
|
|
|
CHECK(is_srp_supported);
|
2019-12-17 17:17:57 +01:00
|
|
|
CHECK(is_wait_registration_supported);
|
|
|
|
CHECK(is_wait_registration_stores_phone_number);
|
2022-09-21 13:25:31 +02:00
|
|
|
CHECK(is_wait_qr_code_confirmation_supported);
|
2019-07-16 21:08:34 +02:00
|
|
|
|
2018-03-14 20:47:08 +01:00
|
|
|
parse(state_, parser);
|
2018-03-14 19:04:41 +01:00
|
|
|
parse(api_id_, parser);
|
|
|
|
parse(api_hash_, parser);
|
2022-11-15 09:36:39 +01:00
|
|
|
parse_time(expires_at_, parser);
|
2018-03-15 11:06:26 +01:00
|
|
|
|
2018-06-07 20:42:17 +02:00
|
|
|
if (has_terms_of_service) {
|
|
|
|
parse(terms_of_service_, parser);
|
|
|
|
}
|
|
|
|
|
2022-09-06 11:31:54 +02:00
|
|
|
if (state_ == State::WaitEmailAddress) {
|
|
|
|
parse(send_code_helper_, parser);
|
2022-09-06 15:08:10 +02:00
|
|
|
} else if (state_ == State::WaitEmailCode) {
|
|
|
|
parse(send_code_helper_, parser);
|
|
|
|
parse(email_address_, parser);
|
2022-09-06 16:42:19 +02:00
|
|
|
parse(email_code_info_, parser);
|
2022-09-06 17:15:43 +02:00
|
|
|
parse(next_phone_number_login_date_, parser);
|
2022-09-06 11:31:54 +02:00
|
|
|
} else if (state_ == State::WaitCode) {
|
2018-03-15 11:06:26 +01:00
|
|
|
parse(send_code_helper_, parser);
|
2019-12-17 17:17:57 +01:00
|
|
|
} else if (state_ == State::WaitQrCodeConfirmation) {
|
|
|
|
parse(other_user_ids_, parser);
|
|
|
|
parse(login_token_, parser);
|
|
|
|
parse_time(login_token_expires_at_, parser);
|
2018-03-15 11:06:26 +01:00
|
|
|
} else if (state_ == State::WaitPassword) {
|
|
|
|
parse(wait_password_state_, parser);
|
2019-07-16 21:08:34 +02:00
|
|
|
} else if (state_ == State::WaitRegistration) {
|
2019-11-08 17:23:05 +01:00
|
|
|
parse(send_code_helper_, parser);
|
2018-03-15 11:06:26 +01:00
|
|
|
} else {
|
|
|
|
parser.set_error(PSTRING() << "Unexpected " << tag("state", static_cast<int32>(state_)));
|
|
|
|
}
|
2018-03-14 19:04:41 +01:00
|
|
|
}
|
2018-06-07 20:42:17 +02:00
|
|
|
|
2018-03-14 19:04:41 +01:00
|
|
|
} // namespace td
|