From da4dd220b86f8378bba804d5287603633577db71 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 26 Jun 2019 23:27:37 +0300 Subject: [PATCH] Minor fixes. GitOrigin-RevId: cbbb78a28570618e5a5c2c04625297678d5ac8cc --- td/mtproto/TcpTransport.h | 2 +- td/mtproto/TlsInit.cpp | 31 +++++++++++++++++++------------ td/mtproto/TlsInit.h | 5 +++++ td/mtproto/TransportType.h | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/td/mtproto/TcpTransport.h b/td/mtproto/TcpTransport.h index 16e8609a..17fc52d1 100644 --- a/td/mtproto/TcpTransport.h +++ b/td/mtproto/TcpTransport.h @@ -125,7 +125,7 @@ class ObfuscatedTransport : public IStreamTransport { public: 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'; + emulate_tls_ = secret.size() >= 17 && secret[0] == '\xee'; } Result read_next(BufferSlice *message, uint32 *quick_ack) override TD_WARN_UNUSED_RESULT; diff --git a/td/mtproto/TlsInit.cpp b/td/mtproto/TlsInit.cpp index bf62933b..31b01224 100644 --- a/td/mtproto/TlsInit.cpp +++ b/td/mtproto/TlsInit.cpp @@ -75,7 +75,7 @@ class TlsHello { }; static const TlsHello &get_default() { - static TlsHello res = [] { + static TlsHello result = [] { TlsHello res; res.ops_ = { Op::string("\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03"), @@ -112,7 +112,7 @@ class TlsHello { Op::string("\x00\x01\x00\x00\x15")}; return res; }(); - return res; + return result; } Span get_ops() const { return ops_; @@ -148,6 +148,9 @@ class TlsHelloContext { class TlsHelloCalcLength { public: void do_op(const TlsHello::Op &op, const TlsHelloContext *context) { + if (status_.is_error()) { + return; + } using Type = TlsHello::Op::Type; switch (op.type) { case Type::String: @@ -155,13 +158,13 @@ class TlsHelloCalcLength { break; case Type::Random: if (op.length <= 0 || op.length > 1024) { - on_error(Status::Error("Invalid random length")); + return on_error(Status::Error("Invalid random length")); } size_ += op.length; break; case Type::Zero: - if (op.length < 0 || op.length > 1024) { - on_error(Status::Error("Invalid zero length")); + if (op.length <= 0 || op.length > 1024) { + return on_error(Status::Error("Invalid zero length")); } size_ += op.length; break; @@ -171,8 +174,8 @@ class TlsHelloCalcLength { break; case Type::Grease: CHECK(context); - if (op.seed < 0 || static_cast(op.seed) > context->grease_size()) { - on_error(Status::Error("Invalid grease seed")); + if (op.seed < 0 || static_cast(op.seed) >= context->grease_size()) { + return on_error(Status::Error("Invalid grease seed")); } size_ += 2; break; @@ -180,22 +183,25 @@ class TlsHelloCalcLength { size_ += 2; scope_offset_.push_back(size_); break; - case Type::EndScope: + case Type::EndScope: { if (scope_offset_.empty()) { - on_error(Status::Error("Unbalanced scopes")); + return on_error(Status::Error("Unbalanced scopes")); } auto begin_offset = scope_offset_.back(); scope_offset_.pop_back(); auto end_offset = size_; auto size = end_offset - begin_offset; if (size >= (1 << 14)) { - on_error(Status::Error("Scope is too big")); + return on_error(Status::Error("Scope is too big")); } break; + } + default: + UNREACHABLE(); } } - Result finish() { + Result finish() { if (size_ > 515) { on_error(Status::Error("Too long for zero padding")); } @@ -215,7 +221,7 @@ class TlsHelloCalcLength { } private: - int64 size_{0}; + size_t size_{0}; Status status_; std::vector scope_offset_; @@ -277,6 +283,7 @@ class TlsHelloStore { } } } + void finish(int32 unix_time) { int zero_pad = 515 - static_cast(get_offset()); using Op = TlsHello::Op; diff --git a/td/mtproto/TlsInit.h b/td/mtproto/TlsInit.h index 2314e8de..769a563a 100644 --- a/td/mtproto/TlsInit.h +++ b/td/mtproto/TlsInit.h @@ -5,9 +5,13 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once + #include "td/net/TransparentProxy.h" +#include "td/utils/Status.h" + namespace td { + class Grease { public: static void init(MutableSlice res); @@ -28,4 +32,5 @@ class TlsInit : public TransparentProxy { Status loop_impl() override; }; + } // namespace td diff --git a/td/mtproto/TransportType.h b/td/mtproto/TransportType.h index 3b0c64ff..decfbfe7 100644 --- a/td/mtproto/TransportType.h +++ b/td/mtproto/TransportType.h @@ -21,7 +21,7 @@ struct TransportType { } bool emulate_tls() const { - return secret.size() >= 17 && secret[0] == '\0xee'; + return secret.size() >= 17 && secret[0] == '\xee'; } };