2018-03-14 19:04:41 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
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"
|
|
|
|
|
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"
|
|
|
|
#include "td/utils/logging.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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
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;
|
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);
|
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);
|
|
|
|
store(state_timestamp_, 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);
|
|
|
|
}
|
|
|
|
|
2018-03-15 11:06:26 +01:00
|
|
|
if (state_ == State::WaitCode) {
|
|
|
|
store(send_code_helper_, storer);
|
|
|
|
} 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;
|
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);
|
2018-06-07 20:42:17 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2019-12-02 01:26:52 +01:00
|
|
|
if (!is_wait_registration_supported || !is_wait_registration_stores_phone_number) {
|
2019-07-16 21:08:34 +02:00
|
|
|
return parser.set_error("Have no wait registration support");
|
|
|
|
}
|
|
|
|
CHECK(is_pbkdf2_supported);
|
|
|
|
CHECK(is_srp_supported);
|
|
|
|
|
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);
|
|
|
|
parse(state_timestamp_, 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);
|
|
|
|
}
|
|
|
|
|
2018-03-15 11:06:26 +01:00
|
|
|
if (state_ == State::WaitCode) {
|
|
|
|
parse(send_code_helper_, parser);
|
|
|
|
} 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
|