diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d8505083..0210d938 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3239,8 +3239,8 @@ checkEmailAddressVerificationCode code:string = Ok; //@description Returns a Telegram Passport authorization form for sharing data with a service @bot_user_id User identified of the service's bot @scope Telegram Passport element types requested by the service @public_key Service's public_key @payload Authorization form payload provided by the service @password Password of the current user getPassportAuthorizationForm bot_user_id:int32 scope:string public_key:string payload:string password:string = PassportAuthorizationForm; -//@description Sends a Telegram Passport authorization form, effectively sharing data with the service @autorization_form_id Authorization form identifier @types Types of Telegram Passport elements chosen by user to complete the authorization form @password Password of the current user -sendPassportAuthorizationForm autorization_form_id:int32 types:vector password:string = Ok; +//@description Sends a Telegram Passport authorization form, effectively sharing data with the service @autorization_form_id Authorization form identifier @types Types of Telegram Passport elements chosen by user to complete the authorization form +sendPassportAuthorizationForm autorization_form_id:int32 types:vector = Ok; //@description Sends phone number confirmation code. Should be called when user presses "https://t.me/confirmphone?phone=*******&hash=**********" or "tg://confirmphone?phone=*******&hash=**********" link @hash Value of the "hash" parameter from the link diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index c3eb8eae..0b3fe784 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/SecureManager.cpp b/td/telegram/SecureManager.cpp index b2bba5df..63720b5e 100644 --- a/td/telegram/SecureManager.cpp +++ b/td/telegram/SecureManager.cpp @@ -742,6 +742,8 @@ class GetPassportAuthorizationForm : public NetQueryCallback { break; } + send_closure(parent_, &SecureManager::on_get_secure_value, r_secure_value.ok()); + auto r_passport_element = get_passport_element_object(file_manager, std::move(r_secure_value.move_as_ok().value)); if (r_passport_element.is_error()) { @@ -867,18 +869,9 @@ void SecureManager::get_secure_value(std::string password, SecureValueType type, } promise.set_value(r_passport_element.move_as_ok()); }); - do_get_secure_value(std::move(password), type, false, std::move(new_promise)); -} - -void SecureManager::do_get_secure_value(std::string password, SecureValueType type, bool allow_from_cache, - Promise promise) { - if (allow_from_cache && secure_value_cache_.count(type)) { - // TODO check password? - return promise.set_value(SecureValueWithCredentials(secure_value_cache_[type])); - } refcnt_++; - create_actor("GetSecureValue", actor_shared(this), std::move(password), type, std::move(promise)) + create_actor("GetSecureValue", actor_shared(this), std::move(password), type, std::move(new_promise)) .release(); } @@ -1062,8 +1055,8 @@ void SecureManager::on_get_passport_authorization_form(int32 authorization_form_ promise.set_value(std::move(authorization_form)); } -void SecureManager::send_passport_authorization_form(string password, int32 authorization_form_id, - std::vector types, Promise<> promise) { +void SecureManager::send_passport_authorization_form(int32 authorization_form_id, std::vector types, + Promise<> promise) { auto it = authorization_forms_.find(authorization_form_id); if (it == authorization_forms_.end()) { return promise.set_error(Status::Error(400, "Unknown authorization_form_id")); @@ -1075,50 +1068,16 @@ void SecureManager::send_passport_authorization_form(string password, int32 auth return promise.set_error(Status::Error(400, "Types must be non-empty")); } - struct JoinPromise { - Promise> promise_; - std::vector credentials_; - int wait_cnt_{0}; - }; - - auto join = std::make_shared(); + std::vector credentials; + credentials.reserve(types.size()); for (auto type : types) { - join->wait_cnt_++; - send_closure_later(actor_id(this), &SecureManager::do_get_secure_value, password, type, true, - PromiseCreator::lambda([join](Result r_secure_value) { - if (!join->promise_) { - return; - } - if (r_secure_value.is_error()) { - return join->promise_.set_error(r_secure_value.move_as_error()); - } - join->credentials_.push_back(r_secure_value.move_as_ok().credentials); - join->wait_cnt_--; - if (join->wait_cnt_ == 0) { - join->promise_.set_value(std::move(join->credentials_)); - } - })); + auto value_it = secure_value_cache_.find(type); + if (value_it == secure_value_cache_.end()) { + return promise.set_error(Status::Error(400, "Passport Element with the specified type is not found")); + } + credentials.push_back(value_it->second.credentials); } - join->promise_ = - PromiseCreator::lambda([promise = std::move(promise), actor_id = actor_id(this), - authorization_form_id](Result> r_credentials) mutable { - if (r_credentials.is_error()) { - return promise.set_error(r_credentials.move_as_error()); - } - send_closure(actor_id, &SecureManager::do_send_passport_authorization_form, authorization_form_id, - r_credentials.move_as_ok(), std::move(promise)); - }); -} -void SecureManager::do_send_passport_authorization_form(int32 authorization_form_id, - vector credentials, Promise<> promise) { - auto it = authorization_forms_.find(authorization_form_id); - if (it == authorization_forms_.end()) { - return promise.set_error(Status::Error(400, "Unknown authorization_form_id")); - } - if (credentials.empty()) { - return promise.set_error(Status::Error(400, "Empty types")); - } std::vector> hashes; for (auto &c : credentials) { hashes.push_back(telegram_api::make_object(get_input_secure_value_type(c.type), diff --git a/td/telegram/SecureManager.h b/td/telegram/SecureManager.h index 018761f4..e0296467 100644 --- a/td/telegram/SecureManager.h +++ b/td/telegram/SecureManager.h @@ -45,8 +45,8 @@ class SecureManager : public NetQueryCallback { void get_passport_authorization_form(string password, UserId bot_user_id, string scope, string public_key, string payload, Promise promise); - void send_passport_authorization_form(string password, int32 authorization_form_id, - std::vector types, Promise<> promise); + void send_passport_authorization_form(int32 authorization_form_id, std::vector types, + Promise<> promise); private: ActorShared<> parent_; @@ -68,13 +68,9 @@ class SecureManager : public NetQueryCallback { void hangup() override; void hangup_shared() override; void dec_refcnt(); - void do_get_secure_value(std::string password, SecureValueType type, bool allow_from_cache, - Promise promise); void on_delete_secure_value(SecureValueType type, Promise promise, Result result); void on_get_passport_authorization_form(int32 authorization_form_id, Promise promise, Result r_authorization_form); - void do_send_passport_authorization_form(int32 authorization_form_id, vector credentials, - Promise<> promise); void on_result(NetQueryPtr query) override; Container> container_; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index abb3e5c6..5650699f 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6442,7 +6442,6 @@ void Td::on_request(uint64 id, td_api::getPassportAuthorizationForm &request) { void Td::on_request(uint64 id, td_api::sendPassportAuthorizationForm &request) { 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"); @@ -6450,8 +6449,8 @@ void Td::on_request(uint64 id, td_api::sendPassportAuthorizationForm &request) { } CREATE_OK_REQUEST_PROMISE(); - send_closure(secure_manager_, &SecureManager::send_passport_authorization_form, request.password_, - request.autorization_form_id_, get_secure_value_types_td_api(request.types_), std::move(promise)); + send_closure(secure_manager_, &SecureManager::send_passport_authorization_form, request.autorization_form_id_, + get_secure_value_types_td_api(request.types_), std::move(promise)); } void Td::on_request(uint64 id, td_api::sendPhoneNumberConfirmationCode &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 9064f307..0232fc61 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1278,13 +1278,11 @@ class CliClient final : public Actor { send_request(make_tl_object(to_integer(bot_id), scope, public_key, payload, password)); } else if (op == "spaf") { - string password; string id; string types; - std::tie(password, args) = split(args); std::tie(id, types) = split(args); send_request(make_tl_object(to_integer(id), - as_passport_element_types(types), password)); + as_passport_element_types(types))); } else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") { send_request(make_tl_object(args, false, false)); } else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") {