mirror of
https://github.com/telemt/telemt.git
synced 2026-04-17 02:24:10 +03:00
ME Frame too large Fixes
Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
//! Protocol constants and datacenter addresses
|
||||
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
|
||||
use crate::crypto::SecureRandom;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
// ============= Telegram Datacenters =============
|
||||
@@ -151,7 +153,18 @@ pub const TLS_RECORD_ALERT: u8 = 0x15;
|
||||
/// Maximum TLS record size
|
||||
pub const MAX_TLS_RECORD_SIZE: usize = 16384;
|
||||
/// Maximum TLS chunk size (with overhead)
|
||||
pub const MAX_TLS_CHUNK_SIZE: usize = 16384 + 24;
|
||||
/// RFC 8446 §5.2 allows up to 16384 + 256 bytes of ciphertext
|
||||
pub const MAX_TLS_CHUNK_SIZE: usize = 16384 + 256;
|
||||
|
||||
/// Generate padding length for Secure Intermediate protocol.
|
||||
/// Total (data + padding) must not be divisible by 4 per MTProto spec.
|
||||
pub fn secure_padding_len(data_len: usize, rng: &SecureRandom) -> usize {
|
||||
if data_len % 4 == 0 {
|
||||
(rng.range(3) + 1) as usize // 1-3
|
||||
} else {
|
||||
rng.range(4) as usize // 0-3
|
||||
}
|
||||
}
|
||||
|
||||
// ============= Timeouts =============
|
||||
|
||||
@@ -319,4 +332,4 @@ mod tests {
|
||||
assert_eq!(TG_DATACENTERS_V4.len(), 5);
|
||||
assert_eq!(TG_DATACENTERS_V6.len(), 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,13 +376,9 @@ pub fn build_server_hello(
|
||||
app_data_record.push(TLS_RECORD_APPLICATION);
|
||||
app_data_record.extend_from_slice(&TLS_VERSION);
|
||||
app_data_record.extend_from_slice(&(fake_cert_len as u16).to_be_bytes());
|
||||
if fake_cert_len > 17 {
|
||||
app_data_record.extend_from_slice(&fake_cert[..fake_cert_len - 17]);
|
||||
app_data_record.push(0x16); // inner content type marker
|
||||
app_data_record.extend_from_slice(&rng.bytes(16)); // AEAD-like tag mimic
|
||||
} else {
|
||||
app_data_record.extend_from_slice(&fake_cert);
|
||||
}
|
||||
// Fill ApplicationData with fully random bytes of desired length to avoid
|
||||
// deterministic DPI fingerprints (fixed inner content type markers).
|
||||
app_data_record.extend_from_slice(&fake_cert);
|
||||
|
||||
// Combine all records
|
||||
let mut response = Vec::with_capacity(
|
||||
|
||||
Reference in New Issue
Block a user