Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

handshake_frame.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package obfuscated2
  2. import "encoding/binary"
  3. const (
  4. handshakeFrameLen = 64
  5. handshakeFrameLenKey = 32
  6. handshakeFrameLenIV = 16
  7. handshakeFrameLenConnectionType = 4
  8. handshakeFrameLenDC = 2
  9. handshakeFrameOffsetStart = 8
  10. handshakeFrameOffsetKey = handshakeFrameOffsetStart
  11. handshakeFrameOffsetIV = handshakeFrameOffsetKey + handshakeFrameLenKey
  12. handshakeFrameOffsetConnectionType = handshakeFrameOffsetIV + handshakeFrameLenIV
  13. handshakeFrameOffsetDC = handshakeFrameOffsetConnectionType + handshakeFrameLenConnectionType
  14. handshakeFrameOffsetEnd = handshakeFrameOffsetDC + handshakeFrameLenDC
  15. )
  16. // A structure of obfuscated2 handshake frame is following:
  17. //
  18. // [frameOffsetFirst:frameOffsetKey:frameOffsetIV:frameOffsetMagic:frameOffsetDC:frameOffsetEnd].
  19. //
  20. // - 8 bytes of noise
  21. // - 32 bytes of AES Key
  22. // - 16 bytes of AES IV
  23. // - 4 bytes of 'connection type' - this has some setting like a connection type
  24. // - 2 bytes of 'DC'. DC is little endian int16
  25. // - 2 bytes of noise
  26. type handshakeFrame struct {
  27. data [handshakeFrameLen]byte
  28. }
  29. func (h *handshakeFrame) dc() int16 {
  30. data := h.data[handshakeFrameOffsetDC:handshakeFrameOffsetEnd]
  31. return int16(binary.LittleEndian.Uint16(data))
  32. }
  33. func (h *handshakeFrame) key() []byte {
  34. return h.data[handshakeFrameOffsetKey:handshakeFrameOffsetIV]
  35. }
  36. func (h *handshakeFrame) iv() []byte {
  37. return h.data[handshakeFrameOffsetIV:handshakeFrameOffsetConnectionType]
  38. }
  39. func (h *handshakeFrame) connectionType() []byte {
  40. return h.data[handshakeFrameOffsetConnectionType:handshakeFrameOffsetDC]
  41. }