Add td_api::updateApplicationVerificationRequired.

This commit is contained in:
levlam 2024-05-09 23:04:50 +03:00
parent d5ac68c067
commit fcf8f012b4
7 changed files with 109 additions and 3 deletions

View File

@ -442,6 +442,7 @@ set(TDLIB_SOURCE
td/telegram/net/NetQueryDelayer.cpp td/telegram/net/NetQueryDelayer.cpp
td/telegram/net/NetQueryDispatcher.cpp td/telegram/net/NetQueryDispatcher.cpp
td/telegram/net/NetQueryStats.cpp td/telegram/net/NetQueryStats.cpp
td/telegram/net/NetQueryVerifier.cpp
td/telegram/net/NetStatsManager.cpp td/telegram/net/NetStatsManager.cpp
td/telegram/net/Proxy.cpp td/telegram/net/Proxy.cpp
td/telegram/net/PublicRsaKeySharedCdn.cpp td/telegram/net/PublicRsaKeySharedCdn.cpp
@ -778,6 +779,7 @@ set(TDLIB_SOURCE
td/telegram/net/NetQueryDelayer.h td/telegram/net/NetQueryDelayer.h
td/telegram/net/NetQueryDispatcher.h td/telegram/net/NetQueryDispatcher.h
td/telegram/net/NetQueryStats.h td/telegram/net/NetQueryStats.h
td/telegram/net/NetQueryVerifier.h
td/telegram/net/NetStatsManager.h td/telegram/net/NetStatsManager.h
td/telegram/net/NetType.h td/telegram/net/NetType.h
td/telegram/net/Proxy.h td/telegram/net/Proxy.h

View File

@ -6801,7 +6801,7 @@ botCommandScopeChatMember chat_id:int53 user_id:int53 = BotCommandScope;
//@class PhoneNumberCodeType @description Describes type of the request for which a code is sent to a phone number //@class PhoneNumberCodeType @description Describes type of the request for which a code is sent to a phone number
//@description Checks ownership of a new phone number to change the user's authentication phone number; for official Android and iOS applications only. //@description Checks ownership of a new phone number to change the user's authentication phone number; for official Android and iOS applications only
phoneNumberCodeTypeChange = PhoneNumberCodeType; phoneNumberCodeTypeChange = PhoneNumberCodeType;
//@description Verifies ownership of a phone number to be added to the user's Telegram Passport //@description Verifies ownership of a phone number to be added to the user's Telegram Passport
@ -7125,6 +7125,13 @@ updateFileDownload file_id:int32 complete_date:int32 is_paused:Bool counts:downl
//@description A file was removed from the file download list. This update is sent only after file download list is loaded for the first time @file_id File identifier @counts New number of being downloaded and recently downloaded files found //@description A file was removed from the file download list. This update is sent only after file download list is loaded for the first time @file_id File identifier @counts New number of being downloaded and recently downloaded files found
updateFileRemovedFromDownloads file_id:int32 counts:downloadedFileCounts = Update; updateFileRemovedFromDownloads file_id:int32 counts:downloadedFileCounts = Update;
//@description A request can't be completed unless application verification is performed; for official mobile applications only.
//-The method setApplicationVerificationToken must be called once the verification is completed or failed
//@verification_id Unique identifier for the verification process
//@nonce Unique nonce for the classic Play Integrity verification (https://developer.android.com/google/play/integrity/classic) for Android,
//-or a unique string to compare with verify_nonce field from a push notification for iOS
updateApplicationVerificationRequired verification_id:int53 nonce:string = Update;
//@description New call was created or information about a call was updated @call New data about a call //@description New call was created or information about a call was updated @call New data about a call
updateCall call:call = Update; updateCall call:call = Update;
@ -7540,7 +7547,7 @@ recoverAuthenticationPassword recovery_code:string new_password:string new_hint:
//@token Play Integrity API or SafetyNet Attestation API token for the Android application, or secret from push notification for the iOS application //@token Play Integrity API or SafetyNet Attestation API token for the Android application, or secret from push notification for the iOS application
sendAuthenticationFirebaseSms token:string = Ok; sendAuthenticationFirebaseSms token:string = Ok;
//@description Reports that authentication code wasn't delivered via SMS; for official mobile apps only. Works only when the current authorization state is authorizationStateWaitCode @mobile_network_code Current mobile network code //@description Reports that authentication code wasn't delivered via SMS; for official mobile applications only. Works only when the current authorization state is authorizationStateWaitCode @mobile_network_code Current mobile network code
reportAuthenticationCodeMissing mobile_network_code:string = Ok; reportAuthenticationCodeMissing mobile_network_code:string = Ok;
//@description Checks the authentication token of a bot; to log in as a bot. Works only when the current authorization state is authorizationStateWaitPhoneNumber. Can be used instead of setAuthenticationPhoneNumber and checkAuthenticationCode to log in @token The bot token //@description Checks the authentication token of a bot; to log in as a bot. Works only when the current authorization state is authorizationStateWaitPhoneNumber. Can be used instead of setAuthenticationPhoneNumber and checkAuthenticationCode to log in @token The bot token
@ -9929,7 +9936,7 @@ sendPhoneNumberCode phone_number:string settings:phoneNumberAuthenticationSettin
//@token Play Integrity API or SafetyNet Attestation API token for the Android application, or secret from push notification for the iOS application //@token Play Integrity API or SafetyNet Attestation API token for the Android application, or secret from push notification for the iOS application
sendPhoneNumberFirebaseSms token:string = Ok; sendPhoneNumberFirebaseSms token:string = Ok;
//@description Reports that authentication code wasn't delivered via SMS to the specified phone number; for official mobile apps only @mobile_network_code Current mobile network code //@description Reports that authentication code wasn't delivered via SMS to the specified phone number; for official mobile applications only @mobile_network_code Current mobile network code
reportPhoneNumberCodeMissing mobile_network_code:string = Ok; reportPhoneNumberCodeMissing mobile_network_code:string = Ok;
//@description Resends the authentication code sent to a phone number. Works only if the previously received authenticationCodeInfo next_code_type was not null and the server-specified timeout has passed //@description Resends the authentication code sent to a phone number. Works only if the previously received authenticationCodeInfo next_code_type was not null and the server-specified timeout has passed

View File

@ -135,6 +135,7 @@ void NetQueryDelayer::tear_down() {
query_slot.query_->set_error(Global::request_aborted_error()); query_slot.query_->set_error(Global::request_aborted_error());
G()->net_query_dispatcher().dispatch(std::move(query_slot.query_)); G()->net_query_dispatcher().dispatch(std::move(query_slot.query_));
}); });
parent_.reset();
} }
} // namespace td } // namespace td

