Various fixes.

GitOrigin-RevId: ec2af1bd18e337425dd6a9287e8d08bbce88eed8
This commit is contained in:
levlam 2018-04-11 20:42:06 +03:00
parent 0bfe50a7b7
commit bc193a97bf
8 changed files with 65 additions and 29 deletions

View File

@ -916,8 +916,10 @@ inputPassportDataEmailAddress email_address:string = InputPassportData;
allPassportData data:vector<PassportData> = AllPassportData; 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 //@description Contains information about requested Telegram Passport authorization form @id Authorization form unique identifier
passportAuthorizationForm id:int32 data:vector<PassportData> is_selfie_required:Bool privacy_policy_url:string = PassportAuthorizationForm; //@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 //@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.

View File

@ -21828,7 +21828,7 @@ unique_ptr<MessageContent> MessagesManager::get_message_action_content(
case telegram_api::messageActionSecureValuesSent::ID: { case telegram_api::messageActionSecureValuesSent::ID: {
LOG_IF(ERROR, td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSent"; LOG_IF(ERROR, td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSent";
auto secure_values = move_tl_object_as<telegram_api::messageActionSecureValuesSent>(action); 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: { case telegram_api::messageActionSecureValuesSentMe::ID: {
LOG_IF(ERROR, !td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSentMe"; LOG_IF(ERROR, !td_->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSentMe";

View File

@ -6,6 +6,7 @@
// //
#include "td/telegram/SecureManager.h" #include "td/telegram/SecureManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/net/NetQueryDispatcher.h" #include "td/telegram/net/NetQueryDispatcher.h"
@ -382,18 +383,27 @@ class GetPassportAuthorizationForm : public NetQueryCallback {
if (!secret_ || !authorization_form_) { if (!secret_ || !authorization_form_) {
return; 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(); auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
std::vector<TdApiSecureValue> values; 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 type : types) {
for (auto &value : authorization_form_->values_) { 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) { if (value_type != type) {
continue; continue;
} }
auto r_secure_value = decrypt_encrypted_secure_value( auto r_secure_value = decrypt_encrypted_secure_value(
file_manager, *secret_, get_encrypted_secure_value(file_manager, std::move(value))); file_manager, *secret_, get_encrypted_secure_value(file_manager, std::move(value)));
value = nullptr;
if (r_secure_value.is_error()) { if (r_secure_value.is_error()) {
LOG(ERROR) << "Failed to decrypt secure value: " << r_secure_value.error(); LOG(ERROR) << "Failed to decrypt secure value: " << r_secure_value.error();
break; break;
@ -409,9 +419,9 @@ class GetPassportAuthorizationForm : public NetQueryCallback {
break; break;
} }
} }
promise_.set_value(make_tl_object<td_api::passportAuthorizationForm>(authorization_form_id_, std::move(values), promise_.set_value(make_tl_object<td_api::passportAuthorizationForm>(
authorization_form_->selfie_required_, authorization_form_id_, get_passport_data_types_object(types), std::move(values), is_selfie_required,
authorization_form_->privacy_policy_url_)); authorization_form_->privacy_policy_url_));
stop(); stop();
} }
}; };
@ -469,6 +479,10 @@ void SecureManager::set_secure_value(string password, SecureValue secure_value,
std::move(secure_value), std::move(new_promise)); 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, void SecureManager::get_passport_authorization_form(string password, UserId bot_user_id, string scope,
string public_key, string payload, string public_key, string payload,
Promise<TdApiAuthorizationForm> promise) { Promise<TdApiAuthorizationForm> promise) {

View File

@ -127,6 +127,7 @@ class SecureManager : public NetQueryCallback {
void get_secure_value(std::string password, SecureValueType type, Promise<TdApiSecureValue> promise); void get_secure_value(std::string password, SecureValueType type, Promise<TdApiSecureValue> promise);
void get_all_secure_values(std::string password, Promise<TdApiAllSecureValues> 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 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, void get_passport_authorization_form(string password, UserId bot_user_id, string scope, string public_key,
string payload, Promise<TdApiAuthorizationForm> promise); string payload, Promise<TdApiAuthorizationForm> promise);

View File

@ -27,7 +27,7 @@
namespace td { 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); CHECK(secure_value_type != nullptr);
switch (secure_value_type->get_id()) { switch (secure_value_type->get_id()) {
case telegram_api::secureValueTypePersonalDetails::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); CHECK(passport_data_type != nullptr);
switch (passport_data_type->get_id()) { switch (passport_data_type->get_id()) {
case td_api::passportDataTypePersonalDetails::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<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) {
return transform(std::move(secure_value_types), get_secure_value_type); return transform(secure_value_types, get_secure_value_type);
} }
vector<SecureValueType> get_secure_value_types_td_api( 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) {
return transform(std::move(secure_value_types), get_secure_value_type_td_api); 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) { 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) { tl_object_ptr<telegram_api::secureValue> &&secure_value) {
EncryptedSecureValue result; EncryptedSecureValue result;
CHECK(secure_value != nullptr); 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) { if (secure_value->plain_data_ != nullptr) {
switch (secure_value->plain_data_->get_id()) { switch (secure_value->plain_data_->get_id()) {
case telegram_api::securePlainPhone::ID: case telegram_api::securePlainPhone::ID:

View File

@ -37,13 +37,13 @@ enum class SecureValueType {
EmailAddress EmailAddress
}; };
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);
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);
vector<SecureValueType> get_secure_value_types( 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<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<td_api::PassportDataType> get_passport_data_type_object(SecureValueType type);
td_api::object_ptr<telegram_api::SecureValueType> get_secure_value_type_object(SecureValueType type); td_api::object_ptr<telegram_api::SecureValueType> get_secure_value_type_object(SecureValueType type);

View File

@ -5375,12 +5375,10 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(promise); CREATE_REQUEST_PROMISE(promise);
if (request.category_ == nullptr) { if (request.category_ == nullptr) {
promise.set_error(Status::Error(400, "Top chat category should not be empty")); return promise.set_error(Status::Error(400, "Top chat category should not be empty"));
return;
} }
if (request.limit_ <= 0) { if (request.limit_ <= 0) {
promise.set_error(Status::Error(400, "Limit must be positive")); return promise.set_error(Status::Error(400, "Limit must be positive"));
return;
} }
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<vector<DialogId>> result) mutable { auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<vector<DialogId>> result) mutable {
if (result.is_error()) { if (result.is_error()) {
@ -6847,7 +6845,7 @@ void Td::on_request(uint64 id, td_api::getPassportData &request) {
} }
CREATE_REQUEST_PROMISE(promise); CREATE_REQUEST_PROMISE(promise);
send_closure(secure_manager_, &SecureManager::get_secure_value, std::move(request.password_), 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) { 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) { void Td::on_request(uint64 id, const td_api::deletePassportData &request) {
CHECK_AUTH(); CHECK_AUTH();
CHECK_IS_USER(); 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) { 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()) { if (!bot_user_id.is_valid()) {
return send_error_raw(id, 400, "Bot user identifier invalid"); 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); CREATE_REQUEST_PROMISE(promise);
send_closure(secure_manager_, &SecureManager::get_passport_authorization_form, request.password_, bot_user_id, send_closure(secure_manager_, &SecureManager::get_passport_authorization_form, std::move(request.password_),
request.scope_, request.public_key_, request.payload_, std::move(promise)); 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) { void Td::on_request(uint64 id, td_api::sendPassportAuthorizationForm &request) {
CHECK_AUTH(); CHECK_AUTH();
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.password_); 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); CREATE_REQUEST_PROMISE(promise);
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<> result) mutable { auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<> result) mutable {
if (result.is_error()) { 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_, 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_)), request.autorization_form_id_, get_secure_value_types_td_api(request.types_), std::move(query_promise));
std::move(query_promise));
} }
void Td::on_request(uint64 id, const td_api::getSupportUser &request) { void Td::on_request(uint64 id, const td_api::getSupportUser &request) {