mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Handle new paddings in improved TCP protocol.
This commit is contained in:
@@ -1415,7 +1415,7 @@ void ConnectionPrivate::handleReceived() {
|
||||
}
|
||||
|
||||
auto encryptedInts = ints + kExternalHeaderIntsCount;
|
||||
auto encryptedIntsCount = (intsCount - kExternalHeaderIntsCount);
|
||||
auto encryptedIntsCount = (intsCount - kExternalHeaderIntsCount) & ~0x03U;
|
||||
auto encryptedBytesCount = encryptedIntsCount * kIntSize;
|
||||
auto decryptedBuffer = QByteArray(encryptedBytesCount, Qt::Uninitialized);
|
||||
auto msgKey = *(MTPint128*)(ints + 2);
|
||||
@@ -3062,35 +3062,22 @@ template <typename Response>
|
||||
bool ConnectionPrivate::readNotSecureResponse(Response &response) {
|
||||
onReceivedSome();
|
||||
|
||||
if (_connection->received().empty()) {
|
||||
LOG(("AuthKey Error: "
|
||||
"trying to read response from empty received list"));
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto buffer = std::move(_connection->received().front());
|
||||
_connection->received().pop_front();
|
||||
|
||||
const auto answer = _connection->parseNotSecureResponse(buffer);
|
||||
if (answer.empty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (_connection->received().empty()) {
|
||||
LOG(("AuthKey Error: trying to read response from empty received list"));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto buffer = std::move(_connection->received().front());
|
||||
_connection->received().pop_front();
|
||||
|
||||
auto answer = buffer.constData();
|
||||
auto len = buffer.size();
|
||||
if (len < 5) {
|
||||
LOG(("AuthKey Error: bad request answer, len = %1").arg(len * sizeof(mtpPrime)));
|
||||
DEBUG_LOG(("AuthKey Error: answer bytes %1").arg(Logs::mb(answer, len * sizeof(mtpPrime)).str()));
|
||||
return false;
|
||||
}
|
||||
if (answer[0] != 0 || answer[1] != 0 || (((uint32)answer[2]) & 0x03) != 1/* || (unixtime() - answer[3] > 300) || (answer[3] - unixtime() > 60)*/) { // didnt sync time yet
|
||||
LOG(("AuthKey Error: bad request answer start (%1 %2 %3)").arg(answer[0]).arg(answer[1]).arg(answer[2]));
|
||||
DEBUG_LOG(("AuthKey Error: answer bytes %1").arg(Logs::mb(answer, len * sizeof(mtpPrime)).str()));
|
||||
return false;
|
||||
}
|
||||
uint32 answerLen = (uint32)answer[4];
|
||||
if (answerLen != (len - 5) * sizeof(mtpPrime)) {
|
||||
LOG(("AuthKey Error: bad request answer %1 <> %2").arg(answerLen).arg((len - 5) * sizeof(mtpPrime)));
|
||||
DEBUG_LOG(("AuthKey Error: answer bytes %1").arg(Logs::mb(answer, len * sizeof(mtpPrime)).str()));
|
||||
return false;
|
||||
}
|
||||
const mtpPrime *from(answer + 5), *end(from + len - 5);
|
||||
response.read(from, end);
|
||||
auto from = answer.data();
|
||||
response.read(from, from + answer.size());
|
||||
} catch (Exception &) {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user