Ignore inbound unencrypted packets padding (0xdd transport)

GitOrigin-RevId: 7da991cb741b65fe2ade26ccc4fc3ef3c788db7a
This commit is contained in:
Arseny Smirnov 2018-06-15 21:11:07 +03:00
parent d07c172ec8
commit fdd898124b
2 changed files with 4 additions and 2 deletions

View File

@ -73,7 +73,8 @@ class HandshakeConnection
} }
packet.confirm_read(12); packet.confirm_read(12);
TRY_STATUS(handshake_->on_message(packet.as_slice(), this, context_.get())); auto fixed_packet_size = packet.size() & ~3; // remove some padded data
TRY_STATUS(handshake_->on_message(packet.as_slice().truncate(fixed_packet_size), this, context_.get()));
return Status::OK(); return Status::OK();
} }
}; };

View File

@ -98,6 +98,7 @@ Status Transport::read_crypto_impl(int X, MutableSlice message, const AuthKey &a
auto *header = &as<HeaderT>(message.begin()); auto *header = &as<HeaderT>(message.begin());
*header_ptr = header; *header_ptr = header;
auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend()); auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend());
to_decrypt = to_decrypt.truncate(to_decrypt.size() & ~15);
if (to_decrypt.size() % 16 != 0) { if (to_decrypt.size() % 16 != 0) {
return Status::Error(PSLICE() << "Invalid mtproto message: size of encrypted part is not multiple of 16 [size=" return Status::Error(PSLICE() << "Invalid mtproto message: size of encrypted part is not multiple of 16 [size="
<< to_decrypt.size() << "]"); << to_decrypt.size() << "]");
@ -287,7 +288,7 @@ Result<uint64> Transport::read_auth_key_id(Slice message) {
Status Transport::read(MutableSlice message, const AuthKey &auth_key, PacketInfo *info, MutableSlice *data, Status Transport::read(MutableSlice message, const AuthKey &auth_key, PacketInfo *info, MutableSlice *data,
int32 *error_code) { int32 *error_code) {
if (message.size() < 8) { if (message.size() < 8) {
if (message.size() == 4) { if (message.size() >= 4) {
*error_code = as<int32>(message.begin()); *error_code = as<int32>(message.begin());
return Status::OK(); return Status::OK();
} }