Various fixes.
GitOrigin-RevId: ec2af1bd18e337425dd6a9287e8d08bbce88eed8
This commit is contained in:
parent
0bfe50a7b7
commit
bc193a97bf
@ -916,8 +916,10 @@ inputPassportDataEmailAddress email_address:string = InputPassportData;
|
||||
allPassportData data:vector<PassportData> = AllPassportData;
|
||||
|
||||
|
||||
//@description Contains information about requested Telegram Passport authorization form @id Authorization form unique identifier @data Available data @is_selfie_required True, if selfie is required with a document @privacy_policy_url URL with the service privacy policy
|
||||
passportAuthorizationForm id:int32 data:vector<PassportData> is_selfie_required:Bool privacy_policy_url:string = PassportAuthorizationForm;
|
||||
//@description Contains information about requested Telegram Passport authorization form @id Authorization form unique identifier
|
||||
//@required_types Types required to complete the form. If there are more than one identity document or address proof, then any of them can be chosen
|
||||
//@data Already available data @is_selfie_required True, if selfie is required with an identity document @privacy_policy_url URL with the service privacy policy; can be empty
|
||||
passportAuthorizationForm id:int32 required_types:vector<PassportDataType> data:vector<PassportData> is_selfie_required:Bool privacy_policy_url:string = PassportAuthorizationForm;
|
||||
|
||||
|
||||
//@description Contains an encrypted Telegram Passport data credentials @data The encrypted credentials @hash The decrypted data hash @secret Encrypted by service public key secret for data decryption
|
||||
|
Binary file not shown.
@ -21828,7 +21828,7 @@ unique_ptr<MessageContent> MessagesManager::get_message_action_content(
|
||||
case telegram_api::messageActionSecureValuesSent::ID: {
|
||||
LOG_IF(ERROR, td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSent";
|
||||
auto secure_values = move_tl_object_as<telegram_api::messageActionSecureValuesSent>(action);
|
||||
return make_unique<MessagePassportDataSent>(get_secure_value_types(std::move(secure_values->types_)));
|
||||
return make_unique<MessagePassportDataSent>(get_secure_value_types(secure_values->types_));
|
||||
}
|
||||
case telegram_api::messageActionSecureValuesSentMe::ID: {
|
||||
LOG_IF(ERROR, !td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSentMe";
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/SecureManager.h"
|
||||
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/files/FileManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/net/NetQueryDispatcher.h"
|
||||
@ -382,18 +383,27 @@ class GetPassportAuthorizationForm : public NetQueryCallback {
|
||||
if (!secret_ || !authorization_form_) {
|
||||
return;
|
||||
}
|
||||
|
||||
G()->td().get_actor_unsafe()->contacts_manager_->on_get_users(std::move(authorization_form_->users_));
|
||||
|
||||
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
|
||||
std::vector<TdApiSecureValue> values;
|
||||
auto types = get_secure_value_types(std::move(authorization_form_->required_types_));
|
||||
bool is_selfie_required =
|
||||
(authorization_form_->flags_ & telegram_api::account_authorizationForm::SELFIE_REQUIRED_MASK) != 0;
|
||||
auto types = get_secure_value_types(authorization_form_->required_types_);
|
||||
for (auto type : types) {
|
||||
for (auto &value : authorization_form_->values_) {
|
||||
auto value_type = get_secure_value_type(std::move(value->type_));
|
||||
if (value == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto value_type = get_secure_value_type(value->type_);
|
||||
if (value_type != type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto r_secure_value = decrypt_encrypted_secure_value(
|
||||
file_manager, *secret_, get_encrypted_secure_value(file_manager, std::move(value)));
|
||||
value = nullptr;
|
||||
if (r_secure_value.is_error()) {
|
||||
LOG(ERROR) << "Failed to decrypt secure value: " << r_secure_value.error();
|
||||
break;
|
||||
@ -409,9 +419,9 @@ class GetPassportAuthorizationForm : public NetQueryCallback {
|
||||
break;
|
||||
}
|
||||
}
|
||||
promise_.set_value(make_tl_object<td_api::passportAuthorizationForm>(authorization_form_id_, std::move(values),
|
||||
authorization_form_->selfie_required_,
|
||||
authorization_form_->privacy_policy_url_));
|
||||
promise_.set_value(make_tl_object<td_api::passportAuthorizationForm>(
|
||||
authorization_form_id_, get_passport_data_types_object(types), std::move(values), is_selfie_required,
|
||||
authorization_form_->privacy_policy_url_));
|
||||
stop();
|
||||
}
|
||||
};
|
||||
@ -469,6 +479,10 @@ void SecureManager::set_secure_value(string password, SecureValue secure_value,
|
||||
std::move(secure_value), std::move(new_promise));
|
||||
}
|
||||
|
||||
void SecureManager::delete_secure_value(SecureValueType type, Promise<Unit> promise) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void SecureManager::get_passport_authorization_form(string password, UserId bot_user_id, string scope,
|
||||
string public_key, string payload,
|
||||
Promise<TdApiAuthorizationForm> promise) {
|
||||
|
@ -127,6 +127,7 @@ class SecureManager : public NetQueryCallback {
|
||||
void get_secure_value(std::string password, SecureValueType type, Promise<TdApiSecureValue> promise);
|
||||
void get_all_secure_values(std::string password, Promise<TdApiAllSecureValues> promise);
|
||||
void set_secure_value(string password, SecureValue secure_value, Promise<TdApiSecureValue> promise);
|
||||
void delete_secure_value(SecureValueType type, Promise<Unit> promise);
|
||||
|
||||
void get_passport_authorization_form(string password, UserId bot_user_id, string scope, string public_key,
|
||||
string payload, Promise<TdApiAuthorizationForm> promise);
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
SecureValueType get_secure_value_type(tl_object_ptr<telegram_api::SecureValueType> &&secure_value_type) {
|
||||
SecureValueType get_secure_value_type(const tl_object_ptr<telegram_api::SecureValueType> &secure_value_type) {
|
||||
CHECK(secure_value_type != nullptr);
|
||||
switch (secure_value_type->get_id()) {
|
||||
case telegram_api::secureValueTypePersonalDetails::ID:
|
||||
@ -56,7 +56,7 @@ SecureValueType get_secure_value_type(tl_object_ptr<telegram_api::SecureValueTyp
|
||||
}
|
||||
}
|
||||
|
||||
SecureValueType get_secure_value_type_td_api(tl_object_ptr<td_api::PassportDataType> &&passport_data_type) {
|
||||
SecureValueType get_secure_value_type_td_api(const tl_object_ptr<td_api::PassportDataType> &passport_data_type) {
|
||||
CHECK(passport_data_type != nullptr);
|
||||
switch (passport_data_type->get_id()) {
|
||||
case td_api::passportDataTypePersonalDetails::ID:
|
||||
@ -86,13 +86,13 @@ SecureValueType get_secure_value_type_td_api(tl_object_ptr<td_api::PassportDataT
|
||||
}
|
||||
|
||||
vector<SecureValueType> get_secure_value_types(
|
||||
vector<tl_object_ptr<telegram_api::SecureValueType>> &&secure_value_types) {
|
||||
return transform(std::move(secure_value_types), get_secure_value_type);
|
||||
const vector<tl_object_ptr<telegram_api::SecureValueType>> &secure_value_types) {
|
||||
return transform(secure_value_types, get_secure_value_type);
|
||||
}
|
||||
|
||||
vector<SecureValueType> get_secure_value_types_td_api(
|
||||
vector<tl_object_ptr<td_api::PassportDataType>> &&secure_value_types) {
|
||||
return transform(std::move(secure_value_types), get_secure_value_type_td_api);
|
||||
const vector<tl_object_ptr<td_api::PassportDataType>> &secure_value_types) {
|
||||
return transform(secure_value_types, get_secure_value_type_td_api);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::PassportDataType> get_passport_data_type_object(SecureValueType type) {
|
||||
@ -285,7 +285,7 @@ EncryptedSecureValue get_encrypted_secure_value(FileManager *file_manager,
|
||||
tl_object_ptr<telegram_api::secureValue> &&secure_value) {
|
||||
EncryptedSecureValue result;
|
||||
CHECK(secure_value != nullptr);
|
||||
result.type = get_secure_value_type(std::move(secure_value->type_));
|
||||
result.type = get_secure_value_type(secure_value->type_);
|
||||
if (secure_value->plain_data_ != nullptr) {
|
||||
switch (secure_value->plain_data_->get_id()) {
|
||||
case telegram_api::securePlainPhone::ID:
|
||||
|
@ -37,13 +37,13 @@ enum class SecureValueType {
|
||||
EmailAddress
|
||||
};
|
||||
|
||||
SecureValueType get_secure_value_type(tl_object_ptr<telegram_api::SecureValueType> &&secure_value_type);
|
||||
SecureValueType get_secure_value_type_td_api(tl_object_ptr<td_api::PassportDataType> &&passport_data_type);
|
||||
SecureValueType get_secure_value_type(const tl_object_ptr<telegram_api::SecureValueType> &secure_value_type);
|
||||
SecureValueType get_secure_value_type_td_api(const tl_object_ptr<td_api::PassportDataType> &passport_data_type);
|
||||
|
||||
vector<SecureValueType> get_secure_value_types(
|
||||
vector<tl_object_ptr<telegram_api::SecureValueType>> &&secure_value_types);
|
||||
const vector<tl_object_ptr<telegram_api::SecureValueType>> &secure_value_types);
|
||||
vector<SecureValueType> get_secure_value_types_td_api(
|
||||
vector<tl_object_ptr<td_api::PassportDataType>> &&secure_value_types);
|
||||
const vector<tl_object_ptr<td_api::PassportDataType>> &secure_value_types);
|
||||
|
||||
td_api::object_ptr<td_api::PassportDataType> get_passport_data_type_object(SecureValueType type);
|
||||
td_api::object_ptr<telegram_api::SecureValueType> get_secure_value_type_object(SecureValueType type);
|
||||
|
@ -5375,12 +5375,10 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
if (request.category_ == nullptr) {
|
||||
promise.set_error(Status::Error(400, "Top chat category should not be empty"));
|
||||
return;
|
||||
return promise.set_error(Status::Error(400, "Top chat category should not be empty"));
|
||||
}
|
||||
if (request.limit_ <= 0) {
|
||||
promise.set_error(Status::Error(400, "Limit must be positive"));
|
||||
return;
|
||||
return promise.set_error(Status::Error(400, "Limit must be positive"));
|
||||
}
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<vector<DialogId>> result) mutable {
|
||||
if (result.is_error()) {
|
||||
@ -6847,7 +6845,7 @@ void Td::on_request(uint64 id, td_api::getPassportData &request) {
|
||||
}
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
send_closure(secure_manager_, &SecureManager::get_secure_value, std::move(request.password_),
|
||||
get_secure_value_type_td_api(std::move(request.type_)), std::move(promise));
|
||||
get_secure_value_type_td_api(request.type_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getAllPassportData &request) {
|
||||
@ -6875,7 +6873,19 @@ void Td::on_request(uint64 id, td_api::setPassportData &request) {
|
||||
void Td::on_request(uint64 id, const td_api::deletePassportData &request) {
|
||||
CHECK_AUTH();
|
||||
CHECK_IS_USER();
|
||||
LOG(FATAL) << "TODO";
|
||||
if (request.type_ == nullptr) {
|
||||
return send_error_raw(id, 400, "Type must not be empty");
|
||||
}
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<> result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(make_tl_object<td_api::ok>());
|
||||
}
|
||||
});
|
||||
send_closure(secure_manager_, &SecureManager::delete_secure_value, get_secure_value_type_td_api(request.type_),
|
||||
std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::sendPhoneNumberVerificationCode &request) {
|
||||
@ -6935,15 +6945,25 @@ void Td::on_request(uint64 id, td_api::getPassportAuthorizationForm &request) {
|
||||
if (!bot_user_id.is_valid()) {
|
||||
return send_error_raw(id, 400, "Bot user identifier invalid");
|
||||
}
|
||||
if (request.payload_.empty()) {
|
||||
return send_error_raw(id, 400, "Payload must be non-empty");
|
||||
}
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
send_closure(secure_manager_, &SecureManager::get_passport_authorization_form, request.password_, bot_user_id,
|
||||
request.scope_, request.public_key_, request.payload_, std::move(promise));
|
||||
send_closure(secure_manager_, &SecureManager::get_passport_authorization_form, std::move(request.password_),
|
||||
bot_user_id, std::move(request.scope_), std::move(request.public_key_), std::move(request.payload_),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::sendPassportAuthorizationForm &request) {
|
||||
CHECK_AUTH();
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.password_);
|
||||
for (auto &type : request.types_) {
|
||||
if (type == nullptr) {
|
||||
return send_error_raw(id, 400, "Type must not be empty");
|
||||
}
|
||||
}
|
||||
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<> result) mutable {
|
||||
if (result.is_error()) {
|
||||
@ -6953,8 +6973,7 @@ void Td::on_request(uint64 id, td_api::sendPassportAuthorizationForm &request) {
|
||||
}
|
||||
});
|
||||
send_closure(secure_manager_, &SecureManager::send_passport_authorization_form, request.password_,
|
||||
request.autorization_form_id_, get_secure_value_types_td_api(std::move(request.types_)),
|
||||
std::move(query_promise));
|
||||
request.autorization_form_id_, get_secure_value_types_td_api(request.types_), std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getSupportUser &request) {
|
||||
|
Reference in New Issue
Block a user