ability to disable replay protection

This commit is contained in:
Alexander Bersenev
2019-08-23 01:59:53 +05:00
parent 068996ab36
commit 8520a26837

View File

@@ -154,7 +154,7 @@ def init_config():
# the data quota for user
conf_dict.setdefault("USER_DATA_QUOTA", {})
# length of used handshake randoms for active fingerprinting protection
# length of used handshake randoms for active fingerprinting protection, zero to disable
conf_dict.setdefault("REPLAY_CHECK_LEN", 32768)
# block bad first packets to even more protect against replay-based fingerprinting
@@ -960,6 +960,9 @@ async def handle_fake_tls_handshake(handshake, reader, writer, peer):
writer.write(hello_pkt)
await writer.drain()
if config.REPLAY_CHECK_LEN > 0:
while len(used_handshakes) >= config.REPLAY_CHECK_LEN:
used_handshakes.popitem(last=False)
used_handshakes[digest] = True
reader = FakeTLSStreamReader(reader)
@@ -1095,6 +1098,7 @@ async def handle_handshake(reader, writer):
dc_idx = int.from_bytes(decrypted[DC_IDX_POS:DC_IDX_POS+2], "little", signed=True)
if config.REPLAY_CHECK_LEN > 0:
while len(used_handshakes) >= config.REPLAY_CHECK_LEN:
used_handshakes.popitem(last=False)
used_handshakes[dec_prekey_and_iv] = True