Commit Graph

573 Commits

Author SHA1 Message Date
Igor Artamonov 4768065e72 faketls: skip ChangeCipherSpec records on read
Go / Lint (old) (push) Failing after 4m40s
Go / Lint (latest) (push) Failing after 4m40s
Go / Lint (old) (pull_request) Failing after 4m42s
Go / Lint (latest) (pull_request) Failing after 4m39s
The Read path treated every TLS record's payload as application data
and wrote it into readBuf — including the 1-byte payload (0x01) of
ChangeCipherSpec records. mtg sends those records intermittently as a
TLS-compat keep-alive; once one arrived inside the data stream it
desynced the obfuscated2 CTR keystream by one byte. From that point
on every MTProto message decrypted to garbage and the engine failed
with "decrypt: msg_key is invalid", forcibly closed the connection,
and looped.

The Go switch cases for ChangeCipherSpec and Application were both
empty (no fallthrough, no continue), so control reached the
o.readBuf.Write(rec.Data) call below the switch for both — exactly
the wrong behaviour for CCS.

Reshape the loop so that:
  - ChangeCipherSpec records are silently dropped
  - Application records are written to readBuf and returned
  - Handshake / unsupported types still error out

This matches tdlib's TlsTransport (CCS is skipped at the TLS framing
layer and never reaches the MTProto decoder).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 12:17:27 +03:00
Igor Artamonov 64bf6bfe90 faketls: emit GREASE bytes and a real padding extension
Go / Lint (old) (push) Failing after 4m39s
Go / Lint (latest) (push) Failing after 4m39s
Go / Lint (old) (pull_request) Failing after 4m39s
Go / Lint (latest) (pull_request) Failing after 4m42s
The ClientHello builder used a closure G(n) that was supposed to insert
two random GREASE bytes (RFC 8701, 0x?A?A pattern) at known positions
but expanded the buffer by zero. Every grease slot was therefore
omitted, and the trailing padding extension was written as a bare ext
id 0x0015 followed by raw zeros — its length field was never set.

Concretely, the old output looked structurally invalid to mtg's faketls
validator: the cipher list was off by two, supported_groups declared a
list_length larger than its body, and what should have been the padding
extension parsed as a stream of empty server_name extensions. mtg
responded with a fatal TLS Alert (description 50, decode_error) and
shut the connection.

Fix:
- generate seven distinct GREASE bytes per ClientHello, with the
  tdlib constraint grease[3] != grease[4]
- thread an io.Reader through writeClientHello so generation is
  deterministic in tests and keyed off the FakeTLS rand source in prod
- replace the trailing zero-pad with a proper padding extension whose
  length field is computed so the ClientHello is exactly 517 bytes

Add a regression test (structure_test.go) that feeds the result to
crypto/tls.Server: it must not return decode_error / malformed /
syntax errors. The previous output failed this; the new output passes.

The TestTLS golden vector is regenerated for the new layout.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 11:15:03 +03:00
Igor Artamonov aab48f0dbe faketls: include real record type and peek bytes on handshake errors
Go / Lint (old) (push) Failing after 4m43s
Go / Lint (latest) (push) Failing after 4m40s
Go / Lint (old) (pull_request) Failing after 4m40s
Go / Lint (latest) (pull_request) Failing after 4m43s
The previous error path used errors.Wrap(err, "unexpected record type")
inside type-mismatch branches where err was already nil. With
go-faster/errors that produced a wrapError with no cause and no detail,
making the user-visible message "unexpected record type" useless for
diagnostics — there was no way to tell what mtg actually sent.

Switch to errors.Errorf with the actual received byte and a 32-byte
hex peek of the read buffer. Also wrap the read-error path with the
same peek so a partial response is visible.

This is a diagnostic-only change; the parser semantics are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 10:51:50 +03:00
Igor Artamonov b00e2d8955 connector: hex-decode mtproxy secret
Go / Lint (old) (push) Failing after 5m14s
Go / Lint (latest) (push) Failing after 5m19s
Go / Lint (old) (pull_request) Failing after 5m14s
Go / Lint (latest) (pull_request) Failing after 4m40s
dcs.MTProxy expects raw secret bytes. Carrying them verbatim through a
YAML string field is impossible: real secrets contain bytes >= 0x80
(faketls starts with 0xee, secured with 0xdd) which cannot survive a
unicode string round-trip, so the value reached the bridge corrupted or
empty (gotd then logged "invalid secret").

