mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-18 21:26:41 +00:00
Improve some paddings.
This commit is contained in:
parent
7decf68122
commit
a2c33545d4
@ -189,9 +189,7 @@ ConnectionPointer AbstractConnection::Create(
|
||||
}
|
||||
|
||||
uint32 AbstractConnection::extendedNotSecurePadding() const {
|
||||
return requiresExtendedPadding()
|
||||
? uint32(openssl::RandomValue<uchar>() & 0x3F)
|
||||
: 0;
|
||||
return uint32(openssl::RandomValue<uchar>() & 0x3F);
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
|
@ -92,9 +92,6 @@ public:
|
||||
[[nodiscard]] virtual bool needHttpWait() {
|
||||
return false;
|
||||
}
|
||||
[[nodiscard]] virtual bool requiresExtendedPadding() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual int32 debugState() const = 0;
|
||||
|
||||
|
@ -198,12 +198,6 @@ void ResolvingConnection::sendData(mtpBuffer &&buffer) {
|
||||
_child->sendData(std::move(buffer));
|
||||
}
|
||||
|
||||
bool ResolvingConnection::requiresExtendedPadding() const {
|
||||
Expects(_child != nullptr);
|
||||
|
||||
return _child->requiresExtendedPadding();
|
||||
}
|
||||
|
||||
void ResolvingConnection::disconnectFromServer() {
|
||||
_address = QString();
|
||||
_port = 0;
|
||||
|
@ -35,7 +35,6 @@ public:
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) override;
|
||||
bool isConnected() const override;
|
||||
bool requiresExtendedPadding() const override;
|
||||
|
||||
int32 debugState() const override;
|
||||
|
||||
|
@ -35,7 +35,6 @@ public:
|
||||
virtual uint32 id() const = 0;
|
||||
virtual bool supportsArbitraryLength() const = 0;
|
||||
|
||||
virtual bool requiresExtendedPadding() const = 0;
|
||||
virtual void prepareKey(bytes::span key, bytes::const_span source) = 0;
|
||||
virtual bytes::span finalizePacket(mtpBuffer &buffer) = 0;
|
||||
|
||||
@ -58,7 +57,6 @@ public:
|
||||
uint32 id() const override;
|
||||
bool supportsArbitraryLength() const override;
|
||||
|
||||
bool requiresExtendedPadding() const override;
|
||||
void prepareKey(bytes::span key, bytes::const_span source) override;
|
||||
bytes::span finalizePacket(mtpBuffer &buffer) override;
|
||||
|
||||
@ -75,10 +73,6 @@ bool TcpConnection::Protocol::Version0::supportsArbitraryLength() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TcpConnection::Protocol::Version0::requiresExtendedPadding() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void TcpConnection::Protocol::Version0::prepareKey(
|
||||
bytes::span key,
|
||||
bytes::const_span source) {
|
||||
@ -142,7 +136,6 @@ class TcpConnection::Protocol::Version1 : public Version0 {
|
||||
public:
|
||||
explicit Version1(bytes::vector &&secret);
|
||||
|
||||
bool requiresExtendedPadding() const override;
|
||||
void prepareKey(bytes::span key, bytes::const_span source) override;
|
||||
|
||||
private:
|
||||
@ -154,10 +147,6 @@ TcpConnection::Protocol::Version1::Version1(bytes::vector &&secret)
|
||||
: _secret(std::move(secret)) {
|
||||
}
|
||||
|
||||
bool TcpConnection::Protocol::Version1::requiresExtendedPadding() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void TcpConnection::Protocol::Version1::prepareKey(
|
||||
bytes::span key,
|
||||
bytes::const_span source) {
|
||||
@ -425,12 +414,6 @@ void TcpConnection::socketDisconnected() {
|
||||
}
|
||||
}
|
||||
|
||||
bool TcpConnection::requiresExtendedPadding() const {
|
||||
Expects(_protocol != nullptr);
|
||||
|
||||
return _protocol->requiresExtendedPadding();
|
||||
}
|
||||
|
||||
void TcpConnection::sendData(mtpBuffer &&buffer) {
|
||||
Expects(buffer.size() > 2);
|
||||
|
||||
|
@ -36,7 +36,6 @@ public:
|
||||
bool protocolForFiles) override;
|
||||
void timedOut() override;
|
||||
bool isConnected() const override;
|
||||
bool requiresExtendedPadding() const override;
|
||||
|
||||
int32 debugState() const override;
|
||||
|
||||
|
@ -25,7 +25,7 @@ namespace {
|
||||
auto serialized = SerializedRequest::Serialize(data);
|
||||
serialized.setMsgId(realMsgId);
|
||||
serialized.setSeqNo(0);
|
||||
serialized.addPadding(false, true);
|
||||
serialized.addPadding(true);
|
||||
|
||||
constexpr auto kMsgIdPosition = SerializedRequest::kMessageIdPosition;
|
||||
constexpr auto kMinMessageSize = 5;
|
||||
|
@ -14,7 +14,6 @@ namespace {
|
||||
|
||||
uint32 CountPaddingPrimesCount(
|
||||
uint32 requestSize,
|
||||
bool extended,
|
||||
bool forAuthKeyInner) {
|
||||
if (forAuthKeyInner) {
|
||||
return ((8 + requestSize) & 0x03)
|
||||
@ -30,12 +29,8 @@ uint32 CountPaddingPrimesCount(
|
||||
result += 4;
|
||||
}
|
||||
|
||||
if (extended) {
|
||||
// Some more random padding.
|
||||
result += ((openssl::RandomValue<uchar>() & 0x0F) << 2);
|
||||
}
|
||||
|
||||
return result;
|
||||
// Some more random padding.
|
||||
return result + ((openssl::RandomValue<uchar>() & 0x0F) << 2);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -103,14 +98,13 @@ uint32 SerializedRequest::getSeqNo() const {
|
||||
return uint32((*_data)[kSeqNoPosition]);
|
||||
}
|
||||
|
||||
void SerializedRequest::addPadding(bool extended, bool forAuthKeyInner) {
|
||||
void SerializedRequest::addPadding(bool forAuthKeyInner) {
|
||||
Expects(_data != nullptr);
|
||||
Expects(_data->size() > kMessageBodyPosition);
|
||||
|
||||
const auto requestSize = (tl::count_length(*this) >> 2);
|
||||
const auto padding = CountPaddingPrimesCount(
|
||||
requestSize,
|
||||
extended,
|
||||
forAuthKeyInner);
|
||||
const auto fullSize = kMessageBodyPosition + requestSize + padding;
|
||||
if (uint32(_data->size()) != fullSize) {
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
void setSeqNo(uint32 seqNo);
|
||||
[[nodiscard]] uint32 getSeqNo() const;
|
||||
|
||||
void addPadding(bool extended, bool forAuthKeyInner);
|
||||
void addPadding(bool forAuthKeyInner);
|
||||
[[nodiscard]] uint32 messageSize() const;
|
||||
|
||||
[[nodiscard]] bool needAck() const;
|
||||
|
@ -2596,7 +2596,7 @@ void SessionPrivate::destroyTemporaryKey() {
|
||||
bool SessionPrivate::sendSecureRequest(
|
||||
SerializedRequest &&request,
|
||||
bool needAnyResponse) {
|
||||
request.addPadding(_connection->requiresExtendedPadding(), false);
|
||||
request.addPadding(false);
|
||||
|
||||
uint32 fullSize = request->size();
|
||||
if (fullSize < 9) {
|
||||
|
Loading…
Reference in New Issue
Block a user