summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/td/mtproto/Handshake.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/td/mtproto/Handshake.h')
-rw-r--r--protocols/Telegram/tdlib/td/td/mtproto/Handshake.h99
1 files changed, 54 insertions, 45 deletions
diff --git a/protocols/Telegram/tdlib/td/td/mtproto/Handshake.h b/protocols/Telegram/tdlib/td/td/mtproto/Handshake.h
index 8c7ae7baac..e53eda6f61 100644
--- a/protocols/Telegram/tdlib/td/td/mtproto/Handshake.h
+++ b/protocols/Telegram/tdlib/td/td/mtproto/Handshake.h
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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)
@@ -7,22 +7,32 @@
#pragma once
#include "td/mtproto/AuthKey.h"
-#include "td/mtproto/crypto.h"
+#include "td/mtproto/RSA.h"
#include "td/utils/buffer.h"
-#include "td/utils/int_types.h"
+#include "td/utils/common.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
+#include "td/utils/StorerBase.h"
+#include "td/utils/UInt.h"
namespace td {
-class Storer;
+
+namespace mtproto_api {
+class Object;
+} // namespace mtproto_api
+
namespace mtproto {
+
+class DhCallback;
+
class AuthKeyHandshakeContext {
public:
virtual ~AuthKeyHandshakeContext() = default;
virtual DhCallback *get_dh_callback() = 0;
virtual PublicRsaKeyInterface *get_public_rsa_key_interface() = 0;
};
+
class AuthKeyHandshake {
public:
class Callback {
@@ -33,70 +43,69 @@ class AuthKeyHandshake {
virtual ~Callback() = default;
virtual void send_no_crypto(const Storer &storer) = 0;
};
- using Context = AuthKeyHandshakeContext;
- enum class Mode { Unknown, Main, Temp };
- AuthKey auth_key;
- double server_time_diff = 0;
- uint64 server_salt = 0;
- bool is_ready_for_start();
- Status start_main(Callback *connection) TD_WARN_UNUSED_RESULT;
- Status start_tmp(Callback *connection, int32 expire_in) TD_WARN_UNUSED_RESULT;
+ AuthKeyHandshake(int32 dc_id, int32 expires_in);
- bool is_ready_for_message(const UInt128 &message_nonce);
+ void set_timeout_in(double timeout_in);
+
+ bool is_ready_for_finish() const;
- bool is_ready_for_finish();
void on_finish();
- explicit AuthKeyHandshake(int32 expire_in = 0) {
- if (expire_in == 0) {
- mode_ = Mode::Main;
- } else {
- mode_ = Mode::Temp;
- expire_in_ = expire_in;
- }
+ void resume(Callback *connection);
+
+ Status on_message(Slice message, Callback *connection, AuthKeyHandshakeContext *context) TD_WARN_UNUSED_RESULT;
+
+ void clear();
+
+ const AuthKey &get_auth_key() const {
+ return auth_key_;
}
- void init_main() {
- clear();
- mode_ = Mode::Main;
+
+ AuthKey release_auth_key() {
+ return std::move(auth_key_);
}
- void init_temp(int32 expire_in) {
- clear();
- mode_ = Mode::Temp;
- expire_in_ = expire_in;
+
+ double get_server_time_diff() const {
+ return server_time_diff_;
}
- void resume(Callback *connection);
- Status on_message(Slice message, Callback *connection, Context *context) TD_WARN_UNUSED_RESULT;
- bool is_ready() {
- return is_ready_for_finish();
+
+ uint64 get_server_salt() const {
+ return server_salt_;
}
- void clear();
private:
- using State = enum { Start, ResPQ, ServerDHParams, DHGenResponse, Finish };
+ enum State : int32 { Start, ResPQ, ServerDHParams, DHGenResponse, Finish };
State state_ = Start;
- Mode mode_ = Mode::Unknown;
- int32 expire_in_;
- double expire_at_ = 0;
+ enum class Mode : int32 { Main, Temp };
+ Mode mode_ = Mode::Main;
+ int32 dc_id_ = 0;
+ int32 expires_in_ = 0;
+ double expires_at_ = 0;
+
+ double start_time_ = 0;
+ double timeout_in_ = 0;
- UInt128 nonce;
- UInt128 server_nonce;
- UInt256 new_nonce;
- UInt256 tmp_aes_key;
- UInt256 tmp_aes_iv;
+ AuthKey auth_key_;
+ double server_time_diff_ = 0;
+ uint64 server_salt_ = 0;
+
+ UInt128 nonce_;
+ UInt128 server_nonce_;
+ UInt256 new_nonce_;
BufferSlice last_query_;
- template <class DataT>
- Result<size_t> fill_data_with_hash(uint8 *data_with_hash, const DataT &data) TD_WARN_UNUSED_RESULT;
+ static string store_object(const mtproto_api::Object &object);
void send(Callback *connection, const Storer &storer);
- void do_send(Callback *connection, const Storer &storer);
+ static void do_send(Callback *connection, const Storer &storer);
Status on_start(Callback *connection) TD_WARN_UNUSED_RESULT;
Status on_res_pq(Slice message, Callback *connection, PublicRsaKeyInterface *public_rsa_key) TD_WARN_UNUSED_RESULT;
Status on_server_dh_params(Slice message, Callback *connection, DhCallback *dh_callback) TD_WARN_UNUSED_RESULT;
Status on_dh_gen_response(Slice message, Callback *connection) TD_WARN_UNUSED_RESULT;
};
+
} // namespace mtproto
} // namespace td