View File

@ -11,6 +11,7 @@
#include "td/telegram/net/DcAuthManager.h" #include "td/telegram/net/DcAuthManager.h"
#include "td/telegram/net/NetQuery.h" #include "td/telegram/net/NetQuery.h"
#include "td/telegram/net/NetQueryDelayer.h" #include "td/telegram/net/NetQueryDelayer.h"
#include "td/telegram/net/NetQueryVerifier.h"
#include "td/telegram/net/PublicRsaKeySharedCdn.h" #include "td/telegram/net/PublicRsaKeySharedCdn.h"
#include "td/telegram/net/PublicRsaKeySharedMain.h" #include "td/telegram/net/PublicRsaKeySharedMain.h"
#include "td/telegram/net/PublicRsaKeyWatchdog.h" #include "td/telegram/net/PublicRsaKeyWatchdog.h"
@ -92,6 +93,23 @@ void NetQueryDispatcher::dispatch(NetQueryPtr net_query) {
return; return;
} }
return send_closure_later(delayer_, &NetQueryDelayer::delay, std::move(net_query)); return send_closure_later(delayer_, &NetQueryDelayer::delay, std::move(net_query));
#if TD_ANDROID || TD_DARWIN_IOS || TD_DARWIN_VISION_OS || TD_DARWIN_WATCH_OS
} else if (code == 403) {
#if TD_ANDROID
Slice prefix("INTEGRITY_CHECK_CLASSIC_");
#else
Slice prefix("APNS_VERIFY_CHECK_");
#endif
if (begins_with(net_query->error().message(), prefix)) {
net_query->debug("sent to NetQueryVerifier");
std::lock_guard<std::mutex> guard(mutex_);
if (check_stop_flag(net_query)) {
return;
}
string nonce = net_query->error().message().substr(prefix.size()).str();
return send_closure_later(verifier_, &NetQueryVerifier::verify, std::move(net_query), std::move(nonce));
}
#endif
} }
} }
@ -232,6 +250,7 @@ void NetQueryDispatcher::stop() {
std::lock_guard<std::mutex> guard(mutex_); std::lock_guard<std::mutex> guard(mutex_);
stop_flag_ = true; stop_flag_ = true;
delayer_.reset(); delayer_.reset();
verifier_.reset();
for (auto &dc : dcs_) { for (auto &dc : dcs_) {
dc.main_session_.reset(); dc.main_session_.reset();
dc.upload_session_.reset(); dc.upload_session_.reset();
@ -324,6 +343,9 @@ NetQueryDispatcher::NetQueryDispatcher(const std::function<ActorShared<>()> &cre
main_dc_id_ = to_integer<int32>(s_main_dc_id); main_dc_id_ = to_integer<int32>(s_main_dc_id);
} }
delayer_ = create_actor<NetQueryDelayer>("NetQueryDelayer", create_reference()); delayer_ = create_actor<NetQueryDelayer>("NetQueryDelayer", create_reference());
#if TD_ANDROID || TD_DARWIN_IOS || TD_DARWIN_VISION_OS || TD_DARWIN_WATCH_OS
verifier_ = create_actor<NetQueryVerifier>("NetQueryVerifier", create_reference());
#endif
dc_auth_manager_ = dc_auth_manager_ =
create_actor_on_scheduler<DcAuthManager>("DcAuthManager", get_main_session_scheduler_id(), create_reference()); create_actor_on_scheduler<DcAuthManager>("DcAuthManager", get_main_session_scheduler_id(), create_reference());
public_rsa_key_watchdog_ = create_actor<PublicRsaKeyWatchdog>("PublicRsaKeyWatchdog", create_reference()); public_rsa_key_watchdog_ = create_actor<PublicRsaKeyWatchdog>("PublicRsaKeyWatchdog", create_reference());

View File

@ -27,6 +27,7 @@ namespace td {
class DcAuthManager; class DcAuthManager;
class MultiSequenceDispatcher; class MultiSequenceDispatcher;
class NetQueryDelayer; class NetQueryDelayer;
class NetQueryVerifier;
class PublicRsaKeyWatchdog; class PublicRsaKeyWatchdog;
class SessionMultiProxy; class SessionMultiProxy;
@ -60,6 +61,7 @@ class NetQueryDispatcher {
std::atomic<bool> stop_flag_{false}; std::atomic<bool> stop_flag_{false};
bool need_destroy_auth_key_{false}; bool need_destroy_auth_key_{false};
ActorOwn<NetQueryDelayer> delayer_; ActorOwn<NetQueryDelayer> delayer_;
ActorOwn<NetQueryVerifier> verifier_;
ActorOwn<DcAuthManager> dc_auth_manager_; ActorOwn<DcAuthManager> dc_auth_manager_;
ActorOwn<MultiSequenceDispatcher> sequence_dispatcher_; ActorOwn<MultiSequenceDispatcher> sequence_dispatcher_;
struct Dc { struct Dc {

View File

@ -0,0 +1,37 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/net/NetQueryVerifier.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/Td.h"
#include "td/utils/common.h"
namespace td {
void NetQueryVerifier::verify(NetQueryPtr query, string nonce) {
CHECK(query->is_ready());
CHECK(query->is_error());
auto query_id = next_query_id_++;
queries_.emplace(query_id, std::make_pair(std::move(query), nonce));
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateApplicationVerificationRequired>(query_id, nonce));
}
void NetQueryVerifier::tear_down() {
for (auto &it : queries_) {
it.second.first->set_error(Global::request_aborted_error());
G()->net_query_dispatcher().dispatch(std::move(it.second.first));
}
queries_.clear();
parent_.reset();
}
} // namespace td

View File

@ -0,0 +1,35 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/net/NetQuery.h"
#include "td/actor/actor.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include <utility>
namespace td {
class NetQueryVerifier final : public Actor {
public:
explicit NetQueryVerifier(ActorShared<> parent) : parent_(std::move(parent)) {
}
void verify(NetQueryPtr query, string nonce);
private:
void tear_down() final;
ActorShared<> parent_;
FlatHashMap<int64, std::pair<NetQueryPtr, string>> queries_;
int64 next_query_id_ = 1;
};
} // namespace td