Always use cached secure values for sendPassportAuthorizationForm.

GitOrigin-RevId: f1827b89c0ef6870813784e48762cd96325d4b89
This commit is contained in:
levlam 2018-08-12 16:46:05 +03:00
parent b07fc66b69
commit 062c016b2c
6 changed files with 19 additions and 67 deletions

View File

@ -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<PassportElementType> 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<PassportElementType> = 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

Binary file not shown.

View File

@ -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<SecureValueWithCredentials> 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>("GetSecureValue", actor_shared(this), std::move(password), type, std::move(promise))
create_actor<GetSecureValue>("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<SecureValueType> types, Promise<> promise) {
void SecureManager::send_passport_authorization_form(int32 authorization_form_id, std::vector<SecureValueType> 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<std::vector<SecureValueCredentials>> promise_;
std::vector<SecureValueCredentials> credentials_;
int wait_cnt_{0};
};
auto join = std::make_shared<JoinPromise>();
std::vector<SecureValueCredentials> 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<SecureValueWithCredentials> 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<vector<SecureValueCredentials>> 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<SecureValueCredentials> 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<telegram_api::object_ptr<telegram_api::secureValueHash>> hashes;
for (auto &c : credentials) {
hashes.push_back(telegram_api::make_object<telegram_api::secureValueHash>(get_input_secure_value_type(c.type),

View File

@ -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<TdApiAuthorizationForm> promise);
void send_passport_authorization_form(string password, int32 authorization_form_id,
std::vector<SecureValueType> types, Promise<> promise);
void send_passport_authorization_form(int32 authorization_form_id, std::vector<SecureValueType> 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<SecureValueWithCredentials> promise);
void on_delete_secure_value(SecureValueType type, Promise<Unit> promise, Result<Unit> result);
void on_get_passport_authorization_form(int32 authorization_form_id, Promise<TdApiAuthorizationForm> promise,
Result<TdApiAuthorizationForm> r_authorization_form);
void do_send_passport_authorization_form(int32 authorization_form_id, vector<SecureValueCredentials> credentials,
Promise<> promise);
void on_result(NetQueryPtr query) override;
Container<Promise<NetQueryPtr>> container_;

View File

@ -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) {

View File

@ -1278,13 +1278,11 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::getPassportAuthorizationForm>(to_integer<int32>(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<td_api::sendPassportAuthorizationForm>(to_integer<int32>(id),
as_passport_element_types(types), password));
as_passport_element_types(types)));
} else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") {
send_request(make_tl_object<td_api::sendPhoneNumberVerificationCode>(args, false, false));
} else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") {