Minor fixes.
GitOrigin-RevId: cbbb78a28570618e5a5c2c04625297678d5ac8cc
This commit is contained in:
parent
c19139aedc
commit
da4dd220b8
@ -125,7 +125,7 @@ class ObfuscatedTransport : public IStreamTransport {
|
|||||||
public:
|
public:
|
||||||
ObfuscatedTransport(int16 dc_id, std::string secret)
|
ObfuscatedTransport(int16 dc_id, std::string secret)
|
||||||
: dc_id_(dc_id), secret_(std::move(secret)), impl_(secret_.size() >= 17) {
|
: 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<size_t> read_next(BufferSlice *message, uint32 *quick_ack) override TD_WARN_UNUSED_RESULT;
|
Result<size_t> read_next(BufferSlice *message, uint32 *quick_ack) override TD_WARN_UNUSED_RESULT;
|
||||||
|
@ -75,7 +75,7 @@ class TlsHello {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const TlsHello &get_default() {
|
static const TlsHello &get_default() {
|
||||||
static TlsHello res = [] {
|
static TlsHello result = [] {
|
||||||
TlsHello res;
|
TlsHello res;
|
||||||
res.ops_ = {
|
res.ops_ = {
|
||||||
Op::string("\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03"),
|
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")};
|
Op::string("\x00\x01\x00\x00\x15")};
|
||||||
return res;
|
return res;
|
||||||
}();
|
}();
|
||||||
return res;
|
return result;
|
||||||
}
|
}
|
||||||
Span<Op> get_ops() const {
|
Span<Op> get_ops() const {
|
||||||
return ops_;
|
return ops_;
|
||||||
@ -148,6 +148,9 @@ class TlsHelloContext {
|
|||||||
class TlsHelloCalcLength {
|
class TlsHelloCalcLength {
|
||||||
public:
|
public:
|
||||||
void do_op(const TlsHello::Op &op, const TlsHelloContext *context) {
|
void do_op(const TlsHello::Op &op, const TlsHelloContext *context) {
|
||||||
|
if (status_.is_error()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
using Type = TlsHello::Op::Type;
|
using Type = TlsHello::Op::Type;
|
||||||
switch (op.type) {
|
switch (op.type) {
|
||||||
case Type::String:
|
case Type::String:
|
||||||
@ -155,13 +158,13 @@ class TlsHelloCalcLength {
|
|||||||
break;
|
break;
|
||||||
case Type::Random:
|
case Type::Random:
|
||||||
if (op.length <= 0 || op.length > 1024) {
|
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;
|
size_ += op.length;
|
||||||
break;
|
break;
|
||||||
case Type::Zero:
|
case Type::Zero:
|
||||||
if (op.length < 0 || op.length > 1024) {
|
if (op.length <= 0 || op.length > 1024) {
|
||||||
on_error(Status::Error("Invalid zero length"));
|
return on_error(Status::Error("Invalid zero length"));
|
||||||
}
|
}
|
||||||
size_ += op.length;
|
size_ += op.length;
|
||||||
break;
|
break;
|
||||||
@ -171,8 +174,8 @@ class TlsHelloCalcLength {
|
|||||||
break;
|
break;
|
||||||
case Type::Grease:
|
case Type::Grease:
|
||||||
CHECK(context);
|
CHECK(context);
|
||||||
if (op.seed < 0 || static_cast<size_t>(op.seed) > context->grease_size()) {
|
if (op.seed < 0 || static_cast<size_t>(op.seed) >= context->grease_size()) {
|
||||||
on_error(Status::Error("Invalid grease seed"));
|
return on_error(Status::Error("Invalid grease seed"));
|
||||||
}
|
}
|
||||||
size_ += 2;
|
size_ += 2;
|
||||||
break;
|
break;
|
||||||
@ -180,22 +183,25 @@ class TlsHelloCalcLength {
|
|||||||
size_ += 2;
|
size_ += 2;
|
||||||
scope_offset_.push_back(size_);
|
scope_offset_.push_back(size_);
|
||||||
break;
|
break;
|
||||||
case Type::EndScope:
|
case Type::EndScope: {
|
||||||
if (scope_offset_.empty()) {
|
if (scope_offset_.empty()) {
|
||||||
on_error(Status::Error("Unbalanced scopes"));
|
return on_error(Status::Error("Unbalanced scopes"));
|
||||||
}
|
}
|
||||||
auto begin_offset = scope_offset_.back();
|
auto begin_offset = scope_offset_.back();
|
||||||
scope_offset_.pop_back();
|
scope_offset_.pop_back();
|
||||||
auto end_offset = size_;
|
auto end_offset = size_;
|
||||||
auto size = end_offset - begin_offset;
|
auto size = end_offset - begin_offset;
|
||||||
if (size >= (1 << 14)) {
|
if (size >= (1 << 14)) {
|
||||||
on_error(Status::Error("Scope is too big"));
|
return on_error(Status::Error("Scope is too big"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<int64> finish() {
|
Result<size_t> finish() {
|
||||||
if (size_ > 515) {
|
if (size_ > 515) {
|
||||||
on_error(Status::Error("Too long for zero padding"));
|
on_error(Status::Error("Too long for zero padding"));
|
||||||
}
|
}
|
||||||
@ -215,7 +221,7 @@ class TlsHelloCalcLength {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64 size_{0};
|
size_t size_{0};
|
||||||
Status status_;
|
Status status_;
|
||||||
std::vector<size_t> scope_offset_;
|
std::vector<size_t> scope_offset_;
|
||||||
|
|
||||||
@ -277,6 +283,7 @@ class TlsHelloStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void finish(int32 unix_time) {
|
void finish(int32 unix_time) {
|
||||||
int zero_pad = 515 - static_cast<int>(get_offset());
|
int zero_pad = 515 - static_cast<int>(get_offset());
|
||||||
using Op = TlsHello::Op;
|
using Op = TlsHello::Op;
|
||||||
|
@ -5,9 +5,13 @@
|
|||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/net/TransparentProxy.h"
|
#include "td/net/TransparentProxy.h"
|
||||||
|
|
||||||
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class Grease {
|
class Grease {
|
||||||
public:
|
public:
|
||||||
static void init(MutableSlice res);
|
static void init(MutableSlice res);
|
||||||
@ -28,4 +32,5 @@ class TlsInit : public TransparentProxy {
|
|||||||
|
|
||||||
Status loop_impl() override;
|
Status loop_impl() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -21,7 +21,7 @@ struct TransportType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool emulate_tls() const {
|
bool emulate_tls() const {
|
||||||
return secret.size() >= 17 && secret[0] == '\0xee';
|
return secret.size() >= 17 && secret[0] == '\xee';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user