2018-04-05 13:18:47 +02:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-04-05 13:18:47 +02: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)
|
|
|
|
//
|
|
|
|
#pragma once
|
2018-04-07 00:29:36 +02:00
|
|
|
|
2018-04-05 13:18:47 +02:00
|
|
|
#include "td/telegram/net/NetQuery.h"
|
2018-12-27 20:24:44 +01:00
|
|
|
#include "td/telegram/SecureStorage.h"
|
2018-04-05 13:18:47 +02:00
|
|
|
#include "td/telegram/SecureValue.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
2018-04-07 01:38:28 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2021-10-27 16:32:09 +02:00
|
|
|
#include "td/telegram/UserId.h"
|
2018-04-05 13:18:47 +02:00
|
|
|
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2019-02-12 22:26:36 +01:00
|
|
|
#include "td/utils/common.h"
|
2018-04-07 01:38:28 +02:00
|
|
|
#include "td/utils/Container.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-04-07 01:38:28 +02:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
2018-08-14 15:44:31 +02:00
|
|
|
#include <map>
|
2018-08-16 00:06:53 +02:00
|
|
|
#include <utility>
|
2018-04-05 13:18:47 +02:00
|
|
|
|
|
|
|
namespace td {
|
2018-04-07 00:29:36 +02:00
|
|
|
|
2018-04-17 17:04:09 +02:00
|
|
|
class Td;
|
|
|
|
|
2018-08-01 15:52:07 +02:00
|
|
|
using TdApiSecureValue = td_api::object_ptr<td_api::PassportElement>;
|
|
|
|
using TdApiSecureValues = td_api::object_ptr<td_api::passportElements>;
|
2018-09-25 04:12:41 +02:00
|
|
|
using TdApiSecureValuesWithErrors = td_api::object_ptr<td_api::passportElementsWithErrors>;
|
2018-04-06 15:24:29 +02:00
|
|
|
using TdApiAuthorizationForm = td_api::object_ptr<td_api::passportAuthorizationForm>;
|
2018-04-07 00:29:36 +02:00
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class SecureManager final : public NetQueryCallback {
|
2018-04-05 13:18:47 +02:00
|
|
|
public:
|
2018-04-07 00:29:36 +02:00
|
|
|
explicit SecureManager(ActorShared<> parent);
|
2018-04-05 13:18:47 +02:00
|
|
|
|
|
|
|
void get_secure_value(std::string password, SecureValueType type, Promise<TdApiSecureValue> promise);
|
2021-10-19 17:11:16 +02:00
|
|
|
|
2018-08-01 15:52:07 +02:00
|
|
|
void get_all_secure_values(std::string password, Promise<TdApiSecureValues> promise);
|
2021-10-19 17:11:16 +02:00
|
|
|
|
2018-04-05 13:18:47 +02:00
|
|
|
void set_secure_value(string password, SecureValue secure_value, Promise<TdApiSecureValue> promise);
|
2021-10-19 17:11:16 +02:00
|
|
|
|
2018-04-11 19:42:06 +02:00
|
|
|
void delete_secure_value(SecureValueType type, Promise<Unit> promise);
|
2021-10-19 17:11:16 +02:00
|
|
|
|
2018-04-17 17:04:09 +02:00
|
|
|
void set_secure_value_errors(Td *td, tl_object_ptr<telegram_api::InputUser> input_user,
|
2018-08-01 15:52:07 +02:00
|
|
|
vector<tl_object_ptr<td_api::inputPassportElementError>> errors, Promise<Unit> promise);
|
2018-04-05 13:18:47 +02:00
|
|
|
|
2018-08-12 14:44:24 +02:00
|
|
|
void on_get_secure_value(SecureValueWithCredentials value);
|
|
|
|
|
2018-09-25 04:12:41 +02:00
|
|
|
void get_passport_authorization_form(UserId bot_user_id, string scope, string public_key, string nonce,
|
|
|
|
Promise<TdApiAuthorizationForm> promise);
|
|
|
|
void get_passport_authorization_form_available_elements(int32 authorization_form_id, string password,
|
|
|
|
Promise<TdApiSecureValuesWithErrors> promise);
|
2018-08-12 15:46:05 +02:00
|
|
|
void send_passport_authorization_form(int32 authorization_form_id, std::vector<SecureValueType> types,
|
|
|
|
Promise<> promise);
|
2018-04-06 15:24:29 +02:00
|
|
|
|
2020-08-23 22:02:20 +02:00
|
|
|
void get_preferred_country_language(string country_code, Promise<td_api::object_ptr<td_api::text>> promise);
|
2018-08-24 00:02:59 +02:00
|
|
|
|
2018-04-05 13:18:47 +02:00
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
|
|
|
int32 refcnt_{1};
|
2018-08-14 15:44:31 +02:00
|
|
|
std::map<SecureValueType, ActorOwn<>> set_secure_value_queries_;
|
|
|
|
std::map<SecureValueType, SecureValueWithCredentials> secure_value_cache_;
|
2018-04-05 13:18:47 +02:00
|
|
|
|
2018-04-06 15:24:29 +02:00
|
|
|
struct AuthorizationForm {
|
2018-04-07 00:29:36 +02:00
|
|
|
UserId bot_user_id;
|
2018-04-06 21:37:30 +02:00
|
|
|
string scope;
|
2018-04-06 15:24:29 +02:00
|
|
|
string public_key;
|
2018-08-17 21:16:55 +02:00
|
|
|
string nonce;
|
2018-09-25 04:12:41 +02:00
|
|
|
bool is_received = false;
|
|
|
|
bool is_decrypted = false;
|
2018-08-14 15:44:31 +02:00
|
|
|
std::map<SecureValueType, SuitableSecureValue> options;
|
2018-09-25 04:12:41 +02:00
|
|
|
vector<telegram_api::object_ptr<telegram_api::secureValue>> values;
|
|
|
|
vector<telegram_api::object_ptr<telegram_api::SecureValueError>> errors;
|
2018-04-06 15:24:29 +02:00
|
|
|
};
|
|
|
|
|
2022-02-11 17:27:32 +01:00
|
|
|
FlatHashMap<int32, unique_ptr<AuthorizationForm>> authorization_forms_;
|
2018-08-12 14:44:24 +02:00
|
|
|
int32 max_authorization_form_id_{0};
|
2018-04-06 15:24:29 +02:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final;
|
|
|
|
void hangup_shared() final;
|
2018-04-05 13:18:47 +02:00
|
|
|
void dec_refcnt();
|
2018-04-19 16:31:25 +02:00
|
|
|
void on_delete_secure_value(SecureValueType type, Promise<Unit> promise, Result<Unit> result);
|
2018-08-12 16:45:30 +02:00
|
|
|
void on_get_passport_authorization_form(
|
|
|
|
int32 authorization_form_id, Promise<TdApiAuthorizationForm> promise,
|
2018-09-25 04:12:41 +02:00
|
|
|
Result<telegram_api::object_ptr<telegram_api::account_authorizationForm>> r_authorization_form);
|
|
|
|
void on_get_passport_authorization_form_secret(int32 authorization_form_id,
|
|
|
|
Promise<TdApiSecureValuesWithErrors> promise,
|
|
|
|
Result<secure_storage::Secret> r_secret);
|
2018-04-06 21:37:30 +02:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_result(NetQueryPtr query) final;
|
2018-04-06 21:37:30 +02:00
|
|
|
Container<Promise<NetQueryPtr>> container_;
|
|
|
|
void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise);
|
2018-04-05 13:18:47 +02:00
|
|
|
};
|
2018-04-07 00:29:36 +02:00
|
|
|
|
2018-04-05 13:18:47 +02:00
|
|
|
} // namespace td
|