Accept the standard hex form printed by mtg/MTProxy tooling
(e.g. "ee" + 16-byte secret + cloak domain hex) and decode it before
handing the bytes to gotd.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 10:14:58 +03:00
Tulir Asokan e3bb26aee1 handlematrix: allow bridging cached custom emoji reactions with any scheme 2026-04-30 16:55:03 +03:00
Tulir Asokan 7c2c72bbde imagepack: implement listing interface 2026-04-30 15:49:10 +03:00
Tulir Asokan 2a0da7801a imagepack: move emoji shortcodes to go-util 2026-04-30 12:24:08 +03:00
Tulir Asokan eaf387abfe imagepack: switch to bridgev2 API for importing 2026-04-29 18:01:36 +03:00
Tulir Asokan 64d80c3d1d imagepack: populate cache when importing pack 2026-04-29 16:18:52 +03:00
Tulir Asokan c78b1abd2d imagepack: use emoji shortcode as fallback when importing packs 2026-04-29 14:51:38 +03:00
Tulir Asokan cdb77f938a tomatrix: include external_url field in messages 2026-04-28 22:01:54 +03:00
Tulir Asokan 5a1a478992 matrixfmt: convert matrix.to links in other direction too 2026-04-28 21:46:07 +03:00
Tulir Asokan d2a06ebbbe capabilities: mark lottie and webm as allowed sticker formats 2026-04-28 16:09:13 +03:00
Tulir Asokan e6243d8935 imagepack: switch to new shared metadata field 2026-04-27 20:24:10 +03:00
Tulir Asokan 9e1c42a992 matrixfmt: fix trimming all-space entity string 2026-04-27 20:24:10 +03:00
Tulir Asokan 6eacf38d74 tomatrix: use extra field in info for custom fields 2026-04-27 20:24:10 +03:00
Gerardo Rodriguez 65fcf712d3 client: treat pool.ErrConnDead as transient in onPing (#1066) 2026-04-24 13:58:43 +03:00
Tulir Asokan 8512cfe6a6 commands/imagepack: include pack metadata in sticker info 2026-04-23 14:26:52 +03:00
Tulir Asokan dce0c4dbe1 handletelegram: add support for updateBotMessageReaction
Fixes #1064
2026-04-19 17:30:20 +03:00
Tulir Asokan ac2a2c2980 legacymigrate: fix mx_room_state migration on sqlite 2026-04-16 23:11:15 +03:00
lavacat d7864fcd3a client: add initial proxy support (#1062) 2026-04-16 13:14:29 +03:00
Tulir Asokan 3f155672a7 login: always set update handler 2026-04-14 17:26:33 +03:00
Tulir Asokan 95db7a6d0d tomatrix: fix default file names 2026-04-13 16:48:19 +03:00
Tulir Asokan 8b3707b0ee handlematrix: redact previous sponsored message when sending new one 2026-04-13 12:24:02 +03:00
Tulir Asokan 4d46c5ee7c tomatrix: use m.image for bridging document images 2026-04-12 01:03:06 +03:00
Tulir Asokan 009ce8c0d3 handlematrix: remove unnecessary nil checks 2026-04-11 19:58:39 +03:00
Tulir Asokan a06b7d607d handlematrix: add video document attribute 2026-04-11 19:56:45 +03:00
Tulir Asokan 53dec19878 login: increase buffer for QR renewal 2026-04-10 22:58:16 +03:00
Tulir Asokan a5b1927acb handletelegram: don't sync empty reactions on new messages 2026-04-10 20:33:31 +03:00
Tulir Asokan 0988de1267 tomatrix: consistently add extensions for all files 2026-04-10 20:19:16 +03:00
Tulir Asokan 5c1975808a tomatrix: add extension to unnamed documents from telegram 2026-04-10 20:01:30 +03:00
Tulir Asokan 634cec5ba9 tomatrix: avoid multipart messages 2026-04-10 14:43:37 +03:00
Tulir Asokan 506e13f6b8 commands: remove extra dots 2026-04-10 13:21:29 +03:00
Tulir Asokan e55e596d68 commands/join: allow different invite hash lengths 2026-04-10 13:20:48 +03:00
Tulir Asokan 11495e6e7e client: fix handling mentions of non-logged-in users 2026-04-09 23:32:34 +03:00
Tulir Asokan 60e3cf9c01 gotd/tgerr: reduce default flood wait max duration 2026-04-08 00:41:22 +03:00
Tulir Asokan cc32d48fea backfill: add support for forward backfilling more than 100 messages 2026-04-08 00:41:22 +03:00
Tulir Asokan 117c5cd0ce tomatrix: always add extension for photos 2026-04-06 18:00:08 +03:00
Tulir Asokan 41f2166feb tomatrix: fix adding per-message profile for channel messages 2026-04-06 00:38:31 +03:00
Tulir Asokan 92fdf7b8e9 all: fix inconsistent method receiver names 2026-04-05 21:22:22 +03:00
Tulir Asokan f13af2ef54 userinfo: add missing changed condition 2026-04-05 21:20:51 +03:00
Tulir Asokan 0172a5733b tomatrix: add support for partial quotes 2026-04-04 22:37:22 +03:00
Tulir Asokan c3216f1e4d commands/join: include chat name in response 2026-04-03 23:41:34 +03:00
Tulir Asokan 0bee8da0f8 commands: add join group command 2026-04-03 21:59:32 +03:00
Tulir Asokan 795b27275f startchat: allow username links when starting DMs 2026-04-03 21:51:56 +03:00
Tulir Asokan cbff082e4d config: re-add displayname template
Fixes #1057
2026-04-03 15:09:36 +03:00
Tulir Asokan e7099d26f3 handletelegram: set dont_render_edited flag 2026-04-03 01:42:20 +03:00
Tulir Asokan 8b68fdce79 handlematrix: fix delete chat error messages 2026-04-03 00:46:09 +03:00
Tulir Asokan 1dc01bcffd handlematrix: ignore more updates in send response 2026-04-03 00:46:09 +03:00
Tulir Asokan dbab7f0ee4 commands: add upgrade command 2026-04-03 00:46:09 +03:00