From bc193a97bfd38611c69476d0458775dc43d0265f Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 11 Apr 2018 20:42:06 +0300 Subject: [PATCH] Various fixes. GitOrigin-RevId: ec2af1bd18e337425dd6a9287e8d08bbce88eed8 --- td/generate/scheme/td_api.tl | 6 +++-- td/generate/scheme/td_api.tlo | Bin 120668 -> 120728 bytes td/telegram/MessagesManager.cpp | 2 +- td/telegram/SecureManager.cpp | 24 ++++++++++++++++---- td/telegram/SecureManager.h | 1 + td/telegram/SecureValue.cpp | 14 ++++++------ td/telegram/SecureValue.h | 8 +++---- td/telegram/Td.cpp | 39 ++++++++++++++++++++++++-------- 8 files changed, 65 insertions(+), 29 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1cb5f9925..3dd562fdd 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -916,8 +916,10 @@ inputPassportDataEmailAddress email_address:string = InputPassportData; allPassportData data:vector = 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 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 data:vector 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 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ca41d718810554102029c97d5f41f326b06421d0..684277dee08babb9f5f426c5695c39195598a253 100644 GIT binary patch delta 141 zcmcb!j(x^@_6-{ZSyvu#myn#!xPwu8^98|}<18TlWP_VBV8(O-Q$~r&2Q&o)_=-{s zOEZg7Q{qc13sQ?2CJSiGOmEo1C@@(jSzz)41%=5gZYF^BZ05N&Wj!azn48Chd|0O! kZeY}&{@@@Z%XFCuj69R~C<#pe(#e 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(action); - return make_unique(get_secure_value_types(std::move(secure_values->types_))); + return make_unique(get_secure_value_types(secure_values->types_)); } case telegram_api::messageActionSecureValuesSentMe::ID: { LOG_IF(ERROR, !td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSentMe"; diff --git a/td/telegram/SecureManager.cpp b/td/telegram/SecureManager.cpp index 66a6f5a37..70f2ccab3 100644 --- a/td/telegram/SecureManager.cpp +++ b/td/telegram/SecureManager.cpp @@ -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 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(authorization_form_id_, std::move(values), - authorization_form_->selfie_required_, - authorization_form_->privacy_policy_url_)); + promise_.set_value(make_tl_object( + 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 promise) { + // TODO +} + void SecureManager::get_passport_authorization_form(string password, UserId bot_user_id, string scope, string public_key, string payload, Promise promise) { diff --git a/td/telegram/SecureManager.h b/td/telegram/SecureManager.h index fdd5d4b73..0f2a01356 100644 --- a/td/telegram/SecureManager.h +++ b/td/telegram/SecureManager.h @@ -127,6 +127,7 @@ class SecureManager : public NetQueryCallback { void get_secure_value(std::string password, SecureValueType type, Promise promise); void get_all_secure_values(std::string password, Promise promise); void set_secure_value(string password, SecureValue secure_value, Promise promise); + void delete_secure_value(SecureValueType type, Promise promise); void get_passport_authorization_form(string password, UserId bot_user_id, string scope, string public_key, string payload, Promise promise); diff --git a/td/telegram/SecureValue.cpp b/td/telegram/SecureValue.cpp index b81b766c5..678489297 100644 --- a/td/telegram/SecureValue.cpp +++ b/td/telegram/SecureValue.cpp @@ -27,7 +27,7 @@ namespace td { -SecureValueType get_secure_value_type(tl_object_ptr &&secure_value_type) { +SecureValueType get_secure_value_type(const tl_object_ptr &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 &&passport_data_type) { +SecureValueType get_secure_value_type_td_api(const tl_object_ptr &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 get_secure_value_types( - vector> &&secure_value_types) { - return transform(std::move(secure_value_types), get_secure_value_type); + const vector> &secure_value_types) { + return transform(secure_value_types, get_secure_value_type); } vector get_secure_value_types_td_api( - vector> &&secure_value_types) { - return transform(std::move(secure_value_types), get_secure_value_type_td_api); + const vector> &secure_value_types) { + return transform(secure_value_types, get_secure_value_type_td_api); } td_api::object_ptr get_passport_data_type_object(SecureValueType type) { @@ -285,7 +285,7 @@ EncryptedSecureValue get_encrypted_secure_value(FileManager *file_manager, tl_object_ptr &&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: diff --git a/td/telegram/SecureValue.h b/td/telegram/SecureValue.h index 7e3c1b3d6..9d21e828c 100644 --- a/td/telegram/SecureValue.h +++ b/td/telegram/SecureValue.h @@ -37,13 +37,13 @@ enum class SecureValueType { EmailAddress }; -SecureValueType get_secure_value_type(tl_object_ptr &&secure_value_type); -SecureValueType get_secure_value_type_td_api(tl_object_ptr &&passport_data_type); +SecureValueType get_secure_value_type(const tl_object_ptr &secure_value_type); +SecureValueType get_secure_value_type_td_api(const tl_object_ptr &passport_data_type); vector get_secure_value_types( - vector> &&secure_value_types); + const vector> &secure_value_types); vector get_secure_value_types_td_api( - vector> &&secure_value_types); + const vector> &secure_value_types); td_api::object_ptr get_passport_data_type_object(SecureValueType type); td_api::object_ptr get_secure_value_type_object(SecureValueType type); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 3653ee57d..685584cba 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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> 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()); + } + }); + 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) {