From 9289b61b923140f26b394574b07d4a615fc31755 Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Wed, 26 Jun 2019 17:27:19 +0200 Subject: [PATCH] ConnectionCreator: use tls init GitOrigin-RevId: f58530975f30e5341e250478c3f83cabf8947b71 --- td/mtproto/IStreamTransport.cpp | 2 +- td/mtproto/TcpTransport.h | 5 +++-- td/mtproto/TransportType.h | 8 +++++--- td/telegram/net/ConnectionCreator.cpp | 11 +++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/td/mtproto/IStreamTransport.cpp b/td/mtproto/IStreamTransport.cpp index 92e050354..6b807e529 100644 --- a/td/mtproto/IStreamTransport.cpp +++ b/td/mtproto/IStreamTransport.cpp @@ -15,7 +15,7 @@ namespace mtproto { unique_ptr create_transport(TransportType type) { switch (type.type) { case TransportType::ObfuscatedTcp: - return td::make_unique(type.dc_id, std::move(type.secret), type.emulate_tls); + return td::make_unique(type.dc_id, std::move(type.secret)); case TransportType::Tcp: return td::make_unique(); case TransportType::Http: diff --git a/td/mtproto/TcpTransport.h b/td/mtproto/TcpTransport.h index 0a950ec64..16e8609ac 100644 --- a/td/mtproto/TcpTransport.h +++ b/td/mtproto/TcpTransport.h @@ -123,8 +123,9 @@ class OldTransport : public IStreamTransport { class ObfuscatedTransport : public IStreamTransport { public: - ObfuscatedTransport(int16 dc_id, std::string secret, bool emulate_tls) - : dc_id_(dc_id), secret_(std::move(secret)), emulate_tls_(emulate_tls), impl_(secret_.size() >= 17) { + ObfuscatedTransport(int16 dc_id, std::string secret) + : dc_id_(dc_id), secret_(std::move(secret)), impl_(secret_.size() >= 17) { + emulate_tls_ = secret.size() >= 17 && secret[0] == '\0xee'; } Result read_next(BufferSlice *message, uint32 *quick_ack) override TD_WARN_UNUSED_RESULT; diff --git a/td/mtproto/TransportType.h b/td/mtproto/TransportType.h index 1a1bb4279..3b0c64ff5 100644 --- a/td/mtproto/TransportType.h +++ b/td/mtproto/TransportType.h @@ -15,11 +15,13 @@ struct TransportType { enum Type { Tcp, ObfuscatedTcp, Http } type = Tcp; int16 dc_id{0}; string secret; - bool emulate_tls{false}; TransportType() = default; - TransportType(Type type, int16 dc_id, string secret, bool emulate_tls = false) - : type(type), dc_id(dc_id), secret(std::move(secret)), emulate_tls(emulate_tls) { + TransportType(Type type, int16 dc_id, string secret) : type(type), dc_id(dc_id), secret(std::move(secret)) { + } + + bool emulate_tls() const { + return secret.size() >= 17 && secret[0] == '\0xee'; } }; diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index e14ffc3ee..d8eb1aa5a 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -21,6 +21,7 @@ #include "td/mtproto/Ping.h" #include "td/mtproto/RawConnection.h" +#include "td/mtproto/TlsInit.h" #include "td/net/GetHostByNameActor.h" #include "td/net/HttpProxy.h" @@ -961,6 +962,8 @@ void ConnectionCreator::client_loop(ClientInfo &client) { client.checking_connections++; } + bool emulate_tls = extra.transport_type.emulate_tls(); + auto promise = PromiseCreator::lambda( [actor_id = actor_id(this), check_mode, transport_type = extra.transport_type, hash = client.hash, debug_str = extra.debug_str, @@ -973,7 +976,7 @@ void ConnectionCreator::client_loop(ClientInfo &client) { td::make_unique(client.is_media ? media_net_stats_callback_ : common_net_stats_callback_, actor_id(this), client.hash, extra.stat); - if (proxy.use_socks5_proxy() || proxy.use_http_tcp_proxy()) { + if (proxy.use_socks5_proxy() || proxy.use_http_tcp_proxy() || emulate_tls) { VLOG(connections) << "In client_loop: create new transparent proxy connection " << extra.debug_str; class Callback : public TransparentProxy::Callback { public: @@ -1013,10 +1016,14 @@ void ConnectionCreator::client_loop(ClientInfo &client) { children_[token] = { true, create_actor("Socks5", std::move(socket_fd), extra.mtproto_ip, proxy.proxy().user().str(), proxy.proxy().password().str(), std::move(callback), create_reference(token))}; - } else { + } else if (proxy.use_http_tcp_proxy()) { children_[token] = {true, create_actor("HttpProxy", std::move(socket_fd), extra.mtproto_ip, proxy.proxy().user().str(), proxy.proxy().password().str(), std::move(callback), create_reference(token))}; + } else { + children_[token] = {true, create_actor("HttpProxy", std::move(socket_fd), extra.mtproto_ip, + "www.google.com" /*todo use domain*/, "", std::move(callback), + create_reference(token))}; } } else { VLOG(connections) << "In client_loop: create new direct connection " << extra.debug_str;