Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions td/mtproto/TlsInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class TlsHello {
BeginScope,
EndScope,
Permutation,
Padding
Padding,
EchPayload
};
Type type;
int length;
Expand Down Expand Up @@ -116,8 +117,7 @@ class TlsHello {
}
static Op ech_payload() {
Op res;
res.type = Type::Random;
res.length = Random::fast(0, 3) * 32 + 144;
res.type = Type::EchPayload;
return res;
}
static Op padding() {
Expand Down Expand Up @@ -232,6 +232,7 @@ class TlsHelloContext {
public:
TlsHelloContext(size_t grease_size, string domain) : grease_(grease_size, '\0'), domain_(std::move(domain)) {
Grease::init(grease_);
ech_payload_size_ = static_cast<size_t>(Random::fast(0, 3)) * 32 + 144;
}

char get_grease(size_t i) const {
Expand All @@ -244,10 +245,14 @@ class TlsHelloContext {
Slice get_domain() const {
return Slice(domain_).substr(0, ProxySecret::MAX_DOMAIN_LENGTH);
}
size_t get_ech_payload_size() const {
return ech_payload_size_;
}

private:
string grease_;
string domain_;
size_t ech_payload_size_;
};

class TlsHelloCalcLength {
Expand Down Expand Up @@ -320,6 +325,10 @@ class TlsHelloCalcLength {
size_ = 517;
}
break;
case Type::EchPayload:
CHECK(context);
size_ += context->get_ech_payload_size();
break;
default:
UNREACHABLE();
}
Expand Down Expand Up @@ -468,6 +477,13 @@ class TlsHelloStore {
}
break;
}
case Type::EchPayload: {
CHECK(context);
auto payload_size = context->get_ech_payload_size();
Random::secure_bytes(dest_.substr(0, payload_size));
dest_.remove_prefix(payload_size);
break;
}
default:
UNREACHABLE();
}
Expand Down