2018-04-05 13:18:47 +02:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
#include "td/telegram/SecureValue.h"
|
2018-04-07 00:29:36 +02:00
|
|
|
#include "td/telegram/UserId.h"
|
2018-04-05 13:18:47 +02:00
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
2018-04-07 01:38:28 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2018-04-05 13:18:47 +02:00
|
|
|
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
2018-04-07 01:38:28 +02:00
|
|
|
#include "td/utils/Container.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <memory>
|
2018-08-12 14:44:24 +02:00
|
|
|
#include <unordered_map>
|
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-04-06 15:24:29 +02:00
|
|
|
using TdApiAuthorizationForm = td_api::object_ptr<td_api::passportAuthorizationForm>;
|
2018-04-07 00:29:36 +02:00
|
|
|
|
2018-04-06 21:37:30 +02:00
|
|
|
class SecureManager : 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);
|
2018-08-01 15:52:07 +02:00
|
|
|
void get_all_secure_values(std::string password, Promise<TdApiSecureValues> promise);
|
2018-04-05 13:18:47 +02:00
|
|
|
void set_secure_value(string password, SecureValue secure_value, Promise<TdApiSecureValue> promise);
|
2018-04-11 19:42:06 +02:00
|
|
|
void delete_secure_value(SecureValueType type, Promise<Unit> promise);
|
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-04-07 00:29:36 +02:00
|
|
|
void get_passport_authorization_form(string password, UserId bot_user_id, string scope, string public_key,
|
|
|
|
string payload, Promise<TdApiAuthorizationForm> 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
|
|
|
|
2018-04-05 13:18:47 +02:00
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
|
|
|
int32 refcnt_{1};
|
2018-08-12 14:44:24 +02:00
|
|
|
std::unordered_map<SecureValueType, ActorOwn<>> set_secure_value_queries_;
|
|
|
|
std::unordered_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-04-06 21:37:30 +02:00
|
|
|
string payload;
|
2018-04-17 14:39:23 +02:00
|
|
|
bool is_received;
|
2018-08-12 16:45:30 +02:00
|
|
|
std::unordered_map<SecureValueType, SuitableSecureValue> options;
|
2018-04-06 15:24:29 +02:00
|
|
|
};
|
|
|
|
|
2018-08-12 14:44:24 +02:00
|
|
|
std::unordered_map<int32, AuthorizationForm> authorization_forms_;
|
|
|
|
int32 max_authorization_form_id_{0};
|
2018-04-06 15:24:29 +02:00
|
|
|
|
2018-04-05 13:18:47 +02:00
|
|
|
void hangup() override;
|
|
|
|
void hangup_shared() override;
|
|
|
|
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,
|
|
|
|
Result<std::pair<std::unordered_map<SecureValueType, SuitableSecureValue>, TdApiAuthorizationForm>>
|
|
|
|
r_authorization_form);
|
2018-04-06 21:37:30 +02:00
|
|
|
|
|
|
|
void on_result(NetQueryPtr query) override;
|
|
|
|
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
|